]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.6-201310191259.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.6-201310191259.patch
CommitLineData
64d2158b
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 e87ba83..ee3c7b7 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/syscall.h b/arch/arm/include/asm/syscall.h
2095index f1d96d4..73ddd72 100644
2096--- a/arch/arm/include/asm/syscall.h
2097+++ b/arch/arm/include/asm/syscall.h
2098@@ -57,6 +57,9 @@ static inline void syscall_get_arguments(struct task_struct *task,
2099 unsigned int i, unsigned int n,
2100 unsigned long *args)
2101 {
2102+ if (n == 0)
2103+ return;
2104+
2105 if (i + n > SYSCALL_MAX_ARGS) {
2106 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
2107 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
2108@@ -81,6 +84,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
2109 unsigned int i, unsigned int n,
2110 const unsigned long *args)
2111 {
2112+ if (n == 0)
2113+ return;
2114+
2115 if (i + n > SYSCALL_MAX_ARGS) {
2116 pr_warning("%s called with max args %d, handling only %d\n",
2117 __func__, i + n, SYSCALL_MAX_ARGS);
2118diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2119index 2b8114f..8fe9bcf 100644
2120--- a/arch/arm/include/asm/thread_info.h
2121+++ b/arch/arm/include/asm/thread_info.h
2122@@ -77,9 +77,9 @@ struct thread_info {
2123 .flags = 0, \
2124 .preempt_count = INIT_PREEMPT_COUNT, \
2125 .addr_limit = KERNEL_DS, \
2126- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2127- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2128- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2129+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2130+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2131+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2132 .restart_block = { \
2133 .fn = do_no_restart_syscall, \
2134 }, \
2135@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2136 #define TIF_SYSCALL_AUDIT 9
2137 #define TIF_SYSCALL_TRACEPOINT 10
2138 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2139-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2140+/* within 8 bits of TIF_SYSCALL_TRACE
2141+ * to meet flexible second operand requirements
2142+ */
2143+#define TIF_GRSEC_SETXID 12
2144+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2145 #define TIF_USING_IWMMXT 17
2146 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2147 #define TIF_RESTORE_SIGMASK 20
2148@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2149 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2150 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2151 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2152+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2153
2154 /* Checks for any syscall work in entry-common.S */
2155 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2156- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2157+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2158
2159 /*
2160 * Change these and you break ASM code in entry-common.S
2161diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2162index 7e1f760..de33b13 100644
2163--- a/arch/arm/include/asm/uaccess.h
2164+++ b/arch/arm/include/asm/uaccess.h
2165@@ -18,6 +18,7 @@
2166 #include <asm/domain.h>
2167 #include <asm/unified.h>
2168 #include <asm/compiler.h>
2169+#include <asm/pgtable.h>
2170
2171 #define VERIFY_READ 0
2172 #define VERIFY_WRITE 1
2173@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2174 static inline void set_fs(mm_segment_t fs)
2175 {
2176 current_thread_info()->addr_limit = fs;
2177- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2178+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2179 }
2180
2181 #define segment_eq(a,b) ((a) == (b))
2182
2183+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2184+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2185+
2186+static inline void pax_open_userland(void)
2187+{
2188+
2189+#ifdef CONFIG_PAX_MEMORY_UDEREF
2190+ if (segment_eq(get_fs(), USER_DS)) {
2191+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2192+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2193+ }
2194+#endif
2195+
2196+}
2197+
2198+static inline void pax_close_userland(void)
2199+{
2200+
2201+#ifdef CONFIG_PAX_MEMORY_UDEREF
2202+ if (segment_eq(get_fs(), USER_DS)) {
2203+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2204+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2205+ }
2206+#endif
2207+
2208+}
2209+
2210 #define __addr_ok(addr) ({ \
2211 unsigned long flag; \
2212 __asm__("cmp %2, %0; movlo %0, #0" \
2213@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2214
2215 #define get_user(x,p) \
2216 ({ \
2217+ int __e; \
2218 might_fault(); \
2219- __get_user_check(x,p); \
2220+ pax_open_userland(); \
2221+ __e = __get_user_check(x,p); \
2222+ pax_close_userland(); \
2223+ __e; \
2224 })
2225
2226 extern int __put_user_1(void *, unsigned int);
2227@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2228
2229 #define put_user(x,p) \
2230 ({ \
2231+ int __e; \
2232 might_fault(); \
2233- __put_user_check(x,p); \
2234+ pax_open_userland(); \
2235+ __e = __put_user_check(x,p); \
2236+ pax_close_userland(); \
2237+ __e; \
2238 })
2239
2240 #else /* CONFIG_MMU */
2241@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2242 #define __get_user(x,ptr) \
2243 ({ \
2244 long __gu_err = 0; \
2245+ pax_open_userland(); \
2246 __get_user_err((x),(ptr),__gu_err); \
2247+ pax_close_userland(); \
2248 __gu_err; \
2249 })
2250
2251 #define __get_user_error(x,ptr,err) \
2252 ({ \
2253+ pax_open_userland(); \
2254 __get_user_err((x),(ptr),err); \
2255+ pax_close_userland(); \
2256 (void) 0; \
2257 })
2258
2259@@ -312,13 +352,17 @@ do { \
2260 #define __put_user(x,ptr) \
2261 ({ \
2262 long __pu_err = 0; \
2263+ pax_open_userland(); \
2264 __put_user_err((x),(ptr),__pu_err); \
2265+ pax_close_userland(); \
2266 __pu_err; \
2267 })
2268
2269 #define __put_user_error(x,ptr,err) \
2270 ({ \
2271+ pax_open_userland(); \
2272 __put_user_err((x),(ptr),err); \
2273+ pax_close_userland(); \
2274 (void) 0; \
2275 })
2276
2277@@ -418,11 +462,44 @@ do { \
2278
2279
2280 #ifdef CONFIG_MMU
2281-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2282-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2283+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2284+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2285+
2286+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2287+{
2288+ unsigned long ret;
2289+
2290+ check_object_size(to, n, false);
2291+ pax_open_userland();
2292+ ret = ___copy_from_user(to, from, n);
2293+ pax_close_userland();
2294+ return ret;
2295+}
2296+
2297+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2298+{
2299+ unsigned long ret;
2300+
2301+ check_object_size(from, n, true);
2302+ pax_open_userland();
2303+ ret = ___copy_to_user(to, from, n);
2304+ pax_close_userland();
2305+ return ret;
2306+}
2307+
2308 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2309-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2310+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2311 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2312+
2313+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2314+{
2315+ unsigned long ret;
2316+ pax_open_userland();
2317+ ret = ___clear_user(addr, n);
2318+ pax_close_userland();
2319+ return ret;
2320+}
2321+
2322 #else
2323 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2324 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2325@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2326
2327 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2328 {
2329+ if ((long)n < 0)
2330+ return n;
2331+
2332 if (access_ok(VERIFY_READ, from, n))
2333 n = __copy_from_user(to, from, n);
2334 else /* security hole - plug it */
2335@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2336
2337 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2338 {
2339+ if ((long)n < 0)
2340+ return n;
2341+
2342 if (access_ok(VERIFY_WRITE, to, n))
2343 n = __copy_to_user(to, from, n);
2344 return n;
2345diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2346index 5af0ed1..cea83883 100644
2347--- a/arch/arm/include/uapi/asm/ptrace.h
2348+++ b/arch/arm/include/uapi/asm/ptrace.h
2349@@ -92,7 +92,7 @@
2350 * ARMv7 groups of PSR bits
2351 */
2352 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2353-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2354+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2355 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2356 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2357
2358diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2359index 60d3b73..e5a0f22 100644
2360--- a/arch/arm/kernel/armksyms.c
2361+++ b/arch/arm/kernel/armksyms.c
2362@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2363
2364 /* networking */
2365 EXPORT_SYMBOL(csum_partial);
2366-EXPORT_SYMBOL(csum_partial_copy_from_user);
2367+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2368 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2369 EXPORT_SYMBOL(__csum_ipv6_magic);
2370
2371@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2372 #ifdef CONFIG_MMU
2373 EXPORT_SYMBOL(copy_page);
2374
2375-EXPORT_SYMBOL(__copy_from_user);
2376-EXPORT_SYMBOL(__copy_to_user);
2377-EXPORT_SYMBOL(__clear_user);
2378+EXPORT_SYMBOL(___copy_from_user);
2379+EXPORT_SYMBOL(___copy_to_user);
2380+EXPORT_SYMBOL(___clear_user);
2381
2382 EXPORT_SYMBOL(__get_user_1);
2383 EXPORT_SYMBOL(__get_user_2);
2384diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2385index 9cbe70c..a7b5e34 100644
2386--- a/arch/arm/kernel/entry-armv.S
2387+++ b/arch/arm/kernel/entry-armv.S
2388@@ -47,6 +47,87 @@
2389 9997:
2390 .endm
2391
2392+ .macro pax_enter_kernel
2393+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2394+ @ make aligned space for saved DACR
2395+ sub sp, sp, #8
2396+ @ save regs
2397+ stmdb sp!, {r1, r2}
2398+ @ read DACR from cpu_domain into r1
2399+ mov r2, sp
2400+ @ assume 8K pages, since we have to split the immediate in two
2401+ bic r2, r2, #(0x1fc0)
2402+ bic r2, r2, #(0x3f)
2403+ ldr r1, [r2, #TI_CPU_DOMAIN]
2404+ @ store old DACR on stack
2405+ str r1, [sp, #8]
2406+#ifdef CONFIG_PAX_KERNEXEC
2407+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2408+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2409+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2410+#endif
2411+#ifdef CONFIG_PAX_MEMORY_UDEREF
2412+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+#endif
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r2, #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!, {r1, r2}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_open_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_CLIENT
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2439+ @ write r1 to current_thread_info()->cpu_domain
2440+ str r1, [r0, #TI_CPU_DOMAIN]
2441+ @ write r1 to DACR
2442+ mcr p15, 0, r1, c3, c0, 0
2443+ @ instruction sync
2444+ instr_sync
2445+ @ restore regs
2446+ ldmia sp!, {r0, r1}
2447+#endif
2448+ .endm
2449+
2450+ .macro pax_close_userland
2451+#ifdef CONFIG_PAX_MEMORY_UDEREF
2452+ @ save regs
2453+ stmdb sp!, {r0, r1}
2454+ @ read DACR from cpu_domain into r1
2455+ mov r0, sp
2456+ @ assume 8K pages, since we have to split the immediate in two
2457+ bic r0, r0, #(0x1fc0)
2458+ bic r0, r0, #(0x3f)
2459+ ldr r1, [r0, #TI_CPU_DOMAIN]
2460+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2461+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2462+ @ write r1 to current_thread_info()->cpu_domain
2463+ str r1, [r0, #TI_CPU_DOMAIN]
2464+ @ write r1 to DACR
2465+ mcr p15, 0, r1, c3, c0, 0
2466+ @ instruction sync
2467+ instr_sync
2468+ @ restore regs
2469+ ldmia sp!, {r0, r1}
2470+#endif
2471+ .endm
2472+
2473 .macro pabt_helper
2474 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2475 #ifdef MULTI_PABORT
2476@@ -89,11 +170,15 @@
2477 * Invalid mode handlers
2478 */
2479 .macro inv_entry, reason
2480+
2481+ pax_enter_kernel
2482+
2483 sub sp, sp, #S_FRAME_SIZE
2484 ARM( stmib sp, {r1 - lr} )
2485 THUMB( stmia sp, {r0 - r12} )
2486 THUMB( str sp, [sp, #S_SP] )
2487 THUMB( str lr, [sp, #S_LR] )
2488+
2489 mov r1, #\reason
2490 .endm
2491
2492@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2493 .macro svc_entry, stack_hole=0
2494 UNWIND(.fnstart )
2495 UNWIND(.save {r0 - pc} )
2496+
2497+ pax_enter_kernel
2498+
2499 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2500+
2501 #ifdef CONFIG_THUMB2_KERNEL
2502 SPFIX( str r0, [sp] ) @ temporarily saved
2503 SPFIX( mov r0, sp )
2504@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2505 ldmia r0, {r3 - r5}
2506 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2507 mov r6, #-1 @ "" "" "" ""
2508+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2509+ @ offset sp by 8 as done in pax_enter_kernel
2510+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2511+#else
2512 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2513+#endif
2514 SPFIX( addeq r2, r2, #4 )
2515 str r3, [sp, #-4]! @ save the "real" r0 copied
2516 @ from the exception stack
2517@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2518 .macro usr_entry
2519 UNWIND(.fnstart )
2520 UNWIND(.cantunwind ) @ don't unwind the user space
2521+
2522+ pax_enter_kernel_user
2523+
2524 sub sp, sp, #S_FRAME_SIZE
2525 ARM( stmib sp, {r1 - r12} )
2526 THUMB( stmia sp, {r0 - r12} )
2527@@ -415,7 +512,9 @@ __und_usr:
2528 tst r3, #PSR_T_BIT @ Thumb mode?
2529 bne __und_usr_thumb
2530 sub r4, r2, #4 @ ARM instr at LR - 4
2531+ pax_open_userland
2532 1: ldrt r0, [r4]
2533+ pax_close_userland
2534 #ifdef CONFIG_CPU_ENDIAN_BE8
2535 rev r0, r0 @ little endian instruction
2536 #endif
2537@@ -450,10 +549,14 @@ __und_usr_thumb:
2538 */
2539 .arch armv6t2
2540 #endif
2541+ pax_open_userland
2542 2: ldrht r5, [r4]
2543+ pax_close_userland
2544 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2545 blo __und_usr_fault_16 @ 16bit undefined instruction
2546+ pax_open_userland
2547 3: ldrht r0, [r2]
2548+ pax_close_userland
2549 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2550 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2551 orr r0, r0, r5, lsl #16
2552@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2553 */
2554 .pushsection .fixup, "ax"
2555 .align 2
2556-4: mov pc, r9
2557+4: pax_close_userland
2558+ mov pc, r9
2559 .popsection
2560 .pushsection __ex_table,"a"
2561 .long 1b, 4b
2562@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2563 THUMB( str lr, [ip], #4 )
2564 ldr r4, [r2, #TI_TP_VALUE]
2565 ldr r5, [r2, #TI_TP_VALUE + 4]
2566-#ifdef CONFIG_CPU_USE_DOMAINS
2567+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2568 ldr r6, [r2, #TI_CPU_DOMAIN]
2569 #endif
2570 switch_tls r1, r4, r5, r3, r7
2571@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2572 ldr r8, =__stack_chk_guard
2573 ldr r7, [r7, #TSK_STACK_CANARY]
2574 #endif
2575-#ifdef CONFIG_CPU_USE_DOMAINS
2576+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2577 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2578 #endif
2579 mov r5, r0
2580diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2581index 94104bf..e425391 100644
2582--- a/arch/arm/kernel/entry-common.S
2583+++ b/arch/arm/kernel/entry-common.S
2584@@ -10,18 +10,46 @@
2585
2586 #include <asm/unistd.h>
2587 #include <asm/ftrace.h>
2588+#include <asm/domain.h>
2589 #include <asm/unwind.h>
2590
2591+#include "entry-header.S"
2592+
2593 #ifdef CONFIG_NEED_RET_TO_USER
2594 #include <mach/entry-macro.S>
2595 #else
2596 .macro arch_ret_to_user, tmp1, tmp2
2597+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2598+ @ save regs
2599+ stmdb sp!, {r1, r2}
2600+ @ read DACR from cpu_domain into r1
2601+ mov r2, sp
2602+ @ assume 8K pages, since we have to split the immediate in two
2603+ bic r2, r2, #(0x1fc0)
2604+ bic r2, r2, #(0x3f)
2605+ ldr r1, [r2, #TI_CPU_DOMAIN]
2606+#ifdef CONFIG_PAX_KERNEXEC
2607+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2608+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2609+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2610+#endif
2611+#ifdef CONFIG_PAX_MEMORY_UDEREF
2612+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2613+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2614+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2615+#endif
2616+ @ write r1 to current_thread_info()->cpu_domain
2617+ str r1, [r2, #TI_CPU_DOMAIN]
2618+ @ write r1 to DACR
2619+ mcr p15, 0, r1, c3, c0, 0
2620+ @ instruction sync
2621+ instr_sync
2622+ @ restore regs
2623+ ldmia sp!, {r1, r2}
2624+#endif
2625 .endm
2626 #endif
2627
2628-#include "entry-header.S"
2629-
2630-
2631 .align 5
2632 /*
2633 * This is the fast syscall return path. We do as little as
2634@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2635 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2636 #endif
2637
2638+ /*
2639+ * do this here to avoid a performance hit of wrapping the code above
2640+ * that directly dereferences userland to parse the SWI instruction
2641+ */
2642+ pax_enter_kernel_user
2643+
2644 adr tbl, sys_call_table @ load syscall table pointer
2645
2646 #if defined(CONFIG_OABI_COMPAT)
2647diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2648index de23a9b..94c37c4 100644
2649--- a/arch/arm/kernel/entry-header.S
2650+++ b/arch/arm/kernel/entry-header.S
2651@@ -184,6 +184,60 @@
2652 msr cpsr_c, \rtemp @ switch back to the SVC mode
2653 .endm
2654
2655+ .macro pax_enter_kernel_user
2656+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2657+ @ save regs
2658+ stmdb sp!, {r0, r1}
2659+ @ read DACR from cpu_domain into r1
2660+ mov r0, sp
2661+ @ assume 8K pages, since we have to split the immediate in two
2662+ bic r0, r0, #(0x1fc0)
2663+ bic r0, r0, #(0x3f)
2664+ ldr r1, [r0, #TI_CPU_DOMAIN]
2665+#ifdef CONFIG_PAX_MEMORY_UDEREF
2666+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2667+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2668+#endif
2669+#ifdef CONFIG_PAX_KERNEXEC
2670+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2671+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2672+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2673+#endif
2674+ @ write r1 to current_thread_info()->cpu_domain
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+ .macro pax_exit_kernel
2686+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2687+ @ save regs
2688+ stmdb sp!, {r0, r1}
2689+ @ read old DACR from stack into r1
2690+ ldr r1, [sp, #(8 + S_SP)]
2691+ sub r1, r1, #8
2692+ ldr r1, [r1]
2693+
2694+ @ write r1 to current_thread_info()->cpu_domain
2695+ mov r0, sp
2696+ @ assume 8K pages, since we have to split the immediate in two
2697+ bic r0, r0, #(0x1fc0)
2698+ bic r0, r0, #(0x3f)
2699+ str r1, [r0, #TI_CPU_DOMAIN]
2700+ @ write r1 to DACR
2701+ mcr p15, 0, r1, c3, c0, 0
2702+ @ instruction sync
2703+ instr_sync
2704+ @ restore regs
2705+ ldmia sp!, {r0, r1}
2706+#endif
2707+ .endm
2708+
2709 #ifndef CONFIG_THUMB2_KERNEL
2710 .macro svc_exit, rpsr, irq = 0
2711 .if \irq != 0
2712@@ -203,6 +257,9 @@
2713 blne trace_hardirqs_off
2714 #endif
2715 .endif
2716+
2717+ pax_exit_kernel
2718+
2719 msr spsr_cxsf, \rpsr
2720 #if defined(CONFIG_CPU_V6)
2721 ldr r0, [sp]
2722@@ -266,6 +323,9 @@
2723 blne trace_hardirqs_off
2724 #endif
2725 .endif
2726+
2727+ pax_exit_kernel
2728+
2729 ldr lr, [sp, #S_SP] @ top of the stack
2730 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2731 clrex @ clear the exclusive monitor
2732diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2733index 918875d..cd5fa27 100644
2734--- a/arch/arm/kernel/fiq.c
2735+++ b/arch/arm/kernel/fiq.c
2736@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2737 void *base = vectors_page;
2738 unsigned offset = FIQ_OFFSET;
2739
2740+ pax_open_kernel();
2741 memcpy(base + offset, start, length);
2742+ pax_close_kernel();
2743+
2744 if (!cache_is_vipt_nonaliasing())
2745 flush_icache_range((unsigned long)base + offset, offset +
2746 length);
2747diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2748index 2c7cc1e..ab2e911 100644
2749--- a/arch/arm/kernel/head.S
2750+++ b/arch/arm/kernel/head.S
2751@@ -52,7 +52,9 @@
2752 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2753
2754 .macro pgtbl, rd, phys
2755- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2756+ mov \rd, #TEXT_OFFSET
2757+ sub \rd, #PG_DIR_SIZE
2758+ add \rd, \rd, \phys
2759 .endm
2760
2761 /*
2762@@ -432,7 +434,7 @@ __enable_mmu:
2763 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2764 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2765 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2766- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2767+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2768 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2769 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2770 #endif
2771diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2772index 85c3fb6..054c2dc 100644
2773--- a/arch/arm/kernel/module.c
2774+++ b/arch/arm/kernel/module.c
2775@@ -37,12 +37,39 @@
2776 #endif
2777
2778 #ifdef CONFIG_MMU
2779-void *module_alloc(unsigned long size)
2780+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2781 {
2782+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2783+ return NULL;
2784 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2785- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2786+ GFP_KERNEL, prot, -1,
2787 __builtin_return_address(0));
2788 }
2789+
2790+void *module_alloc(unsigned long size)
2791+{
2792+
2793+#ifdef CONFIG_PAX_KERNEXEC
2794+ return __module_alloc(size, PAGE_KERNEL);
2795+#else
2796+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2797+#endif
2798+
2799+}
2800+
2801+#ifdef CONFIG_PAX_KERNEXEC
2802+void module_free_exec(struct module *mod, void *module_region)
2803+{
2804+ module_free(mod, module_region);
2805+}
2806+EXPORT_SYMBOL(module_free_exec);
2807+
2808+void *module_alloc_exec(unsigned long size)
2809+{
2810+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2811+}
2812+EXPORT_SYMBOL(module_alloc_exec);
2813+#endif
2814 #endif
2815
2816 int
2817diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2818index 07314af..c46655c 100644
2819--- a/arch/arm/kernel/patch.c
2820+++ b/arch/arm/kernel/patch.c
2821@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2822 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2823 int size;
2824
2825+ pax_open_kernel();
2826 if (thumb2 && __opcode_is_thumb16(insn)) {
2827 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2828 size = sizeof(u16);
2829@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2830 *(u32 *)addr = insn;
2831 size = sizeof(u32);
2832 }
2833+ pax_close_kernel();
2834
2835 flush_icache_range((uintptr_t)(addr),
2836 (uintptr_t)(addr) + size);
2837diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2838index 94f6b05..efd7312 100644
2839--- a/arch/arm/kernel/process.c
2840+++ b/arch/arm/kernel/process.c
2841@@ -217,6 +217,7 @@ void machine_power_off(void)
2842
2843 if (pm_power_off)
2844 pm_power_off();
2845+ BUG();
2846 }
2847
2848 /*
2849@@ -230,7 +231,7 @@ void machine_power_off(void)
2850 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2851 * to use. Implementing such co-ordination would be essentially impossible.
2852 */
2853-void machine_restart(char *cmd)
2854+__noreturn void machine_restart(char *cmd)
2855 {
2856 local_irq_disable();
2857 smp_send_stop();
2858@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2859
2860 show_regs_print_info(KERN_DEFAULT);
2861
2862- print_symbol("PC is at %s\n", instruction_pointer(regs));
2863- print_symbol("LR is at %s\n", regs->ARM_lr);
2864+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2865+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2866 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2867 "sp : %08lx ip : %08lx fp : %08lx\n",
2868 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2869@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2870 return 0;
2871 }
2872
2873-unsigned long arch_randomize_brk(struct mm_struct *mm)
2874-{
2875- unsigned long range_end = mm->brk + 0x02000000;
2876- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2877-}
2878-
2879 #ifdef CONFIG_MMU
2880 #ifdef CONFIG_KUSER_HELPERS
2881 /*
2882@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2883
2884 static int __init gate_vma_init(void)
2885 {
2886- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2887+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2888 return 0;
2889 }
2890 arch_initcall(gate_vma_init);
2891@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2892
2893 const char *arch_vma_name(struct vm_area_struct *vma)
2894 {
2895- return is_gate_vma(vma) ? "[vectors]" :
2896- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2897- "[sigpage]" : NULL;
2898+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2899 }
2900
2901-static struct page *signal_page;
2902-extern struct page *get_signal_page(void);
2903-
2904 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2905 {
2906 struct mm_struct *mm = current->mm;
2907- unsigned long addr;
2908- int ret;
2909-
2910- if (!signal_page)
2911- signal_page = get_signal_page();
2912- if (!signal_page)
2913- return -ENOMEM;
2914
2915 down_write(&mm->mmap_sem);
2916- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2917- if (IS_ERR_VALUE(addr)) {
2918- ret = addr;
2919- goto up_fail;
2920- }
2921-
2922- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2923- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2924- &signal_page);
2925-
2926- if (ret == 0)
2927- mm->context.sigpage = addr;
2928-
2929- up_fail:
2930+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2931 up_write(&mm->mmap_sem);
2932- return ret;
2933+ return 0;
2934 }
2935 #endif
2936diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2937index 4693188..4596c5e 100644
2938--- a/arch/arm/kernel/psci.c
2939+++ b/arch/arm/kernel/psci.c
2940@@ -24,7 +24,7 @@
2941 #include <asm/opcodes-virt.h>
2942 #include <asm/psci.h>
2943
2944-struct psci_operations psci_ops;
2945+struct psci_operations psci_ops __read_only;
2946
2947 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2948
2949diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2950index 0dd3b79..e018f64 100644
2951--- a/arch/arm/kernel/ptrace.c
2952+++ b/arch/arm/kernel/ptrace.c
2953@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2954 return current_thread_info()->syscall;
2955 }
2956
2957+#ifdef CONFIG_GRKERNSEC_SETXID
2958+extern void gr_delayed_cred_worker(void);
2959+#endif
2960+
2961 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2962 {
2963 current_thread_info()->syscall = scno;
2964
2965+#ifdef CONFIG_GRKERNSEC_SETXID
2966+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2967+ gr_delayed_cred_worker();
2968+#endif
2969+
2970 /* Do the secure computing check first; failures should be fast. */
2971 if (secure_computing(scno) == -1)
2972 return -1;
2973diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2974index afc2489..6372bc8 100644
2975--- a/arch/arm/kernel/setup.c
2976+++ b/arch/arm/kernel/setup.c
2977@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2978 unsigned int elf_hwcap __read_mostly;
2979 EXPORT_SYMBOL(elf_hwcap);
2980
2981+pteval_t __supported_pte_mask __read_only;
2982+pmdval_t __supported_pmd_mask __read_only;
2983
2984 #ifdef MULTI_CPU
2985-struct processor processor __read_mostly;
2986+struct processor processor;
2987 #endif
2988 #ifdef MULTI_TLB
2989-struct cpu_tlb_fns cpu_tlb __read_mostly;
2990+struct cpu_tlb_fns cpu_tlb __read_only;
2991 #endif
2992 #ifdef MULTI_USER
2993-struct cpu_user_fns cpu_user __read_mostly;
2994+struct cpu_user_fns cpu_user __read_only;
2995 #endif
2996 #ifdef MULTI_CACHE
2997-struct cpu_cache_fns cpu_cache __read_mostly;
2998+struct cpu_cache_fns cpu_cache __read_only;
2999 #endif
3000 #ifdef CONFIG_OUTER_CACHE
3001-struct outer_cache_fns outer_cache __read_mostly;
3002+struct outer_cache_fns outer_cache __read_only;
3003 EXPORT_SYMBOL(outer_cache);
3004 #endif
3005
3006@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
3007 asm("mrc p15, 0, %0, c0, c1, 4"
3008 : "=r" (mmfr0));
3009 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3010- (mmfr0 & 0x000000f0) >= 0x00000030)
3011+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3012 cpu_arch = CPU_ARCH_ARMv7;
3013- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3014+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3015+ __supported_pte_mask |= L_PTE_PXN;
3016+ __supported_pmd_mask |= PMD_PXNTABLE;
3017+ }
3018+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3019 (mmfr0 & 0x000000f0) == 0x00000020)
3020 cpu_arch = CPU_ARCH_ARMv6;
3021 else
3022@@ -571,7 +577,7 @@ static void __init setup_processor(void)
3023 __cpu_architecture = __get_cpu_architecture();
3024
3025 #ifdef MULTI_CPU
3026- processor = *list->proc;
3027+ memcpy((void *)&processor, list->proc, sizeof processor);
3028 #endif
3029 #ifdef MULTI_TLB
3030 cpu_tlb = *list->tlb;
3031diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3032index ab33042..11248a8 100644
3033--- a/arch/arm/kernel/signal.c
3034+++ b/arch/arm/kernel/signal.c
3035@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3036 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3037 };
3038
3039-static unsigned long signal_return_offset;
3040-
3041 #ifdef CONFIG_CRUNCH
3042 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3043 {
3044@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3045 * except when the MPU has protected the vectors
3046 * page from PL0
3047 */
3048- retcode = mm->context.sigpage + signal_return_offset +
3049- (idx << 2) + thumb;
3050+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3051 } else
3052 #endif
3053 {
3054@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3055 } while (thread_flags & _TIF_WORK_MASK);
3056 return 0;
3057 }
3058-
3059-struct page *get_signal_page(void)
3060-{
3061- unsigned long ptr;
3062- unsigned offset;
3063- struct page *page;
3064- void *addr;
3065-
3066- page = alloc_pages(GFP_KERNEL, 0);
3067-
3068- if (!page)
3069- return NULL;
3070-
3071- addr = page_address(page);
3072-
3073- /* Give the signal return code some randomness */
3074- offset = 0x200 + (get_random_int() & 0x7fc);
3075- signal_return_offset = offset;
3076-
3077- /*
3078- * Copy signal return handlers into the vector page, and
3079- * set sigreturn to be a pointer to these.
3080- */
3081- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3082-
3083- ptr = (unsigned long)addr + offset;
3084- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3085-
3086- return page;
3087-}
3088diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3089index 2dc1934..ecf0e21 100644
3090--- a/arch/arm/kernel/smp.c
3091+++ b/arch/arm/kernel/smp.c
3092@@ -71,7 +71,7 @@ enum ipi_msg_type {
3093
3094 static DECLARE_COMPLETION(cpu_running);
3095
3096-static struct smp_operations smp_ops;
3097+static struct smp_operations smp_ops __read_only;
3098
3099 void __init smp_set_ops(struct smp_operations *ops)
3100 {
3101diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3102index ab517fc..9adf2fa 100644
3103--- a/arch/arm/kernel/traps.c
3104+++ b/arch/arm/kernel/traps.c
3105@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3106 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3107 {
3108 #ifdef CONFIG_KALLSYMS
3109- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3110+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3111 #else
3112 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3113 #endif
3114@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3115 static int die_owner = -1;
3116 static unsigned int die_nest_count;
3117
3118+extern void gr_handle_kernel_exploit(void);
3119+
3120 static unsigned long oops_begin(void)
3121 {
3122 int cpu;
3123@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3124 panic("Fatal exception in interrupt");
3125 if (panic_on_oops)
3126 panic("Fatal exception");
3127+
3128+ gr_handle_kernel_exploit();
3129+
3130 if (signr)
3131 do_exit(signr);
3132 }
3133@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3134 * The user helper at 0xffff0fe0 must be used instead.
3135 * (see entry-armv.S for details)
3136 */
3137+ pax_open_kernel();
3138 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3139+ pax_close_kernel();
3140 }
3141 return 0;
3142
3143@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3144 kuser_init(vectors_base);
3145
3146 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3147- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3148+
3149+#ifndef CONFIG_PAX_MEMORY_UDEREF
3150+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3151+#endif
3152+
3153 #else /* ifndef CONFIG_CPU_V7M */
3154 /*
3155 * on V7-M there is no need to copy the vector table to a dedicated
3156diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3157index 7bcee5c..e2f3249 100644
3158--- a/arch/arm/kernel/vmlinux.lds.S
3159+++ b/arch/arm/kernel/vmlinux.lds.S
3160@@ -8,7 +8,11 @@
3161 #include <asm/thread_info.h>
3162 #include <asm/memory.h>
3163 #include <asm/page.h>
3164-
3165+
3166+#ifdef CONFIG_PAX_KERNEXEC
3167+#include <asm/pgtable.h>
3168+#endif
3169+
3170 #define PROC_INFO \
3171 . = ALIGN(4); \
3172 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3173@@ -34,7 +38,7 @@
3174 #endif
3175
3176 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3177- defined(CONFIG_GENERIC_BUG)
3178+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3179 #define ARM_EXIT_KEEP(x) x
3180 #define ARM_EXIT_DISCARD(x)
3181 #else
3182@@ -90,6 +94,11 @@ SECTIONS
3183 _text = .;
3184 HEAD_TEXT
3185 }
3186+
3187+#ifdef CONFIG_PAX_KERNEXEC
3188+ . = ALIGN(1<<SECTION_SHIFT);
3189+#endif
3190+
3191 .text : { /* Real text segment */
3192 _stext = .; /* Text and read-only data */
3193 __exception_text_start = .;
3194@@ -112,6 +121,8 @@ SECTIONS
3195 ARM_CPU_KEEP(PROC_INFO)
3196 }
3197
3198+ _etext = .; /* End of text section */
3199+
3200 RO_DATA(PAGE_SIZE)
3201
3202 . = ALIGN(4);
3203@@ -142,7 +153,9 @@ SECTIONS
3204
3205 NOTES
3206
3207- _etext = .; /* End of text and rodata section */
3208+#ifdef CONFIG_PAX_KERNEXEC
3209+ . = ALIGN(1<<SECTION_SHIFT);
3210+#endif
3211
3212 #ifndef CONFIG_XIP_KERNEL
3213 . = ALIGN(PAGE_SIZE);
3214@@ -220,6 +233,11 @@ SECTIONS
3215 . = PAGE_OFFSET + TEXT_OFFSET;
3216 #else
3217 __init_end = .;
3218+
3219+#ifdef CONFIG_PAX_KERNEXEC
3220+ . = ALIGN(1<<SECTION_SHIFT);
3221+#endif
3222+
3223 . = ALIGN(THREAD_SIZE);
3224 __data_loc = .;
3225 #endif
3226diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3227index 741f66a..8a5615c 100644
3228--- a/arch/arm/kvm/arm.c
3229+++ b/arch/arm/kvm/arm.c
3230@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3231 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3232
3233 /* The VMID used in the VTTBR */
3234-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3235+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3236 static u8 kvm_next_vmid;
3237 static DEFINE_SPINLOCK(kvm_vmid_lock);
3238
3239@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3240 */
3241 static bool need_new_vmid_gen(struct kvm *kvm)
3242 {
3243- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3244+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3245 }
3246
3247 /**
3248@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3249
3250 /* First user of a new VMID generation? */
3251 if (unlikely(kvm_next_vmid == 0)) {
3252- atomic64_inc(&kvm_vmid_gen);
3253+ atomic64_inc_unchecked(&kvm_vmid_gen);
3254 kvm_next_vmid = 1;
3255
3256 /*
3257@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3258 kvm_call_hyp(__kvm_flush_vm_context);
3259 }
3260
3261- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3262+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3263 kvm->arch.vmid = kvm_next_vmid;
3264 kvm_next_vmid++;
3265
3266diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3267index 14a0d98..7771a7d 100644
3268--- a/arch/arm/lib/clear_user.S
3269+++ b/arch/arm/lib/clear_user.S
3270@@ -12,14 +12,14 @@
3271
3272 .text
3273
3274-/* Prototype: int __clear_user(void *addr, size_t sz)
3275+/* Prototype: int ___clear_user(void *addr, size_t sz)
3276 * Purpose : clear some user memory
3277 * Params : addr - user memory address to clear
3278 * : sz - number of bytes to clear
3279 * Returns : number of bytes NOT cleared
3280 */
3281 ENTRY(__clear_user_std)
3282-WEAK(__clear_user)
3283+WEAK(___clear_user)
3284 stmfd sp!, {r1, lr}
3285 mov r2, #0
3286 cmp r1, #4
3287@@ -44,7 +44,7 @@ WEAK(__clear_user)
3288 USER( strnebt r2, [r0])
3289 mov r0, #0
3290 ldmfd sp!, {r1, pc}
3291-ENDPROC(__clear_user)
3292+ENDPROC(___clear_user)
3293 ENDPROC(__clear_user_std)
3294
3295 .pushsection .fixup,"ax"
3296diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3297index 66a477a..bee61d3 100644
3298--- a/arch/arm/lib/copy_from_user.S
3299+++ b/arch/arm/lib/copy_from_user.S
3300@@ -16,7 +16,7 @@
3301 /*
3302 * Prototype:
3303 *
3304- * size_t __copy_from_user(void *to, const void *from, size_t n)
3305+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3306 *
3307 * Purpose:
3308 *
3309@@ -84,11 +84,11 @@
3310
3311 .text
3312
3313-ENTRY(__copy_from_user)
3314+ENTRY(___copy_from_user)
3315
3316 #include "copy_template.S"
3317
3318-ENDPROC(__copy_from_user)
3319+ENDPROC(___copy_from_user)
3320
3321 .pushsection .fixup,"ax"
3322 .align 0
3323diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3324index 6ee2f67..d1cce76 100644
3325--- a/arch/arm/lib/copy_page.S
3326+++ b/arch/arm/lib/copy_page.S
3327@@ -10,6 +10,7 @@
3328 * ASM optimised string functions
3329 */
3330 #include <linux/linkage.h>
3331+#include <linux/const.h>
3332 #include <asm/assembler.h>
3333 #include <asm/asm-offsets.h>
3334 #include <asm/cache.h>
3335diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3336index d066df6..df28194 100644
3337--- a/arch/arm/lib/copy_to_user.S
3338+++ b/arch/arm/lib/copy_to_user.S
3339@@ -16,7 +16,7 @@
3340 /*
3341 * Prototype:
3342 *
3343- * size_t __copy_to_user(void *to, const void *from, size_t n)
3344+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3345 *
3346 * Purpose:
3347 *
3348@@ -88,11 +88,11 @@
3349 .text
3350
3351 ENTRY(__copy_to_user_std)
3352-WEAK(__copy_to_user)
3353+WEAK(___copy_to_user)
3354
3355 #include "copy_template.S"
3356
3357-ENDPROC(__copy_to_user)
3358+ENDPROC(___copy_to_user)
3359 ENDPROC(__copy_to_user_std)
3360
3361 .pushsection .fixup,"ax"
3362diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3363index 7d08b43..f7ca7ea 100644
3364--- a/arch/arm/lib/csumpartialcopyuser.S
3365+++ b/arch/arm/lib/csumpartialcopyuser.S
3366@@ -57,8 +57,8 @@
3367 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3368 */
3369
3370-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3371-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3372+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3373+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3374
3375 #include "csumpartialcopygeneric.S"
3376
3377diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3378index 5306de3..aed6d03 100644
3379--- a/arch/arm/lib/delay.c
3380+++ b/arch/arm/lib/delay.c
3381@@ -28,7 +28,7 @@
3382 /*
3383 * Default to the loop-based delay implementation.
3384 */
3385-struct arm_delay_ops arm_delay_ops = {
3386+struct arm_delay_ops arm_delay_ops __read_only = {
3387 .delay = __loop_delay,
3388 .const_udelay = __loop_const_udelay,
3389 .udelay = __loop_udelay,
3390diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3391index 025f742..a9e5b3b 100644
3392--- a/arch/arm/lib/uaccess_with_memcpy.c
3393+++ b/arch/arm/lib/uaccess_with_memcpy.c
3394@@ -104,7 +104,7 @@ out:
3395 }
3396
3397 unsigned long
3398-__copy_to_user(void __user *to, const void *from, unsigned long n)
3399+___copy_to_user(void __user *to, const void *from, unsigned long n)
3400 {
3401 /*
3402 * This test is stubbed out of the main function above to keep
3403@@ -155,7 +155,7 @@ out:
3404 return n;
3405 }
3406
3407-unsigned long __clear_user(void __user *addr, unsigned long n)
3408+unsigned long ___clear_user(void __user *addr, unsigned long n)
3409 {
3410 /* See rational for this in __copy_to_user() above. */
3411 if (n < 64)
3412diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3413index e9238b5..6ed904a 100644
3414--- a/arch/arm/mach-kirkwood/common.c
3415+++ b/arch/arm/mach-kirkwood/common.c
3416@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3417 clk_gate_ops.disable(hw);
3418 }
3419
3420-static struct clk_ops clk_gate_fn_ops;
3421+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3422+{
3423+ return clk_gate_ops.is_enabled(hw);
3424+}
3425+
3426+static struct clk_ops clk_gate_fn_ops = {
3427+ .enable = clk_gate_fn_enable,
3428+ .disable = clk_gate_fn_disable,
3429+ .is_enabled = clk_gate_fn_is_enabled,
3430+};
3431
3432 static struct clk __init *clk_register_gate_fn(struct device *dev,
3433 const char *name,
3434@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3435 gate_fn->fn_en = fn_en;
3436 gate_fn->fn_dis = fn_dis;
3437
3438- /* ops is the gate ops, but with our enable/disable functions */
3439- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3440- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3441- clk_gate_fn_ops = clk_gate_ops;
3442- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3443- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3444- }
3445-
3446 clk = clk_register(dev, &gate_fn->gate.hw);
3447
3448 if (IS_ERR(clk))
3449diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3450index 827d1500..2885dc6 100644
3451--- a/arch/arm/mach-omap2/board-n8x0.c
3452+++ b/arch/arm/mach-omap2/board-n8x0.c
3453@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3454 }
3455 #endif
3456
3457-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3458+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3459 .late_init = n8x0_menelaus_late_init,
3460 };
3461
3462diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3463index f3fdd6a..3564800 100644
3464--- a/arch/arm/mach-omap2/gpmc.c
3465+++ b/arch/arm/mach-omap2/gpmc.c
3466@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3467 };
3468
3469 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3470-static struct irq_chip gpmc_irq_chip;
3471 static unsigned gpmc_irq_start;
3472
3473 static struct resource gpmc_mem_root;
3474@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3475
3476 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3477
3478+static struct irq_chip gpmc_irq_chip = {
3479+ .name = "gpmc",
3480+ .irq_startup = gpmc_irq_noop_ret,
3481+ .irq_enable = gpmc_irq_enable,
3482+ .irq_disable = gpmc_irq_disable,
3483+ .irq_shutdown = gpmc_irq_noop,
3484+ .irq_ack = gpmc_irq_noop,
3485+ .irq_mask = gpmc_irq_noop,
3486+ .irq_unmask = gpmc_irq_noop,
3487+
3488+};
3489+
3490 static int gpmc_setup_irq(void)
3491 {
3492 int i;
3493@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3494 return gpmc_irq_start;
3495 }
3496
3497- gpmc_irq_chip.name = "gpmc";
3498- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3499- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3500- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3501- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3502- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3503- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3504- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3505-
3506 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3507 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3508
3509diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3510index f991016..145ebeb 100644
3511--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3512+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3513@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3514 int (*finish_suspend)(unsigned long cpu_state);
3515 void (*resume)(void);
3516 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3517-};
3518+} __no_const;
3519
3520 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3521 static struct powerdomain *mpuss_pd;
3522@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3523 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3524 {}
3525
3526-struct cpu_pm_ops omap_pm_ops = {
3527+static struct cpu_pm_ops omap_pm_ops __read_only = {
3528 .finish_suspend = default_finish_suspend,
3529 .resume = dummy_cpu_resume,
3530 .scu_prepare = dummy_scu_prepare,
3531diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3532index 813c615..ce467c6 100644
3533--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3534+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3535@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3536 return NOTIFY_OK;
3537 }
3538
3539-static struct notifier_block __refdata irq_hotplug_notifier = {
3540+static struct notifier_block irq_hotplug_notifier = {
3541 .notifier_call = irq_cpu_hotplug_notify,
3542 };
3543
3544diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3545index f99f68e..e573e20 100644
3546--- a/arch/arm/mach-omap2/omap_device.c
3547+++ b/arch/arm/mach-omap2/omap_device.c
3548@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3549 struct platform_device __init *omap_device_build(const char *pdev_name,
3550 int pdev_id,
3551 struct omap_hwmod *oh,
3552- void *pdata, int pdata_len)
3553+ const void *pdata, int pdata_len)
3554 {
3555 struct omap_hwmod *ohs[] = { oh };
3556
3557@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3558 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3559 int pdev_id,
3560 struct omap_hwmod **ohs,
3561- int oh_cnt, void *pdata,
3562+ int oh_cnt, const void *pdata,
3563 int pdata_len)
3564 {
3565 int ret = -ENOMEM;
3566diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3567index 17ca1ae..beba869 100644
3568--- a/arch/arm/mach-omap2/omap_device.h
3569+++ b/arch/arm/mach-omap2/omap_device.h
3570@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3571 /* Core code interface */
3572
3573 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3574- struct omap_hwmod *oh, void *pdata,
3575+ struct omap_hwmod *oh, const void *pdata,
3576 int pdata_len);
3577
3578 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3579 struct omap_hwmod **oh, int oh_cnt,
3580- void *pdata, int pdata_len);
3581+ const void *pdata, int pdata_len);
3582
3583 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3584 struct omap_hwmod **ohs, int oh_cnt);
3585diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3586index 7f4db12..0243012 100644
3587--- a/arch/arm/mach-omap2/omap_hwmod.c
3588+++ b/arch/arm/mach-omap2/omap_hwmod.c
3589@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3590 int (*init_clkdm)(struct omap_hwmod *oh);
3591 void (*update_context_lost)(struct omap_hwmod *oh);
3592 int (*get_context_lost)(struct omap_hwmod *oh);
3593-};
3594+} __no_const;
3595
3596 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3597-static struct omap_hwmod_soc_ops soc_ops;
3598+static struct omap_hwmod_soc_ops soc_ops __read_only;
3599
3600 /* omap_hwmod_list contains all registered struct omap_hwmods */
3601 static LIST_HEAD(omap_hwmod_list);
3602diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3603index d15c7bb..b2d1f0c 100644
3604--- a/arch/arm/mach-omap2/wd_timer.c
3605+++ b/arch/arm/mach-omap2/wd_timer.c
3606@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3607 struct omap_hwmod *oh;
3608 char *oh_name = "wd_timer2";
3609 char *dev_name = "omap_wdt";
3610- struct omap_wd_timer_platform_data pdata;
3611+ static struct omap_wd_timer_platform_data pdata = {
3612+ .read_reset_sources = prm_read_reset_sources
3613+ };
3614
3615 if (!cpu_class_is_omap2() || of_have_populated_dt())
3616 return 0;
3617@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3618 return -EINVAL;
3619 }
3620
3621- pdata.read_reset_sources = prm_read_reset_sources;
3622-
3623 pdev = omap_device_build(dev_name, id, oh, &pdata,
3624 sizeof(struct omap_wd_timer_platform_data));
3625 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3626diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3627index 706aa42..f85e9131 100644
3628--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3629+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3630@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3631 bool entered_lp2 = false;
3632
3633 if (tegra_pending_sgi())
3634- ACCESS_ONCE(abort_flag) = true;
3635+ ACCESS_ONCE_RW(abort_flag) = true;
3636
3637 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3638
3639diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3640index cad3ca86..1d79e0f 100644
3641--- a/arch/arm/mach-ux500/setup.h
3642+++ b/arch/arm/mach-ux500/setup.h
3643@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3644 .type = MT_DEVICE, \
3645 }
3646
3647-#define __MEM_DEV_DESC(x, sz) { \
3648- .virtual = IO_ADDRESS(x), \
3649- .pfn = __phys_to_pfn(x), \
3650- .length = sz, \
3651- .type = MT_MEMORY, \
3652-}
3653-
3654 extern struct smp_operations ux500_smp_ops;
3655 extern void ux500_cpu_die(unsigned int cpu);
3656
3657diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3658index cd2c88e..7430282 100644
3659--- a/arch/arm/mm/Kconfig
3660+++ b/arch/arm/mm/Kconfig
3661@@ -446,7 +446,7 @@ config CPU_32v5
3662
3663 config CPU_32v6
3664 bool
3665- select CPU_USE_DOMAINS if CPU_V6 && MMU
3666+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3667 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3668
3669 config CPU_32v6K
3670@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3671
3672 config CPU_USE_DOMAINS
3673 bool
3674+ depends on !ARM_LPAE && !PAX_KERNEXEC
3675 help
3676 This option enables or disables the use of domain switching
3677 via the set_fs() function.
3678@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3679 config KUSER_HELPERS
3680 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3681 default y
3682+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3683 help
3684 Warning: disabling this option may break user programs.
3685
3686@@ -812,7 +814,7 @@ config KUSER_HELPERS
3687 See Documentation/arm/kernel_user_helpers.txt for details.
3688
3689 However, the fixed address nature of these helpers can be used
3690- by ROP (return orientated programming) authors when creating
3691+ by ROP (Return Oriented Programming) authors when creating
3692 exploits.
3693
3694 If all of the binaries and libraries which run on your platform
3695diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3696index 6f4585b..7b6f52b 100644
3697--- a/arch/arm/mm/alignment.c
3698+++ b/arch/arm/mm/alignment.c
3699@@ -211,10 +211,12 @@ union offset_union {
3700 #define __get16_unaligned_check(ins,val,addr) \
3701 do { \
3702 unsigned int err = 0, v, a = addr; \
3703+ pax_open_userland(); \
3704 __get8_unaligned_check(ins,v,a,err); \
3705 val = v << ((BE) ? 8 : 0); \
3706 __get8_unaligned_check(ins,v,a,err); \
3707 val |= v << ((BE) ? 0 : 8); \
3708+ pax_close_userland(); \
3709 if (err) \
3710 goto fault; \
3711 } while (0)
3712@@ -228,6 +230,7 @@ union offset_union {
3713 #define __get32_unaligned_check(ins,val,addr) \
3714 do { \
3715 unsigned int err = 0, v, a = addr; \
3716+ pax_open_userland(); \
3717 __get8_unaligned_check(ins,v,a,err); \
3718 val = v << ((BE) ? 24 : 0); \
3719 __get8_unaligned_check(ins,v,a,err); \
3720@@ -236,6 +239,7 @@ union offset_union {
3721 val |= v << ((BE) ? 8 : 16); \
3722 __get8_unaligned_check(ins,v,a,err); \
3723 val |= v << ((BE) ? 0 : 24); \
3724+ pax_close_userland(); \
3725 if (err) \
3726 goto fault; \
3727 } while (0)
3728@@ -249,6 +253,7 @@ union offset_union {
3729 #define __put16_unaligned_check(ins,val,addr) \
3730 do { \
3731 unsigned int err = 0, v = val, a = addr; \
3732+ pax_open_userland(); \
3733 __asm__( FIRST_BYTE_16 \
3734 ARM( "1: "ins" %1, [%2], #1\n" ) \
3735 THUMB( "1: "ins" %1, [%2]\n" ) \
3736@@ -268,6 +273,7 @@ union offset_union {
3737 " .popsection\n" \
3738 : "=r" (err), "=&r" (v), "=&r" (a) \
3739 : "0" (err), "1" (v), "2" (a)); \
3740+ pax_close_userland(); \
3741 if (err) \
3742 goto fault; \
3743 } while (0)
3744@@ -281,6 +287,7 @@ union offset_union {
3745 #define __put32_unaligned_check(ins,val,addr) \
3746 do { \
3747 unsigned int err = 0, v = val, a = addr; \
3748+ pax_open_userland(); \
3749 __asm__( FIRST_BYTE_32 \
3750 ARM( "1: "ins" %1, [%2], #1\n" ) \
3751 THUMB( "1: "ins" %1, [%2]\n" ) \
3752@@ -310,6 +317,7 @@ union offset_union {
3753 " .popsection\n" \
3754 : "=r" (err), "=&r" (v), "=&r" (a) \
3755 : "0" (err), "1" (v), "2" (a)); \
3756+ pax_close_userland(); \
3757 if (err) \
3758 goto fault; \
3759 } while (0)
3760diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3761index 4a05444..d21968c 100644
3762--- a/arch/arm/mm/context.c
3763+++ b/arch/arm/mm/context.c
3764@@ -43,7 +43,7 @@
3765 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3766
3767 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3768-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3769+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3770 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3771
3772 static DEFINE_PER_CPU(atomic64_t, active_asids);
3773@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3774 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3775 {
3776 u64 asid = atomic64_read(&mm->context.id);
3777- u64 generation = atomic64_read(&asid_generation);
3778+ u64 generation = atomic64_read_unchecked(&asid_generation);
3779
3780 if (asid != 0 && is_reserved_asid(asid)) {
3781 /*
3782@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3783 */
3784 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3785 if (asid == NUM_USER_ASIDS) {
3786- generation = atomic64_add_return(ASID_FIRST_VERSION,
3787+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3788 &asid_generation);
3789 flush_context(cpu);
3790 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3791@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3792 cpu_set_reserved_ttbr0();
3793
3794 asid = atomic64_read(&mm->context.id);
3795- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3796+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3797 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3798 goto switch_mm_fastpath;
3799
3800 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3801 /* Check that our ASID belongs to the current generation. */
3802 asid = atomic64_read(&mm->context.id);
3803- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3804+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3805 asid = new_context(mm, cpu);
3806 atomic64_set(&mm->context.id, asid);
3807 }
3808diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3809index c97f794..6461880 100644
3810--- a/arch/arm/mm/fault.c
3811+++ b/arch/arm/mm/fault.c
3812@@ -25,6 +25,7 @@
3813 #include <asm/system_misc.h>
3814 #include <asm/system_info.h>
3815 #include <asm/tlbflush.h>
3816+#include <asm/sections.h>
3817
3818 #include "fault.h"
3819
3820@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3821 if (fixup_exception(regs))
3822 return;
3823
3824+#ifdef CONFIG_PAX_KERNEXEC
3825+ if ((fsr & FSR_WRITE) &&
3826+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3827+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3828+ {
3829+ if (current->signal->curr_ip)
3830+ 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),
3831+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3832+ else
3833+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3834+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3835+ }
3836+#endif
3837+
3838 /*
3839 * No handler, we'll have to terminate things with extreme prejudice.
3840 */
3841@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3842 }
3843 #endif
3844
3845+#ifdef CONFIG_PAX_PAGEEXEC
3846+ if (fsr & FSR_LNX_PF) {
3847+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3848+ do_group_exit(SIGKILL);
3849+ }
3850+#endif
3851+
3852 tsk->thread.address = addr;
3853 tsk->thread.error_code = fsr;
3854 tsk->thread.trap_no = 14;
3855@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3856 }
3857 #endif /* CONFIG_MMU */
3858
3859+#ifdef CONFIG_PAX_PAGEEXEC
3860+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3861+{
3862+ long i;
3863+
3864+ printk(KERN_ERR "PAX: bytes at PC: ");
3865+ for (i = 0; i < 20; i++) {
3866+ unsigned char c;
3867+ if (get_user(c, (__force unsigned char __user *)pc+i))
3868+ printk(KERN_CONT "?? ");
3869+ else
3870+ printk(KERN_CONT "%02x ", c);
3871+ }
3872+ printk("\n");
3873+
3874+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3875+ for (i = -1; i < 20; i++) {
3876+ unsigned long c;
3877+ if (get_user(c, (__force unsigned long __user *)sp+i))
3878+ printk(KERN_CONT "???????? ");
3879+ else
3880+ printk(KERN_CONT "%08lx ", c);
3881+ }
3882+ printk("\n");
3883+}
3884+#endif
3885+
3886 /*
3887 * First Level Translation Fault Handler
3888 *
3889@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3890 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3891 struct siginfo info;
3892
3893+#ifdef CONFIG_PAX_MEMORY_UDEREF
3894+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3895+ if (current->signal->curr_ip)
3896+ 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),
3897+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3898+ else
3899+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3900+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3901+ goto die;
3902+ }
3903+#endif
3904+
3905 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3906 return;
3907
3908+die:
3909 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3910 inf->name, fsr, addr);
3911
3912@@ -571,15 +633,92 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3913 ifsr_info[nr].name = name;
3914 }
3915
3916+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3917+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3918+
3919 asmlinkage void __exception
3920 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3921 {
3922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3923 struct siginfo info;
3924+ unsigned long pc = instruction_pointer(regs);
3925+
3926+ if (user_mode(regs)) {
3927+ unsigned long sigpage = current->mm->context.sigpage;
3928+
3929+ if (sigpage <= pc && pc < sigpage + 7*4) {
3930+ if (pc < sigpage + 3*4)
3931+ sys_sigreturn(regs);
3932+ else
3933+ sys_rt_sigreturn(regs);
3934+ return;
3935+ }
3936+ if (pc == 0xffff0f60UL) {
3937+ /*
3938+ * PaX: __kuser_cmpxchg64 emulation
3939+ */
3940+ // TODO
3941+ //regs->ARM_pc = regs->ARM_lr;
3942+ //return;
3943+ }
3944+ if (pc == 0xffff0fa0UL) {
3945+ /*
3946+ * PaX: __kuser_memory_barrier emulation
3947+ */
3948+ // dmb(); implied by the exception
3949+ regs->ARM_pc = regs->ARM_lr;
3950+ return;
3951+ }
3952+ if (pc == 0xffff0fc0UL) {
3953+ /*
3954+ * PaX: __kuser_cmpxchg emulation
3955+ */
3956+ // TODO
3957+ //regs->ARM_pc = regs->ARM_lr;
3958+ //return;
3959+ }
3960+ if (pc == 0xffff0fe0UL) {
3961+ /*
3962+ * PaX: __kuser_get_tls emulation
3963+ */
3964+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3965+ regs->ARM_pc = regs->ARM_lr;
3966+ return;
3967+ }
3968+ }
3969+
3970+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3971+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3972+ if (current->signal->curr_ip)
3973+ 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),
3974+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3975+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3976+ else
3977+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3978+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3979+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3980+ goto die;
3981+ }
3982+#endif
3983+
3984+#ifdef CONFIG_PAX_REFCOUNT
3985+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3986+ unsigned int bkpt;
3987+
3988+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3989+ current->thread.error_code = ifsr;
3990+ current->thread.trap_no = 0;
3991+ pax_report_refcount_overflow(regs);
3992+ fixup_exception(regs);
3993+ return;
3994+ }
3995+ }
3996+#endif
3997
3998 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3999 return;
4000
4001+die:
4002 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4003 inf->name, ifsr, addr);
4004
4005diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4006index cf08bdf..772656c 100644
4007--- a/arch/arm/mm/fault.h
4008+++ b/arch/arm/mm/fault.h
4009@@ -3,6 +3,7 @@
4010
4011 /*
4012 * Fault status register encodings. We steal bit 31 for our own purposes.
4013+ * Set when the FSR value is from an instruction fault.
4014 */
4015 #define FSR_LNX_PF (1 << 31)
4016 #define FSR_WRITE (1 << 11)
4017@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4018 }
4019 #endif
4020
4021+/* valid for LPAE and !LPAE */
4022+static inline int is_xn_fault(unsigned int fsr)
4023+{
4024+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4025+}
4026+
4027+static inline int is_domain_fault(unsigned int fsr)
4028+{
4029+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4030+}
4031+
4032 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4033 unsigned long search_exception_table(unsigned long addr);
4034
4035diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4036index 15225d8..25e2e3c 100644
4037--- a/arch/arm/mm/init.c
4038+++ b/arch/arm/mm/init.c
4039@@ -30,6 +30,8 @@
4040 #include <asm/setup.h>
4041 #include <asm/tlb.h>
4042 #include <asm/fixmap.h>
4043+#include <asm/system_info.h>
4044+#include <asm/cp15.h>
4045
4046 #include <asm/mach/arch.h>
4047 #include <asm/mach/map.h>
4048@@ -683,7 +685,46 @@ void free_initmem(void)
4049 {
4050 #ifdef CONFIG_HAVE_TCM
4051 extern char __tcm_start, __tcm_end;
4052+#endif
4053
4054+#ifdef CONFIG_PAX_KERNEXEC
4055+ unsigned long addr;
4056+ pgd_t *pgd;
4057+ pud_t *pud;
4058+ pmd_t *pmd;
4059+ int cpu_arch = cpu_architecture();
4060+ unsigned int cr = get_cr();
4061+
4062+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4063+ /* make pages tables, etc before .text NX */
4064+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4065+ pgd = pgd_offset_k(addr);
4066+ pud = pud_offset(pgd, addr);
4067+ pmd = pmd_offset(pud, addr);
4068+ __section_update(pmd, addr, PMD_SECT_XN);
4069+ }
4070+ /* make init NX */
4071+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4072+ pgd = pgd_offset_k(addr);
4073+ pud = pud_offset(pgd, addr);
4074+ pmd = pmd_offset(pud, addr);
4075+ __section_update(pmd, addr, PMD_SECT_XN);
4076+ }
4077+ /* make kernel code/rodata RX */
4078+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4079+ pgd = pgd_offset_k(addr);
4080+ pud = pud_offset(pgd, addr);
4081+ pmd = pmd_offset(pud, addr);
4082+#ifdef CONFIG_ARM_LPAE
4083+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4084+#else
4085+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4086+#endif
4087+ }
4088+ }
4089+#endif
4090+
4091+#ifdef CONFIG_HAVE_TCM
4092 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4093 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4094 #endif
4095diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4096index f123d6e..04bf569 100644
4097--- a/arch/arm/mm/ioremap.c
4098+++ b/arch/arm/mm/ioremap.c
4099@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4100 unsigned int mtype;
4101
4102 if (cached)
4103- mtype = MT_MEMORY;
4104+ mtype = MT_MEMORY_RX;
4105 else
4106- mtype = MT_MEMORY_NONCACHED;
4107+ mtype = MT_MEMORY_NONCACHED_RX;
4108
4109 return __arm_ioremap_caller(phys_addr, size, mtype,
4110 __builtin_return_address(0));
4111diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4112index 0c63562..7128a90 100644
4113--- a/arch/arm/mm/mmap.c
4114+++ b/arch/arm/mm/mmap.c
4115@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4116 struct vm_area_struct *vma;
4117 int do_align = 0;
4118 int aliasing = cache_is_vipt_aliasing();
4119+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4120 struct vm_unmapped_area_info info;
4121
4122 /*
4123@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4124 if (len > TASK_SIZE)
4125 return -ENOMEM;
4126
4127+#ifdef CONFIG_PAX_RANDMMAP
4128+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4129+#endif
4130+
4131 if (addr) {
4132 if (do_align)
4133 addr = COLOUR_ALIGN(addr, pgoff);
4134@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4135 addr = PAGE_ALIGN(addr);
4136
4137 vma = find_vma(mm, addr);
4138- if (TASK_SIZE - len >= addr &&
4139- (!vma || addr + len <= vma->vm_start))
4140+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4141 return addr;
4142 }
4143
4144@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4145 info.high_limit = TASK_SIZE;
4146 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4147 info.align_offset = pgoff << PAGE_SHIFT;
4148+ info.threadstack_offset = offset;
4149 return vm_unmapped_area(&info);
4150 }
4151
4152@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4153 unsigned long addr = addr0;
4154 int do_align = 0;
4155 int aliasing = cache_is_vipt_aliasing();
4156+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4157 struct vm_unmapped_area_info info;
4158
4159 /*
4160@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4161 return addr;
4162 }
4163
4164+#ifdef CONFIG_PAX_RANDMMAP
4165+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4166+#endif
4167+
4168 /* requesting a specific address */
4169 if (addr) {
4170 if (do_align)
4171@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4172 else
4173 addr = PAGE_ALIGN(addr);
4174 vma = find_vma(mm, addr);
4175- if (TASK_SIZE - len >= addr &&
4176- (!vma || addr + len <= vma->vm_start))
4177+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4178 return addr;
4179 }
4180
4181@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4182 info.high_limit = mm->mmap_base;
4183 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4184 info.align_offset = pgoff << PAGE_SHIFT;
4185+ info.threadstack_offset = offset;
4186 addr = vm_unmapped_area(&info);
4187
4188 /*
4189@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4190 {
4191 unsigned long random_factor = 0UL;
4192
4193+#ifdef CONFIG_PAX_RANDMMAP
4194+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4195+#endif
4196+
4197 /* 8 bits of randomness in 20 address space bits */
4198 if ((current->flags & PF_RANDOMIZE) &&
4199 !(current->personality & ADDR_NO_RANDOMIZE))
4200@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4201
4202 if (mmap_is_legacy()) {
4203 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4204+
4205+#ifdef CONFIG_PAX_RANDMMAP
4206+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4207+ mm->mmap_base += mm->delta_mmap;
4208+#endif
4209+
4210 mm->get_unmapped_area = arch_get_unmapped_area;
4211 } else {
4212 mm->mmap_base = mmap_base(random_factor);
4213+
4214+#ifdef CONFIG_PAX_RANDMMAP
4215+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4216+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4217+#endif
4218+
4219 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4220 }
4221 }
4222diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4223index 53cdbd3..670f177 100644
4224--- a/arch/arm/mm/mmu.c
4225+++ b/arch/arm/mm/mmu.c
4226@@ -36,6 +36,22 @@
4227 #include "mm.h"
4228 #include "tcm.h"
4229
4230+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4231+void modify_domain(unsigned int dom, unsigned int type)
4232+{
4233+ struct thread_info *thread = current_thread_info();
4234+ unsigned int domain = thread->cpu_domain;
4235+ /*
4236+ * DOMAIN_MANAGER might be defined to some other value,
4237+ * use the arch-defined constant
4238+ */
4239+ domain &= ~domain_val(dom, 3);
4240+ thread->cpu_domain = domain | domain_val(dom, type);
4241+ set_domain(thread->cpu_domain);
4242+}
4243+EXPORT_SYMBOL(modify_domain);
4244+#endif
4245+
4246 /*
4247 * empty_zero_page is a special page that is used for
4248 * zero-initialized data and COW.
4249@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4250
4251 #endif /* ifdef CONFIG_CPU_CP15 / else */
4252
4253-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4254+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4255 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4256
4257-static struct mem_type mem_types[] = {
4258+#ifdef CONFIG_PAX_KERNEXEC
4259+#define L_PTE_KERNEXEC L_PTE_RDONLY
4260+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4261+#else
4262+#define L_PTE_KERNEXEC L_PTE_DIRTY
4263+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4264+#endif
4265+
4266+static struct mem_type mem_types[] __read_only = {
4267 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4268 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4269 L_PTE_SHARED,
4270@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4271 [MT_UNCACHED] = {
4272 .prot_pte = PROT_PTE_DEVICE,
4273 .prot_l1 = PMD_TYPE_TABLE,
4274- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4275+ .prot_sect = PROT_SECT_DEVICE,
4276 .domain = DOMAIN_IO,
4277 },
4278 [MT_CACHECLEAN] = {
4279- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4280+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4281 .domain = DOMAIN_KERNEL,
4282 },
4283 #ifndef CONFIG_ARM_LPAE
4284 [MT_MINICLEAN] = {
4285- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4286+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4287 .domain = DOMAIN_KERNEL,
4288 },
4289 #endif
4290@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4291 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4292 L_PTE_RDONLY,
4293 .prot_l1 = PMD_TYPE_TABLE,
4294- .domain = DOMAIN_USER,
4295+ .domain = DOMAIN_VECTORS,
4296 },
4297 [MT_HIGH_VECTORS] = {
4298 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4299 L_PTE_USER | L_PTE_RDONLY,
4300 .prot_l1 = PMD_TYPE_TABLE,
4301- .domain = DOMAIN_USER,
4302+ .domain = DOMAIN_VECTORS,
4303 },
4304- [MT_MEMORY] = {
4305+ [MT_MEMORY_RWX] = {
4306 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4307 .prot_l1 = PMD_TYPE_TABLE,
4308 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4309 .domain = DOMAIN_KERNEL,
4310 },
4311+ [MT_MEMORY_RW] = {
4312+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4313+ .prot_l1 = PMD_TYPE_TABLE,
4314+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4315+ .domain = DOMAIN_KERNEL,
4316+ },
4317+ [MT_MEMORY_RX] = {
4318+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4319+ .prot_l1 = PMD_TYPE_TABLE,
4320+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4321+ .domain = DOMAIN_KERNEL,
4322+ },
4323 [MT_ROM] = {
4324- .prot_sect = PMD_TYPE_SECT,
4325+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4326 .domain = DOMAIN_KERNEL,
4327 },
4328- [MT_MEMORY_NONCACHED] = {
4329+ [MT_MEMORY_NONCACHED_RW] = {
4330 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4331 L_PTE_MT_BUFFERABLE,
4332 .prot_l1 = PMD_TYPE_TABLE,
4333 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4334 .domain = DOMAIN_KERNEL,
4335 },
4336+ [MT_MEMORY_NONCACHED_RX] = {
4337+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4338+ L_PTE_MT_BUFFERABLE,
4339+ .prot_l1 = PMD_TYPE_TABLE,
4340+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4341+ .domain = DOMAIN_KERNEL,
4342+ },
4343 [MT_MEMORY_DTCM] = {
4344- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4345- L_PTE_XN,
4346+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4347 .prot_l1 = PMD_TYPE_TABLE,
4348- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4349+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4350 .domain = DOMAIN_KERNEL,
4351 },
4352 [MT_MEMORY_ITCM] = {
4353@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4354 },
4355 [MT_MEMORY_SO] = {
4356 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357- L_PTE_MT_UNCACHED | L_PTE_XN,
4358+ L_PTE_MT_UNCACHED,
4359 .prot_l1 = PMD_TYPE_TABLE,
4360 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4361- PMD_SECT_UNCACHED | PMD_SECT_XN,
4362+ PMD_SECT_UNCACHED,
4363 .domain = DOMAIN_KERNEL,
4364 },
4365 [MT_MEMORY_DMA_READY] = {
4366@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4367 * to prevent speculative instruction fetches.
4368 */
4369 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4370+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4371 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4372+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4373 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4374+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4375 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4376+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4377+
4378+ /* Mark other regions on ARMv6+ as execute-never */
4379+
4380+#ifdef CONFIG_PAX_KERNEXEC
4381+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4382+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4383+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4384+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4385+#ifndef CONFIG_ARM_LPAE
4386+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4387+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4388+#endif
4389+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4390+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4391+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4392+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4393+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4394+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4395+#endif
4396+
4397+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4398+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4399 }
4400 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4401 /*
4402@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4403 * from SVC mode and no access from userspace.
4404 */
4405 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4406+#ifdef CONFIG_PAX_KERNEXEC
4407+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4408+#endif
4409 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4410 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4411 #endif
4412@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4413 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4414 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4415 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4416- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4417- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4418+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4419+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4420+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4421+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4422+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4423+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4424 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4425- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4426- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4427+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4428+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4429+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4430+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4431 }
4432 }
4433
4434@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4435 if (cpu_arch >= CPU_ARCH_ARMv6) {
4436 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4437 /* Non-cacheable Normal is XCB = 001 */
4438- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4439+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4440+ PMD_SECT_BUFFERED;
4441+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4442 PMD_SECT_BUFFERED;
4443 } else {
4444 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4445- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4446+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4447+ PMD_SECT_TEX(1);
4448+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4449 PMD_SECT_TEX(1);
4450 }
4451 } else {
4452- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4453+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4454+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4455 }
4456
4457 #ifdef CONFIG_ARM_LPAE
4458@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4459 vecs_pgprot |= PTE_EXT_AF;
4460 #endif
4461
4462+ user_pgprot |= __supported_pte_mask;
4463+
4464 for (i = 0; i < 16; i++) {
4465 pteval_t v = pgprot_val(protection_map[i]);
4466 protection_map[i] = __pgprot(v | user_pgprot);
4467@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4468
4469 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4470 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4471- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4472- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4473+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4474+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4475+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4476+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4477+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4478+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4479 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4480- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4481+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4482+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4483 mem_types[MT_ROM].prot_sect |= cp->pmd;
4484
4485 switch (cp->pmd) {
4486@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4487 * called function. This means you can't use any function or debugging
4488 * method which may touch any device, otherwise the kernel _will_ crash.
4489 */
4490+
4491+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4492+
4493 static void __init devicemaps_init(struct machine_desc *mdesc)
4494 {
4495 struct map_desc map;
4496 unsigned long addr;
4497- void *vectors;
4498
4499- /*
4500- * Allocate the vector page early.
4501- */
4502- vectors = early_alloc(PAGE_SIZE * 2);
4503-
4504- early_trap_init(vectors);
4505+ early_trap_init(&vectors);
4506
4507 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4508 pmd_clear(pmd_off_k(addr));
4509@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4510 * location (0xffff0000). If we aren't using high-vectors, also
4511 * create a mapping at the low-vectors virtual address.
4512 */
4513- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4514+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4515 map.virtual = 0xffff0000;
4516 map.length = PAGE_SIZE;
4517 #ifdef CONFIG_KUSER_HELPERS
4518@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4519 map.pfn = __phys_to_pfn(start);
4520 map.virtual = __phys_to_virt(start);
4521 map.length = end - start;
4522- map.type = MT_MEMORY;
4523
4524+#ifdef CONFIG_PAX_KERNEXEC
4525+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4526+ struct map_desc kernel;
4527+ struct map_desc initmap;
4528+
4529+ /* when freeing initmem we will make this RW */
4530+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4531+ initmap.virtual = (unsigned long)__init_begin;
4532+ initmap.length = _sdata - __init_begin;
4533+ initmap.type = MT_MEMORY_RWX;
4534+ create_mapping(&initmap);
4535+
4536+ /* when freeing initmem we will make this RX */
4537+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4538+ kernel.virtual = (unsigned long)_stext;
4539+ kernel.length = __init_begin - _stext;
4540+ kernel.type = MT_MEMORY_RWX;
4541+ create_mapping(&kernel);
4542+
4543+ if (map.virtual < (unsigned long)_stext) {
4544+ map.length = (unsigned long)_stext - map.virtual;
4545+ map.type = MT_MEMORY_RWX;
4546+ create_mapping(&map);
4547+ }
4548+
4549+ map.pfn = __phys_to_pfn(__pa(_sdata));
4550+ map.virtual = (unsigned long)_sdata;
4551+ map.length = end - __pa(_sdata);
4552+ }
4553+#endif
4554+
4555+ map.type = MT_MEMORY_RW;
4556 create_mapping(&map);
4557 }
4558 }
4559diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4560index a5bc92d..0bb4730 100644
4561--- a/arch/arm/plat-omap/sram.c
4562+++ b/arch/arm/plat-omap/sram.c
4563@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4564 * Looks like we need to preserve some bootloader code at the
4565 * beginning of SRAM for jumping to flash for reboot to work...
4566 */
4567+ pax_open_kernel();
4568 memset_io(omap_sram_base + omap_sram_skip, 0,
4569 omap_sram_size - omap_sram_skip);
4570+ pax_close_kernel();
4571 }
4572diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4573index ce6d763..cfea917 100644
4574--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4575+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4576@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4577 int (*started)(unsigned ch);
4578 int (*flush)(unsigned ch);
4579 int (*stop)(unsigned ch);
4580-};
4581+} __no_const;
4582
4583 extern void *samsung_dmadev_get_ops(void);
4584 extern void *s3c_dma_get_ops(void);
4585diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4586index c3a58a1..78fbf54 100644
4587--- a/arch/avr32/include/asm/cache.h
4588+++ b/arch/avr32/include/asm/cache.h
4589@@ -1,8 +1,10 @@
4590 #ifndef __ASM_AVR32_CACHE_H
4591 #define __ASM_AVR32_CACHE_H
4592
4593+#include <linux/const.h>
4594+
4595 #define L1_CACHE_SHIFT 5
4596-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4597+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4598
4599 /*
4600 * Memory returned by kmalloc() may be used for DMA, so we must make
4601diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4602index d232888..87c8df1 100644
4603--- a/arch/avr32/include/asm/elf.h
4604+++ b/arch/avr32/include/asm/elf.h
4605@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4606 the loader. We need to make sure that it is out of the way of the program
4607 that it will "exec", and that there is sufficient room for the brk. */
4608
4609-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4610+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4611
4612+#ifdef CONFIG_PAX_ASLR
4613+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4614+
4615+#define PAX_DELTA_MMAP_LEN 15
4616+#define PAX_DELTA_STACK_LEN 15
4617+#endif
4618
4619 /* This yields a mask that user programs can use to figure out what
4620 instruction set this CPU supports. This could be done in user space,
4621diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4622index 479330b..53717a8 100644
4623--- a/arch/avr32/include/asm/kmap_types.h
4624+++ b/arch/avr32/include/asm/kmap_types.h
4625@@ -2,9 +2,9 @@
4626 #define __ASM_AVR32_KMAP_TYPES_H
4627
4628 #ifdef CONFIG_DEBUG_HIGHMEM
4629-# define KM_TYPE_NR 29
4630+# define KM_TYPE_NR 30
4631 #else
4632-# define KM_TYPE_NR 14
4633+# define KM_TYPE_NR 15
4634 #endif
4635
4636 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4637diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4638index b2f2d2d..d1c85cb 100644
4639--- a/arch/avr32/mm/fault.c
4640+++ b/arch/avr32/mm/fault.c
4641@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4642
4643 int exception_trace = 1;
4644
4645+#ifdef CONFIG_PAX_PAGEEXEC
4646+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4647+{
4648+ unsigned long i;
4649+
4650+ printk(KERN_ERR "PAX: bytes at PC: ");
4651+ for (i = 0; i < 20; i++) {
4652+ unsigned char c;
4653+ if (get_user(c, (unsigned char *)pc+i))
4654+ printk(KERN_CONT "???????? ");
4655+ else
4656+ printk(KERN_CONT "%02x ", c);
4657+ }
4658+ printk("\n");
4659+}
4660+#endif
4661+
4662 /*
4663 * This routine handles page faults. It determines the address and the
4664 * problem, and then passes it off to one of the appropriate routines.
4665@@ -174,6 +191,16 @@ bad_area:
4666 up_read(&mm->mmap_sem);
4667
4668 if (user_mode(regs)) {
4669+
4670+#ifdef CONFIG_PAX_PAGEEXEC
4671+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4672+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4673+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4674+ do_group_exit(SIGKILL);
4675+ }
4676+ }
4677+#endif
4678+
4679 if (exception_trace && printk_ratelimit())
4680 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4681 "sp %08lx ecr %lu\n",
4682diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4683index 568885a..f8008df 100644
4684--- a/arch/blackfin/include/asm/cache.h
4685+++ b/arch/blackfin/include/asm/cache.h
4686@@ -7,6 +7,7 @@
4687 #ifndef __ARCH_BLACKFIN_CACHE_H
4688 #define __ARCH_BLACKFIN_CACHE_H
4689
4690+#include <linux/const.h>
4691 #include <linux/linkage.h> /* for asmlinkage */
4692
4693 /*
4694@@ -14,7 +15,7 @@
4695 * Blackfin loads 32 bytes for cache
4696 */
4697 #define L1_CACHE_SHIFT 5
4698-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4699+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4700 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4701
4702 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4703diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4704index aea2718..3639a60 100644
4705--- a/arch/cris/include/arch-v10/arch/cache.h
4706+++ b/arch/cris/include/arch-v10/arch/cache.h
4707@@ -1,8 +1,9 @@
4708 #ifndef _ASM_ARCH_CACHE_H
4709 #define _ASM_ARCH_CACHE_H
4710
4711+#include <linux/const.h>
4712 /* Etrax 100LX have 32-byte cache-lines. */
4713-#define L1_CACHE_BYTES 32
4714 #define L1_CACHE_SHIFT 5
4715+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4716
4717 #endif /* _ASM_ARCH_CACHE_H */
4718diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4719index 7caf25d..ee65ac5 100644
4720--- a/arch/cris/include/arch-v32/arch/cache.h
4721+++ b/arch/cris/include/arch-v32/arch/cache.h
4722@@ -1,11 +1,12 @@
4723 #ifndef _ASM_CRIS_ARCH_CACHE_H
4724 #define _ASM_CRIS_ARCH_CACHE_H
4725
4726+#include <linux/const.h>
4727 #include <arch/hwregs/dma.h>
4728
4729 /* A cache-line is 32 bytes. */
4730-#define L1_CACHE_BYTES 32
4731 #define L1_CACHE_SHIFT 5
4732+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4733
4734 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4735
4736diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4737index b86329d..6709906 100644
4738--- a/arch/frv/include/asm/atomic.h
4739+++ b/arch/frv/include/asm/atomic.h
4740@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4741 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4742 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4743
4744+#define atomic64_read_unchecked(v) atomic64_read(v)
4745+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4746+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4747+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4748+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4749+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4750+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4751+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4752+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4753+
4754 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4755 {
4756 int c, old;
4757diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4758index 2797163..c2a401d 100644
4759--- a/arch/frv/include/asm/cache.h
4760+++ b/arch/frv/include/asm/cache.h
4761@@ -12,10 +12,11 @@
4762 #ifndef __ASM_CACHE_H
4763 #define __ASM_CACHE_H
4764
4765+#include <linux/const.h>
4766
4767 /* bytes per L1 cache line */
4768 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4769-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4770+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4771
4772 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4773 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4774diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4775index 43901f2..0d8b865 100644
4776--- a/arch/frv/include/asm/kmap_types.h
4777+++ b/arch/frv/include/asm/kmap_types.h
4778@@ -2,6 +2,6 @@
4779 #ifndef _ASM_KMAP_TYPES_H
4780 #define _ASM_KMAP_TYPES_H
4781
4782-#define KM_TYPE_NR 17
4783+#define KM_TYPE_NR 18
4784
4785 #endif
4786diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4787index 836f147..4cf23f5 100644
4788--- a/arch/frv/mm/elf-fdpic.c
4789+++ b/arch/frv/mm/elf-fdpic.c
4790@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4791 {
4792 struct vm_area_struct *vma;
4793 struct vm_unmapped_area_info info;
4794+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4795
4796 if (len > TASK_SIZE)
4797 return -ENOMEM;
4798@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4799 if (addr) {
4800 addr = PAGE_ALIGN(addr);
4801 vma = find_vma(current->mm, addr);
4802- if (TASK_SIZE - len >= addr &&
4803- (!vma || addr + len <= vma->vm_start))
4804+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4805 goto success;
4806 }
4807
4808@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4809 info.high_limit = (current->mm->start_stack - 0x00200000);
4810 info.align_mask = 0;
4811 info.align_offset = 0;
4812+ info.threadstack_offset = offset;
4813 addr = vm_unmapped_area(&info);
4814 if (!(addr & ~PAGE_MASK))
4815 goto success;
4816diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4817index f4ca594..adc72fd6 100644
4818--- a/arch/hexagon/include/asm/cache.h
4819+++ b/arch/hexagon/include/asm/cache.h
4820@@ -21,9 +21,11 @@
4821 #ifndef __ASM_CACHE_H
4822 #define __ASM_CACHE_H
4823
4824+#include <linux/const.h>
4825+
4826 /* Bytes per L1 cache line */
4827-#define L1_CACHE_SHIFT (5)
4828-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4829+#define L1_CACHE_SHIFT 5
4830+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4831
4832 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4833 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4834diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4835index 6e6fe18..a6ae668 100644
4836--- a/arch/ia64/include/asm/atomic.h
4837+++ b/arch/ia64/include/asm/atomic.h
4838@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4839 #define atomic64_inc(v) atomic64_add(1, (v))
4840 #define atomic64_dec(v) atomic64_sub(1, (v))
4841
4842+#define atomic64_read_unchecked(v) atomic64_read(v)
4843+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4844+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4845+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4846+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4847+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4848+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4849+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4850+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4851+
4852 /* Atomic operations are already serializing */
4853 #define smp_mb__before_atomic_dec() barrier()
4854 #define smp_mb__after_atomic_dec() barrier()
4855diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4856index 988254a..e1ee885 100644
4857--- a/arch/ia64/include/asm/cache.h
4858+++ b/arch/ia64/include/asm/cache.h
4859@@ -1,6 +1,7 @@
4860 #ifndef _ASM_IA64_CACHE_H
4861 #define _ASM_IA64_CACHE_H
4862
4863+#include <linux/const.h>
4864
4865 /*
4866 * Copyright (C) 1998-2000 Hewlett-Packard Co
4867@@ -9,7 +10,7 @@
4868
4869 /* Bytes per L1 (data) cache line. */
4870 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4871-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4873
4874 #ifdef CONFIG_SMP
4875 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4876diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4877index 5a83c5c..4d7f553 100644
4878--- a/arch/ia64/include/asm/elf.h
4879+++ b/arch/ia64/include/asm/elf.h
4880@@ -42,6 +42,13 @@
4881 */
4882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4883
4884+#ifdef CONFIG_PAX_ASLR
4885+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4886+
4887+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4888+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4889+#endif
4890+
4891 #define PT_IA_64_UNWIND 0x70000001
4892
4893 /* IA-64 relocations: */
4894diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4895index 96a8d92..617a1cf 100644
4896--- a/arch/ia64/include/asm/pgalloc.h
4897+++ b/arch/ia64/include/asm/pgalloc.h
4898@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4899 pgd_val(*pgd_entry) = __pa(pud);
4900 }
4901
4902+static inline void
4903+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4904+{
4905+ pgd_populate(mm, pgd_entry, pud);
4906+}
4907+
4908 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4909 {
4910 return quicklist_alloc(0, GFP_KERNEL, NULL);
4911@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4912 pud_val(*pud_entry) = __pa(pmd);
4913 }
4914
4915+static inline void
4916+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4917+{
4918+ pud_populate(mm, pud_entry, pmd);
4919+}
4920+
4921 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4922 {
4923 return quicklist_alloc(0, GFP_KERNEL, NULL);
4924diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4925index 7935115..c0eca6a 100644
4926--- a/arch/ia64/include/asm/pgtable.h
4927+++ b/arch/ia64/include/asm/pgtable.h
4928@@ -12,7 +12,7 @@
4929 * David Mosberger-Tang <davidm@hpl.hp.com>
4930 */
4931
4932-
4933+#include <linux/const.h>
4934 #include <asm/mman.h>
4935 #include <asm/page.h>
4936 #include <asm/processor.h>
4937@@ -142,6 +142,17 @@
4938 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4939 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4940 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4941+
4942+#ifdef CONFIG_PAX_PAGEEXEC
4943+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4944+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4945+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4946+#else
4947+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4948+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4949+# define PAGE_COPY_NOEXEC PAGE_COPY
4950+#endif
4951+
4952 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4953 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4954 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4955diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4956index 54ff557..70c88b7 100644
4957--- a/arch/ia64/include/asm/spinlock.h
4958+++ b/arch/ia64/include/asm/spinlock.h
4959@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4960 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4961
4962 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4963- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4964+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4965 }
4966
4967 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4968diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4969index 449c8c0..18965fb 100644
4970--- a/arch/ia64/include/asm/uaccess.h
4971+++ b/arch/ia64/include/asm/uaccess.h
4972@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4973 static inline unsigned long
4974 __copy_to_user (void __user *to, const void *from, unsigned long count)
4975 {
4976+ if (count > INT_MAX)
4977+ return count;
4978+
4979+ if (!__builtin_constant_p(count))
4980+ check_object_size(from, count, true);
4981+
4982 return __copy_user(to, (__force void __user *) from, count);
4983 }
4984
4985 static inline unsigned long
4986 __copy_from_user (void *to, const void __user *from, unsigned long count)
4987 {
4988+ if (count > INT_MAX)
4989+ return count;
4990+
4991+ if (!__builtin_constant_p(count))
4992+ check_object_size(to, count, false);
4993+
4994 return __copy_user((__force void __user *) to, from, count);
4995 }
4996
4997@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4998 ({ \
4999 void __user *__cu_to = (to); \
5000 const void *__cu_from = (from); \
5001- long __cu_len = (n); \
5002+ unsigned long __cu_len = (n); \
5003 \
5004- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5005+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5006+ if (!__builtin_constant_p(n)) \
5007+ check_object_size(__cu_from, __cu_len, true); \
5008 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5009+ } \
5010 __cu_len; \
5011 })
5012
5013@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5014 ({ \
5015 void *__cu_to = (to); \
5016 const void __user *__cu_from = (from); \
5017- long __cu_len = (n); \
5018+ unsigned long __cu_len = (n); \
5019 \
5020 __chk_user_ptr(__cu_from); \
5021- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5022+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5023+ if (!__builtin_constant_p(n)) \
5024+ check_object_size(__cu_to, __cu_len, false); \
5025 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5026+ } \
5027 __cu_len; \
5028 })
5029
5030diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5031index 24603be..948052d 100644
5032--- a/arch/ia64/kernel/module.c
5033+++ b/arch/ia64/kernel/module.c
5034@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5035 void
5036 module_free (struct module *mod, void *module_region)
5037 {
5038- if (mod && mod->arch.init_unw_table &&
5039- module_region == mod->module_init) {
5040+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5041 unw_remove_unwind_table(mod->arch.init_unw_table);
5042 mod->arch.init_unw_table = NULL;
5043 }
5044@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5045 }
5046
5047 static inline int
5048+in_init_rx (const struct module *mod, uint64_t addr)
5049+{
5050+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5051+}
5052+
5053+static inline int
5054+in_init_rw (const struct module *mod, uint64_t addr)
5055+{
5056+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5057+}
5058+
5059+static inline int
5060 in_init (const struct module *mod, uint64_t addr)
5061 {
5062- return addr - (uint64_t) mod->module_init < mod->init_size;
5063+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5064+}
5065+
5066+static inline int
5067+in_core_rx (const struct module *mod, uint64_t addr)
5068+{
5069+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5070+}
5071+
5072+static inline int
5073+in_core_rw (const struct module *mod, uint64_t addr)
5074+{
5075+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5076 }
5077
5078 static inline int
5079 in_core (const struct module *mod, uint64_t addr)
5080 {
5081- return addr - (uint64_t) mod->module_core < mod->core_size;
5082+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5083 }
5084
5085 static inline int
5086@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5087 break;
5088
5089 case RV_BDREL:
5090- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5091+ if (in_init_rx(mod, val))
5092+ val -= (uint64_t) mod->module_init_rx;
5093+ else if (in_init_rw(mod, val))
5094+ val -= (uint64_t) mod->module_init_rw;
5095+ else if (in_core_rx(mod, val))
5096+ val -= (uint64_t) mod->module_core_rx;
5097+ else if (in_core_rw(mod, val))
5098+ val -= (uint64_t) mod->module_core_rw;
5099 break;
5100
5101 case RV_LTV:
5102@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5103 * addresses have been selected...
5104 */
5105 uint64_t gp;
5106- if (mod->core_size > MAX_LTOFF)
5107+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5108 /*
5109 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5110 * at the end of the module.
5111 */
5112- gp = mod->core_size - MAX_LTOFF / 2;
5113+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5114 else
5115- gp = mod->core_size / 2;
5116- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5117+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5118+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5119 mod->arch.gp = gp;
5120 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5121 }
5122diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5123index ab33328..f39506c 100644
5124--- a/arch/ia64/kernel/palinfo.c
5125+++ b/arch/ia64/kernel/palinfo.c
5126@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5127 return NOTIFY_OK;
5128 }
5129
5130-static struct notifier_block __refdata palinfo_cpu_notifier =
5131+static struct notifier_block palinfo_cpu_notifier =
5132 {
5133 .notifier_call = palinfo_cpu_callback,
5134 .priority = 0,
5135diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5136index 41e33f8..65180b2 100644
5137--- a/arch/ia64/kernel/sys_ia64.c
5138+++ b/arch/ia64/kernel/sys_ia64.c
5139@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5140 unsigned long align_mask = 0;
5141 struct mm_struct *mm = current->mm;
5142 struct vm_unmapped_area_info info;
5143+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5144
5145 if (len > RGN_MAP_LIMIT)
5146 return -ENOMEM;
5147@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5148 if (REGION_NUMBER(addr) == RGN_HPAGE)
5149 addr = 0;
5150 #endif
5151+
5152+#ifdef CONFIG_PAX_RANDMMAP
5153+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5154+ addr = mm->free_area_cache;
5155+ else
5156+#endif
5157+
5158 if (!addr)
5159 addr = TASK_UNMAPPED_BASE;
5160
5161@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5162 info.high_limit = TASK_SIZE;
5163 info.align_mask = align_mask;
5164 info.align_offset = 0;
5165+ info.threadstack_offset = offset;
5166 return vm_unmapped_area(&info);
5167 }
5168
5169diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5170index 0ccb28f..8992469 100644
5171--- a/arch/ia64/kernel/vmlinux.lds.S
5172+++ b/arch/ia64/kernel/vmlinux.lds.S
5173@@ -198,7 +198,7 @@ SECTIONS {
5174 /* Per-cpu data: */
5175 . = ALIGN(PERCPU_PAGE_SIZE);
5176 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5177- __phys_per_cpu_start = __per_cpu_load;
5178+ __phys_per_cpu_start = per_cpu_load;
5179 /*
5180 * ensure percpu data fits
5181 * into percpu page size
5182diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5183index 6cf0341..d352594 100644
5184--- a/arch/ia64/mm/fault.c
5185+++ b/arch/ia64/mm/fault.c
5186@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5187 return pte_present(pte);
5188 }
5189
5190+#ifdef CONFIG_PAX_PAGEEXEC
5191+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5192+{
5193+ unsigned long i;
5194+
5195+ printk(KERN_ERR "PAX: bytes at PC: ");
5196+ for (i = 0; i < 8; i++) {
5197+ unsigned int c;
5198+ if (get_user(c, (unsigned int *)pc+i))
5199+ printk(KERN_CONT "???????? ");
5200+ else
5201+ printk(KERN_CONT "%08x ", c);
5202+ }
5203+ printk("\n");
5204+}
5205+#endif
5206+
5207 # define VM_READ_BIT 0
5208 # define VM_WRITE_BIT 1
5209 # define VM_EXEC_BIT 2
5210@@ -149,8 +166,21 @@ retry:
5211 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5212 goto bad_area;
5213
5214- if ((vma->vm_flags & mask) != mask)
5215+ if ((vma->vm_flags & mask) != mask) {
5216+
5217+#ifdef CONFIG_PAX_PAGEEXEC
5218+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5219+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5220+ goto bad_area;
5221+
5222+ up_read(&mm->mmap_sem);
5223+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5224+ do_group_exit(SIGKILL);
5225+ }
5226+#endif
5227+
5228 goto bad_area;
5229+ }
5230
5231 /*
5232 * If for any reason at all we couldn't handle the fault, make
5233diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5234index 76069c1..c2aa816 100644
5235--- a/arch/ia64/mm/hugetlbpage.c
5236+++ b/arch/ia64/mm/hugetlbpage.c
5237@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5238 unsigned long pgoff, unsigned long flags)
5239 {
5240 struct vm_unmapped_area_info info;
5241+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5242
5243 if (len > RGN_MAP_LIMIT)
5244 return -ENOMEM;
5245@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5246 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5247 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5248 info.align_offset = 0;
5249+ info.threadstack_offset = offset;
5250 return vm_unmapped_area(&info);
5251 }
5252
5253diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5254index b6f7f43..c04320d 100644
5255--- a/arch/ia64/mm/init.c
5256+++ b/arch/ia64/mm/init.c
5257@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5258 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5259 vma->vm_end = vma->vm_start + PAGE_SIZE;
5260 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5261+
5262+#ifdef CONFIG_PAX_PAGEEXEC
5263+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5264+ vma->vm_flags &= ~VM_EXEC;
5265+
5266+#ifdef CONFIG_PAX_MPROTECT
5267+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5268+ vma->vm_flags &= ~VM_MAYEXEC;
5269+#endif
5270+
5271+ }
5272+#endif
5273+
5274 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5275 down_write(&current->mm->mmap_sem);
5276 if (insert_vm_struct(current->mm, vma)) {
5277diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5278index 40b3ee9..8c2c112 100644
5279--- a/arch/m32r/include/asm/cache.h
5280+++ b/arch/m32r/include/asm/cache.h
5281@@ -1,8 +1,10 @@
5282 #ifndef _ASM_M32R_CACHE_H
5283 #define _ASM_M32R_CACHE_H
5284
5285+#include <linux/const.h>
5286+
5287 /* L1 cache line size */
5288 #define L1_CACHE_SHIFT 4
5289-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5290+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5291
5292 #endif /* _ASM_M32R_CACHE_H */
5293diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5294index 82abd15..d95ae5d 100644
5295--- a/arch/m32r/lib/usercopy.c
5296+++ b/arch/m32r/lib/usercopy.c
5297@@ -14,6 +14,9 @@
5298 unsigned long
5299 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5300 {
5301+ if ((long)n < 0)
5302+ return n;
5303+
5304 prefetch(from);
5305 if (access_ok(VERIFY_WRITE, to, n))
5306 __copy_user(to,from,n);
5307@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5308 unsigned long
5309 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5310 {
5311+ if ((long)n < 0)
5312+ return n;
5313+
5314 prefetchw(to);
5315 if (access_ok(VERIFY_READ, from, n))
5316 __copy_user_zeroing(to,from,n);
5317diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5318index 0395c51..5f26031 100644
5319--- a/arch/m68k/include/asm/cache.h
5320+++ b/arch/m68k/include/asm/cache.h
5321@@ -4,9 +4,11 @@
5322 #ifndef __ARCH_M68K_CACHE_H
5323 #define __ARCH_M68K_CACHE_H
5324
5325+#include <linux/const.h>
5326+
5327 /* bytes per L1 cache line */
5328 #define L1_CACHE_SHIFT 4
5329-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5330+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5331
5332 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5333
5334diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5335index 3c52fa6..11b2ad8 100644
5336--- a/arch/metag/mm/hugetlbpage.c
5337+++ b/arch/metag/mm/hugetlbpage.c
5338@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5339 info.high_limit = TASK_SIZE;
5340 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5341 info.align_offset = 0;
5342+ info.threadstack_offset = 0;
5343 return vm_unmapped_area(&info);
5344 }
5345
5346diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5347index 4efe96a..60e8699 100644
5348--- a/arch/microblaze/include/asm/cache.h
5349+++ b/arch/microblaze/include/asm/cache.h
5350@@ -13,11 +13,12 @@
5351 #ifndef _ASM_MICROBLAZE_CACHE_H
5352 #define _ASM_MICROBLAZE_CACHE_H
5353
5354+#include <linux/const.h>
5355 #include <asm/registers.h>
5356
5357 #define L1_CACHE_SHIFT 5
5358 /* word-granular cache in microblaze */
5359-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5360+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5361
5362 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5363
5364diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5365index 08b6079..8b554d2 100644
5366--- a/arch/mips/include/asm/atomic.h
5367+++ b/arch/mips/include/asm/atomic.h
5368@@ -21,15 +21,39 @@
5369 #include <asm/cmpxchg.h>
5370 #include <asm/war.h>
5371
5372+#ifdef CONFIG_GENERIC_ATOMIC64
5373+#include <asm-generic/atomic64.h>
5374+#endif
5375+
5376 #define ATOMIC_INIT(i) { (i) }
5377
5378+#ifdef CONFIG_64BIT
5379+#define _ASM_EXTABLE(from, to) \
5380+" .section __ex_table,\"a\"\n" \
5381+" .dword " #from ", " #to"\n" \
5382+" .previous\n"
5383+#else
5384+#define _ASM_EXTABLE(from, to) \
5385+" .section __ex_table,\"a\"\n" \
5386+" .word " #from ", " #to"\n" \
5387+" .previous\n"
5388+#endif
5389+
5390 /*
5391 * atomic_read - read atomic variable
5392 * @v: pointer of type atomic_t
5393 *
5394 * Atomically reads the value of @v.
5395 */
5396-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5397+static inline int atomic_read(const atomic_t *v)
5398+{
5399+ return (*(volatile const int *) &v->counter);
5400+}
5401+
5402+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5403+{
5404+ return (*(volatile const int *) &v->counter);
5405+}
5406
5407 /*
5408 * atomic_set - set atomic variable
5409@@ -38,7 +62,15 @@
5410 *
5411 * Atomically sets the value of @v to @i.
5412 */
5413-#define atomic_set(v, i) ((v)->counter = (i))
5414+static inline void atomic_set(atomic_t *v, int i)
5415+{
5416+ v->counter = i;
5417+}
5418+
5419+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5420+{
5421+ v->counter = i;
5422+}
5423
5424 /*
5425 * atomic_add - add integer to atomic variable
5426@@ -47,7 +79,67 @@
5427 *
5428 * Atomically adds @i to @v.
5429 */
5430-static __inline__ void atomic_add(int i, atomic_t * v)
5431+static __inline__ void atomic_add(int i, atomic_t *v)
5432+{
5433+ int temp;
5434+
5435+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5436+ __asm__ __volatile__(
5437+ " .set mips3 \n"
5438+ "1: ll %0, %1 # atomic_add \n"
5439+#ifdef CONFIG_PAX_REFCOUNT
5440+ /* Exception on overflow. */
5441+ "2: add %0, %2 \n"
5442+#else
5443+ " addu %0, %2 \n"
5444+#endif
5445+ " sc %0, %1 \n"
5446+ " beqzl %0, 1b \n"
5447+#ifdef CONFIG_PAX_REFCOUNT
5448+ "3: \n"
5449+ _ASM_EXTABLE(2b, 3b)
5450+#endif
5451+ " .set mips0 \n"
5452+ : "=&r" (temp), "+m" (v->counter)
5453+ : "Ir" (i));
5454+ } else if (kernel_uses_llsc) {
5455+ __asm__ __volatile__(
5456+ " .set mips3 \n"
5457+ "1: ll %0, %1 # atomic_add \n"
5458+#ifdef CONFIG_PAX_REFCOUNT
5459+ /* Exception on overflow. */
5460+ "2: add %0, %2 \n"
5461+#else
5462+ " addu %0, %2 \n"
5463+#endif
5464+ " sc %0, %1 \n"
5465+ " beqz %0, 1b \n"
5466+#ifdef CONFIG_PAX_REFCOUNT
5467+ "3: \n"
5468+ _ASM_EXTABLE(2b, 3b)
5469+#endif
5470+ " .set mips0 \n"
5471+ : "=&r" (temp), "+m" (v->counter)
5472+ : "Ir" (i));
5473+ } else {
5474+ unsigned long flags;
5475+
5476+ raw_local_irq_save(flags);
5477+ __asm__ __volatile__(
5478+#ifdef CONFIG_PAX_REFCOUNT
5479+ /* Exception on overflow. */
5480+ "1: add %0, %1 \n"
5481+ "2: \n"
5482+ _ASM_EXTABLE(1b, 2b)
5483+#else
5484+ " addu %0, %1 \n"
5485+#endif
5486+ : "+r" (v->counter) : "Ir" (i));
5487+ raw_local_irq_restore(flags);
5488+ }
5489+}
5490+
5491+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5492 {
5493 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5494 int temp;
5495@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5496 *
5497 * Atomically subtracts @i from @v.
5498 */
5499-static __inline__ void atomic_sub(int i, atomic_t * v)
5500+static __inline__ void atomic_sub(int i, atomic_t *v)
5501+{
5502+ int temp;
5503+
5504+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5505+ __asm__ __volatile__(
5506+ " .set mips3 \n"
5507+ "1: ll %0, %1 # atomic64_sub \n"
5508+#ifdef CONFIG_PAX_REFCOUNT
5509+ /* Exception on overflow. */
5510+ "2: sub %0, %2 \n"
5511+#else
5512+ " subu %0, %2 \n"
5513+#endif
5514+ " sc %0, %1 \n"
5515+ " beqzl %0, 1b \n"
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+ "3: \n"
5518+ _ASM_EXTABLE(2b, 3b)
5519+#endif
5520+ " .set mips0 \n"
5521+ : "=&r" (temp), "+m" (v->counter)
5522+ : "Ir" (i));
5523+ } else if (kernel_uses_llsc) {
5524+ __asm__ __volatile__(
5525+ " .set mips3 \n"
5526+ "1: ll %0, %1 # atomic64_sub \n"
5527+#ifdef CONFIG_PAX_REFCOUNT
5528+ /* Exception on overflow. */
5529+ "2: sub %0, %2 \n"
5530+#else
5531+ " subu %0, %2 \n"
5532+#endif
5533+ " sc %0, %1 \n"
5534+ " beqz %0, 1b \n"
5535+#ifdef CONFIG_PAX_REFCOUNT
5536+ "3: \n"
5537+ _ASM_EXTABLE(2b, 3b)
5538+#endif
5539+ " .set mips0 \n"
5540+ : "=&r" (temp), "+m" (v->counter)
5541+ : "Ir" (i));
5542+ } else {
5543+ unsigned long flags;
5544+
5545+ raw_local_irq_save(flags);
5546+ __asm__ __volatile__(
5547+#ifdef CONFIG_PAX_REFCOUNT
5548+ /* Exception on overflow. */
5549+ "1: sub %0, %1 \n"
5550+ "2: \n"
5551+ _ASM_EXTABLE(1b, 2b)
5552+#else
5553+ " subu %0, %1 \n"
5554+#endif
5555+ : "+r" (v->counter) : "Ir" (i));
5556+ raw_local_irq_restore(flags);
5557+ }
5558+}
5559+
5560+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5561 {
5562 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5563 int temp;
5564@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5565 /*
5566 * Same as above, but return the result value
5567 */
5568-static __inline__ int atomic_add_return(int i, atomic_t * v)
5569+static __inline__ int atomic_add_return(int i, atomic_t *v)
5570+{
5571+ int result;
5572+ int temp;
5573+
5574+ smp_mb__before_llsc();
5575+
5576+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5577+ __asm__ __volatile__(
5578+ " .set mips3 \n"
5579+ "1: ll %1, %2 # atomic_add_return \n"
5580+#ifdef CONFIG_PAX_REFCOUNT
5581+ "2: add %0, %1, %3 \n"
5582+#else
5583+ " addu %0, %1, %3 \n"
5584+#endif
5585+ " sc %0, %2 \n"
5586+ " beqzl %0, 1b \n"
5587+#ifdef CONFIG_PAX_REFCOUNT
5588+ " b 4f \n"
5589+ " .set noreorder \n"
5590+ "3: b 5f \n"
5591+ " move %0, %1 \n"
5592+ " .set reorder \n"
5593+ _ASM_EXTABLE(2b, 3b)
5594+#endif
5595+ "4: addu %0, %1, %3 \n"
5596+#ifdef CONFIG_PAX_REFCOUNT
5597+ "5: \n"
5598+#endif
5599+ " .set mips0 \n"
5600+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5601+ : "Ir" (i));
5602+ } else if (kernel_uses_llsc) {
5603+ __asm__ __volatile__(
5604+ " .set mips3 \n"
5605+ "1: ll %1, %2 # atomic_add_return \n"
5606+#ifdef CONFIG_PAX_REFCOUNT
5607+ "2: add %0, %1, %3 \n"
5608+#else
5609+ " addu %0, %1, %3 \n"
5610+#endif
5611+ " sc %0, %2 \n"
5612+ " bnez %0, 4f \n"
5613+ " b 1b \n"
5614+#ifdef CONFIG_PAX_REFCOUNT
5615+ " .set noreorder \n"
5616+ "3: b 5f \n"
5617+ " move %0, %1 \n"
5618+ " .set reorder \n"
5619+ _ASM_EXTABLE(2b, 3b)
5620+#endif
5621+ "4: addu %0, %1, %3 \n"
5622+#ifdef CONFIG_PAX_REFCOUNT
5623+ "5: \n"
5624+#endif
5625+ " .set mips0 \n"
5626+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5627+ : "Ir" (i));
5628+ } else {
5629+ unsigned long flags;
5630+
5631+ raw_local_irq_save(flags);
5632+ __asm__ __volatile__(
5633+ " lw %0, %1 \n"
5634+#ifdef CONFIG_PAX_REFCOUNT
5635+ /* Exception on overflow. */
5636+ "1: add %0, %2 \n"
5637+#else
5638+ " addu %0, %2 \n"
5639+#endif
5640+ " sw %0, %1 \n"
5641+#ifdef CONFIG_PAX_REFCOUNT
5642+ /* Note: Dest reg is not modified on overflow */
5643+ "2: \n"
5644+ _ASM_EXTABLE(1b, 2b)
5645+#endif
5646+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5647+ raw_local_irq_restore(flags);
5648+ }
5649+
5650+ smp_llsc_mb();
5651+
5652+ return result;
5653+}
5654+
5655+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5656 {
5657 int result;
5658
5659@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5660 return result;
5661 }
5662
5663-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5664+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5665+{
5666+ int result;
5667+ int temp;
5668+
5669+ smp_mb__before_llsc();
5670+
5671+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5672+ __asm__ __volatile__(
5673+ " .set mips3 \n"
5674+ "1: ll %1, %2 # atomic_sub_return \n"
5675+#ifdef CONFIG_PAX_REFCOUNT
5676+ "2: sub %0, %1, %3 \n"
5677+#else
5678+ " subu %0, %1, %3 \n"
5679+#endif
5680+ " sc %0, %2 \n"
5681+ " beqzl %0, 1b \n"
5682+#ifdef CONFIG_PAX_REFCOUNT
5683+ " b 4f \n"
5684+ " .set noreorder \n"
5685+ "3: b 5f \n"
5686+ " move %0, %1 \n"
5687+ " .set reorder \n"
5688+ _ASM_EXTABLE(2b, 3b)
5689+#endif
5690+ "4: subu %0, %1, %3 \n"
5691+#ifdef CONFIG_PAX_REFCOUNT
5692+ "5: \n"
5693+#endif
5694+ " .set mips0 \n"
5695+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5696+ : "Ir" (i), "m" (v->counter)
5697+ : "memory");
5698+ } else if (kernel_uses_llsc) {
5699+ __asm__ __volatile__(
5700+ " .set mips3 \n"
5701+ "1: ll %1, %2 # atomic_sub_return \n"
5702+#ifdef CONFIG_PAX_REFCOUNT
5703+ "2: sub %0, %1, %3 \n"
5704+#else
5705+ " subu %0, %1, %3 \n"
5706+#endif
5707+ " sc %0, %2 \n"
5708+ " bnez %0, 4f \n"
5709+ " b 1b \n"
5710+#ifdef CONFIG_PAX_REFCOUNT
5711+ " .set noreorder \n"
5712+ "3: b 5f \n"
5713+ " move %0, %1 \n"
5714+ " .set reorder \n"
5715+ _ASM_EXTABLE(2b, 3b)
5716+#endif
5717+ "4: subu %0, %1, %3 \n"
5718+#ifdef CONFIG_PAX_REFCOUNT
5719+ "5: \n"
5720+#endif
5721+ " .set mips0 \n"
5722+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5723+ : "Ir" (i));
5724+ } else {
5725+ unsigned long flags;
5726+
5727+ raw_local_irq_save(flags);
5728+ __asm__ __volatile__(
5729+ " lw %0, %1 \n"
5730+#ifdef CONFIG_PAX_REFCOUNT
5731+ /* Exception on overflow. */
5732+ "1: sub %0, %2 \n"
5733+#else
5734+ " subu %0, %2 \n"
5735+#endif
5736+ " sw %0, %1 \n"
5737+#ifdef CONFIG_PAX_REFCOUNT
5738+ /* Note: Dest reg is not modified on overflow */
5739+ "2: \n"
5740+ _ASM_EXTABLE(1b, 2b)
5741+#endif
5742+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5743+ raw_local_irq_restore(flags);
5744+ }
5745+
5746+ smp_llsc_mb();
5747+
5748+ return result;
5749+}
5750+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5751 {
5752 int result;
5753
5754@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5755 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5756 * The function returns the old value of @v minus @i.
5757 */
5758-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5759+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5760 {
5761 int result;
5762
5763@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5764 return result;
5765 }
5766
5767-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5768-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5769+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5770+{
5771+ return cmpxchg(&v->counter, old, new);
5772+}
5773+
5774+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5775+ int new)
5776+{
5777+ return cmpxchg(&(v->counter), old, new);
5778+}
5779+
5780+static inline int atomic_xchg(atomic_t *v, int new)
5781+{
5782+ return xchg(&v->counter, new);
5783+}
5784+
5785+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5786+{
5787+ return xchg(&(v->counter), new);
5788+}
5789
5790 /**
5791 * __atomic_add_unless - add unless the number is a given value
5792@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5793
5794 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5795 #define atomic_inc_return(v) atomic_add_return(1, (v))
5796+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5797+{
5798+ return atomic_add_return_unchecked(1, v);
5799+}
5800
5801 /*
5802 * atomic_sub_and_test - subtract value from variable and test result
5803@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5804 * other cases.
5805 */
5806 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5807+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5808+{
5809+ return atomic_add_return_unchecked(1, v) == 0;
5810+}
5811
5812 /*
5813 * atomic_dec_and_test - decrement by 1 and test
5814@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5815 * Atomically increments @v by 1.
5816 */
5817 #define atomic_inc(v) atomic_add(1, (v))
5818+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5819+{
5820+ atomic_add_unchecked(1, v);
5821+}
5822
5823 /*
5824 * atomic_dec - decrement and test
5825@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5826 * Atomically decrements @v by 1.
5827 */
5828 #define atomic_dec(v) atomic_sub(1, (v))
5829+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5830+{
5831+ atomic_sub_unchecked(1, v);
5832+}
5833
5834 /*
5835 * atomic_add_negative - add and test if negative
5836@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5837 * @v: pointer of type atomic64_t
5838 *
5839 */
5840-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5841+static inline long atomic64_read(const atomic64_t *v)
5842+{
5843+ return (*(volatile const long *) &v->counter);
5844+}
5845+
5846+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5847+{
5848+ return (*(volatile const long *) &v->counter);
5849+}
5850
5851 /*
5852 * atomic64_set - set atomic variable
5853 * @v: pointer of type atomic64_t
5854 * @i: required value
5855 */
5856-#define atomic64_set(v, i) ((v)->counter = (i))
5857+static inline void atomic64_set(atomic64_t *v, long i)
5858+{
5859+ v->counter = i;
5860+}
5861+
5862+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5863+{
5864+ v->counter = i;
5865+}
5866
5867 /*
5868 * atomic64_add - add integer to atomic variable
5869@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5870 *
5871 * Atomically adds @i to @v.
5872 */
5873-static __inline__ void atomic64_add(long i, atomic64_t * v)
5874+static __inline__ void atomic64_add(long i, atomic64_t *v)
5875+{
5876+ long temp;
5877+
5878+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5879+ __asm__ __volatile__(
5880+ " .set mips3 \n"
5881+ "1: lld %0, %1 # atomic64_add \n"
5882+#ifdef CONFIG_PAX_REFCOUNT
5883+ /* Exception on overflow. */
5884+ "2: dadd %0, %2 \n"
5885+#else
5886+ " daddu %0, %2 \n"
5887+#endif
5888+ " scd %0, %1 \n"
5889+ " beqzl %0, 1b \n"
5890+#ifdef CONFIG_PAX_REFCOUNT
5891+ "3: \n"
5892+ _ASM_EXTABLE(2b, 3b)
5893+#endif
5894+ " .set mips0 \n"
5895+ : "=&r" (temp), "+m" (v->counter)
5896+ : "Ir" (i));
5897+ } else if (kernel_uses_llsc) {
5898+ __asm__ __volatile__(
5899+ " .set mips3 \n"
5900+ "1: lld %0, %1 # atomic64_add \n"
5901+#ifdef CONFIG_PAX_REFCOUNT
5902+ /* Exception on overflow. */
5903+ "2: dadd %0, %2 \n"
5904+#else
5905+ " daddu %0, %2 \n"
5906+#endif
5907+ " scd %0, %1 \n"
5908+ " beqz %0, 1b \n"
5909+#ifdef CONFIG_PAX_REFCOUNT
5910+ "3: \n"
5911+ _ASM_EXTABLE(2b, 3b)
5912+#endif
5913+ " .set mips0 \n"
5914+ : "=&r" (temp), "+m" (v->counter)
5915+ : "Ir" (i));
5916+ } else {
5917+ unsigned long flags;
5918+
5919+ raw_local_irq_save(flags);
5920+ __asm__ __volatile__(
5921+#ifdef CONFIG_PAX_REFCOUNT
5922+ /* Exception on overflow. */
5923+ "1: dadd %0, %1 \n"
5924+ "2: \n"
5925+ _ASM_EXTABLE(1b, 2b)
5926+#else
5927+ " daddu %0, %1 \n"
5928+#endif
5929+ : "+r" (v->counter) : "Ir" (i));
5930+ raw_local_irq_restore(flags);
5931+ }
5932+}
5933+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5934 {
5935 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5936 long temp;
5937@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5938 *
5939 * Atomically subtracts @i from @v.
5940 */
5941-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5942+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5943+{
5944+ long temp;
5945+
5946+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5947+ __asm__ __volatile__(
5948+ " .set mips3 \n"
5949+ "1: lld %0, %1 # atomic64_sub \n"
5950+#ifdef CONFIG_PAX_REFCOUNT
5951+ /* Exception on overflow. */
5952+ "2: dsub %0, %2 \n"
5953+#else
5954+ " dsubu %0, %2 \n"
5955+#endif
5956+ " scd %0, %1 \n"
5957+ " beqzl %0, 1b \n"
5958+#ifdef CONFIG_PAX_REFCOUNT
5959+ "3: \n"
5960+ _ASM_EXTABLE(2b, 3b)
5961+#endif
5962+ " .set mips0 \n"
5963+ : "=&r" (temp), "+m" (v->counter)
5964+ : "Ir" (i));
5965+ } else if (kernel_uses_llsc) {
5966+ __asm__ __volatile__(
5967+ " .set mips3 \n"
5968+ "1: lld %0, %1 # atomic64_sub \n"
5969+#ifdef CONFIG_PAX_REFCOUNT
5970+ /* Exception on overflow. */
5971+ "2: dsub %0, %2 \n"
5972+#else
5973+ " dsubu %0, %2 \n"
5974+#endif
5975+ " scd %0, %1 \n"
5976+ " beqz %0, 1b \n"
5977+#ifdef CONFIG_PAX_REFCOUNT
5978+ "3: \n"
5979+ _ASM_EXTABLE(2b, 3b)
5980+#endif
5981+ " .set mips0 \n"
5982+ : "=&r" (temp), "+m" (v->counter)
5983+ : "Ir" (i));
5984+ } else {
5985+ unsigned long flags;
5986+
5987+ raw_local_irq_save(flags);
5988+ __asm__ __volatile__(
5989+#ifdef CONFIG_PAX_REFCOUNT
5990+ /* Exception on overflow. */
5991+ "1: dsub %0, %1 \n"
5992+ "2: \n"
5993+ _ASM_EXTABLE(1b, 2b)
5994+#else
5995+ " dsubu %0, %1 \n"
5996+#endif
5997+ : "+r" (v->counter) : "Ir" (i));
5998+ raw_local_irq_restore(flags);
5999+ }
6000+}
6001+
6002+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6003 {
6004 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6005 long temp;
6006@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6007 /*
6008 * Same as above, but return the result value
6009 */
6010-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6011+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6012+{
6013+ long result;
6014+ long temp;
6015+
6016+ smp_mb__before_llsc();
6017+
6018+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6019+ __asm__ __volatile__(
6020+ " .set mips3 \n"
6021+ "1: lld %1, %2 # atomic64_add_return \n"
6022+#ifdef CONFIG_PAX_REFCOUNT
6023+ "2: dadd %0, %1, %3 \n"
6024+#else
6025+ " daddu %0, %1, %3 \n"
6026+#endif
6027+ " scd %0, %2 \n"
6028+ " beqzl %0, 1b \n"
6029+#ifdef CONFIG_PAX_REFCOUNT
6030+ " b 4f \n"
6031+ " .set noreorder \n"
6032+ "3: b 5f \n"
6033+ " move %0, %1 \n"
6034+ " .set reorder \n"
6035+ _ASM_EXTABLE(2b, 3b)
6036+#endif
6037+ "4: daddu %0, %1, %3 \n"
6038+#ifdef CONFIG_PAX_REFCOUNT
6039+ "5: \n"
6040+#endif
6041+ " .set mips0 \n"
6042+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6043+ : "Ir" (i));
6044+ } else if (kernel_uses_llsc) {
6045+ __asm__ __volatile__(
6046+ " .set mips3 \n"
6047+ "1: lld %1, %2 # atomic64_add_return \n"
6048+#ifdef CONFIG_PAX_REFCOUNT
6049+ "2: dadd %0, %1, %3 \n"
6050+#else
6051+ " daddu %0, %1, %3 \n"
6052+#endif
6053+ " scd %0, %2 \n"
6054+ " bnez %0, 4f \n"
6055+ " b 1b \n"
6056+#ifdef CONFIG_PAX_REFCOUNT
6057+ " .set noreorder \n"
6058+ "3: b 5f \n"
6059+ " move %0, %1 \n"
6060+ " .set reorder \n"
6061+ _ASM_EXTABLE(2b, 3b)
6062+#endif
6063+ "4: daddu %0, %1, %3 \n"
6064+#ifdef CONFIG_PAX_REFCOUNT
6065+ "5: \n"
6066+#endif
6067+ " .set mips0 \n"
6068+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6069+ : "Ir" (i), "m" (v->counter)
6070+ : "memory");
6071+ } else {
6072+ unsigned long flags;
6073+
6074+ raw_local_irq_save(flags);
6075+ __asm__ __volatile__(
6076+ " ld %0, %1 \n"
6077+#ifdef CONFIG_PAX_REFCOUNT
6078+ /* Exception on overflow. */
6079+ "1: dadd %0, %2 \n"
6080+#else
6081+ " daddu %0, %2 \n"
6082+#endif
6083+ " sd %0, %1 \n"
6084+#ifdef CONFIG_PAX_REFCOUNT
6085+ /* Note: Dest reg is not modified on overflow */
6086+ "2: \n"
6087+ _ASM_EXTABLE(1b, 2b)
6088+#endif
6089+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6090+ raw_local_irq_restore(flags);
6091+ }
6092+
6093+ smp_llsc_mb();
6094+
6095+ return result;
6096+}
6097+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6098 {
6099 long result;
6100
6101@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6102 return result;
6103 }
6104
6105-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6106+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6107+{
6108+ long result;
6109+ long temp;
6110+
6111+ smp_mb__before_llsc();
6112+
6113+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6114+ long temp;
6115+
6116+ __asm__ __volatile__(
6117+ " .set mips3 \n"
6118+ "1: lld %1, %2 # atomic64_sub_return \n"
6119+#ifdef CONFIG_PAX_REFCOUNT
6120+ "2: dsub %0, %1, %3 \n"
6121+#else
6122+ " dsubu %0, %1, %3 \n"
6123+#endif
6124+ " scd %0, %2 \n"
6125+ " beqzl %0, 1b \n"
6126+#ifdef CONFIG_PAX_REFCOUNT
6127+ " b 4f \n"
6128+ " .set noreorder \n"
6129+ "3: b 5f \n"
6130+ " move %0, %1 \n"
6131+ " .set reorder \n"
6132+ _ASM_EXTABLE(2b, 3b)
6133+#endif
6134+ "4: dsubu %0, %1, %3 \n"
6135+#ifdef CONFIG_PAX_REFCOUNT
6136+ "5: \n"
6137+#endif
6138+ " .set mips0 \n"
6139+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6140+ : "Ir" (i), "m" (v->counter)
6141+ : "memory");
6142+ } else if (kernel_uses_llsc) {
6143+ __asm__ __volatile__(
6144+ " .set mips3 \n"
6145+ "1: lld %1, %2 # atomic64_sub_return \n"
6146+#ifdef CONFIG_PAX_REFCOUNT
6147+ "2: dsub %0, %1, %3 \n"
6148+#else
6149+ " dsubu %0, %1, %3 \n"
6150+#endif
6151+ " scd %0, %2 \n"
6152+ " bnez %0, 4f \n"
6153+ " b 1b \n"
6154+#ifdef CONFIG_PAX_REFCOUNT
6155+ " .set noreorder \n"
6156+ "3: b 5f \n"
6157+ " move %0, %1 \n"
6158+ " .set reorder \n"
6159+ _ASM_EXTABLE(2b, 3b)
6160+#endif
6161+ "4: dsubu %0, %1, %3 \n"
6162+#ifdef CONFIG_PAX_REFCOUNT
6163+ "5: \n"
6164+#endif
6165+ " .set mips0 \n"
6166+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6167+ : "Ir" (i), "m" (v->counter)
6168+ : "memory");
6169+ } else {
6170+ unsigned long flags;
6171+
6172+ raw_local_irq_save(flags);
6173+ __asm__ __volatile__(
6174+ " ld %0, %1 \n"
6175+#ifdef CONFIG_PAX_REFCOUNT
6176+ /* Exception on overflow. */
6177+ "1: dsub %0, %2 \n"
6178+#else
6179+ " dsubu %0, %2 \n"
6180+#endif
6181+ " sd %0, %1 \n"
6182+#ifdef CONFIG_PAX_REFCOUNT
6183+ /* Note: Dest reg is not modified on overflow */
6184+ "2: \n"
6185+ _ASM_EXTABLE(1b, 2b)
6186+#endif
6187+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6188+ raw_local_irq_restore(flags);
6189+ }
6190+
6191+ smp_llsc_mb();
6192+
6193+ return result;
6194+}
6195+
6196+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6197 {
6198 long result;
6199
6200@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6201 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6202 * The function returns the old value of @v minus @i.
6203 */
6204-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6205+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6206 {
6207 long result;
6208
6209@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6210 return result;
6211 }
6212
6213-#define atomic64_cmpxchg(v, o, n) \
6214- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6215-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6216+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6217+{
6218+ return cmpxchg(&v->counter, old, new);
6219+}
6220+
6221+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6222+ long new)
6223+{
6224+ return cmpxchg(&(v->counter), old, new);
6225+}
6226+
6227+static inline long atomic64_xchg(atomic64_t *v, long new)
6228+{
6229+ return xchg(&v->counter, new);
6230+}
6231+
6232+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6233+{
6234+ return xchg(&(v->counter), new);
6235+}
6236
6237 /**
6238 * atomic64_add_unless - add unless the number is a given value
6239@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6240
6241 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6242 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6243+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6244
6245 /*
6246 * atomic64_sub_and_test - subtract value from variable and test result
6247@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6248 * other cases.
6249 */
6250 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6251+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6252
6253 /*
6254 * atomic64_dec_and_test - decrement by 1 and test
6255@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6256 * Atomically increments @v by 1.
6257 */
6258 #define atomic64_inc(v) atomic64_add(1, (v))
6259+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6260
6261 /*
6262 * atomic64_dec - decrement and test
6263@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6264 * Atomically decrements @v by 1.
6265 */
6266 #define atomic64_dec(v) atomic64_sub(1, (v))
6267+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6268
6269 /*
6270 * atomic64_add_negative - add and test if negative
6271diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6272index b4db69f..8f3b093 100644
6273--- a/arch/mips/include/asm/cache.h
6274+++ b/arch/mips/include/asm/cache.h
6275@@ -9,10 +9,11 @@
6276 #ifndef _ASM_CACHE_H
6277 #define _ASM_CACHE_H
6278
6279+#include <linux/const.h>
6280 #include <kmalloc.h>
6281
6282 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6283-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6284+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6285
6286 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6287 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6288diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6289index cf3ae24..238d22f 100644
6290--- a/arch/mips/include/asm/elf.h
6291+++ b/arch/mips/include/asm/elf.h
6292@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6293 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6294 #endif
6295
6296+#ifdef CONFIG_PAX_ASLR
6297+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6298+
6299+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6300+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6301+#endif
6302+
6303 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6304 struct linux_binprm;
6305 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6306 int uses_interp);
6307
6308-struct mm_struct;
6309-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6310-#define arch_randomize_brk arch_randomize_brk
6311-
6312 #endif /* _ASM_ELF_H */
6313diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6314index c1f6afa..38cc6e9 100644
6315--- a/arch/mips/include/asm/exec.h
6316+++ b/arch/mips/include/asm/exec.h
6317@@ -12,6 +12,6 @@
6318 #ifndef _ASM_EXEC_H
6319 #define _ASM_EXEC_H
6320
6321-extern unsigned long arch_align_stack(unsigned long sp);
6322+#define arch_align_stack(x) ((x) & ~0xfUL)
6323
6324 #endif /* _ASM_EXEC_H */
6325diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6326index d44622c..64990d2 100644
6327--- a/arch/mips/include/asm/local.h
6328+++ b/arch/mips/include/asm/local.h
6329@@ -12,15 +12,25 @@ typedef struct
6330 atomic_long_t a;
6331 } local_t;
6332
6333+typedef struct {
6334+ atomic_long_unchecked_t a;
6335+} local_unchecked_t;
6336+
6337 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6338
6339 #define local_read(l) atomic_long_read(&(l)->a)
6340+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6341 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6342+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6343
6344 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6345+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6346 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6347+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6348 #define local_inc(l) atomic_long_inc(&(l)->a)
6349+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6350 #define local_dec(l) atomic_long_dec(&(l)->a)
6351+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6352
6353 /*
6354 * Same as above, but return the result value
6355@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6356 return result;
6357 }
6358
6359+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6360+{
6361+ unsigned long result;
6362+
6363+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6364+ unsigned long temp;
6365+
6366+ __asm__ __volatile__(
6367+ " .set mips3 \n"
6368+ "1:" __LL "%1, %2 # local_add_return \n"
6369+ " addu %0, %1, %3 \n"
6370+ __SC "%0, %2 \n"
6371+ " beqzl %0, 1b \n"
6372+ " addu %0, %1, %3 \n"
6373+ " .set mips0 \n"
6374+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6375+ : "Ir" (i), "m" (l->a.counter)
6376+ : "memory");
6377+ } else if (kernel_uses_llsc) {
6378+ unsigned long temp;
6379+
6380+ __asm__ __volatile__(
6381+ " .set mips3 \n"
6382+ "1:" __LL "%1, %2 # local_add_return \n"
6383+ " addu %0, %1, %3 \n"
6384+ __SC "%0, %2 \n"
6385+ " beqz %0, 1b \n"
6386+ " addu %0, %1, %3 \n"
6387+ " .set mips0 \n"
6388+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6389+ : "Ir" (i), "m" (l->a.counter)
6390+ : "memory");
6391+ } else {
6392+ unsigned long flags;
6393+
6394+ local_irq_save(flags);
6395+ result = l->a.counter;
6396+ result += i;
6397+ l->a.counter = result;
6398+ local_irq_restore(flags);
6399+ }
6400+
6401+ return result;
6402+}
6403+
6404 static __inline__ long local_sub_return(long i, local_t * l)
6405 {
6406 unsigned long result;
6407@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6408
6409 #define local_cmpxchg(l, o, n) \
6410 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6411+#define local_cmpxchg_unchecked(l, o, n) \
6412+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6413 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6414
6415 /**
6416diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6417index f6be474..12ad554 100644
6418--- a/arch/mips/include/asm/page.h
6419+++ b/arch/mips/include/asm/page.h
6420@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6421 #ifdef CONFIG_CPU_MIPS32
6422 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6423 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6424- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6425+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6426 #else
6427 typedef struct { unsigned long long pte; } pte_t;
6428 #define pte_val(x) ((x).pte)
6429diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6430index 881d18b..cea38bc 100644
6431--- a/arch/mips/include/asm/pgalloc.h
6432+++ b/arch/mips/include/asm/pgalloc.h
6433@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6434 {
6435 set_pud(pud, __pud((unsigned long)pmd));
6436 }
6437+
6438+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6439+{
6440+ pud_populate(mm, pud, pmd);
6441+}
6442 #endif
6443
6444 /*
6445diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6446index 25da651..ae2a259 100644
6447--- a/arch/mips/include/asm/smtc_proc.h
6448+++ b/arch/mips/include/asm/smtc_proc.h
6449@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6450
6451 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6452
6453-extern atomic_t smtc_fpu_recoveries;
6454+extern atomic_unchecked_t smtc_fpu_recoveries;
6455
6456 #endif /* __ASM_SMTC_PROC_H */
6457diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6458index 61215a3..213ee0e 100644
6459--- a/arch/mips/include/asm/thread_info.h
6460+++ b/arch/mips/include/asm/thread_info.h
6461@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6462 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6463 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6464 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6465+/* li takes a 32bit immediate */
6466+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6467 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6468
6469 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6470@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6471 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6472 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6473 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6474+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6475
6476-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6477- _TIF_SYSCALL_AUDIT)
6478+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6479
6480 /* work to do in syscall_trace_leave() */
6481-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6482- _TIF_SYSCALL_AUDIT)
6483+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6484
6485 /* work to do on interrupt/exception return */
6486 #define _TIF_WORK_MASK \
6487 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6488 /* work to do on any return to u-space */
6489-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6490- _TIF_WORK_SYSCALL_EXIT)
6491+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6492
6493 #endif /* __KERNEL__ */
6494
6495diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6496index 1188e00..41cf144 100644
6497--- a/arch/mips/kernel/binfmt_elfn32.c
6498+++ b/arch/mips/kernel/binfmt_elfn32.c
6499@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6500 #undef ELF_ET_DYN_BASE
6501 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6502
6503+#ifdef CONFIG_PAX_ASLR
6504+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6505+
6506+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6507+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6508+#endif
6509+
6510 #include <asm/processor.h>
6511 #include <linux/module.h>
6512 #include <linux/elfcore.h>
6513diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6514index 202e581..689ca79 100644
6515--- a/arch/mips/kernel/binfmt_elfo32.c
6516+++ b/arch/mips/kernel/binfmt_elfo32.c
6517@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6518 #undef ELF_ET_DYN_BASE
6519 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6520
6521+#ifdef CONFIG_PAX_ASLR
6522+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6523+
6524+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6525+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6526+#endif
6527+
6528 #include <asm/processor.h>
6529
6530 /*
6531diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6532index d1fea7a..45602ea 100644
6533--- a/arch/mips/kernel/irq.c
6534+++ b/arch/mips/kernel/irq.c
6535@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6536 printk("unexpected IRQ # %d\n", irq);
6537 }
6538
6539-atomic_t irq_err_count;
6540+atomic_unchecked_t irq_err_count;
6541
6542 int arch_show_interrupts(struct seq_file *p, int prec)
6543 {
6544- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6545+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6546 return 0;
6547 }
6548
6549 asmlinkage void spurious_interrupt(void)
6550 {
6551- atomic_inc(&irq_err_count);
6552+ atomic_inc_unchecked(&irq_err_count);
6553 }
6554
6555 void __init init_IRQ(void)
6556diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6557index ddc7610..8c58f17 100644
6558--- a/arch/mips/kernel/process.c
6559+++ b/arch/mips/kernel/process.c
6560@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6561 out:
6562 return pc;
6563 }
6564-
6565-/*
6566- * Don't forget that the stack pointer must be aligned on a 8 bytes
6567- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6568- */
6569-unsigned long arch_align_stack(unsigned long sp)
6570-{
6571- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6572- sp -= get_random_int() & ~PAGE_MASK;
6573-
6574- return sp & ALMASK;
6575-}
6576diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6577index 8ae1ebe..1bcbf47 100644
6578--- a/arch/mips/kernel/ptrace.c
6579+++ b/arch/mips/kernel/ptrace.c
6580@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6581 return arch;
6582 }
6583
6584+#ifdef CONFIG_GRKERNSEC_SETXID
6585+extern void gr_delayed_cred_worker(void);
6586+#endif
6587+
6588 /*
6589 * Notification of system call entry/exit
6590 * - triggered by current->work.syscall_trace
6591@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6592 /* do the secure computing check first */
6593 secure_computing_strict(regs->regs[2]);
6594
6595+#ifdef CONFIG_GRKERNSEC_SETXID
6596+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6597+ gr_delayed_cred_worker();
6598+#endif
6599+
6600 if (!(current->ptrace & PT_PTRACED))
6601 goto out;
6602
6603diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6604index c10aa84..9ec2e60 100644
6605--- a/arch/mips/kernel/smtc-proc.c
6606+++ b/arch/mips/kernel/smtc-proc.c
6607@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6608
6609 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6610
6611-atomic_t smtc_fpu_recoveries;
6612+atomic_unchecked_t smtc_fpu_recoveries;
6613
6614 static int smtc_proc_show(struct seq_file *m, void *v)
6615 {
6616@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6617 for(i = 0; i < NR_CPUS; i++)
6618 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6619 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6620- atomic_read(&smtc_fpu_recoveries));
6621+ atomic_read_unchecked(&smtc_fpu_recoveries));
6622 return 0;
6623 }
6624
6625@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6626 smtc_cpu_stats[i].selfipis = 0;
6627 }
6628
6629- atomic_set(&smtc_fpu_recoveries, 0);
6630+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6631
6632 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6633 }
6634diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6635index dfc1b91..11a2c07 100644
6636--- a/arch/mips/kernel/smtc.c
6637+++ b/arch/mips/kernel/smtc.c
6638@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6639 }
6640 smtc_ipi_qdump();
6641 printk("%d Recoveries of \"stolen\" FPU\n",
6642- atomic_read(&smtc_fpu_recoveries));
6643+ atomic_read_unchecked(&smtc_fpu_recoveries));
6644 }
6645
6646
6647diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6648index 84536bf..79caa4d 100644
6649--- a/arch/mips/kernel/sync-r4k.c
6650+++ b/arch/mips/kernel/sync-r4k.c
6651@@ -21,8 +21,8 @@
6652 #include <asm/mipsregs.h>
6653
6654 static atomic_t count_start_flag = ATOMIC_INIT(0);
6655-static atomic_t count_count_start = ATOMIC_INIT(0);
6656-static atomic_t count_count_stop = ATOMIC_INIT(0);
6657+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6658+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6659 static atomic_t count_reference = ATOMIC_INIT(0);
6660
6661 #define COUNTON 100
6662@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6663
6664 for (i = 0; i < NR_LOOPS; i++) {
6665 /* slaves loop on '!= 2' */
6666- while (atomic_read(&count_count_start) != 1)
6667+ while (atomic_read_unchecked(&count_count_start) != 1)
6668 mb();
6669- atomic_set(&count_count_stop, 0);
6670+ atomic_set_unchecked(&count_count_stop, 0);
6671 smp_wmb();
6672
6673 /* this lets the slaves write their count register */
6674- atomic_inc(&count_count_start);
6675+ atomic_inc_unchecked(&count_count_start);
6676
6677 /*
6678 * Everyone initialises count in the last loop:
6679@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6680 /*
6681 * Wait for all slaves to leave the synchronization point:
6682 */
6683- while (atomic_read(&count_count_stop) != 1)
6684+ while (atomic_read_unchecked(&count_count_stop) != 1)
6685 mb();
6686- atomic_set(&count_count_start, 0);
6687+ atomic_set_unchecked(&count_count_start, 0);
6688 smp_wmb();
6689- atomic_inc(&count_count_stop);
6690+ atomic_inc_unchecked(&count_count_stop);
6691 }
6692 /* Arrange for an interrupt in a short while */
6693 write_c0_compare(read_c0_count() + COUNTON);
6694@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6695 initcount = atomic_read(&count_reference);
6696
6697 for (i = 0; i < NR_LOOPS; i++) {
6698- atomic_inc(&count_count_start);
6699- while (atomic_read(&count_count_start) != 2)
6700+ atomic_inc_unchecked(&count_count_start);
6701+ while (atomic_read_unchecked(&count_count_start) != 2)
6702 mb();
6703
6704 /*
6705@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6706 if (i == NR_LOOPS-1)
6707 write_c0_count(initcount);
6708
6709- atomic_inc(&count_count_stop);
6710- while (atomic_read(&count_count_stop) != 2)
6711+ atomic_inc_unchecked(&count_count_stop);
6712+ while (atomic_read_unchecked(&count_count_stop) != 2)
6713 mb();
6714 }
6715 /* Arrange for an interrupt in a short while */
6716diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6717index aec3408..74d79d3 100644
6718--- a/arch/mips/kernel/traps.c
6719+++ b/arch/mips/kernel/traps.c
6720@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6721 siginfo_t info;
6722
6723 prev_state = exception_enter();
6724- die_if_kernel("Integer overflow", regs);
6725+ if (unlikely(!user_mode(regs))) {
6726+
6727+#ifdef CONFIG_PAX_REFCOUNT
6728+ if (fixup_exception(regs)) {
6729+ pax_report_refcount_overflow(regs);
6730+ exception_exit(prev_state);
6731+ return;
6732+ }
6733+#endif
6734+
6735+ die("Integer overflow", regs);
6736+ }
6737
6738 info.si_code = FPE_INTOVF;
6739 info.si_signo = SIGFPE;
6740diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6741index 85df1cd..4f0a4de 100644
6742--- a/arch/mips/mm/fault.c
6743+++ b/arch/mips/mm/fault.c
6744@@ -28,6 +28,23 @@
6745 #include <asm/highmem.h> /* For VMALLOC_END */
6746 #include <linux/kdebug.h>
6747
6748+#ifdef CONFIG_PAX_PAGEEXEC
6749+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6750+{
6751+ unsigned long i;
6752+
6753+ printk(KERN_ERR "PAX: bytes at PC: ");
6754+ for (i = 0; i < 5; i++) {
6755+ unsigned int c;
6756+ if (get_user(c, (unsigned int *)pc+i))
6757+ printk(KERN_CONT "???????? ");
6758+ else
6759+ printk(KERN_CONT "%08x ", c);
6760+ }
6761+ printk("\n");
6762+}
6763+#endif
6764+
6765 /*
6766 * This routine handles page faults. It determines the address,
6767 * and the problem, and then passes it off to one of the appropriate
6768@@ -197,6 +214,14 @@ bad_area:
6769 bad_area_nosemaphore:
6770 /* User mode accesses just cause a SIGSEGV */
6771 if (user_mode(regs)) {
6772+
6773+#ifdef CONFIG_PAX_PAGEEXEC
6774+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6775+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6776+ do_group_exit(SIGKILL);
6777+ }
6778+#endif
6779+
6780 tsk->thread.cp0_badvaddr = address;
6781 tsk->thread.error_code = write;
6782 #if 0
6783diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6784index f1baadd..8537544 100644
6785--- a/arch/mips/mm/mmap.c
6786+++ b/arch/mips/mm/mmap.c
6787@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6788 struct vm_area_struct *vma;
6789 unsigned long addr = addr0;
6790 int do_color_align;
6791+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6792 struct vm_unmapped_area_info info;
6793
6794 if (unlikely(len > TASK_SIZE))
6795@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6796 do_color_align = 1;
6797
6798 /* requesting a specific address */
6799+
6800+#ifdef CONFIG_PAX_RANDMMAP
6801+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6802+#endif
6803+
6804 if (addr) {
6805 if (do_color_align)
6806 addr = COLOUR_ALIGN(addr, pgoff);
6807@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6808 addr = PAGE_ALIGN(addr);
6809
6810 vma = find_vma(mm, addr);
6811- if (TASK_SIZE - len >= addr &&
6812- (!vma || addr + len <= vma->vm_start))
6813+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6814 return addr;
6815 }
6816
6817 info.length = len;
6818 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6819 info.align_offset = pgoff << PAGE_SHIFT;
6820+ info.threadstack_offset = offset;
6821
6822 if (dir == DOWN) {
6823 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6824@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6825 {
6826 unsigned long random_factor = 0UL;
6827
6828+#ifdef CONFIG_PAX_RANDMMAP
6829+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6830+#endif
6831+
6832 if (current->flags & PF_RANDOMIZE) {
6833 random_factor = get_random_int();
6834 random_factor = random_factor << PAGE_SHIFT;
6835@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6836
6837 if (mmap_is_legacy()) {
6838 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6839+
6840+#ifdef CONFIG_PAX_RANDMMAP
6841+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6842+ mm->mmap_base += mm->delta_mmap;
6843+#endif
6844+
6845 mm->get_unmapped_area = arch_get_unmapped_area;
6846 } else {
6847 mm->mmap_base = mmap_base(random_factor);
6848+
6849+#ifdef CONFIG_PAX_RANDMMAP
6850+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6851+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6852+#endif
6853+
6854 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6855 }
6856 }
6857
6858-static inline unsigned long brk_rnd(void)
6859-{
6860- unsigned long rnd = get_random_int();
6861-
6862- rnd = rnd << PAGE_SHIFT;
6863- /* 8MB for 32bit, 256MB for 64bit */
6864- if (TASK_IS_32BIT_ADDR)
6865- rnd = rnd & 0x7ffffful;
6866- else
6867- rnd = rnd & 0xffffffful;
6868-
6869- return rnd;
6870-}
6871-
6872-unsigned long arch_randomize_brk(struct mm_struct *mm)
6873-{
6874- unsigned long base = mm->brk;
6875- unsigned long ret;
6876-
6877- ret = PAGE_ALIGN(base + brk_rnd());
6878-
6879- if (ret < mm->brk)
6880- return mm->brk;
6881-
6882- return ret;
6883-}
6884-
6885 int __virt_addr_valid(const volatile void *kaddr)
6886 {
6887 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6888diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6889index a2358b4..7cead4f 100644
6890--- a/arch/mips/sgi-ip27/ip27-nmi.c
6891+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6892@@ -187,9 +187,9 @@ void
6893 cont_nmi_dump(void)
6894 {
6895 #ifndef REAL_NMI_SIGNAL
6896- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6897+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6898
6899- atomic_inc(&nmied_cpus);
6900+ atomic_inc_unchecked(&nmied_cpus);
6901 #endif
6902 /*
6903 * Only allow 1 cpu to proceed
6904@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6905 udelay(10000);
6906 }
6907 #else
6908- while (atomic_read(&nmied_cpus) != num_online_cpus());
6909+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6910 #endif
6911
6912 /*
6913diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6914index 967d144..db12197 100644
6915--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6916+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6917@@ -11,12 +11,14 @@
6918 #ifndef _ASM_PROC_CACHE_H
6919 #define _ASM_PROC_CACHE_H
6920
6921+#include <linux/const.h>
6922+
6923 /* L1 cache */
6924
6925 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6926 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6927-#define L1_CACHE_BYTES 16 /* bytes per entry */
6928 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6929+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6930 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6931
6932 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6933diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6934index bcb5df2..84fabd2 100644
6935--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6936+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6937@@ -16,13 +16,15 @@
6938 #ifndef _ASM_PROC_CACHE_H
6939 #define _ASM_PROC_CACHE_H
6940
6941+#include <linux/const.h>
6942+
6943 /*
6944 * L1 cache
6945 */
6946 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6947 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6948-#define L1_CACHE_BYTES 32 /* bytes per entry */
6949 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6950+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6951 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6952
6953 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6954diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6955index 4ce7a01..449202a 100644
6956--- a/arch/openrisc/include/asm/cache.h
6957+++ b/arch/openrisc/include/asm/cache.h
6958@@ -19,11 +19,13 @@
6959 #ifndef __ASM_OPENRISC_CACHE_H
6960 #define __ASM_OPENRISC_CACHE_H
6961
6962+#include <linux/const.h>
6963+
6964 /* FIXME: How can we replace these with values from the CPU...
6965 * they shouldn't be hard-coded!
6966 */
6967
6968-#define L1_CACHE_BYTES 16
6969 #define L1_CACHE_SHIFT 4
6970+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6971
6972 #endif /* __ASM_OPENRISC_CACHE_H */
6973diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6974index 472886c..00e7df9 100644
6975--- a/arch/parisc/include/asm/atomic.h
6976+++ b/arch/parisc/include/asm/atomic.h
6977@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6978 return dec;
6979 }
6980
6981+#define atomic64_read_unchecked(v) atomic64_read(v)
6982+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6983+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6984+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6985+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6986+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6987+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6988+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6989+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6990+
6991 #endif /* !CONFIG_64BIT */
6992
6993
6994diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6995index 47f11c7..3420df2 100644
6996--- a/arch/parisc/include/asm/cache.h
6997+++ b/arch/parisc/include/asm/cache.h
6998@@ -5,6 +5,7 @@
6999 #ifndef __ARCH_PARISC_CACHE_H
7000 #define __ARCH_PARISC_CACHE_H
7001
7002+#include <linux/const.h>
7003
7004 /*
7005 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7006@@ -15,13 +16,13 @@
7007 * just ruin performance.
7008 */
7009 #ifdef CONFIG_PA20
7010-#define L1_CACHE_BYTES 64
7011 #define L1_CACHE_SHIFT 6
7012 #else
7013-#define L1_CACHE_BYTES 32
7014 #define L1_CACHE_SHIFT 5
7015 #endif
7016
7017+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7018+
7019 #ifndef __ASSEMBLY__
7020
7021 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7022diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7023index ad2b503..bdf1651 100644
7024--- a/arch/parisc/include/asm/elf.h
7025+++ b/arch/parisc/include/asm/elf.h
7026@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7027
7028 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7029
7030+#ifdef CONFIG_PAX_ASLR
7031+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7032+
7033+#define PAX_DELTA_MMAP_LEN 16
7034+#define PAX_DELTA_STACK_LEN 16
7035+#endif
7036+
7037 /* This yields a mask that user programs can use to figure out what
7038 instruction set this CPU supports. This could be done in user space,
7039 but it's not easy, and we've already done it here. */
7040diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7041index fc987a1..6e068ef 100644
7042--- a/arch/parisc/include/asm/pgalloc.h
7043+++ b/arch/parisc/include/asm/pgalloc.h
7044@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7045 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7046 }
7047
7048+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7049+{
7050+ pgd_populate(mm, pgd, pmd);
7051+}
7052+
7053 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7054 {
7055 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7056@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7057 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7058 #define pmd_free(mm, x) do { } while (0)
7059 #define pgd_populate(mm, pmd, pte) BUG()
7060+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7061
7062 #endif
7063
7064diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7065index 34899b5..02dd060 100644
7066--- a/arch/parisc/include/asm/pgtable.h
7067+++ b/arch/parisc/include/asm/pgtable.h
7068@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7069 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7070 #define PAGE_COPY PAGE_EXECREAD
7071 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7072+
7073+#ifdef CONFIG_PAX_PAGEEXEC
7074+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7075+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7076+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7077+#else
7078+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7079+# define PAGE_COPY_NOEXEC PAGE_COPY
7080+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7081+#endif
7082+
7083 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7084 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7085 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7086diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7087index e0a8235..ce2f1e1 100644
7088--- a/arch/parisc/include/asm/uaccess.h
7089+++ b/arch/parisc/include/asm/uaccess.h
7090@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7091 const void __user *from,
7092 unsigned long n)
7093 {
7094- int sz = __compiletime_object_size(to);
7095+ size_t sz = __compiletime_object_size(to);
7096 int ret = -EFAULT;
7097
7098- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7099+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7100 ret = __copy_from_user(to, from, n);
7101 else
7102 copy_from_user_overflow();
7103diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7104index 2a625fb..9908930 100644
7105--- a/arch/parisc/kernel/module.c
7106+++ b/arch/parisc/kernel/module.c
7107@@ -98,16 +98,38 @@
7108
7109 /* three functions to determine where in the module core
7110 * or init pieces the location is */
7111+static inline int in_init_rx(struct module *me, void *loc)
7112+{
7113+ return (loc >= me->module_init_rx &&
7114+ loc < (me->module_init_rx + me->init_size_rx));
7115+}
7116+
7117+static inline int in_init_rw(struct module *me, void *loc)
7118+{
7119+ return (loc >= me->module_init_rw &&
7120+ loc < (me->module_init_rw + me->init_size_rw));
7121+}
7122+
7123 static inline int in_init(struct module *me, void *loc)
7124 {
7125- return (loc >= me->module_init &&
7126- loc <= (me->module_init + me->init_size));
7127+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7128+}
7129+
7130+static inline int in_core_rx(struct module *me, void *loc)
7131+{
7132+ return (loc >= me->module_core_rx &&
7133+ loc < (me->module_core_rx + me->core_size_rx));
7134+}
7135+
7136+static inline int in_core_rw(struct module *me, void *loc)
7137+{
7138+ return (loc >= me->module_core_rw &&
7139+ loc < (me->module_core_rw + me->core_size_rw));
7140 }
7141
7142 static inline int in_core(struct module *me, void *loc)
7143 {
7144- return (loc >= me->module_core &&
7145- loc <= (me->module_core + me->core_size));
7146+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7147 }
7148
7149 static inline int in_local(struct module *me, void *loc)
7150@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7151 }
7152
7153 /* align things a bit */
7154- me->core_size = ALIGN(me->core_size, 16);
7155- me->arch.got_offset = me->core_size;
7156- me->core_size += gots * sizeof(struct got_entry);
7157+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7158+ me->arch.got_offset = me->core_size_rw;
7159+ me->core_size_rw += gots * sizeof(struct got_entry);
7160
7161- me->core_size = ALIGN(me->core_size, 16);
7162- me->arch.fdesc_offset = me->core_size;
7163- me->core_size += fdescs * sizeof(Elf_Fdesc);
7164+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7165+ me->arch.fdesc_offset = me->core_size_rw;
7166+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7167
7168 me->arch.got_max = gots;
7169 me->arch.fdesc_max = fdescs;
7170@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7171
7172 BUG_ON(value == 0);
7173
7174- got = me->module_core + me->arch.got_offset;
7175+ got = me->module_core_rw + me->arch.got_offset;
7176 for (i = 0; got[i].addr; i++)
7177 if (got[i].addr == value)
7178 goto out;
7179@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7180 #ifdef CONFIG_64BIT
7181 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7182 {
7183- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7184+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7185
7186 if (!value) {
7187 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7188@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7189
7190 /* Create new one */
7191 fdesc->addr = value;
7192- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7193+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7194 return (Elf_Addr)fdesc;
7195 }
7196 #endif /* CONFIG_64BIT */
7197@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7198
7199 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7200 end = table + sechdrs[me->arch.unwind_section].sh_size;
7201- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7202+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7203
7204 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7205 me->arch.unwind_section, table, end, gp);
7206diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7207index 5dfd248..64914ac 100644
7208--- a/arch/parisc/kernel/sys_parisc.c
7209+++ b/arch/parisc/kernel/sys_parisc.c
7210@@ -33,9 +33,11 @@
7211 #include <linux/utsname.h>
7212 #include <linux/personality.h>
7213
7214-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7215+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7216+ unsigned long flags)
7217 {
7218 struct vm_unmapped_area_info info;
7219+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7220
7221 info.flags = 0;
7222 info.length = len;
7223@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7224 info.high_limit = TASK_SIZE;
7225 info.align_mask = 0;
7226 info.align_offset = 0;
7227+ info.threadstack_offset = offset;
7228 return vm_unmapped_area(&info);
7229 }
7230
7231@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7232 return (unsigned long) mapping >> 8;
7233 }
7234
7235-static unsigned long get_shared_area(struct address_space *mapping,
7236- unsigned long addr, unsigned long len, unsigned long pgoff)
7237+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7238+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7239 {
7240 struct vm_unmapped_area_info info;
7241+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7242
7243 info.flags = 0;
7244 info.length = len;
7245@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7246 info.high_limit = TASK_SIZE;
7247 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7248 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7249+ info.threadstack_offset = offset;
7250 return vm_unmapped_area(&info);
7251 }
7252
7253@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7254 return -EINVAL;
7255 return addr;
7256 }
7257- if (!addr)
7258+ if (!addr) {
7259 addr = TASK_UNMAPPED_BASE;
7260
7261+#ifdef CONFIG_PAX_RANDMMAP
7262+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7263+ addr += current->mm->delta_mmap;
7264+#endif
7265+
7266+ }
7267+
7268 if (filp) {
7269- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7270+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7271 } else if(flags & MAP_SHARED) {
7272- addr = get_shared_area(NULL, addr, len, pgoff);
7273+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7274 } else {
7275- addr = get_unshared_area(addr, len);
7276+ addr = get_unshared_area(filp, addr, len, flags);
7277 }
7278 return addr;
7279 }
7280diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7281index b3f87a3..5d5d03d 100644
7282--- a/arch/parisc/kernel/traps.c
7283+++ b/arch/parisc/kernel/traps.c
7284@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7285
7286 down_read(&current->mm->mmap_sem);
7287 vma = find_vma(current->mm,regs->iaoq[0]);
7288- if (vma && (regs->iaoq[0] >= vma->vm_start)
7289- && (vma->vm_flags & VM_EXEC)) {
7290-
7291+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7292 fault_address = regs->iaoq[0];
7293 fault_space = regs->iasq[0];
7294
7295diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7296index f247a34..dc0f219 100644
7297--- a/arch/parisc/mm/fault.c
7298+++ b/arch/parisc/mm/fault.c
7299@@ -15,6 +15,7 @@
7300 #include <linux/sched.h>
7301 #include <linux/interrupt.h>
7302 #include <linux/module.h>
7303+#include <linux/unistd.h>
7304
7305 #include <asm/uaccess.h>
7306 #include <asm/traps.h>
7307@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7308 static unsigned long
7309 parisc_acctyp(unsigned long code, unsigned int inst)
7310 {
7311- if (code == 6 || code == 16)
7312+ if (code == 6 || code == 7 || code == 16)
7313 return VM_EXEC;
7314
7315 switch (inst & 0xf0000000) {
7316@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7317 }
7318 #endif
7319
7320+#ifdef CONFIG_PAX_PAGEEXEC
7321+/*
7322+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7323+ *
7324+ * returns 1 when task should be killed
7325+ * 2 when rt_sigreturn trampoline was detected
7326+ * 3 when unpatched PLT trampoline was detected
7327+ */
7328+static int pax_handle_fetch_fault(struct pt_regs *regs)
7329+{
7330+
7331+#ifdef CONFIG_PAX_EMUPLT
7332+ int err;
7333+
7334+ do { /* PaX: unpatched PLT emulation */
7335+ unsigned int bl, depwi;
7336+
7337+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7338+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7339+
7340+ if (err)
7341+ break;
7342+
7343+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7344+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7345+
7346+ err = get_user(ldw, (unsigned int *)addr);
7347+ err |= get_user(bv, (unsigned int *)(addr+4));
7348+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7349+
7350+ if (err)
7351+ break;
7352+
7353+ if (ldw == 0x0E801096U &&
7354+ bv == 0xEAC0C000U &&
7355+ ldw2 == 0x0E881095U)
7356+ {
7357+ unsigned int resolver, map;
7358+
7359+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7360+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7361+ if (err)
7362+ break;
7363+
7364+ regs->gr[20] = instruction_pointer(regs)+8;
7365+ regs->gr[21] = map;
7366+ regs->gr[22] = resolver;
7367+ regs->iaoq[0] = resolver | 3UL;
7368+ regs->iaoq[1] = regs->iaoq[0] + 4;
7369+ return 3;
7370+ }
7371+ }
7372+ } while (0);
7373+#endif
7374+
7375+#ifdef CONFIG_PAX_EMUTRAMP
7376+
7377+#ifndef CONFIG_PAX_EMUSIGRT
7378+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7379+ return 1;
7380+#endif
7381+
7382+ do { /* PaX: rt_sigreturn emulation */
7383+ unsigned int ldi1, ldi2, bel, nop;
7384+
7385+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7386+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7387+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7388+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7389+
7390+ if (err)
7391+ break;
7392+
7393+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7394+ ldi2 == 0x3414015AU &&
7395+ bel == 0xE4008200U &&
7396+ nop == 0x08000240U)
7397+ {
7398+ regs->gr[25] = (ldi1 & 2) >> 1;
7399+ regs->gr[20] = __NR_rt_sigreturn;
7400+ regs->gr[31] = regs->iaoq[1] + 16;
7401+ regs->sr[0] = regs->iasq[1];
7402+ regs->iaoq[0] = 0x100UL;
7403+ regs->iaoq[1] = regs->iaoq[0] + 4;
7404+ regs->iasq[0] = regs->sr[2];
7405+ regs->iasq[1] = regs->sr[2];
7406+ return 2;
7407+ }
7408+ } while (0);
7409+#endif
7410+
7411+ return 1;
7412+}
7413+
7414+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7415+{
7416+ unsigned long i;
7417+
7418+ printk(KERN_ERR "PAX: bytes at PC: ");
7419+ for (i = 0; i < 5; i++) {
7420+ unsigned int c;
7421+ if (get_user(c, (unsigned int *)pc+i))
7422+ printk(KERN_CONT "???????? ");
7423+ else
7424+ printk(KERN_CONT "%08x ", c);
7425+ }
7426+ printk("\n");
7427+}
7428+#endif
7429+
7430 int fixup_exception(struct pt_regs *regs)
7431 {
7432 const struct exception_table_entry *fix;
7433@@ -194,8 +305,33 @@ good_area:
7434
7435 acc_type = parisc_acctyp(code,regs->iir);
7436
7437- if ((vma->vm_flags & acc_type) != acc_type)
7438+ if ((vma->vm_flags & acc_type) != acc_type) {
7439+
7440+#ifdef CONFIG_PAX_PAGEEXEC
7441+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7442+ (address & ~3UL) == instruction_pointer(regs))
7443+ {
7444+ up_read(&mm->mmap_sem);
7445+ switch (pax_handle_fetch_fault(regs)) {
7446+
7447+#ifdef CONFIG_PAX_EMUPLT
7448+ case 3:
7449+ return;
7450+#endif
7451+
7452+#ifdef CONFIG_PAX_EMUTRAMP
7453+ case 2:
7454+ return;
7455+#endif
7456+
7457+ }
7458+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7459+ do_group_exit(SIGKILL);
7460+ }
7461+#endif
7462+
7463 goto bad_area;
7464+ }
7465
7466 /*
7467 * If for any reason at all we couldn't handle the fault, make
7468diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7469index e3b1d41..8e81edf 100644
7470--- a/arch/powerpc/include/asm/atomic.h
7471+++ b/arch/powerpc/include/asm/atomic.h
7472@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7473 return t1;
7474 }
7475
7476+#define atomic64_read_unchecked(v) atomic64_read(v)
7477+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7478+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7479+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7480+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7481+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7482+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7483+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7484+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7485+
7486 #endif /* __powerpc64__ */
7487
7488 #endif /* __KERNEL__ */
7489diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7490index 9e495c9..b6878e5 100644
7491--- a/arch/powerpc/include/asm/cache.h
7492+++ b/arch/powerpc/include/asm/cache.h
7493@@ -3,6 +3,7 @@
7494
7495 #ifdef __KERNEL__
7496
7497+#include <linux/const.h>
7498
7499 /* bytes per L1 cache line */
7500 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7501@@ -22,7 +23,7 @@
7502 #define L1_CACHE_SHIFT 7
7503 #endif
7504
7505-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7506+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7507
7508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7509
7510diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7511index cc0655a..13eac2e 100644
7512--- a/arch/powerpc/include/asm/elf.h
7513+++ b/arch/powerpc/include/asm/elf.h
7514@@ -28,8 +28,19 @@
7515 the loader. We need to make sure that it is out of the way of the program
7516 that it will "exec", and that there is sufficient room for the brk. */
7517
7518-extern unsigned long randomize_et_dyn(unsigned long base);
7519-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7520+#define ELF_ET_DYN_BASE (0x20000000)
7521+
7522+#ifdef CONFIG_PAX_ASLR
7523+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7524+
7525+#ifdef __powerpc64__
7526+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7527+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7528+#else
7529+#define PAX_DELTA_MMAP_LEN 15
7530+#define PAX_DELTA_STACK_LEN 15
7531+#endif
7532+#endif
7533
7534 /*
7535 * Our registers are always unsigned longs, whether we're a 32 bit
7536@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7537 (0x7ff >> (PAGE_SHIFT - 12)) : \
7538 (0x3ffff >> (PAGE_SHIFT - 12)))
7539
7540-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7541-#define arch_randomize_brk arch_randomize_brk
7542-
7543-
7544 #ifdef CONFIG_SPU_BASE
7545 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7546 #define NT_SPU 1
7547diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7548index 8196e9c..d83a9f3 100644
7549--- a/arch/powerpc/include/asm/exec.h
7550+++ b/arch/powerpc/include/asm/exec.h
7551@@ -4,6 +4,6 @@
7552 #ifndef _ASM_POWERPC_EXEC_H
7553 #define _ASM_POWERPC_EXEC_H
7554
7555-extern unsigned long arch_align_stack(unsigned long sp);
7556+#define arch_align_stack(x) ((x) & ~0xfUL)
7557
7558 #endif /* _ASM_POWERPC_EXEC_H */
7559diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7560index 5acabbd..7ea14fa 100644
7561--- a/arch/powerpc/include/asm/kmap_types.h
7562+++ b/arch/powerpc/include/asm/kmap_types.h
7563@@ -10,7 +10,7 @@
7564 * 2 of the License, or (at your option) any later version.
7565 */
7566
7567-#define KM_TYPE_NR 16
7568+#define KM_TYPE_NR 17
7569
7570 #endif /* __KERNEL__ */
7571 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7572diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7573index 8565c25..2865190 100644
7574--- a/arch/powerpc/include/asm/mman.h
7575+++ b/arch/powerpc/include/asm/mman.h
7576@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7577 }
7578 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7579
7580-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7581+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7582 {
7583 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7584 }
7585diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7586index b9f4262..dcf04f7 100644
7587--- a/arch/powerpc/include/asm/page.h
7588+++ b/arch/powerpc/include/asm/page.h
7589@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7590 * and needs to be executable. This means the whole heap ends
7591 * up being executable.
7592 */
7593-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7594- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7595+#define VM_DATA_DEFAULT_FLAGS32 \
7596+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7597+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7598
7599 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7600 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7601@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7602 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7603 #endif
7604
7605+#define ktla_ktva(addr) (addr)
7606+#define ktva_ktla(addr) (addr)
7607+
7608 #ifndef CONFIG_PPC_BOOK3S_64
7609 /*
7610 * Use the top bit of the higher-level page table entries to indicate whether
7611diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7612index 88693ce..ac6f9ab 100644
7613--- a/arch/powerpc/include/asm/page_64.h
7614+++ b/arch/powerpc/include/asm/page_64.h
7615@@ -153,15 +153,18 @@ do { \
7616 * stack by default, so in the absence of a PT_GNU_STACK program header
7617 * we turn execute permission off.
7618 */
7619-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7620- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7621+#define VM_STACK_DEFAULT_FLAGS32 \
7622+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7623+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7624
7625 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7626 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7627
7628+#ifndef CONFIG_PAX_PAGEEXEC
7629 #define VM_STACK_DEFAULT_FLAGS \
7630 (is_32bit_task() ? \
7631 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7632+#endif
7633
7634 #include <asm-generic/getorder.h>
7635
7636diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7637index f65e27b..23ffb5b 100644
7638--- a/arch/powerpc/include/asm/pgalloc-64.h
7639+++ b/arch/powerpc/include/asm/pgalloc-64.h
7640@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7641 #ifndef CONFIG_PPC_64K_PAGES
7642
7643 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7644+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7645
7646 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7647 {
7648@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7649 pud_set(pud, (unsigned long)pmd);
7650 }
7651
7652+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7653+{
7654+ pud_populate(mm, pud, pmd);
7655+}
7656+
7657 #define pmd_populate(mm, pmd, pte_page) \
7658 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7659 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7660@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7661 #endif
7662
7663 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7664+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7665
7666 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7667 pte_t *pte)
7668diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7669index 7d6eacf..14c0240 100644
7670--- a/arch/powerpc/include/asm/pgtable.h
7671+++ b/arch/powerpc/include/asm/pgtable.h
7672@@ -2,6 +2,7 @@
7673 #define _ASM_POWERPC_PGTABLE_H
7674 #ifdef __KERNEL__
7675
7676+#include <linux/const.h>
7677 #ifndef __ASSEMBLY__
7678 #include <asm/processor.h> /* For TASK_SIZE */
7679 #include <asm/mmu.h>
7680diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7681index 4aad413..85d86bf 100644
7682--- a/arch/powerpc/include/asm/pte-hash32.h
7683+++ b/arch/powerpc/include/asm/pte-hash32.h
7684@@ -21,6 +21,7 @@
7685 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7686 #define _PAGE_USER 0x004 /* usermode access allowed */
7687 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7688+#define _PAGE_EXEC _PAGE_GUARDED
7689 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7690 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7691 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7692diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7693index 99222e2..f629aef 100644
7694--- a/arch/powerpc/include/asm/reg.h
7695+++ b/arch/powerpc/include/asm/reg.h
7696@@ -234,6 +234,7 @@
7697 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7698 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7699 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7700+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7701 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7702 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7703 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7704diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7705index 48cfc85..891382f 100644
7706--- a/arch/powerpc/include/asm/smp.h
7707+++ b/arch/powerpc/include/asm/smp.h
7708@@ -50,7 +50,7 @@ struct smp_ops_t {
7709 int (*cpu_disable)(void);
7710 void (*cpu_die)(unsigned int nr);
7711 int (*cpu_bootable)(unsigned int nr);
7712-};
7713+} __no_const;
7714
7715 extern void smp_send_debugger_break(void);
7716 extern void start_secondary_resume(void);
7717diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7718index ba7b197..d292e26 100644
7719--- a/arch/powerpc/include/asm/thread_info.h
7720+++ b/arch/powerpc/include/asm/thread_info.h
7721@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7722 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7723 TIF_NEED_RESCHED */
7724 #define TIF_32BIT 4 /* 32 bit binary */
7725-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7726 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7727 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7728 #define TIF_SINGLESTEP 8 /* singlestepping active */
7729@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7730 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7731 for stack store? */
7732 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7733+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7734+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7735+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7736
7737 /* as above, but as bit values */
7738 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7739@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7740 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7741 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7742 #define _TIF_NOHZ (1<<TIF_NOHZ)
7743+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7744 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7745 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7746- _TIF_NOHZ)
7747+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7748
7749 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7750 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7751diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7752index 9485b43..4718d50 100644
7753--- a/arch/powerpc/include/asm/uaccess.h
7754+++ b/arch/powerpc/include/asm/uaccess.h
7755@@ -318,52 +318,6 @@ do { \
7756 extern unsigned long __copy_tofrom_user(void __user *to,
7757 const void __user *from, unsigned long size);
7758
7759-#ifndef __powerpc64__
7760-
7761-static inline unsigned long copy_from_user(void *to,
7762- const void __user *from, unsigned long n)
7763-{
7764- unsigned long over;
7765-
7766- if (access_ok(VERIFY_READ, from, n))
7767- return __copy_tofrom_user((__force void __user *)to, from, n);
7768- if ((unsigned long)from < TASK_SIZE) {
7769- over = (unsigned long)from + n - TASK_SIZE;
7770- return __copy_tofrom_user((__force void __user *)to, from,
7771- n - over) + over;
7772- }
7773- return n;
7774-}
7775-
7776-static inline unsigned long copy_to_user(void __user *to,
7777- const void *from, unsigned long n)
7778-{
7779- unsigned long over;
7780-
7781- if (access_ok(VERIFY_WRITE, to, n))
7782- return __copy_tofrom_user(to, (__force void __user *)from, n);
7783- if ((unsigned long)to < TASK_SIZE) {
7784- over = (unsigned long)to + n - TASK_SIZE;
7785- return __copy_tofrom_user(to, (__force void __user *)from,
7786- n - over) + over;
7787- }
7788- return n;
7789-}
7790-
7791-#else /* __powerpc64__ */
7792-
7793-#define __copy_in_user(to, from, size) \
7794- __copy_tofrom_user((to), (from), (size))
7795-
7796-extern unsigned long copy_from_user(void *to, const void __user *from,
7797- unsigned long n);
7798-extern unsigned long copy_to_user(void __user *to, const void *from,
7799- unsigned long n);
7800-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7801- unsigned long n);
7802-
7803-#endif /* __powerpc64__ */
7804-
7805 static inline unsigned long __copy_from_user_inatomic(void *to,
7806 const void __user *from, unsigned long n)
7807 {
7808@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7809 if (ret == 0)
7810 return 0;
7811 }
7812+
7813+ if (!__builtin_constant_p(n))
7814+ check_object_size(to, n, false);
7815+
7816 return __copy_tofrom_user((__force void __user *)to, from, n);
7817 }
7818
7819@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7820 if (ret == 0)
7821 return 0;
7822 }
7823+
7824+ if (!__builtin_constant_p(n))
7825+ check_object_size(from, n, true);
7826+
7827 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7828 }
7829
7830@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7831 return __copy_to_user_inatomic(to, from, size);
7832 }
7833
7834+#ifndef __powerpc64__
7835+
7836+static inline unsigned long __must_check copy_from_user(void *to,
7837+ const void __user *from, unsigned long n)
7838+{
7839+ unsigned long over;
7840+
7841+ if ((long)n < 0)
7842+ return n;
7843+
7844+ if (access_ok(VERIFY_READ, from, n)) {
7845+ if (!__builtin_constant_p(n))
7846+ check_object_size(to, n, false);
7847+ return __copy_tofrom_user((__force void __user *)to, from, n);
7848+ }
7849+ if ((unsigned long)from < TASK_SIZE) {
7850+ over = (unsigned long)from + n - TASK_SIZE;
7851+ if (!__builtin_constant_p(n - over))
7852+ check_object_size(to, n - over, false);
7853+ return __copy_tofrom_user((__force void __user *)to, from,
7854+ n - over) + over;
7855+ }
7856+ return n;
7857+}
7858+
7859+static inline unsigned long __must_check copy_to_user(void __user *to,
7860+ const void *from, unsigned long n)
7861+{
7862+ unsigned long over;
7863+
7864+ if ((long)n < 0)
7865+ return n;
7866+
7867+ if (access_ok(VERIFY_WRITE, to, n)) {
7868+ if (!__builtin_constant_p(n))
7869+ check_object_size(from, n, true);
7870+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7871+ }
7872+ if ((unsigned long)to < TASK_SIZE) {
7873+ over = (unsigned long)to + n - TASK_SIZE;
7874+ if (!__builtin_constant_p(n))
7875+ check_object_size(from, n - over, true);
7876+ return __copy_tofrom_user(to, (__force void __user *)from,
7877+ n - over) + over;
7878+ }
7879+ return n;
7880+}
7881+
7882+#else /* __powerpc64__ */
7883+
7884+#define __copy_in_user(to, from, size) \
7885+ __copy_tofrom_user((to), (from), (size))
7886+
7887+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7888+{
7889+ if ((long)n < 0 || n > INT_MAX)
7890+ return n;
7891+
7892+ if (!__builtin_constant_p(n))
7893+ check_object_size(to, n, false);
7894+
7895+ if (likely(access_ok(VERIFY_READ, from, n)))
7896+ n = __copy_from_user(to, from, n);
7897+ else
7898+ memset(to, 0, n);
7899+ return n;
7900+}
7901+
7902+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7903+{
7904+ if ((long)n < 0 || n > INT_MAX)
7905+ return n;
7906+
7907+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7908+ if (!__builtin_constant_p(n))
7909+ check_object_size(from, n, true);
7910+ n = __copy_to_user(to, from, n);
7911+ }
7912+ return n;
7913+}
7914+
7915+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7916+ unsigned long n);
7917+
7918+#endif /* __powerpc64__ */
7919+
7920 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7921
7922 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7923diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7924index 645170a..6cf0271 100644
7925--- a/arch/powerpc/kernel/exceptions-64e.S
7926+++ b/arch/powerpc/kernel/exceptions-64e.S
7927@@ -757,6 +757,7 @@ storage_fault_common:
7928 std r14,_DAR(r1)
7929 std r15,_DSISR(r1)
7930 addi r3,r1,STACK_FRAME_OVERHEAD
7931+ bl .save_nvgprs
7932 mr r4,r14
7933 mr r5,r15
7934 ld r14,PACA_EXGEN+EX_R14(r13)
7935@@ -765,8 +766,7 @@ storage_fault_common:
7936 cmpdi r3,0
7937 bne- 1f
7938 b .ret_from_except_lite
7939-1: bl .save_nvgprs
7940- mr r5,r3
7941+1: mr r5,r3
7942 addi r3,r1,STACK_FRAME_OVERHEAD
7943 ld r4,_DAR(r1)
7944 bl .bad_page_fault
7945diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7946index 902ca3c..e942155 100644
7947--- a/arch/powerpc/kernel/exceptions-64s.S
7948+++ b/arch/powerpc/kernel/exceptions-64s.S
7949@@ -1357,10 +1357,10 @@ handle_page_fault:
7950 11: ld r4,_DAR(r1)
7951 ld r5,_DSISR(r1)
7952 addi r3,r1,STACK_FRAME_OVERHEAD
7953+ bl .save_nvgprs
7954 bl .do_page_fault
7955 cmpdi r3,0
7956 beq+ 12f
7957- bl .save_nvgprs
7958 mr r5,r3
7959 addi r3,r1,STACK_FRAME_OVERHEAD
7960 lwz r4,_DAR(r1)
7961diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7962index 2e3200c..72095ce 100644
7963--- a/arch/powerpc/kernel/module_32.c
7964+++ b/arch/powerpc/kernel/module_32.c
7965@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7966 me->arch.core_plt_section = i;
7967 }
7968 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7969- printk("Module doesn't contain .plt or .init.plt sections.\n");
7970+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7971 return -ENOEXEC;
7972 }
7973
7974@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7975
7976 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7977 /* Init, or core PLT? */
7978- if (location >= mod->module_core
7979- && location < mod->module_core + mod->core_size)
7980+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7981+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7982 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7983- else
7984+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7985+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7986 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7987+ else {
7988+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7989+ return ~0UL;
7990+ }
7991
7992 /* Find this entry, or if that fails, the next avail. entry */
7993 while (entry->jump[0]) {
7994diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7995index 8083be2..10aa352 100644
7996--- a/arch/powerpc/kernel/process.c
7997+++ b/arch/powerpc/kernel/process.c
7998@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7999 * Lookup NIP late so we have the best change of getting the
8000 * above info out without failing
8001 */
8002- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8003- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8004+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8005+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8006 #endif
8007 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8008 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8009@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8010 newsp = stack[0];
8011 ip = stack[STACK_FRAME_LR_SAVE];
8012 if (!firstframe || ip != lr) {
8013- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8014+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8015 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8016 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8017- printk(" (%pS)",
8018+ printk(" (%pA)",
8019 (void *)current->ret_stack[curr_frame].ret);
8020 curr_frame--;
8021 }
8022@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8023 struct pt_regs *regs = (struct pt_regs *)
8024 (sp + STACK_FRAME_OVERHEAD);
8025 lr = regs->link;
8026- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8027+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8028 regs->trap, (void *)regs->nip, (void *)lr);
8029 firstframe = 1;
8030 }
8031@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
8032 mtspr(SPRN_CTRLT, ctrl);
8033 }
8034 #endif /* CONFIG_PPC64 */
8035-
8036-unsigned long arch_align_stack(unsigned long sp)
8037-{
8038- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8039- sp -= get_random_int() & ~PAGE_MASK;
8040- return sp & ~0xf;
8041-}
8042-
8043-static inline unsigned long brk_rnd(void)
8044-{
8045- unsigned long rnd = 0;
8046-
8047- /* 8MB for 32bit, 1GB for 64bit */
8048- if (is_32bit_task())
8049- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8050- else
8051- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8052-
8053- return rnd << PAGE_SHIFT;
8054-}
8055-
8056-unsigned long arch_randomize_brk(struct mm_struct *mm)
8057-{
8058- unsigned long base = mm->brk;
8059- unsigned long ret;
8060-
8061-#ifdef CONFIG_PPC_STD_MMU_64
8062- /*
8063- * If we are using 1TB segments and we are allowed to randomise
8064- * the heap, we can put it above 1TB so it is backed by a 1TB
8065- * segment. Otherwise the heap will be in the bottom 1TB
8066- * which always uses 256MB segments and this may result in a
8067- * performance penalty.
8068- */
8069- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8070- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8071-#endif
8072-
8073- ret = PAGE_ALIGN(base + brk_rnd());
8074-
8075- if (ret < mm->brk)
8076- return mm->brk;
8077-
8078- return ret;
8079-}
8080-
8081-unsigned long randomize_et_dyn(unsigned long base)
8082-{
8083- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8084-
8085- if (ret < base)
8086- return base;
8087-
8088- return ret;
8089-}
8090diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8091index 9a0d24c..e7fbedf 100644
8092--- a/arch/powerpc/kernel/ptrace.c
8093+++ b/arch/powerpc/kernel/ptrace.c
8094@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8095 return ret;
8096 }
8097
8098+#ifdef CONFIG_GRKERNSEC_SETXID
8099+extern void gr_delayed_cred_worker(void);
8100+#endif
8101+
8102 /*
8103 * We must return the syscall number to actually look up in the table.
8104 * This can be -1L to skip running any syscall at all.
8105@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8106
8107 secure_computing_strict(regs->gpr[0]);
8108
8109+#ifdef CONFIG_GRKERNSEC_SETXID
8110+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8111+ gr_delayed_cred_worker();
8112+#endif
8113+
8114 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8115 tracehook_report_syscall_entry(regs))
8116 /*
8117@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8118 {
8119 int step;
8120
8121+#ifdef CONFIG_GRKERNSEC_SETXID
8122+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8123+ gr_delayed_cred_worker();
8124+#endif
8125+
8126 audit_syscall_exit(regs);
8127
8128 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8129diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8130index 0f83122..c0aca6a 100644
8131--- a/arch/powerpc/kernel/signal_32.c
8132+++ b/arch/powerpc/kernel/signal_32.c
8133@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8134 /* Save user registers on the stack */
8135 frame = &rt_sf->uc.uc_mcontext;
8136 addr = frame;
8137- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8138+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8139 sigret = 0;
8140 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8141 } else {
8142diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8143index 887e99d..310bc11 100644
8144--- a/arch/powerpc/kernel/signal_64.c
8145+++ b/arch/powerpc/kernel/signal_64.c
8146@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8147 #endif
8148
8149 /* Set up to return from userspace. */
8150- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8151+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8152 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8153 } else {
8154 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8155diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8156index e435bc0..41c2964 100644
8157--- a/arch/powerpc/kernel/traps.c
8158+++ b/arch/powerpc/kernel/traps.c
8159@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8160 return flags;
8161 }
8162
8163+extern void gr_handle_kernel_exploit(void);
8164+
8165 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8166 int signr)
8167 {
8168@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8169 panic("Fatal exception in interrupt");
8170 if (panic_on_oops)
8171 panic("Fatal exception");
8172+
8173+ gr_handle_kernel_exploit();
8174+
8175 do_exit(signr);
8176 }
8177
8178diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8179index 1d9c926..25f4741 100644
8180--- a/arch/powerpc/kernel/vdso.c
8181+++ b/arch/powerpc/kernel/vdso.c
8182@@ -34,6 +34,7 @@
8183 #include <asm/firmware.h>
8184 #include <asm/vdso.h>
8185 #include <asm/vdso_datapage.h>
8186+#include <asm/mman.h>
8187
8188 #include "setup.h"
8189
8190@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8191 vdso_base = VDSO32_MBASE;
8192 #endif
8193
8194- current->mm->context.vdso_base = 0;
8195+ current->mm->context.vdso_base = ~0UL;
8196
8197 /* vDSO has a problem and was disabled, just don't "enable" it for the
8198 * process
8199@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8200 vdso_base = get_unmapped_area(NULL, vdso_base,
8201 (vdso_pages << PAGE_SHIFT) +
8202 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8203- 0, 0);
8204+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8205 if (IS_ERR_VALUE(vdso_base)) {
8206 rc = vdso_base;
8207 goto fail_mmapsem;
8208diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8209index 5eea6f3..5d10396 100644
8210--- a/arch/powerpc/lib/usercopy_64.c
8211+++ b/arch/powerpc/lib/usercopy_64.c
8212@@ -9,22 +9,6 @@
8213 #include <linux/module.h>
8214 #include <asm/uaccess.h>
8215
8216-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8217-{
8218- if (likely(access_ok(VERIFY_READ, from, n)))
8219- n = __copy_from_user(to, from, n);
8220- else
8221- memset(to, 0, n);
8222- return n;
8223-}
8224-
8225-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8226-{
8227- if (likely(access_ok(VERIFY_WRITE, to, n)))
8228- n = __copy_to_user(to, from, n);
8229- return n;
8230-}
8231-
8232 unsigned long copy_in_user(void __user *to, const void __user *from,
8233 unsigned long n)
8234 {
8235@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8236 return n;
8237 }
8238
8239-EXPORT_SYMBOL(copy_from_user);
8240-EXPORT_SYMBOL(copy_to_user);
8241 EXPORT_SYMBOL(copy_in_user);
8242
8243diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8244index 8726779..a33c512 100644
8245--- a/arch/powerpc/mm/fault.c
8246+++ b/arch/powerpc/mm/fault.c
8247@@ -33,6 +33,10 @@
8248 #include <linux/magic.h>
8249 #include <linux/ratelimit.h>
8250 #include <linux/context_tracking.h>
8251+#include <linux/slab.h>
8252+#include <linux/pagemap.h>
8253+#include <linux/compiler.h>
8254+#include <linux/unistd.h>
8255
8256 #include <asm/firmware.h>
8257 #include <asm/page.h>
8258@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8259 }
8260 #endif
8261
8262+#ifdef CONFIG_PAX_PAGEEXEC
8263+/*
8264+ * PaX: decide what to do with offenders (regs->nip = fault address)
8265+ *
8266+ * returns 1 when task should be killed
8267+ */
8268+static int pax_handle_fetch_fault(struct pt_regs *regs)
8269+{
8270+ return 1;
8271+}
8272+
8273+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8274+{
8275+ unsigned long i;
8276+
8277+ printk(KERN_ERR "PAX: bytes at PC: ");
8278+ for (i = 0; i < 5; i++) {
8279+ unsigned int c;
8280+ if (get_user(c, (unsigned int __user *)pc+i))
8281+ printk(KERN_CONT "???????? ");
8282+ else
8283+ printk(KERN_CONT "%08x ", c);
8284+ }
8285+ printk("\n");
8286+}
8287+#endif
8288+
8289 /*
8290 * Check whether the instruction at regs->nip is a store using
8291 * an update addressing form which will update r1.
8292@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8293 * indicate errors in DSISR but can validly be set in SRR1.
8294 */
8295 if (trap == 0x400)
8296- error_code &= 0x48200000;
8297+ error_code &= 0x58200000;
8298 else
8299 is_write = error_code & DSISR_ISSTORE;
8300 #else
8301@@ -371,7 +402,7 @@ good_area:
8302 * "undefined". Of those that can be set, this is the only
8303 * one which seems bad.
8304 */
8305- if (error_code & 0x10000000)
8306+ if (error_code & DSISR_GUARDED)
8307 /* Guarded storage error. */
8308 goto bad_area;
8309 #endif /* CONFIG_8xx */
8310@@ -386,7 +417,7 @@ good_area:
8311 * processors use the same I/D cache coherency mechanism
8312 * as embedded.
8313 */
8314- if (error_code & DSISR_PROTFAULT)
8315+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8316 goto bad_area;
8317 #endif /* CONFIG_PPC_STD_MMU */
8318
8319@@ -471,6 +502,23 @@ bad_area:
8320 bad_area_nosemaphore:
8321 /* User mode accesses cause a SIGSEGV */
8322 if (user_mode(regs)) {
8323+
8324+#ifdef CONFIG_PAX_PAGEEXEC
8325+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8326+#ifdef CONFIG_PPC_STD_MMU
8327+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8328+#else
8329+ if (is_exec && regs->nip == address) {
8330+#endif
8331+ switch (pax_handle_fetch_fault(regs)) {
8332+ }
8333+
8334+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8335+ do_group_exit(SIGKILL);
8336+ }
8337+ }
8338+#endif
8339+
8340 _exception(SIGSEGV, regs, code, address);
8341 goto bail;
8342 }
8343diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8344index cb8bdbe..d770680 100644
8345--- a/arch/powerpc/mm/mmap.c
8346+++ b/arch/powerpc/mm/mmap.c
8347@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8348 {
8349 unsigned long rnd = 0;
8350
8351+#ifdef CONFIG_PAX_RANDMMAP
8352+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8353+#endif
8354+
8355 if (current->flags & PF_RANDOMIZE) {
8356 /* 8MB for 32bit, 1GB for 64bit */
8357 if (is_32bit_task())
8358@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8359 */
8360 if (mmap_is_legacy()) {
8361 mm->mmap_base = TASK_UNMAPPED_BASE;
8362+
8363+#ifdef CONFIG_PAX_RANDMMAP
8364+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8365+ mm->mmap_base += mm->delta_mmap;
8366+#endif
8367+
8368 mm->get_unmapped_area = arch_get_unmapped_area;
8369 } else {
8370 mm->mmap_base = mmap_base();
8371+
8372+#ifdef CONFIG_PAX_RANDMMAP
8373+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8374+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8375+#endif
8376+
8377 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8378 }
8379 }
8380diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8381index 3e99c14..f00953c 100644
8382--- a/arch/powerpc/mm/slice.c
8383+++ b/arch/powerpc/mm/slice.c
8384@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8385 if ((mm->task_size - len) < addr)
8386 return 0;
8387 vma = find_vma(mm, addr);
8388- return (!vma || (addr + len) <= vma->vm_start);
8389+ return check_heap_stack_gap(vma, addr, len, 0);
8390 }
8391
8392 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8393@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8394 info.align_offset = 0;
8395
8396 addr = TASK_UNMAPPED_BASE;
8397+
8398+#ifdef CONFIG_PAX_RANDMMAP
8399+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8400+ addr += mm->delta_mmap;
8401+#endif
8402+
8403 while (addr < TASK_SIZE) {
8404 info.low_limit = addr;
8405 if (!slice_scan_available(addr, available, 1, &addr))
8406@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8407 if (fixed && addr > (mm->task_size - len))
8408 return -EINVAL;
8409
8410+#ifdef CONFIG_PAX_RANDMMAP
8411+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8412+ addr = 0;
8413+#endif
8414+
8415 /* If hint, make sure it matches our alignment restrictions */
8416 if (!fixed && addr) {
8417 addr = _ALIGN_UP(addr, 1ul << pshift);
8418diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8419index 9098692..3d54cd1 100644
8420--- a/arch/powerpc/platforms/cell/spufs/file.c
8421+++ b/arch/powerpc/platforms/cell/spufs/file.c
8422@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8423 return VM_FAULT_NOPAGE;
8424 }
8425
8426-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8427+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8428 unsigned long address,
8429- void *buf, int len, int write)
8430+ void *buf, size_t len, int write)
8431 {
8432 struct spu_context *ctx = vma->vm_file->private_data;
8433 unsigned long offset = address - vma->vm_start;
8434diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8435index c797832..ce575c8 100644
8436--- a/arch/s390/include/asm/atomic.h
8437+++ b/arch/s390/include/asm/atomic.h
8438@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8439 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8441
8442+#define atomic64_read_unchecked(v) atomic64_read(v)
8443+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8444+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8445+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8446+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8447+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8448+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8449+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8450+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8451+
8452 #define smp_mb__before_atomic_dec() smp_mb()
8453 #define smp_mb__after_atomic_dec() smp_mb()
8454 #define smp_mb__before_atomic_inc() smp_mb()
8455diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8456index 4d7ccac..d03d0ad 100644
8457--- a/arch/s390/include/asm/cache.h
8458+++ b/arch/s390/include/asm/cache.h
8459@@ -9,8 +9,10 @@
8460 #ifndef __ARCH_S390_CACHE_H
8461 #define __ARCH_S390_CACHE_H
8462
8463-#define L1_CACHE_BYTES 256
8464+#include <linux/const.h>
8465+
8466 #define L1_CACHE_SHIFT 8
8467+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8468 #define NET_SKB_PAD 32
8469
8470 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8471diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8472index 78f4f87..598ce39 100644
8473--- a/arch/s390/include/asm/elf.h
8474+++ b/arch/s390/include/asm/elf.h
8475@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8476 the loader. We need to make sure that it is out of the way of the program
8477 that it will "exec", and that there is sufficient room for the brk. */
8478
8479-extern unsigned long randomize_et_dyn(unsigned long base);
8480-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8481+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8482+
8483+#ifdef CONFIG_PAX_ASLR
8484+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8485+
8486+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8487+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8488+#endif
8489
8490 /* This yields a mask that user programs can use to figure out what
8491 instruction set this CPU supports. */
8492@@ -222,9 +228,6 @@ struct linux_binprm;
8493 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8494 int arch_setup_additional_pages(struct linux_binprm *, int);
8495
8496-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8497-#define arch_randomize_brk arch_randomize_brk
8498-
8499 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8500
8501 #endif
8502diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8503index c4a93d6..4d2a9b4 100644
8504--- a/arch/s390/include/asm/exec.h
8505+++ b/arch/s390/include/asm/exec.h
8506@@ -7,6 +7,6 @@
8507 #ifndef __ASM_EXEC_H
8508 #define __ASM_EXEC_H
8509
8510-extern unsigned long arch_align_stack(unsigned long sp);
8511+#define arch_align_stack(x) ((x) & ~0xfUL)
8512
8513 #endif /* __ASM_EXEC_H */
8514diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8515index 9c33ed4..e40cbef 100644
8516--- a/arch/s390/include/asm/uaccess.h
8517+++ b/arch/s390/include/asm/uaccess.h
8518@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8519 copy_to_user(void __user *to, const void *from, unsigned long n)
8520 {
8521 might_fault();
8522+
8523+ if ((long)n < 0)
8524+ return n;
8525+
8526 return __copy_to_user(to, from, n);
8527 }
8528
8529@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8530 static inline unsigned long __must_check
8531 __copy_from_user(void *to, const void __user *from, unsigned long n)
8532 {
8533+ if ((long)n < 0)
8534+ return n;
8535+
8536 if (__builtin_constant_p(n) && (n <= 256))
8537 return uaccess.copy_from_user_small(n, from, to);
8538 else
8539@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8540 static inline unsigned long __must_check
8541 copy_from_user(void *to, const void __user *from, unsigned long n)
8542 {
8543- unsigned int sz = __compiletime_object_size(to);
8544+ size_t sz = __compiletime_object_size(to);
8545
8546 might_fault();
8547- if (unlikely(sz != -1 && sz < n)) {
8548+
8549+ if ((long)n < 0)
8550+ return n;
8551+
8552+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8553 copy_from_user_overflow();
8554 return n;
8555 }
8556diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8557index 7845e15..59c4353 100644
8558--- a/arch/s390/kernel/module.c
8559+++ b/arch/s390/kernel/module.c
8560@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8561
8562 /* Increase core size by size of got & plt and set start
8563 offsets for got and plt. */
8564- me->core_size = ALIGN(me->core_size, 4);
8565- me->arch.got_offset = me->core_size;
8566- me->core_size += me->arch.got_size;
8567- me->arch.plt_offset = me->core_size;
8568- me->core_size += me->arch.plt_size;
8569+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8570+ me->arch.got_offset = me->core_size_rw;
8571+ me->core_size_rw += me->arch.got_size;
8572+ me->arch.plt_offset = me->core_size_rx;
8573+ me->core_size_rx += me->arch.plt_size;
8574 return 0;
8575 }
8576
8577@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8578 if (info->got_initialized == 0) {
8579 Elf_Addr *gotent;
8580
8581- gotent = me->module_core + me->arch.got_offset +
8582+ gotent = me->module_core_rw + me->arch.got_offset +
8583 info->got_offset;
8584 *gotent = val;
8585 info->got_initialized = 1;
8586@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8587 rc = apply_rela_bits(loc, val, 0, 64, 0);
8588 else if (r_type == R_390_GOTENT ||
8589 r_type == R_390_GOTPLTENT) {
8590- val += (Elf_Addr) me->module_core - loc;
8591+ val += (Elf_Addr) me->module_core_rw - loc;
8592 rc = apply_rela_bits(loc, val, 1, 32, 1);
8593 }
8594 break;
8595@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8596 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8597 if (info->plt_initialized == 0) {
8598 unsigned int *ip;
8599- ip = me->module_core + me->arch.plt_offset +
8600+ ip = me->module_core_rx + me->arch.plt_offset +
8601 info->plt_offset;
8602 #ifndef CONFIG_64BIT
8603 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8604@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8605 val - loc + 0xffffUL < 0x1ffffeUL) ||
8606 (r_type == R_390_PLT32DBL &&
8607 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8608- val = (Elf_Addr) me->module_core +
8609+ val = (Elf_Addr) me->module_core_rx +
8610 me->arch.plt_offset +
8611 info->plt_offset;
8612 val += rela->r_addend - loc;
8613@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8614 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8615 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8616 val = val + rela->r_addend -
8617- ((Elf_Addr) me->module_core + me->arch.got_offset);
8618+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8619 if (r_type == R_390_GOTOFF16)
8620 rc = apply_rela_bits(loc, val, 0, 16, 0);
8621 else if (r_type == R_390_GOTOFF32)
8622@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8623 break;
8624 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8625 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8626- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8627+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8628 rela->r_addend - loc;
8629 if (r_type == R_390_GOTPC)
8630 rc = apply_rela_bits(loc, val, 1, 32, 0);
8631diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8632index 2bc3edd..ab9d598 100644
8633--- a/arch/s390/kernel/process.c
8634+++ b/arch/s390/kernel/process.c
8635@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8636 }
8637 return 0;
8638 }
8639-
8640-unsigned long arch_align_stack(unsigned long sp)
8641-{
8642- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8643- sp -= get_random_int() & ~PAGE_MASK;
8644- return sp & ~0xf;
8645-}
8646-
8647-static inline unsigned long brk_rnd(void)
8648-{
8649- /* 8MB for 32bit, 1GB for 64bit */
8650- if (is_32bit_task())
8651- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8652- else
8653- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8654-}
8655-
8656-unsigned long arch_randomize_brk(struct mm_struct *mm)
8657-{
8658- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8659-
8660- if (ret < mm->brk)
8661- return mm->brk;
8662- return ret;
8663-}
8664-
8665-unsigned long randomize_et_dyn(unsigned long base)
8666-{
8667- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8668-
8669- if (!(current->flags & PF_RANDOMIZE))
8670- return base;
8671- if (ret < base)
8672- return base;
8673- return ret;
8674-}
8675diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8676index 4002329..99b67cb 100644
8677--- a/arch/s390/mm/mmap.c
8678+++ b/arch/s390/mm/mmap.c
8679@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8680 */
8681 if (mmap_is_legacy()) {
8682 mm->mmap_base = TASK_UNMAPPED_BASE;
8683+
8684+#ifdef CONFIG_PAX_RANDMMAP
8685+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8686+ mm->mmap_base += mm->delta_mmap;
8687+#endif
8688+
8689 mm->get_unmapped_area = arch_get_unmapped_area;
8690 } else {
8691 mm->mmap_base = mmap_base();
8692+
8693+#ifdef CONFIG_PAX_RANDMMAP
8694+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8695+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8696+#endif
8697+
8698 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8699 }
8700 }
8701@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8702 */
8703 if (mmap_is_legacy()) {
8704 mm->mmap_base = TASK_UNMAPPED_BASE;
8705+
8706+#ifdef CONFIG_PAX_RANDMMAP
8707+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8708+ mm->mmap_base += mm->delta_mmap;
8709+#endif
8710+
8711 mm->get_unmapped_area = s390_get_unmapped_area;
8712 } else {
8713 mm->mmap_base = mmap_base();
8714+
8715+#ifdef CONFIG_PAX_RANDMMAP
8716+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8717+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8718+#endif
8719+
8720 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8721 }
8722 }
8723diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8724index ae3d59f..f65f075 100644
8725--- a/arch/score/include/asm/cache.h
8726+++ b/arch/score/include/asm/cache.h
8727@@ -1,7 +1,9 @@
8728 #ifndef _ASM_SCORE_CACHE_H
8729 #define _ASM_SCORE_CACHE_H
8730
8731+#include <linux/const.h>
8732+
8733 #define L1_CACHE_SHIFT 4
8734-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8735+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8736
8737 #endif /* _ASM_SCORE_CACHE_H */
8738diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8739index f9f3cd5..58ff438 100644
8740--- a/arch/score/include/asm/exec.h
8741+++ b/arch/score/include/asm/exec.h
8742@@ -1,6 +1,6 @@
8743 #ifndef _ASM_SCORE_EXEC_H
8744 #define _ASM_SCORE_EXEC_H
8745
8746-extern unsigned long arch_align_stack(unsigned long sp);
8747+#define arch_align_stack(x) (x)
8748
8749 #endif /* _ASM_SCORE_EXEC_H */
8750diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8751index f4c6d02..e9355c3 100644
8752--- a/arch/score/kernel/process.c
8753+++ b/arch/score/kernel/process.c
8754@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8755
8756 return task_pt_regs(task)->cp0_epc;
8757 }
8758-
8759-unsigned long arch_align_stack(unsigned long sp)
8760-{
8761- return sp;
8762-}
8763diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8764index ef9e555..331bd29 100644
8765--- a/arch/sh/include/asm/cache.h
8766+++ b/arch/sh/include/asm/cache.h
8767@@ -9,10 +9,11 @@
8768 #define __ASM_SH_CACHE_H
8769 #ifdef __KERNEL__
8770
8771+#include <linux/const.h>
8772 #include <linux/init.h>
8773 #include <cpu/cache.h>
8774
8775-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8776+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8777
8778 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8779
8780diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8781index 6777177..cb5e44f 100644
8782--- a/arch/sh/mm/mmap.c
8783+++ b/arch/sh/mm/mmap.c
8784@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8785 struct mm_struct *mm = current->mm;
8786 struct vm_area_struct *vma;
8787 int do_colour_align;
8788+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8789 struct vm_unmapped_area_info info;
8790
8791 if (flags & MAP_FIXED) {
8792@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8793 if (filp || (flags & MAP_SHARED))
8794 do_colour_align = 1;
8795
8796+#ifdef CONFIG_PAX_RANDMMAP
8797+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8798+#endif
8799+
8800 if (addr) {
8801 if (do_colour_align)
8802 addr = COLOUR_ALIGN(addr, pgoff);
8803@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8804 addr = PAGE_ALIGN(addr);
8805
8806 vma = find_vma(mm, addr);
8807- if (TASK_SIZE - len >= addr &&
8808- (!vma || addr + len <= vma->vm_start))
8809+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8810 return addr;
8811 }
8812
8813 info.flags = 0;
8814 info.length = len;
8815- info.low_limit = TASK_UNMAPPED_BASE;
8816+ info.low_limit = mm->mmap_base;
8817 info.high_limit = TASK_SIZE;
8818 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8819 info.align_offset = pgoff << PAGE_SHIFT;
8820@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8821 struct mm_struct *mm = current->mm;
8822 unsigned long addr = addr0;
8823 int do_colour_align;
8824+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8825 struct vm_unmapped_area_info info;
8826
8827 if (flags & MAP_FIXED) {
8828@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8829 if (filp || (flags & MAP_SHARED))
8830 do_colour_align = 1;
8831
8832+#ifdef CONFIG_PAX_RANDMMAP
8833+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8834+#endif
8835+
8836 /* requesting a specific address */
8837 if (addr) {
8838 if (do_colour_align)
8839@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8840 addr = PAGE_ALIGN(addr);
8841
8842 vma = find_vma(mm, addr);
8843- if (TASK_SIZE - len >= addr &&
8844- (!vma || addr + len <= vma->vm_start))
8845+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8846 return addr;
8847 }
8848
8849@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8850 VM_BUG_ON(addr != -ENOMEM);
8851 info.flags = 0;
8852 info.low_limit = TASK_UNMAPPED_BASE;
8853+
8854+#ifdef CONFIG_PAX_RANDMMAP
8855+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8856+ info.low_limit += mm->delta_mmap;
8857+#endif
8858+
8859 info.high_limit = TASK_SIZE;
8860 addr = vm_unmapped_area(&info);
8861 }
8862diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8863index be56a24..443328f 100644
8864--- a/arch/sparc/include/asm/atomic_64.h
8865+++ b/arch/sparc/include/asm/atomic_64.h
8866@@ -14,18 +14,40 @@
8867 #define ATOMIC64_INIT(i) { (i) }
8868
8869 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8870+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8871+{
8872+ return v->counter;
8873+}
8874 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8875+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8876+{
8877+ return v->counter;
8878+}
8879
8880 #define atomic_set(v, i) (((v)->counter) = i)
8881+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8882+{
8883+ v->counter = i;
8884+}
8885 #define atomic64_set(v, i) (((v)->counter) = i)
8886+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8887+{
8888+ v->counter = i;
8889+}
8890
8891 extern void atomic_add(int, atomic_t *);
8892+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8893 extern void atomic64_add(long, atomic64_t *);
8894+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8895 extern void atomic_sub(int, atomic_t *);
8896+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8897 extern void atomic64_sub(long, atomic64_t *);
8898+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8899
8900 extern int atomic_add_ret(int, atomic_t *);
8901+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8902 extern long atomic64_add_ret(long, atomic64_t *);
8903+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8904 extern int atomic_sub_ret(int, atomic_t *);
8905 extern long atomic64_sub_ret(long, atomic64_t *);
8906
8907@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8908 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8909
8910 #define atomic_inc_return(v) atomic_add_ret(1, v)
8911+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8912+{
8913+ return atomic_add_ret_unchecked(1, v);
8914+}
8915 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8916+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8917+{
8918+ return atomic64_add_ret_unchecked(1, v);
8919+}
8920
8921 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8922 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8923
8924 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8925+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8926+{
8927+ return atomic_add_ret_unchecked(i, v);
8928+}
8929 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8930+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8931+{
8932+ return atomic64_add_ret_unchecked(i, v);
8933+}
8934
8935 /*
8936 * atomic_inc_and_test - increment and test
8937@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8938 * other cases.
8939 */
8940 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8941+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8942+{
8943+ return atomic_inc_return_unchecked(v) == 0;
8944+}
8945 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8946
8947 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8948@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8949 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8950
8951 #define atomic_inc(v) atomic_add(1, v)
8952+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8953+{
8954+ atomic_add_unchecked(1, v);
8955+}
8956 #define atomic64_inc(v) atomic64_add(1, v)
8957+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8958+{
8959+ atomic64_add_unchecked(1, v);
8960+}
8961
8962 #define atomic_dec(v) atomic_sub(1, v)
8963+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8964+{
8965+ atomic_sub_unchecked(1, v);
8966+}
8967 #define atomic64_dec(v) atomic64_sub(1, v)
8968+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8969+{
8970+ atomic64_sub_unchecked(1, v);
8971+}
8972
8973 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8974 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8975
8976 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8977+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8978+{
8979+ return cmpxchg(&v->counter, old, new);
8980+}
8981 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8982+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8983+{
8984+ return xchg(&v->counter, new);
8985+}
8986
8987 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8988 {
8989- int c, old;
8990+ int c, old, new;
8991 c = atomic_read(v);
8992 for (;;) {
8993- if (unlikely(c == (u)))
8994+ if (unlikely(c == u))
8995 break;
8996- old = atomic_cmpxchg((v), c, c + (a));
8997+
8998+ asm volatile("addcc %2, %0, %0\n"
8999+
9000+#ifdef CONFIG_PAX_REFCOUNT
9001+ "tvs %%icc, 6\n"
9002+#endif
9003+
9004+ : "=r" (new)
9005+ : "0" (c), "ir" (a)
9006+ : "cc");
9007+
9008+ old = atomic_cmpxchg(v, c, new);
9009 if (likely(old == c))
9010 break;
9011 c = old;
9012@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9013 #define atomic64_cmpxchg(v, o, n) \
9014 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9015 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9016+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9017+{
9018+ return xchg(&v->counter, new);
9019+}
9020
9021 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9022 {
9023- long c, old;
9024+ long c, old, new;
9025 c = atomic64_read(v);
9026 for (;;) {
9027- if (unlikely(c == (u)))
9028+ if (unlikely(c == u))
9029 break;
9030- old = atomic64_cmpxchg((v), c, c + (a));
9031+
9032+ asm volatile("addcc %2, %0, %0\n"
9033+
9034+#ifdef CONFIG_PAX_REFCOUNT
9035+ "tvs %%xcc, 6\n"
9036+#endif
9037+
9038+ : "=r" (new)
9039+ : "0" (c), "ir" (a)
9040+ : "cc");
9041+
9042+ old = atomic64_cmpxchg(v, c, new);
9043 if (likely(old == c))
9044 break;
9045 c = old;
9046 }
9047- return c != (u);
9048+ return c != u;
9049 }
9050
9051 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9052diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9053index 5bb6991..5c2132e 100644
9054--- a/arch/sparc/include/asm/cache.h
9055+++ b/arch/sparc/include/asm/cache.h
9056@@ -7,10 +7,12 @@
9057 #ifndef _SPARC_CACHE_H
9058 #define _SPARC_CACHE_H
9059
9060+#include <linux/const.h>
9061+
9062 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9063
9064 #define L1_CACHE_SHIFT 5
9065-#define L1_CACHE_BYTES 32
9066+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9067
9068 #ifdef CONFIG_SPARC32
9069 #define SMP_CACHE_BYTES_SHIFT 5
9070diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9071index a24e41f..47677ff 100644
9072--- a/arch/sparc/include/asm/elf_32.h
9073+++ b/arch/sparc/include/asm/elf_32.h
9074@@ -114,6 +114,13 @@ typedef struct {
9075
9076 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9077
9078+#ifdef CONFIG_PAX_ASLR
9079+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9080+
9081+#define PAX_DELTA_MMAP_LEN 16
9082+#define PAX_DELTA_STACK_LEN 16
9083+#endif
9084+
9085 /* This yields a mask that user programs can use to figure out what
9086 instruction set this cpu supports. This can NOT be done in userspace
9087 on Sparc. */
9088diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9089index 370ca1e..d4f4a98 100644
9090--- a/arch/sparc/include/asm/elf_64.h
9091+++ b/arch/sparc/include/asm/elf_64.h
9092@@ -189,6 +189,13 @@ typedef struct {
9093 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9094 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9095
9096+#ifdef CONFIG_PAX_ASLR
9097+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9098+
9099+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9100+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9101+#endif
9102+
9103 extern unsigned long sparc64_elf_hwcap;
9104 #define ELF_HWCAP sparc64_elf_hwcap
9105
9106diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9107index 9b1c36d..209298b 100644
9108--- a/arch/sparc/include/asm/pgalloc_32.h
9109+++ b/arch/sparc/include/asm/pgalloc_32.h
9110@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9111 }
9112
9113 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9114+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9115
9116 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9117 unsigned long address)
9118diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9119index bcfe063..b333142 100644
9120--- a/arch/sparc/include/asm/pgalloc_64.h
9121+++ b/arch/sparc/include/asm/pgalloc_64.h
9122@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9123 }
9124
9125 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9126+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9127
9128 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9129 {
9130diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9131index 502f632..da1917f 100644
9132--- a/arch/sparc/include/asm/pgtable_32.h
9133+++ b/arch/sparc/include/asm/pgtable_32.h
9134@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9135 #define PAGE_SHARED SRMMU_PAGE_SHARED
9136 #define PAGE_COPY SRMMU_PAGE_COPY
9137 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9138+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9139+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9140+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9141 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9142
9143 /* Top-level page directory - dummy used by init-mm.
9144@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9145
9146 /* xwr */
9147 #define __P000 PAGE_NONE
9148-#define __P001 PAGE_READONLY
9149-#define __P010 PAGE_COPY
9150-#define __P011 PAGE_COPY
9151+#define __P001 PAGE_READONLY_NOEXEC
9152+#define __P010 PAGE_COPY_NOEXEC
9153+#define __P011 PAGE_COPY_NOEXEC
9154 #define __P100 PAGE_READONLY
9155 #define __P101 PAGE_READONLY
9156 #define __P110 PAGE_COPY
9157 #define __P111 PAGE_COPY
9158
9159 #define __S000 PAGE_NONE
9160-#define __S001 PAGE_READONLY
9161-#define __S010 PAGE_SHARED
9162-#define __S011 PAGE_SHARED
9163+#define __S001 PAGE_READONLY_NOEXEC
9164+#define __S010 PAGE_SHARED_NOEXEC
9165+#define __S011 PAGE_SHARED_NOEXEC
9166 #define __S100 PAGE_READONLY
9167 #define __S101 PAGE_READONLY
9168 #define __S110 PAGE_SHARED
9169diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9170index 79da178..c2eede8 100644
9171--- a/arch/sparc/include/asm/pgtsrmmu.h
9172+++ b/arch/sparc/include/asm/pgtsrmmu.h
9173@@ -115,6 +115,11 @@
9174 SRMMU_EXEC | SRMMU_REF)
9175 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9176 SRMMU_EXEC | SRMMU_REF)
9177+
9178+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9179+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9180+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9181+
9182 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9183 SRMMU_DIRTY | SRMMU_REF)
9184
9185diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9186index 9689176..63c18ea 100644
9187--- a/arch/sparc/include/asm/spinlock_64.h
9188+++ b/arch/sparc/include/asm/spinlock_64.h
9189@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9190
9191 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9192
9193-static void inline arch_read_lock(arch_rwlock_t *lock)
9194+static inline void arch_read_lock(arch_rwlock_t *lock)
9195 {
9196 unsigned long tmp1, tmp2;
9197
9198 __asm__ __volatile__ (
9199 "1: ldsw [%2], %0\n"
9200 " brlz,pn %0, 2f\n"
9201-"4: add %0, 1, %1\n"
9202+"4: addcc %0, 1, %1\n"
9203+
9204+#ifdef CONFIG_PAX_REFCOUNT
9205+" tvs %%icc, 6\n"
9206+#endif
9207+
9208 " cas [%2], %0, %1\n"
9209 " cmp %0, %1\n"
9210 " bne,pn %%icc, 1b\n"
9211@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9212 " .previous"
9213 : "=&r" (tmp1), "=&r" (tmp2)
9214 : "r" (lock)
9215- : "memory");
9216+ : "memory", "cc");
9217 }
9218
9219-static int inline arch_read_trylock(arch_rwlock_t *lock)
9220+static inline int arch_read_trylock(arch_rwlock_t *lock)
9221 {
9222 int tmp1, tmp2;
9223
9224@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9225 "1: ldsw [%2], %0\n"
9226 " brlz,a,pn %0, 2f\n"
9227 " mov 0, %0\n"
9228-" add %0, 1, %1\n"
9229+" addcc %0, 1, %1\n"
9230+
9231+#ifdef CONFIG_PAX_REFCOUNT
9232+" tvs %%icc, 6\n"
9233+#endif
9234+
9235 " cas [%2], %0, %1\n"
9236 " cmp %0, %1\n"
9237 " bne,pn %%icc, 1b\n"
9238@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9239 return tmp1;
9240 }
9241
9242-static void inline arch_read_unlock(arch_rwlock_t *lock)
9243+static inline void arch_read_unlock(arch_rwlock_t *lock)
9244 {
9245 unsigned long tmp1, tmp2;
9246
9247 __asm__ __volatile__(
9248 "1: lduw [%2], %0\n"
9249-" sub %0, 1, %1\n"
9250+" subcc %0, 1, %1\n"
9251+
9252+#ifdef CONFIG_PAX_REFCOUNT
9253+" tvs %%icc, 6\n"
9254+#endif
9255+
9256 " cas [%2], %0, %1\n"
9257 " cmp %0, %1\n"
9258 " bne,pn %%xcc, 1b\n"
9259@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9260 : "memory");
9261 }
9262
9263-static void inline arch_write_lock(arch_rwlock_t *lock)
9264+static inline void arch_write_lock(arch_rwlock_t *lock)
9265 {
9266 unsigned long mask, tmp1, tmp2;
9267
9268@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9269 : "memory");
9270 }
9271
9272-static void inline arch_write_unlock(arch_rwlock_t *lock)
9273+static inline void arch_write_unlock(arch_rwlock_t *lock)
9274 {
9275 __asm__ __volatile__(
9276 " stw %%g0, [%0]"
9277@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9278 : "memory");
9279 }
9280
9281-static int inline arch_write_trylock(arch_rwlock_t *lock)
9282+static inline int arch_write_trylock(arch_rwlock_t *lock)
9283 {
9284 unsigned long mask, tmp1, tmp2, result;
9285
9286diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9287index dd38075..e7cac83 100644
9288--- a/arch/sparc/include/asm/thread_info_32.h
9289+++ b/arch/sparc/include/asm/thread_info_32.h
9290@@ -49,6 +49,8 @@ struct thread_info {
9291 unsigned long w_saved;
9292
9293 struct restart_block restart_block;
9294+
9295+ unsigned long lowest_stack;
9296 };
9297
9298 /*
9299diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9300index d5e5042..9bfee76 100644
9301--- a/arch/sparc/include/asm/thread_info_64.h
9302+++ b/arch/sparc/include/asm/thread_info_64.h
9303@@ -63,6 +63,8 @@ struct thread_info {
9304 struct pt_regs *kern_una_regs;
9305 unsigned int kern_una_insn;
9306
9307+ unsigned long lowest_stack;
9308+
9309 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9310 };
9311
9312@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9313 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9314 /* flag bit 6 is available */
9315 #define TIF_32BIT 7 /* 32-bit binary */
9316-/* flag bit 8 is available */
9317+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9318 #define TIF_SECCOMP 9 /* secure computing */
9319 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9320 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9321+
9322 /* NOTE: Thread flags >= 12 should be ones we have no interest
9323 * in using in assembly, else we can't use the mask as
9324 * an immediate value in instructions such as andcc.
9325@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9326 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9327 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9328 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9329+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9330
9331 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9332 _TIF_DO_NOTIFY_RESUME_MASK | \
9333 _TIF_NEED_RESCHED)
9334 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9335
9336+#define _TIF_WORK_SYSCALL \
9337+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9338+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9339+
9340+
9341 /*
9342 * Thread-synchronous status.
9343 *
9344diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9345index 0167d26..767bb0c 100644
9346--- a/arch/sparc/include/asm/uaccess.h
9347+++ b/arch/sparc/include/asm/uaccess.h
9348@@ -1,5 +1,6 @@
9349 #ifndef ___ASM_SPARC_UACCESS_H
9350 #define ___ASM_SPARC_UACCESS_H
9351+
9352 #if defined(__sparc__) && defined(__arch64__)
9353 #include <asm/uaccess_64.h>
9354 #else
9355diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9356index 53a28dd..50c38c3 100644
9357--- a/arch/sparc/include/asm/uaccess_32.h
9358+++ b/arch/sparc/include/asm/uaccess_32.h
9359@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9360
9361 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9362 {
9363- if (n && __access_ok((unsigned long) to, n))
9364+ if ((long)n < 0)
9365+ return n;
9366+
9367+ if (n && __access_ok((unsigned long) to, n)) {
9368+ if (!__builtin_constant_p(n))
9369+ check_object_size(from, n, true);
9370 return __copy_user(to, (__force void __user *) from, n);
9371- else
9372+ } else
9373 return n;
9374 }
9375
9376 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9377 {
9378+ if ((long)n < 0)
9379+ return n;
9380+
9381+ if (!__builtin_constant_p(n))
9382+ check_object_size(from, n, true);
9383+
9384 return __copy_user(to, (__force void __user *) from, n);
9385 }
9386
9387 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9388 {
9389- if (n && __access_ok((unsigned long) from, n))
9390+ if ((long)n < 0)
9391+ return n;
9392+
9393+ if (n && __access_ok((unsigned long) from, n)) {
9394+ if (!__builtin_constant_p(n))
9395+ check_object_size(to, n, false);
9396 return __copy_user((__force void __user *) to, from, n);
9397- else
9398+ } else
9399 return n;
9400 }
9401
9402 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9403 {
9404+ if ((long)n < 0)
9405+ return n;
9406+
9407 return __copy_user((__force void __user *) to, from, n);
9408 }
9409
9410diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9411index e562d3c..191f176 100644
9412--- a/arch/sparc/include/asm/uaccess_64.h
9413+++ b/arch/sparc/include/asm/uaccess_64.h
9414@@ -10,6 +10,7 @@
9415 #include <linux/compiler.h>
9416 #include <linux/string.h>
9417 #include <linux/thread_info.h>
9418+#include <linux/kernel.h>
9419 #include <asm/asi.h>
9420 #include <asm/spitfire.h>
9421 #include <asm-generic/uaccess-unaligned.h>
9422@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9423 static inline unsigned long __must_check
9424 copy_from_user(void *to, const void __user *from, unsigned long size)
9425 {
9426- unsigned long ret = ___copy_from_user(to, from, size);
9427+ unsigned long ret;
9428
9429+ if ((long)size < 0 || size > INT_MAX)
9430+ return size;
9431+
9432+ if (!__builtin_constant_p(size))
9433+ check_object_size(to, size, false);
9434+
9435+ ret = ___copy_from_user(to, from, size);
9436 if (unlikely(ret))
9437 ret = copy_from_user_fixup(to, from, size);
9438
9439@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9440 static inline unsigned long __must_check
9441 copy_to_user(void __user *to, const void *from, unsigned long size)
9442 {
9443- unsigned long ret = ___copy_to_user(to, from, size);
9444+ unsigned long ret;
9445
9446+ if ((long)size < 0 || size > INT_MAX)
9447+ return size;
9448+
9449+ if (!__builtin_constant_p(size))
9450+ check_object_size(from, size, true);
9451+
9452+ ret = ___copy_to_user(to, from, size);
9453 if (unlikely(ret))
9454 ret = copy_to_user_fixup(to, from, size);
9455 return ret;
9456diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9457index d432fb2..6056af1 100644
9458--- a/arch/sparc/kernel/Makefile
9459+++ b/arch/sparc/kernel/Makefile
9460@@ -3,7 +3,7 @@
9461 #
9462
9463 asflags-y := -ansi
9464-ccflags-y := -Werror
9465+#ccflags-y := -Werror
9466
9467 extra-y := head_$(BITS).o
9468
9469diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9470index fdd819d..5af08c8 100644
9471--- a/arch/sparc/kernel/process_32.c
9472+++ b/arch/sparc/kernel/process_32.c
9473@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9474
9475 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9476 r->psr, r->pc, r->npc, r->y, print_tainted());
9477- printk("PC: <%pS>\n", (void *) r->pc);
9478+ printk("PC: <%pA>\n", (void *) r->pc);
9479 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9480 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9481 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9482 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9483 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9484 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9485- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9486+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9487
9488 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9489 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9490@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9491 rw = (struct reg_window32 *) fp;
9492 pc = rw->ins[7];
9493 printk("[%08lx : ", pc);
9494- printk("%pS ] ", (void *) pc);
9495+ printk("%pA ] ", (void *) pc);
9496 fp = rw->ins[6];
9497 } while (++count < 16);
9498 printk("\n");
9499diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9500index baebab2..9cd13b1 100644
9501--- a/arch/sparc/kernel/process_64.c
9502+++ b/arch/sparc/kernel/process_64.c
9503@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9504 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9505 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9506 if (regs->tstate & TSTATE_PRIV)
9507- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9508+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9509 }
9510
9511 void show_regs(struct pt_regs *regs)
9512@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9513
9514 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9515 regs->tpc, regs->tnpc, regs->y, print_tainted());
9516- printk("TPC: <%pS>\n", (void *) regs->tpc);
9517+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9518 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9519 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9520 regs->u_regs[3]);
9521@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9522 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9523 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9524 regs->u_regs[15]);
9525- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9526+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9527 show_regwindow(regs);
9528 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9529 }
9530@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9531 ((tp && tp->task) ? tp->task->pid : -1));
9532
9533 if (gp->tstate & TSTATE_PRIV) {
9534- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9535+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9536 (void *) gp->tpc,
9537 (void *) gp->o7,
9538 (void *) gp->i7,
9539diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9540index 79cc0d1..ec62734 100644
9541--- a/arch/sparc/kernel/prom_common.c
9542+++ b/arch/sparc/kernel/prom_common.c
9543@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9544
9545 unsigned int prom_early_allocated __initdata;
9546
9547-static struct of_pdt_ops prom_sparc_ops __initdata = {
9548+static struct of_pdt_ops prom_sparc_ops __initconst = {
9549 .nextprop = prom_common_nextprop,
9550 .getproplen = prom_getproplen,
9551 .getproperty = prom_getproperty,
9552diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9553index 7ff45e4..a58f271 100644
9554--- a/arch/sparc/kernel/ptrace_64.c
9555+++ b/arch/sparc/kernel/ptrace_64.c
9556@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9557 return ret;
9558 }
9559
9560+#ifdef CONFIG_GRKERNSEC_SETXID
9561+extern void gr_delayed_cred_worker(void);
9562+#endif
9563+
9564 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9565 {
9566 int ret = 0;
9567@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9568 /* do the secure computing check first */
9569 secure_computing_strict(regs->u_regs[UREG_G1]);
9570
9571+#ifdef CONFIG_GRKERNSEC_SETXID
9572+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9573+ gr_delayed_cred_worker();
9574+#endif
9575+
9576 if (test_thread_flag(TIF_SYSCALL_TRACE))
9577 ret = tracehook_report_syscall_entry(regs);
9578
9579@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9580
9581 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9582 {
9583+#ifdef CONFIG_GRKERNSEC_SETXID
9584+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9585+ gr_delayed_cred_worker();
9586+#endif
9587+
9588 audit_syscall_exit(regs);
9589
9590 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9591diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9592index e142545..fd29654 100644
9593--- a/arch/sparc/kernel/smp_64.c
9594+++ b/arch/sparc/kernel/smp_64.c
9595@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9596 extern unsigned long xcall_flush_dcache_page_spitfire;
9597
9598 #ifdef CONFIG_DEBUG_DCFLUSH
9599-extern atomic_t dcpage_flushes;
9600-extern atomic_t dcpage_flushes_xcall;
9601+extern atomic_unchecked_t dcpage_flushes;
9602+extern atomic_unchecked_t dcpage_flushes_xcall;
9603 #endif
9604
9605 static inline void __local_flush_dcache_page(struct page *page)
9606@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9607 return;
9608
9609 #ifdef CONFIG_DEBUG_DCFLUSH
9610- atomic_inc(&dcpage_flushes);
9611+ atomic_inc_unchecked(&dcpage_flushes);
9612 #endif
9613
9614 this_cpu = get_cpu();
9615@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9616 xcall_deliver(data0, __pa(pg_addr),
9617 (u64) pg_addr, cpumask_of(cpu));
9618 #ifdef CONFIG_DEBUG_DCFLUSH
9619- atomic_inc(&dcpage_flushes_xcall);
9620+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9621 #endif
9622 }
9623 }
9624@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9625 preempt_disable();
9626
9627 #ifdef CONFIG_DEBUG_DCFLUSH
9628- atomic_inc(&dcpage_flushes);
9629+ atomic_inc_unchecked(&dcpage_flushes);
9630 #endif
9631 data0 = 0;
9632 pg_addr = page_address(page);
9633@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9634 xcall_deliver(data0, __pa(pg_addr),
9635 (u64) pg_addr, cpu_online_mask);
9636 #ifdef CONFIG_DEBUG_DCFLUSH
9637- atomic_inc(&dcpage_flushes_xcall);
9638+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9639 #endif
9640 }
9641 __local_flush_dcache_page(page);
9642diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9643index 3a8d184..49498a8 100644
9644--- a/arch/sparc/kernel/sys_sparc_32.c
9645+++ b/arch/sparc/kernel/sys_sparc_32.c
9646@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9647 if (len > TASK_SIZE - PAGE_SIZE)
9648 return -ENOMEM;
9649 if (!addr)
9650- addr = TASK_UNMAPPED_BASE;
9651+ addr = current->mm->mmap_base;
9652
9653 info.flags = 0;
9654 info.length = len;
9655diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9656index 51561b8..8256764 100644
9657--- a/arch/sparc/kernel/sys_sparc_64.c
9658+++ b/arch/sparc/kernel/sys_sparc_64.c
9659@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9660 struct vm_area_struct * vma;
9661 unsigned long task_size = TASK_SIZE;
9662 int do_color_align;
9663+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9664 struct vm_unmapped_area_info info;
9665
9666 if (flags & MAP_FIXED) {
9667 /* We do not accept a shared mapping if it would violate
9668 * cache aliasing constraints.
9669 */
9670- if ((flags & MAP_SHARED) &&
9671+ if ((filp || (flags & MAP_SHARED)) &&
9672 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9673 return -EINVAL;
9674 return addr;
9675@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9676 if (filp || (flags & MAP_SHARED))
9677 do_color_align = 1;
9678
9679+#ifdef CONFIG_PAX_RANDMMAP
9680+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9681+#endif
9682+
9683 if (addr) {
9684 if (do_color_align)
9685 addr = COLOR_ALIGN(addr, pgoff);
9686@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9687 addr = PAGE_ALIGN(addr);
9688
9689 vma = find_vma(mm, addr);
9690- if (task_size - len >= addr &&
9691- (!vma || addr + len <= vma->vm_start))
9692+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9693 return addr;
9694 }
9695
9696 info.flags = 0;
9697 info.length = len;
9698- info.low_limit = TASK_UNMAPPED_BASE;
9699+ info.low_limit = mm->mmap_base;
9700 info.high_limit = min(task_size, VA_EXCLUDE_START);
9701 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9702 info.align_offset = pgoff << PAGE_SHIFT;
9703+ info.threadstack_offset = offset;
9704 addr = vm_unmapped_area(&info);
9705
9706 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9707 VM_BUG_ON(addr != -ENOMEM);
9708 info.low_limit = VA_EXCLUDE_END;
9709+
9710+#ifdef CONFIG_PAX_RANDMMAP
9711+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9712+ info.low_limit += mm->delta_mmap;
9713+#endif
9714+
9715 info.high_limit = task_size;
9716 addr = vm_unmapped_area(&info);
9717 }
9718@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9719 unsigned long task_size = STACK_TOP32;
9720 unsigned long addr = addr0;
9721 int do_color_align;
9722+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9723 struct vm_unmapped_area_info info;
9724
9725 /* This should only ever run for 32-bit processes. */
9726@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9727 /* We do not accept a shared mapping if it would violate
9728 * cache aliasing constraints.
9729 */
9730- if ((flags & MAP_SHARED) &&
9731+ if ((filp || (flags & MAP_SHARED)) &&
9732 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9733 return -EINVAL;
9734 return addr;
9735@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9736 if (filp || (flags & MAP_SHARED))
9737 do_color_align = 1;
9738
9739+#ifdef CONFIG_PAX_RANDMMAP
9740+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9741+#endif
9742+
9743 /* requesting a specific address */
9744 if (addr) {
9745 if (do_color_align)
9746@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9747 addr = PAGE_ALIGN(addr);
9748
9749 vma = find_vma(mm, addr);
9750- if (task_size - len >= addr &&
9751- (!vma || addr + len <= vma->vm_start))
9752+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9753 return addr;
9754 }
9755
9756@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9757 info.high_limit = mm->mmap_base;
9758 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9759 info.align_offset = pgoff << PAGE_SHIFT;
9760+ info.threadstack_offset = offset;
9761 addr = vm_unmapped_area(&info);
9762
9763 /*
9764@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9765 VM_BUG_ON(addr != -ENOMEM);
9766 info.flags = 0;
9767 info.low_limit = TASK_UNMAPPED_BASE;
9768+
9769+#ifdef CONFIG_PAX_RANDMMAP
9770+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9771+ info.low_limit += mm->delta_mmap;
9772+#endif
9773+
9774 info.high_limit = STACK_TOP32;
9775 addr = vm_unmapped_area(&info);
9776 }
9777@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9778 EXPORT_SYMBOL(get_fb_unmapped_area);
9779
9780 /* Essentially the same as PowerPC. */
9781-static unsigned long mmap_rnd(void)
9782+static unsigned long mmap_rnd(struct mm_struct *mm)
9783 {
9784 unsigned long rnd = 0UL;
9785
9786+#ifdef CONFIG_PAX_RANDMMAP
9787+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9788+#endif
9789+
9790 if (current->flags & PF_RANDOMIZE) {
9791 unsigned long val = get_random_int();
9792 if (test_thread_flag(TIF_32BIT))
9793@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9794
9795 void arch_pick_mmap_layout(struct mm_struct *mm)
9796 {
9797- unsigned long random_factor = mmap_rnd();
9798+ unsigned long random_factor = mmap_rnd(mm);
9799 unsigned long gap;
9800
9801 /*
9802@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9803 gap == RLIM_INFINITY ||
9804 sysctl_legacy_va_layout) {
9805 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9806+
9807+#ifdef CONFIG_PAX_RANDMMAP
9808+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9809+ mm->mmap_base += mm->delta_mmap;
9810+#endif
9811+
9812 mm->get_unmapped_area = arch_get_unmapped_area;
9813 } else {
9814 /* We know it's 32-bit */
9815@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9816 gap = (task_size / 6 * 5);
9817
9818 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9819+
9820+#ifdef CONFIG_PAX_RANDMMAP
9821+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9822+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9823+#endif
9824+
9825 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9826 }
9827 }
9828diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9829index 73ec8a7..4611979 100644
9830--- a/arch/sparc/kernel/syscalls.S
9831+++ b/arch/sparc/kernel/syscalls.S
9832@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9833 #endif
9834 .align 32
9835 1: ldx [%g6 + TI_FLAGS], %l5
9836- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9837+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9838 be,pt %icc, rtrap
9839 nop
9840 call syscall_trace_leave
9841@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9842
9843 srl %i3, 0, %o3 ! IEU0
9844 srl %i2, 0, %o2 ! IEU0 Group
9845- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9846+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9847 bne,pn %icc, linux_syscall_trace32 ! CTI
9848 mov %i0, %l5 ! IEU1
9849 5: call %l7 ! CTI Group brk forced
9850@@ -207,7 +207,7 @@ linux_sparc_syscall:
9851
9852 mov %i3, %o3 ! IEU1
9853 mov %i4, %o4 ! IEU0 Group
9854- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9855+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9856 bne,pn %icc, linux_syscall_trace ! CTI Group
9857 mov %i0, %l5 ! IEU0
9858 2: call %l7 ! CTI Group brk forced
9859@@ -223,7 +223,7 @@ ret_sys_call:
9860
9861 cmp %o0, -ERESTART_RESTARTBLOCK
9862 bgeu,pn %xcc, 1f
9863- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9864+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9865 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9866
9867 2:
9868diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9869index 6629829..036032d 100644
9870--- a/arch/sparc/kernel/traps_32.c
9871+++ b/arch/sparc/kernel/traps_32.c
9872@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9873 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9874 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9875
9876+extern void gr_handle_kernel_exploit(void);
9877+
9878 void die_if_kernel(char *str, struct pt_regs *regs)
9879 {
9880 static int die_counter;
9881@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9882 count++ < 30 &&
9883 (((unsigned long) rw) >= PAGE_OFFSET) &&
9884 !(((unsigned long) rw) & 0x7)) {
9885- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9886+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9887 (void *) rw->ins[7]);
9888 rw = (struct reg_window32 *)rw->ins[6];
9889 }
9890 }
9891 printk("Instruction DUMP:");
9892 instruction_dump ((unsigned long *) regs->pc);
9893- if(regs->psr & PSR_PS)
9894+ if(regs->psr & PSR_PS) {
9895+ gr_handle_kernel_exploit();
9896 do_exit(SIGKILL);
9897+ }
9898 do_exit(SIGSEGV);
9899 }
9900
9901diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9902index b3f833a..f485f80 100644
9903--- a/arch/sparc/kernel/traps_64.c
9904+++ b/arch/sparc/kernel/traps_64.c
9905@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9906 i + 1,
9907 p->trapstack[i].tstate, p->trapstack[i].tpc,
9908 p->trapstack[i].tnpc, p->trapstack[i].tt);
9909- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9910+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9911 }
9912 }
9913
9914@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9915
9916 lvl -= 0x100;
9917 if (regs->tstate & TSTATE_PRIV) {
9918+
9919+#ifdef CONFIG_PAX_REFCOUNT
9920+ if (lvl == 6)
9921+ pax_report_refcount_overflow(regs);
9922+#endif
9923+
9924 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9925 die_if_kernel(buffer, regs);
9926 }
9927@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9928 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9929 {
9930 char buffer[32];
9931-
9932+
9933 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9934 0, lvl, SIGTRAP) == NOTIFY_STOP)
9935 return;
9936
9937+#ifdef CONFIG_PAX_REFCOUNT
9938+ if (lvl == 6)
9939+ pax_report_refcount_overflow(regs);
9940+#endif
9941+
9942 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9943
9944 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9945@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9946 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9947 printk("%s" "ERROR(%d): ",
9948 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9949- printk("TPC<%pS>\n", (void *) regs->tpc);
9950+ printk("TPC<%pA>\n", (void *) regs->tpc);
9951 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9952 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9953 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9954@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9955 smp_processor_id(),
9956 (type & 0x1) ? 'I' : 'D',
9957 regs->tpc);
9958- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9959+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9960 panic("Irrecoverable Cheetah+ parity error.");
9961 }
9962
9963@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9964 smp_processor_id(),
9965 (type & 0x1) ? 'I' : 'D',
9966 regs->tpc);
9967- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9968+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9969 }
9970
9971 struct sun4v_error_entry {
9972@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9973 /*0x38*/u64 reserved_5;
9974 };
9975
9976-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9977-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9978+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9979+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9980
9981 static const char *sun4v_err_type_to_str(u8 type)
9982 {
9983@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9984 }
9985
9986 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9987- int cpu, const char *pfx, atomic_t *ocnt)
9988+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9989 {
9990 u64 *raw_ptr = (u64 *) ent;
9991 u32 attrs;
9992@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9993
9994 show_regs(regs);
9995
9996- if ((cnt = atomic_read(ocnt)) != 0) {
9997- atomic_set(ocnt, 0);
9998+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9999+ atomic_set_unchecked(ocnt, 0);
10000 wmb();
10001 printk("%s: Queue overflowed %d times.\n",
10002 pfx, cnt);
10003@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10004 */
10005 void sun4v_resum_overflow(struct pt_regs *regs)
10006 {
10007- atomic_inc(&sun4v_resum_oflow_cnt);
10008+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10009 }
10010
10011 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10012@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10013 /* XXX Actually even this can make not that much sense. Perhaps
10014 * XXX we should just pull the plug and panic directly from here?
10015 */
10016- atomic_inc(&sun4v_nonresum_oflow_cnt);
10017+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10018 }
10019
10020 unsigned long sun4v_err_itlb_vaddr;
10021@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10022
10023 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10024 regs->tpc, tl);
10025- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10026+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10027 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10028- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10029+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10030 (void *) regs->u_regs[UREG_I7]);
10031 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10032 "pte[%lx] error[%lx]\n",
10033@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10034
10035 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10036 regs->tpc, tl);
10037- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10038+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10039 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10040- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10041+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10042 (void *) regs->u_regs[UREG_I7]);
10043 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10044 "pte[%lx] error[%lx]\n",
10045@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10046 fp = (unsigned long)sf->fp + STACK_BIAS;
10047 }
10048
10049- printk(" [%016lx] %pS\n", pc, (void *) pc);
10050+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10051 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10052 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10053 int index = tsk->curr_ret_stack;
10054 if (tsk->ret_stack && index >= graph) {
10055 pc = tsk->ret_stack[index - graph].ret;
10056- printk(" [%016lx] %pS\n", pc, (void *) pc);
10057+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10058 graph++;
10059 }
10060 }
10061@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10062 return (struct reg_window *) (fp + STACK_BIAS);
10063 }
10064
10065+extern void gr_handle_kernel_exploit(void);
10066+
10067 void die_if_kernel(char *str, struct pt_regs *regs)
10068 {
10069 static int die_counter;
10070@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10071 while (rw &&
10072 count++ < 30 &&
10073 kstack_valid(tp, (unsigned long) rw)) {
10074- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10075+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10076 (void *) rw->ins[7]);
10077
10078 rw = kernel_stack_up(rw);
10079@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10080 }
10081 user_instruction_dump ((unsigned int __user *) regs->tpc);
10082 }
10083- if (regs->tstate & TSTATE_PRIV)
10084+ if (regs->tstate & TSTATE_PRIV) {
10085+ gr_handle_kernel_exploit();
10086 do_exit(SIGKILL);
10087+ }
10088 do_exit(SIGSEGV);
10089 }
10090 EXPORT_SYMBOL(die_if_kernel);
10091diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10092index 8201c25e..072a2a7 100644
10093--- a/arch/sparc/kernel/unaligned_64.c
10094+++ b/arch/sparc/kernel/unaligned_64.c
10095@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10096 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10097
10098 if (__ratelimit(&ratelimit)) {
10099- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10100+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10101 regs->tpc, (void *) regs->tpc);
10102 }
10103 }
10104diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10105index dbe119b..089c7c1 100644
10106--- a/arch/sparc/lib/Makefile
10107+++ b/arch/sparc/lib/Makefile
10108@@ -2,7 +2,7 @@
10109 #
10110
10111 asflags-y := -ansi -DST_DIV0=0x02
10112-ccflags-y := -Werror
10113+#ccflags-y := -Werror
10114
10115 lib-$(CONFIG_SPARC32) += ashrdi3.o
10116 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10117diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10118index 85c233d..68500e0 100644
10119--- a/arch/sparc/lib/atomic_64.S
10120+++ b/arch/sparc/lib/atomic_64.S
10121@@ -17,7 +17,12 @@
10122 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10123 BACKOFF_SETUP(%o2)
10124 1: lduw [%o1], %g1
10125- add %g1, %o0, %g7
10126+ addcc %g1, %o0, %g7
10127+
10128+#ifdef CONFIG_PAX_REFCOUNT
10129+ tvs %icc, 6
10130+#endif
10131+
10132 cas [%o1], %g1, %g7
10133 cmp %g1, %g7
10134 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10135@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10136 2: BACKOFF_SPIN(%o2, %o3, 1b)
10137 ENDPROC(atomic_add)
10138
10139+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10140+ BACKOFF_SETUP(%o2)
10141+1: lduw [%o1], %g1
10142+ add %g1, %o0, %g7
10143+ cas [%o1], %g1, %g7
10144+ cmp %g1, %g7
10145+ bne,pn %icc, 2f
10146+ nop
10147+ retl
10148+ nop
10149+2: BACKOFF_SPIN(%o2, %o3, 1b)
10150+ENDPROC(atomic_add_unchecked)
10151+
10152 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10153 BACKOFF_SETUP(%o2)
10154 1: lduw [%o1], %g1
10155- sub %g1, %o0, %g7
10156+ subcc %g1, %o0, %g7
10157+
10158+#ifdef CONFIG_PAX_REFCOUNT
10159+ tvs %icc, 6
10160+#endif
10161+
10162 cas [%o1], %g1, %g7
10163 cmp %g1, %g7
10164 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10165@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10166 2: BACKOFF_SPIN(%o2, %o3, 1b)
10167 ENDPROC(atomic_sub)
10168
10169+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10170+ BACKOFF_SETUP(%o2)
10171+1: lduw [%o1], %g1
10172+ sub %g1, %o0, %g7
10173+ cas [%o1], %g1, %g7
10174+ cmp %g1, %g7
10175+ bne,pn %icc, 2f
10176+ nop
10177+ retl
10178+ nop
10179+2: BACKOFF_SPIN(%o2, %o3, 1b)
10180+ENDPROC(atomic_sub_unchecked)
10181+
10182 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10183 BACKOFF_SETUP(%o2)
10184 1: lduw [%o1], %g1
10185- add %g1, %o0, %g7
10186+ addcc %g1, %o0, %g7
10187+
10188+#ifdef CONFIG_PAX_REFCOUNT
10189+ tvs %icc, 6
10190+#endif
10191+
10192 cas [%o1], %g1, %g7
10193 cmp %g1, %g7
10194 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10195@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10196 2: BACKOFF_SPIN(%o2, %o3, 1b)
10197 ENDPROC(atomic_add_ret)
10198
10199+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10200+ BACKOFF_SETUP(%o2)
10201+1: lduw [%o1], %g1
10202+ addcc %g1, %o0, %g7
10203+ cas [%o1], %g1, %g7
10204+ cmp %g1, %g7
10205+ bne,pn %icc, 2f
10206+ add %g7, %o0, %g7
10207+ sra %g7, 0, %o0
10208+ retl
10209+ nop
10210+2: BACKOFF_SPIN(%o2, %o3, 1b)
10211+ENDPROC(atomic_add_ret_unchecked)
10212+
10213 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10214 BACKOFF_SETUP(%o2)
10215 1: lduw [%o1], %g1
10216- sub %g1, %o0, %g7
10217+ subcc %g1, %o0, %g7
10218+
10219+#ifdef CONFIG_PAX_REFCOUNT
10220+ tvs %icc, 6
10221+#endif
10222+
10223 cas [%o1], %g1, %g7
10224 cmp %g1, %g7
10225 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10226@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10227 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10228 BACKOFF_SETUP(%o2)
10229 1: ldx [%o1], %g1
10230- add %g1, %o0, %g7
10231+ addcc %g1, %o0, %g7
10232+
10233+#ifdef CONFIG_PAX_REFCOUNT
10234+ tvs %xcc, 6
10235+#endif
10236+
10237 casx [%o1], %g1, %g7
10238 cmp %g1, %g7
10239 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10240@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10241 2: BACKOFF_SPIN(%o2, %o3, 1b)
10242 ENDPROC(atomic64_add)
10243
10244+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10245+ BACKOFF_SETUP(%o2)
10246+1: ldx [%o1], %g1
10247+ addcc %g1, %o0, %g7
10248+ casx [%o1], %g1, %g7
10249+ cmp %g1, %g7
10250+ bne,pn %xcc, 2f
10251+ nop
10252+ retl
10253+ nop
10254+2: BACKOFF_SPIN(%o2, %o3, 1b)
10255+ENDPROC(atomic64_add_unchecked)
10256+
10257 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10258 BACKOFF_SETUP(%o2)
10259 1: ldx [%o1], %g1
10260- sub %g1, %o0, %g7
10261+ subcc %g1, %o0, %g7
10262+
10263+#ifdef CONFIG_PAX_REFCOUNT
10264+ tvs %xcc, 6
10265+#endif
10266+
10267 casx [%o1], %g1, %g7
10268 cmp %g1, %g7
10269 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10270@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10271 2: BACKOFF_SPIN(%o2, %o3, 1b)
10272 ENDPROC(atomic64_sub)
10273
10274+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10275+ BACKOFF_SETUP(%o2)
10276+1: ldx [%o1], %g1
10277+ subcc %g1, %o0, %g7
10278+ casx [%o1], %g1, %g7
10279+ cmp %g1, %g7
10280+ bne,pn %xcc, 2f
10281+ nop
10282+ retl
10283+ nop
10284+2: BACKOFF_SPIN(%o2, %o3, 1b)
10285+ENDPROC(atomic64_sub_unchecked)
10286+
10287 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10288 BACKOFF_SETUP(%o2)
10289 1: ldx [%o1], %g1
10290- add %g1, %o0, %g7
10291+ addcc %g1, %o0, %g7
10292+
10293+#ifdef CONFIG_PAX_REFCOUNT
10294+ tvs %xcc, 6
10295+#endif
10296+
10297 casx [%o1], %g1, %g7
10298 cmp %g1, %g7
10299 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10300@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10301 2: BACKOFF_SPIN(%o2, %o3, 1b)
10302 ENDPROC(atomic64_add_ret)
10303
10304+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10305+ BACKOFF_SETUP(%o2)
10306+1: ldx [%o1], %g1
10307+ addcc %g1, %o0, %g7
10308+ casx [%o1], %g1, %g7
10309+ cmp %g1, %g7
10310+ bne,pn %xcc, 2f
10311+ add %g7, %o0, %g7
10312+ mov %g7, %o0
10313+ retl
10314+ nop
10315+2: BACKOFF_SPIN(%o2, %o3, 1b)
10316+ENDPROC(atomic64_add_ret_unchecked)
10317+
10318 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10319 BACKOFF_SETUP(%o2)
10320 1: ldx [%o1], %g1
10321- sub %g1, %o0, %g7
10322+ subcc %g1, %o0, %g7
10323+
10324+#ifdef CONFIG_PAX_REFCOUNT
10325+ tvs %xcc, 6
10326+#endif
10327+
10328 casx [%o1], %g1, %g7
10329 cmp %g1, %g7
10330 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10331diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10332index 323335b..ed85ea2 100644
10333--- a/arch/sparc/lib/ksyms.c
10334+++ b/arch/sparc/lib/ksyms.c
10335@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10336
10337 /* Atomic counter implementation. */
10338 EXPORT_SYMBOL(atomic_add);
10339+EXPORT_SYMBOL(atomic_add_unchecked);
10340 EXPORT_SYMBOL(atomic_add_ret);
10341+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10342 EXPORT_SYMBOL(atomic_sub);
10343+EXPORT_SYMBOL(atomic_sub_unchecked);
10344 EXPORT_SYMBOL(atomic_sub_ret);
10345 EXPORT_SYMBOL(atomic64_add);
10346+EXPORT_SYMBOL(atomic64_add_unchecked);
10347 EXPORT_SYMBOL(atomic64_add_ret);
10348+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10349 EXPORT_SYMBOL(atomic64_sub);
10350+EXPORT_SYMBOL(atomic64_sub_unchecked);
10351 EXPORT_SYMBOL(atomic64_sub_ret);
10352 EXPORT_SYMBOL(atomic64_dec_if_positive);
10353
10354diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10355index 30c3ecc..736f015 100644
10356--- a/arch/sparc/mm/Makefile
10357+++ b/arch/sparc/mm/Makefile
10358@@ -2,7 +2,7 @@
10359 #
10360
10361 asflags-y := -ansi
10362-ccflags-y := -Werror
10363+#ccflags-y := -Werror
10364
10365 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10366 obj-y += fault_$(BITS).o
10367diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10368index e98bfda..ea8d221 100644
10369--- a/arch/sparc/mm/fault_32.c
10370+++ b/arch/sparc/mm/fault_32.c
10371@@ -21,6 +21,9 @@
10372 #include <linux/perf_event.h>
10373 #include <linux/interrupt.h>
10374 #include <linux/kdebug.h>
10375+#include <linux/slab.h>
10376+#include <linux/pagemap.h>
10377+#include <linux/compiler.h>
10378
10379 #include <asm/page.h>
10380 #include <asm/pgtable.h>
10381@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10382 return safe_compute_effective_address(regs, insn);
10383 }
10384
10385+#ifdef CONFIG_PAX_PAGEEXEC
10386+#ifdef CONFIG_PAX_DLRESOLVE
10387+static void pax_emuplt_close(struct vm_area_struct *vma)
10388+{
10389+ vma->vm_mm->call_dl_resolve = 0UL;
10390+}
10391+
10392+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10393+{
10394+ unsigned int *kaddr;
10395+
10396+ vmf->page = alloc_page(GFP_HIGHUSER);
10397+ if (!vmf->page)
10398+ return VM_FAULT_OOM;
10399+
10400+ kaddr = kmap(vmf->page);
10401+ memset(kaddr, 0, PAGE_SIZE);
10402+ kaddr[0] = 0x9DE3BFA8U; /* save */
10403+ flush_dcache_page(vmf->page);
10404+ kunmap(vmf->page);
10405+ return VM_FAULT_MAJOR;
10406+}
10407+
10408+static const struct vm_operations_struct pax_vm_ops = {
10409+ .close = pax_emuplt_close,
10410+ .fault = pax_emuplt_fault
10411+};
10412+
10413+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10414+{
10415+ int ret;
10416+
10417+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10418+ vma->vm_mm = current->mm;
10419+ vma->vm_start = addr;
10420+ vma->vm_end = addr + PAGE_SIZE;
10421+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10422+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10423+ vma->vm_ops = &pax_vm_ops;
10424+
10425+ ret = insert_vm_struct(current->mm, vma);
10426+ if (ret)
10427+ return ret;
10428+
10429+ ++current->mm->total_vm;
10430+ return 0;
10431+}
10432+#endif
10433+
10434+/*
10435+ * PaX: decide what to do with offenders (regs->pc = fault address)
10436+ *
10437+ * returns 1 when task should be killed
10438+ * 2 when patched PLT trampoline was detected
10439+ * 3 when unpatched PLT trampoline was detected
10440+ */
10441+static int pax_handle_fetch_fault(struct pt_regs *regs)
10442+{
10443+
10444+#ifdef CONFIG_PAX_EMUPLT
10445+ int err;
10446+
10447+ do { /* PaX: patched PLT emulation #1 */
10448+ unsigned int sethi1, sethi2, jmpl;
10449+
10450+ err = get_user(sethi1, (unsigned int *)regs->pc);
10451+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10452+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10453+
10454+ if (err)
10455+ break;
10456+
10457+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10458+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10459+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10460+ {
10461+ unsigned int addr;
10462+
10463+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10464+ addr = regs->u_regs[UREG_G1];
10465+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10466+ regs->pc = addr;
10467+ regs->npc = addr+4;
10468+ return 2;
10469+ }
10470+ } while (0);
10471+
10472+ do { /* PaX: patched PLT emulation #2 */
10473+ unsigned int ba;
10474+
10475+ err = get_user(ba, (unsigned int *)regs->pc);
10476+
10477+ if (err)
10478+ break;
10479+
10480+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10481+ unsigned int addr;
10482+
10483+ if ((ba & 0xFFC00000U) == 0x30800000U)
10484+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10485+ else
10486+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10487+ regs->pc = addr;
10488+ regs->npc = addr+4;
10489+ return 2;
10490+ }
10491+ } while (0);
10492+
10493+ do { /* PaX: patched PLT emulation #3 */
10494+ unsigned int sethi, bajmpl, nop;
10495+
10496+ err = get_user(sethi, (unsigned int *)regs->pc);
10497+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10498+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10499+
10500+ if (err)
10501+ break;
10502+
10503+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10504+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10505+ nop == 0x01000000U)
10506+ {
10507+ unsigned int addr;
10508+
10509+ addr = (sethi & 0x003FFFFFU) << 10;
10510+ regs->u_regs[UREG_G1] = addr;
10511+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10512+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10513+ else
10514+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10515+ regs->pc = addr;
10516+ regs->npc = addr+4;
10517+ return 2;
10518+ }
10519+ } while (0);
10520+
10521+ do { /* PaX: unpatched PLT emulation step 1 */
10522+ unsigned int sethi, ba, nop;
10523+
10524+ err = get_user(sethi, (unsigned int *)regs->pc);
10525+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10526+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10527+
10528+ if (err)
10529+ break;
10530+
10531+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10532+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10533+ nop == 0x01000000U)
10534+ {
10535+ unsigned int addr, save, call;
10536+
10537+ if ((ba & 0xFFC00000U) == 0x30800000U)
10538+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10539+ else
10540+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10541+
10542+ err = get_user(save, (unsigned int *)addr);
10543+ err |= get_user(call, (unsigned int *)(addr+4));
10544+ err |= get_user(nop, (unsigned int *)(addr+8));
10545+ if (err)
10546+ break;
10547+
10548+#ifdef CONFIG_PAX_DLRESOLVE
10549+ if (save == 0x9DE3BFA8U &&
10550+ (call & 0xC0000000U) == 0x40000000U &&
10551+ nop == 0x01000000U)
10552+ {
10553+ struct vm_area_struct *vma;
10554+ unsigned long call_dl_resolve;
10555+
10556+ down_read(&current->mm->mmap_sem);
10557+ call_dl_resolve = current->mm->call_dl_resolve;
10558+ up_read(&current->mm->mmap_sem);
10559+ if (likely(call_dl_resolve))
10560+ goto emulate;
10561+
10562+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10563+
10564+ down_write(&current->mm->mmap_sem);
10565+ if (current->mm->call_dl_resolve) {
10566+ call_dl_resolve = current->mm->call_dl_resolve;
10567+ up_write(&current->mm->mmap_sem);
10568+ if (vma)
10569+ kmem_cache_free(vm_area_cachep, vma);
10570+ goto emulate;
10571+ }
10572+
10573+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10574+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10575+ up_write(&current->mm->mmap_sem);
10576+ if (vma)
10577+ kmem_cache_free(vm_area_cachep, vma);
10578+ return 1;
10579+ }
10580+
10581+ if (pax_insert_vma(vma, call_dl_resolve)) {
10582+ up_write(&current->mm->mmap_sem);
10583+ kmem_cache_free(vm_area_cachep, vma);
10584+ return 1;
10585+ }
10586+
10587+ current->mm->call_dl_resolve = call_dl_resolve;
10588+ up_write(&current->mm->mmap_sem);
10589+
10590+emulate:
10591+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10592+ regs->pc = call_dl_resolve;
10593+ regs->npc = addr+4;
10594+ return 3;
10595+ }
10596+#endif
10597+
10598+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10599+ if ((save & 0xFFC00000U) == 0x05000000U &&
10600+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10601+ nop == 0x01000000U)
10602+ {
10603+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10604+ regs->u_regs[UREG_G2] = addr + 4;
10605+ addr = (save & 0x003FFFFFU) << 10;
10606+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10607+ regs->pc = addr;
10608+ regs->npc = addr+4;
10609+ return 3;
10610+ }
10611+ }
10612+ } while (0);
10613+
10614+ do { /* PaX: unpatched PLT emulation step 2 */
10615+ unsigned int save, call, nop;
10616+
10617+ err = get_user(save, (unsigned int *)(regs->pc-4));
10618+ err |= get_user(call, (unsigned int *)regs->pc);
10619+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10620+ if (err)
10621+ break;
10622+
10623+ if (save == 0x9DE3BFA8U &&
10624+ (call & 0xC0000000U) == 0x40000000U &&
10625+ nop == 0x01000000U)
10626+ {
10627+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10628+
10629+ regs->u_regs[UREG_RETPC] = regs->pc;
10630+ regs->pc = dl_resolve;
10631+ regs->npc = dl_resolve+4;
10632+ return 3;
10633+ }
10634+ } while (0);
10635+#endif
10636+
10637+ return 1;
10638+}
10639+
10640+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10641+{
10642+ unsigned long i;
10643+
10644+ printk(KERN_ERR "PAX: bytes at PC: ");
10645+ for (i = 0; i < 8; i++) {
10646+ unsigned int c;
10647+ if (get_user(c, (unsigned int *)pc+i))
10648+ printk(KERN_CONT "???????? ");
10649+ else
10650+ printk(KERN_CONT "%08x ", c);
10651+ }
10652+ printk("\n");
10653+}
10654+#endif
10655+
10656 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10657 int text_fault)
10658 {
10659@@ -230,6 +504,24 @@ good_area:
10660 if (!(vma->vm_flags & VM_WRITE))
10661 goto bad_area;
10662 } else {
10663+
10664+#ifdef CONFIG_PAX_PAGEEXEC
10665+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10666+ up_read(&mm->mmap_sem);
10667+ switch (pax_handle_fetch_fault(regs)) {
10668+
10669+#ifdef CONFIG_PAX_EMUPLT
10670+ case 2:
10671+ case 3:
10672+ return;
10673+#endif
10674+
10675+ }
10676+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10677+ do_group_exit(SIGKILL);
10678+ }
10679+#endif
10680+
10681 /* Allow reads even for write-only mappings */
10682 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10683 goto bad_area;
10684diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10685index 5062ff3..e0b75f3 100644
10686--- a/arch/sparc/mm/fault_64.c
10687+++ b/arch/sparc/mm/fault_64.c
10688@@ -21,6 +21,9 @@
10689 #include <linux/kprobes.h>
10690 #include <linux/kdebug.h>
10691 #include <linux/percpu.h>
10692+#include <linux/slab.h>
10693+#include <linux/pagemap.h>
10694+#include <linux/compiler.h>
10695
10696 #include <asm/page.h>
10697 #include <asm/pgtable.h>
10698@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10699 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10700 regs->tpc);
10701 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10702- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10703+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10704 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10705 dump_stack();
10706 unhandled_fault(regs->tpc, current, regs);
10707@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10708 show_regs(regs);
10709 }
10710
10711+#ifdef CONFIG_PAX_PAGEEXEC
10712+#ifdef CONFIG_PAX_DLRESOLVE
10713+static void pax_emuplt_close(struct vm_area_struct *vma)
10714+{
10715+ vma->vm_mm->call_dl_resolve = 0UL;
10716+}
10717+
10718+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10719+{
10720+ unsigned int *kaddr;
10721+
10722+ vmf->page = alloc_page(GFP_HIGHUSER);
10723+ if (!vmf->page)
10724+ return VM_FAULT_OOM;
10725+
10726+ kaddr = kmap(vmf->page);
10727+ memset(kaddr, 0, PAGE_SIZE);
10728+ kaddr[0] = 0x9DE3BFA8U; /* save */
10729+ flush_dcache_page(vmf->page);
10730+ kunmap(vmf->page);
10731+ return VM_FAULT_MAJOR;
10732+}
10733+
10734+static const struct vm_operations_struct pax_vm_ops = {
10735+ .close = pax_emuplt_close,
10736+ .fault = pax_emuplt_fault
10737+};
10738+
10739+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10740+{
10741+ int ret;
10742+
10743+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10744+ vma->vm_mm = current->mm;
10745+ vma->vm_start = addr;
10746+ vma->vm_end = addr + PAGE_SIZE;
10747+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10748+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10749+ vma->vm_ops = &pax_vm_ops;
10750+
10751+ ret = insert_vm_struct(current->mm, vma);
10752+ if (ret)
10753+ return ret;
10754+
10755+ ++current->mm->total_vm;
10756+ return 0;
10757+}
10758+#endif
10759+
10760+/*
10761+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10762+ *
10763+ * returns 1 when task should be killed
10764+ * 2 when patched PLT trampoline was detected
10765+ * 3 when unpatched PLT trampoline was detected
10766+ */
10767+static int pax_handle_fetch_fault(struct pt_regs *regs)
10768+{
10769+
10770+#ifdef CONFIG_PAX_EMUPLT
10771+ int err;
10772+
10773+ do { /* PaX: patched PLT emulation #1 */
10774+ unsigned int sethi1, sethi2, jmpl;
10775+
10776+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10777+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10778+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10779+
10780+ if (err)
10781+ break;
10782+
10783+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10784+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10785+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10786+ {
10787+ unsigned long addr;
10788+
10789+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10790+ addr = regs->u_regs[UREG_G1];
10791+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10792+
10793+ if (test_thread_flag(TIF_32BIT))
10794+ addr &= 0xFFFFFFFFUL;
10795+
10796+ regs->tpc = addr;
10797+ regs->tnpc = addr+4;
10798+ return 2;
10799+ }
10800+ } while (0);
10801+
10802+ do { /* PaX: patched PLT emulation #2 */
10803+ unsigned int ba;
10804+
10805+ err = get_user(ba, (unsigned int *)regs->tpc);
10806+
10807+ if (err)
10808+ break;
10809+
10810+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10811+ unsigned long addr;
10812+
10813+ if ((ba & 0xFFC00000U) == 0x30800000U)
10814+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10815+ else
10816+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10817+
10818+ if (test_thread_flag(TIF_32BIT))
10819+ addr &= 0xFFFFFFFFUL;
10820+
10821+ regs->tpc = addr;
10822+ regs->tnpc = addr+4;
10823+ return 2;
10824+ }
10825+ } while (0);
10826+
10827+ do { /* PaX: patched PLT emulation #3 */
10828+ unsigned int sethi, bajmpl, nop;
10829+
10830+ err = get_user(sethi, (unsigned int *)regs->tpc);
10831+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10832+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10833+
10834+ if (err)
10835+ break;
10836+
10837+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10838+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10839+ nop == 0x01000000U)
10840+ {
10841+ unsigned long addr;
10842+
10843+ addr = (sethi & 0x003FFFFFU) << 10;
10844+ regs->u_regs[UREG_G1] = addr;
10845+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10846+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10847+ else
10848+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10849+
10850+ if (test_thread_flag(TIF_32BIT))
10851+ addr &= 0xFFFFFFFFUL;
10852+
10853+ regs->tpc = addr;
10854+ regs->tnpc = addr+4;
10855+ return 2;
10856+ }
10857+ } while (0);
10858+
10859+ do { /* PaX: patched PLT emulation #4 */
10860+ unsigned int sethi, mov1, call, mov2;
10861+
10862+ err = get_user(sethi, (unsigned int *)regs->tpc);
10863+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10864+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10865+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10866+
10867+ if (err)
10868+ break;
10869+
10870+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10871+ mov1 == 0x8210000FU &&
10872+ (call & 0xC0000000U) == 0x40000000U &&
10873+ mov2 == 0x9E100001U)
10874+ {
10875+ unsigned long addr;
10876+
10877+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10878+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10879+
10880+ if (test_thread_flag(TIF_32BIT))
10881+ addr &= 0xFFFFFFFFUL;
10882+
10883+ regs->tpc = addr;
10884+ regs->tnpc = addr+4;
10885+ return 2;
10886+ }
10887+ } while (0);
10888+
10889+ do { /* PaX: patched PLT emulation #5 */
10890+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10891+
10892+ err = get_user(sethi, (unsigned int *)regs->tpc);
10893+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10894+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10895+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10896+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10897+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10898+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10899+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10900+
10901+ if (err)
10902+ break;
10903+
10904+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10905+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10906+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10907+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10908+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10909+ sllx == 0x83287020U &&
10910+ jmpl == 0x81C04005U &&
10911+ nop == 0x01000000U)
10912+ {
10913+ unsigned long addr;
10914+
10915+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10916+ regs->u_regs[UREG_G1] <<= 32;
10917+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10918+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10919+ regs->tpc = addr;
10920+ regs->tnpc = addr+4;
10921+ return 2;
10922+ }
10923+ } while (0);
10924+
10925+ do { /* PaX: patched PLT emulation #6 */
10926+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10927+
10928+ err = get_user(sethi, (unsigned int *)regs->tpc);
10929+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10930+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10931+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10932+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10933+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10934+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10935+
10936+ if (err)
10937+ break;
10938+
10939+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10940+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10941+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10942+ sllx == 0x83287020U &&
10943+ (or & 0xFFFFE000U) == 0x8A116000U &&
10944+ jmpl == 0x81C04005U &&
10945+ nop == 0x01000000U)
10946+ {
10947+ unsigned long addr;
10948+
10949+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10950+ regs->u_regs[UREG_G1] <<= 32;
10951+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10952+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10953+ regs->tpc = addr;
10954+ regs->tnpc = addr+4;
10955+ return 2;
10956+ }
10957+ } while (0);
10958+
10959+ do { /* PaX: unpatched PLT emulation step 1 */
10960+ unsigned int sethi, ba, nop;
10961+
10962+ err = get_user(sethi, (unsigned int *)regs->tpc);
10963+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10964+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10965+
10966+ if (err)
10967+ break;
10968+
10969+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10970+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10971+ nop == 0x01000000U)
10972+ {
10973+ unsigned long addr;
10974+ unsigned int save, call;
10975+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10976+
10977+ if ((ba & 0xFFC00000U) == 0x30800000U)
10978+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10979+ else
10980+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10981+
10982+ if (test_thread_flag(TIF_32BIT))
10983+ addr &= 0xFFFFFFFFUL;
10984+
10985+ err = get_user(save, (unsigned int *)addr);
10986+ err |= get_user(call, (unsigned int *)(addr+4));
10987+ err |= get_user(nop, (unsigned int *)(addr+8));
10988+ if (err)
10989+ break;
10990+
10991+#ifdef CONFIG_PAX_DLRESOLVE
10992+ if (save == 0x9DE3BFA8U &&
10993+ (call & 0xC0000000U) == 0x40000000U &&
10994+ nop == 0x01000000U)
10995+ {
10996+ struct vm_area_struct *vma;
10997+ unsigned long call_dl_resolve;
10998+
10999+ down_read(&current->mm->mmap_sem);
11000+ call_dl_resolve = current->mm->call_dl_resolve;
11001+ up_read(&current->mm->mmap_sem);
11002+ if (likely(call_dl_resolve))
11003+ goto emulate;
11004+
11005+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11006+
11007+ down_write(&current->mm->mmap_sem);
11008+ if (current->mm->call_dl_resolve) {
11009+ call_dl_resolve = current->mm->call_dl_resolve;
11010+ up_write(&current->mm->mmap_sem);
11011+ if (vma)
11012+ kmem_cache_free(vm_area_cachep, vma);
11013+ goto emulate;
11014+ }
11015+
11016+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11017+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11018+ up_write(&current->mm->mmap_sem);
11019+ if (vma)
11020+ kmem_cache_free(vm_area_cachep, vma);
11021+ return 1;
11022+ }
11023+
11024+ if (pax_insert_vma(vma, call_dl_resolve)) {
11025+ up_write(&current->mm->mmap_sem);
11026+ kmem_cache_free(vm_area_cachep, vma);
11027+ return 1;
11028+ }
11029+
11030+ current->mm->call_dl_resolve = call_dl_resolve;
11031+ up_write(&current->mm->mmap_sem);
11032+
11033+emulate:
11034+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11035+ regs->tpc = call_dl_resolve;
11036+ regs->tnpc = addr+4;
11037+ return 3;
11038+ }
11039+#endif
11040+
11041+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11042+ if ((save & 0xFFC00000U) == 0x05000000U &&
11043+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11044+ nop == 0x01000000U)
11045+ {
11046+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11047+ regs->u_regs[UREG_G2] = addr + 4;
11048+ addr = (save & 0x003FFFFFU) << 10;
11049+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11050+
11051+ if (test_thread_flag(TIF_32BIT))
11052+ addr &= 0xFFFFFFFFUL;
11053+
11054+ regs->tpc = addr;
11055+ regs->tnpc = addr+4;
11056+ return 3;
11057+ }
11058+
11059+ /* PaX: 64-bit PLT stub */
11060+ err = get_user(sethi1, (unsigned int *)addr);
11061+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11062+ err |= get_user(or1, (unsigned int *)(addr+8));
11063+ err |= get_user(or2, (unsigned int *)(addr+12));
11064+ err |= get_user(sllx, (unsigned int *)(addr+16));
11065+ err |= get_user(add, (unsigned int *)(addr+20));
11066+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11067+ err |= get_user(nop, (unsigned int *)(addr+28));
11068+ if (err)
11069+ break;
11070+
11071+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11072+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11073+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11074+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11075+ sllx == 0x89293020U &&
11076+ add == 0x8A010005U &&
11077+ jmpl == 0x89C14000U &&
11078+ nop == 0x01000000U)
11079+ {
11080+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11081+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11082+ regs->u_regs[UREG_G4] <<= 32;
11083+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11084+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11085+ regs->u_regs[UREG_G4] = addr + 24;
11086+ addr = regs->u_regs[UREG_G5];
11087+ regs->tpc = addr;
11088+ regs->tnpc = addr+4;
11089+ return 3;
11090+ }
11091+ }
11092+ } while (0);
11093+
11094+#ifdef CONFIG_PAX_DLRESOLVE
11095+ do { /* PaX: unpatched PLT emulation step 2 */
11096+ unsigned int save, call, nop;
11097+
11098+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11099+ err |= get_user(call, (unsigned int *)regs->tpc);
11100+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11101+ if (err)
11102+ break;
11103+
11104+ if (save == 0x9DE3BFA8U &&
11105+ (call & 0xC0000000U) == 0x40000000U &&
11106+ nop == 0x01000000U)
11107+ {
11108+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11109+
11110+ if (test_thread_flag(TIF_32BIT))
11111+ dl_resolve &= 0xFFFFFFFFUL;
11112+
11113+ regs->u_regs[UREG_RETPC] = regs->tpc;
11114+ regs->tpc = dl_resolve;
11115+ regs->tnpc = dl_resolve+4;
11116+ return 3;
11117+ }
11118+ } while (0);
11119+#endif
11120+
11121+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11122+ unsigned int sethi, ba, nop;
11123+
11124+ err = get_user(sethi, (unsigned int *)regs->tpc);
11125+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11126+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11127+
11128+ if (err)
11129+ break;
11130+
11131+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11132+ (ba & 0xFFF00000U) == 0x30600000U &&
11133+ nop == 0x01000000U)
11134+ {
11135+ unsigned long addr;
11136+
11137+ addr = (sethi & 0x003FFFFFU) << 10;
11138+ regs->u_regs[UREG_G1] = addr;
11139+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11140+
11141+ if (test_thread_flag(TIF_32BIT))
11142+ addr &= 0xFFFFFFFFUL;
11143+
11144+ regs->tpc = addr;
11145+ regs->tnpc = addr+4;
11146+ return 2;
11147+ }
11148+ } while (0);
11149+
11150+#endif
11151+
11152+ return 1;
11153+}
11154+
11155+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11156+{
11157+ unsigned long i;
11158+
11159+ printk(KERN_ERR "PAX: bytes at PC: ");
11160+ for (i = 0; i < 8; i++) {
11161+ unsigned int c;
11162+ if (get_user(c, (unsigned int *)pc+i))
11163+ printk(KERN_CONT "???????? ");
11164+ else
11165+ printk(KERN_CONT "%08x ", c);
11166+ }
11167+ printk("\n");
11168+}
11169+#endif
11170+
11171 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11172 {
11173 struct mm_struct *mm = current->mm;
11174@@ -341,6 +804,29 @@ retry:
11175 if (!vma)
11176 goto bad_area;
11177
11178+#ifdef CONFIG_PAX_PAGEEXEC
11179+ /* PaX: detect ITLB misses on non-exec pages */
11180+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11181+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11182+ {
11183+ if (address != regs->tpc)
11184+ goto good_area;
11185+
11186+ up_read(&mm->mmap_sem);
11187+ switch (pax_handle_fetch_fault(regs)) {
11188+
11189+#ifdef CONFIG_PAX_EMUPLT
11190+ case 2:
11191+ case 3:
11192+ return;
11193+#endif
11194+
11195+ }
11196+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11197+ do_group_exit(SIGKILL);
11198+ }
11199+#endif
11200+
11201 /* Pure DTLB misses do not tell us whether the fault causing
11202 * load/store/atomic was a write or not, it only says that there
11203 * was no match. So in such a case we (carefully) read the
11204diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11205index d2b5944..d878f3c 100644
11206--- a/arch/sparc/mm/hugetlbpage.c
11207+++ b/arch/sparc/mm/hugetlbpage.c
11208@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11209 unsigned long addr,
11210 unsigned long len,
11211 unsigned long pgoff,
11212- unsigned long flags)
11213+ unsigned long flags,
11214+ unsigned long offset)
11215 {
11216 unsigned long task_size = TASK_SIZE;
11217 struct vm_unmapped_area_info info;
11218@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11219
11220 info.flags = 0;
11221 info.length = len;
11222- info.low_limit = TASK_UNMAPPED_BASE;
11223+ info.low_limit = mm->mmap_base;
11224 info.high_limit = min(task_size, VA_EXCLUDE_START);
11225 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11226 info.align_offset = 0;
11227+ info.threadstack_offset = offset;
11228 addr = vm_unmapped_area(&info);
11229
11230 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11231 VM_BUG_ON(addr != -ENOMEM);
11232 info.low_limit = VA_EXCLUDE_END;
11233+
11234+#ifdef CONFIG_PAX_RANDMMAP
11235+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11236+ info.low_limit += mm->delta_mmap;
11237+#endif
11238+
11239 info.high_limit = task_size;
11240 addr = vm_unmapped_area(&info);
11241 }
11242@@ -58,7 +66,8 @@ static unsigned long
11243 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11244 const unsigned long len,
11245 const unsigned long pgoff,
11246- const unsigned long flags)
11247+ const unsigned long flags,
11248+ const unsigned long offset)
11249 {
11250 struct mm_struct *mm = current->mm;
11251 unsigned long addr = addr0;
11252@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11253 info.high_limit = mm->mmap_base;
11254 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11255 info.align_offset = 0;
11256+ info.threadstack_offset = offset;
11257 addr = vm_unmapped_area(&info);
11258
11259 /*
11260@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11261 VM_BUG_ON(addr != -ENOMEM);
11262 info.flags = 0;
11263 info.low_limit = TASK_UNMAPPED_BASE;
11264+
11265+#ifdef CONFIG_PAX_RANDMMAP
11266+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11267+ info.low_limit += mm->delta_mmap;
11268+#endif
11269+
11270 info.high_limit = STACK_TOP32;
11271 addr = vm_unmapped_area(&info);
11272 }
11273@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11274 struct mm_struct *mm = current->mm;
11275 struct vm_area_struct *vma;
11276 unsigned long task_size = TASK_SIZE;
11277+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11278
11279 if (test_thread_flag(TIF_32BIT))
11280 task_size = STACK_TOP32;
11281@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11282 return addr;
11283 }
11284
11285+#ifdef CONFIG_PAX_RANDMMAP
11286+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11287+#endif
11288+
11289 if (addr) {
11290 addr = ALIGN(addr, HPAGE_SIZE);
11291 vma = find_vma(mm, addr);
11292- if (task_size - len >= addr &&
11293- (!vma || addr + len <= vma->vm_start))
11294+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11295 return addr;
11296 }
11297 if (mm->get_unmapped_area == arch_get_unmapped_area)
11298 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11299- pgoff, flags);
11300+ pgoff, flags, offset);
11301 else
11302 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11303- pgoff, flags);
11304+ pgoff, flags, offset);
11305 }
11306
11307 pte_t *huge_pte_alloc(struct mm_struct *mm,
11308diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11309index ed82eda..0d80e77 100644
11310--- a/arch/sparc/mm/init_64.c
11311+++ b/arch/sparc/mm/init_64.c
11312@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11313 int num_kernel_image_mappings;
11314
11315 #ifdef CONFIG_DEBUG_DCFLUSH
11316-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11317+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11318 #ifdef CONFIG_SMP
11319-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11320+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11321 #endif
11322 #endif
11323
11324@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11325 {
11326 BUG_ON(tlb_type == hypervisor);
11327 #ifdef CONFIG_DEBUG_DCFLUSH
11328- atomic_inc(&dcpage_flushes);
11329+ atomic_inc_unchecked(&dcpage_flushes);
11330 #endif
11331
11332 #ifdef DCACHE_ALIASING_POSSIBLE
11333@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11334
11335 #ifdef CONFIG_DEBUG_DCFLUSH
11336 seq_printf(m, "DCPageFlushes\t: %d\n",
11337- atomic_read(&dcpage_flushes));
11338+ atomic_read_unchecked(&dcpage_flushes));
11339 #ifdef CONFIG_SMP
11340 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11341- atomic_read(&dcpage_flushes_xcall));
11342+ atomic_read_unchecked(&dcpage_flushes_xcall));
11343 #endif /* CONFIG_SMP */
11344 #endif /* CONFIG_DEBUG_DCFLUSH */
11345 }
11346diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11347index f4500c6..889656c 100644
11348--- a/arch/tile/include/asm/atomic_64.h
11349+++ b/arch/tile/include/asm/atomic_64.h
11350@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11351
11352 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11353
11354+#define atomic64_read_unchecked(v) atomic64_read(v)
11355+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11356+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11357+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11358+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11359+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11360+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11361+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11362+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11363+
11364 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11365 #define smp_mb__before_atomic_dec() smp_mb()
11366 #define smp_mb__after_atomic_dec() smp_mb()
11367diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11368index a9a5299..0fce79e 100644
11369--- a/arch/tile/include/asm/cache.h
11370+++ b/arch/tile/include/asm/cache.h
11371@@ -15,11 +15,12 @@
11372 #ifndef _ASM_TILE_CACHE_H
11373 #define _ASM_TILE_CACHE_H
11374
11375+#include <linux/const.h>
11376 #include <arch/chip.h>
11377
11378 /* bytes per L1 data cache line */
11379 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11380-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11381+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11382
11383 /* bytes per L2 cache line */
11384 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11385diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11386index e4d44bd..99927a3 100644
11387--- a/arch/tile/include/asm/uaccess.h
11388+++ b/arch/tile/include/asm/uaccess.h
11389@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11390 const void __user *from,
11391 unsigned long n)
11392 {
11393- int sz = __compiletime_object_size(to);
11394+ size_t sz = __compiletime_object_size(to);
11395
11396- if (likely(sz == -1 || sz >= n))
11397+ if (likely(sz == (size_t)-1 || sz >= n))
11398 n = _copy_from_user(to, from, n);
11399 else
11400 copy_from_user_overflow();
11401diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11402index 650ccff..45fe2d6 100644
11403--- a/arch/tile/mm/hugetlbpage.c
11404+++ b/arch/tile/mm/hugetlbpage.c
11405@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11406 info.high_limit = TASK_SIZE;
11407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11408 info.align_offset = 0;
11409+ info.threadstack_offset = 0;
11410 return vm_unmapped_area(&info);
11411 }
11412
11413@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11414 info.high_limit = current->mm->mmap_base;
11415 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11416 info.align_offset = 0;
11417+ info.threadstack_offset = 0;
11418 addr = vm_unmapped_area(&info);
11419
11420 /*
11421diff --git a/arch/um/Makefile b/arch/um/Makefile
11422index 133f7de..1d6f2f1 100644
11423--- a/arch/um/Makefile
11424+++ b/arch/um/Makefile
11425@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11428
11429+ifdef CONSTIFY_PLUGIN
11430+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11431+endif
11432+
11433 #This will adjust *FLAGS accordingly to the platform.
11434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11435
11436diff --git a/arch/um/defconfig b/arch/um/defconfig
11437index 08107a7..ab22afe 100644
11438--- a/arch/um/defconfig
11439+++ b/arch/um/defconfig
11440@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11441 CONFIG_X86_L1_CACHE_SHIFT=5
11442 CONFIG_X86_XADD=y
11443 CONFIG_X86_PPRO_FENCE=y
11444-CONFIG_X86_WP_WORKS_OK=y
11445 CONFIG_X86_INVLPG=y
11446 CONFIG_X86_BSWAP=y
11447 CONFIG_X86_POPAD_OK=y
11448diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11449index 19e1bdd..3665b77 100644
11450--- a/arch/um/include/asm/cache.h
11451+++ b/arch/um/include/asm/cache.h
11452@@ -1,6 +1,7 @@
11453 #ifndef __UM_CACHE_H
11454 #define __UM_CACHE_H
11455
11456+#include <linux/const.h>
11457
11458 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11459 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11460@@ -12,6 +13,6 @@
11461 # define L1_CACHE_SHIFT 5
11462 #endif
11463
11464-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11465+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11466
11467 #endif
11468diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11469index 2e0a6b1..a64d0f5 100644
11470--- a/arch/um/include/asm/kmap_types.h
11471+++ b/arch/um/include/asm/kmap_types.h
11472@@ -8,6 +8,6 @@
11473
11474 /* No more #include "asm/arch/kmap_types.h" ! */
11475
11476-#define KM_TYPE_NR 14
11477+#define KM_TYPE_NR 15
11478
11479 #endif
11480diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11481index 5ff53d9..5850cdf 100644
11482--- a/arch/um/include/asm/page.h
11483+++ b/arch/um/include/asm/page.h
11484@@ -14,6 +14,9 @@
11485 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11486 #define PAGE_MASK (~(PAGE_SIZE-1))
11487
11488+#define ktla_ktva(addr) (addr)
11489+#define ktva_ktla(addr) (addr)
11490+
11491 #ifndef __ASSEMBLY__
11492
11493 struct page;
11494diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11495index 0032f92..cd151e0 100644
11496--- a/arch/um/include/asm/pgtable-3level.h
11497+++ b/arch/um/include/asm/pgtable-3level.h
11498@@ -58,6 +58,7 @@
11499 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11500 #define pud_populate(mm, pud, pmd) \
11501 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11502+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11503
11504 #ifdef CONFIG_64BIT
11505 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11506diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11507index bbcef52..6a2a483 100644
11508--- a/arch/um/kernel/process.c
11509+++ b/arch/um/kernel/process.c
11510@@ -367,22 +367,6 @@ int singlestepping(void * t)
11511 return 2;
11512 }
11513
11514-/*
11515- * Only x86 and x86_64 have an arch_align_stack().
11516- * All other arches have "#define arch_align_stack(x) (x)"
11517- * in their asm/system.h
11518- * As this is included in UML from asm-um/system-generic.h,
11519- * we can use it to behave as the subarch does.
11520- */
11521-#ifndef arch_align_stack
11522-unsigned long arch_align_stack(unsigned long sp)
11523-{
11524- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11525- sp -= get_random_int() % 8192;
11526- return sp & ~0xf;
11527-}
11528-#endif
11529-
11530 unsigned long get_wchan(struct task_struct *p)
11531 {
11532 unsigned long stack_page, sp, ip;
11533diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11534index ad8f795..2c7eec6 100644
11535--- a/arch/unicore32/include/asm/cache.h
11536+++ b/arch/unicore32/include/asm/cache.h
11537@@ -12,8 +12,10 @@
11538 #ifndef __UNICORE_CACHE_H__
11539 #define __UNICORE_CACHE_H__
11540
11541-#define L1_CACHE_SHIFT (5)
11542-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11543+#include <linux/const.h>
11544+
11545+#define L1_CACHE_SHIFT 5
11546+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11547
11548 /*
11549 * Memory returned by kmalloc() may be used for DMA, so we must make
11550diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11551index b32ebf9..5704f98 100644
11552--- a/arch/x86/Kconfig
11553+++ b/arch/x86/Kconfig
11554@@ -248,7 +248,7 @@ config X86_HT
11555
11556 config X86_32_LAZY_GS
11557 def_bool y
11558- depends on X86_32 && !CC_STACKPROTECTOR
11559+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11560
11561 config ARCH_HWEIGHT_CFLAGS
11562 string
11563@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11564
11565 config X86_MSR
11566 tristate "/dev/cpu/*/msr - Model-specific register support"
11567+ depends on !GRKERNSEC_KMEM
11568 ---help---
11569 This device gives privileged processes access to the x86
11570 Model-Specific Registers (MSRs). It is a character device with
11571@@ -1111,7 +1112,7 @@ choice
11572
11573 config NOHIGHMEM
11574 bool "off"
11575- depends on !X86_NUMAQ
11576+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11577 ---help---
11578 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11579 However, the address space of 32-bit x86 processors is only 4
11580@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11581
11582 config HIGHMEM4G
11583 bool "4GB"
11584- depends on !X86_NUMAQ
11585+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11586 ---help---
11587 Select this if you have a 32-bit processor and between 1 and 4
11588 gigabytes of physical RAM.
11589@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11590 hex
11591 default 0xB0000000 if VMSPLIT_3G_OPT
11592 default 0x80000000 if VMSPLIT_2G
11593- default 0x78000000 if VMSPLIT_2G_OPT
11594+ default 0x70000000 if VMSPLIT_2G_OPT
11595 default 0x40000000 if VMSPLIT_1G
11596 default 0xC0000000
11597 depends on X86_32
11598@@ -1599,6 +1600,7 @@ config SECCOMP
11599
11600 config CC_STACKPROTECTOR
11601 bool "Enable -fstack-protector buffer overflow detection"
11602+ depends on X86_64 || !PAX_MEMORY_UDEREF
11603 ---help---
11604 This option turns on the -fstack-protector GCC feature. This
11605 feature puts, at the beginning of functions, a canary value on
11606@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11607 config PHYSICAL_ALIGN
11608 hex "Alignment value to which kernel should be aligned" if X86_32
11609 default "0x1000000"
11610+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11611+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11612 range 0x2000 0x1000000
11613 ---help---
11614 This value puts the alignment restrictions on physical address
11615@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11616 If unsure, say N.
11617
11618 config COMPAT_VDSO
11619- def_bool y
11620+ def_bool n
11621 prompt "Compat VDSO support"
11622 depends on X86_32 || IA32_EMULATION
11623+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11624 ---help---
11625 Map the 32-bit VDSO to the predictable old-style address too.
11626
11627diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11628index c026cca..14657ae 100644
11629--- a/arch/x86/Kconfig.cpu
11630+++ b/arch/x86/Kconfig.cpu
11631@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11632
11633 config X86_F00F_BUG
11634 def_bool y
11635- depends on M586MMX || M586TSC || M586 || M486
11636+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11637
11638 config X86_INVD_BUG
11639 def_bool y
11640@@ -327,7 +327,7 @@ config X86_INVD_BUG
11641
11642 config X86_ALIGNMENT_16
11643 def_bool y
11644- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11645+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11646
11647 config X86_INTEL_USERCOPY
11648 def_bool y
11649@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11650 # generates cmov.
11651 config X86_CMOV
11652 def_bool y
11653- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11654+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11655
11656 config X86_MINIMUM_CPU_FAMILY
11657 int
11658diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11659index 78d91af..8ceb94b 100644
11660--- a/arch/x86/Kconfig.debug
11661+++ b/arch/x86/Kconfig.debug
11662@@ -74,7 +74,7 @@ config X86_PTDUMP
11663 config DEBUG_RODATA
11664 bool "Write protect kernel read-only data structures"
11665 default y
11666- depends on DEBUG_KERNEL
11667+ depends on DEBUG_KERNEL && BROKEN
11668 ---help---
11669 Mark the kernel read-only data as write-protected in the pagetables,
11670 in order to catch accidental (and incorrect) writes to such const
11671@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11672
11673 config DEBUG_SET_MODULE_RONX
11674 bool "Set loadable kernel module data as NX and text as RO"
11675- depends on MODULES
11676+ depends on MODULES && BROKEN
11677 ---help---
11678 This option helps catch unintended modifications to loadable
11679 kernel module's text and read-only data. It also prevents execution
11680diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11681index 07639c6..6f2c901 100644
11682--- a/arch/x86/Makefile
11683+++ b/arch/x86/Makefile
11684@@ -54,6 +54,7 @@ else
11685 UTS_MACHINE := x86_64
11686 CHECKFLAGS += -D__x86_64__ -m64
11687
11688+ biarch := $(call cc-option,-m64)
11689 KBUILD_AFLAGS += -m64
11690 KBUILD_CFLAGS += -m64
11691
11692@@ -241,3 +242,12 @@ define archhelp
11693 echo ' FDINITRD=file initrd for the booted kernel'
11694 echo ' kvmconfig - Enable additional options for guest kernel support'
11695 endef
11696+
11697+define OLD_LD
11698+
11699+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11700+*** Please upgrade your binutils to 2.18 or newer
11701+endef
11702+
11703+archprepare:
11704+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11705diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11706index 379814b..add62ce 100644
11707--- a/arch/x86/boot/Makefile
11708+++ b/arch/x86/boot/Makefile
11709@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11710 $(call cc-option, -fno-stack-protector) \
11711 $(call cc-option, -mpreferred-stack-boundary=2)
11712 KBUILD_CFLAGS += $(call cc-option, -m32)
11713+ifdef CONSTIFY_PLUGIN
11714+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11715+endif
11716 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11717 GCOV_PROFILE := n
11718
11719diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11720index 878e4b9..20537ab 100644
11721--- a/arch/x86/boot/bitops.h
11722+++ b/arch/x86/boot/bitops.h
11723@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11724 u8 v;
11725 const u32 *p = (const u32 *)addr;
11726
11727- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11728+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11729 return v;
11730 }
11731
11732@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11733
11734 static inline void set_bit(int nr, void *addr)
11735 {
11736- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11737+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11738 }
11739
11740 #endif /* BOOT_BITOPS_H */
11741diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11742index 5b75319..331a4ca 100644
11743--- a/arch/x86/boot/boot.h
11744+++ b/arch/x86/boot/boot.h
11745@@ -85,7 +85,7 @@ static inline void io_delay(void)
11746 static inline u16 ds(void)
11747 {
11748 u16 seg;
11749- asm("movw %%ds,%0" : "=rm" (seg));
11750+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11751 return seg;
11752 }
11753
11754@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11755 static inline int memcmp(const void *s1, const void *s2, size_t len)
11756 {
11757 u8 diff;
11758- asm("repe; cmpsb; setnz %0"
11759+ asm volatile("repe; cmpsb; setnz %0"
11760 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11761 return diff;
11762 }
11763diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11764index dcd90df..c830d7d 100644
11765--- a/arch/x86/boot/compressed/Makefile
11766+++ b/arch/x86/boot/compressed/Makefile
11767@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11768 KBUILD_CFLAGS += $(cflags-y)
11769 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11770 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11771+ifdef CONSTIFY_PLUGIN
11772+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11773+endif
11774
11775 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11776 GCOV_PROFILE := n
11777diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11778index b7388a4..03844ec 100644
11779--- a/arch/x86/boot/compressed/eboot.c
11780+++ b/arch/x86/boot/compressed/eboot.c
11781@@ -150,7 +150,6 @@ again:
11782 *addr = max_addr;
11783 }
11784
11785-free_pool:
11786 efi_call_phys1(sys_table->boottime->free_pool, map);
11787
11788 fail:
11789@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11790 if (i == map_size / desc_size)
11791 status = EFI_NOT_FOUND;
11792
11793-free_pool:
11794 efi_call_phys1(sys_table->boottime->free_pool, map);
11795 fail:
11796 return status;
11797diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11798index a53440e..c3dbf1e 100644
11799--- a/arch/x86/boot/compressed/efi_stub_32.S
11800+++ b/arch/x86/boot/compressed/efi_stub_32.S
11801@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11802 * parameter 2, ..., param n. To make things easy, we save the return
11803 * address of efi_call_phys in a global variable.
11804 */
11805- popl %ecx
11806- movl %ecx, saved_return_addr(%edx)
11807- /* get the function pointer into ECX*/
11808- popl %ecx
11809- movl %ecx, efi_rt_function_ptr(%edx)
11810+ popl saved_return_addr(%edx)
11811+ popl efi_rt_function_ptr(%edx)
11812
11813 /*
11814 * 3. Call the physical function.
11815 */
11816- call *%ecx
11817+ call *efi_rt_function_ptr(%edx)
11818
11819 /*
11820 * 4. Balance the stack. And because EAX contain the return value,
11821@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11822 1: popl %edx
11823 subl $1b, %edx
11824
11825- movl efi_rt_function_ptr(%edx), %ecx
11826- pushl %ecx
11827+ pushl efi_rt_function_ptr(%edx)
11828
11829 /*
11830 * 10. Push the saved return address onto the stack and return.
11831 */
11832- movl saved_return_addr(%edx), %ecx
11833- pushl %ecx
11834- ret
11835+ jmpl *saved_return_addr(%edx)
11836 ENDPROC(efi_call_phys)
11837 .previous
11838
11839diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11840index 1e3184f..0d11e2e 100644
11841--- a/arch/x86/boot/compressed/head_32.S
11842+++ b/arch/x86/boot/compressed/head_32.S
11843@@ -118,7 +118,7 @@ preferred_addr:
11844 notl %eax
11845 andl %eax, %ebx
11846 #else
11847- movl $LOAD_PHYSICAL_ADDR, %ebx
11848+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11849 #endif
11850
11851 /* Target address to relocate to for decompression */
11852@@ -204,7 +204,7 @@ relocated:
11853 * and where it was actually loaded.
11854 */
11855 movl %ebp, %ebx
11856- subl $LOAD_PHYSICAL_ADDR, %ebx
11857+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11858 jz 2f /* Nothing to be done if loaded at compiled addr. */
11859 /*
11860 * Process relocations.
11861@@ -212,8 +212,7 @@ relocated:
11862
11863 1: subl $4, %edi
11864 movl (%edi), %ecx
11865- testl %ecx, %ecx
11866- jz 2f
11867+ jecxz 2f
11868 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11869 jmp 1b
11870 2:
11871diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11872index 06e71c2..88a98264 100644
11873--- a/arch/x86/boot/compressed/head_64.S
11874+++ b/arch/x86/boot/compressed/head_64.S
11875@@ -95,7 +95,7 @@ ENTRY(startup_32)
11876 notl %eax
11877 andl %eax, %ebx
11878 #else
11879- movl $LOAD_PHYSICAL_ADDR, %ebx
11880+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11881 #endif
11882
11883 /* Target address to relocate to for decompression */
11884@@ -270,7 +270,7 @@ preferred_addr:
11885 notq %rax
11886 andq %rax, %rbp
11887 #else
11888- movq $LOAD_PHYSICAL_ADDR, %rbp
11889+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11890 #endif
11891
11892 /* Target address to relocate to for decompression */
11893@@ -361,8 +361,8 @@ gdt:
11894 .long gdt
11895 .word 0
11896 .quad 0x0000000000000000 /* NULL descriptor */
11897- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11898- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11899+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11900+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11901 .quad 0x0080890000000000 /* TS descriptor */
11902 .quad 0x0000000000000000 /* TS continued */
11903 gdt_end:
11904diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11905index 0319c88..7c1931f 100644
11906--- a/arch/x86/boot/compressed/misc.c
11907+++ b/arch/x86/boot/compressed/misc.c
11908@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11909 case PT_LOAD:
11910 #ifdef CONFIG_RELOCATABLE
11911 dest = output;
11912- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11913+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11914 #else
11915 dest = (void *)(phdr->p_paddr);
11916 #endif
11917@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11918 error("Destination address too large");
11919 #endif
11920 #ifndef CONFIG_RELOCATABLE
11921- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11922+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11923 error("Wrong destination address");
11924 #endif
11925
11926diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11927index 4d3ff03..e4972ff 100644
11928--- a/arch/x86/boot/cpucheck.c
11929+++ b/arch/x86/boot/cpucheck.c
11930@@ -74,7 +74,7 @@ static int has_fpu(void)
11931 u16 fcw = -1, fsw = -1;
11932 u32 cr0;
11933
11934- asm("movl %%cr0,%0" : "=r" (cr0));
11935+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11936 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11937 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11938 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11939@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11940 {
11941 u32 f0, f1;
11942
11943- asm("pushfl ; "
11944+ asm volatile("pushfl ; "
11945 "pushfl ; "
11946 "popl %0 ; "
11947 "movl %0,%1 ; "
11948@@ -115,7 +115,7 @@ static void get_flags(void)
11949 set_bit(X86_FEATURE_FPU, cpu.flags);
11950
11951 if (has_eflag(X86_EFLAGS_ID)) {
11952- asm("cpuid"
11953+ asm volatile("cpuid"
11954 : "=a" (max_intel_level),
11955 "=b" (cpu_vendor[0]),
11956 "=d" (cpu_vendor[1]),
11957@@ -124,7 +124,7 @@ static void get_flags(void)
11958
11959 if (max_intel_level >= 0x00000001 &&
11960 max_intel_level <= 0x0000ffff) {
11961- asm("cpuid"
11962+ asm volatile("cpuid"
11963 : "=a" (tfms),
11964 "=c" (cpu.flags[4]),
11965 "=d" (cpu.flags[0])
11966@@ -136,7 +136,7 @@ static void get_flags(void)
11967 cpu.model += ((tfms >> 16) & 0xf) << 4;
11968 }
11969
11970- asm("cpuid"
11971+ asm volatile("cpuid"
11972 : "=a" (max_amd_level)
11973 : "a" (0x80000000)
11974 : "ebx", "ecx", "edx");
11975@@ -144,7 +144,7 @@ static void get_flags(void)
11976 if (max_amd_level >= 0x80000001 &&
11977 max_amd_level <= 0x8000ffff) {
11978 u32 eax = 0x80000001;
11979- asm("cpuid"
11980+ asm volatile("cpuid"
11981 : "+a" (eax),
11982 "=c" (cpu.flags[6]),
11983 "=d" (cpu.flags[1])
11984@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11985 u32 ecx = MSR_K7_HWCR;
11986 u32 eax, edx;
11987
11988- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11989+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11990 eax &= ~(1 << 15);
11991- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11992+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11993
11994 get_flags(); /* Make sure it really did something */
11995 err = check_flags();
11996@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11997 u32 ecx = MSR_VIA_FCR;
11998 u32 eax, edx;
11999
12000- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12001+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12002 eax |= (1<<1)|(1<<7);
12003- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12004+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12005
12006 set_bit(X86_FEATURE_CX8, cpu.flags);
12007 err = check_flags();
12008@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12009 u32 eax, edx;
12010 u32 level = 1;
12011
12012- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12013- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12014- asm("cpuid"
12015+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12016+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12017+ asm volatile("cpuid"
12018 : "+a" (level), "=d" (cpu.flags[0])
12019 : : "ecx", "ebx");
12020- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12021+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12022
12023 err = check_flags();
12024 }
12025diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12026index 9ec06a1..2c25e79 100644
12027--- a/arch/x86/boot/header.S
12028+++ b/arch/x86/boot/header.S
12029@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12030 # single linked list of
12031 # struct setup_data
12032
12033-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12034+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12035
12036 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12037+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12038+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12039+#else
12040 #define VO_INIT_SIZE (VO__end - VO__text)
12041+#endif
12042 #if ZO_INIT_SIZE > VO_INIT_SIZE
12043 #define INIT_SIZE ZO_INIT_SIZE
12044 #else
12045diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12046index db75d07..8e6d0af 100644
12047--- a/arch/x86/boot/memory.c
12048+++ b/arch/x86/boot/memory.c
12049@@ -19,7 +19,7 @@
12050
12051 static int detect_memory_e820(void)
12052 {
12053- int count = 0;
12054+ unsigned int count = 0;
12055 struct biosregs ireg, oreg;
12056 struct e820entry *desc = boot_params.e820_map;
12057 static struct e820entry buf; /* static so it is zeroed */
12058diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12059index 11e8c6e..fdbb1ed 100644
12060--- a/arch/x86/boot/video-vesa.c
12061+++ b/arch/x86/boot/video-vesa.c
12062@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12063
12064 boot_params.screen_info.vesapm_seg = oreg.es;
12065 boot_params.screen_info.vesapm_off = oreg.di;
12066+ boot_params.screen_info.vesapm_size = oreg.cx;
12067 }
12068
12069 /*
12070diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12071index 43eda28..5ab5fdb 100644
12072--- a/arch/x86/boot/video.c
12073+++ b/arch/x86/boot/video.c
12074@@ -96,7 +96,7 @@ static void store_mode_params(void)
12075 static unsigned int get_entry(void)
12076 {
12077 char entry_buf[4];
12078- int i, len = 0;
12079+ unsigned int i, len = 0;
12080 int key;
12081 unsigned int v;
12082
12083diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12084index 9105655..5e37f27 100644
12085--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12086+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12087@@ -8,6 +8,8 @@
12088 * including this sentence is retained in full.
12089 */
12090
12091+#include <asm/alternative-asm.h>
12092+
12093 .extern crypto_ft_tab
12094 .extern crypto_it_tab
12095 .extern crypto_fl_tab
12096@@ -70,6 +72,8 @@
12097 je B192; \
12098 leaq 32(r9),r9;
12099
12100+#define ret pax_force_retaddr 0, 1; ret
12101+
12102 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12103 movq r1,r2; \
12104 movq r3,r4; \
12105diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12106index 477e9d7..3ab339f 100644
12107--- a/arch/x86/crypto/aesni-intel_asm.S
12108+++ b/arch/x86/crypto/aesni-intel_asm.S
12109@@ -31,6 +31,7 @@
12110
12111 #include <linux/linkage.h>
12112 #include <asm/inst.h>
12113+#include <asm/alternative-asm.h>
12114
12115 #ifdef __x86_64__
12116 .data
12117@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12118 pop %r14
12119 pop %r13
12120 pop %r12
12121+ pax_force_retaddr 0, 1
12122 ret
12123 ENDPROC(aesni_gcm_dec)
12124
12125@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12126 pop %r14
12127 pop %r13
12128 pop %r12
12129+ pax_force_retaddr 0, 1
12130 ret
12131 ENDPROC(aesni_gcm_enc)
12132
12133@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12134 pxor %xmm1, %xmm0
12135 movaps %xmm0, (TKEYP)
12136 add $0x10, TKEYP
12137+ pax_force_retaddr_bts
12138 ret
12139 ENDPROC(_key_expansion_128)
12140 ENDPROC(_key_expansion_256a)
12141@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12142 shufps $0b01001110, %xmm2, %xmm1
12143 movaps %xmm1, 0x10(TKEYP)
12144 add $0x20, TKEYP
12145+ pax_force_retaddr_bts
12146 ret
12147 ENDPROC(_key_expansion_192a)
12148
12149@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12150
12151 movaps %xmm0, (TKEYP)
12152 add $0x10, TKEYP
12153+ pax_force_retaddr_bts
12154 ret
12155 ENDPROC(_key_expansion_192b)
12156
12157@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12158 pxor %xmm1, %xmm2
12159 movaps %xmm2, (TKEYP)
12160 add $0x10, TKEYP
12161+ pax_force_retaddr_bts
12162 ret
12163 ENDPROC(_key_expansion_256b)
12164
12165@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12166 #ifndef __x86_64__
12167 popl KEYP
12168 #endif
12169+ pax_force_retaddr 0, 1
12170 ret
12171 ENDPROC(aesni_set_key)
12172
12173@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12174 popl KLEN
12175 popl KEYP
12176 #endif
12177+ pax_force_retaddr 0, 1
12178 ret
12179 ENDPROC(aesni_enc)
12180
12181@@ -1974,6 +1983,7 @@ _aesni_enc1:
12182 AESENC KEY STATE
12183 movaps 0x70(TKEYP), KEY
12184 AESENCLAST KEY STATE
12185+ pax_force_retaddr_bts
12186 ret
12187 ENDPROC(_aesni_enc1)
12188
12189@@ -2083,6 +2093,7 @@ _aesni_enc4:
12190 AESENCLAST KEY STATE2
12191 AESENCLAST KEY STATE3
12192 AESENCLAST KEY STATE4
12193+ pax_force_retaddr_bts
12194 ret
12195 ENDPROC(_aesni_enc4)
12196
12197@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12198 popl KLEN
12199 popl KEYP
12200 #endif
12201+ pax_force_retaddr 0, 1
12202 ret
12203 ENDPROC(aesni_dec)
12204
12205@@ -2164,6 +2176,7 @@ _aesni_dec1:
12206 AESDEC KEY STATE
12207 movaps 0x70(TKEYP), KEY
12208 AESDECLAST KEY STATE
12209+ pax_force_retaddr_bts
12210 ret
12211 ENDPROC(_aesni_dec1)
12212
12213@@ -2273,6 +2286,7 @@ _aesni_dec4:
12214 AESDECLAST KEY STATE2
12215 AESDECLAST KEY STATE3
12216 AESDECLAST KEY STATE4
12217+ pax_force_retaddr_bts
12218 ret
12219 ENDPROC(_aesni_dec4)
12220
12221@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12222 popl KEYP
12223 popl LEN
12224 #endif
12225+ pax_force_retaddr 0, 1
12226 ret
12227 ENDPROC(aesni_ecb_enc)
12228
12229@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12230 popl KEYP
12231 popl LEN
12232 #endif
12233+ pax_force_retaddr 0, 1
12234 ret
12235 ENDPROC(aesni_ecb_dec)
12236
12237@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12238 popl LEN
12239 popl IVP
12240 #endif
12241+ pax_force_retaddr 0, 1
12242 ret
12243 ENDPROC(aesni_cbc_enc)
12244
12245@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12246 popl LEN
12247 popl IVP
12248 #endif
12249+ pax_force_retaddr 0, 1
12250 ret
12251 ENDPROC(aesni_cbc_dec)
12252
12253@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12254 mov $1, TCTR_LOW
12255 MOVQ_R64_XMM TCTR_LOW INC
12256 MOVQ_R64_XMM CTR TCTR_LOW
12257+ pax_force_retaddr_bts
12258 ret
12259 ENDPROC(_aesni_inc_init)
12260
12261@@ -2579,6 +2598,7 @@ _aesni_inc:
12262 .Linc_low:
12263 movaps CTR, IV
12264 PSHUFB_XMM BSWAP_MASK IV
12265+ pax_force_retaddr_bts
12266 ret
12267 ENDPROC(_aesni_inc)
12268
12269@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12270 .Lctr_enc_ret:
12271 movups IV, (IVP)
12272 .Lctr_enc_just_ret:
12273+ pax_force_retaddr 0, 1
12274 ret
12275 ENDPROC(aesni_ctr_enc)
12276
12277@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12278 pxor INC, STATE4
12279 movdqu STATE4, 0x70(OUTP)
12280
12281+ pax_force_retaddr 0, 1
12282 ret
12283 ENDPROC(aesni_xts_crypt8)
12284
12285diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12286index 246c670..4d1ed00 100644
12287--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12288+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12289@@ -21,6 +21,7 @@
12290 */
12291
12292 #include <linux/linkage.h>
12293+#include <asm/alternative-asm.h>
12294
12295 .file "blowfish-x86_64-asm.S"
12296 .text
12297@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12298 jnz .L__enc_xor;
12299
12300 write_block();
12301+ pax_force_retaddr 0, 1
12302 ret;
12303 .L__enc_xor:
12304 xor_block();
12305+ pax_force_retaddr 0, 1
12306 ret;
12307 ENDPROC(__blowfish_enc_blk)
12308
12309@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12310
12311 movq %r11, %rbp;
12312
12313+ pax_force_retaddr 0, 1
12314 ret;
12315 ENDPROC(blowfish_dec_blk)
12316
12317@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12318
12319 popq %rbx;
12320 popq %rbp;
12321+ pax_force_retaddr 0, 1
12322 ret;
12323
12324 .L__enc_xor4:
12325@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12326
12327 popq %rbx;
12328 popq %rbp;
12329+ pax_force_retaddr 0, 1
12330 ret;
12331 ENDPROC(__blowfish_enc_blk_4way)
12332
12333@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12334 popq %rbx;
12335 popq %rbp;
12336
12337+ pax_force_retaddr 0, 1
12338 ret;
12339 ENDPROC(blowfish_dec_blk_4way)
12340diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12341index ce71f92..2dd5b1e 100644
12342--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12343+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12344@@ -16,6 +16,7 @@
12345 */
12346
12347 #include <linux/linkage.h>
12348+#include <asm/alternative-asm.h>
12349
12350 #define CAMELLIA_TABLE_BYTE_LEN 272
12351
12352@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12353 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12354 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12355 %rcx, (%r9));
12356+ pax_force_retaddr_bts
12357 ret;
12358 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12359
12360@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12361 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12362 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12363 %rax, (%r9));
12364+ pax_force_retaddr_bts
12365 ret;
12366 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12367
12368@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12369 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12370 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12371
12372+ pax_force_retaddr_bts
12373 ret;
12374
12375 .align 8
12376@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12377 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12378 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12379
12380+ pax_force_retaddr_bts
12381 ret;
12382
12383 .align 8
12384@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12385 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12386 %xmm8, %rsi);
12387
12388+ pax_force_retaddr 0, 1
12389 ret;
12390 ENDPROC(camellia_ecb_enc_16way)
12391
12392@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12393 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12394 %xmm8, %rsi);
12395
12396+ pax_force_retaddr 0, 1
12397 ret;
12398 ENDPROC(camellia_ecb_dec_16way)
12399
12400@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12401 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12402 %xmm8, %rsi);
12403
12404+ pax_force_retaddr 0, 1
12405 ret;
12406 ENDPROC(camellia_cbc_dec_16way)
12407
12408@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12409 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12410 %xmm8, %rsi);
12411
12412+ pax_force_retaddr 0, 1
12413 ret;
12414 ENDPROC(camellia_ctr_16way)
12415
12416@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12417 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12418 %xmm8, %rsi);
12419
12420+ pax_force_retaddr 0, 1
12421 ret;
12422 ENDPROC(camellia_xts_crypt_16way)
12423
12424diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12425index 0e0b886..8fc756a 100644
12426--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12427+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12428@@ -11,6 +11,7 @@
12429 */
12430
12431 #include <linux/linkage.h>
12432+#include <asm/alternative-asm.h>
12433
12434 #define CAMELLIA_TABLE_BYTE_LEN 272
12435
12436@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12437 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12438 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12439 %rcx, (%r9));
12440+ pax_force_retaddr_bts
12441 ret;
12442 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12443
12444@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12445 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12446 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12447 %rax, (%r9));
12448+ pax_force_retaddr_bts
12449 ret;
12450 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12451
12452@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12453 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12454 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12455
12456+ pax_force_retaddr_bts
12457 ret;
12458
12459 .align 8
12460@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12461 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12462 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12463
12464+ pax_force_retaddr_bts
12465 ret;
12466
12467 .align 8
12468@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12469
12470 vzeroupper;
12471
12472+ pax_force_retaddr 0, 1
12473 ret;
12474 ENDPROC(camellia_ecb_enc_32way)
12475
12476@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12477
12478 vzeroupper;
12479
12480+ pax_force_retaddr 0, 1
12481 ret;
12482 ENDPROC(camellia_ecb_dec_32way)
12483
12484@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12485
12486 vzeroupper;
12487
12488+ pax_force_retaddr 0, 1
12489 ret;
12490 ENDPROC(camellia_cbc_dec_32way)
12491
12492@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12493
12494 vzeroupper;
12495
12496+ pax_force_retaddr 0, 1
12497 ret;
12498 ENDPROC(camellia_ctr_32way)
12499
12500@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12501
12502 vzeroupper;
12503
12504+ pax_force_retaddr 0, 1
12505 ret;
12506 ENDPROC(camellia_xts_crypt_32way)
12507
12508diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12509index 310319c..ce174a4 100644
12510--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12511+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12512@@ -21,6 +21,7 @@
12513 */
12514
12515 #include <linux/linkage.h>
12516+#include <asm/alternative-asm.h>
12517
12518 .file "camellia-x86_64-asm_64.S"
12519 .text
12520@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12521 enc_outunpack(mov, RT1);
12522
12523 movq RRBP, %rbp;
12524+ pax_force_retaddr 0, 1
12525 ret;
12526
12527 .L__enc_xor:
12528 enc_outunpack(xor, RT1);
12529
12530 movq RRBP, %rbp;
12531+ pax_force_retaddr 0, 1
12532 ret;
12533 ENDPROC(__camellia_enc_blk)
12534
12535@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12536 dec_outunpack();
12537
12538 movq RRBP, %rbp;
12539+ pax_force_retaddr 0, 1
12540 ret;
12541 ENDPROC(camellia_dec_blk)
12542
12543@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12544
12545 movq RRBP, %rbp;
12546 popq %rbx;
12547+ pax_force_retaddr 0, 1
12548 ret;
12549
12550 .L__enc2_xor:
12551@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12552
12553 movq RRBP, %rbp;
12554 popq %rbx;
12555+ pax_force_retaddr 0, 1
12556 ret;
12557 ENDPROC(__camellia_enc_blk_2way)
12558
12559@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12560
12561 movq RRBP, %rbp;
12562 movq RXOR, %rbx;
12563+ pax_force_retaddr 0, 1
12564 ret;
12565 ENDPROC(camellia_dec_blk_2way)
12566diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12567index c35fd5d..c1ee236 100644
12568--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12569+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12570@@ -24,6 +24,7 @@
12571 */
12572
12573 #include <linux/linkage.h>
12574+#include <asm/alternative-asm.h>
12575
12576 .file "cast5-avx-x86_64-asm_64.S"
12577
12578@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12579 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12580 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12581
12582+ pax_force_retaddr 0, 1
12583 ret;
12584 ENDPROC(__cast5_enc_blk16)
12585
12586@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12587 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12588 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12589
12590+ pax_force_retaddr 0, 1
12591 ret;
12592
12593 .L__skip_dec:
12594@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12595 vmovdqu RR4, (6*4*4)(%r11);
12596 vmovdqu RL4, (7*4*4)(%r11);
12597
12598+ pax_force_retaddr
12599 ret;
12600 ENDPROC(cast5_ecb_enc_16way)
12601
12602@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12603 vmovdqu RR4, (6*4*4)(%r11);
12604 vmovdqu RL4, (7*4*4)(%r11);
12605
12606+ pax_force_retaddr
12607 ret;
12608 ENDPROC(cast5_ecb_dec_16way)
12609
12610@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12611
12612 popq %r12;
12613
12614+ pax_force_retaddr
12615 ret;
12616 ENDPROC(cast5_cbc_dec_16way)
12617
12618@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12619
12620 popq %r12;
12621
12622+ pax_force_retaddr
12623 ret;
12624 ENDPROC(cast5_ctr_16way)
12625diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12626index e3531f8..18ded3a 100644
12627--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12628+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12629@@ -24,6 +24,7 @@
12630 */
12631
12632 #include <linux/linkage.h>
12633+#include <asm/alternative-asm.h>
12634 #include "glue_helper-asm-avx.S"
12635
12636 .file "cast6-avx-x86_64-asm_64.S"
12637@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12638 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12639 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12640
12641+ pax_force_retaddr 0, 1
12642 ret;
12643 ENDPROC(__cast6_enc_blk8)
12644
12645@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12646 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12647 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12648
12649+ pax_force_retaddr 0, 1
12650 ret;
12651 ENDPROC(__cast6_dec_blk8)
12652
12653@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12654
12655 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12656
12657+ pax_force_retaddr
12658 ret;
12659 ENDPROC(cast6_ecb_enc_8way)
12660
12661@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12662
12663 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12664
12665+ pax_force_retaddr
12666 ret;
12667 ENDPROC(cast6_ecb_dec_8way)
12668
12669@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12670
12671 popq %r12;
12672
12673+ pax_force_retaddr
12674 ret;
12675 ENDPROC(cast6_cbc_dec_8way)
12676
12677@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12678
12679 popq %r12;
12680
12681+ pax_force_retaddr
12682 ret;
12683 ENDPROC(cast6_ctr_8way)
12684
12685@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12686 /* dst <= regs xor IVs(in dst) */
12687 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12688
12689+ pax_force_retaddr
12690 ret;
12691 ENDPROC(cast6_xts_enc_8way)
12692
12693@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12694 /* dst <= regs xor IVs(in dst) */
12695 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12696
12697+ pax_force_retaddr
12698 ret;
12699 ENDPROC(cast6_xts_dec_8way)
12700diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12701index dbc4339..3d868c5 100644
12702--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12703+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12704@@ -45,6 +45,7 @@
12705
12706 #include <asm/inst.h>
12707 #include <linux/linkage.h>
12708+#include <asm/alternative-asm.h>
12709
12710 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12711
12712@@ -312,6 +313,7 @@ do_return:
12713 popq %rsi
12714 popq %rdi
12715 popq %rbx
12716+ pax_force_retaddr 0, 1
12717 ret
12718
12719 ################################################################
12720diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12721index 586f41a..d02851e 100644
12722--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12723+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12724@@ -18,6 +18,7 @@
12725
12726 #include <linux/linkage.h>
12727 #include <asm/inst.h>
12728+#include <asm/alternative-asm.h>
12729
12730 .data
12731
12732@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12733 psrlq $1, T2
12734 pxor T2, T1
12735 pxor T1, DATA
12736+ pax_force_retaddr
12737 ret
12738 ENDPROC(__clmul_gf128mul_ble)
12739
12740@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12741 call __clmul_gf128mul_ble
12742 PSHUFB_XMM BSWAP DATA
12743 movups DATA, (%rdi)
12744+ pax_force_retaddr
12745 ret
12746 ENDPROC(clmul_ghash_mul)
12747
12748@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12749 PSHUFB_XMM BSWAP DATA
12750 movups DATA, (%rdi)
12751 .Lupdate_just_ret:
12752+ pax_force_retaddr
12753 ret
12754 ENDPROC(clmul_ghash_update)
12755
12756@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12757 pand .Lpoly, %xmm1
12758 pxor %xmm1, %xmm0
12759 movups %xmm0, (%rdi)
12760+ pax_force_retaddr
12761 ret
12762 ENDPROC(clmul_ghash_setkey)
12763diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12764index 9279e0b..9270820 100644
12765--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12766+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12767@@ -1,4 +1,5 @@
12768 #include <linux/linkage.h>
12769+#include <asm/alternative-asm.h>
12770
12771 # enter salsa20_encrypt_bytes
12772 ENTRY(salsa20_encrypt_bytes)
12773@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12774 add %r11,%rsp
12775 mov %rdi,%rax
12776 mov %rsi,%rdx
12777+ pax_force_retaddr 0, 1
12778 ret
12779 # bytesatleast65:
12780 ._bytesatleast65:
12781@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12782 add %r11,%rsp
12783 mov %rdi,%rax
12784 mov %rsi,%rdx
12785+ pax_force_retaddr
12786 ret
12787 ENDPROC(salsa20_keysetup)
12788
12789@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12790 add %r11,%rsp
12791 mov %rdi,%rax
12792 mov %rsi,%rdx
12793+ pax_force_retaddr
12794 ret
12795 ENDPROC(salsa20_ivsetup)
12796diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12797index 2f202f4..d9164d6 100644
12798--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12799+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12800@@ -24,6 +24,7 @@
12801 */
12802
12803 #include <linux/linkage.h>
12804+#include <asm/alternative-asm.h>
12805 #include "glue_helper-asm-avx.S"
12806
12807 .file "serpent-avx-x86_64-asm_64.S"
12808@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12809 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12810 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12811
12812+ pax_force_retaddr
12813 ret;
12814 ENDPROC(__serpent_enc_blk8_avx)
12815
12816@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12817 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12818 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12819
12820+ pax_force_retaddr
12821 ret;
12822 ENDPROC(__serpent_dec_blk8_avx)
12823
12824@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12825
12826 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12827
12828+ pax_force_retaddr
12829 ret;
12830 ENDPROC(serpent_ecb_enc_8way_avx)
12831
12832@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12833
12834 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12835
12836+ pax_force_retaddr
12837 ret;
12838 ENDPROC(serpent_ecb_dec_8way_avx)
12839
12840@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12841
12842 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12843
12844+ pax_force_retaddr
12845 ret;
12846 ENDPROC(serpent_cbc_dec_8way_avx)
12847
12848@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12849
12850 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12851
12852+ pax_force_retaddr
12853 ret;
12854 ENDPROC(serpent_ctr_8way_avx)
12855
12856@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12857 /* dst <= regs xor IVs(in dst) */
12858 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12859
12860+ pax_force_retaddr
12861 ret;
12862 ENDPROC(serpent_xts_enc_8way_avx)
12863
12864@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12865 /* dst <= regs xor IVs(in dst) */
12866 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12867
12868+ pax_force_retaddr
12869 ret;
12870 ENDPROC(serpent_xts_dec_8way_avx)
12871diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12872index b222085..abd483c 100644
12873--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12874+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12875@@ -15,6 +15,7 @@
12876 */
12877
12878 #include <linux/linkage.h>
12879+#include <asm/alternative-asm.h>
12880 #include "glue_helper-asm-avx2.S"
12881
12882 .file "serpent-avx2-asm_64.S"
12883@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12884 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12885 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12886
12887+ pax_force_retaddr
12888 ret;
12889 ENDPROC(__serpent_enc_blk16)
12890
12891@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12892 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12893 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12894
12895+ pax_force_retaddr
12896 ret;
12897 ENDPROC(__serpent_dec_blk16)
12898
12899@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12900
12901 vzeroupper;
12902
12903+ pax_force_retaddr
12904 ret;
12905 ENDPROC(serpent_ecb_enc_16way)
12906
12907@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12908
12909 vzeroupper;
12910
12911+ pax_force_retaddr
12912 ret;
12913 ENDPROC(serpent_ecb_dec_16way)
12914
12915@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12916
12917 vzeroupper;
12918
12919+ pax_force_retaddr
12920 ret;
12921 ENDPROC(serpent_cbc_dec_16way)
12922
12923@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12924
12925 vzeroupper;
12926
12927+ pax_force_retaddr
12928 ret;
12929 ENDPROC(serpent_ctr_16way)
12930
12931@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12932
12933 vzeroupper;
12934
12935+ pax_force_retaddr
12936 ret;
12937 ENDPROC(serpent_xts_enc_16way)
12938
12939@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12940
12941 vzeroupper;
12942
12943+ pax_force_retaddr
12944 ret;
12945 ENDPROC(serpent_xts_dec_16way)
12946diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12947index acc066c..1559cc4 100644
12948--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12949+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12950@@ -25,6 +25,7 @@
12951 */
12952
12953 #include <linux/linkage.h>
12954+#include <asm/alternative-asm.h>
12955
12956 .file "serpent-sse2-x86_64-asm_64.S"
12957 .text
12958@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12959 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12960 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12961
12962+ pax_force_retaddr
12963 ret;
12964
12965 .L__enc_xor8:
12966 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12967 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12968
12969+ pax_force_retaddr
12970 ret;
12971 ENDPROC(__serpent_enc_blk_8way)
12972
12973@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12974 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12975 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12976
12977+ pax_force_retaddr
12978 ret;
12979 ENDPROC(serpent_dec_blk_8way)
12980diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12981index a410950..3356d42 100644
12982--- a/arch/x86/crypto/sha1_ssse3_asm.S
12983+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12984@@ -29,6 +29,7 @@
12985 */
12986
12987 #include <linux/linkage.h>
12988+#include <asm/alternative-asm.h>
12989
12990 #define CTX %rdi // arg1
12991 #define BUF %rsi // arg2
12992@@ -104,6 +105,7 @@
12993 pop %r12
12994 pop %rbp
12995 pop %rbx
12996+ pax_force_retaddr 0, 1
12997 ret
12998
12999 ENDPROC(\name)
13000diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13001index 642f156..4ab07b9 100644
13002--- a/arch/x86/crypto/sha256-avx-asm.S
13003+++ b/arch/x86/crypto/sha256-avx-asm.S
13004@@ -49,6 +49,7 @@
13005
13006 #ifdef CONFIG_AS_AVX
13007 #include <linux/linkage.h>
13008+#include <asm/alternative-asm.h>
13009
13010 ## assume buffers not aligned
13011 #define VMOVDQ vmovdqu
13012@@ -460,6 +461,7 @@ done_hash:
13013 popq %r13
13014 popq %rbp
13015 popq %rbx
13016+ pax_force_retaddr 0, 1
13017 ret
13018 ENDPROC(sha256_transform_avx)
13019
13020diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13021index 9e86944..2e7f95a 100644
13022--- a/arch/x86/crypto/sha256-avx2-asm.S
13023+++ b/arch/x86/crypto/sha256-avx2-asm.S
13024@@ -50,6 +50,7 @@
13025
13026 #ifdef CONFIG_AS_AVX2
13027 #include <linux/linkage.h>
13028+#include <asm/alternative-asm.h>
13029
13030 ## assume buffers not aligned
13031 #define VMOVDQ vmovdqu
13032@@ -720,6 +721,7 @@ done_hash:
13033 popq %r12
13034 popq %rbp
13035 popq %rbx
13036+ pax_force_retaddr 0, 1
13037 ret
13038 ENDPROC(sha256_transform_rorx)
13039
13040diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13041index f833b74..c36ed14 100644
13042--- a/arch/x86/crypto/sha256-ssse3-asm.S
13043+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13044@@ -47,6 +47,7 @@
13045 ########################################################################
13046
13047 #include <linux/linkage.h>
13048+#include <asm/alternative-asm.h>
13049
13050 ## assume buffers not aligned
13051 #define MOVDQ movdqu
13052@@ -471,6 +472,7 @@ done_hash:
13053 popq %rbp
13054 popq %rbx
13055
13056+ pax_force_retaddr 0, 1
13057 ret
13058 ENDPROC(sha256_transform_ssse3)
13059
13060diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13061index 974dde9..4533d34 100644
13062--- a/arch/x86/crypto/sha512-avx-asm.S
13063+++ b/arch/x86/crypto/sha512-avx-asm.S
13064@@ -49,6 +49,7 @@
13065
13066 #ifdef CONFIG_AS_AVX
13067 #include <linux/linkage.h>
13068+#include <asm/alternative-asm.h>
13069
13070 .text
13071
13072@@ -364,6 +365,7 @@ updateblock:
13073 mov frame_RSPSAVE(%rsp), %rsp
13074
13075 nowork:
13076+ pax_force_retaddr 0, 1
13077 ret
13078 ENDPROC(sha512_transform_avx)
13079
13080diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13081index 568b961..061ef1d 100644
13082--- a/arch/x86/crypto/sha512-avx2-asm.S
13083+++ b/arch/x86/crypto/sha512-avx2-asm.S
13084@@ -51,6 +51,7 @@
13085
13086 #ifdef CONFIG_AS_AVX2
13087 #include <linux/linkage.h>
13088+#include <asm/alternative-asm.h>
13089
13090 .text
13091
13092@@ -678,6 +679,7 @@ done_hash:
13093
13094 # Restore Stack Pointer
13095 mov frame_RSPSAVE(%rsp), %rsp
13096+ pax_force_retaddr 0, 1
13097 ret
13098 ENDPROC(sha512_transform_rorx)
13099
13100diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13101index fb56855..e23914f 100644
13102--- a/arch/x86/crypto/sha512-ssse3-asm.S
13103+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13104@@ -48,6 +48,7 @@
13105 ########################################################################
13106
13107 #include <linux/linkage.h>
13108+#include <asm/alternative-asm.h>
13109
13110 .text
13111
13112@@ -363,6 +364,7 @@ updateblock:
13113 mov frame_RSPSAVE(%rsp), %rsp
13114
13115 nowork:
13116+ pax_force_retaddr 0, 1
13117 ret
13118 ENDPROC(sha512_transform_ssse3)
13119
13120diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13121index 0505813..63b1d00 100644
13122--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13123+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13124@@ -24,6 +24,7 @@
13125 */
13126
13127 #include <linux/linkage.h>
13128+#include <asm/alternative-asm.h>
13129 #include "glue_helper-asm-avx.S"
13130
13131 .file "twofish-avx-x86_64-asm_64.S"
13132@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13133 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13134 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13135
13136+ pax_force_retaddr 0, 1
13137 ret;
13138 ENDPROC(__twofish_enc_blk8)
13139
13140@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13141 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13142 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13143
13144+ pax_force_retaddr 0, 1
13145 ret;
13146 ENDPROC(__twofish_dec_blk8)
13147
13148@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13149
13150 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13151
13152+ pax_force_retaddr 0, 1
13153 ret;
13154 ENDPROC(twofish_ecb_enc_8way)
13155
13156@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13157
13158 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13159
13160+ pax_force_retaddr 0, 1
13161 ret;
13162 ENDPROC(twofish_ecb_dec_8way)
13163
13164@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13165
13166 popq %r12;
13167
13168+ pax_force_retaddr 0, 1
13169 ret;
13170 ENDPROC(twofish_cbc_dec_8way)
13171
13172@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13173
13174 popq %r12;
13175
13176+ pax_force_retaddr 0, 1
13177 ret;
13178 ENDPROC(twofish_ctr_8way)
13179
13180@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13181 /* dst <= regs xor IVs(in dst) */
13182 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13183
13184+ pax_force_retaddr 0, 1
13185 ret;
13186 ENDPROC(twofish_xts_enc_8way)
13187
13188@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13189 /* dst <= regs xor IVs(in dst) */
13190 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13191
13192+ pax_force_retaddr 0, 1
13193 ret;
13194 ENDPROC(twofish_xts_dec_8way)
13195diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13196index 1c3b7ce..b365c5e 100644
13197--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13198+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13199@@ -21,6 +21,7 @@
13200 */
13201
13202 #include <linux/linkage.h>
13203+#include <asm/alternative-asm.h>
13204
13205 .file "twofish-x86_64-asm-3way.S"
13206 .text
13207@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13208 popq %r13;
13209 popq %r14;
13210 popq %r15;
13211+ pax_force_retaddr 0, 1
13212 ret;
13213
13214 .L__enc_xor3:
13215@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13216 popq %r13;
13217 popq %r14;
13218 popq %r15;
13219+ pax_force_retaddr 0, 1
13220 ret;
13221 ENDPROC(__twofish_enc_blk_3way)
13222
13223@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13224 popq %r13;
13225 popq %r14;
13226 popq %r15;
13227+ pax_force_retaddr 0, 1
13228 ret;
13229 ENDPROC(twofish_dec_blk_3way)
13230diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13231index a039d21..29e7615 100644
13232--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13233+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13234@@ -22,6 +22,7 @@
13235
13236 #include <linux/linkage.h>
13237 #include <asm/asm-offsets.h>
13238+#include <asm/alternative-asm.h>
13239
13240 #define a_offset 0
13241 #define b_offset 4
13242@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13243
13244 popq R1
13245 movq $1,%rax
13246+ pax_force_retaddr 0, 1
13247 ret
13248 ENDPROC(twofish_enc_blk)
13249
13250@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13251
13252 popq R1
13253 movq $1,%rax
13254+ pax_force_retaddr 0, 1
13255 ret
13256 ENDPROC(twofish_dec_blk)
13257diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13258index bae3aba..c1788c1 100644
13259--- a/arch/x86/ia32/ia32_aout.c
13260+++ b/arch/x86/ia32/ia32_aout.c
13261@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13262 unsigned long dump_start, dump_size;
13263 struct user32 dump;
13264
13265+ memset(&dump, 0, sizeof(dump));
13266+
13267 fs = get_fs();
13268 set_fs(KERNEL_DS);
13269 has_dumped = 1;
13270diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13271index 665a730..8e7a67a 100644
13272--- a/arch/x86/ia32/ia32_signal.c
13273+++ b/arch/x86/ia32/ia32_signal.c
13274@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13275 sp -= frame_size;
13276 /* Align the stack pointer according to the i386 ABI,
13277 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13278- sp = ((sp + 4) & -16ul) - 4;
13279+ sp = ((sp - 12) & -16ul) - 4;
13280 return (void __user *) sp;
13281 }
13282
13283@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13284 * These are actually not used anymore, but left because some
13285 * gdb versions depend on them as a marker.
13286 */
13287- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13288+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13289 } put_user_catch(err);
13290
13291 if (err)
13292@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13293 0xb8,
13294 __NR_ia32_rt_sigreturn,
13295 0x80cd,
13296- 0,
13297+ 0
13298 };
13299
13300 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13301@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13302
13303 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13304 restorer = ksig->ka.sa.sa_restorer;
13305+ else if (current->mm->context.vdso)
13306+ /* Return stub is in 32bit vsyscall page */
13307+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13308 else
13309- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13310- rt_sigreturn);
13311+ restorer = &frame->retcode;
13312 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13313
13314 /*
13315 * Not actually used anymore, but left because some gdb
13316 * versions need it.
13317 */
13318- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13319+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13320 } put_user_catch(err);
13321
13322 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13323diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13324index 474dc1b..9297c58 100644
13325--- a/arch/x86/ia32/ia32entry.S
13326+++ b/arch/x86/ia32/ia32entry.S
13327@@ -15,8 +15,10 @@
13328 #include <asm/irqflags.h>
13329 #include <asm/asm.h>
13330 #include <asm/smap.h>
13331+#include <asm/pgtable.h>
13332 #include <linux/linkage.h>
13333 #include <linux/err.h>
13334+#include <asm/alternative-asm.h>
13335
13336 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13337 #include <linux/elf-em.h>
13338@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13339 ENDPROC(native_irq_enable_sysexit)
13340 #endif
13341
13342+ .macro pax_enter_kernel_user
13343+ pax_set_fptr_mask
13344+#ifdef CONFIG_PAX_MEMORY_UDEREF
13345+ call pax_enter_kernel_user
13346+#endif
13347+ .endm
13348+
13349+ .macro pax_exit_kernel_user
13350+#ifdef CONFIG_PAX_MEMORY_UDEREF
13351+ call pax_exit_kernel_user
13352+#endif
13353+#ifdef CONFIG_PAX_RANDKSTACK
13354+ pushq %rax
13355+ pushq %r11
13356+ call pax_randomize_kstack
13357+ popq %r11
13358+ popq %rax
13359+#endif
13360+ .endm
13361+
13362+ .macro pax_erase_kstack
13363+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13364+ call pax_erase_kstack
13365+#endif
13366+ .endm
13367+
13368 /*
13369 * 32bit SYSENTER instruction entry.
13370 *
13371@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13372 CFI_REGISTER rsp,rbp
13373 SWAPGS_UNSAFE_STACK
13374 movq PER_CPU_VAR(kernel_stack), %rsp
13375- addq $(KERNEL_STACK_OFFSET),%rsp
13376- /*
13377- * No need to follow this irqs on/off section: the syscall
13378- * disabled irqs, here we enable it straight after entry:
13379- */
13380- ENABLE_INTERRUPTS(CLBR_NONE)
13381 movl %ebp,%ebp /* zero extension */
13382 pushq_cfi $__USER32_DS
13383 /*CFI_REL_OFFSET ss,0*/
13384@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13385 CFI_REL_OFFSET rsp,0
13386 pushfq_cfi
13387 /*CFI_REL_OFFSET rflags,0*/
13388- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13389- CFI_REGISTER rip,r10
13390+ orl $X86_EFLAGS_IF,(%rsp)
13391+ GET_THREAD_INFO(%r11)
13392+ movl TI_sysenter_return(%r11), %r11d
13393+ CFI_REGISTER rip,r11
13394 pushq_cfi $__USER32_CS
13395 /*CFI_REL_OFFSET cs,0*/
13396 movl %eax, %eax
13397- pushq_cfi %r10
13398+ pushq_cfi %r11
13399 CFI_REL_OFFSET rip,0
13400 pushq_cfi %rax
13401 cld
13402 SAVE_ARGS 0,1,0
13403+ pax_enter_kernel_user
13404+
13405+#ifdef CONFIG_PAX_RANDKSTACK
13406+ pax_erase_kstack
13407+#endif
13408+
13409+ /*
13410+ * No need to follow this irqs on/off section: the syscall
13411+ * disabled irqs, here we enable it straight after entry:
13412+ */
13413+ ENABLE_INTERRUPTS(CLBR_NONE)
13414 /* no need to do an access_ok check here because rbp has been
13415 32bit zero extended */
13416+
13417+#ifdef CONFIG_PAX_MEMORY_UDEREF
13418+ addq pax_user_shadow_base,%rbp
13419+ ASM_PAX_OPEN_USERLAND
13420+#endif
13421+
13422 ASM_STAC
13423 1: movl (%rbp),%ebp
13424 _ASM_EXTABLE(1b,ia32_badarg)
13425 ASM_CLAC
13426- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13427- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13428+
13429+#ifdef CONFIG_PAX_MEMORY_UDEREF
13430+ ASM_PAX_CLOSE_USERLAND
13431+#endif
13432+
13433+ GET_THREAD_INFO(%r11)
13434+ orl $TS_COMPAT,TI_status(%r11)
13435+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13436 CFI_REMEMBER_STATE
13437 jnz sysenter_tracesys
13438 cmpq $(IA32_NR_syscalls-1),%rax
13439@@ -162,12 +209,15 @@ sysenter_do_call:
13440 sysenter_dispatch:
13441 call *ia32_sys_call_table(,%rax,8)
13442 movq %rax,RAX-ARGOFFSET(%rsp)
13443+ GET_THREAD_INFO(%r11)
13444 DISABLE_INTERRUPTS(CLBR_NONE)
13445 TRACE_IRQS_OFF
13446- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13447+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13448 jnz sysexit_audit
13449 sysexit_from_sys_call:
13450- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13451+ pax_exit_kernel_user
13452+ pax_erase_kstack
13453+ andl $~TS_COMPAT,TI_status(%r11)
13454 /* clear IF, that popfq doesn't enable interrupts early */
13455 andl $~0x200,EFLAGS-R11(%rsp)
13456 movl RIP-R11(%rsp),%edx /* User %eip */
13457@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13458 movl %eax,%esi /* 2nd arg: syscall number */
13459 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13460 call __audit_syscall_entry
13461+
13462+ pax_erase_kstack
13463+
13464 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13465 cmpq $(IA32_NR_syscalls-1),%rax
13466 ja ia32_badsys
13467@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13468 .endm
13469
13470 .macro auditsys_exit exit
13471- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13472+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13473 jnz ia32_ret_from_sys_call
13474 TRACE_IRQS_ON
13475 ENABLE_INTERRUPTS(CLBR_NONE)
13476@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13477 1: setbe %al /* 1 if error, 0 if not */
13478 movzbl %al,%edi /* zero-extend that into %edi */
13479 call __audit_syscall_exit
13480+ GET_THREAD_INFO(%r11)
13481 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13482 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13483 DISABLE_INTERRUPTS(CLBR_NONE)
13484 TRACE_IRQS_OFF
13485- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13486+ testl %edi,TI_flags(%r11)
13487 jz \exit
13488 CLEAR_RREGS -ARGOFFSET
13489 jmp int_with_check
13490@@ -237,7 +291,7 @@ sysexit_audit:
13491
13492 sysenter_tracesys:
13493 #ifdef CONFIG_AUDITSYSCALL
13494- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13495+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13496 jz sysenter_auditsys
13497 #endif
13498 SAVE_REST
13499@@ -249,6 +303,9 @@ sysenter_tracesys:
13500 RESTORE_REST
13501 cmpq $(IA32_NR_syscalls-1),%rax
13502 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13503+
13504+ pax_erase_kstack
13505+
13506 jmp sysenter_do_call
13507 CFI_ENDPROC
13508 ENDPROC(ia32_sysenter_target)
13509@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13510 ENTRY(ia32_cstar_target)
13511 CFI_STARTPROC32 simple
13512 CFI_SIGNAL_FRAME
13513- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13514+ CFI_DEF_CFA rsp,0
13515 CFI_REGISTER rip,rcx
13516 /*CFI_REGISTER rflags,r11*/
13517 SWAPGS_UNSAFE_STACK
13518 movl %esp,%r8d
13519 CFI_REGISTER rsp,r8
13520 movq PER_CPU_VAR(kernel_stack),%rsp
13521+ SAVE_ARGS 8*6,0,0
13522+ pax_enter_kernel_user
13523+
13524+#ifdef CONFIG_PAX_RANDKSTACK
13525+ pax_erase_kstack
13526+#endif
13527+
13528 /*
13529 * No need to follow this irqs on/off section: the syscall
13530 * disabled irqs and here we enable it straight after entry:
13531 */
13532 ENABLE_INTERRUPTS(CLBR_NONE)
13533- SAVE_ARGS 8,0,0
13534 movl %eax,%eax /* zero extension */
13535 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13536 movq %rcx,RIP-ARGOFFSET(%rsp)
13537@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13538 /* no need to do an access_ok check here because r8 has been
13539 32bit zero extended */
13540 /* hardware stack frame is complete now */
13541+
13542+#ifdef CONFIG_PAX_MEMORY_UDEREF
13543+ ASM_PAX_OPEN_USERLAND
13544+ movq pax_user_shadow_base,%r8
13545+ addq RSP-ARGOFFSET(%rsp),%r8
13546+#endif
13547+
13548 ASM_STAC
13549 1: movl (%r8),%r9d
13550 _ASM_EXTABLE(1b,ia32_badarg)
13551 ASM_CLAC
13552- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13553- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13554+
13555+#ifdef CONFIG_PAX_MEMORY_UDEREF
13556+ ASM_PAX_CLOSE_USERLAND
13557+#endif
13558+
13559+ GET_THREAD_INFO(%r11)
13560+ orl $TS_COMPAT,TI_status(%r11)
13561+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13562 CFI_REMEMBER_STATE
13563 jnz cstar_tracesys
13564 cmpq $IA32_NR_syscalls-1,%rax
13565@@ -319,12 +395,15 @@ cstar_do_call:
13566 cstar_dispatch:
13567 call *ia32_sys_call_table(,%rax,8)
13568 movq %rax,RAX-ARGOFFSET(%rsp)
13569+ GET_THREAD_INFO(%r11)
13570 DISABLE_INTERRUPTS(CLBR_NONE)
13571 TRACE_IRQS_OFF
13572- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13573+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13574 jnz sysretl_audit
13575 sysretl_from_sys_call:
13576- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13577+ pax_exit_kernel_user
13578+ pax_erase_kstack
13579+ andl $~TS_COMPAT,TI_status(%r11)
13580 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13581 movl RIP-ARGOFFSET(%rsp),%ecx
13582 CFI_REGISTER rip,rcx
13583@@ -352,7 +431,7 @@ sysretl_audit:
13584
13585 cstar_tracesys:
13586 #ifdef CONFIG_AUDITSYSCALL
13587- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13588+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13589 jz cstar_auditsys
13590 #endif
13591 xchgl %r9d,%ebp
13592@@ -366,11 +445,19 @@ cstar_tracesys:
13593 xchgl %ebp,%r9d
13594 cmpq $(IA32_NR_syscalls-1),%rax
13595 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13596+
13597+ pax_erase_kstack
13598+
13599 jmp cstar_do_call
13600 END(ia32_cstar_target)
13601
13602 ia32_badarg:
13603 ASM_CLAC
13604+
13605+#ifdef CONFIG_PAX_MEMORY_UDEREF
13606+ ASM_PAX_CLOSE_USERLAND
13607+#endif
13608+
13609 movq $-EFAULT,%rax
13610 jmp ia32_sysret
13611 CFI_ENDPROC
13612@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13613 CFI_REL_OFFSET rip,RIP-RIP
13614 PARAVIRT_ADJUST_EXCEPTION_FRAME
13615 SWAPGS
13616- /*
13617- * No need to follow this irqs on/off section: the syscall
13618- * disabled irqs and here we enable it straight after entry:
13619- */
13620- ENABLE_INTERRUPTS(CLBR_NONE)
13621 movl %eax,%eax
13622 pushq_cfi %rax
13623 cld
13624 /* note the registers are not zero extended to the sf.
13625 this could be a problem. */
13626 SAVE_ARGS 0,1,0
13627- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13628- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13629+ pax_enter_kernel_user
13630+
13631+#ifdef CONFIG_PAX_RANDKSTACK
13632+ pax_erase_kstack
13633+#endif
13634+
13635+ /*
13636+ * No need to follow this irqs on/off section: the syscall
13637+ * disabled irqs and here we enable it straight after entry:
13638+ */
13639+ ENABLE_INTERRUPTS(CLBR_NONE)
13640+ GET_THREAD_INFO(%r11)
13641+ orl $TS_COMPAT,TI_status(%r11)
13642+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13643 jnz ia32_tracesys
13644 cmpq $(IA32_NR_syscalls-1),%rax
13645 ja ia32_badsys
13646@@ -442,6 +536,9 @@ ia32_tracesys:
13647 RESTORE_REST
13648 cmpq $(IA32_NR_syscalls-1),%rax
13649 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13650+
13651+ pax_erase_kstack
13652+
13653 jmp ia32_do_call
13654 END(ia32_syscall)
13655
13656diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13657index 8e0ceec..af13504 100644
13658--- a/arch/x86/ia32/sys_ia32.c
13659+++ b/arch/x86/ia32/sys_ia32.c
13660@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13661 */
13662 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13663 {
13664- typeof(ubuf->st_uid) uid = 0;
13665- typeof(ubuf->st_gid) gid = 0;
13666+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13667+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13668 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13669 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13670 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13671diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13672index 372231c..a5aa1a1 100644
13673--- a/arch/x86/include/asm/alternative-asm.h
13674+++ b/arch/x86/include/asm/alternative-asm.h
13675@@ -18,6 +18,45 @@
13676 .endm
13677 #endif
13678
13679+#ifdef KERNEXEC_PLUGIN
13680+ .macro pax_force_retaddr_bts rip=0
13681+ btsq $63,\rip(%rsp)
13682+ .endm
13683+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13684+ .macro pax_force_retaddr rip=0, reload=0
13685+ btsq $63,\rip(%rsp)
13686+ .endm
13687+ .macro pax_force_fptr ptr
13688+ btsq $63,\ptr
13689+ .endm
13690+ .macro pax_set_fptr_mask
13691+ .endm
13692+#endif
13693+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13694+ .macro pax_force_retaddr rip=0, reload=0
13695+ .if \reload
13696+ pax_set_fptr_mask
13697+ .endif
13698+ orq %r10,\rip(%rsp)
13699+ .endm
13700+ .macro pax_force_fptr ptr
13701+ orq %r10,\ptr
13702+ .endm
13703+ .macro pax_set_fptr_mask
13704+ movabs $0x8000000000000000,%r10
13705+ .endm
13706+#endif
13707+#else
13708+ .macro pax_force_retaddr rip=0, reload=0
13709+ .endm
13710+ .macro pax_force_fptr ptr
13711+ .endm
13712+ .macro pax_force_retaddr_bts rip=0
13713+ .endm
13714+ .macro pax_set_fptr_mask
13715+ .endm
13716+#endif
13717+
13718 .macro altinstruction_entry orig alt feature orig_len alt_len
13719 .long \orig - .
13720 .long \alt - .
13721diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13722index 58ed6d9..f1cbe58 100644
13723--- a/arch/x86/include/asm/alternative.h
13724+++ b/arch/x86/include/asm/alternative.h
13725@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13726 ".pushsection .discard,\"aw\",@progbits\n" \
13727 DISCARD_ENTRY(1) \
13728 ".popsection\n" \
13729- ".pushsection .altinstr_replacement, \"ax\"\n" \
13730+ ".pushsection .altinstr_replacement, \"a\"\n" \
13731 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13732 ".popsection"
13733
13734@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13735 DISCARD_ENTRY(1) \
13736 DISCARD_ENTRY(2) \
13737 ".popsection\n" \
13738- ".pushsection .altinstr_replacement, \"ax\"\n" \
13739+ ".pushsection .altinstr_replacement, \"a\"\n" \
13740 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13741 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13742 ".popsection"
13743diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13744index f8119b5..7209d5b 100644
13745--- a/arch/x86/include/asm/apic.h
13746+++ b/arch/x86/include/asm/apic.h
13747@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13748
13749 #ifdef CONFIG_X86_LOCAL_APIC
13750
13751-extern unsigned int apic_verbosity;
13752+extern int apic_verbosity;
13753 extern int local_apic_timer_c2_ok;
13754
13755 extern int disable_apic;
13756diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13757index 20370c6..a2eb9b0 100644
13758--- a/arch/x86/include/asm/apm.h
13759+++ b/arch/x86/include/asm/apm.h
13760@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13761 __asm__ __volatile__(APM_DO_ZERO_SEGS
13762 "pushl %%edi\n\t"
13763 "pushl %%ebp\n\t"
13764- "lcall *%%cs:apm_bios_entry\n\t"
13765+ "lcall *%%ss:apm_bios_entry\n\t"
13766 "setc %%al\n\t"
13767 "popl %%ebp\n\t"
13768 "popl %%edi\n\t"
13769@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13770 __asm__ __volatile__(APM_DO_ZERO_SEGS
13771 "pushl %%edi\n\t"
13772 "pushl %%ebp\n\t"
13773- "lcall *%%cs:apm_bios_entry\n\t"
13774+ "lcall *%%ss:apm_bios_entry\n\t"
13775 "setc %%bl\n\t"
13776 "popl %%ebp\n\t"
13777 "popl %%edi\n\t"
13778diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13779index 722aa3b..3a0bb27 100644
13780--- a/arch/x86/include/asm/atomic.h
13781+++ b/arch/x86/include/asm/atomic.h
13782@@ -22,7 +22,18 @@
13783 */
13784 static inline int atomic_read(const atomic_t *v)
13785 {
13786- return (*(volatile int *)&(v)->counter);
13787+ return (*(volatile const int *)&(v)->counter);
13788+}
13789+
13790+/**
13791+ * atomic_read_unchecked - read atomic variable
13792+ * @v: pointer of type atomic_unchecked_t
13793+ *
13794+ * Atomically reads the value of @v.
13795+ */
13796+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13797+{
13798+ return (*(volatile const int *)&(v)->counter);
13799 }
13800
13801 /**
13802@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13803 }
13804
13805 /**
13806+ * atomic_set_unchecked - set atomic variable
13807+ * @v: pointer of type atomic_unchecked_t
13808+ * @i: required value
13809+ *
13810+ * Atomically sets the value of @v to @i.
13811+ */
13812+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13813+{
13814+ v->counter = i;
13815+}
13816+
13817+/**
13818 * atomic_add - add integer to atomic variable
13819 * @i: integer value to add
13820 * @v: pointer of type atomic_t
13821@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13822 */
13823 static inline void atomic_add(int i, atomic_t *v)
13824 {
13825- asm volatile(LOCK_PREFIX "addl %1,%0"
13826+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13827+
13828+#ifdef CONFIG_PAX_REFCOUNT
13829+ "jno 0f\n"
13830+ LOCK_PREFIX "subl %1,%0\n"
13831+ "int $4\n0:\n"
13832+ _ASM_EXTABLE(0b, 0b)
13833+#endif
13834+
13835+ : "+m" (v->counter)
13836+ : "ir" (i));
13837+}
13838+
13839+/**
13840+ * atomic_add_unchecked - add integer to atomic variable
13841+ * @i: integer value to add
13842+ * @v: pointer of type atomic_unchecked_t
13843+ *
13844+ * Atomically adds @i to @v.
13845+ */
13846+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13847+{
13848+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13849 : "+m" (v->counter)
13850 : "ir" (i));
13851 }
13852@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13853 */
13854 static inline void atomic_sub(int i, atomic_t *v)
13855 {
13856- asm volatile(LOCK_PREFIX "subl %1,%0"
13857+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13858+
13859+#ifdef CONFIG_PAX_REFCOUNT
13860+ "jno 0f\n"
13861+ LOCK_PREFIX "addl %1,%0\n"
13862+ "int $4\n0:\n"
13863+ _ASM_EXTABLE(0b, 0b)
13864+#endif
13865+
13866+ : "+m" (v->counter)
13867+ : "ir" (i));
13868+}
13869+
13870+/**
13871+ * atomic_sub_unchecked - subtract integer from atomic variable
13872+ * @i: integer value to subtract
13873+ * @v: pointer of type atomic_unchecked_t
13874+ *
13875+ * Atomically subtracts @i from @v.
13876+ */
13877+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13878+{
13879+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13880 : "+m" (v->counter)
13881 : "ir" (i));
13882 }
13883@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13884 {
13885 unsigned char c;
13886
13887- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13888+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13889+
13890+#ifdef CONFIG_PAX_REFCOUNT
13891+ "jno 0f\n"
13892+ LOCK_PREFIX "addl %2,%0\n"
13893+ "int $4\n0:\n"
13894+ _ASM_EXTABLE(0b, 0b)
13895+#endif
13896+
13897+ "sete %1\n"
13898 : "+m" (v->counter), "=qm" (c)
13899 : "ir" (i) : "memory");
13900 return c;
13901@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13902 */
13903 static inline void atomic_inc(atomic_t *v)
13904 {
13905- asm volatile(LOCK_PREFIX "incl %0"
13906+ asm volatile(LOCK_PREFIX "incl %0\n"
13907+
13908+#ifdef CONFIG_PAX_REFCOUNT
13909+ "jno 0f\n"
13910+ LOCK_PREFIX "decl %0\n"
13911+ "int $4\n0:\n"
13912+ _ASM_EXTABLE(0b, 0b)
13913+#endif
13914+
13915+ : "+m" (v->counter));
13916+}
13917+
13918+/**
13919+ * atomic_inc_unchecked - increment atomic variable
13920+ * @v: pointer of type atomic_unchecked_t
13921+ *
13922+ * Atomically increments @v by 1.
13923+ */
13924+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13925+{
13926+ asm volatile(LOCK_PREFIX "incl %0\n"
13927 : "+m" (v->counter));
13928 }
13929
13930@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13931 */
13932 static inline void atomic_dec(atomic_t *v)
13933 {
13934- asm volatile(LOCK_PREFIX "decl %0"
13935+ asm volatile(LOCK_PREFIX "decl %0\n"
13936+
13937+#ifdef CONFIG_PAX_REFCOUNT
13938+ "jno 0f\n"
13939+ LOCK_PREFIX "incl %0\n"
13940+ "int $4\n0:\n"
13941+ _ASM_EXTABLE(0b, 0b)
13942+#endif
13943+
13944+ : "+m" (v->counter));
13945+}
13946+
13947+/**
13948+ * atomic_dec_unchecked - decrement atomic variable
13949+ * @v: pointer of type atomic_unchecked_t
13950+ *
13951+ * Atomically decrements @v by 1.
13952+ */
13953+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13954+{
13955+ asm volatile(LOCK_PREFIX "decl %0\n"
13956 : "+m" (v->counter));
13957 }
13958
13959@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13960 {
13961 unsigned char c;
13962
13963- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13964+ asm volatile(LOCK_PREFIX "decl %0\n"
13965+
13966+#ifdef CONFIG_PAX_REFCOUNT
13967+ "jno 0f\n"
13968+ LOCK_PREFIX "incl %0\n"
13969+ "int $4\n0:\n"
13970+ _ASM_EXTABLE(0b, 0b)
13971+#endif
13972+
13973+ "sete %1\n"
13974 : "+m" (v->counter), "=qm" (c)
13975 : : "memory");
13976 return c != 0;
13977@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13978 {
13979 unsigned char c;
13980
13981- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13982+ asm volatile(LOCK_PREFIX "incl %0\n"
13983+
13984+#ifdef CONFIG_PAX_REFCOUNT
13985+ "jno 0f\n"
13986+ LOCK_PREFIX "decl %0\n"
13987+ "int $4\n0:\n"
13988+ _ASM_EXTABLE(0b, 0b)
13989+#endif
13990+
13991+ "sete %1\n"
13992+ : "+m" (v->counter), "=qm" (c)
13993+ : : "memory");
13994+ return c != 0;
13995+}
13996+
13997+/**
13998+ * atomic_inc_and_test_unchecked - increment and test
13999+ * @v: pointer of type atomic_unchecked_t
14000+ *
14001+ * Atomically increments @v by 1
14002+ * and returns true if the result is zero, or false for all
14003+ * other cases.
14004+ */
14005+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14006+{
14007+ unsigned char c;
14008+
14009+ asm volatile(LOCK_PREFIX "incl %0\n"
14010+ "sete %1\n"
14011 : "+m" (v->counter), "=qm" (c)
14012 : : "memory");
14013 return c != 0;
14014@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14015 {
14016 unsigned char c;
14017
14018- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14019+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14020+
14021+#ifdef CONFIG_PAX_REFCOUNT
14022+ "jno 0f\n"
14023+ LOCK_PREFIX "subl %2,%0\n"
14024+ "int $4\n0:\n"
14025+ _ASM_EXTABLE(0b, 0b)
14026+#endif
14027+
14028+ "sets %1\n"
14029 : "+m" (v->counter), "=qm" (c)
14030 : "ir" (i) : "memory");
14031 return c;
14032@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14033 */
14034 static inline int atomic_add_return(int i, atomic_t *v)
14035 {
14036+ return i + xadd_check_overflow(&v->counter, i);
14037+}
14038+
14039+/**
14040+ * atomic_add_return_unchecked - add integer and return
14041+ * @i: integer value to add
14042+ * @v: pointer of type atomic_unchecked_t
14043+ *
14044+ * Atomically adds @i to @v and returns @i + @v
14045+ */
14046+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14047+{
14048 return i + xadd(&v->counter, i);
14049 }
14050
14051@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14052 }
14053
14054 #define atomic_inc_return(v) (atomic_add_return(1, v))
14055+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14056+{
14057+ return atomic_add_return_unchecked(1, v);
14058+}
14059 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14060
14061 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14062@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14063 return cmpxchg(&v->counter, old, new);
14064 }
14065
14066+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14067+{
14068+ return cmpxchg(&v->counter, old, new);
14069+}
14070+
14071 static inline int atomic_xchg(atomic_t *v, int new)
14072 {
14073 return xchg(&v->counter, new);
14074 }
14075
14076+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14077+{
14078+ return xchg(&v->counter, new);
14079+}
14080+
14081 /**
14082 * __atomic_add_unless - add unless the number is already a given value
14083 * @v: pointer of type atomic_t
14084@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14085 */
14086 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14087 {
14088- int c, old;
14089+ int c, old, new;
14090 c = atomic_read(v);
14091 for (;;) {
14092- if (unlikely(c == (u)))
14093+ if (unlikely(c == u))
14094 break;
14095- old = atomic_cmpxchg((v), c, c + (a));
14096+
14097+ asm volatile("addl %2,%0\n"
14098+
14099+#ifdef CONFIG_PAX_REFCOUNT
14100+ "jno 0f\n"
14101+ "subl %2,%0\n"
14102+ "int $4\n0:\n"
14103+ _ASM_EXTABLE(0b, 0b)
14104+#endif
14105+
14106+ : "=r" (new)
14107+ : "0" (c), "ir" (a));
14108+
14109+ old = atomic_cmpxchg(v, c, new);
14110 if (likely(old == c))
14111 break;
14112 c = old;
14113@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14114 }
14115
14116 /**
14117+ * atomic_inc_not_zero_hint - increment if not null
14118+ * @v: pointer of type atomic_t
14119+ * @hint: probable value of the atomic before the increment
14120+ *
14121+ * This version of atomic_inc_not_zero() gives a hint of probable
14122+ * value of the atomic. This helps processor to not read the memory
14123+ * before doing the atomic read/modify/write cycle, lowering
14124+ * number of bus transactions on some arches.
14125+ *
14126+ * Returns: 0 if increment was not done, 1 otherwise.
14127+ */
14128+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14129+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14130+{
14131+ int val, c = hint, new;
14132+
14133+ /* sanity test, should be removed by compiler if hint is a constant */
14134+ if (!hint)
14135+ return __atomic_add_unless(v, 1, 0);
14136+
14137+ do {
14138+ asm volatile("incl %0\n"
14139+
14140+#ifdef CONFIG_PAX_REFCOUNT
14141+ "jno 0f\n"
14142+ "decl %0\n"
14143+ "int $4\n0:\n"
14144+ _ASM_EXTABLE(0b, 0b)
14145+#endif
14146+
14147+ : "=r" (new)
14148+ : "0" (c));
14149+
14150+ val = atomic_cmpxchg(v, c, new);
14151+ if (val == c)
14152+ return 1;
14153+ c = val;
14154+ } while (c);
14155+
14156+ return 0;
14157+}
14158+
14159+/**
14160 * atomic_inc_short - increment of a short integer
14161 * @v: pointer to type int
14162 *
14163@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14164 #endif
14165
14166 /* These are x86-specific, used by some header files */
14167-#define atomic_clear_mask(mask, addr) \
14168- asm volatile(LOCK_PREFIX "andl %0,%1" \
14169- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14170+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14171+{
14172+ asm volatile(LOCK_PREFIX "andl %1,%0"
14173+ : "+m" (v->counter)
14174+ : "r" (~(mask))
14175+ : "memory");
14176+}
14177
14178-#define atomic_set_mask(mask, addr) \
14179- asm volatile(LOCK_PREFIX "orl %0,%1" \
14180- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14181- : "memory")
14182+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14183+{
14184+ asm volatile(LOCK_PREFIX "andl %1,%0"
14185+ : "+m" (v->counter)
14186+ : "r" (~(mask))
14187+ : "memory");
14188+}
14189+
14190+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14191+{
14192+ asm volatile(LOCK_PREFIX "orl %1,%0"
14193+ : "+m" (v->counter)
14194+ : "r" (mask)
14195+ : "memory");
14196+}
14197+
14198+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14199+{
14200+ asm volatile(LOCK_PREFIX "orl %1,%0"
14201+ : "+m" (v->counter)
14202+ : "r" (mask)
14203+ : "memory");
14204+}
14205
14206 /* Atomic operations are already serializing on x86 */
14207 #define smp_mb__before_atomic_dec() barrier()
14208diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14209index b154de7..aadebd8 100644
14210--- a/arch/x86/include/asm/atomic64_32.h
14211+++ b/arch/x86/include/asm/atomic64_32.h
14212@@ -12,6 +12,14 @@ typedef struct {
14213 u64 __aligned(8) counter;
14214 } atomic64_t;
14215
14216+#ifdef CONFIG_PAX_REFCOUNT
14217+typedef struct {
14218+ u64 __aligned(8) counter;
14219+} atomic64_unchecked_t;
14220+#else
14221+typedef atomic64_t atomic64_unchecked_t;
14222+#endif
14223+
14224 #define ATOMIC64_INIT(val) { (val) }
14225
14226 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14227@@ -37,21 +45,31 @@ typedef struct {
14228 ATOMIC64_DECL_ONE(sym##_386)
14229
14230 ATOMIC64_DECL_ONE(add_386);
14231+ATOMIC64_DECL_ONE(add_unchecked_386);
14232 ATOMIC64_DECL_ONE(sub_386);
14233+ATOMIC64_DECL_ONE(sub_unchecked_386);
14234 ATOMIC64_DECL_ONE(inc_386);
14235+ATOMIC64_DECL_ONE(inc_unchecked_386);
14236 ATOMIC64_DECL_ONE(dec_386);
14237+ATOMIC64_DECL_ONE(dec_unchecked_386);
14238 #endif
14239
14240 #define alternative_atomic64(f, out, in...) \
14241 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14242
14243 ATOMIC64_DECL(read);
14244+ATOMIC64_DECL(read_unchecked);
14245 ATOMIC64_DECL(set);
14246+ATOMIC64_DECL(set_unchecked);
14247 ATOMIC64_DECL(xchg);
14248 ATOMIC64_DECL(add_return);
14249+ATOMIC64_DECL(add_return_unchecked);
14250 ATOMIC64_DECL(sub_return);
14251+ATOMIC64_DECL(sub_return_unchecked);
14252 ATOMIC64_DECL(inc_return);
14253+ATOMIC64_DECL(inc_return_unchecked);
14254 ATOMIC64_DECL(dec_return);
14255+ATOMIC64_DECL(dec_return_unchecked);
14256 ATOMIC64_DECL(dec_if_positive);
14257 ATOMIC64_DECL(inc_not_zero);
14258 ATOMIC64_DECL(add_unless);
14259@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14260 }
14261
14262 /**
14263+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14264+ * @p: pointer to type atomic64_unchecked_t
14265+ * @o: expected value
14266+ * @n: new value
14267+ *
14268+ * Atomically sets @v to @n if it was equal to @o and returns
14269+ * the old value.
14270+ */
14271+
14272+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14273+{
14274+ return cmpxchg64(&v->counter, o, n);
14275+}
14276+
14277+/**
14278 * atomic64_xchg - xchg atomic64 variable
14279 * @v: pointer to type atomic64_t
14280 * @n: value to assign
14281@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14282 }
14283
14284 /**
14285+ * atomic64_set_unchecked - set atomic64 variable
14286+ * @v: pointer to type atomic64_unchecked_t
14287+ * @n: value to assign
14288+ *
14289+ * Atomically sets the value of @v to @n.
14290+ */
14291+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14292+{
14293+ unsigned high = (unsigned)(i >> 32);
14294+ unsigned low = (unsigned)i;
14295+ alternative_atomic64(set, /* no output */,
14296+ "S" (v), "b" (low), "c" (high)
14297+ : "eax", "edx", "memory");
14298+}
14299+
14300+/**
14301 * atomic64_read - read atomic64 variable
14302 * @v: pointer to type atomic64_t
14303 *
14304@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14305 }
14306
14307 /**
14308+ * atomic64_read_unchecked - read atomic64 variable
14309+ * @v: pointer to type atomic64_unchecked_t
14310+ *
14311+ * Atomically reads the value of @v and returns it.
14312+ */
14313+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14314+{
14315+ long long r;
14316+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14317+ return r;
14318+ }
14319+
14320+/**
14321 * atomic64_add_return - add and return
14322 * @i: integer value to add
14323 * @v: pointer to type atomic64_t
14324@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14325 return i;
14326 }
14327
14328+/**
14329+ * atomic64_add_return_unchecked - add and return
14330+ * @i: integer value to add
14331+ * @v: pointer to type atomic64_unchecked_t
14332+ *
14333+ * Atomically adds @i to @v and returns @i + *@v
14334+ */
14335+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14336+{
14337+ alternative_atomic64(add_return_unchecked,
14338+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14339+ ASM_NO_INPUT_CLOBBER("memory"));
14340+ return i;
14341+}
14342+
14343 /*
14344 * Other variants with different arithmetic operators:
14345 */
14346@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14347 return a;
14348 }
14349
14350+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14351+{
14352+ long long a;
14353+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14354+ "S" (v) : "memory", "ecx");
14355+ return a;
14356+}
14357+
14358 static inline long long atomic64_dec_return(atomic64_t *v)
14359 {
14360 long long a;
14361@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14362 }
14363
14364 /**
14365+ * atomic64_add_unchecked - add integer to atomic64 variable
14366+ * @i: integer value to add
14367+ * @v: pointer to type atomic64_unchecked_t
14368+ *
14369+ * Atomically adds @i to @v.
14370+ */
14371+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14372+{
14373+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14374+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14375+ ASM_NO_INPUT_CLOBBER("memory"));
14376+ return i;
14377+}
14378+
14379+/**
14380 * atomic64_sub - subtract the atomic64 variable
14381 * @i: integer value to subtract
14382 * @v: pointer to type atomic64_t
14383diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14384index 0e1cbfc..5623683 100644
14385--- a/arch/x86/include/asm/atomic64_64.h
14386+++ b/arch/x86/include/asm/atomic64_64.h
14387@@ -18,7 +18,19 @@
14388 */
14389 static inline long atomic64_read(const atomic64_t *v)
14390 {
14391- return (*(volatile long *)&(v)->counter);
14392+ return (*(volatile const long *)&(v)->counter);
14393+}
14394+
14395+/**
14396+ * atomic64_read_unchecked - read atomic64 variable
14397+ * @v: pointer of type atomic64_unchecked_t
14398+ *
14399+ * Atomically reads the value of @v.
14400+ * Doesn't imply a read memory barrier.
14401+ */
14402+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14403+{
14404+ return (*(volatile const long *)&(v)->counter);
14405 }
14406
14407 /**
14408@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14409 }
14410
14411 /**
14412+ * atomic64_set_unchecked - set atomic64 variable
14413+ * @v: pointer to type atomic64_unchecked_t
14414+ * @i: required value
14415+ *
14416+ * Atomically sets the value of @v to @i.
14417+ */
14418+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14419+{
14420+ v->counter = i;
14421+}
14422+
14423+/**
14424 * atomic64_add - add integer to atomic64 variable
14425 * @i: integer value to add
14426 * @v: pointer to type atomic64_t
14427@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14428 */
14429 static inline void atomic64_add(long i, atomic64_t *v)
14430 {
14431+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14432+
14433+#ifdef CONFIG_PAX_REFCOUNT
14434+ "jno 0f\n"
14435+ LOCK_PREFIX "subq %1,%0\n"
14436+ "int $4\n0:\n"
14437+ _ASM_EXTABLE(0b, 0b)
14438+#endif
14439+
14440+ : "=m" (v->counter)
14441+ : "er" (i), "m" (v->counter));
14442+}
14443+
14444+/**
14445+ * atomic64_add_unchecked - add integer to atomic64 variable
14446+ * @i: integer value to add
14447+ * @v: pointer to type atomic64_unchecked_t
14448+ *
14449+ * Atomically adds @i to @v.
14450+ */
14451+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14452+{
14453 asm volatile(LOCK_PREFIX "addq %1,%0"
14454 : "=m" (v->counter)
14455 : "er" (i), "m" (v->counter));
14456@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14457 */
14458 static inline void atomic64_sub(long i, atomic64_t *v)
14459 {
14460- asm volatile(LOCK_PREFIX "subq %1,%0"
14461+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14462+
14463+#ifdef CONFIG_PAX_REFCOUNT
14464+ "jno 0f\n"
14465+ LOCK_PREFIX "addq %1,%0\n"
14466+ "int $4\n0:\n"
14467+ _ASM_EXTABLE(0b, 0b)
14468+#endif
14469+
14470+ : "=m" (v->counter)
14471+ : "er" (i), "m" (v->counter));
14472+}
14473+
14474+/**
14475+ * atomic64_sub_unchecked - subtract the atomic64 variable
14476+ * @i: integer value to subtract
14477+ * @v: pointer to type atomic64_unchecked_t
14478+ *
14479+ * Atomically subtracts @i from @v.
14480+ */
14481+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14482+{
14483+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14484 : "=m" (v->counter)
14485 : "er" (i), "m" (v->counter));
14486 }
14487@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14488 {
14489 unsigned char c;
14490
14491- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14492+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14493+
14494+#ifdef CONFIG_PAX_REFCOUNT
14495+ "jno 0f\n"
14496+ LOCK_PREFIX "addq %2,%0\n"
14497+ "int $4\n0:\n"
14498+ _ASM_EXTABLE(0b, 0b)
14499+#endif
14500+
14501+ "sete %1\n"
14502 : "=m" (v->counter), "=qm" (c)
14503 : "er" (i), "m" (v->counter) : "memory");
14504 return c;
14505@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14506 */
14507 static inline void atomic64_inc(atomic64_t *v)
14508 {
14509+ asm volatile(LOCK_PREFIX "incq %0\n"
14510+
14511+#ifdef CONFIG_PAX_REFCOUNT
14512+ "jno 0f\n"
14513+ LOCK_PREFIX "decq %0\n"
14514+ "int $4\n0:\n"
14515+ _ASM_EXTABLE(0b, 0b)
14516+#endif
14517+
14518+ : "=m" (v->counter)
14519+ : "m" (v->counter));
14520+}
14521+
14522+/**
14523+ * atomic64_inc_unchecked - increment atomic64 variable
14524+ * @v: pointer to type atomic64_unchecked_t
14525+ *
14526+ * Atomically increments @v by 1.
14527+ */
14528+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14529+{
14530 asm volatile(LOCK_PREFIX "incq %0"
14531 : "=m" (v->counter)
14532 : "m" (v->counter));
14533@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14534 */
14535 static inline void atomic64_dec(atomic64_t *v)
14536 {
14537- asm volatile(LOCK_PREFIX "decq %0"
14538+ asm volatile(LOCK_PREFIX "decq %0\n"
14539+
14540+#ifdef CONFIG_PAX_REFCOUNT
14541+ "jno 0f\n"
14542+ LOCK_PREFIX "incq %0\n"
14543+ "int $4\n0:\n"
14544+ _ASM_EXTABLE(0b, 0b)
14545+#endif
14546+
14547+ : "=m" (v->counter)
14548+ : "m" (v->counter));
14549+}
14550+
14551+/**
14552+ * atomic64_dec_unchecked - decrement atomic64 variable
14553+ * @v: pointer to type atomic64_t
14554+ *
14555+ * Atomically decrements @v by 1.
14556+ */
14557+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14558+{
14559+ asm volatile(LOCK_PREFIX "decq %0\n"
14560 : "=m" (v->counter)
14561 : "m" (v->counter));
14562 }
14563@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14564 {
14565 unsigned char c;
14566
14567- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14568+ asm volatile(LOCK_PREFIX "decq %0\n"
14569+
14570+#ifdef CONFIG_PAX_REFCOUNT
14571+ "jno 0f\n"
14572+ LOCK_PREFIX "incq %0\n"
14573+ "int $4\n0:\n"
14574+ _ASM_EXTABLE(0b, 0b)
14575+#endif
14576+
14577+ "sete %1\n"
14578 : "=m" (v->counter), "=qm" (c)
14579 : "m" (v->counter) : "memory");
14580 return c != 0;
14581@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14582 {
14583 unsigned char c;
14584
14585- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14586+ asm volatile(LOCK_PREFIX "incq %0\n"
14587+
14588+#ifdef CONFIG_PAX_REFCOUNT
14589+ "jno 0f\n"
14590+ LOCK_PREFIX "decq %0\n"
14591+ "int $4\n0:\n"
14592+ _ASM_EXTABLE(0b, 0b)
14593+#endif
14594+
14595+ "sete %1\n"
14596 : "=m" (v->counter), "=qm" (c)
14597 : "m" (v->counter) : "memory");
14598 return c != 0;
14599@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14600 {
14601 unsigned char c;
14602
14603- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14604+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14605+
14606+#ifdef CONFIG_PAX_REFCOUNT
14607+ "jno 0f\n"
14608+ LOCK_PREFIX "subq %2,%0\n"
14609+ "int $4\n0:\n"
14610+ _ASM_EXTABLE(0b, 0b)
14611+#endif
14612+
14613+ "sets %1\n"
14614 : "=m" (v->counter), "=qm" (c)
14615 : "er" (i), "m" (v->counter) : "memory");
14616 return c;
14617@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14618 */
14619 static inline long atomic64_add_return(long i, atomic64_t *v)
14620 {
14621+ return i + xadd_check_overflow(&v->counter, i);
14622+}
14623+
14624+/**
14625+ * atomic64_add_return_unchecked - add and return
14626+ * @i: integer value to add
14627+ * @v: pointer to type atomic64_unchecked_t
14628+ *
14629+ * Atomically adds @i to @v and returns @i + @v
14630+ */
14631+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14632+{
14633 return i + xadd(&v->counter, i);
14634 }
14635
14636@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14637 }
14638
14639 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14640+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14641+{
14642+ return atomic64_add_return_unchecked(1, v);
14643+}
14644 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14645
14646 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14647@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14648 return cmpxchg(&v->counter, old, new);
14649 }
14650
14651+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14652+{
14653+ return cmpxchg(&v->counter, old, new);
14654+}
14655+
14656 static inline long atomic64_xchg(atomic64_t *v, long new)
14657 {
14658 return xchg(&v->counter, new);
14659@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14660 */
14661 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14662 {
14663- long c, old;
14664+ long c, old, new;
14665 c = atomic64_read(v);
14666 for (;;) {
14667- if (unlikely(c == (u)))
14668+ if (unlikely(c == u))
14669 break;
14670- old = atomic64_cmpxchg((v), c, c + (a));
14671+
14672+ asm volatile("add %2,%0\n"
14673+
14674+#ifdef CONFIG_PAX_REFCOUNT
14675+ "jno 0f\n"
14676+ "sub %2,%0\n"
14677+ "int $4\n0:\n"
14678+ _ASM_EXTABLE(0b, 0b)
14679+#endif
14680+
14681+ : "=r" (new)
14682+ : "0" (c), "ir" (a));
14683+
14684+ old = atomic64_cmpxchg(v, c, new);
14685 if (likely(old == c))
14686 break;
14687 c = old;
14688 }
14689- return c != (u);
14690+ return c != u;
14691 }
14692
14693 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14694diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14695index 6dfd019..28e188d 100644
14696--- a/arch/x86/include/asm/bitops.h
14697+++ b/arch/x86/include/asm/bitops.h
14698@@ -40,7 +40,7 @@
14699 * a mask operation on a byte.
14700 */
14701 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14702-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14703+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14704 #define CONST_MASK(nr) (1 << ((nr) & 7))
14705
14706 /**
14707@@ -486,7 +486,7 @@ static inline int fls(int x)
14708 * at position 64.
14709 */
14710 #ifdef CONFIG_X86_64
14711-static __always_inline int fls64(__u64 x)
14712+static __always_inline long fls64(__u64 x)
14713 {
14714 int bitpos = -1;
14715 /*
14716diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14717index 4fa687a..60f2d39 100644
14718--- a/arch/x86/include/asm/boot.h
14719+++ b/arch/x86/include/asm/boot.h
14720@@ -6,10 +6,15 @@
14721 #include <uapi/asm/boot.h>
14722
14723 /* Physical address where kernel should be loaded. */
14724-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14725+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14726 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14727 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14728
14729+#ifndef __ASSEMBLY__
14730+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14731+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14732+#endif
14733+
14734 /* Minimum kernel alignment, as a power of two */
14735 #ifdef CONFIG_X86_64
14736 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14737diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14738index 48f99f1..d78ebf9 100644
14739--- a/arch/x86/include/asm/cache.h
14740+++ b/arch/x86/include/asm/cache.h
14741@@ -5,12 +5,13 @@
14742
14743 /* L1 cache line size */
14744 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14747
14748 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14749+#define __read_only __attribute__((__section__(".data..read_only")))
14750
14751 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14752-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14753+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14754
14755 #ifdef CONFIG_X86_VSMP
14756 #ifdef CONFIG_SMP
14757diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14758index 9863ee3..4a1f8e1 100644
14759--- a/arch/x86/include/asm/cacheflush.h
14760+++ b/arch/x86/include/asm/cacheflush.h
14761@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14762 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14763
14764 if (pg_flags == _PGMT_DEFAULT)
14765- return -1;
14766+ return ~0UL;
14767 else if (pg_flags == _PGMT_WC)
14768 return _PAGE_CACHE_WC;
14769 else if (pg_flags == _PGMT_UC_MINUS)
14770diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14771index f50de69..2b0a458 100644
14772--- a/arch/x86/include/asm/checksum_32.h
14773+++ b/arch/x86/include/asm/checksum_32.h
14774@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14775 int len, __wsum sum,
14776 int *src_err_ptr, int *dst_err_ptr);
14777
14778+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14779+ int len, __wsum sum,
14780+ int *src_err_ptr, int *dst_err_ptr);
14781+
14782+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14783+ int len, __wsum sum,
14784+ int *src_err_ptr, int *dst_err_ptr);
14785+
14786 /*
14787 * Note: when you get a NULL pointer exception here this means someone
14788 * passed in an incorrect kernel address to one of these functions.
14789@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14790
14791 might_sleep();
14792 stac();
14793- ret = csum_partial_copy_generic((__force void *)src, dst,
14794+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
14795 len, sum, err_ptr, NULL);
14796 clac();
14797
14798@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14799 might_sleep();
14800 if (access_ok(VERIFY_WRITE, dst, len)) {
14801 stac();
14802- ret = csum_partial_copy_generic(src, (__force void *)dst,
14803+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
14804 len, sum, NULL, err_ptr);
14805 clac();
14806 return ret;
14807diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14808index d47786a..ce1b05d 100644
14809--- a/arch/x86/include/asm/cmpxchg.h
14810+++ b/arch/x86/include/asm/cmpxchg.h
14811@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14812 __compiletime_error("Bad argument size for cmpxchg");
14813 extern void __xadd_wrong_size(void)
14814 __compiletime_error("Bad argument size for xadd");
14815+extern void __xadd_check_overflow_wrong_size(void)
14816+ __compiletime_error("Bad argument size for xadd_check_overflow");
14817 extern void __add_wrong_size(void)
14818 __compiletime_error("Bad argument size for add");
14819+extern void __add_check_overflow_wrong_size(void)
14820+ __compiletime_error("Bad argument size for add_check_overflow");
14821
14822 /*
14823 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14824@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14825 __ret; \
14826 })
14827
14828+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14829+ ({ \
14830+ __typeof__ (*(ptr)) __ret = (arg); \
14831+ switch (sizeof(*(ptr))) { \
14832+ case __X86_CASE_L: \
14833+ asm volatile (lock #op "l %0, %1\n" \
14834+ "jno 0f\n" \
14835+ "mov %0,%1\n" \
14836+ "int $4\n0:\n" \
14837+ _ASM_EXTABLE(0b, 0b) \
14838+ : "+r" (__ret), "+m" (*(ptr)) \
14839+ : : "memory", "cc"); \
14840+ break; \
14841+ case __X86_CASE_Q: \
14842+ asm volatile (lock #op "q %q0, %1\n" \
14843+ "jno 0f\n" \
14844+ "mov %0,%1\n" \
14845+ "int $4\n0:\n" \
14846+ _ASM_EXTABLE(0b, 0b) \
14847+ : "+r" (__ret), "+m" (*(ptr)) \
14848+ : : "memory", "cc"); \
14849+ break; \
14850+ default: \
14851+ __ ## op ## _check_overflow_wrong_size(); \
14852+ } \
14853+ __ret; \
14854+ })
14855+
14856 /*
14857 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14858 * Since this is generally used to protect other memory information, we
14859@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14860 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14861 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14862
14863+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14864+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14865+
14866 #define __add(ptr, inc, lock) \
14867 ({ \
14868 __typeof__ (*(ptr)) __ret = (inc); \
14869diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14870index 59c6c40..5e0b22c 100644
14871--- a/arch/x86/include/asm/compat.h
14872+++ b/arch/x86/include/asm/compat.h
14873@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14874 typedef u32 compat_uint_t;
14875 typedef u32 compat_ulong_t;
14876 typedef u64 __attribute__((aligned(4))) compat_u64;
14877-typedef u32 compat_uptr_t;
14878+typedef u32 __user compat_uptr_t;
14879
14880 struct compat_timespec {
14881 compat_time_t tv_sec;
14882diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14883index 7290585..717e89e 100644
14884--- a/arch/x86/include/asm/cpufeature.h
14885+++ b/arch/x86/include/asm/cpufeature.h
14886@@ -203,7 +203,7 @@
14887 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14888 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14889 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14890-
14891+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14892
14893 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14894 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14895@@ -211,7 +211,7 @@
14896 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14897 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14898 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14899-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14900+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14901 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14902 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14903 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14904@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14905 #undef cpu_has_centaur_mcr
14906 #define cpu_has_centaur_mcr 0
14907
14908+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14909 #endif /* CONFIG_X86_64 */
14910
14911 #if __GNUC__ >= 4
14912@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14913
14914 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14915 t_warn:
14916- warn_pre_alternatives();
14917+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14918+ warn_pre_alternatives();
14919 return false;
14920 #endif
14921 #else /* GCC_VERSION >= 40500 */
14922@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14923 ".section .discard,\"aw\",@progbits\n"
14924 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14925 ".previous\n"
14926- ".section .altinstr_replacement,\"ax\"\n"
14927+ ".section .altinstr_replacement,\"a\"\n"
14928 "3: movb $1,%0\n"
14929 "4:\n"
14930 ".previous\n"
14931@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14932 " .byte 2b - 1b\n" /* src len */
14933 " .byte 4f - 3f\n" /* repl len */
14934 ".previous\n"
14935- ".section .altinstr_replacement,\"ax\"\n"
14936+ ".section .altinstr_replacement,\"a\"\n"
14937 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14938 "4:\n"
14939 ".previous\n"
14940@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14941 ".section .discard,\"aw\",@progbits\n"
14942 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14943 ".previous\n"
14944- ".section .altinstr_replacement,\"ax\"\n"
14945+ ".section .altinstr_replacement,\"a\"\n"
14946 "3: movb $0,%0\n"
14947 "4:\n"
14948 ".previous\n"
14949@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14950 ".section .discard,\"aw\",@progbits\n"
14951 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14952 ".previous\n"
14953- ".section .altinstr_replacement,\"ax\"\n"
14954+ ".section .altinstr_replacement,\"a\"\n"
14955 "5: movb $1,%0\n"
14956 "6:\n"
14957 ".previous\n"
14958diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14959index b90e5df..b462c91 100644
14960--- a/arch/x86/include/asm/desc.h
14961+++ b/arch/x86/include/asm/desc.h
14962@@ -4,6 +4,7 @@
14963 #include <asm/desc_defs.h>
14964 #include <asm/ldt.h>
14965 #include <asm/mmu.h>
14966+#include <asm/pgtable.h>
14967
14968 #include <linux/smp.h>
14969 #include <linux/percpu.h>
14970@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14971
14972 desc->type = (info->read_exec_only ^ 1) << 1;
14973 desc->type |= info->contents << 2;
14974+ desc->type |= info->seg_not_present ^ 1;
14975
14976 desc->s = 1;
14977 desc->dpl = 0x3;
14978@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14979 }
14980
14981 extern struct desc_ptr idt_descr;
14982-extern gate_desc idt_table[];
14983-extern struct desc_ptr debug_idt_descr;
14984-extern gate_desc debug_idt_table[];
14985-
14986-struct gdt_page {
14987- struct desc_struct gdt[GDT_ENTRIES];
14988-} __attribute__((aligned(PAGE_SIZE)));
14989-
14990-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14991+extern gate_desc idt_table[IDT_ENTRIES];
14992+extern const struct desc_ptr debug_idt_descr;
14993+extern gate_desc debug_idt_table[IDT_ENTRIES];
14994
14995+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14996 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14997 {
14998- return per_cpu(gdt_page, cpu).gdt;
14999+ return cpu_gdt_table[cpu];
15000 }
15001
15002 #ifdef CONFIG_X86_64
15003@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15004 unsigned long base, unsigned dpl, unsigned flags,
15005 unsigned short seg)
15006 {
15007- gate->a = (seg << 16) | (base & 0xffff);
15008- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15009+ gate->gate.offset_low = base;
15010+ gate->gate.seg = seg;
15011+ gate->gate.reserved = 0;
15012+ gate->gate.type = type;
15013+ gate->gate.s = 0;
15014+ gate->gate.dpl = dpl;
15015+ gate->gate.p = 1;
15016+ gate->gate.offset_high = base >> 16;
15017 }
15018
15019 #endif
15020@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15021
15022 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15023 {
15024+ pax_open_kernel();
15025 memcpy(&idt[entry], gate, sizeof(*gate));
15026+ pax_close_kernel();
15027 }
15028
15029 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15030 {
15031+ pax_open_kernel();
15032 memcpy(&ldt[entry], desc, 8);
15033+ pax_close_kernel();
15034 }
15035
15036 static inline void
15037@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15038 default: size = sizeof(*gdt); break;
15039 }
15040
15041+ pax_open_kernel();
15042 memcpy(&gdt[entry], desc, size);
15043+ pax_close_kernel();
15044 }
15045
15046 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15047@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15048
15049 static inline void native_load_tr_desc(void)
15050 {
15051+ pax_open_kernel();
15052 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15053+ pax_close_kernel();
15054 }
15055
15056 static inline void native_load_gdt(const struct desc_ptr *dtr)
15057@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15058 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15059 unsigned int i;
15060
15061+ pax_open_kernel();
15062 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15063 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15064+ pax_close_kernel();
15065 }
15066
15067 #define _LDT_empty(info) \
15068@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15069 preempt_enable();
15070 }
15071
15072-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15073+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15074 {
15075 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15076 }
15077@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15078 }
15079
15080 #ifdef CONFIG_X86_64
15081-static inline void set_nmi_gate(int gate, void *addr)
15082+static inline void set_nmi_gate(int gate, const void *addr)
15083 {
15084 gate_desc s;
15085
15086@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15087 #endif
15088
15089 #ifdef CONFIG_TRACING
15090-extern struct desc_ptr trace_idt_descr;
15091-extern gate_desc trace_idt_table[];
15092+extern const struct desc_ptr trace_idt_descr;
15093+extern gate_desc trace_idt_table[IDT_ENTRIES];
15094 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15095 {
15096 write_idt_entry(trace_idt_table, entry, gate);
15097@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15098 }
15099 #endif
15100
15101-static inline void _set_gate(int gate, unsigned type, void *addr,
15102+static inline void _set_gate(int gate, unsigned type, const void *addr,
15103 unsigned dpl, unsigned ist, unsigned seg)
15104 {
15105 gate_desc s;
15106@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15107 * Pentium F0 0F bugfix can have resulted in the mapped
15108 * IDT being write-protected.
15109 */
15110-static inline void set_intr_gate(unsigned int n, void *addr)
15111+static inline void set_intr_gate(unsigned int n, const void *addr)
15112 {
15113 BUG_ON((unsigned)n > 0xFF);
15114 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15115@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15116 /*
15117 * This routine sets up an interrupt gate at directory privilege level 3.
15118 */
15119-static inline void set_system_intr_gate(unsigned int n, void *addr)
15120+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15121 {
15122 BUG_ON((unsigned)n > 0xFF);
15123 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15124 }
15125
15126-static inline void set_system_trap_gate(unsigned int n, void *addr)
15127+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15128 {
15129 BUG_ON((unsigned)n > 0xFF);
15130 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15131 }
15132
15133-static inline void set_trap_gate(unsigned int n, void *addr)
15134+static inline void set_trap_gate(unsigned int n, const void *addr)
15135 {
15136 BUG_ON((unsigned)n > 0xFF);
15137 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15138@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15139 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15140 {
15141 BUG_ON((unsigned)n > 0xFF);
15142- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15143+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15144 }
15145
15146-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15147+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15148 {
15149 BUG_ON((unsigned)n > 0xFF);
15150 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15151 }
15152
15153-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15154+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15155 {
15156 BUG_ON((unsigned)n > 0xFF);
15157 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15158@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15159 else
15160 load_idt((const struct desc_ptr *)&idt_descr);
15161 }
15162+
15163+#ifdef CONFIG_X86_32
15164+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15165+{
15166+ struct desc_struct d;
15167+
15168+ if (likely(limit))
15169+ limit = (limit - 1UL) >> PAGE_SHIFT;
15170+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15171+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15172+}
15173+#endif
15174+
15175 #endif /* _ASM_X86_DESC_H */
15176diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15177index 278441f..b95a174 100644
15178--- a/arch/x86/include/asm/desc_defs.h
15179+++ b/arch/x86/include/asm/desc_defs.h
15180@@ -31,6 +31,12 @@ struct desc_struct {
15181 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15182 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15183 };
15184+ struct {
15185+ u16 offset_low;
15186+ u16 seg;
15187+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15188+ unsigned offset_high: 16;
15189+ } gate;
15190 };
15191 } __attribute__((packed));
15192
15193diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15194index ced283a..ffe04cc 100644
15195--- a/arch/x86/include/asm/div64.h
15196+++ b/arch/x86/include/asm/div64.h
15197@@ -39,7 +39,7 @@
15198 __mod; \
15199 })
15200
15201-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15202+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15203 {
15204 union {
15205 u64 v64;
15206diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15207index 9c999c1..3860cb8 100644
15208--- a/arch/x86/include/asm/elf.h
15209+++ b/arch/x86/include/asm/elf.h
15210@@ -243,7 +243,25 @@ extern int force_personality32;
15211 the loader. We need to make sure that it is out of the way of the program
15212 that it will "exec", and that there is sufficient room for the brk. */
15213
15214+#ifdef CONFIG_PAX_SEGMEXEC
15215+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15216+#else
15217 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15218+#endif
15219+
15220+#ifdef CONFIG_PAX_ASLR
15221+#ifdef CONFIG_X86_32
15222+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15223+
15224+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15225+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15226+#else
15227+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15228+
15229+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15230+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15231+#endif
15232+#endif
15233
15234 /* This yields a mask that user programs can use to figure out what
15235 instruction set this CPU supports. This could be done in user space,
15236@@ -296,16 +314,12 @@ do { \
15237
15238 #define ARCH_DLINFO \
15239 do { \
15240- if (vdso_enabled) \
15241- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15242- (unsigned long)current->mm->context.vdso); \
15243+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15244 } while (0)
15245
15246 #define ARCH_DLINFO_X32 \
15247 do { \
15248- if (vdso_enabled) \
15249- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15250- (unsigned long)current->mm->context.vdso); \
15251+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15252 } while (0)
15253
15254 #define AT_SYSINFO 32
15255@@ -320,7 +334,7 @@ else \
15256
15257 #endif /* !CONFIG_X86_32 */
15258
15259-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15260+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15261
15262 #define VDSO_ENTRY \
15263 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15264@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15265 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15266 #define compat_arch_setup_additional_pages syscall32_setup_pages
15267
15268-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15269-#define arch_randomize_brk arch_randomize_brk
15270-
15271 /*
15272 * True on X86_32 or when emulating IA32 on X86_64
15273 */
15274diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15275index 77a99ac..39ff7f5 100644
15276--- a/arch/x86/include/asm/emergency-restart.h
15277+++ b/arch/x86/include/asm/emergency-restart.h
15278@@ -1,6 +1,6 @@
15279 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15280 #define _ASM_X86_EMERGENCY_RESTART_H
15281
15282-extern void machine_emergency_restart(void);
15283+extern void machine_emergency_restart(void) __noreturn;
15284
15285 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15286diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15287index 4d0bda7..221da4d 100644
15288--- a/arch/x86/include/asm/fpu-internal.h
15289+++ b/arch/x86/include/asm/fpu-internal.h
15290@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15291 #define user_insn(insn, output, input...) \
15292 ({ \
15293 int err; \
15294+ pax_open_userland(); \
15295 asm volatile(ASM_STAC "\n" \
15296- "1:" #insn "\n\t" \
15297+ "1:" \
15298+ __copyuser_seg \
15299+ #insn "\n\t" \
15300 "2: " ASM_CLAC "\n" \
15301 ".section .fixup,\"ax\"\n" \
15302 "3: movl $-1,%[err]\n" \
15303@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15304 _ASM_EXTABLE(1b, 3b) \
15305 : [err] "=r" (err), output \
15306 : "0"(0), input); \
15307+ pax_close_userland(); \
15308 err; \
15309 })
15310
15311@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15312 "emms\n\t" /* clear stack tags */
15313 "fildl %P[addr]", /* set F?P to defined value */
15314 X86_FEATURE_FXSAVE_LEAK,
15315- [addr] "m" (tsk->thread.fpu.has_fpu));
15316+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15317
15318 return fpu_restore_checking(&tsk->thread.fpu);
15319 }
15320diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15321index be27ba1..04a8801 100644
15322--- a/arch/x86/include/asm/futex.h
15323+++ b/arch/x86/include/asm/futex.h
15324@@ -12,6 +12,7 @@
15325 #include <asm/smap.h>
15326
15327 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15328+ typecheck(u32 __user *, uaddr); \
15329 asm volatile("\t" ASM_STAC "\n" \
15330 "1:\t" insn "\n" \
15331 "2:\t" ASM_CLAC "\n" \
15332@@ -20,15 +21,16 @@
15333 "\tjmp\t2b\n" \
15334 "\t.previous\n" \
15335 _ASM_EXTABLE(1b, 3b) \
15336- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15337+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15338 : "i" (-EFAULT), "0" (oparg), "1" (0))
15339
15340 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15341+ typecheck(u32 __user *, uaddr); \
15342 asm volatile("\t" ASM_STAC "\n" \
15343 "1:\tmovl %2, %0\n" \
15344 "\tmovl\t%0, %3\n" \
15345 "\t" insn "\n" \
15346- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15347+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15348 "\tjnz\t1b\n" \
15349 "3:\t" ASM_CLAC "\n" \
15350 "\t.section .fixup,\"ax\"\n" \
15351@@ -38,7 +40,7 @@
15352 _ASM_EXTABLE(1b, 4b) \
15353 _ASM_EXTABLE(2b, 4b) \
15354 : "=&a" (oldval), "=&r" (ret), \
15355- "+m" (*uaddr), "=&r" (tem) \
15356+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15357 : "r" (oparg), "i" (-EFAULT), "1" (0))
15358
15359 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15360@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15361
15362 pagefault_disable();
15363
15364+ pax_open_userland();
15365 switch (op) {
15366 case FUTEX_OP_SET:
15367- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15368+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15369 break;
15370 case FUTEX_OP_ADD:
15371- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15372+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15373 uaddr, oparg);
15374 break;
15375 case FUTEX_OP_OR:
15376@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15377 default:
15378 ret = -ENOSYS;
15379 }
15380+ pax_close_userland();
15381
15382 pagefault_enable();
15383
15384@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15385 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15386 return -EFAULT;
15387
15388+ pax_open_userland();
15389 asm volatile("\t" ASM_STAC "\n"
15390- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15391+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15392 "2:\t" ASM_CLAC "\n"
15393 "\t.section .fixup, \"ax\"\n"
15394 "3:\tmov %3, %0\n"
15395 "\tjmp 2b\n"
15396 "\t.previous\n"
15397 _ASM_EXTABLE(1b, 3b)
15398- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15399+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15400 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15401 : "memory"
15402 );
15403+ pax_close_userland();
15404
15405 *uval = oldval;
15406 return ret;
15407diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15408index e4ac559..c1c0c87 100644
15409--- a/arch/x86/include/asm/hw_irq.h
15410+++ b/arch/x86/include/asm/hw_irq.h
15411@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15412 extern void enable_IO_APIC(void);
15413
15414 /* Statistics */
15415-extern atomic_t irq_err_count;
15416-extern atomic_t irq_mis_count;
15417+extern atomic_unchecked_t irq_err_count;
15418+extern atomic_unchecked_t irq_mis_count;
15419
15420 /* EISA */
15421 extern void eisa_set_level_irq(unsigned int irq);
15422diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15423index a203659..9889f1c 100644
15424--- a/arch/x86/include/asm/i8259.h
15425+++ b/arch/x86/include/asm/i8259.h
15426@@ -62,7 +62,7 @@ struct legacy_pic {
15427 void (*init)(int auto_eoi);
15428 int (*irq_pending)(unsigned int irq);
15429 void (*make_irq)(unsigned int irq);
15430-};
15431+} __do_const;
15432
15433 extern struct legacy_pic *legacy_pic;
15434 extern struct legacy_pic null_legacy_pic;
15435diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15436index 34f69cb..6d95446 100644
15437--- a/arch/x86/include/asm/io.h
15438+++ b/arch/x86/include/asm/io.h
15439@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15440 "m" (*(volatile type __force *)addr) barrier); }
15441
15442 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15443-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15444-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15445+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15446+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15447
15448 build_mmio_read(__readb, "b", unsigned char, "=q", )
15449-build_mmio_read(__readw, "w", unsigned short, "=r", )
15450-build_mmio_read(__readl, "l", unsigned int, "=r", )
15451+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15452+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15453
15454 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15455 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15456@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15457 return ioremap_nocache(offset, size);
15458 }
15459
15460-extern void iounmap(volatile void __iomem *addr);
15461+extern void iounmap(const volatile void __iomem *addr);
15462
15463 extern void set_iounmap_nonlazy(void);
15464
15465@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15466
15467 #include <linux/vmalloc.h>
15468
15469+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15470+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15471+{
15472+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15473+}
15474+
15475+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15476+{
15477+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15478+}
15479+
15480 /*
15481 * Convert a virtual cached pointer to an uncached pointer
15482 */
15483diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15484index bba3cf8..06bc8da 100644
15485--- a/arch/x86/include/asm/irqflags.h
15486+++ b/arch/x86/include/asm/irqflags.h
15487@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15488 sti; \
15489 sysexit
15490
15491+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15492+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15493+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15494+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15495+
15496 #else
15497 #define INTERRUPT_RETURN iret
15498 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15499diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15500index 5a6d287..f815789 100644
15501--- a/arch/x86/include/asm/kprobes.h
15502+++ b/arch/x86/include/asm/kprobes.h
15503@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15504 #define RELATIVEJUMP_SIZE 5
15505 #define RELATIVECALL_OPCODE 0xe8
15506 #define RELATIVE_ADDR_SIZE 4
15507-#define MAX_STACK_SIZE 64
15508-#define MIN_STACK_SIZE(ADDR) \
15509- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15510- THREAD_SIZE - (unsigned long)(ADDR))) \
15511- ? (MAX_STACK_SIZE) \
15512- : (((unsigned long)current_thread_info()) + \
15513- THREAD_SIZE - (unsigned long)(ADDR)))
15514+#define MAX_STACK_SIZE 64UL
15515+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15516
15517 #define flush_insn_slot(p) do { } while (0)
15518
15519diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15520index 2d89e39..baee879 100644
15521--- a/arch/x86/include/asm/local.h
15522+++ b/arch/x86/include/asm/local.h
15523@@ -10,33 +10,97 @@ typedef struct {
15524 atomic_long_t a;
15525 } local_t;
15526
15527+typedef struct {
15528+ atomic_long_unchecked_t a;
15529+} local_unchecked_t;
15530+
15531 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15532
15533 #define local_read(l) atomic_long_read(&(l)->a)
15534+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15535 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15536+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15537
15538 static inline void local_inc(local_t *l)
15539 {
15540- asm volatile(_ASM_INC "%0"
15541+ asm volatile(_ASM_INC "%0\n"
15542+
15543+#ifdef CONFIG_PAX_REFCOUNT
15544+ "jno 0f\n"
15545+ _ASM_DEC "%0\n"
15546+ "int $4\n0:\n"
15547+ _ASM_EXTABLE(0b, 0b)
15548+#endif
15549+
15550+ : "+m" (l->a.counter));
15551+}
15552+
15553+static inline void local_inc_unchecked(local_unchecked_t *l)
15554+{
15555+ asm volatile(_ASM_INC "%0\n"
15556 : "+m" (l->a.counter));
15557 }
15558
15559 static inline void local_dec(local_t *l)
15560 {
15561- asm volatile(_ASM_DEC "%0"
15562+ asm volatile(_ASM_DEC "%0\n"
15563+
15564+#ifdef CONFIG_PAX_REFCOUNT
15565+ "jno 0f\n"
15566+ _ASM_INC "%0\n"
15567+ "int $4\n0:\n"
15568+ _ASM_EXTABLE(0b, 0b)
15569+#endif
15570+
15571+ : "+m" (l->a.counter));
15572+}
15573+
15574+static inline void local_dec_unchecked(local_unchecked_t *l)
15575+{
15576+ asm volatile(_ASM_DEC "%0\n"
15577 : "+m" (l->a.counter));
15578 }
15579
15580 static inline void local_add(long i, local_t *l)
15581 {
15582- asm volatile(_ASM_ADD "%1,%0"
15583+ asm volatile(_ASM_ADD "%1,%0\n"
15584+
15585+#ifdef CONFIG_PAX_REFCOUNT
15586+ "jno 0f\n"
15587+ _ASM_SUB "%1,%0\n"
15588+ "int $4\n0:\n"
15589+ _ASM_EXTABLE(0b, 0b)
15590+#endif
15591+
15592+ : "+m" (l->a.counter)
15593+ : "ir" (i));
15594+}
15595+
15596+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15597+{
15598+ asm volatile(_ASM_ADD "%1,%0\n"
15599 : "+m" (l->a.counter)
15600 : "ir" (i));
15601 }
15602
15603 static inline void local_sub(long i, local_t *l)
15604 {
15605- asm volatile(_ASM_SUB "%1,%0"
15606+ asm volatile(_ASM_SUB "%1,%0\n"
15607+
15608+#ifdef CONFIG_PAX_REFCOUNT
15609+ "jno 0f\n"
15610+ _ASM_ADD "%1,%0\n"
15611+ "int $4\n0:\n"
15612+ _ASM_EXTABLE(0b, 0b)
15613+#endif
15614+
15615+ : "+m" (l->a.counter)
15616+ : "ir" (i));
15617+}
15618+
15619+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15620+{
15621+ asm volatile(_ASM_SUB "%1,%0\n"
15622 : "+m" (l->a.counter)
15623 : "ir" (i));
15624 }
15625@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15626 {
15627 unsigned char c;
15628
15629- asm volatile(_ASM_SUB "%2,%0; sete %1"
15630+ asm volatile(_ASM_SUB "%2,%0\n"
15631+
15632+#ifdef CONFIG_PAX_REFCOUNT
15633+ "jno 0f\n"
15634+ _ASM_ADD "%2,%0\n"
15635+ "int $4\n0:\n"
15636+ _ASM_EXTABLE(0b, 0b)
15637+#endif
15638+
15639+ "sete %1\n"
15640 : "+m" (l->a.counter), "=qm" (c)
15641 : "ir" (i) : "memory");
15642 return c;
15643@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15644 {
15645 unsigned char c;
15646
15647- asm volatile(_ASM_DEC "%0; sete %1"
15648+ asm volatile(_ASM_DEC "%0\n"
15649+
15650+#ifdef CONFIG_PAX_REFCOUNT
15651+ "jno 0f\n"
15652+ _ASM_INC "%0\n"
15653+ "int $4\n0:\n"
15654+ _ASM_EXTABLE(0b, 0b)
15655+#endif
15656+
15657+ "sete %1\n"
15658 : "+m" (l->a.counter), "=qm" (c)
15659 : : "memory");
15660 return c != 0;
15661@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15662 {
15663 unsigned char c;
15664
15665- asm volatile(_ASM_INC "%0; sete %1"
15666+ asm volatile(_ASM_INC "%0\n"
15667+
15668+#ifdef CONFIG_PAX_REFCOUNT
15669+ "jno 0f\n"
15670+ _ASM_DEC "%0\n"
15671+ "int $4\n0:\n"
15672+ _ASM_EXTABLE(0b, 0b)
15673+#endif
15674+
15675+ "sete %1\n"
15676 : "+m" (l->a.counter), "=qm" (c)
15677 : : "memory");
15678 return c != 0;
15679@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15680 {
15681 unsigned char c;
15682
15683- asm volatile(_ASM_ADD "%2,%0; sets %1"
15684+ asm volatile(_ASM_ADD "%2,%0\n"
15685+
15686+#ifdef CONFIG_PAX_REFCOUNT
15687+ "jno 0f\n"
15688+ _ASM_SUB "%2,%0\n"
15689+ "int $4\n0:\n"
15690+ _ASM_EXTABLE(0b, 0b)
15691+#endif
15692+
15693+ "sets %1\n"
15694 : "+m" (l->a.counter), "=qm" (c)
15695 : "ir" (i) : "memory");
15696 return c;
15697@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15698 static inline long local_add_return(long i, local_t *l)
15699 {
15700 long __i = i;
15701+ asm volatile(_ASM_XADD "%0, %1\n"
15702+
15703+#ifdef CONFIG_PAX_REFCOUNT
15704+ "jno 0f\n"
15705+ _ASM_MOV "%0,%1\n"
15706+ "int $4\n0:\n"
15707+ _ASM_EXTABLE(0b, 0b)
15708+#endif
15709+
15710+ : "+r" (i), "+m" (l->a.counter)
15711+ : : "memory");
15712+ return i + __i;
15713+}
15714+
15715+/**
15716+ * local_add_return_unchecked - add and return
15717+ * @i: integer value to add
15718+ * @l: pointer to type local_unchecked_t
15719+ *
15720+ * Atomically adds @i to @l and returns @i + @l
15721+ */
15722+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15723+{
15724+ long __i = i;
15725 asm volatile(_ASM_XADD "%0, %1;"
15726 : "+r" (i), "+m" (l->a.counter)
15727 : : "memory");
15728@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15729
15730 #define local_cmpxchg(l, o, n) \
15731 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15732+#define local_cmpxchg_unchecked(l, o, n) \
15733+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15734 /* Always has a lock prefix */
15735 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15736
15737diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15738new file mode 100644
15739index 0000000..2bfd3ba
15740--- /dev/null
15741+++ b/arch/x86/include/asm/mman.h
15742@@ -0,0 +1,15 @@
15743+#ifndef _X86_MMAN_H
15744+#define _X86_MMAN_H
15745+
15746+#include <uapi/asm/mman.h>
15747+
15748+#ifdef __KERNEL__
15749+#ifndef __ASSEMBLY__
15750+#ifdef CONFIG_X86_32
15751+#define arch_mmap_check i386_mmap_check
15752+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15753+#endif
15754+#endif
15755+#endif
15756+
15757+#endif /* X86_MMAN_H */
15758diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15759index 5f55e69..e20bfb1 100644
15760--- a/arch/x86/include/asm/mmu.h
15761+++ b/arch/x86/include/asm/mmu.h
15762@@ -9,7 +9,7 @@
15763 * we put the segment information here.
15764 */
15765 typedef struct {
15766- void *ldt;
15767+ struct desc_struct *ldt;
15768 int size;
15769
15770 #ifdef CONFIG_X86_64
15771@@ -18,7 +18,19 @@ typedef struct {
15772 #endif
15773
15774 struct mutex lock;
15775- void *vdso;
15776+ unsigned long vdso;
15777+
15778+#ifdef CONFIG_X86_32
15779+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15780+ unsigned long user_cs_base;
15781+ unsigned long user_cs_limit;
15782+
15783+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15784+ cpumask_t cpu_user_cs_mask;
15785+#endif
15786+
15787+#endif
15788+#endif
15789 } mm_context_t;
15790
15791 #ifdef CONFIG_SMP
15792diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15793index be12c53..2124e35 100644
15794--- a/arch/x86/include/asm/mmu_context.h
15795+++ b/arch/x86/include/asm/mmu_context.h
15796@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15797
15798 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15799 {
15800+
15801+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15802+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15803+ unsigned int i;
15804+ pgd_t *pgd;
15805+
15806+ pax_open_kernel();
15807+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15808+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15809+ set_pgd_batched(pgd+i, native_make_pgd(0));
15810+ pax_close_kernel();
15811+ }
15812+#endif
15813+
15814 #ifdef CONFIG_SMP
15815 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15816 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15817@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15818 struct task_struct *tsk)
15819 {
15820 unsigned cpu = smp_processor_id();
15821+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15822+ int tlbstate = TLBSTATE_OK;
15823+#endif
15824
15825 if (likely(prev != next)) {
15826 #ifdef CONFIG_SMP
15827+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15828+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15829+#endif
15830 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15831 this_cpu_write(cpu_tlbstate.active_mm, next);
15832 #endif
15833 cpumask_set_cpu(cpu, mm_cpumask(next));
15834
15835 /* Re-load page tables */
15836+#ifdef CONFIG_PAX_PER_CPU_PGD
15837+ pax_open_kernel();
15838+
15839+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15840+ if (static_cpu_has(X86_FEATURE_PCID))
15841+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15842+ else
15843+#endif
15844+
15845+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15846+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15847+ pax_close_kernel();
15848+ 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));
15849+
15850+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15851+ if (static_cpu_has(X86_FEATURE_PCID)) {
15852+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15853+ u64 descriptor[2];
15854+ descriptor[0] = PCID_USER;
15855+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15856+ } else {
15857+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15858+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15859+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15860+ else
15861+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15862+ }
15863+ } else
15864+#endif
15865+
15866+ load_cr3(get_cpu_pgd(cpu, kernel));
15867+#else
15868 load_cr3(next->pgd);
15869+#endif
15870
15871 /* Stop flush ipis for the previous mm */
15872 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15873@@ -51,9 +104,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15874 /* Load the LDT, if the LDT is different: */
15875 if (unlikely(prev->context.ldt != next->context.ldt))
15876 load_LDT_nolock(&next->context);
15877+
15878+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15879+ if (!(__supported_pte_mask & _PAGE_NX)) {
15880+ smp_mb__before_clear_bit();
15881+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15882+ smp_mb__after_clear_bit();
15883+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15884+ }
15885+#endif
15886+
15887+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15888+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15889+ prev->context.user_cs_limit != next->context.user_cs_limit))
15890+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15891+#ifdef CONFIG_SMP
15892+ else if (unlikely(tlbstate != TLBSTATE_OK))
15893+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15894+#endif
15895+#endif
15896+
15897 }
15898+ else {
15899+
15900+#ifdef CONFIG_PAX_PER_CPU_PGD
15901+ pax_open_kernel();
15902+
15903+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15904+ if (static_cpu_has(X86_FEATURE_PCID))
15905+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15906+ else
15907+#endif
15908+
15909+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15910+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15911+ pax_close_kernel();
15912+ 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));
15913+
15914+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15915+ if (static_cpu_has(X86_FEATURE_PCID)) {
15916+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15917+ u64 descriptor[2];
15918+ descriptor[0] = PCID_USER;
15919+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15920+ } else {
15921+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15922+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15923+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15924+ else
15925+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15926+ }
15927+ } else
15928+#endif
15929+
15930+ load_cr3(get_cpu_pgd(cpu, kernel));
15931+#endif
15932+
15933 #ifdef CONFIG_SMP
15934- else {
15935 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15936 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15937
15938@@ -70,11 +177,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15939 * tlb flush IPI delivery. We must reload CR3
15940 * to make sure to use no freed page tables.
15941 */
15942+
15943+#ifndef CONFIG_PAX_PER_CPU_PGD
15944 load_cr3(next->pgd);
15945+#endif
15946+
15947 load_LDT_nolock(&next->context);
15948+
15949+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15950+ if (!(__supported_pte_mask & _PAGE_NX))
15951+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15952+#endif
15953+
15954+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15955+#ifdef CONFIG_PAX_PAGEEXEC
15956+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15957+#endif
15958+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15959+#endif
15960+
15961 }
15962+#endif
15963 }
15964-#endif
15965 }
15966
15967 #define activate_mm(prev, next) \
15968diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15969index e3b7819..b257c64 100644
15970--- a/arch/x86/include/asm/module.h
15971+++ b/arch/x86/include/asm/module.h
15972@@ -5,6 +5,7 @@
15973
15974 #ifdef CONFIG_X86_64
15975 /* X86_64 does not define MODULE_PROC_FAMILY */
15976+#define MODULE_PROC_FAMILY ""
15977 #elif defined CONFIG_M486
15978 #define MODULE_PROC_FAMILY "486 "
15979 #elif defined CONFIG_M586
15980@@ -57,8 +58,20 @@
15981 #error unknown processor family
15982 #endif
15983
15984-#ifdef CONFIG_X86_32
15985-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15986+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15987+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15988+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15989+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15990+#else
15991+#define MODULE_PAX_KERNEXEC ""
15992 #endif
15993
15994+#ifdef CONFIG_PAX_MEMORY_UDEREF
15995+#define MODULE_PAX_UDEREF "UDEREF "
15996+#else
15997+#define MODULE_PAX_UDEREF ""
15998+#endif
15999+
16000+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16001+
16002 #endif /* _ASM_X86_MODULE_H */
16003diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16004index 86f9301..b365cda 100644
16005--- a/arch/x86/include/asm/nmi.h
16006+++ b/arch/x86/include/asm/nmi.h
16007@@ -40,11 +40,11 @@ struct nmiaction {
16008 nmi_handler_t handler;
16009 unsigned long flags;
16010 const char *name;
16011-};
16012+} __do_const;
16013
16014 #define register_nmi_handler(t, fn, fg, n, init...) \
16015 ({ \
16016- static struct nmiaction init fn##_na = { \
16017+ static const struct nmiaction init fn##_na = { \
16018 .handler = (fn), \
16019 .name = (n), \
16020 .flags = (fg), \
16021@@ -52,7 +52,7 @@ struct nmiaction {
16022 __register_nmi_handler((t), &fn##_na); \
16023 })
16024
16025-int __register_nmi_handler(unsigned int, struct nmiaction *);
16026+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16027
16028 void unregister_nmi_handler(unsigned int, const char *);
16029
16030diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16031index c878924..21f4889 100644
16032--- a/arch/x86/include/asm/page.h
16033+++ b/arch/x86/include/asm/page.h
16034@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16035 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16036
16037 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16038+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16039
16040 #define __boot_va(x) __va(x)
16041 #define __boot_pa(x) __pa(x)
16042diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16043index 0f1ddee..e2fc3d1 100644
16044--- a/arch/x86/include/asm/page_64.h
16045+++ b/arch/x86/include/asm/page_64.h
16046@@ -7,9 +7,9 @@
16047
16048 /* duplicated to the one in bootmem.h */
16049 extern unsigned long max_pfn;
16050-extern unsigned long phys_base;
16051+extern const unsigned long phys_base;
16052
16053-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16054+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16055 {
16056 unsigned long y = x - __START_KERNEL_map;
16057
16058diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16059index cfdc9ee..3f7b5d6 100644
16060--- a/arch/x86/include/asm/paravirt.h
16061+++ b/arch/x86/include/asm/paravirt.h
16062@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16063 return (pmd_t) { ret };
16064 }
16065
16066-static inline pmdval_t pmd_val(pmd_t pmd)
16067+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16068 {
16069 pmdval_t ret;
16070
16071@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16072 val);
16073 }
16074
16075+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16076+{
16077+ pgdval_t val = native_pgd_val(pgd);
16078+
16079+ if (sizeof(pgdval_t) > sizeof(long))
16080+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16081+ val, (u64)val >> 32);
16082+ else
16083+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16084+ val);
16085+}
16086+
16087 static inline void pgd_clear(pgd_t *pgdp)
16088 {
16089 set_pgd(pgdp, __pgd(0));
16090@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16091 pv_mmu_ops.set_fixmap(idx, phys, flags);
16092 }
16093
16094+#ifdef CONFIG_PAX_KERNEXEC
16095+static inline unsigned long pax_open_kernel(void)
16096+{
16097+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16098+}
16099+
16100+static inline unsigned long pax_close_kernel(void)
16101+{
16102+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16103+}
16104+#else
16105+static inline unsigned long pax_open_kernel(void) { return 0; }
16106+static inline unsigned long pax_close_kernel(void) { return 0; }
16107+#endif
16108+
16109 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16110
16111 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16112@@ -926,7 +953,7 @@ extern void default_banner(void);
16113
16114 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16115 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16116-#define PARA_INDIRECT(addr) *%cs:addr
16117+#define PARA_INDIRECT(addr) *%ss:addr
16118 #endif
16119
16120 #define INTERRUPT_RETURN \
16121@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16122 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16123 CLBR_NONE, \
16124 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16125+
16126+#define GET_CR0_INTO_RDI \
16127+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16128+ mov %rax,%rdi
16129+
16130+#define SET_RDI_INTO_CR0 \
16131+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16132+
16133+#define GET_CR3_INTO_RDI \
16134+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16135+ mov %rax,%rdi
16136+
16137+#define SET_RDI_INTO_CR3 \
16138+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16139+
16140 #endif /* CONFIG_X86_32 */
16141
16142 #endif /* __ASSEMBLY__ */
16143diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16144index 0db1fca..52310cc 100644
16145--- a/arch/x86/include/asm/paravirt_types.h
16146+++ b/arch/x86/include/asm/paravirt_types.h
16147@@ -84,7 +84,7 @@ struct pv_init_ops {
16148 */
16149 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16150 unsigned long addr, unsigned len);
16151-};
16152+} __no_const;
16153
16154
16155 struct pv_lazy_ops {
16156@@ -98,7 +98,7 @@ struct pv_time_ops {
16157 unsigned long long (*sched_clock)(void);
16158 unsigned long long (*steal_clock)(int cpu);
16159 unsigned long (*get_tsc_khz)(void);
16160-};
16161+} __no_const;
16162
16163 struct pv_cpu_ops {
16164 /* hooks for various privileged instructions */
16165@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16166
16167 void (*start_context_switch)(struct task_struct *prev);
16168 void (*end_context_switch)(struct task_struct *next);
16169-};
16170+} __no_const;
16171
16172 struct pv_irq_ops {
16173 /*
16174@@ -223,7 +223,7 @@ struct pv_apic_ops {
16175 unsigned long start_eip,
16176 unsigned long start_esp);
16177 #endif
16178-};
16179+} __no_const;
16180
16181 struct pv_mmu_ops {
16182 unsigned long (*read_cr2)(void);
16183@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16184 struct paravirt_callee_save make_pud;
16185
16186 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16187+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16188 #endif /* PAGETABLE_LEVELS == 4 */
16189 #endif /* PAGETABLE_LEVELS >= 3 */
16190
16191@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16192 an mfn. We can tell which is which from the index. */
16193 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16194 phys_addr_t phys, pgprot_t flags);
16195+
16196+#ifdef CONFIG_PAX_KERNEXEC
16197+ unsigned long (*pax_open_kernel)(void);
16198+ unsigned long (*pax_close_kernel)(void);
16199+#endif
16200+
16201 };
16202
16203 struct arch_spinlock;
16204@@ -334,7 +341,7 @@ struct pv_lock_ops {
16205 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16206 int (*spin_trylock)(struct arch_spinlock *lock);
16207 void (*spin_unlock)(struct arch_spinlock *lock);
16208-};
16209+} __no_const;
16210
16211 /* This contains all the paravirt structures: we get a convenient
16212 * number for each function using the offset which we use to indicate
16213diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16214index b4389a4..7024269 100644
16215--- a/arch/x86/include/asm/pgalloc.h
16216+++ b/arch/x86/include/asm/pgalloc.h
16217@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16218 pmd_t *pmd, pte_t *pte)
16219 {
16220 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16221+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16222+}
16223+
16224+static inline void pmd_populate_user(struct mm_struct *mm,
16225+ pmd_t *pmd, pte_t *pte)
16226+{
16227+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16228 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16229 }
16230
16231@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16232
16233 #ifdef CONFIG_X86_PAE
16234 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16235+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16236+{
16237+ pud_populate(mm, pudp, pmd);
16238+}
16239 #else /* !CONFIG_X86_PAE */
16240 static inline void pud_populate(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(_PAGE_TABLE | __pa(pmd)));
16244 }
16245+
16246+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16247+{
16248+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16249+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16250+}
16251 #endif /* CONFIG_X86_PAE */
16252
16253 #if PAGETABLE_LEVELS > 3
16254@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16255 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16256 }
16257
16258+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16259+{
16260+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16261+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16262+}
16263+
16264 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16265 {
16266 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16267diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16268index 3bf2dd0..23d2a9f 100644
16269--- a/arch/x86/include/asm/pgtable-2level.h
16270+++ b/arch/x86/include/asm/pgtable-2level.h
16271@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16272
16273 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16274 {
16275+ pax_open_kernel();
16276 *pmdp = pmd;
16277+ pax_close_kernel();
16278 }
16279
16280 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16281diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16282index 81bb91b..9392125 100644
16283--- a/arch/x86/include/asm/pgtable-3level.h
16284+++ b/arch/x86/include/asm/pgtable-3level.h
16285@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16286
16287 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16288 {
16289+ pax_open_kernel();
16290 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16291+ pax_close_kernel();
16292 }
16293
16294 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16295 {
16296+ pax_open_kernel();
16297 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16298+ pax_close_kernel();
16299 }
16300
16301 /*
16302diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16303index 1c00631..845f898 100644
16304--- a/arch/x86/include/asm/pgtable.h
16305+++ b/arch/x86/include/asm/pgtable.h
16306@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16307
16308 #ifndef __PAGETABLE_PUD_FOLDED
16309 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16310+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16311 #define pgd_clear(pgd) native_pgd_clear(pgd)
16312 #endif
16313
16314@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16315
16316 #define arch_end_context_switch(prev) do {} while(0)
16317
16318+#define pax_open_kernel() native_pax_open_kernel()
16319+#define pax_close_kernel() native_pax_close_kernel()
16320 #endif /* CONFIG_PARAVIRT */
16321
16322+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16323+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16324+
16325+#ifdef CONFIG_PAX_KERNEXEC
16326+static inline unsigned long native_pax_open_kernel(void)
16327+{
16328+ unsigned long cr0;
16329+
16330+ preempt_disable();
16331+ barrier();
16332+ cr0 = read_cr0() ^ X86_CR0_WP;
16333+ BUG_ON(cr0 & X86_CR0_WP);
16334+ write_cr0(cr0);
16335+ return cr0 ^ X86_CR0_WP;
16336+}
16337+
16338+static inline unsigned long native_pax_close_kernel(void)
16339+{
16340+ unsigned long cr0;
16341+
16342+ cr0 = read_cr0() ^ X86_CR0_WP;
16343+ BUG_ON(!(cr0 & X86_CR0_WP));
16344+ write_cr0(cr0);
16345+ barrier();
16346+ preempt_enable_no_resched();
16347+ return cr0 ^ X86_CR0_WP;
16348+}
16349+#else
16350+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16351+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16352+#endif
16353+
16354 /*
16355 * The following only work if pte_present() is true.
16356 * Undefined behaviour if not..
16357 */
16358+static inline int pte_user(pte_t pte)
16359+{
16360+ return pte_val(pte) & _PAGE_USER;
16361+}
16362+
16363 static inline int pte_dirty(pte_t pte)
16364 {
16365 return pte_flags(pte) & _PAGE_DIRTY;
16366@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16367 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16368 }
16369
16370+static inline unsigned long pgd_pfn(pgd_t pgd)
16371+{
16372+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16373+}
16374+
16375 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16376
16377 static inline int pmd_large(pmd_t pte)
16378@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16379 return pte_clear_flags(pte, _PAGE_RW);
16380 }
16381
16382+static inline pte_t pte_mkread(pte_t pte)
16383+{
16384+ return __pte(pte_val(pte) | _PAGE_USER);
16385+}
16386+
16387 static inline pte_t pte_mkexec(pte_t pte)
16388 {
16389- return pte_clear_flags(pte, _PAGE_NX);
16390+#ifdef CONFIG_X86_PAE
16391+ if (__supported_pte_mask & _PAGE_NX)
16392+ return pte_clear_flags(pte, _PAGE_NX);
16393+ else
16394+#endif
16395+ return pte_set_flags(pte, _PAGE_USER);
16396+}
16397+
16398+static inline pte_t pte_exprotect(pte_t pte)
16399+{
16400+#ifdef CONFIG_X86_PAE
16401+ if (__supported_pte_mask & _PAGE_NX)
16402+ return pte_set_flags(pte, _PAGE_NX);
16403+ else
16404+#endif
16405+ return pte_clear_flags(pte, _PAGE_USER);
16406 }
16407
16408 static inline pte_t pte_mkdirty(pte_t pte)
16409@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16410 #endif
16411
16412 #ifndef __ASSEMBLY__
16413+
16414+#ifdef CONFIG_PAX_PER_CPU_PGD
16415+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16416+enum cpu_pgd_type {kernel = 0, user = 1};
16417+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16418+{
16419+ return cpu_pgd[cpu][type];
16420+}
16421+#endif
16422+
16423 #include <linux/mm_types.h>
16424 #include <linux/log2.h>
16425
16426@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16427 * Currently stuck as a macro due to indirect forward reference to
16428 * linux/mmzone.h's __section_mem_map_addr() definition:
16429 */
16430-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16431+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16432
16433 /* Find an entry in the second-level page table.. */
16434 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16435@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16436 * Currently stuck as a macro due to indirect forward reference to
16437 * linux/mmzone.h's __section_mem_map_addr() definition:
16438 */
16439-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16440+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16441
16442 /* to find an entry in a page-table-directory. */
16443 static inline unsigned long pud_index(unsigned long address)
16444@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16445
16446 static inline int pgd_bad(pgd_t pgd)
16447 {
16448- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16449+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16450 }
16451
16452 static inline int pgd_none(pgd_t pgd)
16453@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16454 * pgd_offset() returns a (pgd_t *)
16455 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16456 */
16457-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16458+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16459+
16460+#ifdef CONFIG_PAX_PER_CPU_PGD
16461+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16462+#endif
16463+
16464 /*
16465 * a shortcut which implies the use of the kernel's pgd, instead
16466 * of a process's
16467@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16468 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16469 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16470
16471+#ifdef CONFIG_X86_32
16472+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16473+#else
16474+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16475+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16476+
16477+#ifdef CONFIG_PAX_MEMORY_UDEREF
16478+#ifdef __ASSEMBLY__
16479+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16480+#else
16481+extern unsigned long pax_user_shadow_base;
16482+extern pgdval_t clone_pgd_mask;
16483+#endif
16484+#endif
16485+
16486+#endif
16487+
16488 #ifndef __ASSEMBLY__
16489
16490 extern int direct_gbpages;
16491@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16492 * dst and src can be on the same page, but the range must not overlap,
16493 * and must not cross a page boundary.
16494 */
16495-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16496+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16497 {
16498- memcpy(dst, src, count * sizeof(pgd_t));
16499+ pax_open_kernel();
16500+ while (count--)
16501+ *dst++ = *src++;
16502+ pax_close_kernel();
16503 }
16504
16505+#ifdef CONFIG_PAX_PER_CPU_PGD
16506+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16507+#endif
16508+
16509+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16510+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16511+#else
16512+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16513+#endif
16514+
16515 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16516 static inline int page_level_shift(enum pg_level level)
16517 {
16518diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16519index 9ee3221..b979c6b 100644
16520--- a/arch/x86/include/asm/pgtable_32.h
16521+++ b/arch/x86/include/asm/pgtable_32.h
16522@@ -25,9 +25,6 @@
16523 struct mm_struct;
16524 struct vm_area_struct;
16525
16526-extern pgd_t swapper_pg_dir[1024];
16527-extern pgd_t initial_page_table[1024];
16528-
16529 static inline void pgtable_cache_init(void) { }
16530 static inline void check_pgt_cache(void) { }
16531 void paging_init(void);
16532@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16533 # include <asm/pgtable-2level.h>
16534 #endif
16535
16536+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16537+extern pgd_t initial_page_table[PTRS_PER_PGD];
16538+#ifdef CONFIG_X86_PAE
16539+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16540+#endif
16541+
16542 #if defined(CONFIG_HIGHPTE)
16543 #define pte_offset_map(dir, address) \
16544 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16545@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16546 /* Clear a kernel PTE and flush it from the TLB */
16547 #define kpte_clear_flush(ptep, vaddr) \
16548 do { \
16549+ pax_open_kernel(); \
16550 pte_clear(&init_mm, (vaddr), (ptep)); \
16551+ pax_close_kernel(); \
16552 __flush_tlb_one((vaddr)); \
16553 } while (0)
16554
16555 #endif /* !__ASSEMBLY__ */
16556
16557+#define HAVE_ARCH_UNMAPPED_AREA
16558+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16559+
16560 /*
16561 * kern_addr_valid() is (1) for FLATMEM and (0) for
16562 * SPARSEMEM and DISCONTIGMEM
16563diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16564index ed5903b..c7fe163 100644
16565--- a/arch/x86/include/asm/pgtable_32_types.h
16566+++ b/arch/x86/include/asm/pgtable_32_types.h
16567@@ -8,7 +8,7 @@
16568 */
16569 #ifdef CONFIG_X86_PAE
16570 # include <asm/pgtable-3level_types.h>
16571-# define PMD_SIZE (1UL << PMD_SHIFT)
16572+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16573 # define PMD_MASK (~(PMD_SIZE - 1))
16574 #else
16575 # include <asm/pgtable-2level_types.h>
16576@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16577 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16578 #endif
16579
16580+#ifdef CONFIG_PAX_KERNEXEC
16581+#ifndef __ASSEMBLY__
16582+extern unsigned char MODULES_EXEC_VADDR[];
16583+extern unsigned char MODULES_EXEC_END[];
16584+#endif
16585+#include <asm/boot.h>
16586+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16587+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16588+#else
16589+#define ktla_ktva(addr) (addr)
16590+#define ktva_ktla(addr) (addr)
16591+#endif
16592+
16593 #define MODULES_VADDR VMALLOC_START
16594 #define MODULES_END VMALLOC_END
16595 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16596diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16597index e22c1db..23a625a 100644
16598--- a/arch/x86/include/asm/pgtable_64.h
16599+++ b/arch/x86/include/asm/pgtable_64.h
16600@@ -16,10 +16,14 @@
16601
16602 extern pud_t level3_kernel_pgt[512];
16603 extern pud_t level3_ident_pgt[512];
16604+extern pud_t level3_vmalloc_start_pgt[512];
16605+extern pud_t level3_vmalloc_end_pgt[512];
16606+extern pud_t level3_vmemmap_pgt[512];
16607+extern pud_t level2_vmemmap_pgt[512];
16608 extern pmd_t level2_kernel_pgt[512];
16609 extern pmd_t level2_fixmap_pgt[512];
16610-extern pmd_t level2_ident_pgt[512];
16611-extern pgd_t init_level4_pgt[];
16612+extern pmd_t level2_ident_pgt[512*2];
16613+extern pgd_t init_level4_pgt[512];
16614
16615 #define swapper_pg_dir init_level4_pgt
16616
16617@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16618
16619 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16620 {
16621+ pax_open_kernel();
16622 *pmdp = pmd;
16623+ pax_close_kernel();
16624 }
16625
16626 static inline void native_pmd_clear(pmd_t *pmd)
16627@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16628
16629 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16630 {
16631+ pax_open_kernel();
16632 *pudp = pud;
16633+ pax_close_kernel();
16634 }
16635
16636 static inline void native_pud_clear(pud_t *pud)
16637@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16638
16639 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16640 {
16641+ pax_open_kernel();
16642+ *pgdp = pgd;
16643+ pax_close_kernel();
16644+}
16645+
16646+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16647+{
16648 *pgdp = pgd;
16649 }
16650
16651diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16652index 2d88344..4679fc3 100644
16653--- a/arch/x86/include/asm/pgtable_64_types.h
16654+++ b/arch/x86/include/asm/pgtable_64_types.h
16655@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16656 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16657 #define MODULES_END _AC(0xffffffffff000000, UL)
16658 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16659+#define MODULES_EXEC_VADDR MODULES_VADDR
16660+#define MODULES_EXEC_END MODULES_END
16661+
16662+#define ktla_ktva(addr) (addr)
16663+#define ktva_ktla(addr) (addr)
16664
16665 #define EARLY_DYNAMIC_PAGE_TABLES 64
16666
16667diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16668index f4843e0..a2526f8 100644
16669--- a/arch/x86/include/asm/pgtable_types.h
16670+++ b/arch/x86/include/asm/pgtable_types.h
16671@@ -16,13 +16,12 @@
16672 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16673 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16674 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16675-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16676+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16677 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16678 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16679 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16680-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16681-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16682-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16683+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16684+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16685 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16686
16687 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16688@@ -40,7 +39,6 @@
16689 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16690 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16691 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16692-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16693 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16694 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16695 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16696@@ -84,8 +82,10 @@
16697
16698 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16699 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16700-#else
16701+#elif defined(CONFIG_KMEMCHECK)
16702 #define _PAGE_NX (_AT(pteval_t, 0))
16703+#else
16704+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16705 #endif
16706
16707 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16708@@ -143,6 +143,9 @@
16709 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16710 _PAGE_ACCESSED)
16711
16712+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16713+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16714+
16715 #define __PAGE_KERNEL_EXEC \
16716 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16717 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16718@@ -153,7 +156,7 @@
16719 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16720 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16721 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16722-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16723+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16724 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16725 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16726 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16727@@ -215,8 +218,8 @@
16728 * bits are combined, this will alow user to access the high address mapped
16729 * VDSO in the presence of CONFIG_COMPAT_VDSO
16730 */
16731-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16732-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16733+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16734+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16735 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16736 #endif
16737
16738@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16739 {
16740 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16741 }
16742+#endif
16743
16744+#if PAGETABLE_LEVELS == 3
16745+#include <asm-generic/pgtable-nopud.h>
16746+#endif
16747+
16748+#if PAGETABLE_LEVELS == 2
16749+#include <asm-generic/pgtable-nopmd.h>
16750+#endif
16751+
16752+#ifndef __ASSEMBLY__
16753 #if PAGETABLE_LEVELS > 3
16754 typedef struct { pudval_t pud; } pud_t;
16755
16756@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16757 return pud.pud;
16758 }
16759 #else
16760-#include <asm-generic/pgtable-nopud.h>
16761-
16762 static inline pudval_t native_pud_val(pud_t pud)
16763 {
16764 return native_pgd_val(pud.pgd);
16765@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16766 return pmd.pmd;
16767 }
16768 #else
16769-#include <asm-generic/pgtable-nopmd.h>
16770-
16771 static inline pmdval_t native_pmd_val(pmd_t pmd)
16772 {
16773 return native_pgd_val(pmd.pud.pgd);
16774@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16775
16776 extern pteval_t __supported_pte_mask;
16777 extern void set_nx(void);
16778-extern int nx_enabled;
16779
16780 #define pgprot_writecombine pgprot_writecombine
16781 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16782diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16783index 24cf5ae..4d9fa2d 100644
16784--- a/arch/x86/include/asm/processor.h
16785+++ b/arch/x86/include/asm/processor.h
16786@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16787 : "memory");
16788 }
16789
16790+/* invpcid (%rdx),%rax */
16791+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16792+
16793+#define INVPCID_SINGLE_ADDRESS 0UL
16794+#define INVPCID_SINGLE_CONTEXT 1UL
16795+#define INVPCID_ALL_GLOBAL 2UL
16796+#define INVPCID_ALL_MONGLOBAL 3UL
16797+
16798+#define PCID_KERNEL 0UL
16799+#define PCID_USER 1UL
16800+#define PCID_NOFLUSH (1UL << 63)
16801+
16802 static inline void load_cr3(pgd_t *pgdir)
16803 {
16804- write_cr3(__pa(pgdir));
16805+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16806 }
16807
16808 #ifdef CONFIG_X86_32
16809@@ -283,7 +295,7 @@ struct tss_struct {
16810
16811 } ____cacheline_aligned;
16812
16813-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16814+extern struct tss_struct init_tss[NR_CPUS];
16815
16816 /*
16817 * Save the original ist values for checking stack pointers during debugging
16818@@ -453,6 +465,7 @@ struct thread_struct {
16819 unsigned short ds;
16820 unsigned short fsindex;
16821 unsigned short gsindex;
16822+ unsigned short ss;
16823 #endif
16824 #ifdef CONFIG_X86_32
16825 unsigned long ip;
16826@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16827 extern unsigned long mmu_cr4_features;
16828 extern u32 *trampoline_cr4_features;
16829
16830-static inline void set_in_cr4(unsigned long mask)
16831-{
16832- unsigned long cr4;
16833-
16834- mmu_cr4_features |= mask;
16835- if (trampoline_cr4_features)
16836- *trampoline_cr4_features = mmu_cr4_features;
16837- cr4 = read_cr4();
16838- cr4 |= mask;
16839- write_cr4(cr4);
16840-}
16841-
16842-static inline void clear_in_cr4(unsigned long mask)
16843-{
16844- unsigned long cr4;
16845-
16846- mmu_cr4_features &= ~mask;
16847- if (trampoline_cr4_features)
16848- *trampoline_cr4_features = mmu_cr4_features;
16849- cr4 = read_cr4();
16850- cr4 &= ~mask;
16851- write_cr4(cr4);
16852-}
16853+extern void set_in_cr4(unsigned long mask);
16854+extern void clear_in_cr4(unsigned long mask);
16855
16856 typedef struct {
16857 unsigned long seg;
16858@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16859 */
16860 #define TASK_SIZE PAGE_OFFSET
16861 #define TASK_SIZE_MAX TASK_SIZE
16862+
16863+#ifdef CONFIG_PAX_SEGMEXEC
16864+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16865+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16866+#else
16867 #define STACK_TOP TASK_SIZE
16868-#define STACK_TOP_MAX STACK_TOP
16869+#endif
16870+
16871+#define STACK_TOP_MAX TASK_SIZE
16872
16873 #define INIT_THREAD { \
16874- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16875+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16876 .vm86_info = NULL, \
16877 .sysenter_cs = __KERNEL_CS, \
16878 .io_bitmap_ptr = NULL, \
16879@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16880 */
16881 #define INIT_TSS { \
16882 .x86_tss = { \
16883- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16884+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16885 .ss0 = __KERNEL_DS, \
16886 .ss1 = __KERNEL_CS, \
16887 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16888@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16889 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16890
16891 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16892-#define KSTK_TOP(info) \
16893-({ \
16894- unsigned long *__ptr = (unsigned long *)(info); \
16895- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16896-})
16897+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16898
16899 /*
16900 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16901@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16902 #define task_pt_regs(task) \
16903 ({ \
16904 struct pt_regs *__regs__; \
16905- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16906+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16907 __regs__ - 1; \
16908 })
16909
16910@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16911 /*
16912 * User space process size. 47bits minus one guard page.
16913 */
16914-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16915+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16916
16917 /* This decides where the kernel will search for a free chunk of vm
16918 * space during mmap's.
16919 */
16920 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16921- 0xc0000000 : 0xFFFFe000)
16922+ 0xc0000000 : 0xFFFFf000)
16923
16924 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16925 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16926@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16927 #define STACK_TOP_MAX TASK_SIZE_MAX
16928
16929 #define INIT_THREAD { \
16930- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16931+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16932 }
16933
16934 #define INIT_TSS { \
16935- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16936+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16937 }
16938
16939 /*
16940@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16941 */
16942 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16943
16944+#ifdef CONFIG_PAX_SEGMEXEC
16945+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16946+#endif
16947+
16948 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16949
16950 /* Get/set a process' ability to use the timestamp counter instruction */
16951@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16952 extern u16 amd_get_nb_id(int cpu);
16953
16954 struct aperfmperf {
16955- u64 aperf, mperf;
16956+ u64 aperf __intentional_overflow(0);
16957+ u64 mperf __intentional_overflow(0);
16958 };
16959
16960 static inline void get_aperfmperf(struct aperfmperf *am)
16961@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16962 return ratio;
16963 }
16964
16965-extern unsigned long arch_align_stack(unsigned long sp);
16966+#define arch_align_stack(x) ((x) & ~0xfUL)
16967 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16968
16969 void default_idle(void);
16970@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16971 #define xen_set_default_idle 0
16972 #endif
16973
16974-void stop_this_cpu(void *dummy);
16975+void stop_this_cpu(void *dummy) __noreturn;
16976 void df_debug(struct pt_regs *regs, long error_code);
16977 #endif /* _ASM_X86_PROCESSOR_H */
16978diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16979index 942a086..6c26446 100644
16980--- a/arch/x86/include/asm/ptrace.h
16981+++ b/arch/x86/include/asm/ptrace.h
16982@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16983 }
16984
16985 /*
16986- * user_mode_vm(regs) determines whether a register set came from user mode.
16987+ * user_mode(regs) determines whether a register set came from user mode.
16988 * This is true if V8086 mode was enabled OR if the register set was from
16989 * protected mode with RPL-3 CS value. This tricky test checks that with
16990 * one comparison. Many places in the kernel can bypass this full check
16991- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16992+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16993+ * be used.
16994 */
16995-static inline int user_mode(struct pt_regs *regs)
16996+static inline int user_mode_novm(struct pt_regs *regs)
16997 {
16998 #ifdef CONFIG_X86_32
16999 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17000 #else
17001- return !!(regs->cs & 3);
17002+ return !!(regs->cs & SEGMENT_RPL_MASK);
17003 #endif
17004 }
17005
17006-static inline int user_mode_vm(struct pt_regs *regs)
17007+static inline int user_mode(struct pt_regs *regs)
17008 {
17009 #ifdef CONFIG_X86_32
17010 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17011 USER_RPL;
17012 #else
17013- return user_mode(regs);
17014+ return user_mode_novm(regs);
17015 #endif
17016 }
17017
17018@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17019 #ifdef CONFIG_X86_64
17020 static inline bool user_64bit_mode(struct pt_regs *regs)
17021 {
17022+ unsigned long cs = regs->cs & 0xffff;
17023 #ifndef CONFIG_PARAVIRT
17024 /*
17025 * On non-paravirt systems, this is the only long mode CPL 3
17026 * selector. We do not allow long mode selectors in the LDT.
17027 */
17028- return regs->cs == __USER_CS;
17029+ return cs == __USER_CS;
17030 #else
17031 /* Headers are too twisted for this to go in paravirt.h. */
17032- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17033+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17034 #endif
17035 }
17036
17037@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17038 * Traps from the kernel do not save sp and ss.
17039 * Use the helper function to retrieve sp.
17040 */
17041- if (offset == offsetof(struct pt_regs, sp) &&
17042- regs->cs == __KERNEL_CS)
17043- return kernel_stack_pointer(regs);
17044+ if (offset == offsetof(struct pt_regs, sp)) {
17045+ unsigned long cs = regs->cs & 0xffff;
17046+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17047+ return kernel_stack_pointer(regs);
17048+ }
17049 #endif
17050 return *(unsigned long *)((unsigned long)regs + offset);
17051 }
17052diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17053index 9c6b890..5305f53 100644
17054--- a/arch/x86/include/asm/realmode.h
17055+++ b/arch/x86/include/asm/realmode.h
17056@@ -22,16 +22,14 @@ struct real_mode_header {
17057 #endif
17058 /* APM/BIOS reboot */
17059 u32 machine_real_restart_asm;
17060-#ifdef CONFIG_X86_64
17061 u32 machine_real_restart_seg;
17062-#endif
17063 };
17064
17065 /* This must match data at trampoline_32/64.S */
17066 struct trampoline_header {
17067 #ifdef CONFIG_X86_32
17068 u32 start;
17069- u16 gdt_pad;
17070+ u16 boot_cs;
17071 u16 gdt_limit;
17072 u32 gdt_base;
17073 #else
17074diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17075index a82c4f1..ac45053 100644
17076--- a/arch/x86/include/asm/reboot.h
17077+++ b/arch/x86/include/asm/reboot.h
17078@@ -6,13 +6,13 @@
17079 struct pt_regs;
17080
17081 struct machine_ops {
17082- void (*restart)(char *cmd);
17083- void (*halt)(void);
17084- void (*power_off)(void);
17085+ void (* __noreturn restart)(char *cmd);
17086+ void (* __noreturn halt)(void);
17087+ void (* __noreturn power_off)(void);
17088 void (*shutdown)(void);
17089 void (*crash_shutdown)(struct pt_regs *);
17090- void (*emergency_restart)(void);
17091-};
17092+ void (* __noreturn emergency_restart)(void);
17093+} __no_const;
17094
17095 extern struct machine_ops machine_ops;
17096
17097diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17098index cad82c9..2e5c5c1 100644
17099--- a/arch/x86/include/asm/rwsem.h
17100+++ b/arch/x86/include/asm/rwsem.h
17101@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17102 {
17103 asm volatile("# beginning down_read\n\t"
17104 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17105+
17106+#ifdef CONFIG_PAX_REFCOUNT
17107+ "jno 0f\n"
17108+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17109+ "int $4\n0:\n"
17110+ _ASM_EXTABLE(0b, 0b)
17111+#endif
17112+
17113 /* adds 0x00000001 */
17114 " jns 1f\n"
17115 " call call_rwsem_down_read_failed\n"
17116@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17117 "1:\n\t"
17118 " mov %1,%2\n\t"
17119 " add %3,%2\n\t"
17120+
17121+#ifdef CONFIG_PAX_REFCOUNT
17122+ "jno 0f\n"
17123+ "sub %3,%2\n"
17124+ "int $4\n0:\n"
17125+ _ASM_EXTABLE(0b, 0b)
17126+#endif
17127+
17128 " jle 2f\n\t"
17129 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17130 " jnz 1b\n\t"
17131@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17132 long tmp;
17133 asm volatile("# beginning down_write\n\t"
17134 LOCK_PREFIX " xadd %1,(%2)\n\t"
17135+
17136+#ifdef CONFIG_PAX_REFCOUNT
17137+ "jno 0f\n"
17138+ "mov %1,(%2)\n"
17139+ "int $4\n0:\n"
17140+ _ASM_EXTABLE(0b, 0b)
17141+#endif
17142+
17143 /* adds 0xffff0001, returns the old value */
17144 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17145 /* was the active mask 0 before? */
17146@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17147 long tmp;
17148 asm volatile("# beginning __up_read\n\t"
17149 LOCK_PREFIX " xadd %1,(%2)\n\t"
17150+
17151+#ifdef CONFIG_PAX_REFCOUNT
17152+ "jno 0f\n"
17153+ "mov %1,(%2)\n"
17154+ "int $4\n0:\n"
17155+ _ASM_EXTABLE(0b, 0b)
17156+#endif
17157+
17158 /* subtracts 1, returns the old value */
17159 " jns 1f\n\t"
17160 " call call_rwsem_wake\n" /* expects old value in %edx */
17161@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17162 long tmp;
17163 asm volatile("# beginning __up_write\n\t"
17164 LOCK_PREFIX " xadd %1,(%2)\n\t"
17165+
17166+#ifdef CONFIG_PAX_REFCOUNT
17167+ "jno 0f\n"
17168+ "mov %1,(%2)\n"
17169+ "int $4\n0:\n"
17170+ _ASM_EXTABLE(0b, 0b)
17171+#endif
17172+
17173 /* subtracts 0xffff0001, returns the old value */
17174 " jns 1f\n\t"
17175 " call call_rwsem_wake\n" /* expects old value in %edx */
17176@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17177 {
17178 asm volatile("# beginning __downgrade_write\n\t"
17179 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17180+
17181+#ifdef CONFIG_PAX_REFCOUNT
17182+ "jno 0f\n"
17183+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17184+ "int $4\n0:\n"
17185+ _ASM_EXTABLE(0b, 0b)
17186+#endif
17187+
17188 /*
17189 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17190 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17191@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17192 */
17193 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17194 {
17195- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17196+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17197+
17198+#ifdef CONFIG_PAX_REFCOUNT
17199+ "jno 0f\n"
17200+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17201+ "int $4\n0:\n"
17202+ _ASM_EXTABLE(0b, 0b)
17203+#endif
17204+
17205 : "+m" (sem->count)
17206 : "er" (delta));
17207 }
17208@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17209 */
17210 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17211 {
17212- return delta + xadd(&sem->count, delta);
17213+ return delta + xadd_check_overflow(&sem->count, delta);
17214 }
17215
17216 #endif /* __KERNEL__ */
17217diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17218index c48a950..bc40804 100644
17219--- a/arch/x86/include/asm/segment.h
17220+++ b/arch/x86/include/asm/segment.h
17221@@ -64,10 +64,15 @@
17222 * 26 - ESPFIX small SS
17223 * 27 - per-cpu [ offset to per-cpu data area ]
17224 * 28 - stack_canary-20 [ for stack protector ]
17225- * 29 - unused
17226- * 30 - unused
17227+ * 29 - PCI BIOS CS
17228+ * 30 - PCI BIOS DS
17229 * 31 - TSS for double fault handler
17230 */
17231+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17232+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17233+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17234+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17235+
17236 #define GDT_ENTRY_TLS_MIN 6
17237 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17238
17239@@ -79,6 +84,8 @@
17240
17241 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17242
17243+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17244+
17245 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17246
17247 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17248@@ -104,6 +111,12 @@
17249 #define __KERNEL_STACK_CANARY 0
17250 #endif
17251
17252+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17253+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17254+
17255+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17256+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17257+
17258 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17259
17260 /*
17261@@ -141,7 +154,7 @@
17262 */
17263
17264 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17265-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17266+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17267
17268
17269 #else
17270@@ -165,6 +178,8 @@
17271 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17272 #define __USER32_DS __USER_DS
17273
17274+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17275+
17276 #define GDT_ENTRY_TSS 8 /* needs two entries */
17277 #define GDT_ENTRY_LDT 10 /* needs two entries */
17278 #define GDT_ENTRY_TLS_MIN 12
17279@@ -173,6 +188,8 @@
17280 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17281 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17282
17283+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17284+
17285 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17286 #define FS_TLS 0
17287 #define GS_TLS 1
17288@@ -180,12 +197,14 @@
17289 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17290 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17291
17292-#define GDT_ENTRIES 16
17293+#define GDT_ENTRIES 17
17294
17295 #endif
17296
17297 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17298+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17299 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17300+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17301 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17302 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17303 #ifndef CONFIG_PARAVIRT
17304@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17305 {
17306 unsigned long __limit;
17307 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17308- return __limit + 1;
17309+ return __limit;
17310 }
17311
17312 #endif /* !__ASSEMBLY__ */
17313diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17314index 8d3120f..352b440 100644
17315--- a/arch/x86/include/asm/smap.h
17316+++ b/arch/x86/include/asm/smap.h
17317@@ -25,11 +25,40 @@
17318
17319 #include <asm/alternative-asm.h>
17320
17321+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17322+#define ASM_PAX_OPEN_USERLAND \
17323+ 661: jmp 663f; \
17324+ .pushsection .altinstr_replacement, "a" ; \
17325+ 662: pushq %rax; nop; \
17326+ .popsection ; \
17327+ .pushsection .altinstructions, "a" ; \
17328+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17329+ .popsection ; \
17330+ call __pax_open_userland; \
17331+ popq %rax; \
17332+ 663:
17333+
17334+#define ASM_PAX_CLOSE_USERLAND \
17335+ 661: jmp 663f; \
17336+ .pushsection .altinstr_replacement, "a" ; \
17337+ 662: pushq %rax; nop; \
17338+ .popsection; \
17339+ .pushsection .altinstructions, "a" ; \
17340+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17341+ .popsection; \
17342+ call __pax_close_userland; \
17343+ popq %rax; \
17344+ 663:
17345+#else
17346+#define ASM_PAX_OPEN_USERLAND
17347+#define ASM_PAX_CLOSE_USERLAND
17348+#endif
17349+
17350 #ifdef CONFIG_X86_SMAP
17351
17352 #define ASM_CLAC \
17353 661: ASM_NOP3 ; \
17354- .pushsection .altinstr_replacement, "ax" ; \
17355+ .pushsection .altinstr_replacement, "a" ; \
17356 662: __ASM_CLAC ; \
17357 .popsection ; \
17358 .pushsection .altinstructions, "a" ; \
17359@@ -38,7 +67,7 @@
17360
17361 #define ASM_STAC \
17362 661: ASM_NOP3 ; \
17363- .pushsection .altinstr_replacement, "ax" ; \
17364+ .pushsection .altinstr_replacement, "a" ; \
17365 662: __ASM_STAC ; \
17366 .popsection ; \
17367 .pushsection .altinstructions, "a" ; \
17368@@ -56,6 +85,37 @@
17369
17370 #include <asm/alternative.h>
17371
17372+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17373+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17374+
17375+extern void __pax_open_userland(void);
17376+static __always_inline unsigned long pax_open_userland(void)
17377+{
17378+
17379+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17380+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17381+ :
17382+ : [open] "i" (__pax_open_userland)
17383+ : "memory", "rax");
17384+#endif
17385+
17386+ return 0;
17387+}
17388+
17389+extern void __pax_close_userland(void);
17390+static __always_inline unsigned long pax_close_userland(void)
17391+{
17392+
17393+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17394+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17395+ :
17396+ : [close] "i" (__pax_close_userland)
17397+ : "memory", "rax");
17398+#endif
17399+
17400+ return 0;
17401+}
17402+
17403 #ifdef CONFIG_X86_SMAP
17404
17405 static __always_inline void clac(void)
17406diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17407index 4137890..03fa172 100644
17408--- a/arch/x86/include/asm/smp.h
17409+++ b/arch/x86/include/asm/smp.h
17410@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17411 /* cpus sharing the last level cache: */
17412 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17413 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17414-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17415+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17416
17417 static inline struct cpumask *cpu_sibling_mask(int cpu)
17418 {
17419@@ -79,7 +79,7 @@ struct smp_ops {
17420
17421 void (*send_call_func_ipi)(const struct cpumask *mask);
17422 void (*send_call_func_single_ipi)(int cpu);
17423-};
17424+} __no_const;
17425
17426 /* Globals due to paravirt */
17427 extern void set_cpu_sibling_map(int cpu);
17428@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17429 extern int safe_smp_processor_id(void);
17430
17431 #elif defined(CONFIG_X86_64_SMP)
17432-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17433-
17434-#define stack_smp_processor_id() \
17435-({ \
17436- struct thread_info *ti; \
17437- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17438- ti->cpu; \
17439-})
17440+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17441+#define stack_smp_processor_id() raw_smp_processor_id()
17442 #define safe_smp_processor_id() smp_processor_id()
17443
17444 #endif
17445diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17446index e3ddd7d..3611fce 100644
17447--- a/arch/x86/include/asm/spinlock.h
17448+++ b/arch/x86/include/asm/spinlock.h
17449@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17450 static inline void arch_read_lock(arch_rwlock_t *rw)
17451 {
17452 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17453+
17454+#ifdef CONFIG_PAX_REFCOUNT
17455+ "jno 0f\n"
17456+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17457+ "int $4\n0:\n"
17458+ _ASM_EXTABLE(0b, 0b)
17459+#endif
17460+
17461 "jns 1f\n"
17462 "call __read_lock_failed\n\t"
17463 "1:\n"
17464@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17465 static inline void arch_write_lock(arch_rwlock_t *rw)
17466 {
17467 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17468+
17469+#ifdef CONFIG_PAX_REFCOUNT
17470+ "jno 0f\n"
17471+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17472+ "int $4\n0:\n"
17473+ _ASM_EXTABLE(0b, 0b)
17474+#endif
17475+
17476 "jz 1f\n"
17477 "call __write_lock_failed\n\t"
17478 "1:\n"
17479@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17480
17481 static inline void arch_read_unlock(arch_rwlock_t *rw)
17482 {
17483- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17484+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17485+
17486+#ifdef CONFIG_PAX_REFCOUNT
17487+ "jno 0f\n"
17488+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17489+ "int $4\n0:\n"
17490+ _ASM_EXTABLE(0b, 0b)
17491+#endif
17492+
17493 :"+m" (rw->lock) : : "memory");
17494 }
17495
17496 static inline void arch_write_unlock(arch_rwlock_t *rw)
17497 {
17498- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17499+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17500+
17501+#ifdef CONFIG_PAX_REFCOUNT
17502+ "jno 0f\n"
17503+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17504+ "int $4\n0:\n"
17505+ _ASM_EXTABLE(0b, 0b)
17506+#endif
17507+
17508 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17509 }
17510
17511diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17512index 6a99859..03cb807 100644
17513--- a/arch/x86/include/asm/stackprotector.h
17514+++ b/arch/x86/include/asm/stackprotector.h
17515@@ -47,7 +47,7 @@
17516 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17517 */
17518 #define GDT_STACK_CANARY_INIT \
17519- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17520+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17521
17522 /*
17523 * Initialize the stackprotector canary value.
17524@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17525
17526 static inline void load_stack_canary_segment(void)
17527 {
17528-#ifdef CONFIG_X86_32
17529+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17530 asm volatile ("mov %0, %%gs" : : "r" (0));
17531 #endif
17532 }
17533diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17534index 70bbe39..4ae2bd4 100644
17535--- a/arch/x86/include/asm/stacktrace.h
17536+++ b/arch/x86/include/asm/stacktrace.h
17537@@ -11,28 +11,20 @@
17538
17539 extern int kstack_depth_to_print;
17540
17541-struct thread_info;
17542+struct task_struct;
17543 struct stacktrace_ops;
17544
17545-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17546- unsigned long *stack,
17547- unsigned long bp,
17548- const struct stacktrace_ops *ops,
17549- void *data,
17550- unsigned long *end,
17551- int *graph);
17552+typedef unsigned long walk_stack_t(struct task_struct *task,
17553+ void *stack_start,
17554+ unsigned long *stack,
17555+ unsigned long bp,
17556+ const struct stacktrace_ops *ops,
17557+ void *data,
17558+ unsigned long *end,
17559+ int *graph);
17560
17561-extern unsigned long
17562-print_context_stack(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-
17567-extern unsigned long
17568-print_context_stack_bp(struct thread_info *tinfo,
17569- unsigned long *stack, unsigned long bp,
17570- const struct stacktrace_ops *ops, void *data,
17571- unsigned long *end, int *graph);
17572+extern walk_stack_t print_context_stack;
17573+extern walk_stack_t print_context_stack_bp;
17574
17575 /* Generic stack tracer with callbacks */
17576
17577@@ -40,7 +32,7 @@ struct stacktrace_ops {
17578 void (*address)(void *data, unsigned long address, int reliable);
17579 /* On negative return stop dumping */
17580 int (*stack)(void *data, char *name);
17581- walk_stack_t walk_stack;
17582+ walk_stack_t *walk_stack;
17583 };
17584
17585 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17586diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17587index 4ec45b3..a4f0a8a 100644
17588--- a/arch/x86/include/asm/switch_to.h
17589+++ b/arch/x86/include/asm/switch_to.h
17590@@ -108,7 +108,7 @@ do { \
17591 "call __switch_to\n\t" \
17592 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17593 __switch_canary \
17594- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17595+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17596 "movq %%rax,%%rdi\n\t" \
17597 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17598 "jnz ret_from_fork\n\t" \
17599@@ -119,7 +119,7 @@ do { \
17600 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17601 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17602 [_tif_fork] "i" (_TIF_FORK), \
17603- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17604+ [thread_info] "m" (current_tinfo), \
17605 [current_task] "m" (current_task) \
17606 __switch_canary_iparam \
17607 : "memory", "cc" __EXTRA_CLOBBER)
17608diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17609index 2781119..618b59b 100644
17610--- a/arch/x86/include/asm/thread_info.h
17611+++ b/arch/x86/include/asm/thread_info.h
17612@@ -10,6 +10,7 @@
17613 #include <linux/compiler.h>
17614 #include <asm/page.h>
17615 #include <asm/types.h>
17616+#include <asm/percpu.h>
17617
17618 /*
17619 * low level task data that entry.S needs immediate access to
17620@@ -23,7 +24,6 @@ struct exec_domain;
17621 #include <linux/atomic.h>
17622
17623 struct thread_info {
17624- struct task_struct *task; /* main task structure */
17625 struct exec_domain *exec_domain; /* execution domain */
17626 __u32 flags; /* low level flags */
17627 __u32 status; /* thread synchronous flags */
17628@@ -33,19 +33,13 @@ struct thread_info {
17629 mm_segment_t addr_limit;
17630 struct restart_block restart_block;
17631 void __user *sysenter_return;
17632-#ifdef CONFIG_X86_32
17633- unsigned long previous_esp; /* ESP of the previous stack in
17634- case of nested (IRQ) stacks
17635- */
17636- __u8 supervisor_stack[0];
17637-#endif
17638+ unsigned long lowest_stack;
17639 unsigned int sig_on_uaccess_error:1;
17640 unsigned int uaccess_err:1; /* uaccess failed */
17641 };
17642
17643-#define INIT_THREAD_INFO(tsk) \
17644+#define INIT_THREAD_INFO \
17645 { \
17646- .task = &tsk, \
17647 .exec_domain = &default_exec_domain, \
17648 .flags = 0, \
17649 .cpu = 0, \
17650@@ -56,7 +50,7 @@ struct thread_info {
17651 }, \
17652 }
17653
17654-#define init_thread_info (init_thread_union.thread_info)
17655+#define init_thread_info (init_thread_union.stack)
17656 #define init_stack (init_thread_union.stack)
17657
17658 #else /* !__ASSEMBLY__ */
17659@@ -96,6 +90,7 @@ struct thread_info {
17660 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17661 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17662 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17663+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17664
17665 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17666 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17667@@ -119,17 +114,18 @@ struct thread_info {
17668 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17669 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17670 #define _TIF_X32 (1 << TIF_X32)
17671+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17672
17673 /* work to do in syscall_trace_enter() */
17674 #define _TIF_WORK_SYSCALL_ENTRY \
17675 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17676 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17677- _TIF_NOHZ)
17678+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17679
17680 /* work to do in syscall_trace_leave() */
17681 #define _TIF_WORK_SYSCALL_EXIT \
17682 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17683- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17684+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17685
17686 /* work to do on interrupt/exception return */
17687 #define _TIF_WORK_MASK \
17688@@ -140,7 +136,7 @@ struct thread_info {
17689 /* work to do on any return to user space */
17690 #define _TIF_ALLWORK_MASK \
17691 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17692- _TIF_NOHZ)
17693+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17694
17695 /* Only used for 64 bit */
17696 #define _TIF_DO_NOTIFY_MASK \
17697@@ -156,45 +152,40 @@ struct thread_info {
17698
17699 #define PREEMPT_ACTIVE 0x10000000
17700
17701-#ifdef CONFIG_X86_32
17702-
17703-#define STACK_WARN (THREAD_SIZE/8)
17704-/*
17705- * macros/functions for gaining access to the thread information structure
17706- *
17707- * preempt_count needs to be 1 initially, until the scheduler is functional.
17708- */
17709-#ifndef __ASSEMBLY__
17710-
17711-
17712-/* how to get the current stack pointer from C */
17713-register unsigned long current_stack_pointer asm("esp") __used;
17714-
17715-/* how to get the thread information struct from C */
17716-static inline struct thread_info *current_thread_info(void)
17717-{
17718- return (struct thread_info *)
17719- (current_stack_pointer & ~(THREAD_SIZE - 1));
17720-}
17721-
17722-#else /* !__ASSEMBLY__ */
17723-
17724+#ifdef __ASSEMBLY__
17725 /* how to get the thread information struct from ASM */
17726 #define GET_THREAD_INFO(reg) \
17727- movl $-THREAD_SIZE, reg; \
17728- andl %esp, reg
17729+ mov PER_CPU_VAR(current_tinfo), reg
17730
17731 /* use this one if reg already contains %esp */
17732-#define GET_THREAD_INFO_WITH_ESP(reg) \
17733- andl $-THREAD_SIZE, reg
17734+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17735+#else
17736+/* how to get the thread information struct from C */
17737+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17738+
17739+static __always_inline struct thread_info *current_thread_info(void)
17740+{
17741+ return this_cpu_read_stable(current_tinfo);
17742+}
17743+#endif
17744+
17745+#ifdef CONFIG_X86_32
17746+
17747+#define STACK_WARN (THREAD_SIZE/8)
17748+/*
17749+ * macros/functions for gaining access to the thread information structure
17750+ *
17751+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17752+ */
17753+#ifndef __ASSEMBLY__
17754+
17755+/* how to get the current stack pointer from C */
17756+register unsigned long current_stack_pointer asm("esp") __used;
17757
17758 #endif
17759
17760 #else /* X86_32 */
17761
17762-#include <asm/percpu.h>
17763-#define KERNEL_STACK_OFFSET (5*8)
17764-
17765 /*
17766 * macros/functions for gaining access to the thread information structure
17767 * preempt_count needs to be 1 initially, until the scheduler is functional.
17768@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17769 #ifndef __ASSEMBLY__
17770 DECLARE_PER_CPU(unsigned long, kernel_stack);
17771
17772-static inline struct thread_info *current_thread_info(void)
17773-{
17774- struct thread_info *ti;
17775- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17776- KERNEL_STACK_OFFSET - THREAD_SIZE);
17777- return ti;
17778-}
17779-
17780-#else /* !__ASSEMBLY__ */
17781-
17782-/* how to get the thread information struct from ASM */
17783-#define GET_THREAD_INFO(reg) \
17784- movq PER_CPU_VAR(kernel_stack),reg ; \
17785- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17786-
17787-/*
17788- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17789- * a certain register (to be used in assembler memory operands).
17790- */
17791-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17792-
17793+/* how to get the current stack pointer from C */
17794+register unsigned long current_stack_pointer asm("rsp") __used;
17795 #endif
17796
17797 #endif /* !X86_32 */
17798@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17799 extern void arch_task_cache_init(void);
17800 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17801 extern void arch_release_task_struct(struct task_struct *tsk);
17802+
17803+#define __HAVE_THREAD_FUNCTIONS
17804+#define task_thread_info(task) (&(task)->tinfo)
17805+#define task_stack_page(task) ((task)->stack)
17806+#define setup_thread_stack(p, org) do {} while (0)
17807+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17808+
17809 #endif
17810 #endif /* _ASM_X86_THREAD_INFO_H */
17811diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17812index cf51200..63ff068 100644
17813--- a/arch/x86/include/asm/tlbflush.h
17814+++ b/arch/x86/include/asm/tlbflush.h
17815@@ -17,18 +17,44 @@
17816
17817 static inline void __native_flush_tlb(void)
17818 {
17819+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17820+ u64 descriptor[2];
17821+
17822+ descriptor[0] = PCID_KERNEL;
17823+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17824+ return;
17825+ }
17826+
17827+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17828+ if (static_cpu_has(X86_FEATURE_PCID)) {
17829+ unsigned int cpu = raw_get_cpu();
17830+
17831+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17832+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17833+ raw_put_cpu_no_resched();
17834+ return;
17835+ }
17836+#endif
17837+
17838 native_write_cr3(native_read_cr3());
17839 }
17840
17841 static inline void __native_flush_tlb_global_irq_disabled(void)
17842 {
17843- unsigned long cr4;
17844+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17845+ u64 descriptor[2];
17846
17847- cr4 = native_read_cr4();
17848- /* clear PGE */
17849- native_write_cr4(cr4 & ~X86_CR4_PGE);
17850- /* write old PGE again and flush TLBs */
17851- native_write_cr4(cr4);
17852+ descriptor[0] = PCID_KERNEL;
17853+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17854+ } else {
17855+ unsigned long cr4;
17856+
17857+ cr4 = native_read_cr4();
17858+ /* clear PGE */
17859+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17860+ /* write old PGE again and flush TLBs */
17861+ native_write_cr4(cr4);
17862+ }
17863 }
17864
17865 static inline void __native_flush_tlb_global(void)
17866@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17867
17868 static inline void __native_flush_tlb_single(unsigned long addr)
17869 {
17870+
17871+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17872+ u64 descriptor[2];
17873+
17874+ descriptor[0] = PCID_KERNEL;
17875+ descriptor[1] = addr;
17876+
17877+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17878+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17879+ if (addr < TASK_SIZE_MAX)
17880+ descriptor[1] += pax_user_shadow_base;
17881+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17882+ }
17883+
17884+ descriptor[0] = PCID_USER;
17885+ descriptor[1] = addr;
17886+#endif
17887+
17888+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17889+ return;
17890+ }
17891+
17892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17893+ if (static_cpu_has(X86_FEATURE_PCID)) {
17894+ unsigned int cpu = raw_get_cpu();
17895+
17896+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17897+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17898+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17899+ raw_put_cpu_no_resched();
17900+
17901+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17902+ addr += pax_user_shadow_base;
17903+ }
17904+#endif
17905+
17906 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17907 }
17908
17909diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17910index 5ee2687..74590b9 100644
17911--- a/arch/x86/include/asm/uaccess.h
17912+++ b/arch/x86/include/asm/uaccess.h
17913@@ -7,6 +7,7 @@
17914 #include <linux/compiler.h>
17915 #include <linux/thread_info.h>
17916 #include <linux/string.h>
17917+#include <linux/sched.h>
17918 #include <asm/asm.h>
17919 #include <asm/page.h>
17920 #include <asm/smap.h>
17921@@ -29,7 +30,12 @@
17922
17923 #define get_ds() (KERNEL_DS)
17924 #define get_fs() (current_thread_info()->addr_limit)
17925+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17926+void __set_fs(mm_segment_t x);
17927+void set_fs(mm_segment_t x);
17928+#else
17929 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17930+#endif
17931
17932 #define segment_eq(a, b) ((a).seg == (b).seg)
17933
17934@@ -77,8 +83,33 @@
17935 * checks that the pointer is in the user space range - after calling
17936 * this function, memory access functions may still return -EFAULT.
17937 */
17938-#define access_ok(type, addr, size) \
17939- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17940+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17941+#define access_ok(type, addr, size) \
17942+({ \
17943+ long __size = size; \
17944+ unsigned long __addr = (unsigned long)addr; \
17945+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17946+ unsigned long __end_ao = __addr + __size - 1; \
17947+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17948+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17949+ while(__addr_ao <= __end_ao) { \
17950+ char __c_ao; \
17951+ __addr_ao += PAGE_SIZE; \
17952+ if (__size > PAGE_SIZE) \
17953+ cond_resched(); \
17954+ if (__get_user(__c_ao, (char __user *)__addr)) \
17955+ break; \
17956+ if (type != VERIFY_WRITE) { \
17957+ __addr = __addr_ao; \
17958+ continue; \
17959+ } \
17960+ if (__put_user(__c_ao, (char __user *)__addr)) \
17961+ break; \
17962+ __addr = __addr_ao; \
17963+ } \
17964+ } \
17965+ __ret_ao; \
17966+})
17967
17968 /*
17969 * The exception table consists of pairs of addresses relative to the
17970@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17971 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17972 __chk_user_ptr(ptr); \
17973 might_fault(); \
17974+ pax_open_userland(); \
17975 asm volatile("call __get_user_%P3" \
17976 : "=a" (__ret_gu), "=r" (__val_gu) \
17977 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17978 (x) = (__typeof__(*(ptr))) __val_gu; \
17979+ pax_close_userland(); \
17980 __ret_gu; \
17981 })
17982
17983@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17984 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17985 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17986
17987-
17988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17989+#define __copyuser_seg "gs;"
17990+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17991+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17992+#else
17993+#define __copyuser_seg
17994+#define __COPYUSER_SET_ES
17995+#define __COPYUSER_RESTORE_ES
17996+#endif
17997
17998 #ifdef CONFIG_X86_32
17999 #define __put_user_asm_u64(x, addr, err, errret) \
18000 asm volatile(ASM_STAC "\n" \
18001- "1: movl %%eax,0(%2)\n" \
18002- "2: movl %%edx,4(%2)\n" \
18003+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18004+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18005 "3: " ASM_CLAC "\n" \
18006 ".section .fixup,\"ax\"\n" \
18007 "4: movl %3,%0\n" \
18008@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18009
18010 #define __put_user_asm_ex_u64(x, addr) \
18011 asm volatile(ASM_STAC "\n" \
18012- "1: movl %%eax,0(%1)\n" \
18013- "2: movl %%edx,4(%1)\n" \
18014+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18015+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18016 "3: " ASM_CLAC "\n" \
18017 _ASM_EXTABLE_EX(1b, 2b) \
18018 _ASM_EXTABLE_EX(2b, 3b) \
18019@@ -246,7 +287,8 @@ extern void __put_user_8(void);
18020 __typeof__(*(ptr)) __pu_val; \
18021 __chk_user_ptr(ptr); \
18022 might_fault(); \
18023- __pu_val = x; \
18024+ __pu_val = (x); \
18025+ pax_open_userland(); \
18026 switch (sizeof(*(ptr))) { \
18027 case 1: \
18028 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18029@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18030 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18031 break; \
18032 } \
18033+ pax_close_userland(); \
18034 __ret_pu; \
18035 })
18036
18037@@ -344,8 +387,10 @@ do { \
18038 } while (0)
18039
18040 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18041+do { \
18042+ pax_open_userland(); \
18043 asm volatile(ASM_STAC "\n" \
18044- "1: mov"itype" %2,%"rtype"1\n" \
18045+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18046 "2: " ASM_CLAC "\n" \
18047 ".section .fixup,\"ax\"\n" \
18048 "3: mov %3,%0\n" \
18049@@ -353,8 +398,10 @@ do { \
18050 " jmp 2b\n" \
18051 ".previous\n" \
18052 _ASM_EXTABLE(1b, 3b) \
18053- : "=r" (err), ltype(x) \
18054- : "m" (__m(addr)), "i" (errret), "0" (err))
18055+ : "=r" (err), ltype (x) \
18056+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18057+ pax_close_userland(); \
18058+} while (0)
18059
18060 #define __get_user_size_ex(x, ptr, size) \
18061 do { \
18062@@ -378,7 +425,7 @@ do { \
18063 } while (0)
18064
18065 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18066- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18067+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18068 "2:\n" \
18069 _ASM_EXTABLE_EX(1b, 2b) \
18070 : ltype(x) : "m" (__m(addr)))
18071@@ -395,13 +442,24 @@ do { \
18072 int __gu_err; \
18073 unsigned long __gu_val; \
18074 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18075- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18076+ (x) = (__typeof__(*(ptr)))__gu_val; \
18077 __gu_err; \
18078 })
18079
18080 /* FIXME: this hack is definitely wrong -AK */
18081 struct __large_struct { unsigned long buf[100]; };
18082-#define __m(x) (*(struct __large_struct __user *)(x))
18083+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18084+#define ____m(x) \
18085+({ \
18086+ unsigned long ____x = (unsigned long)(x); \
18087+ if (____x < pax_user_shadow_base) \
18088+ ____x += pax_user_shadow_base; \
18089+ (typeof(x))____x; \
18090+})
18091+#else
18092+#define ____m(x) (x)
18093+#endif
18094+#define __m(x) (*(struct __large_struct __user *)____m(x))
18095
18096 /*
18097 * Tell gcc we read from memory instead of writing: this is because
18098@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18099 * aliasing issues.
18100 */
18101 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18102+do { \
18103+ pax_open_userland(); \
18104 asm volatile(ASM_STAC "\n" \
18105- "1: mov"itype" %"rtype"1,%2\n" \
18106+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18107 "2: " ASM_CLAC "\n" \
18108 ".section .fixup,\"ax\"\n" \
18109 "3: mov %3,%0\n" \
18110@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18111 ".previous\n" \
18112 _ASM_EXTABLE(1b, 3b) \
18113 : "=r"(err) \
18114- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18115+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18116+ pax_close_userland(); \
18117+} while (0)
18118
18119 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18120- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18121+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18122 "2:\n" \
18123 _ASM_EXTABLE_EX(1b, 2b) \
18124 : : ltype(x), "m" (__m(addr)))
18125@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18126 */
18127 #define uaccess_try do { \
18128 current_thread_info()->uaccess_err = 0; \
18129+ pax_open_userland(); \
18130 stac(); \
18131 barrier();
18132
18133 #define uaccess_catch(err) \
18134 clac(); \
18135+ pax_close_userland(); \
18136 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18137 } while (0)
18138
18139@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18140 * On error, the variable @x is set to zero.
18141 */
18142
18143+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18144+#define __get_user(x, ptr) get_user((x), (ptr))
18145+#else
18146 #define __get_user(x, ptr) \
18147 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18148+#endif
18149
18150 /**
18151 * __put_user: - Write a simple value into user space, with less checking.
18152@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18153 * Returns zero on success, or -EFAULT on error.
18154 */
18155
18156+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18157+#define __put_user(x, ptr) put_user((x), (ptr))
18158+#else
18159 #define __put_user(x, ptr) \
18160 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18161+#endif
18162
18163 #define __get_user_unaligned __get_user
18164 #define __put_user_unaligned __put_user
18165@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18166 #define get_user_ex(x, ptr) do { \
18167 unsigned long __gue_val; \
18168 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18169- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18170+ (x) = (__typeof__(*(ptr)))__gue_val; \
18171 } while (0)
18172
18173 #define put_user_try uaccess_try
18174@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18175 extern __must_check long strlen_user(const char __user *str);
18176 extern __must_check long strnlen_user(const char __user *str, long n);
18177
18178-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18179-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18180+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18181+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18182
18183 /*
18184 * movsl can be slow when source and dest are not both 8-byte aligned
18185diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18186index 7f760a9..04b1c65 100644
18187--- a/arch/x86/include/asm/uaccess_32.h
18188+++ b/arch/x86/include/asm/uaccess_32.h
18189@@ -11,15 +11,15 @@
18190 #include <asm/page.h>
18191
18192 unsigned long __must_check __copy_to_user_ll
18193- (void __user *to, const void *from, unsigned long n);
18194+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18195 unsigned long __must_check __copy_from_user_ll
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_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 unsigned long __must_check __copy_from_user_ll_nocache
18202- (void *to, const void __user *from, unsigned long n);
18203+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18204 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18205- (void *to, const void __user *from, unsigned long n);
18206+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18207
18208 /**
18209 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18210@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18211 static __always_inline unsigned long __must_check
18212 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18213 {
18214+ if ((long)n < 0)
18215+ return n;
18216+
18217+ check_object_size(from, n, true);
18218+
18219 if (__builtin_constant_p(n)) {
18220 unsigned long ret;
18221
18222@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18223 __copy_to_user(void __user *to, const void *from, unsigned long n)
18224 {
18225 might_fault();
18226+
18227 return __copy_to_user_inatomic(to, from, n);
18228 }
18229
18230 static __always_inline unsigned long
18231 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18232 {
18233+ if ((long)n < 0)
18234+ return n;
18235+
18236 /* Avoid zeroing the tail if the copy fails..
18237 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18238 * but as the zeroing behaviour is only significant when n is not
18239@@ -137,6 +146,12 @@ static __always_inline unsigned long
18240 __copy_from_user(void *to, const void __user *from, unsigned long n)
18241 {
18242 might_fault();
18243+
18244+ if ((long)n < 0)
18245+ return n;
18246+
18247+ check_object_size(to, n, false);
18248+
18249 if (__builtin_constant_p(n)) {
18250 unsigned long ret;
18251
18252@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18253 const void __user *from, unsigned long n)
18254 {
18255 might_fault();
18256+
18257+ if ((long)n < 0)
18258+ return n;
18259+
18260 if (__builtin_constant_p(n)) {
18261 unsigned long ret;
18262
18263@@ -181,15 +200,19 @@ static __always_inline unsigned long
18264 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18265 unsigned long n)
18266 {
18267- return __copy_from_user_ll_nocache_nozero(to, from, n);
18268+ if ((long)n < 0)
18269+ return n;
18270+
18271+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18272 }
18273
18274-unsigned long __must_check copy_to_user(void __user *to,
18275- const void *from, unsigned long n);
18276-unsigned long __must_check _copy_from_user(void *to,
18277- const void __user *from,
18278- unsigned long n);
18279-
18280+extern void copy_to_user_overflow(void)
18281+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18282+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18283+#else
18284+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18285+#endif
18286+;
18287
18288 extern void copy_from_user_overflow(void)
18289 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18290@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18291 #endif
18292 ;
18293
18294-static inline unsigned long __must_check copy_from_user(void *to,
18295- const void __user *from,
18296- unsigned long n)
18297+/**
18298+ * copy_to_user: - Copy a block of data into user space.
18299+ * @to: Destination address, in user space.
18300+ * @from: Source address, in kernel space.
18301+ * @n: Number of bytes to copy.
18302+ *
18303+ * Context: User context only. This function may sleep.
18304+ *
18305+ * Copy data from kernel space to user space.
18306+ *
18307+ * Returns number of bytes that could not be copied.
18308+ * On success, this will be zero.
18309+ */
18310+static inline unsigned long __must_check
18311+copy_to_user(void __user *to, const void *from, unsigned long n)
18312 {
18313- int sz = __compiletime_object_size(to);
18314+ size_t sz = __compiletime_object_size(from);
18315
18316- if (likely(sz == -1 || sz >= n))
18317- n = _copy_from_user(to, from, n);
18318- else
18319+ if (unlikely(sz != (size_t)-1 && sz < n))
18320+ copy_to_user_overflow();
18321+ else if (access_ok(VERIFY_WRITE, to, n))
18322+ n = __copy_to_user(to, from, n);
18323+ return n;
18324+}
18325+
18326+/**
18327+ * copy_from_user: - Copy a block of data from user space.
18328+ * @to: Destination address, in kernel space.
18329+ * @from: Source address, in user space.
18330+ * @n: Number of bytes to copy.
18331+ *
18332+ * Context: User context only. This function may sleep.
18333+ *
18334+ * Copy data from user space to kernel space.
18335+ *
18336+ * Returns number of bytes that could not be copied.
18337+ * On success, this will be zero.
18338+ *
18339+ * If some data could not be copied, this function will pad the copied
18340+ * data to the requested size using zero bytes.
18341+ */
18342+static inline unsigned long __must_check
18343+copy_from_user(void *to, const void __user *from, unsigned long n)
18344+{
18345+ size_t sz = __compiletime_object_size(to);
18346+
18347+ check_object_size(to, n, false);
18348+
18349+ if (unlikely(sz != (size_t)-1 && sz < n))
18350 copy_from_user_overflow();
18351-
18352+ else if (access_ok(VERIFY_READ, from, n))
18353+ n = __copy_from_user(to, from, n);
18354+ else if ((long)n > 0)
18355+ memset(to, 0, n);
18356 return n;
18357 }
18358
18359diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18360index 4f7923d..20cb24e 100644
18361--- a/arch/x86/include/asm/uaccess_64.h
18362+++ b/arch/x86/include/asm/uaccess_64.h
18363@@ -10,6 +10,9 @@
18364 #include <asm/alternative.h>
18365 #include <asm/cpufeature.h>
18366 #include <asm/page.h>
18367+#include <asm/pgtable.h>
18368+
18369+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18370
18371 /*
18372 * Copy To/From Userspace
18373@@ -17,13 +20,13 @@
18374
18375 /* Handles exceptions in both to and from, but doesn't do access_ok */
18376 __must_check unsigned long
18377-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18378+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18379 __must_check unsigned long
18380-copy_user_generic_string(void *to, const void *from, unsigned len);
18381+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18382 __must_check unsigned long
18383-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18384+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18385
18386-static __always_inline __must_check unsigned long
18387+static __always_inline __must_check __size_overflow(3) unsigned long
18388 copy_user_generic(void *to, const void *from, unsigned len)
18389 {
18390 unsigned ret;
18391@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18392 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18393 "=d" (len)),
18394 "1" (to), "2" (from), "3" (len)
18395- : "memory", "rcx", "r8", "r9", "r10", "r11");
18396+ : "memory", "rcx", "r8", "r9", "r11");
18397 return ret;
18398 }
18399
18400+static __always_inline __must_check unsigned long
18401+__copy_to_user(void __user *to, const void *from, unsigned long len);
18402+static __always_inline __must_check unsigned long
18403+__copy_from_user(void *to, const void __user *from, unsigned long len);
18404 __must_check unsigned long
18405-_copy_to_user(void __user *to, const void *from, unsigned len);
18406-__must_check unsigned long
18407-_copy_from_user(void *to, const void __user *from, unsigned len);
18408-__must_check unsigned long
18409-copy_in_user(void __user *to, const void __user *from, unsigned len);
18410+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18411+
18412+extern void copy_to_user_overflow(void)
18413+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18414+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18415+#else
18416+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18417+#endif
18418+;
18419+
18420+extern void copy_from_user_overflow(void)
18421+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18422+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18423+#else
18424+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18425+#endif
18426+;
18427
18428 static inline unsigned long __must_check copy_from_user(void *to,
18429 const void __user *from,
18430 unsigned long n)
18431 {
18432- int sz = __compiletime_object_size(to);
18433-
18434 might_fault();
18435- if (likely(sz == -1 || sz >= n))
18436- n = _copy_from_user(to, from, n);
18437-#ifdef CONFIG_DEBUG_VM
18438- else
18439- WARN(1, "Buffer overflow detected!\n");
18440-#endif
18441+
18442+ check_object_size(to, n, false);
18443+
18444+ if (access_ok(VERIFY_READ, from, n))
18445+ n = __copy_from_user(to, from, n);
18446+ else if (n < INT_MAX)
18447+ memset(to, 0, n);
18448 return n;
18449 }
18450
18451 static __always_inline __must_check
18452-int copy_to_user(void __user *dst, const void *src, unsigned size)
18453+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18454 {
18455 might_fault();
18456
18457- return _copy_to_user(dst, src, size);
18458+ if (access_ok(VERIFY_WRITE, dst, size))
18459+ size = __copy_to_user(dst, src, size);
18460+ return size;
18461 }
18462
18463 static __always_inline __must_check
18464-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18465+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18466 {
18467- int ret = 0;
18468+ size_t sz = __compiletime_object_size(dst);
18469+ unsigned ret = 0;
18470
18471 might_fault();
18472+
18473+ if (size > INT_MAX)
18474+ return size;
18475+
18476+ check_object_size(dst, size, false);
18477+
18478+#ifdef CONFIG_PAX_MEMORY_UDEREF
18479+ if (!__access_ok(VERIFY_READ, src, size))
18480+ return size;
18481+#endif
18482+
18483+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18484+ copy_from_user_overflow();
18485+ return size;
18486+ }
18487+
18488 if (!__builtin_constant_p(size))
18489- return copy_user_generic(dst, (__force void *)src, size);
18490+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18491 switch (size) {
18492- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18493+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18494 ret, "b", "b", "=q", 1);
18495 return ret;
18496- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18497+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18498 ret, "w", "w", "=r", 2);
18499 return ret;
18500- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18501+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18502 ret, "l", "k", "=r", 4);
18503 return ret;
18504- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18505+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18506 ret, "q", "", "=r", 8);
18507 return ret;
18508 case 10:
18509- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18510+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18511 ret, "q", "", "=r", 10);
18512 if (unlikely(ret))
18513 return ret;
18514 __get_user_asm(*(u16 *)(8 + (char *)dst),
18515- (u16 __user *)(8 + (char __user *)src),
18516+ (const u16 __user *)(8 + (const char __user *)src),
18517 ret, "w", "w", "=r", 2);
18518 return ret;
18519 case 16:
18520- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18521+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18522 ret, "q", "", "=r", 16);
18523 if (unlikely(ret))
18524 return ret;
18525 __get_user_asm(*(u64 *)(8 + (char *)dst),
18526- (u64 __user *)(8 + (char __user *)src),
18527+ (const u64 __user *)(8 + (const char __user *)src),
18528 ret, "q", "", "=r", 8);
18529 return ret;
18530 default:
18531- return copy_user_generic(dst, (__force void *)src, size);
18532+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18533 }
18534 }
18535
18536 static __always_inline __must_check
18537-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18538+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18539 {
18540- int ret = 0;
18541+ size_t sz = __compiletime_object_size(src);
18542+ unsigned ret = 0;
18543
18544 might_fault();
18545+
18546+ if (size > INT_MAX)
18547+ return size;
18548+
18549+ check_object_size(src, size, true);
18550+
18551+#ifdef CONFIG_PAX_MEMORY_UDEREF
18552+ if (!__access_ok(VERIFY_WRITE, dst, size))
18553+ return size;
18554+#endif
18555+
18556+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18557+ copy_to_user_overflow();
18558+ return size;
18559+ }
18560+
18561 if (!__builtin_constant_p(size))
18562- return copy_user_generic((__force void *)dst, src, size);
18563+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18564 switch (size) {
18565- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18566+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18567 ret, "b", "b", "iq", 1);
18568 return ret;
18569- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18570+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18571 ret, "w", "w", "ir", 2);
18572 return ret;
18573- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18574+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18575 ret, "l", "k", "ir", 4);
18576 return ret;
18577- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18578+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18579 ret, "q", "", "er", 8);
18580 return ret;
18581 case 10:
18582- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18583+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18584 ret, "q", "", "er", 10);
18585 if (unlikely(ret))
18586 return ret;
18587 asm("":::"memory");
18588- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18589+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18590 ret, "w", "w", "ir", 2);
18591 return ret;
18592 case 16:
18593- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18594+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18595 ret, "q", "", "er", 16);
18596 if (unlikely(ret))
18597 return ret;
18598 asm("":::"memory");
18599- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18600+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18601 ret, "q", "", "er", 8);
18602 return ret;
18603 default:
18604- return copy_user_generic((__force void *)dst, src, size);
18605+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18606 }
18607 }
18608
18609 static __always_inline __must_check
18610-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18611+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18612 {
18613- int ret = 0;
18614+ unsigned ret = 0;
18615
18616 might_fault();
18617+
18618+ if (size > INT_MAX)
18619+ return size;
18620+
18621+#ifdef CONFIG_PAX_MEMORY_UDEREF
18622+ if (!__access_ok(VERIFY_READ, src, size))
18623+ return size;
18624+ if (!__access_ok(VERIFY_WRITE, dst, size))
18625+ return size;
18626+#endif
18627+
18628 if (!__builtin_constant_p(size))
18629- return copy_user_generic((__force void *)dst,
18630- (__force void *)src, size);
18631+ return copy_user_generic((__force_kernel void *)____m(dst),
18632+ (__force_kernel const void *)____m(src), size);
18633 switch (size) {
18634 case 1: {
18635 u8 tmp;
18636- __get_user_asm(tmp, (u8 __user *)src,
18637+ __get_user_asm(tmp, (const u8 __user *)src,
18638 ret, "b", "b", "=q", 1);
18639 if (likely(!ret))
18640 __put_user_asm(tmp, (u8 __user *)dst,
18641@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18642 }
18643 case 2: {
18644 u16 tmp;
18645- __get_user_asm(tmp, (u16 __user *)src,
18646+ __get_user_asm(tmp, (const u16 __user *)src,
18647 ret, "w", "w", "=r", 2);
18648 if (likely(!ret))
18649 __put_user_asm(tmp, (u16 __user *)dst,
18650@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18651
18652 case 4: {
18653 u32 tmp;
18654- __get_user_asm(tmp, (u32 __user *)src,
18655+ __get_user_asm(tmp, (const u32 __user *)src,
18656 ret, "l", "k", "=r", 4);
18657 if (likely(!ret))
18658 __put_user_asm(tmp, (u32 __user *)dst,
18659@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18660 }
18661 case 8: {
18662 u64 tmp;
18663- __get_user_asm(tmp, (u64 __user *)src,
18664+ __get_user_asm(tmp, (const u64 __user *)src,
18665 ret, "q", "", "=r", 8);
18666 if (likely(!ret))
18667 __put_user_asm(tmp, (u64 __user *)dst,
18668@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18669 return ret;
18670 }
18671 default:
18672- return copy_user_generic((__force void *)dst,
18673- (__force void *)src, size);
18674+ return copy_user_generic((__force_kernel void *)____m(dst),
18675+ (__force_kernel const void *)____m(src), size);
18676 }
18677 }
18678
18679-static __must_check __always_inline int
18680-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18681+static __must_check __always_inline unsigned long
18682+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18683 {
18684- return copy_user_generic(dst, (__force const void *)src, size);
18685+ if (size > INT_MAX)
18686+ return size;
18687+
18688+#ifdef CONFIG_PAX_MEMORY_UDEREF
18689+ if (!__access_ok(VERIFY_READ, src, size))
18690+ return size;
18691+#endif
18692+
18693+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18694 }
18695
18696-static __must_check __always_inline int
18697-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18698+static __must_check __always_inline unsigned long
18699+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18700 {
18701- return copy_user_generic((__force void *)dst, src, size);
18702+ if (size > INT_MAX)
18703+ return size;
18704+
18705+#ifdef CONFIG_PAX_MEMORY_UDEREF
18706+ if (!__access_ok(VERIFY_WRITE, dst, size))
18707+ return size;
18708+#endif
18709+
18710+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18711 }
18712
18713-extern long __copy_user_nocache(void *dst, const void __user *src,
18714- unsigned size, int zerorest);
18715+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18716+ unsigned long size, int zerorest) __size_overflow(3);
18717
18718-static inline int
18719-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18720+static inline unsigned long
18721+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18722 {
18723 might_fault();
18724+
18725+ if (size > INT_MAX)
18726+ return size;
18727+
18728+#ifdef CONFIG_PAX_MEMORY_UDEREF
18729+ if (!__access_ok(VERIFY_READ, src, size))
18730+ return size;
18731+#endif
18732+
18733 return __copy_user_nocache(dst, src, size, 1);
18734 }
18735
18736-static inline int
18737+static inline unsigned long
18738 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18739- unsigned size)
18740+ unsigned long size)
18741 {
18742+ if (size > INT_MAX)
18743+ return size;
18744+
18745+#ifdef CONFIG_PAX_MEMORY_UDEREF
18746+ if (!__access_ok(VERIFY_READ, src, size))
18747+ return size;
18748+#endif
18749+
18750 return __copy_user_nocache(dst, src, size, 0);
18751 }
18752
18753 unsigned long
18754-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18755+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18756
18757 #endif /* _ASM_X86_UACCESS_64_H */
18758diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18759index 5b238981..77fdd78 100644
18760--- a/arch/x86/include/asm/word-at-a-time.h
18761+++ b/arch/x86/include/asm/word-at-a-time.h
18762@@ -11,7 +11,7 @@
18763 * and shift, for example.
18764 */
18765 struct word_at_a_time {
18766- const unsigned long one_bits, high_bits;
18767+ unsigned long one_bits, high_bits;
18768 };
18769
18770 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18771diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18772index 828a156..650e625 100644
18773--- a/arch/x86/include/asm/x86_init.h
18774+++ b/arch/x86/include/asm/x86_init.h
18775@@ -129,7 +129,7 @@ struct x86_init_ops {
18776 struct x86_init_timers timers;
18777 struct x86_init_iommu iommu;
18778 struct x86_init_pci pci;
18779-};
18780+} __no_const;
18781
18782 /**
18783 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18784@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18785 void (*setup_percpu_clockev)(void);
18786 void (*early_percpu_clock_init)(void);
18787 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18788-};
18789+} __no_const;
18790
18791 struct timespec;
18792
18793@@ -168,7 +168,7 @@ struct x86_platform_ops {
18794 void (*save_sched_clock_state)(void);
18795 void (*restore_sched_clock_state)(void);
18796 void (*apic_post_init)(void);
18797-};
18798+} __no_const;
18799
18800 struct pci_dev;
18801 struct msi_msg;
18802@@ -182,7 +182,7 @@ struct x86_msi_ops {
18803 void (*teardown_msi_irqs)(struct pci_dev *dev);
18804 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18805 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18806-};
18807+} __no_const;
18808
18809 struct IO_APIC_route_entry;
18810 struct io_apic_irq_attr;
18811@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18812 unsigned int destination, int vector,
18813 struct io_apic_irq_attr *attr);
18814 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18815-};
18816+} __no_const;
18817
18818 extern struct x86_init_ops x86_init;
18819 extern struct x86_cpuinit_ops x86_cpuinit;
18820diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18821index 0415cda..3b22adc 100644
18822--- a/arch/x86/include/asm/xsave.h
18823+++ b/arch/x86/include/asm/xsave.h
18824@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18825 if (unlikely(err))
18826 return -EFAULT;
18827
18828+ pax_open_userland();
18829 __asm__ __volatile__(ASM_STAC "\n"
18830- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18831+ "1:"
18832+ __copyuser_seg
18833+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18834 "2: " ASM_CLAC "\n"
18835 ".section .fixup,\"ax\"\n"
18836 "3: movl $-1,%[err]\n"
18837@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18838 : [err] "=r" (err)
18839 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18840 : "memory");
18841+ pax_close_userland();
18842 return err;
18843 }
18844
18845 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18846 {
18847 int err;
18848- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18849+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18850 u32 lmask = mask;
18851 u32 hmask = mask >> 32;
18852
18853+ pax_open_userland();
18854 __asm__ __volatile__(ASM_STAC "\n"
18855- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18856+ "1:"
18857+ __copyuser_seg
18858+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18859 "2: " ASM_CLAC "\n"
18860 ".section .fixup,\"ax\"\n"
18861 "3: movl $-1,%[err]\n"
18862@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18863 : [err] "=r" (err)
18864 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18865 : "memory"); /* memory required? */
18866+ pax_close_userland();
18867 return err;
18868 }
18869
18870diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18871index bbae024..e1528f9 100644
18872--- a/arch/x86/include/uapi/asm/e820.h
18873+++ b/arch/x86/include/uapi/asm/e820.h
18874@@ -63,7 +63,7 @@ struct e820map {
18875 #define ISA_START_ADDRESS 0xa0000
18876 #define ISA_END_ADDRESS 0x100000
18877
18878-#define BIOS_BEGIN 0x000a0000
18879+#define BIOS_BEGIN 0x000c0000
18880 #define BIOS_END 0x00100000
18881
18882 #define BIOS_ROM_BASE 0xffe00000
18883diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18884index 88d99ea..9fc7e17 100644
18885--- a/arch/x86/kernel/Makefile
18886+++ b/arch/x86/kernel/Makefile
18887@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18888 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18889 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18890 obj-y += probe_roms.o
18891-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18892+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18893 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18894 obj-y += syscall_$(BITS).o
18895 obj-$(CONFIG_X86_64) += vsyscall_64.o
18896diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18897index 2627a81..cd8325e 100644
18898--- a/arch/x86/kernel/acpi/boot.c
18899+++ b/arch/x86/kernel/acpi/boot.c
18900@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18901 * If your system is blacklisted here, but you find that acpi=force
18902 * works for you, please contact linux-acpi@vger.kernel.org
18903 */
18904-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18905+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18906 /*
18907 * Boxes that need ACPI disabled
18908 */
18909@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18910 };
18911
18912 /* second table for DMI checks that should run after early-quirks */
18913-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18914+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18915 /*
18916 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18917 * which includes some code which overrides all temperature
18918diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18919index 3312010..a65ca7b 100644
18920--- a/arch/x86/kernel/acpi/sleep.c
18921+++ b/arch/x86/kernel/acpi/sleep.c
18922@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18923 #else /* CONFIG_64BIT */
18924 #ifdef CONFIG_SMP
18925 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18926+
18927+ pax_open_kernel();
18928 early_gdt_descr.address =
18929 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18930+ pax_close_kernel();
18931+
18932 initial_gs = per_cpu_offset(smp_processor_id());
18933 #endif
18934 initial_code = (unsigned long)wakeup_long64;
18935diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18936index d1daa66..59fecba 100644
18937--- a/arch/x86/kernel/acpi/wakeup_32.S
18938+++ b/arch/x86/kernel/acpi/wakeup_32.S
18939@@ -29,13 +29,11 @@ wakeup_pmode_return:
18940 # and restore the stack ... but you need gdt for this to work
18941 movl saved_context_esp, %esp
18942
18943- movl %cs:saved_magic, %eax
18944- cmpl $0x12345678, %eax
18945+ cmpl $0x12345678, saved_magic
18946 jne bogus_magic
18947
18948 # jump to place where we left off
18949- movl saved_eip, %eax
18950- jmp *%eax
18951+ jmp *(saved_eip)
18952
18953 bogus_magic:
18954 jmp bogus_magic
18955diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18956index c15cf9a..0e63558 100644
18957--- a/arch/x86/kernel/alternative.c
18958+++ b/arch/x86/kernel/alternative.c
18959@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18960 */
18961 for (a = start; a < end; a++) {
18962 instr = (u8 *)&a->instr_offset + a->instr_offset;
18963+
18964+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18965+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18966+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18967+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18968+#endif
18969+
18970 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18971 BUG_ON(a->replacementlen > a->instrlen);
18972 BUG_ON(a->instrlen > sizeof(insnbuf));
18973@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18974 for (poff = start; poff < end; poff++) {
18975 u8 *ptr = (u8 *)poff + *poff;
18976
18977+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18978+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18979+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18980+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18981+#endif
18982+
18983 if (!*poff || ptr < text || ptr >= text_end)
18984 continue;
18985 /* turn DS segment override prefix into lock prefix */
18986- if (*ptr == 0x3e)
18987+ if (*ktla_ktva(ptr) == 0x3e)
18988 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18989 }
18990 mutex_unlock(&text_mutex);
18991@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18992 for (poff = start; poff < end; poff++) {
18993 u8 *ptr = (u8 *)poff + *poff;
18994
18995+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18996+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18997+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18998+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18999+#endif
19000+
19001 if (!*poff || ptr < text || ptr >= text_end)
19002 continue;
19003 /* turn lock prefix into DS segment override prefix */
19004- if (*ptr == 0xf0)
19005+ if (*ktla_ktva(ptr) == 0xf0)
19006 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19007 }
19008 mutex_unlock(&text_mutex);
19009@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19010
19011 BUG_ON(p->len > MAX_PATCH_LEN);
19012 /* prep the buffer with the original instructions */
19013- memcpy(insnbuf, p->instr, p->len);
19014+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19015 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19016 (unsigned long)p->instr, p->len);
19017
19018@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19019 if (!uniproc_patched || num_possible_cpus() == 1)
19020 free_init_pages("SMP alternatives",
19021 (unsigned long)__smp_locks,
19022- (unsigned long)__smp_locks_end);
19023+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19024 #endif
19025
19026 apply_paravirt(__parainstructions, __parainstructions_end);
19027@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19028 * instructions. And on the local CPU you need to be protected again NMI or MCE
19029 * handlers seeing an inconsistent instruction while you patch.
19030 */
19031-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19032+void *__kprobes text_poke_early(void *addr, const void *opcode,
19033 size_t len)
19034 {
19035 unsigned long flags;
19036 local_irq_save(flags);
19037- memcpy(addr, opcode, len);
19038+
19039+ pax_open_kernel();
19040+ memcpy(ktla_ktva(addr), opcode, len);
19041 sync_core();
19042+ pax_close_kernel();
19043+
19044 local_irq_restore(flags);
19045 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19046 that causes hangs on some VIA CPUs. */
19047@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19048 */
19049 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19050 {
19051- unsigned long flags;
19052- char *vaddr;
19053+ unsigned char *vaddr = ktla_ktva(addr);
19054 struct page *pages[2];
19055- int i;
19056+ size_t i;
19057
19058 if (!core_kernel_text((unsigned long)addr)) {
19059- pages[0] = vmalloc_to_page(addr);
19060- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19061+ pages[0] = vmalloc_to_page(vaddr);
19062+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19063 } else {
19064- pages[0] = virt_to_page(addr);
19065+ pages[0] = virt_to_page(vaddr);
19066 WARN_ON(!PageReserved(pages[0]));
19067- pages[1] = virt_to_page(addr + PAGE_SIZE);
19068+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19069 }
19070 BUG_ON(!pages[0]);
19071- local_irq_save(flags);
19072- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19073- if (pages[1])
19074- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19075- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19076- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19077- clear_fixmap(FIX_TEXT_POKE0);
19078- if (pages[1])
19079- clear_fixmap(FIX_TEXT_POKE1);
19080- local_flush_tlb();
19081- sync_core();
19082- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19083- that causes hangs on some VIA CPUs. */
19084+ text_poke_early(addr, opcode, len);
19085 for (i = 0; i < len; i++)
19086- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19087- local_irq_restore(flags);
19088+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19089 return addr;
19090 }
19091
19092diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19093index eca89c5..d566b78 100644
19094--- a/arch/x86/kernel/apic/apic.c
19095+++ b/arch/x86/kernel/apic/apic.c
19096@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19097 /*
19098 * Debug level, exported for io_apic.c
19099 */
19100-unsigned int apic_verbosity;
19101+int apic_verbosity;
19102
19103 int pic_mode;
19104
19105@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19106 apic_write(APIC_ESR, 0);
19107 v1 = apic_read(APIC_ESR);
19108 ack_APIC_irq();
19109- atomic_inc(&irq_err_count);
19110+ atomic_inc_unchecked(&irq_err_count);
19111
19112 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19113 smp_processor_id(), v0 , v1);
19114diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19115index 00c77cf..2dc6a2d 100644
19116--- a/arch/x86/kernel/apic/apic_flat_64.c
19117+++ b/arch/x86/kernel/apic/apic_flat_64.c
19118@@ -157,7 +157,7 @@ static int flat_probe(void)
19119 return 1;
19120 }
19121
19122-static struct apic apic_flat = {
19123+static struct apic apic_flat __read_only = {
19124 .name = "flat",
19125 .probe = flat_probe,
19126 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19127@@ -271,7 +271,7 @@ static int physflat_probe(void)
19128 return 0;
19129 }
19130
19131-static struct apic apic_physflat = {
19132+static struct apic apic_physflat __read_only = {
19133
19134 .name = "physical flat",
19135 .probe = physflat_probe,
19136diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19137index e145f28..2752888 100644
19138--- a/arch/x86/kernel/apic/apic_noop.c
19139+++ b/arch/x86/kernel/apic/apic_noop.c
19140@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19141 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19142 }
19143
19144-struct apic apic_noop = {
19145+struct apic apic_noop __read_only = {
19146 .name = "noop",
19147 .probe = noop_probe,
19148 .acpi_madt_oem_check = NULL,
19149diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19150index d50e364..543bee3 100644
19151--- a/arch/x86/kernel/apic/bigsmp_32.c
19152+++ b/arch/x86/kernel/apic/bigsmp_32.c
19153@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19154 return dmi_bigsmp;
19155 }
19156
19157-static struct apic apic_bigsmp = {
19158+static struct apic apic_bigsmp __read_only = {
19159
19160 .name = "bigsmp",
19161 .probe = probe_bigsmp,
19162diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19163index c552247..587a316 100644
19164--- a/arch/x86/kernel/apic/es7000_32.c
19165+++ b/arch/x86/kernel/apic/es7000_32.c
19166@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19167 return ret && es7000_apic_is_cluster();
19168 }
19169
19170-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19171-static struct apic __refdata apic_es7000_cluster = {
19172+static struct apic apic_es7000_cluster __read_only = {
19173
19174 .name = "es7000",
19175 .probe = probe_es7000,
19176@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19177 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19178 };
19179
19180-static struct apic __refdata apic_es7000 = {
19181+static struct apic apic_es7000 __read_only = {
19182
19183 .name = "es7000",
19184 .probe = probe_es7000,
19185diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19186index 9ed796c..e930fe4 100644
19187--- a/arch/x86/kernel/apic/io_apic.c
19188+++ b/arch/x86/kernel/apic/io_apic.c
19189@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19190 }
19191 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19192
19193-void lock_vector_lock(void)
19194+void lock_vector_lock(void) __acquires(vector_lock)
19195 {
19196 /* Used to the online set of cpus does not change
19197 * during assign_irq_vector.
19198@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19199 raw_spin_lock(&vector_lock);
19200 }
19201
19202-void unlock_vector_lock(void)
19203+void unlock_vector_lock(void) __releases(vector_lock)
19204 {
19205 raw_spin_unlock(&vector_lock);
19206 }
19207@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19208 ack_APIC_irq();
19209 }
19210
19211-atomic_t irq_mis_count;
19212+atomic_unchecked_t irq_mis_count;
19213
19214 #ifdef CONFIG_GENERIC_PENDING_IRQ
19215 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19216@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19217 * at the cpu.
19218 */
19219 if (!(v & (1 << (i & 0x1f)))) {
19220- atomic_inc(&irq_mis_count);
19221+ atomic_inc_unchecked(&irq_mis_count);
19222
19223 eoi_ioapic_irq(irq, cfg);
19224 }
19225diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19226index 1e42e8f..daacf44 100644
19227--- a/arch/x86/kernel/apic/numaq_32.c
19228+++ b/arch/x86/kernel/apic/numaq_32.c
19229@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19230 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19231 }
19232
19233-/* Use __refdata to keep false positive warning calm. */
19234-static struct apic __refdata apic_numaq = {
19235+static struct apic apic_numaq __read_only = {
19236
19237 .name = "NUMAQ",
19238 .probe = probe_numaq,
19239diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19240index eb35ef9..f184a21 100644
19241--- a/arch/x86/kernel/apic/probe_32.c
19242+++ b/arch/x86/kernel/apic/probe_32.c
19243@@ -72,7 +72,7 @@ static int probe_default(void)
19244 return 1;
19245 }
19246
19247-static struct apic apic_default = {
19248+static struct apic apic_default __read_only = {
19249
19250 .name = "default",
19251 .probe = probe_default,
19252diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19253index 77c95c0..434f8a4 100644
19254--- a/arch/x86/kernel/apic/summit_32.c
19255+++ b/arch/x86/kernel/apic/summit_32.c
19256@@ -486,7 +486,7 @@ void setup_summit(void)
19257 }
19258 #endif
19259
19260-static struct apic apic_summit = {
19261+static struct apic apic_summit __read_only = {
19262
19263 .name = "summit",
19264 .probe = probe_summit,
19265diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19266index 140e29d..d88bc95 100644
19267--- a/arch/x86/kernel/apic/x2apic_cluster.c
19268+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19269@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19270 return notifier_from_errno(err);
19271 }
19272
19273-static struct notifier_block __refdata x2apic_cpu_notifier = {
19274+static struct notifier_block x2apic_cpu_notifier = {
19275 .notifier_call = update_clusterinfo,
19276 };
19277
19278@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19279 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19280 }
19281
19282-static struct apic apic_x2apic_cluster = {
19283+static struct apic apic_x2apic_cluster __read_only = {
19284
19285 .name = "cluster x2apic",
19286 .probe = x2apic_cluster_probe,
19287diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19288index 562a76d..a003c0f 100644
19289--- a/arch/x86/kernel/apic/x2apic_phys.c
19290+++ b/arch/x86/kernel/apic/x2apic_phys.c
19291@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19292 return apic == &apic_x2apic_phys;
19293 }
19294
19295-static struct apic apic_x2apic_phys = {
19296+static struct apic apic_x2apic_phys __read_only = {
19297
19298 .name = "physical x2apic",
19299 .probe = x2apic_phys_probe,
19300diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19301index 1191ac1..2335fa4 100644
19302--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19303+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19304@@ -357,7 +357,7 @@ static int uv_probe(void)
19305 return apic == &apic_x2apic_uv_x;
19306 }
19307
19308-static struct apic __refdata apic_x2apic_uv_x = {
19309+static struct apic apic_x2apic_uv_x __read_only = {
19310
19311 .name = "UV large system",
19312 .probe = uv_probe,
19313diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19314index 53a4e27..038760a 100644
19315--- a/arch/x86/kernel/apm_32.c
19316+++ b/arch/x86/kernel/apm_32.c
19317@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19318 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19319 * even though they are called in protected mode.
19320 */
19321-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19322+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19323 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19324
19325 static const char driver_version[] = "1.16ac"; /* no spaces */
19326@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19327 BUG_ON(cpu != 0);
19328 gdt = get_cpu_gdt_table(cpu);
19329 save_desc_40 = gdt[0x40 / 8];
19330+
19331+ pax_open_kernel();
19332 gdt[0x40 / 8] = bad_bios_desc;
19333+ pax_close_kernel();
19334
19335 apm_irq_save(flags);
19336 APM_DO_SAVE_SEGS;
19337@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19338 &call->esi);
19339 APM_DO_RESTORE_SEGS;
19340 apm_irq_restore(flags);
19341+
19342+ pax_open_kernel();
19343 gdt[0x40 / 8] = save_desc_40;
19344+ pax_close_kernel();
19345+
19346 put_cpu();
19347
19348 return call->eax & 0xff;
19349@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19350 BUG_ON(cpu != 0);
19351 gdt = get_cpu_gdt_table(cpu);
19352 save_desc_40 = gdt[0x40 / 8];
19353+
19354+ pax_open_kernel();
19355 gdt[0x40 / 8] = bad_bios_desc;
19356+ pax_close_kernel();
19357
19358 apm_irq_save(flags);
19359 APM_DO_SAVE_SEGS;
19360@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19361 &call->eax);
19362 APM_DO_RESTORE_SEGS;
19363 apm_irq_restore(flags);
19364+
19365+ pax_open_kernel();
19366 gdt[0x40 / 8] = save_desc_40;
19367+ pax_close_kernel();
19368+
19369 put_cpu();
19370 return error;
19371 }
19372@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19373 * code to that CPU.
19374 */
19375 gdt = get_cpu_gdt_table(0);
19376+
19377+ pax_open_kernel();
19378 set_desc_base(&gdt[APM_CS >> 3],
19379 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19380 set_desc_base(&gdt[APM_CS_16 >> 3],
19381 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19382 set_desc_base(&gdt[APM_DS >> 3],
19383 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19384+ pax_close_kernel();
19385
19386 proc_create("apm", 0, NULL, &apm_file_ops);
19387
19388diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19389index 2861082..6d4718e 100644
19390--- a/arch/x86/kernel/asm-offsets.c
19391+++ b/arch/x86/kernel/asm-offsets.c
19392@@ -33,6 +33,8 @@ void common(void) {
19393 OFFSET(TI_status, thread_info, status);
19394 OFFSET(TI_addr_limit, thread_info, addr_limit);
19395 OFFSET(TI_preempt_count, thread_info, preempt_count);
19396+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19397+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19398
19399 BLANK();
19400 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19401@@ -53,8 +55,26 @@ void common(void) {
19402 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19403 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19404 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19405+
19406+#ifdef CONFIG_PAX_KERNEXEC
19407+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19408 #endif
19409
19410+#ifdef CONFIG_PAX_MEMORY_UDEREF
19411+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19412+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19413+#ifdef CONFIG_X86_64
19414+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19415+#endif
19416+#endif
19417+
19418+#endif
19419+
19420+ BLANK();
19421+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19422+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19423+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19424+
19425 #ifdef CONFIG_XEN
19426 BLANK();
19427 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19428diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19429index e7c798b..2b2019b 100644
19430--- a/arch/x86/kernel/asm-offsets_64.c
19431+++ b/arch/x86/kernel/asm-offsets_64.c
19432@@ -77,6 +77,7 @@ int main(void)
19433 BLANK();
19434 #undef ENTRY
19435
19436+ DEFINE(TSS_size, sizeof(struct tss_struct));
19437 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19438 BLANK();
19439
19440diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19441index 47b56a7..efc2bc6 100644
19442--- a/arch/x86/kernel/cpu/Makefile
19443+++ b/arch/x86/kernel/cpu/Makefile
19444@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19445 CFLAGS_REMOVE_perf_event.o = -pg
19446 endif
19447
19448-# Make sure load_percpu_segment has no stackprotector
19449-nostackp := $(call cc-option, -fno-stack-protector)
19450-CFLAGS_common.o := $(nostackp)
19451-
19452 obj-y := intel_cacheinfo.o scattered.o topology.o
19453 obj-y += proc.o capflags.o powerflags.o common.o
19454 obj-y += rdrand.o
19455diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19456index 08a0890..e557865 100644
19457--- a/arch/x86/kernel/cpu/amd.c
19458+++ b/arch/x86/kernel/cpu/amd.c
19459@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19460 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19461 {
19462 /* AMD errata T13 (order #21922) */
19463- if ((c->x86 == 6)) {
19464+ if (c->x86 == 6) {
19465 /* Duron Rev A0 */
19466 if (c->x86_model == 3 && c->x86_mask == 0)
19467 size = 64;
19468diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19469index 25eb274..3a92d93 100644
19470--- a/arch/x86/kernel/cpu/common.c
19471+++ b/arch/x86/kernel/cpu/common.c
19472@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19473
19474 static const struct cpu_dev *this_cpu = &default_cpu;
19475
19476-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19477-#ifdef CONFIG_X86_64
19478- /*
19479- * We need valid kernel segments for data and code in long mode too
19480- * IRET will check the segment types kkeil 2000/10/28
19481- * Also sysret mandates a special GDT layout
19482- *
19483- * TLS descriptors are currently at a different place compared to i386.
19484- * Hopefully nobody expects them at a fixed place (Wine?)
19485- */
19486- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19487- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19488- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19489- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19490- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19491- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19492-#else
19493- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19494- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19495- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19496- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19497- /*
19498- * Segments used for calling PnP BIOS have byte granularity.
19499- * They code segments and data segments have fixed 64k limits,
19500- * the transfer segment sizes are set at run time.
19501- */
19502- /* 32-bit code */
19503- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19504- /* 16-bit code */
19505- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19506- /* 16-bit data */
19507- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19508- /* 16-bit data */
19509- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19510- /* 16-bit data */
19511- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19512- /*
19513- * The APM segments have byte granularity and their bases
19514- * are set at run time. All have 64k limits.
19515- */
19516- /* 32-bit code */
19517- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19518- /* 16-bit code */
19519- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19520- /* data */
19521- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19522-
19523- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19524- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19525- GDT_STACK_CANARY_INIT
19526-#endif
19527-} };
19528-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19529-
19530 static int __init x86_xsave_setup(char *s)
19531 {
19532 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19533@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19534 set_in_cr4(X86_CR4_SMAP);
19535 }
19536
19537+#ifdef CONFIG_X86_64
19538+static __init int setup_disable_pcid(char *arg)
19539+{
19540+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19541+
19542+#ifdef CONFIG_PAX_MEMORY_UDEREF
19543+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19544+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19545+#endif
19546+
19547+ return 1;
19548+}
19549+__setup("nopcid", setup_disable_pcid);
19550+
19551+static void setup_pcid(struct cpuinfo_x86 *c)
19552+{
19553+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19554+
19555+#ifdef CONFIG_PAX_MEMORY_UDEREF
19556+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19557+ pax_open_kernel();
19558+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19559+ pax_close_kernel();
19560+ printk("PAX: slow and weak UDEREF enabled\n");
19561+ } else
19562+ printk("PAX: UDEREF disabled\n");
19563+#endif
19564+
19565+ return;
19566+ }
19567+
19568+ printk("PAX: PCID detected\n");
19569+ set_in_cr4(X86_CR4_PCIDE);
19570+
19571+#ifdef CONFIG_PAX_MEMORY_UDEREF
19572+ pax_open_kernel();
19573+ clone_pgd_mask = ~(pgdval_t)0UL;
19574+ pax_close_kernel();
19575+ if (pax_user_shadow_base)
19576+ printk("PAX: weak UDEREF enabled\n");
19577+ else {
19578+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19579+ printk("PAX: strong UDEREF enabled\n");
19580+ }
19581+#endif
19582+
19583+ if (cpu_has(c, X86_FEATURE_INVPCID))
19584+ printk("PAX: INVPCID detected\n");
19585+}
19586+#endif
19587+
19588 /*
19589 * Some CPU features depend on higher CPUID levels, which may not always
19590 * be available due to CPUID level capping or broken virtualization
19591@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19592 {
19593 struct desc_ptr gdt_descr;
19594
19595- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19596+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19597 gdt_descr.size = GDT_SIZE - 1;
19598 load_gdt(&gdt_descr);
19599 /* Reload the per-cpu base */
19600@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19601 setup_smep(c);
19602 setup_smap(c);
19603
19604+#ifdef CONFIG_X86_64
19605+ setup_pcid(c);
19606+#endif
19607+
19608 /*
19609 * The vendor-specific functions might have changed features.
19610 * Now we do "generic changes."
19611@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19612 /* Filter out anything that depends on CPUID levels we don't have */
19613 filter_cpuid_features(c, true);
19614
19615+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19616+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19617+#endif
19618+
19619 /* If the model name is still unset, do table lookup. */
19620 if (!c->x86_model_id[0]) {
19621 const char *p;
19622@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19623 }
19624 __setup("clearcpuid=", setup_disablecpuid);
19625
19626+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19627+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19628+
19629 #ifdef CONFIG_X86_64
19630-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19631-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19632- (unsigned long) debug_idt_table };
19633+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19634+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19635
19636 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19637 irq_stack_union) __aligned(PAGE_SIZE);
19638@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19639 EXPORT_PER_CPU_SYMBOL(current_task);
19640
19641 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19642- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19643+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19644 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19645
19646 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19647@@ -1232,7 +1239,7 @@ void cpu_init(void)
19648 load_ucode_ap();
19649
19650 cpu = stack_smp_processor_id();
19651- t = &per_cpu(init_tss, cpu);
19652+ t = init_tss + cpu;
19653 oist = &per_cpu(orig_ist, cpu);
19654
19655 #ifdef CONFIG_NUMA
19656@@ -1267,7 +1274,6 @@ void cpu_init(void)
19657 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19658 barrier();
19659
19660- x86_configure_nx();
19661 enable_x2apic();
19662
19663 /*
19664@@ -1319,7 +1325,7 @@ void cpu_init(void)
19665 {
19666 int cpu = smp_processor_id();
19667 struct task_struct *curr = current;
19668- struct tss_struct *t = &per_cpu(init_tss, cpu);
19669+ struct tss_struct *t = init_tss + cpu;
19670 struct thread_struct *thread = &curr->thread;
19671
19672 show_ucode_info_early();
19673diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19674index 1414c90..1159406 100644
19675--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19676+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19677@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19678 };
19679
19680 #ifdef CONFIG_AMD_NB
19681+static struct attribute *default_attrs_amd_nb[] = {
19682+ &type.attr,
19683+ &level.attr,
19684+ &coherency_line_size.attr,
19685+ &physical_line_partition.attr,
19686+ &ways_of_associativity.attr,
19687+ &number_of_sets.attr,
19688+ &size.attr,
19689+ &shared_cpu_map.attr,
19690+ &shared_cpu_list.attr,
19691+ NULL,
19692+ NULL,
19693+ NULL,
19694+ NULL
19695+};
19696+
19697 static struct attribute **amd_l3_attrs(void)
19698 {
19699 static struct attribute **attrs;
19700@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19701
19702 n = ARRAY_SIZE(default_attrs);
19703
19704- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19705- n += 2;
19706-
19707- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19708- n += 1;
19709-
19710- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19711- if (attrs == NULL)
19712- return attrs = default_attrs;
19713-
19714- for (n = 0; default_attrs[n]; n++)
19715- attrs[n] = default_attrs[n];
19716+ attrs = default_attrs_amd_nb;
19717
19718 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19719 attrs[n++] = &cache_disable_0.attr;
19720@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19721 .default_attrs = default_attrs,
19722 };
19723
19724+#ifdef CONFIG_AMD_NB
19725+static struct kobj_type ktype_cache_amd_nb = {
19726+ .sysfs_ops = &sysfs_ops,
19727+ .default_attrs = default_attrs_amd_nb,
19728+};
19729+#endif
19730+
19731 static struct kobj_type ktype_percpu_entry = {
19732 .sysfs_ops = &sysfs_ops,
19733 };
19734@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19735 return retval;
19736 }
19737
19738+#ifdef CONFIG_AMD_NB
19739+ amd_l3_attrs();
19740+#endif
19741+
19742 for (i = 0; i < num_cache_leaves; i++) {
19743+ struct kobj_type *ktype;
19744+
19745 this_object = INDEX_KOBJECT_PTR(cpu, i);
19746 this_object->cpu = cpu;
19747 this_object->index = i;
19748
19749 this_leaf = CPUID4_INFO_IDX(cpu, i);
19750
19751- ktype_cache.default_attrs = default_attrs;
19752+ ktype = &ktype_cache;
19753 #ifdef CONFIG_AMD_NB
19754 if (this_leaf->base.nb)
19755- ktype_cache.default_attrs = amd_l3_attrs();
19756+ ktype = &ktype_cache_amd_nb;
19757 #endif
19758 retval = kobject_init_and_add(&(this_object->kobj),
19759- &ktype_cache,
19760+ ktype,
19761 per_cpu(ici_cache_kobject, cpu),
19762 "index%1lu", i);
19763 if (unlikely(retval)) {
19764diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19765index 87a65c9..92fcce6 100644
19766--- a/arch/x86/kernel/cpu/mcheck/mce.c
19767+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19768@@ -45,6 +45,7 @@
19769 #include <asm/processor.h>
19770 #include <asm/mce.h>
19771 #include <asm/msr.h>
19772+#include <asm/local.h>
19773
19774 #include "mce-internal.h"
19775
19776@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19777 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19778 m->cs, m->ip);
19779
19780- if (m->cs == __KERNEL_CS)
19781+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19782 print_symbol("{%s}", m->ip);
19783 pr_cont("\n");
19784 }
19785@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19786
19787 #define PANIC_TIMEOUT 5 /* 5 seconds */
19788
19789-static atomic_t mce_paniced;
19790+static atomic_unchecked_t mce_paniced;
19791
19792 static int fake_panic;
19793-static atomic_t mce_fake_paniced;
19794+static atomic_unchecked_t mce_fake_paniced;
19795
19796 /* Panic in progress. Enable interrupts and wait for final IPI */
19797 static void wait_for_panic(void)
19798@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19799 /*
19800 * Make sure only one CPU runs in machine check panic
19801 */
19802- if (atomic_inc_return(&mce_paniced) > 1)
19803+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19804 wait_for_panic();
19805 barrier();
19806
19807@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19808 console_verbose();
19809 } else {
19810 /* Don't log too much for fake panic */
19811- if (atomic_inc_return(&mce_fake_paniced) > 1)
19812+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19813 return;
19814 }
19815 /* First print corrected ones that are still unlogged */
19816@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19817 if (!fake_panic) {
19818 if (panic_timeout == 0)
19819 panic_timeout = mca_cfg.panic_timeout;
19820- panic(msg);
19821+ panic("%s", msg);
19822 } else
19823 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19824 }
19825@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19826 * might have been modified by someone else.
19827 */
19828 rmb();
19829- if (atomic_read(&mce_paniced))
19830+ if (atomic_read_unchecked(&mce_paniced))
19831 wait_for_panic();
19832 if (!mca_cfg.monarch_timeout)
19833 goto out;
19834@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19835 }
19836
19837 /* Call the installed machine check handler for this CPU setup. */
19838-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19839+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19840 unexpected_machine_check;
19841
19842 /*
19843@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19844 return;
19845 }
19846
19847+ pax_open_kernel();
19848 machine_check_vector = do_machine_check;
19849+ pax_close_kernel();
19850
19851 __mcheck_cpu_init_generic();
19852 __mcheck_cpu_init_vendor(c);
19853@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19854 */
19855
19856 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19857-static int mce_chrdev_open_count; /* #times opened */
19858+static local_t mce_chrdev_open_count; /* #times opened */
19859 static int mce_chrdev_open_exclu; /* already open exclusive? */
19860
19861 static int mce_chrdev_open(struct inode *inode, struct file *file)
19862@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19863 spin_lock(&mce_chrdev_state_lock);
19864
19865 if (mce_chrdev_open_exclu ||
19866- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19867+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19868 spin_unlock(&mce_chrdev_state_lock);
19869
19870 return -EBUSY;
19871@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19872
19873 if (file->f_flags & O_EXCL)
19874 mce_chrdev_open_exclu = 1;
19875- mce_chrdev_open_count++;
19876+ local_inc(&mce_chrdev_open_count);
19877
19878 spin_unlock(&mce_chrdev_state_lock);
19879
19880@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19881 {
19882 spin_lock(&mce_chrdev_state_lock);
19883
19884- mce_chrdev_open_count--;
19885+ local_dec(&mce_chrdev_open_count);
19886 mce_chrdev_open_exclu = 0;
19887
19888 spin_unlock(&mce_chrdev_state_lock);
19889@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19890
19891 for (i = 0; i < mca_cfg.banks; i++) {
19892 struct mce_bank *b = &mce_banks[i];
19893- struct device_attribute *a = &b->attr;
19894+ device_attribute_no_const *a = &b->attr;
19895
19896 sysfs_attr_init(&a->attr);
19897 a->attr.name = b->attrname;
19898@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19899 static void mce_reset(void)
19900 {
19901 cpu_missing = 0;
19902- atomic_set(&mce_fake_paniced, 0);
19903+ atomic_set_unchecked(&mce_fake_paniced, 0);
19904 atomic_set(&mce_executing, 0);
19905 atomic_set(&mce_callin, 0);
19906 atomic_set(&global_nwo, 0);
19907diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19908index 1c044b1..37a2a43 100644
19909--- a/arch/x86/kernel/cpu/mcheck/p5.c
19910+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19911@@ -11,6 +11,7 @@
19912 #include <asm/processor.h>
19913 #include <asm/mce.h>
19914 #include <asm/msr.h>
19915+#include <asm/pgtable.h>
19916
19917 /* By default disabled */
19918 int mce_p5_enabled __read_mostly;
19919@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19920 if (!cpu_has(c, X86_FEATURE_MCE))
19921 return;
19922
19923+ pax_open_kernel();
19924 machine_check_vector = pentium_machine_check;
19925+ pax_close_kernel();
19926 /* Make sure the vector pointer is visible before we enable MCEs: */
19927 wmb();
19928
19929diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19930index e9a701a..35317d6 100644
19931--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19932+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19933@@ -10,6 +10,7 @@
19934 #include <asm/processor.h>
19935 #include <asm/mce.h>
19936 #include <asm/msr.h>
19937+#include <asm/pgtable.h>
19938
19939 /* Machine check handler for WinChip C6: */
19940 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19941@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19942 {
19943 u32 lo, hi;
19944
19945+ pax_open_kernel();
19946 machine_check_vector = winchip_machine_check;
19947+ pax_close_kernel();
19948 /* Make sure the vector pointer is visible before we enable MCEs: */
19949 wmb();
19950
19951diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19952index f961de9..8a9d332 100644
19953--- a/arch/x86/kernel/cpu/mtrr/main.c
19954+++ b/arch/x86/kernel/cpu/mtrr/main.c
19955@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19956 u64 size_or_mask, size_and_mask;
19957 static bool mtrr_aps_delayed_init;
19958
19959-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19960+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19961
19962 const struct mtrr_ops *mtrr_if;
19963
19964diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19965index df5e41f..816c719 100644
19966--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19967+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19968@@ -25,7 +25,7 @@ struct mtrr_ops {
19969 int (*validate_add_page)(unsigned long base, unsigned long size,
19970 unsigned int type);
19971 int (*have_wrcomb)(void);
19972-};
19973+} __do_const;
19974
19975 extern int generic_get_free_region(unsigned long base, unsigned long size,
19976 int replace_reg);
19977diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19978index a7c7305..b9705ab 100644
19979--- a/arch/x86/kernel/cpu/perf_event.c
19980+++ b/arch/x86/kernel/cpu/perf_event.c
19981@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19982 pr_info("no hardware sampling interrupt available.\n");
19983 }
19984
19985-static struct attribute_group x86_pmu_format_group = {
19986+static attribute_group_no_const x86_pmu_format_group = {
19987 .name = "format",
19988 .attrs = NULL,
19989 };
19990@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19991 NULL,
19992 };
19993
19994-static struct attribute_group x86_pmu_events_group = {
19995+static attribute_group_no_const x86_pmu_events_group = {
19996 .name = "events",
19997 .attrs = events_attr,
19998 };
19999@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
20000 if (idx > GDT_ENTRIES)
20001 return 0;
20002
20003- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20004+ desc = get_cpu_gdt_table(smp_processor_id());
20005 }
20006
20007 return get_desc_base(desc + idx);
20008@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20009 break;
20010
20011 perf_callchain_store(entry, frame.return_address);
20012- fp = frame.next_frame;
20013+ fp = (const void __force_user *)frame.next_frame;
20014 }
20015 }
20016
20017diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20018index 639d128..e92d7e5 100644
20019--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20020+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20021@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20022 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20023 {
20024 struct attribute **attrs;
20025- struct attribute_group *attr_group;
20026+ attribute_group_no_const *attr_group;
20027 int i = 0, j;
20028
20029 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20030diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20031index a45d8d4..8abd32c 100644
20032--- a/arch/x86/kernel/cpu/perf_event_intel.c
20033+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20034@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20035 * v2 and above have a perf capabilities MSR
20036 */
20037 if (version > 1) {
20038- u64 capabilities;
20039+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20040
20041- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20042- x86_pmu.intel_cap.capabilities = capabilities;
20043+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20044+ x86_pmu.intel_cap.capabilities = capabilities;
20045 }
20046
20047 intel_ds_init();
20048diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20049index 1fb6c72..f5fa2a3 100644
20050--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20051+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20052@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20053 static int __init uncore_type_init(struct intel_uncore_type *type)
20054 {
20055 struct intel_uncore_pmu *pmus;
20056- struct attribute_group *attr_group;
20057+ attribute_group_no_const *attr_group;
20058 struct attribute **attrs;
20059 int i, j;
20060
20061diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20062index 47b3d00c..2cf1751 100644
20063--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20064+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20065@@ -488,7 +488,7 @@ struct intel_uncore_box {
20066 struct uncore_event_desc {
20067 struct kobj_attribute attr;
20068 const char *config;
20069-};
20070+} __do_const;
20071
20072 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20073 { \
20074diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20075index 7d9481c..99c7e4b 100644
20076--- a/arch/x86/kernel/cpuid.c
20077+++ b/arch/x86/kernel/cpuid.c
20078@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20079 return notifier_from_errno(err);
20080 }
20081
20082-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20083+static struct notifier_block cpuid_class_cpu_notifier =
20084 {
20085 .notifier_call = cpuid_class_cpu_callback,
20086 };
20087diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20088index 74467fe..18793d5 100644
20089--- a/arch/x86/kernel/crash.c
20090+++ b/arch/x86/kernel/crash.c
20091@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20092 {
20093 #ifdef CONFIG_X86_32
20094 struct pt_regs fixed_regs;
20095-#endif
20096
20097-#ifdef CONFIG_X86_32
20098- if (!user_mode_vm(regs)) {
20099+ if (!user_mode(regs)) {
20100 crash_fixup_ss_esp(&fixed_regs, regs);
20101 regs = &fixed_regs;
20102 }
20103diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20104index afa64ad..dce67dd 100644
20105--- a/arch/x86/kernel/crash_dump_64.c
20106+++ b/arch/x86/kernel/crash_dump_64.c
20107@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20108 return -ENOMEM;
20109
20110 if (userbuf) {
20111- if (copy_to_user(buf, vaddr + offset, csize)) {
20112+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20113 iounmap(vaddr);
20114 return -EFAULT;
20115 }
20116diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20117index 5d3fe8d..02e1429 100644
20118--- a/arch/x86/kernel/doublefault.c
20119+++ b/arch/x86/kernel/doublefault.c
20120@@ -13,7 +13,7 @@
20121
20122 #define DOUBLEFAULT_STACKSIZE (1024)
20123 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20124-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20125+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20126
20127 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20128
20129@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20130 unsigned long gdt, tss;
20131
20132 native_store_gdt(&gdt_desc);
20133- gdt = gdt_desc.address;
20134+ gdt = (unsigned long)gdt_desc.address;
20135
20136 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20137
20138@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20139 /* 0x2 bit is always set */
20140 .flags = X86_EFLAGS_SF | 0x2,
20141 .sp = STACK_START,
20142- .es = __USER_DS,
20143+ .es = __KERNEL_DS,
20144 .cs = __KERNEL_CS,
20145 .ss = __KERNEL_DS,
20146- .ds = __USER_DS,
20147+ .ds = __KERNEL_DS,
20148 .fs = __KERNEL_PERCPU,
20149
20150 .__cr3 = __pa_nodebug(swapper_pg_dir),
20151diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20152index deb6421..76bbc12 100644
20153--- a/arch/x86/kernel/dumpstack.c
20154+++ b/arch/x86/kernel/dumpstack.c
20155@@ -2,6 +2,9 @@
20156 * Copyright (C) 1991, 1992 Linus Torvalds
20157 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20158 */
20159+#ifdef CONFIG_GRKERNSEC_HIDESYM
20160+#define __INCLUDED_BY_HIDESYM 1
20161+#endif
20162 #include <linux/kallsyms.h>
20163 #include <linux/kprobes.h>
20164 #include <linux/uaccess.h>
20165@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20166 static void
20167 print_ftrace_graph_addr(unsigned long addr, void *data,
20168 const struct stacktrace_ops *ops,
20169- struct thread_info *tinfo, int *graph)
20170+ struct task_struct *task, int *graph)
20171 {
20172- struct task_struct *task;
20173 unsigned long ret_addr;
20174 int index;
20175
20176 if (addr != (unsigned long)return_to_handler)
20177 return;
20178
20179- task = tinfo->task;
20180 index = task->curr_ret_stack;
20181
20182 if (!task->ret_stack || index < *graph)
20183@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20184 static inline void
20185 print_ftrace_graph_addr(unsigned long addr, void *data,
20186 const struct stacktrace_ops *ops,
20187- struct thread_info *tinfo, int *graph)
20188+ struct task_struct *task, int *graph)
20189 { }
20190 #endif
20191
20192@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20193 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20194 */
20195
20196-static inline int valid_stack_ptr(struct thread_info *tinfo,
20197- void *p, unsigned int size, void *end)
20198+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20199 {
20200- void *t = tinfo;
20201 if (end) {
20202 if (p < end && p >= (end-THREAD_SIZE))
20203 return 1;
20204@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20205 }
20206
20207 unsigned long
20208-print_context_stack(struct thread_info *tinfo,
20209+print_context_stack(struct task_struct *task, void *stack_start,
20210 unsigned long *stack, unsigned long bp,
20211 const struct stacktrace_ops *ops, void *data,
20212 unsigned long *end, int *graph)
20213 {
20214 struct stack_frame *frame = (struct stack_frame *)bp;
20215
20216- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20217+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20218 unsigned long addr;
20219
20220 addr = *stack;
20221@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20222 } else {
20223 ops->address(data, addr, 0);
20224 }
20225- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20226+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20227 }
20228 stack++;
20229 }
20230@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20231 EXPORT_SYMBOL_GPL(print_context_stack);
20232
20233 unsigned long
20234-print_context_stack_bp(struct thread_info *tinfo,
20235+print_context_stack_bp(struct task_struct *task, void *stack_start,
20236 unsigned long *stack, unsigned long bp,
20237 const struct stacktrace_ops *ops, void *data,
20238 unsigned long *end, int *graph)
20239@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20240 struct stack_frame *frame = (struct stack_frame *)bp;
20241 unsigned long *ret_addr = &frame->return_address;
20242
20243- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20244+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20245 unsigned long addr = *ret_addr;
20246
20247 if (!__kernel_text_address(addr))
20248@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20249 ops->address(data, addr, 1);
20250 frame = frame->next_frame;
20251 ret_addr = &frame->return_address;
20252- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20253+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20254 }
20255
20256 return (unsigned long)frame;
20257@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20258 static void print_trace_address(void *data, unsigned long addr, int reliable)
20259 {
20260 touch_nmi_watchdog();
20261- printk(data);
20262+ printk("%s", (char *)data);
20263 printk_address(addr, reliable);
20264 }
20265
20266@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20267 }
20268 EXPORT_SYMBOL_GPL(oops_begin);
20269
20270+extern void gr_handle_kernel_exploit(void);
20271+
20272 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20273 {
20274 if (regs && kexec_should_crash(current))
20275@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20276 panic("Fatal exception in interrupt");
20277 if (panic_on_oops)
20278 panic("Fatal exception");
20279- do_exit(signr);
20280+
20281+ gr_handle_kernel_exploit();
20282+
20283+ do_group_exit(signr);
20284 }
20285
20286 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20287@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20288 print_modules();
20289 show_regs(regs);
20290 #ifdef CONFIG_X86_32
20291- if (user_mode_vm(regs)) {
20292+ if (user_mode(regs)) {
20293 sp = regs->sp;
20294 ss = regs->ss & 0xffff;
20295 } else {
20296@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20297 unsigned long flags = oops_begin();
20298 int sig = SIGSEGV;
20299
20300- if (!user_mode_vm(regs))
20301+ if (!user_mode(regs))
20302 report_bug(regs->ip, regs);
20303
20304 if (__die(str, regs, err))
20305diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20306index f2a1770..540657f 100644
20307--- a/arch/x86/kernel/dumpstack_32.c
20308+++ b/arch/x86/kernel/dumpstack_32.c
20309@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20310 bp = stack_frame(task, regs);
20311
20312 for (;;) {
20313- struct thread_info *context;
20314+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20315
20316- context = (struct thread_info *)
20317- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20318- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20319+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20320
20321- stack = (unsigned long *)context->previous_esp;
20322- if (!stack)
20323+ if (stack_start == task_stack_page(task))
20324 break;
20325+ stack = *(unsigned long **)stack_start;
20326 if (ops->stack(data, "IRQ") < 0)
20327 break;
20328 touch_nmi_watchdog();
20329@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20330 int i;
20331
20332 show_regs_print_info(KERN_EMERG);
20333- __show_regs(regs, !user_mode_vm(regs));
20334+ __show_regs(regs, !user_mode(regs));
20335
20336 /*
20337 * When in-kernel, we also print out the stack and code at the
20338 * time of the fault..
20339 */
20340- if (!user_mode_vm(regs)) {
20341+ if (!user_mode(regs)) {
20342 unsigned int code_prologue = code_bytes * 43 / 64;
20343 unsigned int code_len = code_bytes;
20344 unsigned char c;
20345 u8 *ip;
20346+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20347
20348 pr_emerg("Stack:\n");
20349 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20350
20351 pr_emerg("Code:");
20352
20353- ip = (u8 *)regs->ip - code_prologue;
20354+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20355 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20356 /* try starting at IP */
20357- ip = (u8 *)regs->ip;
20358+ ip = (u8 *)regs->ip + cs_base;
20359 code_len = code_len - code_prologue + 1;
20360 }
20361 for (i = 0; i < code_len; i++, ip++) {
20362@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20363 pr_cont(" Bad EIP value.");
20364 break;
20365 }
20366- if (ip == (u8 *)regs->ip)
20367+ if (ip == (u8 *)regs->ip + cs_base)
20368 pr_cont(" <%02x>", c);
20369 else
20370 pr_cont(" %02x", c);
20371@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20372 {
20373 unsigned short ud2;
20374
20375+ ip = ktla_ktva(ip);
20376 if (ip < PAGE_OFFSET)
20377 return 0;
20378 if (probe_kernel_address((unsigned short *)ip, ud2))
20379@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20380
20381 return ud2 == 0x0b0f;
20382 }
20383+
20384+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20385+void pax_check_alloca(unsigned long size)
20386+{
20387+ unsigned long sp = (unsigned long)&sp, stack_left;
20388+
20389+ /* all kernel stacks are of the same size */
20390+ stack_left = sp & (THREAD_SIZE - 1);
20391+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20392+}
20393+EXPORT_SYMBOL(pax_check_alloca);
20394+#endif
20395diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20396index addb207..99635fa 100644
20397--- a/arch/x86/kernel/dumpstack_64.c
20398+++ b/arch/x86/kernel/dumpstack_64.c
20399@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20400 unsigned long *irq_stack_end =
20401 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20402 unsigned used = 0;
20403- struct thread_info *tinfo;
20404 int graph = 0;
20405 unsigned long dummy;
20406+ void *stack_start;
20407
20408 if (!task)
20409 task = current;
20410@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20411 * current stack address. If the stacks consist of nested
20412 * exceptions
20413 */
20414- tinfo = task_thread_info(task);
20415 for (;;) {
20416 char *id;
20417 unsigned long *estack_end;
20418+
20419 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20420 &used, &id);
20421
20422@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20423 if (ops->stack(data, id) < 0)
20424 break;
20425
20426- bp = ops->walk_stack(tinfo, stack, bp, ops,
20427+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20428 data, estack_end, &graph);
20429 ops->stack(data, "<EOE>");
20430 /*
20431@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20432 * second-to-last pointer (index -2 to end) in the
20433 * exception stack:
20434 */
20435+ if ((u16)estack_end[-1] != __KERNEL_DS)
20436+ goto out;
20437 stack = (unsigned long *) estack_end[-2];
20438 continue;
20439 }
20440@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20441 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20442 if (ops->stack(data, "IRQ") < 0)
20443 break;
20444- bp = ops->walk_stack(tinfo, stack, bp,
20445+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20446 ops, data, irq_stack_end, &graph);
20447 /*
20448 * We link to the next stack (which would be
20449@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20450 /*
20451 * This handles the process stack:
20452 */
20453- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20454+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20455+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20456+out:
20457 put_cpu();
20458 }
20459 EXPORT_SYMBOL(dump_trace);
20460@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20461
20462 return ud2 == 0x0b0f;
20463 }
20464+
20465+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20466+void pax_check_alloca(unsigned long size)
20467+{
20468+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20469+ unsigned cpu, used;
20470+ char *id;
20471+
20472+ /* check the process stack first */
20473+ stack_start = (unsigned long)task_stack_page(current);
20474+ stack_end = stack_start + THREAD_SIZE;
20475+ if (likely(stack_start <= sp && sp < stack_end)) {
20476+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20477+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20478+ return;
20479+ }
20480+
20481+ cpu = get_cpu();
20482+
20483+ /* check the irq stacks */
20484+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20485+ stack_start = stack_end - IRQ_STACK_SIZE;
20486+ if (stack_start <= sp && sp < stack_end) {
20487+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20488+ put_cpu();
20489+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20490+ return;
20491+ }
20492+
20493+ /* check the exception stacks */
20494+ used = 0;
20495+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20496+ stack_start = stack_end - EXCEPTION_STKSZ;
20497+ if (stack_end && stack_start <= sp && sp < stack_end) {
20498+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20499+ put_cpu();
20500+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20501+ return;
20502+ }
20503+
20504+ put_cpu();
20505+
20506+ /* unknown stack */
20507+ BUG();
20508+}
20509+EXPORT_SYMBOL(pax_check_alloca);
20510+#endif
20511diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20512index 174da5f..5e55606 100644
20513--- a/arch/x86/kernel/e820.c
20514+++ b/arch/x86/kernel/e820.c
20515@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20516
20517 static void early_panic(char *msg)
20518 {
20519- early_printk(msg);
20520- panic(msg);
20521+ early_printk("%s", msg);
20522+ panic("%s", msg);
20523 }
20524
20525 static int userdef __initdata;
20526diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20527index d15f575..d692043 100644
20528--- a/arch/x86/kernel/early_printk.c
20529+++ b/arch/x86/kernel/early_printk.c
20530@@ -7,6 +7,7 @@
20531 #include <linux/pci_regs.h>
20532 #include <linux/pci_ids.h>
20533 #include <linux/errno.h>
20534+#include <linux/sched.h>
20535 #include <asm/io.h>
20536 #include <asm/processor.h>
20537 #include <asm/fcntl.h>
20538diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20539index 2cfbc3a..b756682 100644
20540--- a/arch/x86/kernel/entry_32.S
20541+++ b/arch/x86/kernel/entry_32.S
20542@@ -177,13 +177,153 @@
20543 /*CFI_REL_OFFSET gs, PT_GS*/
20544 .endm
20545 .macro SET_KERNEL_GS reg
20546+
20547+#ifdef CONFIG_CC_STACKPROTECTOR
20548 movl $(__KERNEL_STACK_CANARY), \reg
20549+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20550+ movl $(__USER_DS), \reg
20551+#else
20552+ xorl \reg, \reg
20553+#endif
20554+
20555 movl \reg, %gs
20556 .endm
20557
20558 #endif /* CONFIG_X86_32_LAZY_GS */
20559
20560-.macro SAVE_ALL
20561+.macro pax_enter_kernel
20562+#ifdef CONFIG_PAX_KERNEXEC
20563+ call pax_enter_kernel
20564+#endif
20565+.endm
20566+
20567+.macro pax_exit_kernel
20568+#ifdef CONFIG_PAX_KERNEXEC
20569+ call pax_exit_kernel
20570+#endif
20571+.endm
20572+
20573+#ifdef CONFIG_PAX_KERNEXEC
20574+ENTRY(pax_enter_kernel)
20575+#ifdef CONFIG_PARAVIRT
20576+ pushl %eax
20577+ pushl %ecx
20578+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20579+ mov %eax, %esi
20580+#else
20581+ mov %cr0, %esi
20582+#endif
20583+ bts $16, %esi
20584+ jnc 1f
20585+ mov %cs, %esi
20586+ cmp $__KERNEL_CS, %esi
20587+ jz 3f
20588+ ljmp $__KERNEL_CS, $3f
20589+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20590+2:
20591+#ifdef CONFIG_PARAVIRT
20592+ mov %esi, %eax
20593+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20594+#else
20595+ mov %esi, %cr0
20596+#endif
20597+3:
20598+#ifdef CONFIG_PARAVIRT
20599+ popl %ecx
20600+ popl %eax
20601+#endif
20602+ ret
20603+ENDPROC(pax_enter_kernel)
20604+
20605+ENTRY(pax_exit_kernel)
20606+#ifdef CONFIG_PARAVIRT
20607+ pushl %eax
20608+ pushl %ecx
20609+#endif
20610+ mov %cs, %esi
20611+ cmp $__KERNEXEC_KERNEL_CS, %esi
20612+ jnz 2f
20613+#ifdef CONFIG_PARAVIRT
20614+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20615+ mov %eax, %esi
20616+#else
20617+ mov %cr0, %esi
20618+#endif
20619+ btr $16, %esi
20620+ ljmp $__KERNEL_CS, $1f
20621+1:
20622+#ifdef CONFIG_PARAVIRT
20623+ mov %esi, %eax
20624+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20625+#else
20626+ mov %esi, %cr0
20627+#endif
20628+2:
20629+#ifdef CONFIG_PARAVIRT
20630+ popl %ecx
20631+ popl %eax
20632+#endif
20633+ ret
20634+ENDPROC(pax_exit_kernel)
20635+#endif
20636+
20637+ .macro pax_erase_kstack
20638+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20639+ call pax_erase_kstack
20640+#endif
20641+ .endm
20642+
20643+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20644+/*
20645+ * ebp: thread_info
20646+ */
20647+ENTRY(pax_erase_kstack)
20648+ pushl %edi
20649+ pushl %ecx
20650+ pushl %eax
20651+
20652+ mov TI_lowest_stack(%ebp), %edi
20653+ mov $-0xBEEF, %eax
20654+ std
20655+
20656+1: mov %edi, %ecx
20657+ and $THREAD_SIZE_asm - 1, %ecx
20658+ shr $2, %ecx
20659+ repne scasl
20660+ jecxz 2f
20661+
20662+ cmp $2*16, %ecx
20663+ jc 2f
20664+
20665+ mov $2*16, %ecx
20666+ repe scasl
20667+ jecxz 2f
20668+ jne 1b
20669+
20670+2: cld
20671+ mov %esp, %ecx
20672+ sub %edi, %ecx
20673+
20674+ cmp $THREAD_SIZE_asm, %ecx
20675+ jb 3f
20676+ ud2
20677+3:
20678+
20679+ shr $2, %ecx
20680+ rep stosl
20681+
20682+ mov TI_task_thread_sp0(%ebp), %edi
20683+ sub $128, %edi
20684+ mov %edi, TI_lowest_stack(%ebp)
20685+
20686+ popl %eax
20687+ popl %ecx
20688+ popl %edi
20689+ ret
20690+ENDPROC(pax_erase_kstack)
20691+#endif
20692+
20693+.macro __SAVE_ALL _DS
20694 cld
20695 PUSH_GS
20696 pushl_cfi %fs
20697@@ -206,7 +346,7 @@
20698 CFI_REL_OFFSET ecx, 0
20699 pushl_cfi %ebx
20700 CFI_REL_OFFSET ebx, 0
20701- movl $(__USER_DS), %edx
20702+ movl $\_DS, %edx
20703 movl %edx, %ds
20704 movl %edx, %es
20705 movl $(__KERNEL_PERCPU), %edx
20706@@ -214,6 +354,15 @@
20707 SET_KERNEL_GS %edx
20708 .endm
20709
20710+.macro SAVE_ALL
20711+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20712+ __SAVE_ALL __KERNEL_DS
20713+ pax_enter_kernel
20714+#else
20715+ __SAVE_ALL __USER_DS
20716+#endif
20717+.endm
20718+
20719 .macro RESTORE_INT_REGS
20720 popl_cfi %ebx
20721 CFI_RESTORE ebx
20722@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20723 popfl_cfi
20724 jmp syscall_exit
20725 CFI_ENDPROC
20726-END(ret_from_fork)
20727+ENDPROC(ret_from_fork)
20728
20729 ENTRY(ret_from_kernel_thread)
20730 CFI_STARTPROC
20731@@ -344,7 +493,15 @@ ret_from_intr:
20732 andl $SEGMENT_RPL_MASK, %eax
20733 #endif
20734 cmpl $USER_RPL, %eax
20735+
20736+#ifdef CONFIG_PAX_KERNEXEC
20737+ jae resume_userspace
20738+
20739+ pax_exit_kernel
20740+ jmp resume_kernel
20741+#else
20742 jb resume_kernel # not returning to v8086 or userspace
20743+#endif
20744
20745 ENTRY(resume_userspace)
20746 LOCKDEP_SYS_EXIT
20747@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20748 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20749 # int/exception return?
20750 jne work_pending
20751- jmp restore_all
20752-END(ret_from_exception)
20753+ jmp restore_all_pax
20754+ENDPROC(ret_from_exception)
20755
20756 #ifdef CONFIG_PREEMPT
20757 ENTRY(resume_kernel)
20758@@ -372,7 +529,7 @@ need_resched:
20759 jz restore_all
20760 call preempt_schedule_irq
20761 jmp need_resched
20762-END(resume_kernel)
20763+ENDPROC(resume_kernel)
20764 #endif
20765 CFI_ENDPROC
20766 /*
20767@@ -406,30 +563,45 @@ sysenter_past_esp:
20768 /*CFI_REL_OFFSET cs, 0*/
20769 /*
20770 * Push current_thread_info()->sysenter_return to the stack.
20771- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20772- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20773 */
20774- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20775+ pushl_cfi $0
20776 CFI_REL_OFFSET eip, 0
20777
20778 pushl_cfi %eax
20779 SAVE_ALL
20780+ GET_THREAD_INFO(%ebp)
20781+ movl TI_sysenter_return(%ebp),%ebp
20782+ movl %ebp,PT_EIP(%esp)
20783 ENABLE_INTERRUPTS(CLBR_NONE)
20784
20785 /*
20786 * Load the potential sixth argument from user stack.
20787 * Careful about security.
20788 */
20789+ movl PT_OLDESP(%esp),%ebp
20790+
20791+#ifdef CONFIG_PAX_MEMORY_UDEREF
20792+ mov PT_OLDSS(%esp),%ds
20793+1: movl %ds:(%ebp),%ebp
20794+ push %ss
20795+ pop %ds
20796+#else
20797 cmpl $__PAGE_OFFSET-3,%ebp
20798 jae syscall_fault
20799 ASM_STAC
20800 1: movl (%ebp),%ebp
20801 ASM_CLAC
20802+#endif
20803+
20804 movl %ebp,PT_EBP(%esp)
20805 _ASM_EXTABLE(1b,syscall_fault)
20806
20807 GET_THREAD_INFO(%ebp)
20808
20809+#ifdef CONFIG_PAX_RANDKSTACK
20810+ pax_erase_kstack
20811+#endif
20812+
20813 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20814 jnz sysenter_audit
20815 sysenter_do_call:
20816@@ -444,12 +616,24 @@ sysenter_do_call:
20817 testl $_TIF_ALLWORK_MASK, %ecx
20818 jne sysexit_audit
20819 sysenter_exit:
20820+
20821+#ifdef CONFIG_PAX_RANDKSTACK
20822+ pushl_cfi %eax
20823+ movl %esp, %eax
20824+ call pax_randomize_kstack
20825+ popl_cfi %eax
20826+#endif
20827+
20828+ pax_erase_kstack
20829+
20830 /* if something modifies registers it must also disable sysexit */
20831 movl PT_EIP(%esp), %edx
20832 movl PT_OLDESP(%esp), %ecx
20833 xorl %ebp,%ebp
20834 TRACE_IRQS_ON
20835 1: mov PT_FS(%esp), %fs
20836+2: mov PT_DS(%esp), %ds
20837+3: mov PT_ES(%esp), %es
20838 PTGS_TO_GS
20839 ENABLE_INTERRUPTS_SYSEXIT
20840
20841@@ -466,6 +650,9 @@ sysenter_audit:
20842 movl %eax,%edx /* 2nd arg: syscall number */
20843 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20844 call __audit_syscall_entry
20845+
20846+ pax_erase_kstack
20847+
20848 pushl_cfi %ebx
20849 movl PT_EAX(%esp),%eax /* reload syscall number */
20850 jmp sysenter_do_call
20851@@ -491,10 +678,16 @@ sysexit_audit:
20852
20853 CFI_ENDPROC
20854 .pushsection .fixup,"ax"
20855-2: movl $0,PT_FS(%esp)
20856+4: movl $0,PT_FS(%esp)
20857+ jmp 1b
20858+5: movl $0,PT_DS(%esp)
20859+ jmp 1b
20860+6: movl $0,PT_ES(%esp)
20861 jmp 1b
20862 .popsection
20863- _ASM_EXTABLE(1b,2b)
20864+ _ASM_EXTABLE(1b,4b)
20865+ _ASM_EXTABLE(2b,5b)
20866+ _ASM_EXTABLE(3b,6b)
20867 PTGS_TO_GS_EX
20868 ENDPROC(ia32_sysenter_target)
20869
20870@@ -509,6 +702,11 @@ ENTRY(system_call)
20871 pushl_cfi %eax # save orig_eax
20872 SAVE_ALL
20873 GET_THREAD_INFO(%ebp)
20874+
20875+#ifdef CONFIG_PAX_RANDKSTACK
20876+ pax_erase_kstack
20877+#endif
20878+
20879 # system call tracing in operation / emulation
20880 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20881 jnz syscall_trace_entry
20882@@ -527,6 +725,15 @@ syscall_exit:
20883 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20884 jne syscall_exit_work
20885
20886+restore_all_pax:
20887+
20888+#ifdef CONFIG_PAX_RANDKSTACK
20889+ movl %esp, %eax
20890+ call pax_randomize_kstack
20891+#endif
20892+
20893+ pax_erase_kstack
20894+
20895 restore_all:
20896 TRACE_IRQS_IRET
20897 restore_all_notrace:
20898@@ -583,14 +790,34 @@ ldt_ss:
20899 * compensating for the offset by changing to the ESPFIX segment with
20900 * a base address that matches for the difference.
20901 */
20902-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20903+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20904 mov %esp, %edx /* load kernel esp */
20905 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20906 mov %dx, %ax /* eax: new kernel esp */
20907 sub %eax, %edx /* offset (low word is 0) */
20908+#ifdef CONFIG_SMP
20909+ movl PER_CPU_VAR(cpu_number), %ebx
20910+ shll $PAGE_SHIFT_asm, %ebx
20911+ addl $cpu_gdt_table, %ebx
20912+#else
20913+ movl $cpu_gdt_table, %ebx
20914+#endif
20915 shr $16, %edx
20916- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20917- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20918+
20919+#ifdef CONFIG_PAX_KERNEXEC
20920+ mov %cr0, %esi
20921+ btr $16, %esi
20922+ mov %esi, %cr0
20923+#endif
20924+
20925+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20926+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20927+
20928+#ifdef CONFIG_PAX_KERNEXEC
20929+ bts $16, %esi
20930+ mov %esi, %cr0
20931+#endif
20932+
20933 pushl_cfi $__ESPFIX_SS
20934 pushl_cfi %eax /* new kernel esp */
20935 /* Disable interrupts, but do not irqtrace this section: we
20936@@ -619,20 +846,18 @@ work_resched:
20937 movl TI_flags(%ebp), %ecx
20938 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20939 # than syscall tracing?
20940- jz restore_all
20941+ jz restore_all_pax
20942 testb $_TIF_NEED_RESCHED, %cl
20943 jnz work_resched
20944
20945 work_notifysig: # deal with pending signals and
20946 # notify-resume requests
20947+ movl %esp, %eax
20948 #ifdef CONFIG_VM86
20949 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20950- movl %esp, %eax
20951 jne work_notifysig_v86 # returning to kernel-space or
20952 # vm86-space
20953 1:
20954-#else
20955- movl %esp, %eax
20956 #endif
20957 TRACE_IRQS_ON
20958 ENABLE_INTERRUPTS(CLBR_NONE)
20959@@ -653,7 +878,7 @@ work_notifysig_v86:
20960 movl %eax, %esp
20961 jmp 1b
20962 #endif
20963-END(work_pending)
20964+ENDPROC(work_pending)
20965
20966 # perform syscall exit tracing
20967 ALIGN
20968@@ -661,11 +886,14 @@ syscall_trace_entry:
20969 movl $-ENOSYS,PT_EAX(%esp)
20970 movl %esp, %eax
20971 call syscall_trace_enter
20972+
20973+ pax_erase_kstack
20974+
20975 /* What it returned is what we'll actually use. */
20976 cmpl $(NR_syscalls), %eax
20977 jnae syscall_call
20978 jmp syscall_exit
20979-END(syscall_trace_entry)
20980+ENDPROC(syscall_trace_entry)
20981
20982 # perform syscall exit tracing
20983 ALIGN
20984@@ -678,21 +906,25 @@ syscall_exit_work:
20985 movl %esp, %eax
20986 call syscall_trace_leave
20987 jmp resume_userspace
20988-END(syscall_exit_work)
20989+ENDPROC(syscall_exit_work)
20990 CFI_ENDPROC
20991
20992 RING0_INT_FRAME # can't unwind into user space anyway
20993 syscall_fault:
20994+#ifdef CONFIG_PAX_MEMORY_UDEREF
20995+ push %ss
20996+ pop %ds
20997+#endif
20998 ASM_CLAC
20999 GET_THREAD_INFO(%ebp)
21000 movl $-EFAULT,PT_EAX(%esp)
21001 jmp resume_userspace
21002-END(syscall_fault)
21003+ENDPROC(syscall_fault)
21004
21005 syscall_badsys:
21006 movl $-ENOSYS,PT_EAX(%esp)
21007 jmp resume_userspace
21008-END(syscall_badsys)
21009+ENDPROC(syscall_badsys)
21010 CFI_ENDPROC
21011 /*
21012 * End of kprobes section
21013@@ -708,8 +940,15 @@ END(syscall_badsys)
21014 * normal stack and adjusts ESP with the matching offset.
21015 */
21016 /* fixup the stack */
21017- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21018- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21019+#ifdef CONFIG_SMP
21020+ movl PER_CPU_VAR(cpu_number), %ebx
21021+ shll $PAGE_SHIFT_asm, %ebx
21022+ addl $cpu_gdt_table, %ebx
21023+#else
21024+ movl $cpu_gdt_table, %ebx
21025+#endif
21026+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21027+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21028 shl $16, %eax
21029 addl %esp, %eax /* the adjusted stack pointer */
21030 pushl_cfi $__KERNEL_DS
21031@@ -762,7 +1001,7 @@ vector=vector+1
21032 .endr
21033 2: jmp common_interrupt
21034 .endr
21035-END(irq_entries_start)
21036+ENDPROC(irq_entries_start)
21037
21038 .previous
21039 END(interrupt)
21040@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21041 pushl_cfi $do_coprocessor_error
21042 jmp error_code
21043 CFI_ENDPROC
21044-END(coprocessor_error)
21045+ENDPROC(coprocessor_error)
21046
21047 ENTRY(simd_coprocessor_error)
21048 RING0_INT_FRAME
21049@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21050 .section .altinstructions,"a"
21051 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21052 .previous
21053-.section .altinstr_replacement,"ax"
21054+.section .altinstr_replacement,"a"
21055 663: pushl $do_simd_coprocessor_error
21056 664:
21057 .previous
21058@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21059 #endif
21060 jmp error_code
21061 CFI_ENDPROC
21062-END(simd_coprocessor_error)
21063+ENDPROC(simd_coprocessor_error)
21064
21065 ENTRY(device_not_available)
21066 RING0_INT_FRAME
21067@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21068 pushl_cfi $do_device_not_available
21069 jmp error_code
21070 CFI_ENDPROC
21071-END(device_not_available)
21072+ENDPROC(device_not_available)
21073
21074 #ifdef CONFIG_PARAVIRT
21075 ENTRY(native_iret)
21076 iret
21077 _ASM_EXTABLE(native_iret, iret_exc)
21078-END(native_iret)
21079+ENDPROC(native_iret)
21080
21081 ENTRY(native_irq_enable_sysexit)
21082 sti
21083 sysexit
21084-END(native_irq_enable_sysexit)
21085+ENDPROC(native_irq_enable_sysexit)
21086 #endif
21087
21088 ENTRY(overflow)
21089@@ -875,7 +1114,7 @@ ENTRY(overflow)
21090 pushl_cfi $do_overflow
21091 jmp error_code
21092 CFI_ENDPROC
21093-END(overflow)
21094+ENDPROC(overflow)
21095
21096 ENTRY(bounds)
21097 RING0_INT_FRAME
21098@@ -884,7 +1123,7 @@ ENTRY(bounds)
21099 pushl_cfi $do_bounds
21100 jmp error_code
21101 CFI_ENDPROC
21102-END(bounds)
21103+ENDPROC(bounds)
21104
21105 ENTRY(invalid_op)
21106 RING0_INT_FRAME
21107@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21108 pushl_cfi $do_invalid_op
21109 jmp error_code
21110 CFI_ENDPROC
21111-END(invalid_op)
21112+ENDPROC(invalid_op)
21113
21114 ENTRY(coprocessor_segment_overrun)
21115 RING0_INT_FRAME
21116@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21117 pushl_cfi $do_coprocessor_segment_overrun
21118 jmp error_code
21119 CFI_ENDPROC
21120-END(coprocessor_segment_overrun)
21121+ENDPROC(coprocessor_segment_overrun)
21122
21123 ENTRY(invalid_TSS)
21124 RING0_EC_FRAME
21125@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21126 pushl_cfi $do_invalid_TSS
21127 jmp error_code
21128 CFI_ENDPROC
21129-END(invalid_TSS)
21130+ENDPROC(invalid_TSS)
21131
21132 ENTRY(segment_not_present)
21133 RING0_EC_FRAME
21134@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21135 pushl_cfi $do_segment_not_present
21136 jmp error_code
21137 CFI_ENDPROC
21138-END(segment_not_present)
21139+ENDPROC(segment_not_present)
21140
21141 ENTRY(stack_segment)
21142 RING0_EC_FRAME
21143@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21144 pushl_cfi $do_stack_segment
21145 jmp error_code
21146 CFI_ENDPROC
21147-END(stack_segment)
21148+ENDPROC(stack_segment)
21149
21150 ENTRY(alignment_check)
21151 RING0_EC_FRAME
21152@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21153 pushl_cfi $do_alignment_check
21154 jmp error_code
21155 CFI_ENDPROC
21156-END(alignment_check)
21157+ENDPROC(alignment_check)
21158
21159 ENTRY(divide_error)
21160 RING0_INT_FRAME
21161@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21162 pushl_cfi $do_divide_error
21163 jmp error_code
21164 CFI_ENDPROC
21165-END(divide_error)
21166+ENDPROC(divide_error)
21167
21168 #ifdef CONFIG_X86_MCE
21169 ENTRY(machine_check)
21170@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21171 pushl_cfi machine_check_vector
21172 jmp error_code
21173 CFI_ENDPROC
21174-END(machine_check)
21175+ENDPROC(machine_check)
21176 #endif
21177
21178 ENTRY(spurious_interrupt_bug)
21179@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21180 pushl_cfi $do_spurious_interrupt_bug
21181 jmp error_code
21182 CFI_ENDPROC
21183-END(spurious_interrupt_bug)
21184+ENDPROC(spurious_interrupt_bug)
21185 /*
21186 * End of kprobes section
21187 */
21188@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21189
21190 ENTRY(mcount)
21191 ret
21192-END(mcount)
21193+ENDPROC(mcount)
21194
21195 ENTRY(ftrace_caller)
21196 cmpl $0, function_trace_stop
21197@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21198 .globl ftrace_stub
21199 ftrace_stub:
21200 ret
21201-END(ftrace_caller)
21202+ENDPROC(ftrace_caller)
21203
21204 ENTRY(ftrace_regs_caller)
21205 pushf /* push flags before compare (in cs location) */
21206@@ -1207,7 +1446,7 @@ trace:
21207 popl %ecx
21208 popl %eax
21209 jmp ftrace_stub
21210-END(mcount)
21211+ENDPROC(mcount)
21212 #endif /* CONFIG_DYNAMIC_FTRACE */
21213 #endif /* CONFIG_FUNCTION_TRACER */
21214
21215@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21216 popl %ecx
21217 popl %eax
21218 ret
21219-END(ftrace_graph_caller)
21220+ENDPROC(ftrace_graph_caller)
21221
21222 .globl return_to_handler
21223 return_to_handler:
21224@@ -1281,15 +1520,18 @@ error_code:
21225 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21226 REG_TO_PTGS %ecx
21227 SET_KERNEL_GS %ecx
21228- movl $(__USER_DS), %ecx
21229+ movl $(__KERNEL_DS), %ecx
21230 movl %ecx, %ds
21231 movl %ecx, %es
21232+
21233+ pax_enter_kernel
21234+
21235 TRACE_IRQS_OFF
21236 movl %esp,%eax # pt_regs pointer
21237 call *%edi
21238 jmp ret_from_exception
21239 CFI_ENDPROC
21240-END(page_fault)
21241+ENDPROC(page_fault)
21242
21243 /*
21244 * Debug traps and NMI can happen at the one SYSENTER instruction
21245@@ -1332,7 +1574,7 @@ debug_stack_correct:
21246 call do_debug
21247 jmp ret_from_exception
21248 CFI_ENDPROC
21249-END(debug)
21250+ENDPROC(debug)
21251
21252 /*
21253 * NMI is doubly nasty. It can happen _while_ we're handling
21254@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21255 xorl %edx,%edx # zero error code
21256 movl %esp,%eax # pt_regs pointer
21257 call do_nmi
21258+
21259+ pax_exit_kernel
21260+
21261 jmp restore_all_notrace
21262 CFI_ENDPROC
21263
21264@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21265 FIXUP_ESPFIX_STACK # %eax == %esp
21266 xorl %edx,%edx # zero error code
21267 call do_nmi
21268+
21269+ pax_exit_kernel
21270+
21271 RESTORE_REGS
21272 lss 12+4(%esp), %esp # back to espfix stack
21273 CFI_ADJUST_CFA_OFFSET -24
21274 jmp irq_return
21275 CFI_ENDPROC
21276-END(nmi)
21277+ENDPROC(nmi)
21278
21279 ENTRY(int3)
21280 RING0_INT_FRAME
21281@@ -1424,14 +1672,14 @@ ENTRY(int3)
21282 call do_int3
21283 jmp ret_from_exception
21284 CFI_ENDPROC
21285-END(int3)
21286+ENDPROC(int3)
21287
21288 ENTRY(general_protection)
21289 RING0_EC_FRAME
21290 pushl_cfi $do_general_protection
21291 jmp error_code
21292 CFI_ENDPROC
21293-END(general_protection)
21294+ENDPROC(general_protection)
21295
21296 #ifdef CONFIG_KVM_GUEST
21297 ENTRY(async_page_fault)
21298@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21299 pushl_cfi $do_async_page_fault
21300 jmp error_code
21301 CFI_ENDPROC
21302-END(async_page_fault)
21303+ENDPROC(async_page_fault)
21304 #endif
21305
21306 /*
21307diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21308index 1b69951..8430a6d 100644
21309--- a/arch/x86/kernel/entry_64.S
21310+++ b/arch/x86/kernel/entry_64.S
21311@@ -59,6 +59,8 @@
21312 #include <asm/context_tracking.h>
21313 #include <asm/smap.h>
21314 #include <linux/err.h>
21315+#include <asm/pgtable.h>
21316+#include <asm/alternative-asm.h>
21317
21318 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21319 #include <linux/elf-em.h>
21320@@ -80,8 +82,9 @@
21321 #ifdef CONFIG_DYNAMIC_FTRACE
21322
21323 ENTRY(function_hook)
21324+ pax_force_retaddr
21325 retq
21326-END(function_hook)
21327+ENDPROC(function_hook)
21328
21329 /* skip is set if stack has been adjusted */
21330 .macro ftrace_caller_setup skip=0
21331@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21332 #endif
21333
21334 GLOBAL(ftrace_stub)
21335+ pax_force_retaddr
21336 retq
21337-END(ftrace_caller)
21338+ENDPROC(ftrace_caller)
21339
21340 ENTRY(ftrace_regs_caller)
21341 /* Save the current flags before compare (in SS location)*/
21342@@ -191,7 +195,7 @@ ftrace_restore_flags:
21343 popfq
21344 jmp ftrace_stub
21345
21346-END(ftrace_regs_caller)
21347+ENDPROC(ftrace_regs_caller)
21348
21349
21350 #else /* ! CONFIG_DYNAMIC_FTRACE */
21351@@ -212,6 +216,7 @@ ENTRY(function_hook)
21352 #endif
21353
21354 GLOBAL(ftrace_stub)
21355+ pax_force_retaddr
21356 retq
21357
21358 trace:
21359@@ -225,12 +230,13 @@ trace:
21360 #endif
21361 subq $MCOUNT_INSN_SIZE, %rdi
21362
21363+ pax_force_fptr ftrace_trace_function
21364 call *ftrace_trace_function
21365
21366 MCOUNT_RESTORE_FRAME
21367
21368 jmp ftrace_stub
21369-END(function_hook)
21370+ENDPROC(function_hook)
21371 #endif /* CONFIG_DYNAMIC_FTRACE */
21372 #endif /* CONFIG_FUNCTION_TRACER */
21373
21374@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21375
21376 MCOUNT_RESTORE_FRAME
21377
21378+ pax_force_retaddr
21379 retq
21380-END(ftrace_graph_caller)
21381+ENDPROC(ftrace_graph_caller)
21382
21383 GLOBAL(return_to_handler)
21384 subq $24, %rsp
21385@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21386 movq 8(%rsp), %rdx
21387 movq (%rsp), %rax
21388 addq $24, %rsp
21389+ pax_force_fptr %rdi
21390 jmp *%rdi
21391+ENDPROC(return_to_handler)
21392 #endif
21393
21394
21395@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21396 ENDPROC(native_usergs_sysret64)
21397 #endif /* CONFIG_PARAVIRT */
21398
21399+ .macro ljmpq sel, off
21400+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21401+ .byte 0x48; ljmp *1234f(%rip)
21402+ .pushsection .rodata
21403+ .align 16
21404+ 1234: .quad \off; .word \sel
21405+ .popsection
21406+#else
21407+ pushq $\sel
21408+ pushq $\off
21409+ lretq
21410+#endif
21411+ .endm
21412+
21413+ .macro pax_enter_kernel
21414+ pax_set_fptr_mask
21415+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21416+ call pax_enter_kernel
21417+#endif
21418+ .endm
21419+
21420+ .macro pax_exit_kernel
21421+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21422+ call pax_exit_kernel
21423+#endif
21424+
21425+ .endm
21426+
21427+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21428+ENTRY(pax_enter_kernel)
21429+ pushq %rdi
21430+
21431+#ifdef CONFIG_PARAVIRT
21432+ PV_SAVE_REGS(CLBR_RDI)
21433+#endif
21434+
21435+#ifdef CONFIG_PAX_KERNEXEC
21436+ GET_CR0_INTO_RDI
21437+ bts $16,%rdi
21438+ jnc 3f
21439+ mov %cs,%edi
21440+ cmp $__KERNEL_CS,%edi
21441+ jnz 2f
21442+1:
21443+#endif
21444+
21445+#ifdef CONFIG_PAX_MEMORY_UDEREF
21446+ 661: jmp 111f
21447+ .pushsection .altinstr_replacement, "a"
21448+ 662: ASM_NOP2
21449+ .popsection
21450+ .pushsection .altinstructions, "a"
21451+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21452+ .popsection
21453+ GET_CR3_INTO_RDI
21454+ cmp $0,%dil
21455+ jnz 112f
21456+ mov $__KERNEL_DS,%edi
21457+ mov %edi,%ss
21458+ jmp 111f
21459+112: cmp $1,%dil
21460+ jz 113f
21461+ ud2
21462+113: sub $4097,%rdi
21463+ bts $63,%rdi
21464+ SET_RDI_INTO_CR3
21465+ mov $__UDEREF_KERNEL_DS,%edi
21466+ mov %edi,%ss
21467+111:
21468+#endif
21469+
21470+#ifdef CONFIG_PARAVIRT
21471+ PV_RESTORE_REGS(CLBR_RDI)
21472+#endif
21473+
21474+ popq %rdi
21475+ pax_force_retaddr
21476+ retq
21477+
21478+#ifdef CONFIG_PAX_KERNEXEC
21479+2: ljmpq __KERNEL_CS,1b
21480+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21481+4: SET_RDI_INTO_CR0
21482+ jmp 1b
21483+#endif
21484+ENDPROC(pax_enter_kernel)
21485+
21486+ENTRY(pax_exit_kernel)
21487+ pushq %rdi
21488+
21489+#ifdef CONFIG_PARAVIRT
21490+ PV_SAVE_REGS(CLBR_RDI)
21491+#endif
21492+
21493+#ifdef CONFIG_PAX_KERNEXEC
21494+ mov %cs,%rdi
21495+ cmp $__KERNEXEC_KERNEL_CS,%edi
21496+ jz 2f
21497+ GET_CR0_INTO_RDI
21498+ bts $16,%rdi
21499+ jnc 4f
21500+1:
21501+#endif
21502+
21503+#ifdef CONFIG_PAX_MEMORY_UDEREF
21504+ 661: jmp 111f
21505+ .pushsection .altinstr_replacement, "a"
21506+ 662: ASM_NOP2
21507+ .popsection
21508+ .pushsection .altinstructions, "a"
21509+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21510+ .popsection
21511+ mov %ss,%edi
21512+ cmp $__UDEREF_KERNEL_DS,%edi
21513+ jnz 111f
21514+ GET_CR3_INTO_RDI
21515+ cmp $0,%dil
21516+ jz 112f
21517+ ud2
21518+112: add $4097,%rdi
21519+ bts $63,%rdi
21520+ SET_RDI_INTO_CR3
21521+ mov $__KERNEL_DS,%edi
21522+ mov %edi,%ss
21523+111:
21524+#endif
21525+
21526+#ifdef CONFIG_PARAVIRT
21527+ PV_RESTORE_REGS(CLBR_RDI);
21528+#endif
21529+
21530+ popq %rdi
21531+ pax_force_retaddr
21532+ retq
21533+
21534+#ifdef CONFIG_PAX_KERNEXEC
21535+2: GET_CR0_INTO_RDI
21536+ btr $16,%rdi
21537+ jnc 4f
21538+ ljmpq __KERNEL_CS,3f
21539+3: SET_RDI_INTO_CR0
21540+ jmp 1b
21541+4: ud2
21542+ jmp 4b
21543+#endif
21544+ENDPROC(pax_exit_kernel)
21545+#endif
21546+
21547+ .macro pax_enter_kernel_user
21548+ pax_set_fptr_mask
21549+#ifdef CONFIG_PAX_MEMORY_UDEREF
21550+ call pax_enter_kernel_user
21551+#endif
21552+ .endm
21553+
21554+ .macro pax_exit_kernel_user
21555+#ifdef CONFIG_PAX_MEMORY_UDEREF
21556+ call pax_exit_kernel_user
21557+#endif
21558+#ifdef CONFIG_PAX_RANDKSTACK
21559+ pushq %rax
21560+ pushq %r11
21561+ call pax_randomize_kstack
21562+ popq %r11
21563+ popq %rax
21564+#endif
21565+ .endm
21566+
21567+#ifdef CONFIG_PAX_MEMORY_UDEREF
21568+ENTRY(pax_enter_kernel_user)
21569+ pushq %rdi
21570+ pushq %rbx
21571+
21572+#ifdef CONFIG_PARAVIRT
21573+ PV_SAVE_REGS(CLBR_RDI)
21574+#endif
21575+
21576+ 661: jmp 111f
21577+ .pushsection .altinstr_replacement, "a"
21578+ 662: ASM_NOP2
21579+ .popsection
21580+ .pushsection .altinstructions, "a"
21581+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21582+ .popsection
21583+ GET_CR3_INTO_RDI
21584+ cmp $1,%dil
21585+ jnz 4f
21586+ sub $4097,%rdi
21587+ bts $63,%rdi
21588+ SET_RDI_INTO_CR3
21589+ jmp 3f
21590+111:
21591+
21592+ GET_CR3_INTO_RDI
21593+ mov %rdi,%rbx
21594+ add $__START_KERNEL_map,%rbx
21595+ sub phys_base(%rip),%rbx
21596+
21597+#ifdef CONFIG_PARAVIRT
21598+ cmpl $0, pv_info+PARAVIRT_enabled
21599+ jz 1f
21600+ pushq %rdi
21601+ i = 0
21602+ .rept USER_PGD_PTRS
21603+ mov i*8(%rbx),%rsi
21604+ mov $0,%sil
21605+ lea i*8(%rbx),%rdi
21606+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21607+ i = i + 1
21608+ .endr
21609+ popq %rdi
21610+ jmp 2f
21611+1:
21612+#endif
21613+
21614+ i = 0
21615+ .rept USER_PGD_PTRS
21616+ movb $0,i*8(%rbx)
21617+ i = i + 1
21618+ .endr
21619+
21620+2: SET_RDI_INTO_CR3
21621+
21622+#ifdef CONFIG_PAX_KERNEXEC
21623+ GET_CR0_INTO_RDI
21624+ bts $16,%rdi
21625+ SET_RDI_INTO_CR0
21626+#endif
21627+
21628+3:
21629+
21630+#ifdef CONFIG_PARAVIRT
21631+ PV_RESTORE_REGS(CLBR_RDI)
21632+#endif
21633+
21634+ popq %rbx
21635+ popq %rdi
21636+ pax_force_retaddr
21637+ retq
21638+4: ud2
21639+ENDPROC(pax_enter_kernel_user)
21640+
21641+ENTRY(pax_exit_kernel_user)
21642+ pushq %rdi
21643+ pushq %rbx
21644+
21645+#ifdef CONFIG_PARAVIRT
21646+ PV_SAVE_REGS(CLBR_RDI)
21647+#endif
21648+
21649+ GET_CR3_INTO_RDI
21650+ 661: jmp 1f
21651+ .pushsection .altinstr_replacement, "a"
21652+ 662: ASM_NOP2
21653+ .popsection
21654+ .pushsection .altinstructions, "a"
21655+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21656+ .popsection
21657+ cmp $0,%dil
21658+ jnz 3f
21659+ add $4097,%rdi
21660+ bts $63,%rdi
21661+ SET_RDI_INTO_CR3
21662+ jmp 2f
21663+1:
21664+
21665+ mov %rdi,%rbx
21666+
21667+#ifdef CONFIG_PAX_KERNEXEC
21668+ GET_CR0_INTO_RDI
21669+ btr $16,%rdi
21670+ jnc 3f
21671+ SET_RDI_INTO_CR0
21672+#endif
21673+
21674+ add $__START_KERNEL_map,%rbx
21675+ sub phys_base(%rip),%rbx
21676+
21677+#ifdef CONFIG_PARAVIRT
21678+ cmpl $0, pv_info+PARAVIRT_enabled
21679+ jz 1f
21680+ i = 0
21681+ .rept USER_PGD_PTRS
21682+ mov i*8(%rbx),%rsi
21683+ mov $0x67,%sil
21684+ lea i*8(%rbx),%rdi
21685+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21686+ i = i + 1
21687+ .endr
21688+ jmp 2f
21689+1:
21690+#endif
21691+
21692+ i = 0
21693+ .rept USER_PGD_PTRS
21694+ movb $0x67,i*8(%rbx)
21695+ i = i + 1
21696+ .endr
21697+2:
21698+
21699+#ifdef CONFIG_PARAVIRT
21700+ PV_RESTORE_REGS(CLBR_RDI)
21701+#endif
21702+
21703+ popq %rbx
21704+ popq %rdi
21705+ pax_force_retaddr
21706+ retq
21707+3: ud2
21708+ENDPROC(pax_exit_kernel_user)
21709+#endif
21710+
21711+ .macro pax_enter_kernel_nmi
21712+ pax_set_fptr_mask
21713+
21714+#ifdef CONFIG_PAX_KERNEXEC
21715+ GET_CR0_INTO_RDI
21716+ bts $16,%rdi
21717+ jc 110f
21718+ SET_RDI_INTO_CR0
21719+ or $2,%ebx
21720+110:
21721+#endif
21722+
21723+#ifdef CONFIG_PAX_MEMORY_UDEREF
21724+ 661: jmp 111f
21725+ .pushsection .altinstr_replacement, "a"
21726+ 662: ASM_NOP2
21727+ .popsection
21728+ .pushsection .altinstructions, "a"
21729+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21730+ .popsection
21731+ GET_CR3_INTO_RDI
21732+ cmp $0,%dil
21733+ jz 111f
21734+ sub $4097,%rdi
21735+ or $4,%ebx
21736+ bts $63,%rdi
21737+ SET_RDI_INTO_CR3
21738+ mov $__UDEREF_KERNEL_DS,%edi
21739+ mov %edi,%ss
21740+111:
21741+#endif
21742+ .endm
21743+
21744+ .macro pax_exit_kernel_nmi
21745+#ifdef CONFIG_PAX_KERNEXEC
21746+ btr $1,%ebx
21747+ jnc 110f
21748+ GET_CR0_INTO_RDI
21749+ btr $16,%rdi
21750+ SET_RDI_INTO_CR0
21751+110:
21752+#endif
21753+
21754+#ifdef CONFIG_PAX_MEMORY_UDEREF
21755+ btr $2,%ebx
21756+ jnc 111f
21757+ GET_CR3_INTO_RDI
21758+ add $4097,%rdi
21759+ bts $63,%rdi
21760+ SET_RDI_INTO_CR3
21761+ mov $__KERNEL_DS,%edi
21762+ mov %edi,%ss
21763+111:
21764+#endif
21765+ .endm
21766+
21767+ .macro pax_erase_kstack
21768+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21769+ call pax_erase_kstack
21770+#endif
21771+ .endm
21772+
21773+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21774+ENTRY(pax_erase_kstack)
21775+ pushq %rdi
21776+ pushq %rcx
21777+ pushq %rax
21778+ pushq %r11
21779+
21780+ GET_THREAD_INFO(%r11)
21781+ mov TI_lowest_stack(%r11), %rdi
21782+ mov $-0xBEEF, %rax
21783+ std
21784+
21785+1: mov %edi, %ecx
21786+ and $THREAD_SIZE_asm - 1, %ecx
21787+ shr $3, %ecx
21788+ repne scasq
21789+ jecxz 2f
21790+
21791+ cmp $2*8, %ecx
21792+ jc 2f
21793+
21794+ mov $2*8, %ecx
21795+ repe scasq
21796+ jecxz 2f
21797+ jne 1b
21798+
21799+2: cld
21800+ mov %esp, %ecx
21801+ sub %edi, %ecx
21802+
21803+ cmp $THREAD_SIZE_asm, %rcx
21804+ jb 3f
21805+ ud2
21806+3:
21807+
21808+ shr $3, %ecx
21809+ rep stosq
21810+
21811+ mov TI_task_thread_sp0(%r11), %rdi
21812+ sub $256, %rdi
21813+ mov %rdi, TI_lowest_stack(%r11)
21814+
21815+ popq %r11
21816+ popq %rax
21817+ popq %rcx
21818+ popq %rdi
21819+ pax_force_retaddr
21820+ ret
21821+ENDPROC(pax_erase_kstack)
21822+#endif
21823
21824 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21825 #ifdef CONFIG_TRACE_IRQFLAGS
21826@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21827 .endm
21828
21829 .macro UNFAKE_STACK_FRAME
21830- addq $8*6, %rsp
21831- CFI_ADJUST_CFA_OFFSET -(6*8)
21832+ addq $8*6 + ARG_SKIP, %rsp
21833+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21834 .endm
21835
21836 /*
21837@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21838 movq %rsp, %rsi
21839
21840 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21841- testl $3, CS-RBP(%rsi)
21842+ testb $3, CS-RBP(%rsi)
21843 je 1f
21844 SWAPGS
21845 /*
21846@@ -498,9 +931,10 @@ ENTRY(save_rest)
21847 movq_cfi r15, R15+16
21848 movq %r11, 8(%rsp) /* return address */
21849 FIXUP_TOP_OF_STACK %r11, 16
21850+ pax_force_retaddr
21851 ret
21852 CFI_ENDPROC
21853-END(save_rest)
21854+ENDPROC(save_rest)
21855
21856 /* save complete stack frame */
21857 .pushsection .kprobes.text, "ax"
21858@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21859 js 1f /* negative -> in kernel */
21860 SWAPGS
21861 xorl %ebx,%ebx
21862-1: ret
21863+1: pax_force_retaddr_bts
21864+ ret
21865 CFI_ENDPROC
21866-END(save_paranoid)
21867+ENDPROC(save_paranoid)
21868 .popsection
21869
21870 /*
21871@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21872
21873 RESTORE_REST
21874
21875- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21876+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21877 jz 1f
21878
21879 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21880@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21881 RESTORE_REST
21882 jmp int_ret_from_sys_call
21883 CFI_ENDPROC
21884-END(ret_from_fork)
21885+ENDPROC(ret_from_fork)
21886
21887 /*
21888 * System call entry. Up to 6 arguments in registers are supported.
21889@@ -608,7 +1043,7 @@ END(ret_from_fork)
21890 ENTRY(system_call)
21891 CFI_STARTPROC simple
21892 CFI_SIGNAL_FRAME
21893- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21894+ CFI_DEF_CFA rsp,0
21895 CFI_REGISTER rip,rcx
21896 /*CFI_REGISTER rflags,r11*/
21897 SWAPGS_UNSAFE_STACK
21898@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21899
21900 movq %rsp,PER_CPU_VAR(old_rsp)
21901 movq PER_CPU_VAR(kernel_stack),%rsp
21902+ SAVE_ARGS 8*6,0
21903+ pax_enter_kernel_user
21904+
21905+#ifdef CONFIG_PAX_RANDKSTACK
21906+ pax_erase_kstack
21907+#endif
21908+
21909 /*
21910 * No need to follow this irqs off/on section - it's straight
21911 * and short:
21912 */
21913 ENABLE_INTERRUPTS(CLBR_NONE)
21914- SAVE_ARGS 8,0
21915 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21916 movq %rcx,RIP-ARGOFFSET(%rsp)
21917 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21918- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21919+ GET_THREAD_INFO(%rcx)
21920+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21921 jnz tracesys
21922 system_call_fastpath:
21923 #if __SYSCALL_MASK == ~0
21924@@ -640,7 +1082,7 @@ system_call_fastpath:
21925 cmpl $__NR_syscall_max,%eax
21926 #endif
21927 ja badsys
21928- movq %r10,%rcx
21929+ movq R10-ARGOFFSET(%rsp),%rcx
21930 call *sys_call_table(,%rax,8) # XXX: rip relative
21931 movq %rax,RAX-ARGOFFSET(%rsp)
21932 /*
21933@@ -654,10 +1096,13 @@ sysret_check:
21934 LOCKDEP_SYS_EXIT
21935 DISABLE_INTERRUPTS(CLBR_NONE)
21936 TRACE_IRQS_OFF
21937- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21938+ GET_THREAD_INFO(%rcx)
21939+ movl TI_flags(%rcx),%edx
21940 andl %edi,%edx
21941 jnz sysret_careful
21942 CFI_REMEMBER_STATE
21943+ pax_exit_kernel_user
21944+ pax_erase_kstack
21945 /*
21946 * sysretq will re-enable interrupts:
21947 */
21948@@ -709,14 +1154,18 @@ badsys:
21949 * jump back to the normal fast path.
21950 */
21951 auditsys:
21952- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21953+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21954 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21955 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21956 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21957 movq %rax,%rsi /* 2nd arg: syscall number */
21958 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21959 call __audit_syscall_entry
21960+
21961+ pax_erase_kstack
21962+
21963 LOAD_ARGS 0 /* reload call-clobbered registers */
21964+ pax_set_fptr_mask
21965 jmp system_call_fastpath
21966
21967 /*
21968@@ -737,7 +1186,7 @@ sysret_audit:
21969 /* Do syscall tracing */
21970 tracesys:
21971 #ifdef CONFIG_AUDITSYSCALL
21972- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21973+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21974 jz auditsys
21975 #endif
21976 SAVE_REST
21977@@ -745,12 +1194,16 @@ tracesys:
21978 FIXUP_TOP_OF_STACK %rdi
21979 movq %rsp,%rdi
21980 call syscall_trace_enter
21981+
21982+ pax_erase_kstack
21983+
21984 /*
21985 * Reload arg registers from stack in case ptrace changed them.
21986 * We don't reload %rax because syscall_trace_enter() returned
21987 * the value it wants us to use in the table lookup.
21988 */
21989 LOAD_ARGS ARGOFFSET, 1
21990+ pax_set_fptr_mask
21991 RESTORE_REST
21992 #if __SYSCALL_MASK == ~0
21993 cmpq $__NR_syscall_max,%rax
21994@@ -759,7 +1212,7 @@ tracesys:
21995 cmpl $__NR_syscall_max,%eax
21996 #endif
21997 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21998- movq %r10,%rcx /* fixup for C */
21999+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
22000 call *sys_call_table(,%rax,8)
22001 movq %rax,RAX-ARGOFFSET(%rsp)
22002 /* Use IRET because user could have changed frame */
22003@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
22004 andl %edi,%edx
22005 jnz int_careful
22006 andl $~TS_COMPAT,TI_status(%rcx)
22007- jmp retint_swapgs
22008+ pax_exit_kernel_user
22009+ pax_erase_kstack
22010+ jmp retint_swapgs_pax
22011
22012 /* Either reschedule or signal or syscall exit tracking needed. */
22013 /* First do a reschedule test. */
22014@@ -826,7 +1281,7 @@ int_restore_rest:
22015 TRACE_IRQS_OFF
22016 jmp int_with_check
22017 CFI_ENDPROC
22018-END(system_call)
22019+ENDPROC(system_call)
22020
22021 .macro FORK_LIKE func
22022 ENTRY(stub_\func)
22023@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22024 DEFAULT_FRAME 0 8 /* offset 8: return address */
22025 call sys_\func
22026 RESTORE_TOP_OF_STACK %r11, 8
22027+ pax_force_retaddr
22028 ret $REST_SKIP /* pop extended registers */
22029 CFI_ENDPROC
22030-END(stub_\func)
22031+ENDPROC(stub_\func)
22032 .endm
22033
22034 .macro FIXED_FRAME label,func
22035@@ -851,9 +1307,10 @@ ENTRY(\label)
22036 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22037 call \func
22038 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22039+ pax_force_retaddr
22040 ret
22041 CFI_ENDPROC
22042-END(\label)
22043+ENDPROC(\label)
22044 .endm
22045
22046 FORK_LIKE clone
22047@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22048 movq_cfi_restore R12+8, r12
22049 movq_cfi_restore RBP+8, rbp
22050 movq_cfi_restore RBX+8, rbx
22051+ pax_force_retaddr
22052 ret $REST_SKIP /* pop extended registers */
22053 CFI_ENDPROC
22054-END(ptregscall_common)
22055+ENDPROC(ptregscall_common)
22056
22057 ENTRY(stub_execve)
22058 CFI_STARTPROC
22059@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22060 RESTORE_REST
22061 jmp int_ret_from_sys_call
22062 CFI_ENDPROC
22063-END(stub_execve)
22064+ENDPROC(stub_execve)
22065
22066 /*
22067 * sigreturn is special because it needs to restore all registers on return.
22068@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22069 RESTORE_REST
22070 jmp int_ret_from_sys_call
22071 CFI_ENDPROC
22072-END(stub_rt_sigreturn)
22073+ENDPROC(stub_rt_sigreturn)
22074
22075 #ifdef CONFIG_X86_X32_ABI
22076 ENTRY(stub_x32_rt_sigreturn)
22077@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22078 RESTORE_REST
22079 jmp int_ret_from_sys_call
22080 CFI_ENDPROC
22081-END(stub_x32_rt_sigreturn)
22082+ENDPROC(stub_x32_rt_sigreturn)
22083
22084 ENTRY(stub_x32_execve)
22085 CFI_STARTPROC
22086@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22087 RESTORE_REST
22088 jmp int_ret_from_sys_call
22089 CFI_ENDPROC
22090-END(stub_x32_execve)
22091+ENDPROC(stub_x32_execve)
22092
22093 #endif
22094
22095@@ -967,7 +1425,7 @@ vector=vector+1
22096 2: jmp common_interrupt
22097 .endr
22098 CFI_ENDPROC
22099-END(irq_entries_start)
22100+ENDPROC(irq_entries_start)
22101
22102 .previous
22103 END(interrupt)
22104@@ -987,6 +1445,16 @@ END(interrupt)
22105 subq $ORIG_RAX-RBP, %rsp
22106 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22107 SAVE_ARGS_IRQ
22108+#ifdef CONFIG_PAX_MEMORY_UDEREF
22109+ testb $3, CS(%rdi)
22110+ jnz 1f
22111+ pax_enter_kernel
22112+ jmp 2f
22113+1: pax_enter_kernel_user
22114+2:
22115+#else
22116+ pax_enter_kernel
22117+#endif
22118 call \func
22119 .endm
22120
22121@@ -1019,7 +1487,7 @@ ret_from_intr:
22122
22123 exit_intr:
22124 GET_THREAD_INFO(%rcx)
22125- testl $3,CS-ARGOFFSET(%rsp)
22126+ testb $3,CS-ARGOFFSET(%rsp)
22127 je retint_kernel
22128
22129 /* Interrupt came from user space */
22130@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22131 * The iretq could re-enable interrupts:
22132 */
22133 DISABLE_INTERRUPTS(CLBR_ANY)
22134+ pax_exit_kernel_user
22135+retint_swapgs_pax:
22136 TRACE_IRQS_IRETQ
22137 SWAPGS
22138 jmp restore_args
22139
22140 retint_restore_args: /* return to kernel space */
22141 DISABLE_INTERRUPTS(CLBR_ANY)
22142+ pax_exit_kernel
22143+ pax_force_retaddr (RIP-ARGOFFSET)
22144 /*
22145 * The iretq could re-enable interrupts:
22146 */
22147@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22148 #endif
22149
22150 CFI_ENDPROC
22151-END(common_interrupt)
22152+ENDPROC(common_interrupt)
22153 /*
22154 * End of kprobes section
22155 */
22156@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22157 interrupt \do_sym
22158 jmp ret_from_intr
22159 CFI_ENDPROC
22160-END(\sym)
22161+ENDPROC(\sym)
22162 .endm
22163
22164 #ifdef CONFIG_TRACING
22165@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22166 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22167 call error_entry
22168 DEFAULT_FRAME 0
22169+#ifdef CONFIG_PAX_MEMORY_UDEREF
22170+ testb $3, CS(%rsp)
22171+ jnz 1f
22172+ pax_enter_kernel
22173+ jmp 2f
22174+1: pax_enter_kernel_user
22175+2:
22176+#else
22177+ pax_enter_kernel
22178+#endif
22179 movq %rsp,%rdi /* pt_regs pointer */
22180 xorl %esi,%esi /* no error code */
22181 call \do_sym
22182 jmp error_exit /* %ebx: no swapgs flag */
22183 CFI_ENDPROC
22184-END(\sym)
22185+ENDPROC(\sym)
22186 .endm
22187
22188 .macro paranoidzeroentry sym do_sym
22189@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22190 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22191 call save_paranoid
22192 TRACE_IRQS_OFF
22193+#ifdef CONFIG_PAX_MEMORY_UDEREF
22194+ testb $3, CS(%rsp)
22195+ jnz 1f
22196+ pax_enter_kernel
22197+ jmp 2f
22198+1: pax_enter_kernel_user
22199+2:
22200+#else
22201+ pax_enter_kernel
22202+#endif
22203 movq %rsp,%rdi /* pt_regs pointer */
22204 xorl %esi,%esi /* no error code */
22205 call \do_sym
22206 jmp paranoid_exit /* %ebx: no swapgs flag */
22207 CFI_ENDPROC
22208-END(\sym)
22209+ENDPROC(\sym)
22210 .endm
22211
22212-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22213+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22214 .macro paranoidzeroentry_ist sym do_sym ist
22215 ENTRY(\sym)
22216 INTR_FRAME
22217@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22218 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22219 call save_paranoid
22220 TRACE_IRQS_OFF_DEBUG
22221+#ifdef CONFIG_PAX_MEMORY_UDEREF
22222+ testb $3, CS(%rsp)
22223+ jnz 1f
22224+ pax_enter_kernel
22225+ jmp 2f
22226+1: pax_enter_kernel_user
22227+2:
22228+#else
22229+ pax_enter_kernel
22230+#endif
22231 movq %rsp,%rdi /* pt_regs pointer */
22232 xorl %esi,%esi /* no error code */
22233+#ifdef CONFIG_SMP
22234+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22235+ lea init_tss(%r12), %r12
22236+#else
22237+ lea init_tss(%rip), %r12
22238+#endif
22239 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22240 call \do_sym
22241 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22242 jmp paranoid_exit /* %ebx: no swapgs flag */
22243 CFI_ENDPROC
22244-END(\sym)
22245+ENDPROC(\sym)
22246 .endm
22247
22248 .macro errorentry sym do_sym
22249@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22250 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22251 call error_entry
22252 DEFAULT_FRAME 0
22253+#ifdef CONFIG_PAX_MEMORY_UDEREF
22254+ testb $3, CS(%rsp)
22255+ jnz 1f
22256+ pax_enter_kernel
22257+ jmp 2f
22258+1: pax_enter_kernel_user
22259+2:
22260+#else
22261+ pax_enter_kernel
22262+#endif
22263 movq %rsp,%rdi /* pt_regs pointer */
22264 movq ORIG_RAX(%rsp),%rsi /* get error code */
22265 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22266 call \do_sym
22267 jmp error_exit /* %ebx: no swapgs flag */
22268 CFI_ENDPROC
22269-END(\sym)
22270+ENDPROC(\sym)
22271 .endm
22272
22273 /* error code is on the stack already */
22274@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22275 call save_paranoid
22276 DEFAULT_FRAME 0
22277 TRACE_IRQS_OFF
22278+#ifdef CONFIG_PAX_MEMORY_UDEREF
22279+ testb $3, CS(%rsp)
22280+ jnz 1f
22281+ pax_enter_kernel
22282+ jmp 2f
22283+1: pax_enter_kernel_user
22284+2:
22285+#else
22286+ pax_enter_kernel
22287+#endif
22288 movq %rsp,%rdi /* pt_regs pointer */
22289 movq ORIG_RAX(%rsp),%rsi /* get error code */
22290 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22291 call \do_sym
22292 jmp paranoid_exit /* %ebx: no swapgs flag */
22293 CFI_ENDPROC
22294-END(\sym)
22295+ENDPROC(\sym)
22296 .endm
22297
22298 zeroentry divide_error do_divide_error
22299@@ -1342,9 +1870,10 @@ gs_change:
22300 2: mfence /* workaround */
22301 SWAPGS
22302 popfq_cfi
22303+ pax_force_retaddr
22304 ret
22305 CFI_ENDPROC
22306-END(native_load_gs_index)
22307+ENDPROC(native_load_gs_index)
22308
22309 _ASM_EXTABLE(gs_change,bad_gs)
22310 .section .fixup,"ax"
22311@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22312 CFI_DEF_CFA_REGISTER rsp
22313 CFI_ADJUST_CFA_OFFSET -8
22314 decl PER_CPU_VAR(irq_count)
22315+ pax_force_retaddr
22316 ret
22317 CFI_ENDPROC
22318-END(call_softirq)
22319+ENDPROC(call_softirq)
22320
22321 #ifdef CONFIG_XEN
22322 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22323@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22324 decl PER_CPU_VAR(irq_count)
22325 jmp error_exit
22326 CFI_ENDPROC
22327-END(xen_do_hypervisor_callback)
22328+ENDPROC(xen_do_hypervisor_callback)
22329
22330 /*
22331 * Hypervisor uses this for application faults while it executes.
22332@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22333 SAVE_ALL
22334 jmp error_exit
22335 CFI_ENDPROC
22336-END(xen_failsafe_callback)
22337+ENDPROC(xen_failsafe_callback)
22338
22339 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22340 xen_hvm_callback_vector xen_evtchn_do_upcall
22341@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22342 DEFAULT_FRAME
22343 DISABLE_INTERRUPTS(CLBR_NONE)
22344 TRACE_IRQS_OFF_DEBUG
22345- testl %ebx,%ebx /* swapgs needed? */
22346+ testl $1,%ebx /* swapgs needed? */
22347 jnz paranoid_restore
22348- testl $3,CS(%rsp)
22349+ testb $3,CS(%rsp)
22350 jnz paranoid_userspace
22351+#ifdef CONFIG_PAX_MEMORY_UDEREF
22352+ pax_exit_kernel
22353+ TRACE_IRQS_IRETQ 0
22354+ SWAPGS_UNSAFE_STACK
22355+ RESTORE_ALL 8
22356+ pax_force_retaddr_bts
22357+ jmp irq_return
22358+#endif
22359 paranoid_swapgs:
22360+#ifdef CONFIG_PAX_MEMORY_UDEREF
22361+ pax_exit_kernel_user
22362+#else
22363+ pax_exit_kernel
22364+#endif
22365 TRACE_IRQS_IRETQ 0
22366 SWAPGS_UNSAFE_STACK
22367 RESTORE_ALL 8
22368 jmp irq_return
22369 paranoid_restore:
22370+ pax_exit_kernel
22371 TRACE_IRQS_IRETQ_DEBUG 0
22372 RESTORE_ALL 8
22373+ pax_force_retaddr_bts
22374 jmp irq_return
22375 paranoid_userspace:
22376 GET_THREAD_INFO(%rcx)
22377@@ -1563,7 +2108,7 @@ paranoid_schedule:
22378 TRACE_IRQS_OFF
22379 jmp paranoid_userspace
22380 CFI_ENDPROC
22381-END(paranoid_exit)
22382+ENDPROC(paranoid_exit)
22383
22384 /*
22385 * Exception entry point. This expects an error code/orig_rax on the stack.
22386@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22387 movq_cfi r14, R14+8
22388 movq_cfi r15, R15+8
22389 xorl %ebx,%ebx
22390- testl $3,CS+8(%rsp)
22391+ testb $3,CS+8(%rsp)
22392 je error_kernelspace
22393 error_swapgs:
22394 SWAPGS
22395 error_sti:
22396 TRACE_IRQS_OFF
22397+ pax_force_retaddr_bts
22398 ret
22399
22400 /*
22401@@ -1622,7 +2168,7 @@ bstep_iret:
22402 movq %rcx,RIP+8(%rsp)
22403 jmp error_swapgs
22404 CFI_ENDPROC
22405-END(error_entry)
22406+ENDPROC(error_entry)
22407
22408
22409 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22410@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22411 DISABLE_INTERRUPTS(CLBR_NONE)
22412 TRACE_IRQS_OFF
22413 GET_THREAD_INFO(%rcx)
22414- testl %eax,%eax
22415+ testl $1,%eax
22416 jne retint_kernel
22417 LOCKDEP_SYS_EXIT_IRQ
22418 movl TI_flags(%rcx),%edx
22419@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22420 jnz retint_careful
22421 jmp retint_swapgs
22422 CFI_ENDPROC
22423-END(error_exit)
22424+ENDPROC(error_exit)
22425
22426 /*
22427 * Test if a given stack is an NMI stack or not.
22428@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22429 * If %cs was not the kernel segment, then the NMI triggered in user
22430 * space, which means it is definitely not nested.
22431 */
22432+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22433+ je 1f
22434 cmpl $__KERNEL_CS, 16(%rsp)
22435 jne first_nmi
22436-
22437+1:
22438 /*
22439 * Check the special variable on the stack to see if NMIs are
22440 * executing.
22441@@ -1736,8 +2284,7 @@ nested_nmi:
22442
22443 1:
22444 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22445- leaq -1*8(%rsp), %rdx
22446- movq %rdx, %rsp
22447+ subq $8, %rsp
22448 CFI_ADJUST_CFA_OFFSET 1*8
22449 leaq -10*8(%rsp), %rdx
22450 pushq_cfi $__KERNEL_DS
22451@@ -1755,6 +2302,7 @@ nested_nmi_out:
22452 CFI_RESTORE rdx
22453
22454 /* No need to check faults here */
22455+# pax_force_retaddr_bts
22456 INTERRUPT_RETURN
22457
22458 CFI_RESTORE_STATE
22459@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22460 */
22461 movq %cr2, %r12
22462
22463+ pax_enter_kernel_nmi
22464+
22465 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22466 movq %rsp,%rdi
22467 movq $-1,%rsi
22468@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22469 movq %r12, %cr2
22470 1:
22471
22472- testl %ebx,%ebx /* swapgs needed? */
22473+ testl $1,%ebx /* swapgs needed? */
22474 jnz nmi_restore
22475 nmi_swapgs:
22476 SWAPGS_UNSAFE_STACK
22477 nmi_restore:
22478+ pax_exit_kernel_nmi
22479 /* Pop the extra iret frame at once */
22480 RESTORE_ALL 6*8
22481+ testb $3, 8(%rsp)
22482+ jnz 1f
22483+ pax_force_retaddr_bts
22484+1:
22485
22486 /* Clear the NMI executing stack variable */
22487 movq $0, 5*8(%rsp)
22488 jmp irq_return
22489 CFI_ENDPROC
22490-END(nmi)
22491+ENDPROC(nmi)
22492
22493 ENTRY(ignore_sysret)
22494 CFI_STARTPROC
22495 mov $-ENOSYS,%eax
22496 sysret
22497 CFI_ENDPROC
22498-END(ignore_sysret)
22499+ENDPROC(ignore_sysret)
22500
22501 /*
22502 * End of kprobes section
22503diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22504index 42a392a..fbbd930 100644
22505--- a/arch/x86/kernel/ftrace.c
22506+++ b/arch/x86/kernel/ftrace.c
22507@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22508 {
22509 unsigned char replaced[MCOUNT_INSN_SIZE];
22510
22511+ ip = ktla_ktva(ip);
22512+
22513 /*
22514 * Note: Due to modules and __init, code can
22515 * disappear and change, we need to protect against faulting
22516@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22517 unsigned char old[MCOUNT_INSN_SIZE], *new;
22518 int ret;
22519
22520- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22521+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22522 new = ftrace_call_replace(ip, (unsigned long)func);
22523
22524 /* See comment above by declaration of modifying_ftrace_code */
22525@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22526 /* Also update the regs callback function */
22527 if (!ret) {
22528 ip = (unsigned long)(&ftrace_regs_call);
22529- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22530+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22531 new = ftrace_call_replace(ip, (unsigned long)func);
22532 ret = ftrace_modify_code(ip, old, new);
22533 }
22534@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22535 * kernel identity mapping to modify code.
22536 */
22537 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22538- ip = (unsigned long)__va(__pa_symbol(ip));
22539+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22540
22541 return probe_kernel_write((void *)ip, val, size);
22542 }
22543@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22544 unsigned char replaced[MCOUNT_INSN_SIZE];
22545 unsigned char brk = BREAKPOINT_INSTRUCTION;
22546
22547- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22548+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22549 return -EFAULT;
22550
22551 /* Make sure it is what we expect it to be */
22552@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22553 return ret;
22554
22555 fail_update:
22556- probe_kernel_write((void *)ip, &old_code[0], 1);
22557+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22558 goto out;
22559 }
22560
22561@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22562 {
22563 unsigned char code[MCOUNT_INSN_SIZE];
22564
22565+ ip = ktla_ktva(ip);
22566+
22567 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22568 return -EFAULT;
22569
22570diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22571index 55b6761..a6456fc 100644
22572--- a/arch/x86/kernel/head64.c
22573+++ b/arch/x86/kernel/head64.c
22574@@ -67,12 +67,12 @@ again:
22575 pgd = *pgd_p;
22576
22577 /*
22578- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22579- * critical -- __PAGE_OFFSET would point us back into the dynamic
22580+ * The use of __early_va rather than __va here is critical:
22581+ * __va would point us back into the dynamic
22582 * range and we might end up looping forever...
22583 */
22584 if (pgd)
22585- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22586+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22587 else {
22588 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22589 reset_early_page_tables();
22590@@ -82,13 +82,13 @@ again:
22591 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22592 for (i = 0; i < PTRS_PER_PUD; i++)
22593 pud_p[i] = 0;
22594- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22595+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22596 }
22597 pud_p += pud_index(address);
22598 pud = *pud_p;
22599
22600 if (pud)
22601- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22602+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22603 else {
22604 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22605 reset_early_page_tables();
22606@@ -98,7 +98,7 @@ again:
22607 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22608 for (i = 0; i < PTRS_PER_PMD; i++)
22609 pmd_p[i] = 0;
22610- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22611+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22612 }
22613 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22614 pmd_p[pmd_index(address)] = pmd;
22615@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22616 if (console_loglevel == 10)
22617 early_printk("Kernel alive\n");
22618
22619- clear_page(init_level4_pgt);
22620 /* set init_level4_pgt kernel high mapping*/
22621 init_level4_pgt[511] = early_level4_pgt[511];
22622
22623diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22624index 5dd87a8..d68b3f4 100644
22625--- a/arch/x86/kernel/head_32.S
22626+++ b/arch/x86/kernel/head_32.S
22627@@ -26,6 +26,12 @@
22628 /* Physical address */
22629 #define pa(X) ((X) - __PAGE_OFFSET)
22630
22631+#ifdef CONFIG_PAX_KERNEXEC
22632+#define ta(X) (X)
22633+#else
22634+#define ta(X) ((X) - __PAGE_OFFSET)
22635+#endif
22636+
22637 /*
22638 * References to members of the new_cpu_data structure.
22639 */
22640@@ -55,11 +61,7 @@
22641 * and small than max_low_pfn, otherwise will waste some page table entries
22642 */
22643
22644-#if PTRS_PER_PMD > 1
22645-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22646-#else
22647-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22648-#endif
22649+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22650
22651 /* Number of possible pages in the lowmem region */
22652 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22653@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22654 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22655
22656 /*
22657+ * Real beginning of normal "text" segment
22658+ */
22659+ENTRY(stext)
22660+ENTRY(_stext)
22661+
22662+/*
22663 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22664 * %esi points to the real-mode code as a 32-bit pointer.
22665 * CS and DS must be 4 GB flat segments, but we don't depend on
22666@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22667 * can.
22668 */
22669 __HEAD
22670+
22671+#ifdef CONFIG_PAX_KERNEXEC
22672+ jmp startup_32
22673+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22674+.fill PAGE_SIZE-5,1,0xcc
22675+#endif
22676+
22677 ENTRY(startup_32)
22678 movl pa(stack_start),%ecx
22679
22680@@ -106,6 +121,59 @@ ENTRY(startup_32)
22681 2:
22682 leal -__PAGE_OFFSET(%ecx),%esp
22683
22684+#ifdef CONFIG_SMP
22685+ movl $pa(cpu_gdt_table),%edi
22686+ movl $__per_cpu_load,%eax
22687+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22688+ rorl $16,%eax
22689+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22690+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22691+ movl $__per_cpu_end - 1,%eax
22692+ subl $__per_cpu_start,%eax
22693+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22694+#endif
22695+
22696+#ifdef CONFIG_PAX_MEMORY_UDEREF
22697+ movl $NR_CPUS,%ecx
22698+ movl $pa(cpu_gdt_table),%edi
22699+1:
22700+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22701+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22702+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22703+ addl $PAGE_SIZE_asm,%edi
22704+ loop 1b
22705+#endif
22706+
22707+#ifdef CONFIG_PAX_KERNEXEC
22708+ movl $pa(boot_gdt),%edi
22709+ movl $__LOAD_PHYSICAL_ADDR,%eax
22710+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22711+ rorl $16,%eax
22712+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22713+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22714+ rorl $16,%eax
22715+
22716+ ljmp $(__BOOT_CS),$1f
22717+1:
22718+
22719+ movl $NR_CPUS,%ecx
22720+ movl $pa(cpu_gdt_table),%edi
22721+ addl $__PAGE_OFFSET,%eax
22722+1:
22723+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22724+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22725+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22726+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22727+ rorl $16,%eax
22728+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22729+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22730+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22731+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22732+ rorl $16,%eax
22733+ addl $PAGE_SIZE_asm,%edi
22734+ loop 1b
22735+#endif
22736+
22737 /*
22738 * Clear BSS first so that there are no surprises...
22739 */
22740@@ -201,8 +269,11 @@ ENTRY(startup_32)
22741 movl %eax, pa(max_pfn_mapped)
22742
22743 /* Do early initialization of the fixmap area */
22744- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22745- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22746+#ifdef CONFIG_COMPAT_VDSO
22747+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22748+#else
22749+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22750+#endif
22751 #else /* Not PAE */
22752
22753 page_pde_offset = (__PAGE_OFFSET >> 20);
22754@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22755 movl %eax, pa(max_pfn_mapped)
22756
22757 /* Do early initialization of the fixmap area */
22758- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22759- movl %eax,pa(initial_page_table+0xffc)
22760+#ifdef CONFIG_COMPAT_VDSO
22761+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22762+#else
22763+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22764+#endif
22765 #endif
22766
22767 #ifdef CONFIG_PARAVIRT
22768@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22769 cmpl $num_subarch_entries, %eax
22770 jae bad_subarch
22771
22772- movl pa(subarch_entries)(,%eax,4), %eax
22773- subl $__PAGE_OFFSET, %eax
22774- jmp *%eax
22775+ jmp *pa(subarch_entries)(,%eax,4)
22776
22777 bad_subarch:
22778 WEAK(lguest_entry)
22779@@ -261,10 +333,10 @@ WEAK(xen_entry)
22780 __INITDATA
22781
22782 subarch_entries:
22783- .long default_entry /* normal x86/PC */
22784- .long lguest_entry /* lguest hypervisor */
22785- .long xen_entry /* Xen hypervisor */
22786- .long default_entry /* Moorestown MID */
22787+ .long ta(default_entry) /* normal x86/PC */
22788+ .long ta(lguest_entry) /* lguest hypervisor */
22789+ .long ta(xen_entry) /* Xen hypervisor */
22790+ .long ta(default_entry) /* Moorestown MID */
22791 num_subarch_entries = (. - subarch_entries) / 4
22792 .previous
22793 #else
22794@@ -354,6 +426,7 @@ default_entry:
22795 movl pa(mmu_cr4_features),%eax
22796 movl %eax,%cr4
22797
22798+#ifdef CONFIG_X86_PAE
22799 testb $X86_CR4_PAE, %al # check if PAE is enabled
22800 jz enable_paging
22801
22802@@ -382,6 +455,9 @@ default_entry:
22803 /* Make changes effective */
22804 wrmsr
22805
22806+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22807+#endif
22808+
22809 enable_paging:
22810
22811 /*
22812@@ -449,14 +525,20 @@ is486:
22813 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22814 movl %eax,%ss # after changing gdt.
22815
22816- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22817+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22818 movl %eax,%ds
22819 movl %eax,%es
22820
22821 movl $(__KERNEL_PERCPU), %eax
22822 movl %eax,%fs # set this cpu's percpu
22823
22824+#ifdef CONFIG_CC_STACKPROTECTOR
22825 movl $(__KERNEL_STACK_CANARY),%eax
22826+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22827+ movl $(__USER_DS),%eax
22828+#else
22829+ xorl %eax,%eax
22830+#endif
22831 movl %eax,%gs
22832
22833 xorl %eax,%eax # Clear LDT
22834@@ -512,8 +594,11 @@ setup_once:
22835 * relocation. Manually set base address in stack canary
22836 * segment descriptor.
22837 */
22838- movl $gdt_page,%eax
22839+ movl $cpu_gdt_table,%eax
22840 movl $stack_canary,%ecx
22841+#ifdef CONFIG_SMP
22842+ addl $__per_cpu_load,%ecx
22843+#endif
22844 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22845 shrl $16, %ecx
22846 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22847@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22848 /* This is global to keep gas from relaxing the jumps */
22849 ENTRY(early_idt_handler)
22850 cld
22851- cmpl $2,%ss:early_recursion_flag
22852+ cmpl $1,%ss:early_recursion_flag
22853 je hlt_loop
22854 incl %ss:early_recursion_flag
22855
22856@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22857 pushl (20+6*4)(%esp) /* trapno */
22858 pushl $fault_msg
22859 call printk
22860-#endif
22861 call dump_stack
22862+#endif
22863 hlt_loop:
22864 hlt
22865 jmp hlt_loop
22866@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22867 /* This is the default interrupt "handler" :-) */
22868 ALIGN
22869 ignore_int:
22870- cld
22871 #ifdef CONFIG_PRINTK
22872+ cmpl $2,%ss:early_recursion_flag
22873+ je hlt_loop
22874+ incl %ss:early_recursion_flag
22875+ cld
22876 pushl %eax
22877 pushl %ecx
22878 pushl %edx
22879@@ -612,9 +700,6 @@ ignore_int:
22880 movl $(__KERNEL_DS),%eax
22881 movl %eax,%ds
22882 movl %eax,%es
22883- cmpl $2,early_recursion_flag
22884- je hlt_loop
22885- incl early_recursion_flag
22886 pushl 16(%esp)
22887 pushl 24(%esp)
22888 pushl 32(%esp)
22889@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22890 /*
22891 * BSS section
22892 */
22893-__PAGE_ALIGNED_BSS
22894- .align PAGE_SIZE
22895 #ifdef CONFIG_X86_PAE
22896+.section .initial_pg_pmd,"a",@progbits
22897 initial_pg_pmd:
22898 .fill 1024*KPMDS,4,0
22899 #else
22900+.section .initial_page_table,"a",@progbits
22901 ENTRY(initial_page_table)
22902 .fill 1024,4,0
22903 #endif
22904+.section .initial_pg_fixmap,"a",@progbits
22905 initial_pg_fixmap:
22906 .fill 1024,4,0
22907+.section .empty_zero_page,"a",@progbits
22908 ENTRY(empty_zero_page)
22909 .fill 4096,1,0
22910+.section .swapper_pg_dir,"a",@progbits
22911 ENTRY(swapper_pg_dir)
22912+#ifdef CONFIG_X86_PAE
22913+ .fill 4,8,0
22914+#else
22915 .fill 1024,4,0
22916+#endif
22917
22918 /*
22919 * This starts the data section.
22920 */
22921 #ifdef CONFIG_X86_PAE
22922-__PAGE_ALIGNED_DATA
22923- /* Page-aligned for the benefit of paravirt? */
22924- .align PAGE_SIZE
22925+.section .initial_page_table,"a",@progbits
22926 ENTRY(initial_page_table)
22927 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22928 # if KPMDS == 3
22929@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22930 # error "Kernel PMDs should be 1, 2 or 3"
22931 # endif
22932 .align PAGE_SIZE /* needs to be page-sized too */
22933+
22934+#ifdef CONFIG_PAX_PER_CPU_PGD
22935+ENTRY(cpu_pgd)
22936+ .rept 2*NR_CPUS
22937+ .fill 4,8,0
22938+ .endr
22939+#endif
22940+
22941 #endif
22942
22943 .data
22944 .balign 4
22945 ENTRY(stack_start)
22946- .long init_thread_union+THREAD_SIZE
22947+ .long init_thread_union+THREAD_SIZE-8
22948
22949 __INITRODATA
22950 int_msg:
22951@@ -722,7 +820,7 @@ fault_msg:
22952 * segment size, and 32-bit linear address value:
22953 */
22954
22955- .data
22956+.section .rodata,"a",@progbits
22957 .globl boot_gdt_descr
22958 .globl idt_descr
22959
22960@@ -731,7 +829,7 @@ fault_msg:
22961 .word 0 # 32 bit align gdt_desc.address
22962 boot_gdt_descr:
22963 .word __BOOT_DS+7
22964- .long boot_gdt - __PAGE_OFFSET
22965+ .long pa(boot_gdt)
22966
22967 .word 0 # 32-bit align idt_desc.address
22968 idt_descr:
22969@@ -742,7 +840,7 @@ idt_descr:
22970 .word 0 # 32 bit align gdt_desc.address
22971 ENTRY(early_gdt_descr)
22972 .word GDT_ENTRIES*8-1
22973- .long gdt_page /* Overwritten for secondary CPUs */
22974+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22975
22976 /*
22977 * The boot_gdt must mirror the equivalent in setup.S and is
22978@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22979 .align L1_CACHE_BYTES
22980 ENTRY(boot_gdt)
22981 .fill GDT_ENTRY_BOOT_CS,8,0
22982- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22983- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22984+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22985+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22986+
22987+ .align PAGE_SIZE_asm
22988+ENTRY(cpu_gdt_table)
22989+ .rept NR_CPUS
22990+ .quad 0x0000000000000000 /* NULL descriptor */
22991+ .quad 0x0000000000000000 /* 0x0b reserved */
22992+ .quad 0x0000000000000000 /* 0x13 reserved */
22993+ .quad 0x0000000000000000 /* 0x1b reserved */
22994+
22995+#ifdef CONFIG_PAX_KERNEXEC
22996+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22997+#else
22998+ .quad 0x0000000000000000 /* 0x20 unused */
22999+#endif
23000+
23001+ .quad 0x0000000000000000 /* 0x28 unused */
23002+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23003+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23004+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23005+ .quad 0x0000000000000000 /* 0x4b reserved */
23006+ .quad 0x0000000000000000 /* 0x53 reserved */
23007+ .quad 0x0000000000000000 /* 0x5b reserved */
23008+
23009+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23010+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23011+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23012+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23013+
23014+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23015+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23016+
23017+ /*
23018+ * Segments used for calling PnP BIOS have byte granularity.
23019+ * The code segments and data segments have fixed 64k limits,
23020+ * the transfer segment sizes are set at run time.
23021+ */
23022+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23023+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23024+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23025+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23026+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23027+
23028+ /*
23029+ * The APM segments have byte granularity and their bases
23030+ * are set at run time. All have 64k limits.
23031+ */
23032+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23033+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23034+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23035+
23036+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23037+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23038+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23039+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23040+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23041+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23042+
23043+ /* Be sure this is zeroed to avoid false validations in Xen */
23044+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23045+ .endr
23046diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23047index e1aabdb..73dcad8 100644
23048--- a/arch/x86/kernel/head_64.S
23049+++ b/arch/x86/kernel/head_64.S
23050@@ -20,6 +20,8 @@
23051 #include <asm/processor-flags.h>
23052 #include <asm/percpu.h>
23053 #include <asm/nops.h>
23054+#include <asm/cpufeature.h>
23055+#include <asm/alternative-asm.h>
23056
23057 #ifdef CONFIG_PARAVIRT
23058 #include <asm/asm-offsets.h>
23059@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23060 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23061 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23062 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23063+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23064+L3_VMALLOC_START = pud_index(VMALLOC_START)
23065+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23066+L3_VMALLOC_END = pud_index(VMALLOC_END)
23067+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23068+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23069
23070 .text
23071 __HEAD
23072@@ -89,11 +97,23 @@ startup_64:
23073 * Fixup the physical addresses in the page table
23074 */
23075 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23076+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23077+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23078+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23079+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23080+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23081
23082- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23083- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23084+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23085+#ifndef CONFIG_XEN
23086+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23087+#endif
23088
23089- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23090+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23091+
23092+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23093+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23094+
23095+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23096
23097 /*
23098 * Set up the identity mapping for the switchover. These
23099@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23100 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23101 1:
23102
23103- /* Enable PAE mode and PGE */
23104- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23105+ /* Enable PAE mode and PSE/PGE */
23106+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23107 movq %rcx, %cr4
23108
23109 /* Setup early boot stage 4 level pagetables. */
23110@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23111 movl $MSR_EFER, %ecx
23112 rdmsr
23113 btsl $_EFER_SCE, %eax /* Enable System Call */
23114- btl $20,%edi /* No Execute supported? */
23115+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23116 jnc 1f
23117 btsl $_EFER_NX, %eax
23118 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23119+ leaq init_level4_pgt(%rip), %rdi
23120+#ifndef CONFIG_EFI
23121+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23122+#endif
23123+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23124+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23125+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23126+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23127 1: wrmsr /* Make changes effective */
23128
23129 /* Setup cr0 */
23130@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23131 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23132 * address given in m16:64.
23133 */
23134+ pax_set_fptr_mask
23135 movq initial_code(%rip),%rax
23136 pushq $0 # fake return address to stop unwinder
23137 pushq $__KERNEL_CS # set correct cs
23138@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23139 call dump_stack
23140 #ifdef CONFIG_KALLSYMS
23141 leaq early_idt_ripmsg(%rip),%rdi
23142- movq 40(%rsp),%rsi # %rip again
23143+ movq 88(%rsp),%rsi # %rip again
23144 call __print_symbol
23145 #endif
23146 #endif /* EARLY_PRINTK */
23147@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23148 early_recursion_flag:
23149 .long 0
23150
23151+ .section .rodata,"a",@progbits
23152 #ifdef CONFIG_EARLY_PRINTK
23153 early_idt_msg:
23154 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23155@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23156 NEXT_PAGE(early_dynamic_pgts)
23157 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23158
23159- .data
23160+ .section .rodata,"a",@progbits
23161
23162-#ifndef CONFIG_XEN
23163 NEXT_PAGE(init_level4_pgt)
23164- .fill 512,8,0
23165-#else
23166-NEXT_PAGE(init_level4_pgt)
23167- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23168 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23169 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23170+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23171+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23172+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23173+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23174+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23175+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23176 .org init_level4_pgt + L4_START_KERNEL*8, 0
23177 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23178 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23179
23180+#ifdef CONFIG_PAX_PER_CPU_PGD
23181+NEXT_PAGE(cpu_pgd)
23182+ .rept 2*NR_CPUS
23183+ .fill 512,8,0
23184+ .endr
23185+#endif
23186+
23187 NEXT_PAGE(level3_ident_pgt)
23188 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23189+#ifdef CONFIG_XEN
23190 .fill 511, 8, 0
23191+#else
23192+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23193+ .fill 510,8,0
23194+#endif
23195+
23196+NEXT_PAGE(level3_vmalloc_start_pgt)
23197+ .fill 512,8,0
23198+
23199+NEXT_PAGE(level3_vmalloc_end_pgt)
23200+ .fill 512,8,0
23201+
23202+NEXT_PAGE(level3_vmemmap_pgt)
23203+ .fill L3_VMEMMAP_START,8,0
23204+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23205+
23206 NEXT_PAGE(level2_ident_pgt)
23207- /* Since I easily can, map the first 1G.
23208+ /* Since I easily can, map the first 2G.
23209 * Don't set NX because code runs from these pages.
23210 */
23211- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23212-#endif
23213+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23214
23215 NEXT_PAGE(level3_kernel_pgt)
23216 .fill L3_START_KERNEL,8,0
23217@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23218 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23219 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23220
23221+NEXT_PAGE(level2_vmemmap_pgt)
23222+ .fill 512,8,0
23223+
23224 NEXT_PAGE(level2_kernel_pgt)
23225 /*
23226 * 512 MB kernel mapping. We spend a full page on this pagetable
23227@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23228 KERNEL_IMAGE_SIZE/PMD_SIZE)
23229
23230 NEXT_PAGE(level2_fixmap_pgt)
23231- .fill 506,8,0
23232- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23233- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23234- .fill 5,8,0
23235+ .fill 507,8,0
23236+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23237+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23238+ .fill 4,8,0
23239
23240-NEXT_PAGE(level1_fixmap_pgt)
23241+NEXT_PAGE(level1_vsyscall_pgt)
23242 .fill 512,8,0
23243
23244 #undef PMDS
23245
23246- .data
23247+ .align PAGE_SIZE
23248+ENTRY(cpu_gdt_table)
23249+ .rept NR_CPUS
23250+ .quad 0x0000000000000000 /* NULL descriptor */
23251+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23252+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23253+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23254+ .quad 0x00cffb000000ffff /* __USER32_CS */
23255+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23256+ .quad 0x00affb000000ffff /* __USER_CS */
23257+
23258+#ifdef CONFIG_PAX_KERNEXEC
23259+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23260+#else
23261+ .quad 0x0 /* unused */
23262+#endif
23263+
23264+ .quad 0,0 /* TSS */
23265+ .quad 0,0 /* LDT */
23266+ .quad 0,0,0 /* three TLS descriptors */
23267+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23268+ /* asm/segment.h:GDT_ENTRIES must match this */
23269+
23270+#ifdef CONFIG_PAX_MEMORY_UDEREF
23271+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23272+#else
23273+ .quad 0x0 /* unused */
23274+#endif
23275+
23276+ /* zero the remaining page */
23277+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23278+ .endr
23279+
23280 .align 16
23281 .globl early_gdt_descr
23282 early_gdt_descr:
23283 .word GDT_ENTRIES*8-1
23284 early_gdt_descr_base:
23285- .quad INIT_PER_CPU_VAR(gdt_page)
23286+ .quad cpu_gdt_table
23287
23288 ENTRY(phys_base)
23289 /* This must match the first entry in level2_kernel_pgt */
23290 .quad 0x0000000000000000
23291
23292 #include "../../x86/xen/xen-head.S"
23293-
23294- __PAGE_ALIGNED_BSS
23295+
23296+ .section .rodata,"a",@progbits
23297 NEXT_PAGE(empty_zero_page)
23298 .skip PAGE_SIZE
23299diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23300index 0fa6912..b37438b 100644
23301--- a/arch/x86/kernel/i386_ksyms_32.c
23302+++ b/arch/x86/kernel/i386_ksyms_32.c
23303@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23304 EXPORT_SYMBOL(cmpxchg8b_emu);
23305 #endif
23306
23307+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23308+
23309 /* Networking helper routines. */
23310 EXPORT_SYMBOL(csum_partial_copy_generic);
23311+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23312+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23313
23314 EXPORT_SYMBOL(__get_user_1);
23315 EXPORT_SYMBOL(__get_user_2);
23316@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23317
23318 EXPORT_SYMBOL(csum_partial);
23319 EXPORT_SYMBOL(empty_zero_page);
23320+
23321+#ifdef CONFIG_PAX_KERNEXEC
23322+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23323+#endif
23324+
23325+#ifdef CONFIG_PAX_PER_CPU_PGD
23326+EXPORT_SYMBOL(cpu_pgd);
23327+#endif
23328diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23329index 5d576ab..1403a03 100644
23330--- a/arch/x86/kernel/i387.c
23331+++ b/arch/x86/kernel/i387.c
23332@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23333 static inline bool interrupted_user_mode(void)
23334 {
23335 struct pt_regs *regs = get_irq_regs();
23336- return regs && user_mode_vm(regs);
23337+ return regs && user_mode(regs);
23338 }
23339
23340 /*
23341diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23342index 9a5c460..84868423 100644
23343--- a/arch/x86/kernel/i8259.c
23344+++ b/arch/x86/kernel/i8259.c
23345@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23346 static void make_8259A_irq(unsigned int irq)
23347 {
23348 disable_irq_nosync(irq);
23349- io_apic_irqs &= ~(1<<irq);
23350+ io_apic_irqs &= ~(1UL<<irq);
23351 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23352 i8259A_chip.name);
23353 enable_irq(irq);
23354@@ -209,7 +209,7 @@ spurious_8259A_irq:
23355 "spurious 8259A interrupt: IRQ%d.\n", irq);
23356 spurious_irq_mask |= irqmask;
23357 }
23358- atomic_inc(&irq_err_count);
23359+ atomic_inc_unchecked(&irq_err_count);
23360 /*
23361 * Theoretically we do not have to handle this IRQ,
23362 * but in Linux this does not cause problems and is
23363@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23364 /* (slave's support for AEOI in flat mode is to be investigated) */
23365 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23366
23367+ pax_open_kernel();
23368 if (auto_eoi)
23369 /*
23370 * In AEOI mode we just have to mask the interrupt
23371 * when acking.
23372 */
23373- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23374+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23375 else
23376- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23377+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23378+ pax_close_kernel();
23379
23380 udelay(100); /* wait for 8259A to initialize */
23381
23382diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23383index a979b5b..1d6db75 100644
23384--- a/arch/x86/kernel/io_delay.c
23385+++ b/arch/x86/kernel/io_delay.c
23386@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23387 * Quirk table for systems that misbehave (lock up, etc.) if port
23388 * 0x80 is used:
23389 */
23390-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23391+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23392 {
23393 .callback = dmi_io_delay_0xed_port,
23394 .ident = "Compaq Presario V6000",
23395diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23396index 4ddaf66..6292f4e 100644
23397--- a/arch/x86/kernel/ioport.c
23398+++ b/arch/x86/kernel/ioport.c
23399@@ -6,6 +6,7 @@
23400 #include <linux/sched.h>
23401 #include <linux/kernel.h>
23402 #include <linux/capability.h>
23403+#include <linux/security.h>
23404 #include <linux/errno.h>
23405 #include <linux/types.h>
23406 #include <linux/ioport.h>
23407@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23408
23409 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23410 return -EINVAL;
23411+#ifdef CONFIG_GRKERNSEC_IO
23412+ if (turn_on && grsec_disable_privio) {
23413+ gr_handle_ioperm();
23414+ return -EPERM;
23415+ }
23416+#endif
23417 if (turn_on && !capable(CAP_SYS_RAWIO))
23418 return -EPERM;
23419
23420@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23421 * because the ->io_bitmap_max value must match the bitmap
23422 * contents:
23423 */
23424- tss = &per_cpu(init_tss, get_cpu());
23425+ tss = init_tss + get_cpu();
23426
23427 if (turn_on)
23428 bitmap_clear(t->io_bitmap_ptr, from, num);
23429@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23430 return -EINVAL;
23431 /* Trying to gain more privileges? */
23432 if (level > old) {
23433+#ifdef CONFIG_GRKERNSEC_IO
23434+ if (grsec_disable_privio) {
23435+ gr_handle_iopl();
23436+ return -EPERM;
23437+ }
23438+#endif
23439 if (!capable(CAP_SYS_RAWIO))
23440 return -EPERM;
23441 }
23442diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23443index 3a8185c..3c042ee 100644
23444--- a/arch/x86/kernel/irq.c
23445+++ b/arch/x86/kernel/irq.c
23446@@ -21,7 +21,7 @@
23447 #define CREATE_TRACE_POINTS
23448 #include <asm/trace/irq_vectors.h>
23449
23450-atomic_t irq_err_count;
23451+atomic_unchecked_t irq_err_count;
23452
23453 /* Function pointer for generic interrupt vector handling */
23454 void (*x86_platform_ipi_callback)(void) = NULL;
23455@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23456 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23457 seq_printf(p, " Machine check polls\n");
23458 #endif
23459- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23460+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23461 #if defined(CONFIG_X86_IO_APIC)
23462- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23463+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23464 #endif
23465 return 0;
23466 }
23467@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23468
23469 u64 arch_irq_stat(void)
23470 {
23471- u64 sum = atomic_read(&irq_err_count);
23472+ u64 sum = atomic_read_unchecked(&irq_err_count);
23473 return sum;
23474 }
23475
23476diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23477index 4186755..784efa0 100644
23478--- a/arch/x86/kernel/irq_32.c
23479+++ b/arch/x86/kernel/irq_32.c
23480@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23481 __asm__ __volatile__("andl %%esp,%0" :
23482 "=r" (sp) : "0" (THREAD_SIZE - 1));
23483
23484- return sp < (sizeof(struct thread_info) + STACK_WARN);
23485+ return sp < STACK_WARN;
23486 }
23487
23488 static void print_stack_overflow(void)
23489@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23490 * per-CPU IRQ handling contexts (thread information and stack)
23491 */
23492 union irq_ctx {
23493- struct thread_info tinfo;
23494- u32 stack[THREAD_SIZE/sizeof(u32)];
23495+ unsigned long previous_esp;
23496+ u32 stack[THREAD_SIZE/sizeof(u32)];
23497 } __attribute__((aligned(THREAD_SIZE)));
23498
23499 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23500@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23501 static inline int
23502 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23503 {
23504- union irq_ctx *curctx, *irqctx;
23505+ union irq_ctx *irqctx;
23506 u32 *isp, arg1, arg2;
23507
23508- curctx = (union irq_ctx *) current_thread_info();
23509 irqctx = __this_cpu_read(hardirq_ctx);
23510
23511 /*
23512@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23513 * handler) we can't do that and just have to keep using the
23514 * current stack (which is the irq stack already after all)
23515 */
23516- if (unlikely(curctx == irqctx))
23517+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23518 return 0;
23519
23520 /* build the stack frame on the IRQ stack */
23521- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23522- irqctx->tinfo.task = curctx->tinfo.task;
23523- irqctx->tinfo.previous_esp = current_stack_pointer;
23524+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23525+ irqctx->previous_esp = current_stack_pointer;
23526
23527- /* Copy the preempt_count so that the [soft]irq checks work. */
23528- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23529+#ifdef CONFIG_PAX_MEMORY_UDEREF
23530+ __set_fs(MAKE_MM_SEG(0));
23531+#endif
23532
23533 if (unlikely(overflow))
23534 call_on_stack(print_stack_overflow, isp);
23535@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23536 : "0" (irq), "1" (desc), "2" (isp),
23537 "D" (desc->handle_irq)
23538 : "memory", "cc", "ecx");
23539+
23540+#ifdef CONFIG_PAX_MEMORY_UDEREF
23541+ __set_fs(current_thread_info()->addr_limit);
23542+#endif
23543+
23544 return 1;
23545 }
23546
23547@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23548 */
23549 void irq_ctx_init(int cpu)
23550 {
23551- union irq_ctx *irqctx;
23552-
23553 if (per_cpu(hardirq_ctx, cpu))
23554 return;
23555
23556- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23557- THREADINFO_GFP,
23558- THREAD_SIZE_ORDER));
23559- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23560- irqctx->tinfo.cpu = cpu;
23561- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23562- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23563+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23564+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23565
23566- per_cpu(hardirq_ctx, cpu) = irqctx;
23567-
23568- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23569- THREADINFO_GFP,
23570- THREAD_SIZE_ORDER));
23571- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23572- irqctx->tinfo.cpu = cpu;
23573- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23574-
23575- per_cpu(softirq_ctx, cpu) = irqctx;
23576+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23577+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23578
23579 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23580 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23581@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23582 asmlinkage void do_softirq(void)
23583 {
23584 unsigned long flags;
23585- struct thread_info *curctx;
23586 union irq_ctx *irqctx;
23587 u32 *isp;
23588
23589@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23590 local_irq_save(flags);
23591
23592 if (local_softirq_pending()) {
23593- curctx = current_thread_info();
23594 irqctx = __this_cpu_read(softirq_ctx);
23595- irqctx->tinfo.task = curctx->task;
23596- irqctx->tinfo.previous_esp = current_stack_pointer;
23597+ irqctx->previous_esp = current_stack_pointer;
23598
23599 /* build the stack frame on the softirq stack */
23600- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23601+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23602+
23603+#ifdef CONFIG_PAX_MEMORY_UDEREF
23604+ __set_fs(MAKE_MM_SEG(0));
23605+#endif
23606
23607 call_on_stack(__do_softirq, isp);
23608+
23609+#ifdef CONFIG_PAX_MEMORY_UDEREF
23610+ __set_fs(current_thread_info()->addr_limit);
23611+#endif
23612+
23613 /*
23614 * Shouldn't happen, we returned above if in_interrupt():
23615 */
23616@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23617 if (unlikely(!desc))
23618 return false;
23619
23620- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23621+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23622 if (unlikely(overflow))
23623 print_stack_overflow();
23624 desc->handle_irq(irq, desc);
23625diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23626index d04d3ec..ea4b374 100644
23627--- a/arch/x86/kernel/irq_64.c
23628+++ b/arch/x86/kernel/irq_64.c
23629@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23630 u64 estack_top, estack_bottom;
23631 u64 curbase = (u64)task_stack_page(current);
23632
23633- if (user_mode_vm(regs))
23634+ if (user_mode(regs))
23635 return;
23636
23637 if (regs->sp >= curbase + sizeof(struct thread_info) +
23638diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23639index dc1404b..bbc43e7 100644
23640--- a/arch/x86/kernel/kdebugfs.c
23641+++ b/arch/x86/kernel/kdebugfs.c
23642@@ -27,7 +27,7 @@ struct setup_data_node {
23643 u32 len;
23644 };
23645
23646-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23647+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23648 size_t count, loff_t *ppos)
23649 {
23650 struct setup_data_node *node = file->private_data;
23651diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23652index 836f832..a8bda67 100644
23653--- a/arch/x86/kernel/kgdb.c
23654+++ b/arch/x86/kernel/kgdb.c
23655@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23656 #ifdef CONFIG_X86_32
23657 switch (regno) {
23658 case GDB_SS:
23659- if (!user_mode_vm(regs))
23660+ if (!user_mode(regs))
23661 *(unsigned long *)mem = __KERNEL_DS;
23662 break;
23663 case GDB_SP:
23664- if (!user_mode_vm(regs))
23665+ if (!user_mode(regs))
23666 *(unsigned long *)mem = kernel_stack_pointer(regs);
23667 break;
23668 case GDB_GS:
23669@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23670 bp->attr.bp_addr = breakinfo[breakno].addr;
23671 bp->attr.bp_len = breakinfo[breakno].len;
23672 bp->attr.bp_type = breakinfo[breakno].type;
23673- info->address = breakinfo[breakno].addr;
23674+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23675+ info->address = ktla_ktva(breakinfo[breakno].addr);
23676+ else
23677+ info->address = breakinfo[breakno].addr;
23678 info->len = breakinfo[breakno].len;
23679 info->type = breakinfo[breakno].type;
23680 val = arch_install_hw_breakpoint(bp);
23681@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23682 case 'k':
23683 /* clear the trace bit */
23684 linux_regs->flags &= ~X86_EFLAGS_TF;
23685- atomic_set(&kgdb_cpu_doing_single_step, -1);
23686+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23687
23688 /* set the trace bit if we're stepping */
23689 if (remcomInBuffer[0] == 's') {
23690 linux_regs->flags |= X86_EFLAGS_TF;
23691- atomic_set(&kgdb_cpu_doing_single_step,
23692+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23693 raw_smp_processor_id());
23694 }
23695
23696@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23697
23698 switch (cmd) {
23699 case DIE_DEBUG:
23700- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23701+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23702 if (user_mode(regs))
23703 return single_step_cont(regs, args);
23704 break;
23705@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23706 #endif /* CONFIG_DEBUG_RODATA */
23707
23708 bpt->type = BP_BREAKPOINT;
23709- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23710+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23711 BREAK_INSTR_SIZE);
23712 if (err)
23713 return err;
23714- err = probe_kernel_write((char *)bpt->bpt_addr,
23715+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23716 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23717 #ifdef CONFIG_DEBUG_RODATA
23718 if (!err)
23719@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23720 return -EBUSY;
23721 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23722 BREAK_INSTR_SIZE);
23723- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23724+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23725 if (err)
23726 return err;
23727 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23728@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23729 if (mutex_is_locked(&text_mutex))
23730 goto knl_write;
23731 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23732- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23733+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23734 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23735 goto knl_write;
23736 return err;
23737 knl_write:
23738 #endif /* CONFIG_DEBUG_RODATA */
23739- return probe_kernel_write((char *)bpt->bpt_addr,
23740+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23741 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23742 }
23743
23744diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23745index 211bce4..6e2580a 100644
23746--- a/arch/x86/kernel/kprobes/core.c
23747+++ b/arch/x86/kernel/kprobes/core.c
23748@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23749 s32 raddr;
23750 } __packed *insn;
23751
23752- insn = (struct __arch_relative_insn *)from;
23753+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23754+
23755+ pax_open_kernel();
23756 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23757 insn->op = op;
23758+ pax_close_kernel();
23759 }
23760
23761 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23762@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23763 kprobe_opcode_t opcode;
23764 kprobe_opcode_t *orig_opcodes = opcodes;
23765
23766- if (search_exception_tables((unsigned long)opcodes))
23767+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23768 return 0; /* Page fault may occur on this address. */
23769
23770 retry:
23771@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23772 * for the first byte, we can recover the original instruction
23773 * from it and kp->opcode.
23774 */
23775- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23776+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23777 buf[0] = kp->opcode;
23778- return (unsigned long)buf;
23779+ return ktva_ktla((unsigned long)buf);
23780 }
23781
23782 /*
23783@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23784 /* Another subsystem puts a breakpoint, failed to recover */
23785 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23786 return 0;
23787+ pax_open_kernel();
23788 memcpy(dest, insn.kaddr, insn.length);
23789+ pax_close_kernel();
23790
23791 #ifdef CONFIG_X86_64
23792 if (insn_rip_relative(&insn)) {
23793@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23794 return 0;
23795 }
23796 disp = (u8 *) dest + insn_offset_displacement(&insn);
23797+ pax_open_kernel();
23798 *(s32 *) disp = (s32) newdisp;
23799+ pax_close_kernel();
23800 }
23801 #endif
23802 return insn.length;
23803@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23804 * nor set current_kprobe, because it doesn't use single
23805 * stepping.
23806 */
23807- regs->ip = (unsigned long)p->ainsn.insn;
23808+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23809 preempt_enable_no_resched();
23810 return;
23811 }
23812@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23813 regs->flags &= ~X86_EFLAGS_IF;
23814 /* single step inline if the instruction is an int3 */
23815 if (p->opcode == BREAKPOINT_INSTRUCTION)
23816- regs->ip = (unsigned long)p->addr;
23817+ regs->ip = ktla_ktva((unsigned long)p->addr);
23818 else
23819- regs->ip = (unsigned long)p->ainsn.insn;
23820+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23821 }
23822
23823 /*
23824@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23825 setup_singlestep(p, regs, kcb, 0);
23826 return 1;
23827 }
23828- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23829+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23830 /*
23831 * The breakpoint instruction was removed right
23832 * after we hit it. Another cpu has removed
23833@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23834 " movq %rax, 152(%rsp)\n"
23835 RESTORE_REGS_STRING
23836 " popfq\n"
23837+#ifdef KERNEXEC_PLUGIN
23838+ " btsq $63,(%rsp)\n"
23839+#endif
23840 #else
23841 " pushf\n"
23842 SAVE_REGS_STRING
23843@@ -779,7 +789,7 @@ static void __kprobes
23844 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23845 {
23846 unsigned long *tos = stack_addr(regs);
23847- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23848+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23849 unsigned long orig_ip = (unsigned long)p->addr;
23850 kprobe_opcode_t *insn = p->ainsn.insn;
23851
23852@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23853 struct die_args *args = data;
23854 int ret = NOTIFY_DONE;
23855
23856- if (args->regs && user_mode_vm(args->regs))
23857+ if (args->regs && user_mode(args->regs))
23858 return ret;
23859
23860 switch (val) {
23861diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23862index 76dc6f0..66bdfc3 100644
23863--- a/arch/x86/kernel/kprobes/opt.c
23864+++ b/arch/x86/kernel/kprobes/opt.c
23865@@ -79,6 +79,7 @@ found:
23866 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23867 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23868 {
23869+ pax_open_kernel();
23870 #ifdef CONFIG_X86_64
23871 *addr++ = 0x48;
23872 *addr++ = 0xbf;
23873@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23874 *addr++ = 0xb8;
23875 #endif
23876 *(unsigned long *)addr = val;
23877+ pax_close_kernel();
23878 }
23879
23880 static void __used __kprobes kprobes_optinsn_template_holder(void)
23881@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23882 * Verify if the address gap is in 2GB range, because this uses
23883 * a relative jump.
23884 */
23885- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23886+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23887 if (abs(rel) > 0x7fffffff)
23888 return -ERANGE;
23889
23890@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23891 op->optinsn.size = ret;
23892
23893 /* Copy arch-dep-instance from template */
23894- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23895+ pax_open_kernel();
23896+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23897+ pax_close_kernel();
23898
23899 /* Set probe information */
23900 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23901
23902 /* Set probe function call */
23903- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23904+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23905
23906 /* Set returning jmp instruction at the tail of out-of-line buffer */
23907- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23908+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23909 (u8 *)op->kp.addr + op->optinsn.size);
23910
23911 flush_icache_range((unsigned long) buf,
23912@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23913 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23914
23915 /* Backup instructions which will be replaced by jump address */
23916- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23917+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23918 RELATIVE_ADDR_SIZE);
23919
23920 insn_buf[0] = RELATIVEJUMP_OPCODE;
23921@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23922 /* This kprobe is really able to run optimized path. */
23923 op = container_of(p, struct optimized_kprobe, kp);
23924 /* Detour through copied instructions */
23925- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23926+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23927 if (!reenter)
23928 reset_current_kprobe();
23929 preempt_enable_no_resched();
23930diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23931index ebc9873..1b9724b 100644
23932--- a/arch/x86/kernel/ldt.c
23933+++ b/arch/x86/kernel/ldt.c
23934@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23935 if (reload) {
23936 #ifdef CONFIG_SMP
23937 preempt_disable();
23938- load_LDT(pc);
23939+ load_LDT_nolock(pc);
23940 if (!cpumask_equal(mm_cpumask(current->mm),
23941 cpumask_of(smp_processor_id())))
23942 smp_call_function(flush_ldt, current->mm, 1);
23943 preempt_enable();
23944 #else
23945- load_LDT(pc);
23946+ load_LDT_nolock(pc);
23947 #endif
23948 }
23949 if (oldsize) {
23950@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23951 return err;
23952
23953 for (i = 0; i < old->size; i++)
23954- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23955+ write_ldt_entry(new->ldt, i, old->ldt + i);
23956 return 0;
23957 }
23958
23959@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23960 retval = copy_ldt(&mm->context, &old_mm->context);
23961 mutex_unlock(&old_mm->context.lock);
23962 }
23963+
23964+ if (tsk == current) {
23965+ mm->context.vdso = 0;
23966+
23967+#ifdef CONFIG_X86_32
23968+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23969+ mm->context.user_cs_base = 0UL;
23970+ mm->context.user_cs_limit = ~0UL;
23971+
23972+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23973+ cpus_clear(mm->context.cpu_user_cs_mask);
23974+#endif
23975+
23976+#endif
23977+#endif
23978+
23979+ }
23980+
23981 return retval;
23982 }
23983
23984@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23985 }
23986 }
23987
23988+#ifdef CONFIG_PAX_SEGMEXEC
23989+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23990+ error = -EINVAL;
23991+ goto out_unlock;
23992+ }
23993+#endif
23994+
23995 fill_ldt(&ldt, &ldt_info);
23996 if (oldmode)
23997 ldt.avl = 0;
23998diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23999index 5b19e4d..6476a76 100644
24000--- a/arch/x86/kernel/machine_kexec_32.c
24001+++ b/arch/x86/kernel/machine_kexec_32.c
24002@@ -26,7 +26,7 @@
24003 #include <asm/cacheflush.h>
24004 #include <asm/debugreg.h>
24005
24006-static void set_idt(void *newidt, __u16 limit)
24007+static void set_idt(struct desc_struct *newidt, __u16 limit)
24008 {
24009 struct desc_ptr curidt;
24010
24011@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24012 }
24013
24014
24015-static void set_gdt(void *newgdt, __u16 limit)
24016+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24017 {
24018 struct desc_ptr curgdt;
24019
24020@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24021 }
24022
24023 control_page = page_address(image->control_code_page);
24024- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24025+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24026
24027 relocate_kernel_ptr = control_page;
24028 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24029diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24030index 15c9876..0a43909 100644
24031--- a/arch/x86/kernel/microcode_core.c
24032+++ b/arch/x86/kernel/microcode_core.c
24033@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24034 return NOTIFY_OK;
24035 }
24036
24037-static struct notifier_block __refdata mc_cpu_notifier = {
24038+static struct notifier_block mc_cpu_notifier = {
24039 .notifier_call = mc_cpu_callback,
24040 };
24041
24042diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24043index 5fb2ceb..3ae90bb 100644
24044--- a/arch/x86/kernel/microcode_intel.c
24045+++ b/arch/x86/kernel/microcode_intel.c
24046@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24047
24048 static int get_ucode_user(void *to, const void *from, size_t n)
24049 {
24050- return copy_from_user(to, from, n);
24051+ return copy_from_user(to, (const void __force_user *)from, n);
24052 }
24053
24054 static enum ucode_state
24055 request_microcode_user(int cpu, const void __user *buf, size_t size)
24056 {
24057- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24058+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24059 }
24060
24061 static void microcode_fini_cpu(int cpu)
24062diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24063index 216a4d7..228255a 100644
24064--- a/arch/x86/kernel/module.c
24065+++ b/arch/x86/kernel/module.c
24066@@ -43,15 +43,60 @@ do { \
24067 } while (0)
24068 #endif
24069
24070-void *module_alloc(unsigned long size)
24071+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24072 {
24073- if (PAGE_ALIGN(size) > MODULES_LEN)
24074+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24075 return NULL;
24076 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24077- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24078+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24079 -1, __builtin_return_address(0));
24080 }
24081
24082+void *module_alloc(unsigned long size)
24083+{
24084+
24085+#ifdef CONFIG_PAX_KERNEXEC
24086+ return __module_alloc(size, PAGE_KERNEL);
24087+#else
24088+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24089+#endif
24090+
24091+}
24092+
24093+#ifdef CONFIG_PAX_KERNEXEC
24094+#ifdef CONFIG_X86_32
24095+void *module_alloc_exec(unsigned long size)
24096+{
24097+ struct vm_struct *area;
24098+
24099+ if (size == 0)
24100+ return NULL;
24101+
24102+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24103+ return area ? area->addr : NULL;
24104+}
24105+EXPORT_SYMBOL(module_alloc_exec);
24106+
24107+void module_free_exec(struct module *mod, void *module_region)
24108+{
24109+ vunmap(module_region);
24110+}
24111+EXPORT_SYMBOL(module_free_exec);
24112+#else
24113+void module_free_exec(struct module *mod, void *module_region)
24114+{
24115+ module_free(mod, module_region);
24116+}
24117+EXPORT_SYMBOL(module_free_exec);
24118+
24119+void *module_alloc_exec(unsigned long size)
24120+{
24121+ return __module_alloc(size, PAGE_KERNEL_RX);
24122+}
24123+EXPORT_SYMBOL(module_alloc_exec);
24124+#endif
24125+#endif
24126+
24127 #ifdef CONFIG_X86_32
24128 int apply_relocate(Elf32_Shdr *sechdrs,
24129 const char *strtab,
24130@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24131 unsigned int i;
24132 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24133 Elf32_Sym *sym;
24134- uint32_t *location;
24135+ uint32_t *plocation, location;
24136
24137 DEBUGP("Applying relocate section %u to %u\n",
24138 relsec, sechdrs[relsec].sh_info);
24139 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24140 /* This is where to make the change */
24141- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24142- + rel[i].r_offset;
24143+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24144+ location = (uint32_t)plocation;
24145+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24146+ plocation = ktla_ktva((void *)plocation);
24147 /* This is the symbol it is referring to. Note that all
24148 undefined symbols have been resolved. */
24149 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24150@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24151 switch (ELF32_R_TYPE(rel[i].r_info)) {
24152 case R_386_32:
24153 /* We add the value into the location given */
24154- *location += sym->st_value;
24155+ pax_open_kernel();
24156+ *plocation += sym->st_value;
24157+ pax_close_kernel();
24158 break;
24159 case R_386_PC32:
24160 /* Add the value, subtract its position */
24161- *location += sym->st_value - (uint32_t)location;
24162+ pax_open_kernel();
24163+ *plocation += sym->st_value - location;
24164+ pax_close_kernel();
24165 break;
24166 default:
24167 pr_err("%s: Unknown relocation: %u\n",
24168@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24169 case R_X86_64_NONE:
24170 break;
24171 case R_X86_64_64:
24172+ pax_open_kernel();
24173 *(u64 *)loc = val;
24174+ pax_close_kernel();
24175 break;
24176 case R_X86_64_32:
24177+ pax_open_kernel();
24178 *(u32 *)loc = val;
24179+ pax_close_kernel();
24180 if (val != *(u32 *)loc)
24181 goto overflow;
24182 break;
24183 case R_X86_64_32S:
24184+ pax_open_kernel();
24185 *(s32 *)loc = val;
24186+ pax_close_kernel();
24187 if ((s64)val != *(s32 *)loc)
24188 goto overflow;
24189 break;
24190 case R_X86_64_PC32:
24191 val -= (u64)loc;
24192+ pax_open_kernel();
24193 *(u32 *)loc = val;
24194+ pax_close_kernel();
24195+
24196 #if 0
24197 if ((s64)val != *(s32 *)loc)
24198 goto overflow;
24199diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24200index 88458fa..349f7a4 100644
24201--- a/arch/x86/kernel/msr.c
24202+++ b/arch/x86/kernel/msr.c
24203@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24204 return notifier_from_errno(err);
24205 }
24206
24207-static struct notifier_block __refdata msr_class_cpu_notifier = {
24208+static struct notifier_block msr_class_cpu_notifier = {
24209 .notifier_call = msr_class_cpu_callback,
24210 };
24211
24212diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24213index ba77ebc..65da999 100644
24214--- a/arch/x86/kernel/nmi.c
24215+++ b/arch/x86/kernel/nmi.c
24216@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24217 return handled;
24218 }
24219
24220-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24221+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24222 {
24223 struct nmi_desc *desc = nmi_to_desc(type);
24224 unsigned long flags;
24225@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24226 * event confuses some handlers (kdump uses this flag)
24227 */
24228 if (action->flags & NMI_FLAG_FIRST)
24229- list_add_rcu(&action->list, &desc->head);
24230+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24231 else
24232- list_add_tail_rcu(&action->list, &desc->head);
24233+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24234
24235 spin_unlock_irqrestore(&desc->lock, flags);
24236 return 0;
24237@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24238 if (!strcmp(n->name, name)) {
24239 WARN(in_nmi(),
24240 "Trying to free NMI (%s) from NMI context!\n", n->name);
24241- list_del_rcu(&n->list);
24242+ pax_list_del_rcu((struct list_head *)&n->list);
24243 break;
24244 }
24245 }
24246@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24247 dotraplinkage notrace __kprobes void
24248 do_nmi(struct pt_regs *regs, long error_code)
24249 {
24250+
24251+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24252+ if (!user_mode(regs)) {
24253+ unsigned long cs = regs->cs & 0xFFFF;
24254+ unsigned long ip = ktva_ktla(regs->ip);
24255+
24256+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24257+ regs->ip = ip;
24258+ }
24259+#endif
24260+
24261 nmi_nesting_preprocess(regs);
24262
24263 nmi_enter();
24264diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24265index 6d9582e..f746287 100644
24266--- a/arch/x86/kernel/nmi_selftest.c
24267+++ b/arch/x86/kernel/nmi_selftest.c
24268@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24269 {
24270 /* trap all the unknown NMIs we may generate */
24271 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24272- __initdata);
24273+ __initconst);
24274 }
24275
24276 static void __init cleanup_nmi_testsuite(void)
24277@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24278 unsigned long timeout;
24279
24280 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24281- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24282+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24283 nmi_fail = FAILURE;
24284 return;
24285 }
24286diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24287index 676b8c7..870ba04 100644
24288--- a/arch/x86/kernel/paravirt-spinlocks.c
24289+++ b/arch/x86/kernel/paravirt-spinlocks.c
24290@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24291 arch_spin_lock(lock);
24292 }
24293
24294-struct pv_lock_ops pv_lock_ops = {
24295+struct pv_lock_ops pv_lock_ops __read_only = {
24296 #ifdef CONFIG_SMP
24297 .spin_is_locked = __ticket_spin_is_locked,
24298 .spin_is_contended = __ticket_spin_is_contended,
24299diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24300index cd6de64..27c6af0 100644
24301--- a/arch/x86/kernel/paravirt.c
24302+++ b/arch/x86/kernel/paravirt.c
24303@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24304 {
24305 return x;
24306 }
24307+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24308+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24309+#endif
24310
24311 void __init default_banner(void)
24312 {
24313@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24314 if (opfunc == NULL)
24315 /* If there's no function, patch it with a ud2a (BUG) */
24316 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24317- else if (opfunc == _paravirt_nop)
24318+ else if (opfunc == (void *)_paravirt_nop)
24319 /* If the operation is a nop, then nop the callsite */
24320 ret = paravirt_patch_nop();
24321
24322 /* identity functions just return their single argument */
24323- else if (opfunc == _paravirt_ident_32)
24324+ else if (opfunc == (void *)_paravirt_ident_32)
24325 ret = paravirt_patch_ident_32(insnbuf, len);
24326- else if (opfunc == _paravirt_ident_64)
24327+ else if (opfunc == (void *)_paravirt_ident_64)
24328 ret = paravirt_patch_ident_64(insnbuf, len);
24329+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24330+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24331+ ret = paravirt_patch_ident_64(insnbuf, len);
24332+#endif
24333
24334 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24335 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24336@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24337 if (insn_len > len || start == NULL)
24338 insn_len = len;
24339 else
24340- memcpy(insnbuf, start, insn_len);
24341+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24342
24343 return insn_len;
24344 }
24345@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24346 return this_cpu_read(paravirt_lazy_mode);
24347 }
24348
24349-struct pv_info pv_info = {
24350+struct pv_info pv_info __read_only = {
24351 .name = "bare hardware",
24352 .paravirt_enabled = 0,
24353 .kernel_rpl = 0,
24354@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24355 #endif
24356 };
24357
24358-struct pv_init_ops pv_init_ops = {
24359+struct pv_init_ops pv_init_ops __read_only = {
24360 .patch = native_patch,
24361 };
24362
24363-struct pv_time_ops pv_time_ops = {
24364+struct pv_time_ops pv_time_ops __read_only = {
24365 .sched_clock = native_sched_clock,
24366 .steal_clock = native_steal_clock,
24367 };
24368
24369-struct pv_irq_ops pv_irq_ops = {
24370+struct pv_irq_ops pv_irq_ops __read_only = {
24371 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24372 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24373 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24374@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24375 #endif
24376 };
24377
24378-struct pv_cpu_ops pv_cpu_ops = {
24379+struct pv_cpu_ops pv_cpu_ops __read_only = {
24380 .cpuid = native_cpuid,
24381 .get_debugreg = native_get_debugreg,
24382 .set_debugreg = native_set_debugreg,
24383@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24384 .end_context_switch = paravirt_nop,
24385 };
24386
24387-struct pv_apic_ops pv_apic_ops = {
24388+struct pv_apic_ops pv_apic_ops __read_only= {
24389 #ifdef CONFIG_X86_LOCAL_APIC
24390 .startup_ipi_hook = paravirt_nop,
24391 #endif
24392 };
24393
24394-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24395+#ifdef CONFIG_X86_32
24396+#ifdef CONFIG_X86_PAE
24397+/* 64-bit pagetable entries */
24398+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24399+#else
24400 /* 32-bit pagetable entries */
24401 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24402+#endif
24403 #else
24404 /* 64-bit pagetable entries */
24405 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24406 #endif
24407
24408-struct pv_mmu_ops pv_mmu_ops = {
24409+struct pv_mmu_ops pv_mmu_ops __read_only = {
24410
24411 .read_cr2 = native_read_cr2,
24412 .write_cr2 = native_write_cr2,
24413@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24414 .make_pud = PTE_IDENT,
24415
24416 .set_pgd = native_set_pgd,
24417+ .set_pgd_batched = native_set_pgd_batched,
24418 #endif
24419 #endif /* PAGETABLE_LEVELS >= 3 */
24420
24421@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24422 },
24423
24424 .set_fixmap = native_set_fixmap,
24425+
24426+#ifdef CONFIG_PAX_KERNEXEC
24427+ .pax_open_kernel = native_pax_open_kernel,
24428+ .pax_close_kernel = native_pax_close_kernel,
24429+#endif
24430+
24431 };
24432
24433 EXPORT_SYMBOL_GPL(pv_time_ops);
24434diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24435index 299d493..2ccb0ee 100644
24436--- a/arch/x86/kernel/pci-calgary_64.c
24437+++ b/arch/x86/kernel/pci-calgary_64.c
24438@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24439 tce_space = be64_to_cpu(readq(target));
24440 tce_space = tce_space & TAR_SW_BITS;
24441
24442- tce_space = tce_space & (~specified_table_size);
24443+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24444 info->tce_space = (u64 *)__va(tce_space);
24445 }
24446 }
24447diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24448index 35ccf75..7a15747 100644
24449--- a/arch/x86/kernel/pci-iommu_table.c
24450+++ b/arch/x86/kernel/pci-iommu_table.c
24451@@ -2,7 +2,7 @@
24452 #include <asm/iommu_table.h>
24453 #include <linux/string.h>
24454 #include <linux/kallsyms.h>
24455-
24456+#include <linux/sched.h>
24457
24458 #define DEBUG 1
24459
24460diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24461index 6c483ba..d10ce2f 100644
24462--- a/arch/x86/kernel/pci-swiotlb.c
24463+++ b/arch/x86/kernel/pci-swiotlb.c
24464@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24465 void *vaddr, dma_addr_t dma_addr,
24466 struct dma_attrs *attrs)
24467 {
24468- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24469+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24470 }
24471
24472 static struct dma_map_ops swiotlb_dma_ops = {
24473diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24474index 83369e5..52b93f0 100644
24475--- a/arch/x86/kernel/process.c
24476+++ b/arch/x86/kernel/process.c
24477@@ -36,7 +36,8 @@
24478 * section. Since TSS's are completely CPU-local, we want them
24479 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24480 */
24481-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24482+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24483+EXPORT_SYMBOL(init_tss);
24484
24485 #ifdef CONFIG_X86_64
24486 static DEFINE_PER_CPU(unsigned char, is_idle);
24487@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24488 task_xstate_cachep =
24489 kmem_cache_create("task_xstate", xstate_size,
24490 __alignof__(union thread_xstate),
24491- SLAB_PANIC | SLAB_NOTRACK, NULL);
24492+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24493 }
24494
24495 /*
24496@@ -105,7 +106,7 @@ void exit_thread(void)
24497 unsigned long *bp = t->io_bitmap_ptr;
24498
24499 if (bp) {
24500- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24501+ struct tss_struct *tss = init_tss + get_cpu();
24502
24503 t->io_bitmap_ptr = NULL;
24504 clear_thread_flag(TIF_IO_BITMAP);
24505@@ -125,6 +126,9 @@ void flush_thread(void)
24506 {
24507 struct task_struct *tsk = current;
24508
24509+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24510+ loadsegment(gs, 0);
24511+#endif
24512 flush_ptrace_hw_breakpoint(tsk);
24513 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24514 drop_init_fpu(tsk);
24515@@ -271,7 +275,7 @@ static void __exit_idle(void)
24516 void exit_idle(void)
24517 {
24518 /* idle loop has pid 0 */
24519- if (current->pid)
24520+ if (task_pid_nr(current))
24521 return;
24522 __exit_idle();
24523 }
24524@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24525 return ret;
24526 }
24527 #endif
24528-void stop_this_cpu(void *dummy)
24529+__noreturn void stop_this_cpu(void *dummy)
24530 {
24531 local_irq_disable();
24532 /*
24533@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24534 }
24535 early_param("idle", idle_setup);
24536
24537-unsigned long arch_align_stack(unsigned long sp)
24538+#ifdef CONFIG_PAX_RANDKSTACK
24539+void pax_randomize_kstack(struct pt_regs *regs)
24540 {
24541- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24542- sp -= get_random_int() % 8192;
24543- return sp & ~0xf;
24544-}
24545+ struct thread_struct *thread = &current->thread;
24546+ unsigned long time;
24547
24548-unsigned long arch_randomize_brk(struct mm_struct *mm)
24549-{
24550- unsigned long range_end = mm->brk + 0x02000000;
24551- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24552-}
24553+ if (!randomize_va_space)
24554+ return;
24555+
24556+ if (v8086_mode(regs))
24557+ return;
24558
24559+ rdtscl(time);
24560+
24561+ /* P4 seems to return a 0 LSB, ignore it */
24562+#ifdef CONFIG_MPENTIUM4
24563+ time &= 0x3EUL;
24564+ time <<= 2;
24565+#elif defined(CONFIG_X86_64)
24566+ time &= 0xFUL;
24567+ time <<= 4;
24568+#else
24569+ time &= 0x1FUL;
24570+ time <<= 3;
24571+#endif
24572+
24573+ thread->sp0 ^= time;
24574+ load_sp0(init_tss + smp_processor_id(), thread);
24575+
24576+#ifdef CONFIG_X86_64
24577+ this_cpu_write(kernel_stack, thread->sp0);
24578+#endif
24579+}
24580+#endif
24581diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24582index f8adefc..4bce3d6 100644
24583--- a/arch/x86/kernel/process_32.c
24584+++ b/arch/x86/kernel/process_32.c
24585@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24586 unsigned long thread_saved_pc(struct task_struct *tsk)
24587 {
24588 return ((unsigned long *)tsk->thread.sp)[3];
24589+//XXX return tsk->thread.eip;
24590 }
24591
24592 void __show_regs(struct pt_regs *regs, int all)
24593@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24594 unsigned long sp;
24595 unsigned short ss, gs;
24596
24597- if (user_mode_vm(regs)) {
24598+ if (user_mode(regs)) {
24599 sp = regs->sp;
24600 ss = regs->ss & 0xffff;
24601- gs = get_user_gs(regs);
24602 } else {
24603 sp = kernel_stack_pointer(regs);
24604 savesegment(ss, ss);
24605- savesegment(gs, gs);
24606 }
24607+ gs = get_user_gs(regs);
24608
24609 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24610 (u16)regs->cs, regs->ip, regs->flags,
24611- smp_processor_id());
24612+ raw_smp_processor_id());
24613 print_symbol("EIP is at %s\n", regs->ip);
24614
24615 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24616@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24617 int copy_thread(unsigned long clone_flags, unsigned long sp,
24618 unsigned long arg, struct task_struct *p)
24619 {
24620- struct pt_regs *childregs = task_pt_regs(p);
24621+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24622 struct task_struct *tsk;
24623 int err;
24624
24625 p->thread.sp = (unsigned long) childregs;
24626 p->thread.sp0 = (unsigned long) (childregs+1);
24627+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24628
24629 if (unlikely(p->flags & PF_KTHREAD)) {
24630 /* kernel thread */
24631 memset(childregs, 0, sizeof(struct pt_regs));
24632 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24633- task_user_gs(p) = __KERNEL_STACK_CANARY;
24634- childregs->ds = __USER_DS;
24635- childregs->es = __USER_DS;
24636+ savesegment(gs, childregs->gs);
24637+ childregs->ds = __KERNEL_DS;
24638+ childregs->es = __KERNEL_DS;
24639 childregs->fs = __KERNEL_PERCPU;
24640 childregs->bx = sp; /* function */
24641 childregs->bp = arg;
24642@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24643 struct thread_struct *prev = &prev_p->thread,
24644 *next = &next_p->thread;
24645 int cpu = smp_processor_id();
24646- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24647+ struct tss_struct *tss = init_tss + cpu;
24648 fpu_switch_t fpu;
24649
24650 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24651@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24652 */
24653 lazy_save_gs(prev->gs);
24654
24655+#ifdef CONFIG_PAX_MEMORY_UDEREF
24656+ __set_fs(task_thread_info(next_p)->addr_limit);
24657+#endif
24658+
24659 /*
24660 * Load the per-thread Thread-Local Storage descriptor.
24661 */
24662@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24663 */
24664 arch_end_context_switch(next_p);
24665
24666+ this_cpu_write(current_task, next_p);
24667+ this_cpu_write(current_tinfo, &next_p->tinfo);
24668+
24669 /*
24670 * Restore %gs if needed (which is common)
24671 */
24672@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24673
24674 switch_fpu_finish(next_p, fpu);
24675
24676- this_cpu_write(current_task, next_p);
24677-
24678 return prev_p;
24679 }
24680
24681@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24682 } while (count++ < 16);
24683 return 0;
24684 }
24685-
24686diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24687index 05646ba..0c2906d 100644
24688--- a/arch/x86/kernel/process_64.c
24689+++ b/arch/x86/kernel/process_64.c
24690@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24691 struct pt_regs *childregs;
24692 struct task_struct *me = current;
24693
24694- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24695+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24696 childregs = task_pt_regs(p);
24697 p->thread.sp = (unsigned long) childregs;
24698 p->thread.usersp = me->thread.usersp;
24699+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24700 set_tsk_thread_flag(p, TIF_FORK);
24701 p->fpu_counter = 0;
24702 p->thread.io_bitmap_ptr = NULL;
24703@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24704 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24705 savesegment(es, p->thread.es);
24706 savesegment(ds, p->thread.ds);
24707+ savesegment(ss, p->thread.ss);
24708+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24709 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24710
24711 if (unlikely(p->flags & PF_KTHREAD)) {
24712@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24713 struct thread_struct *prev = &prev_p->thread;
24714 struct thread_struct *next = &next_p->thread;
24715 int cpu = smp_processor_id();
24716- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24717+ struct tss_struct *tss = init_tss + cpu;
24718 unsigned fsindex, gsindex;
24719 fpu_switch_t fpu;
24720
24721@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24722 if (unlikely(next->ds | prev->ds))
24723 loadsegment(ds, next->ds);
24724
24725+ savesegment(ss, prev->ss);
24726+ if (unlikely(next->ss != prev->ss))
24727+ loadsegment(ss, next->ss);
24728
24729 /* We must save %fs and %gs before load_TLS() because
24730 * %fs and %gs may be cleared by load_TLS().
24731@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24732 prev->usersp = this_cpu_read(old_rsp);
24733 this_cpu_write(old_rsp, next->usersp);
24734 this_cpu_write(current_task, next_p);
24735+ this_cpu_write(current_tinfo, &next_p->tinfo);
24736
24737- this_cpu_write(kernel_stack,
24738- (unsigned long)task_stack_page(next_p) +
24739- THREAD_SIZE - KERNEL_STACK_OFFSET);
24740+ this_cpu_write(kernel_stack, next->sp0);
24741
24742 /*
24743 * Now maybe reload the debug registers and handle I/O bitmaps
24744@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24745 if (!p || p == current || p->state == TASK_RUNNING)
24746 return 0;
24747 stack = (unsigned long)task_stack_page(p);
24748- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24749+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24750 return 0;
24751 fp = *(u64 *)(p->thread.sp);
24752 do {
24753- if (fp < (unsigned long)stack ||
24754- fp >= (unsigned long)stack+THREAD_SIZE)
24755+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24756 return 0;
24757 ip = *(u64 *)(fp+8);
24758 if (!in_sched_functions(ip))
24759diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24760index 7461f50..1334029 100644
24761--- a/arch/x86/kernel/ptrace.c
24762+++ b/arch/x86/kernel/ptrace.c
24763@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24764 {
24765 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24766 unsigned long sp = (unsigned long)&regs->sp;
24767- struct thread_info *tinfo;
24768
24769- if (context == (sp & ~(THREAD_SIZE - 1)))
24770+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24771 return sp;
24772
24773- tinfo = (struct thread_info *)context;
24774- if (tinfo->previous_esp)
24775- return tinfo->previous_esp;
24776+ sp = *(unsigned long *)context;
24777+ if (sp)
24778+ return sp;
24779
24780 return (unsigned long)regs;
24781 }
24782@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24783 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24784 {
24785 int i;
24786- int dr7 = 0;
24787+ unsigned long dr7 = 0;
24788 struct arch_hw_breakpoint *info;
24789
24790 for (i = 0; i < HBP_NUM; i++) {
24791@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24792 unsigned long addr, unsigned long data)
24793 {
24794 int ret;
24795- unsigned long __user *datap = (unsigned long __user *)data;
24796+ unsigned long __user *datap = (__force unsigned long __user *)data;
24797
24798 switch (request) {
24799 /* read the word at location addr in the USER area. */
24800@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24801 if ((int) addr < 0)
24802 return -EIO;
24803 ret = do_get_thread_area(child, addr,
24804- (struct user_desc __user *)data);
24805+ (__force struct user_desc __user *) data);
24806 break;
24807
24808 case PTRACE_SET_THREAD_AREA:
24809 if ((int) addr < 0)
24810 return -EIO;
24811 ret = do_set_thread_area(child, addr,
24812- (struct user_desc __user *)data, 0);
24813+ (__force struct user_desc __user *) data, 0);
24814 break;
24815 #endif
24816
24817@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24818
24819 #ifdef CONFIG_X86_64
24820
24821-static struct user_regset x86_64_regsets[] __read_mostly = {
24822+static user_regset_no_const x86_64_regsets[] __read_only = {
24823 [REGSET_GENERAL] = {
24824 .core_note_type = NT_PRSTATUS,
24825 .n = sizeof(struct user_regs_struct) / sizeof(long),
24826@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24827 #endif /* CONFIG_X86_64 */
24828
24829 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24830-static struct user_regset x86_32_regsets[] __read_mostly = {
24831+static user_regset_no_const x86_32_regsets[] __read_only = {
24832 [REGSET_GENERAL] = {
24833 .core_note_type = NT_PRSTATUS,
24834 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24835@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24836 */
24837 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24838
24839-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24840+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24841 {
24842 #ifdef CONFIG_X86_64
24843 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24844@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24845 memset(info, 0, sizeof(*info));
24846 info->si_signo = SIGTRAP;
24847 info->si_code = si_code;
24848- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24849+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24850 }
24851
24852 void user_single_step_siginfo(struct task_struct *tsk,
24853@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24854 # define IS_IA32 0
24855 #endif
24856
24857+#ifdef CONFIG_GRKERNSEC_SETXID
24858+extern void gr_delayed_cred_worker(void);
24859+#endif
24860+
24861 /*
24862 * We must return the syscall number to actually look up in the table.
24863 * This can be -1L to skip running any syscall at all.
24864@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24865
24866 user_exit();
24867
24868+#ifdef CONFIG_GRKERNSEC_SETXID
24869+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24870+ gr_delayed_cred_worker();
24871+#endif
24872+
24873 /*
24874 * If we stepped into a sysenter/syscall insn, it trapped in
24875 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24876@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24877 */
24878 user_exit();
24879
24880+#ifdef CONFIG_GRKERNSEC_SETXID
24881+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24882+ gr_delayed_cred_worker();
24883+#endif
24884+
24885 audit_syscall_exit(regs);
24886
24887 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24888diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24889index 2cb9470..ff1fd80 100644
24890--- a/arch/x86/kernel/pvclock.c
24891+++ b/arch/x86/kernel/pvclock.c
24892@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24893 return pv_tsc_khz;
24894 }
24895
24896-static atomic64_t last_value = ATOMIC64_INIT(0);
24897+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24898
24899 void pvclock_resume(void)
24900 {
24901- atomic64_set(&last_value, 0);
24902+ atomic64_set_unchecked(&last_value, 0);
24903 }
24904
24905 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24906@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24907 * updating at the same time, and one of them could be slightly behind,
24908 * making the assumption that last_value always go forward fail to hold.
24909 */
24910- last = atomic64_read(&last_value);
24911+ last = atomic64_read_unchecked(&last_value);
24912 do {
24913 if (ret < last)
24914 return last;
24915- last = atomic64_cmpxchg(&last_value, last, ret);
24916+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24917 } while (unlikely(last != ret));
24918
24919 return ret;
24920diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24921index 5f4ad27..9d96c99 100644
24922--- a/arch/x86/kernel/reboot.c
24923+++ b/arch/x86/kernel/reboot.c
24924@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24925
24926 void __noreturn machine_real_restart(unsigned int type)
24927 {
24928+
24929+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24930+ struct desc_struct *gdt;
24931+#endif
24932+
24933 local_irq_disable();
24934
24935 /*
24936@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24937
24938 /* Jump to the identity-mapped low memory code */
24939 #ifdef CONFIG_X86_32
24940- asm volatile("jmpl *%0" : :
24941+
24942+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24943+ gdt = get_cpu_gdt_table(smp_processor_id());
24944+ pax_open_kernel();
24945+#ifdef CONFIG_PAX_MEMORY_UDEREF
24946+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24947+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24948+ loadsegment(ds, __KERNEL_DS);
24949+ loadsegment(es, __KERNEL_DS);
24950+ loadsegment(ss, __KERNEL_DS);
24951+#endif
24952+#ifdef CONFIG_PAX_KERNEXEC
24953+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24954+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24955+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24956+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24957+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24958+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24959+#endif
24960+ pax_close_kernel();
24961+#endif
24962+
24963+ asm volatile("ljmpl *%0" : :
24964 "rm" (real_mode_header->machine_real_restart_asm),
24965 "a" (type));
24966 #else
24967@@ -458,7 +485,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24968 * try to force a triple fault and then cycle between hitting the keyboard
24969 * controller and doing that
24970 */
24971-static void native_machine_emergency_restart(void)
24972+static void __noreturn native_machine_emergency_restart(void)
24973 {
24974 int i;
24975 int attempt = 0;
24976@@ -567,13 +594,13 @@ void native_machine_shutdown(void)
24977 #endif
24978 }
24979
24980-static void __machine_emergency_restart(int emergency)
24981+static void __noreturn __machine_emergency_restart(int emergency)
24982 {
24983 reboot_emergency = emergency;
24984 machine_ops.emergency_restart();
24985 }
24986
24987-static void native_machine_restart(char *__unused)
24988+static void __noreturn native_machine_restart(char *__unused)
24989 {
24990 pr_notice("machine restart\n");
24991
24992@@ -582,7 +609,7 @@ static void native_machine_restart(char *__unused)
24993 __machine_emergency_restart(0);
24994 }
24995
24996-static void native_machine_halt(void)
24997+static void __noreturn native_machine_halt(void)
24998 {
24999 /* Stop other cpus and apics */
25000 machine_shutdown();
25001@@ -592,7 +619,7 @@ static void native_machine_halt(void)
25002 stop_this_cpu(NULL);
25003 }
25004
25005-static void native_machine_power_off(void)
25006+static void __noreturn native_machine_power_off(void)
25007 {
25008 if (pm_power_off) {
25009 if (!reboot_force)
25010@@ -601,9 +628,10 @@ static void native_machine_power_off(void)
25011 }
25012 /* A fallback in case there is no PM info available */
25013 tboot_shutdown(TB_SHUTDOWN_HALT);
25014+ unreachable();
25015 }
25016
25017-struct machine_ops machine_ops = {
25018+struct machine_ops machine_ops __read_only = {
25019 .power_off = native_machine_power_off,
25020 .shutdown = native_machine_shutdown,
25021 .emergency_restart = native_machine_emergency_restart,
25022diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25023index c8e41e9..64049ef 100644
25024--- a/arch/x86/kernel/reboot_fixups_32.c
25025+++ b/arch/x86/kernel/reboot_fixups_32.c
25026@@ -57,7 +57,7 @@ struct device_fixup {
25027 unsigned int vendor;
25028 unsigned int device;
25029 void (*reboot_fixup)(struct pci_dev *);
25030-};
25031+} __do_const;
25032
25033 /*
25034 * PCI ids solely used for fixups_table go here
25035diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25036index 3fd2c69..16ef367 100644
25037--- a/arch/x86/kernel/relocate_kernel_64.S
25038+++ b/arch/x86/kernel/relocate_kernel_64.S
25039@@ -11,6 +11,7 @@
25040 #include <asm/kexec.h>
25041 #include <asm/processor-flags.h>
25042 #include <asm/pgtable_types.h>
25043+#include <asm/alternative-asm.h>
25044
25045 /*
25046 * Must be relocatable PIC code callable as a C function
25047@@ -96,8 +97,7 @@ relocate_kernel:
25048
25049 /* jump to identity mapped page */
25050 addq $(identity_mapped - relocate_kernel), %r8
25051- pushq %r8
25052- ret
25053+ jmp *%r8
25054
25055 identity_mapped:
25056 /* set return address to 0 if not preserving context */
25057@@ -167,6 +167,7 @@ identity_mapped:
25058 xorl %r14d, %r14d
25059 xorl %r15d, %r15d
25060
25061+ pax_force_retaddr 0, 1
25062 ret
25063
25064 1:
25065diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25066index 234e1e3..1246d05 100644
25067--- a/arch/x86/kernel/setup.c
25068+++ b/arch/x86/kernel/setup.c
25069@@ -110,6 +110,7 @@
25070 #include <asm/mce.h>
25071 #include <asm/alternative.h>
25072 #include <asm/prom.h>
25073+#include <asm/boot.h>
25074
25075 /*
25076 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25077@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25078 #endif
25079
25080
25081-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25082-unsigned long mmu_cr4_features;
25083+#ifdef CONFIG_X86_64
25084+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25085+#elif defined(CONFIG_X86_PAE)
25086+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25087 #else
25088-unsigned long mmu_cr4_features = X86_CR4_PAE;
25089+unsigned long mmu_cr4_features __read_only;
25090 #endif
25091
25092+void set_in_cr4(unsigned long mask)
25093+{
25094+ unsigned long cr4 = read_cr4();
25095+
25096+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25097+ return;
25098+
25099+ pax_open_kernel();
25100+ mmu_cr4_features |= mask;
25101+ pax_close_kernel();
25102+
25103+ if (trampoline_cr4_features)
25104+ *trampoline_cr4_features = mmu_cr4_features;
25105+ cr4 |= mask;
25106+ write_cr4(cr4);
25107+}
25108+EXPORT_SYMBOL(set_in_cr4);
25109+
25110+void clear_in_cr4(unsigned long mask)
25111+{
25112+ unsigned long cr4 = read_cr4();
25113+
25114+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25115+ return;
25116+
25117+ pax_open_kernel();
25118+ mmu_cr4_features &= ~mask;
25119+ pax_close_kernel();
25120+
25121+ if (trampoline_cr4_features)
25122+ *trampoline_cr4_features = mmu_cr4_features;
25123+ cr4 &= ~mask;
25124+ write_cr4(cr4);
25125+}
25126+EXPORT_SYMBOL(clear_in_cr4);
25127+
25128 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25129 int bootloader_type, bootloader_version;
25130
25131@@ -442,7 +481,7 @@ static void __init parse_setup_data(void)
25132
25133 switch (data_type) {
25134 case SETUP_E820_EXT:
25135- parse_e820_ext(pa_data, data_len);
25136+ parse_e820_ext((struct setup_data __force_kernel *)pa_data, data_len);
25137 break;
25138 case SETUP_DTB:
25139 add_dtb(pa_data);
25140@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25141 * area (640->1Mb) as ram even though it is not.
25142 * take them out.
25143 */
25144- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25145+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25146
25147 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25148 }
25149@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25150 /* called before trim_bios_range() to spare extra sanitize */
25151 static void __init e820_add_kernel_range(void)
25152 {
25153- u64 start = __pa_symbol(_text);
25154+ u64 start = __pa_symbol(ktla_ktva(_text));
25155 u64 size = __pa_symbol(_end) - start;
25156
25157 /*
25158@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25159
25160 void __init setup_arch(char **cmdline_p)
25161 {
25162+#ifdef CONFIG_X86_32
25163+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25164+#else
25165 memblock_reserve(__pa_symbol(_text),
25166 (unsigned long)__bss_stop - (unsigned long)_text);
25167+#endif
25168
25169 early_reserve_initrd();
25170
25171@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25172
25173 if (!boot_params.hdr.root_flags)
25174 root_mountflags &= ~MS_RDONLY;
25175- init_mm.start_code = (unsigned long) _text;
25176- init_mm.end_code = (unsigned long) _etext;
25177+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25178+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25179 init_mm.end_data = (unsigned long) _edata;
25180 init_mm.brk = _brk_end;
25181
25182- code_resource.start = __pa_symbol(_text);
25183- code_resource.end = __pa_symbol(_etext)-1;
25184- data_resource.start = __pa_symbol(_etext);
25185+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25186+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25187+ data_resource.start = __pa_symbol(_sdata);
25188 data_resource.end = __pa_symbol(_edata)-1;
25189 bss_resource.start = __pa_symbol(__bss_start);
25190 bss_resource.end = __pa_symbol(__bss_stop)-1;
25191diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25192index 5cdff03..80fa283 100644
25193--- a/arch/x86/kernel/setup_percpu.c
25194+++ b/arch/x86/kernel/setup_percpu.c
25195@@ -21,19 +21,17 @@
25196 #include <asm/cpu.h>
25197 #include <asm/stackprotector.h>
25198
25199-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25200+#ifdef CONFIG_SMP
25201+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25202 EXPORT_PER_CPU_SYMBOL(cpu_number);
25203+#endif
25204
25205-#ifdef CONFIG_X86_64
25206 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25207-#else
25208-#define BOOT_PERCPU_OFFSET 0
25209-#endif
25210
25211 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25212 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25213
25214-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25215+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25216 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25217 };
25218 EXPORT_SYMBOL(__per_cpu_offset);
25219@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25220 {
25221 #ifdef CONFIG_NEED_MULTIPLE_NODES
25222 pg_data_t *last = NULL;
25223- unsigned int cpu;
25224+ int cpu;
25225
25226 for_each_possible_cpu(cpu) {
25227 int node = early_cpu_to_node(cpu);
25228@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25229 {
25230 #ifdef CONFIG_X86_32
25231 struct desc_struct gdt;
25232+ unsigned long base = per_cpu_offset(cpu);
25233
25234- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25235- 0x2 | DESCTYPE_S, 0x8);
25236- gdt.s = 1;
25237+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25238+ 0x83 | DESCTYPE_S, 0xC);
25239 write_gdt_entry(get_cpu_gdt_table(cpu),
25240 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25241 #endif
25242@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25243 /* alrighty, percpu areas up and running */
25244 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25245 for_each_possible_cpu(cpu) {
25246+#ifdef CONFIG_CC_STACKPROTECTOR
25247+#ifdef CONFIG_X86_32
25248+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25249+#endif
25250+#endif
25251 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25252 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25253 per_cpu(cpu_number, cpu) = cpu;
25254@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25255 */
25256 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25257 #endif
25258+#ifdef CONFIG_CC_STACKPROTECTOR
25259+#ifdef CONFIG_X86_32
25260+ if (!cpu)
25261+ per_cpu(stack_canary.canary, cpu) = canary;
25262+#endif
25263+#endif
25264 /*
25265 * Up to this point, the boot CPU has been using .init.data
25266 * area. Reload any changed state for the boot CPU.
25267diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25268index d859eea..44e17c4 100644
25269--- a/arch/x86/kernel/signal.c
25270+++ b/arch/x86/kernel/signal.c
25271@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25272 * Align the stack pointer according to the i386 ABI,
25273 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25274 */
25275- sp = ((sp + 4) & -16ul) - 4;
25276+ sp = ((sp - 12) & -16ul) - 4;
25277 #else /* !CONFIG_X86_32 */
25278 sp = round_down(sp, 16) - 8;
25279 #endif
25280@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25281 }
25282
25283 if (current->mm->context.vdso)
25284- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25285+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25286 else
25287- restorer = &frame->retcode;
25288+ restorer = (void __user *)&frame->retcode;
25289 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25290 restorer = ksig->ka.sa.sa_restorer;
25291
25292@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25293 * reasons and because gdb uses it as a signature to notice
25294 * signal handler stack frames.
25295 */
25296- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25297+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25298
25299 if (err)
25300 return -EFAULT;
25301@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25302 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25303
25304 /* Set up to return from userspace. */
25305- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25306+ if (current->mm->context.vdso)
25307+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25308+ else
25309+ restorer = (void __user *)&frame->retcode;
25310 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25311 restorer = ksig->ka.sa.sa_restorer;
25312 put_user_ex(restorer, &frame->pretcode);
25313@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25314 * reasons and because gdb uses it as a signature to notice
25315 * signal handler stack frames.
25316 */
25317- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25318+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25319 } put_user_catch(err);
25320
25321 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25322@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25323 {
25324 int usig = signr_convert(ksig->sig);
25325 sigset_t *set = sigmask_to_save();
25326- compat_sigset_t *cset = (compat_sigset_t *) set;
25327+ sigset_t sigcopy;
25328+ compat_sigset_t *cset;
25329+
25330+ sigcopy = *set;
25331+
25332+ cset = (compat_sigset_t *) &sigcopy;
25333
25334 /* Set up the stack frame */
25335 if (is_ia32_frame()) {
25336@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25337 } else if (is_x32_frame()) {
25338 return x32_setup_rt_frame(ksig, cset, regs);
25339 } else {
25340- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25341+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25342 }
25343 }
25344
25345diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25346index cdaa347..f5af55d 100644
25347--- a/arch/x86/kernel/smp.c
25348+++ b/arch/x86/kernel/smp.c
25349@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25350
25351 __setup("nonmi_ipi", nonmi_ipi_setup);
25352
25353-struct smp_ops smp_ops = {
25354+struct smp_ops smp_ops __read_only = {
25355 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25356 .smp_prepare_cpus = native_smp_prepare_cpus,
25357 .smp_cpus_done = native_smp_cpus_done,
25358diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25359index aecc98a..0244a53 100644
25360--- a/arch/x86/kernel/smpboot.c
25361+++ b/arch/x86/kernel/smpboot.c
25362@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25363
25364 enable_start_cpu0 = 0;
25365
25366-#ifdef CONFIG_X86_32
25367- /* switch away from the initial page table */
25368- load_cr3(swapper_pg_dir);
25369- __flush_tlb_all();
25370-#endif
25371-
25372 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25373 barrier();
25374+
25375+ /* switch away from the initial page table */
25376+#ifdef CONFIG_PAX_PER_CPU_PGD
25377+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25378+ __flush_tlb_all();
25379+#elif defined(CONFIG_X86_32)
25380+ load_cr3(swapper_pg_dir);
25381+ __flush_tlb_all();
25382+#endif
25383+
25384 /*
25385 * Check TSC synchronization with the BP:
25386 */
25387@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25388 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25389 (THREAD_SIZE + task_stack_page(idle))) - 1);
25390 per_cpu(current_task, cpu) = idle;
25391+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25392
25393 #ifdef CONFIG_X86_32
25394 /* Stack for startup_32 can be just as for start_secondary onwards */
25395@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25396 #else
25397 clear_tsk_thread_flag(idle, TIF_FORK);
25398 initial_gs = per_cpu_offset(cpu);
25399- per_cpu(kernel_stack, cpu) =
25400- (unsigned long)task_stack_page(idle) -
25401- KERNEL_STACK_OFFSET + THREAD_SIZE;
25402+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25403 #endif
25404+
25405+ pax_open_kernel();
25406 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25407+ pax_close_kernel();
25408+
25409 initial_code = (unsigned long)start_secondary;
25410 stack_start = idle->thread.sp;
25411
25412@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25413 /* the FPU context is blank, nobody can own it */
25414 __cpu_disable_lazy_restore(cpu);
25415
25416+#ifdef CONFIG_PAX_PER_CPU_PGD
25417+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25418+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25419+ KERNEL_PGD_PTRS);
25420+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25421+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25422+ KERNEL_PGD_PTRS);
25423+#endif
25424+
25425 err = do_boot_cpu(apicid, cpu, tidle);
25426 if (err) {
25427 pr_debug("do_boot_cpu failed %d\n", err);
25428diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25429index 9b4d51d..5d28b58 100644
25430--- a/arch/x86/kernel/step.c
25431+++ b/arch/x86/kernel/step.c
25432@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25433 struct desc_struct *desc;
25434 unsigned long base;
25435
25436- seg &= ~7UL;
25437+ seg >>= 3;
25438
25439 mutex_lock(&child->mm->context.lock);
25440- if (unlikely((seg >> 3) >= child->mm->context.size))
25441+ if (unlikely(seg >= child->mm->context.size))
25442 addr = -1L; /* bogus selector, access would fault */
25443 else {
25444 desc = child->mm->context.ldt + seg;
25445@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25446 addr += base;
25447 }
25448 mutex_unlock(&child->mm->context.lock);
25449- }
25450+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25451+ addr = ktla_ktva(addr);
25452
25453 return addr;
25454 }
25455@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25456 unsigned char opcode[15];
25457 unsigned long addr = convert_ip_to_linear(child, regs);
25458
25459+ if (addr == -EINVAL)
25460+ return 0;
25461+
25462 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25463 for (i = 0; i < copied; i++) {
25464 switch (opcode[i]) {
25465diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25466new file mode 100644
25467index 0000000..5877189
25468--- /dev/null
25469+++ b/arch/x86/kernel/sys_i386_32.c
25470@@ -0,0 +1,189 @@
25471+/*
25472+ * This file contains various random system calls that
25473+ * have a non-standard calling sequence on the Linux/i386
25474+ * platform.
25475+ */
25476+
25477+#include <linux/errno.h>
25478+#include <linux/sched.h>
25479+#include <linux/mm.h>
25480+#include <linux/fs.h>
25481+#include <linux/smp.h>
25482+#include <linux/sem.h>
25483+#include <linux/msg.h>
25484+#include <linux/shm.h>
25485+#include <linux/stat.h>
25486+#include <linux/syscalls.h>
25487+#include <linux/mman.h>
25488+#include <linux/file.h>
25489+#include <linux/utsname.h>
25490+#include <linux/ipc.h>
25491+#include <linux/elf.h>
25492+
25493+#include <linux/uaccess.h>
25494+#include <linux/unistd.h>
25495+
25496+#include <asm/syscalls.h>
25497+
25498+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25499+{
25500+ unsigned long pax_task_size = TASK_SIZE;
25501+
25502+#ifdef CONFIG_PAX_SEGMEXEC
25503+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25504+ pax_task_size = SEGMEXEC_TASK_SIZE;
25505+#endif
25506+
25507+ if (flags & MAP_FIXED)
25508+ if (len > pax_task_size || addr > pax_task_size - len)
25509+ return -EINVAL;
25510+
25511+ return 0;
25512+}
25513+
25514+/*
25515+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25516+ */
25517+static unsigned long get_align_mask(void)
25518+{
25519+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25520+ return 0;
25521+
25522+ if (!(current->flags & PF_RANDOMIZE))
25523+ return 0;
25524+
25525+ return va_align.mask;
25526+}
25527+
25528+unsigned long
25529+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25530+ unsigned long len, unsigned long pgoff, unsigned long flags)
25531+{
25532+ struct mm_struct *mm = current->mm;
25533+ struct vm_area_struct *vma;
25534+ unsigned long pax_task_size = TASK_SIZE;
25535+ struct vm_unmapped_area_info info;
25536+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25537+
25538+#ifdef CONFIG_PAX_SEGMEXEC
25539+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25540+ pax_task_size = SEGMEXEC_TASK_SIZE;
25541+#endif
25542+
25543+ pax_task_size -= PAGE_SIZE;
25544+
25545+ if (len > pax_task_size)
25546+ return -ENOMEM;
25547+
25548+ if (flags & MAP_FIXED)
25549+ return addr;
25550+
25551+#ifdef CONFIG_PAX_RANDMMAP
25552+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25553+#endif
25554+
25555+ if (addr) {
25556+ addr = PAGE_ALIGN(addr);
25557+ if (pax_task_size - len >= addr) {
25558+ vma = find_vma(mm, addr);
25559+ if (check_heap_stack_gap(vma, addr, len, offset))
25560+ return addr;
25561+ }
25562+ }
25563+
25564+ info.flags = 0;
25565+ info.length = len;
25566+ info.align_mask = filp ? get_align_mask() : 0;
25567+ info.align_offset = pgoff << PAGE_SHIFT;
25568+ info.threadstack_offset = offset;
25569+
25570+#ifdef CONFIG_PAX_PAGEEXEC
25571+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25572+ info.low_limit = 0x00110000UL;
25573+ info.high_limit = mm->start_code;
25574+
25575+#ifdef CONFIG_PAX_RANDMMAP
25576+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25577+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25578+#endif
25579+
25580+ if (info.low_limit < info.high_limit) {
25581+ addr = vm_unmapped_area(&info);
25582+ if (!IS_ERR_VALUE(addr))
25583+ return addr;
25584+ }
25585+ } else
25586+#endif
25587+
25588+ info.low_limit = mm->mmap_base;
25589+ info.high_limit = pax_task_size;
25590+
25591+ return vm_unmapped_area(&info);
25592+}
25593+
25594+unsigned long
25595+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25596+ const unsigned long len, const unsigned long pgoff,
25597+ const unsigned long flags)
25598+{
25599+ struct vm_area_struct *vma;
25600+ struct mm_struct *mm = current->mm;
25601+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25602+ struct vm_unmapped_area_info info;
25603+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25604+
25605+#ifdef CONFIG_PAX_SEGMEXEC
25606+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25607+ pax_task_size = SEGMEXEC_TASK_SIZE;
25608+#endif
25609+
25610+ pax_task_size -= PAGE_SIZE;
25611+
25612+ /* requested length too big for entire address space */
25613+ if (len > pax_task_size)
25614+ return -ENOMEM;
25615+
25616+ if (flags & MAP_FIXED)
25617+ return addr;
25618+
25619+#ifdef CONFIG_PAX_PAGEEXEC
25620+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25621+ goto bottomup;
25622+#endif
25623+
25624+#ifdef CONFIG_PAX_RANDMMAP
25625+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25626+#endif
25627+
25628+ /* requesting a specific address */
25629+ if (addr) {
25630+ addr = PAGE_ALIGN(addr);
25631+ if (pax_task_size - len >= addr) {
25632+ vma = find_vma(mm, addr);
25633+ if (check_heap_stack_gap(vma, addr, len, offset))
25634+ return addr;
25635+ }
25636+ }
25637+
25638+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25639+ info.length = len;
25640+ info.low_limit = PAGE_SIZE;
25641+ info.high_limit = mm->mmap_base;
25642+ info.align_mask = filp ? get_align_mask() : 0;
25643+ info.align_offset = pgoff << PAGE_SHIFT;
25644+ info.threadstack_offset = offset;
25645+
25646+ addr = vm_unmapped_area(&info);
25647+ if (!(addr & ~PAGE_MASK))
25648+ return addr;
25649+ VM_BUG_ON(addr != -ENOMEM);
25650+
25651+bottomup:
25652+ /*
25653+ * A failed mmap() very likely causes application failure,
25654+ * so fall back to the bottom-up function here. This scenario
25655+ * can happen with large stack limits and large mmap()
25656+ * allocations.
25657+ */
25658+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25659+}
25660diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25661index 30277e2..5664a29 100644
25662--- a/arch/x86/kernel/sys_x86_64.c
25663+++ b/arch/x86/kernel/sys_x86_64.c
25664@@ -81,8 +81,8 @@ out:
25665 return error;
25666 }
25667
25668-static void find_start_end(unsigned long flags, unsigned long *begin,
25669- unsigned long *end)
25670+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25671+ unsigned long *begin, unsigned long *end)
25672 {
25673 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25674 unsigned long new_begin;
25675@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25676 *begin = new_begin;
25677 }
25678 } else {
25679- *begin = current->mm->mmap_legacy_base;
25680+ *begin = mm->mmap_legacy_base;
25681 *end = TASK_SIZE;
25682 }
25683 }
25684@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25685 struct vm_area_struct *vma;
25686 struct vm_unmapped_area_info info;
25687 unsigned long begin, end;
25688+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25689
25690 if (flags & MAP_FIXED)
25691 return addr;
25692
25693- find_start_end(flags, &begin, &end);
25694+ find_start_end(mm, flags, &begin, &end);
25695
25696 if (len > end)
25697 return -ENOMEM;
25698
25699+#ifdef CONFIG_PAX_RANDMMAP
25700+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25701+#endif
25702+
25703 if (addr) {
25704 addr = PAGE_ALIGN(addr);
25705 vma = find_vma(mm, addr);
25706- if (end - len >= addr &&
25707- (!vma || addr + len <= vma->vm_start))
25708+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25709 return addr;
25710 }
25711
25712@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25713 info.high_limit = end;
25714 info.align_mask = filp ? get_align_mask() : 0;
25715 info.align_offset = pgoff << PAGE_SHIFT;
25716+ info.threadstack_offset = offset;
25717 return vm_unmapped_area(&info);
25718 }
25719
25720@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25721 struct mm_struct *mm = current->mm;
25722 unsigned long addr = addr0;
25723 struct vm_unmapped_area_info info;
25724+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25725
25726 /* requested length too big for entire address space */
25727 if (len > TASK_SIZE)
25728@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25729 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25730 goto bottomup;
25731
25732+#ifdef CONFIG_PAX_RANDMMAP
25733+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25734+#endif
25735+
25736 /* requesting a specific address */
25737 if (addr) {
25738 addr = PAGE_ALIGN(addr);
25739 vma = find_vma(mm, addr);
25740- if (TASK_SIZE - len >= addr &&
25741- (!vma || addr + len <= vma->vm_start))
25742+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25743 return addr;
25744 }
25745
25746@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25747 info.high_limit = mm->mmap_base;
25748 info.align_mask = filp ? get_align_mask() : 0;
25749 info.align_offset = pgoff << PAGE_SHIFT;
25750+ info.threadstack_offset = offset;
25751 addr = vm_unmapped_area(&info);
25752 if (!(addr & ~PAGE_MASK))
25753 return addr;
25754diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25755index addf7b5..f960685 100644
25756--- a/arch/x86/kernel/tboot.c
25757+++ b/arch/x86/kernel/tboot.c
25758@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25759
25760 void tboot_shutdown(u32 shutdown_type)
25761 {
25762- void (*shutdown)(void);
25763+ void (* __noreturn shutdown)(void);
25764
25765 if (!tboot_enabled())
25766 return;
25767@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25768
25769 switch_to_tboot_pt();
25770
25771- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25772+ shutdown = (void *)tboot->shutdown_entry;
25773 shutdown();
25774
25775 /* should not reach here */
25776@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25777 return 0;
25778 }
25779
25780-static atomic_t ap_wfs_count;
25781+static atomic_unchecked_t ap_wfs_count;
25782
25783 static int tboot_wait_for_aps(int num_aps)
25784 {
25785@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25786 {
25787 switch (action) {
25788 case CPU_DYING:
25789- atomic_inc(&ap_wfs_count);
25790+ atomic_inc_unchecked(&ap_wfs_count);
25791 if (num_online_cpus() == 1)
25792- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25793+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25794 return NOTIFY_BAD;
25795 break;
25796 }
25797@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25798
25799 tboot_create_trampoline();
25800
25801- atomic_set(&ap_wfs_count, 0);
25802+ atomic_set_unchecked(&ap_wfs_count, 0);
25803 register_hotcpu_notifier(&tboot_cpu_notifier);
25804
25805 #ifdef CONFIG_DEBUG_FS
25806diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25807index 24d3c91..d06b473 100644
25808--- a/arch/x86/kernel/time.c
25809+++ b/arch/x86/kernel/time.c
25810@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25811 {
25812 unsigned long pc = instruction_pointer(regs);
25813
25814- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25815+ if (!user_mode(regs) && in_lock_functions(pc)) {
25816 #ifdef CONFIG_FRAME_POINTER
25817- return *(unsigned long *)(regs->bp + sizeof(long));
25818+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25819 #else
25820 unsigned long *sp =
25821 (unsigned long *)kernel_stack_pointer(regs);
25822@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25823 * or above a saved flags. Eflags has bits 22-31 zero,
25824 * kernel addresses don't.
25825 */
25826+
25827+#ifdef CONFIG_PAX_KERNEXEC
25828+ return ktla_ktva(sp[0]);
25829+#else
25830 if (sp[0] >> 22)
25831 return sp[0];
25832 if (sp[1] >> 22)
25833 return sp[1];
25834 #endif
25835+
25836+#endif
25837 }
25838 return pc;
25839 }
25840diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25841index f7fec09..9991981 100644
25842--- a/arch/x86/kernel/tls.c
25843+++ b/arch/x86/kernel/tls.c
25844@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25845 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25846 return -EINVAL;
25847
25848+#ifdef CONFIG_PAX_SEGMEXEC
25849+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25850+ return -EINVAL;
25851+#endif
25852+
25853 set_tls_desc(p, idx, &info, 1);
25854
25855 return 0;
25856@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25857
25858 if (kbuf)
25859 info = kbuf;
25860- else if (__copy_from_user(infobuf, ubuf, count))
25861+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25862 return -EFAULT;
25863 else
25864 info = infobuf;
25865diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25866index 1c113db..287b42e 100644
25867--- a/arch/x86/kernel/tracepoint.c
25868+++ b/arch/x86/kernel/tracepoint.c
25869@@ -9,11 +9,11 @@
25870 #include <linux/atomic.h>
25871
25872 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25873-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25874+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25875 (unsigned long) trace_idt_table };
25876
25877 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25878-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25879+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25880
25881 static int trace_irq_vector_refcount;
25882 static DEFINE_MUTEX(irq_vector_mutex);
25883diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25884index 1b23a1c..910de0d 100644
25885--- a/arch/x86/kernel/traps.c
25886+++ b/arch/x86/kernel/traps.c
25887@@ -65,7 +65,7 @@
25888 #include <asm/proto.h>
25889
25890 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25891-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25892+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25893 #else
25894 #include <asm/processor-flags.h>
25895 #include <asm/setup.h>
25896@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25897 #endif
25898
25899 /* Must be page-aligned because the real IDT is used in a fixmap. */
25900-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25901+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25902
25903 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25904 EXPORT_SYMBOL_GPL(used_vectors);
25905@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25906 }
25907
25908 static int __kprobes
25909-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25910+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25911 struct pt_regs *regs, long error_code)
25912 {
25913 #ifdef CONFIG_X86_32
25914- if (regs->flags & X86_VM_MASK) {
25915+ if (v8086_mode(regs)) {
25916 /*
25917 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25918 * On nmi (interrupt 2), do_trap should not be called.
25919@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25920 return -1;
25921 }
25922 #endif
25923- if (!user_mode(regs)) {
25924+ if (!user_mode_novm(regs)) {
25925 if (!fixup_exception(regs)) {
25926 tsk->thread.error_code = error_code;
25927 tsk->thread.trap_nr = trapnr;
25928+
25929+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25930+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25931+ str = "PAX: suspicious stack segment fault";
25932+#endif
25933+
25934 die(str, regs, error_code);
25935 }
25936+
25937+#ifdef CONFIG_PAX_REFCOUNT
25938+ if (trapnr == 4)
25939+ pax_report_refcount_overflow(regs);
25940+#endif
25941+
25942 return 0;
25943 }
25944
25945@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25946 }
25947
25948 static void __kprobes
25949-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25950+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25951 long error_code, siginfo_t *info)
25952 {
25953 struct task_struct *tsk = current;
25954@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25955 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25956 printk_ratelimit()) {
25957 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25958- tsk->comm, tsk->pid, str,
25959+ tsk->comm, task_pid_nr(tsk), str,
25960 regs->ip, regs->sp, error_code);
25961 print_vma_addr(" in ", regs->ip);
25962 pr_cont("\n");
25963@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25964 conditional_sti(regs);
25965
25966 #ifdef CONFIG_X86_32
25967- if (regs->flags & X86_VM_MASK) {
25968+ if (v8086_mode(regs)) {
25969 local_irq_enable();
25970 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25971 goto exit;
25972@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25973 #endif
25974
25975 tsk = current;
25976- if (!user_mode(regs)) {
25977+ if (!user_mode_novm(regs)) {
25978 if (fixup_exception(regs))
25979 goto exit;
25980
25981 tsk->thread.error_code = error_code;
25982 tsk->thread.trap_nr = X86_TRAP_GP;
25983 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25984- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25985+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25986+
25987+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25988+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25989+ die("PAX: suspicious general protection fault", regs, error_code);
25990+ else
25991+#endif
25992+
25993 die("general protection fault", regs, error_code);
25994+ }
25995 goto exit;
25996 }
25997
25998+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25999+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26000+ struct mm_struct *mm = tsk->mm;
26001+ unsigned long limit;
26002+
26003+ down_write(&mm->mmap_sem);
26004+ limit = mm->context.user_cs_limit;
26005+ if (limit < TASK_SIZE) {
26006+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26007+ up_write(&mm->mmap_sem);
26008+ return;
26009+ }
26010+ up_write(&mm->mmap_sem);
26011+ }
26012+#endif
26013+
26014 tsk->thread.error_code = error_code;
26015 tsk->thread.trap_nr = X86_TRAP_GP;
26016
26017@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26018 /* It's safe to allow irq's after DR6 has been saved */
26019 preempt_conditional_sti(regs);
26020
26021- if (regs->flags & X86_VM_MASK) {
26022+ if (v8086_mode(regs)) {
26023 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26024 X86_TRAP_DB);
26025 preempt_conditional_cli(regs);
26026@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26027 * We already checked v86 mode above, so we can check for kernel mode
26028 * by just checking the CPL of CS.
26029 */
26030- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26031+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26032 tsk->thread.debugreg6 &= ~DR_STEP;
26033 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26034 regs->flags &= ~X86_EFLAGS_TF;
26035@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26036 return;
26037 conditional_sti(regs);
26038
26039- if (!user_mode_vm(regs))
26040+ if (!user_mode(regs))
26041 {
26042 if (!fixup_exception(regs)) {
26043 task->thread.error_code = error_code;
26044diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26045index 2ed8459..7cf329f 100644
26046--- a/arch/x86/kernel/uprobes.c
26047+++ b/arch/x86/kernel/uprobes.c
26048@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26049 int ret = NOTIFY_DONE;
26050
26051 /* We are only interested in userspace traps */
26052- if (regs && !user_mode_vm(regs))
26053+ if (regs && !user_mode(regs))
26054 return NOTIFY_DONE;
26055
26056 switch (val) {
26057@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26058
26059 if (ncopied != rasize) {
26060 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26061- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26062+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26063
26064 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26065 }
26066diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26067index b9242ba..50c5edd 100644
26068--- a/arch/x86/kernel/verify_cpu.S
26069+++ b/arch/x86/kernel/verify_cpu.S
26070@@ -20,6 +20,7 @@
26071 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26072 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26073 * arch/x86/kernel/head_32.S: processor startup
26074+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26075 *
26076 * verify_cpu, returns the status of longmode and SSE in register %eax.
26077 * 0: Success 1: Failure
26078diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26079index e8edcf5..27f9344 100644
26080--- a/arch/x86/kernel/vm86_32.c
26081+++ b/arch/x86/kernel/vm86_32.c
26082@@ -44,6 +44,7 @@
26083 #include <linux/ptrace.h>
26084 #include <linux/audit.h>
26085 #include <linux/stddef.h>
26086+#include <linux/grsecurity.h>
26087
26088 #include <asm/uaccess.h>
26089 #include <asm/io.h>
26090@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26091 do_exit(SIGSEGV);
26092 }
26093
26094- tss = &per_cpu(init_tss, get_cpu());
26095+ tss = init_tss + get_cpu();
26096 current->thread.sp0 = current->thread.saved_sp0;
26097 current->thread.sysenter_cs = __KERNEL_CS;
26098 load_sp0(tss, &current->thread);
26099@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26100
26101 if (tsk->thread.saved_sp0)
26102 return -EPERM;
26103+
26104+#ifdef CONFIG_GRKERNSEC_VM86
26105+ if (!capable(CAP_SYS_RAWIO)) {
26106+ gr_handle_vm86();
26107+ return -EPERM;
26108+ }
26109+#endif
26110+
26111 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26112 offsetof(struct kernel_vm86_struct, vm86plus) -
26113 sizeof(info.regs));
26114@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26115 int tmp;
26116 struct vm86plus_struct __user *v86;
26117
26118+#ifdef CONFIG_GRKERNSEC_VM86
26119+ if (!capable(CAP_SYS_RAWIO)) {
26120+ gr_handle_vm86();
26121+ return -EPERM;
26122+ }
26123+#endif
26124+
26125 tsk = current;
26126 switch (cmd) {
26127 case VM86_REQUEST_IRQ:
26128@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26129 tsk->thread.saved_fs = info->regs32->fs;
26130 tsk->thread.saved_gs = get_user_gs(info->regs32);
26131
26132- tss = &per_cpu(init_tss, get_cpu());
26133+ tss = init_tss + get_cpu();
26134 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26135 if (cpu_has_sep)
26136 tsk->thread.sysenter_cs = 0;
26137@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26138 goto cannot_handle;
26139 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26140 goto cannot_handle;
26141- intr_ptr = (unsigned long __user *) (i << 2);
26142+ intr_ptr = (__force unsigned long __user *) (i << 2);
26143 if (get_user(segoffs, intr_ptr))
26144 goto cannot_handle;
26145 if ((segoffs >> 16) == BIOSSEG)
26146diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26147index 10c4f30..65408b9 100644
26148--- a/arch/x86/kernel/vmlinux.lds.S
26149+++ b/arch/x86/kernel/vmlinux.lds.S
26150@@ -26,6 +26,13 @@
26151 #include <asm/page_types.h>
26152 #include <asm/cache.h>
26153 #include <asm/boot.h>
26154+#include <asm/segment.h>
26155+
26156+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26157+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26158+#else
26159+#define __KERNEL_TEXT_OFFSET 0
26160+#endif
26161
26162 #undef i386 /* in case the preprocessor is a 32bit one */
26163
26164@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26165
26166 PHDRS {
26167 text PT_LOAD FLAGS(5); /* R_E */
26168+#ifdef CONFIG_X86_32
26169+ module PT_LOAD FLAGS(5); /* R_E */
26170+#endif
26171+#ifdef CONFIG_XEN
26172+ rodata PT_LOAD FLAGS(5); /* R_E */
26173+#else
26174+ rodata PT_LOAD FLAGS(4); /* R__ */
26175+#endif
26176 data PT_LOAD FLAGS(6); /* RW_ */
26177-#ifdef CONFIG_X86_64
26178+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26179 #ifdef CONFIG_SMP
26180 percpu PT_LOAD FLAGS(6); /* RW_ */
26181 #endif
26182+ text.init PT_LOAD FLAGS(5); /* R_E */
26183+ text.exit PT_LOAD FLAGS(5); /* R_E */
26184 init PT_LOAD FLAGS(7); /* RWE */
26185-#endif
26186 note PT_NOTE FLAGS(0); /* ___ */
26187 }
26188
26189 SECTIONS
26190 {
26191 #ifdef CONFIG_X86_32
26192- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26193- phys_startup_32 = startup_32 - LOAD_OFFSET;
26194+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26195 #else
26196- . = __START_KERNEL;
26197- phys_startup_64 = startup_64 - LOAD_OFFSET;
26198+ . = __START_KERNEL;
26199 #endif
26200
26201 /* Text and read-only data */
26202- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26203- _text = .;
26204+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26205 /* bootstrapping code */
26206+#ifdef CONFIG_X86_32
26207+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26208+#else
26209+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26210+#endif
26211+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26212+ _text = .;
26213 HEAD_TEXT
26214 . = ALIGN(8);
26215 _stext = .;
26216@@ -104,13 +124,47 @@ SECTIONS
26217 IRQENTRY_TEXT
26218 *(.fixup)
26219 *(.gnu.warning)
26220- /* End of text section */
26221- _etext = .;
26222 } :text = 0x9090
26223
26224- NOTES :text :note
26225+ . += __KERNEL_TEXT_OFFSET;
26226
26227- EXCEPTION_TABLE(16) :text = 0x9090
26228+#ifdef CONFIG_X86_32
26229+ . = ALIGN(PAGE_SIZE);
26230+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26231+
26232+#ifdef CONFIG_PAX_KERNEXEC
26233+ MODULES_EXEC_VADDR = .;
26234+ BYTE(0)
26235+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26236+ . = ALIGN(HPAGE_SIZE) - 1;
26237+ MODULES_EXEC_END = .;
26238+#endif
26239+
26240+ } :module
26241+#endif
26242+
26243+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26244+ /* End of text section */
26245+ BYTE(0)
26246+ _etext = . - __KERNEL_TEXT_OFFSET;
26247+ }
26248+
26249+#ifdef CONFIG_X86_32
26250+ . = ALIGN(PAGE_SIZE);
26251+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26252+ . = ALIGN(PAGE_SIZE);
26253+ *(.empty_zero_page)
26254+ *(.initial_pg_fixmap)
26255+ *(.initial_pg_pmd)
26256+ *(.initial_page_table)
26257+ *(.swapper_pg_dir)
26258+ } :rodata
26259+#endif
26260+
26261+ . = ALIGN(PAGE_SIZE);
26262+ NOTES :rodata :note
26263+
26264+ EXCEPTION_TABLE(16) :rodata
26265
26266 #if defined(CONFIG_DEBUG_RODATA)
26267 /* .text should occupy whole number of pages */
26268@@ -122,16 +176,20 @@ SECTIONS
26269
26270 /* Data */
26271 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26272+
26273+#ifdef CONFIG_PAX_KERNEXEC
26274+ . = ALIGN(HPAGE_SIZE);
26275+#else
26276+ . = ALIGN(PAGE_SIZE);
26277+#endif
26278+
26279 /* Start of data section */
26280 _sdata = .;
26281
26282 /* init_task */
26283 INIT_TASK_DATA(THREAD_SIZE)
26284
26285-#ifdef CONFIG_X86_32
26286- /* 32 bit has nosave before _edata */
26287 NOSAVE_DATA
26288-#endif
26289
26290 PAGE_ALIGNED_DATA(PAGE_SIZE)
26291
26292@@ -172,12 +230,19 @@ SECTIONS
26293 #endif /* CONFIG_X86_64 */
26294
26295 /* Init code and data - will be freed after init */
26296- . = ALIGN(PAGE_SIZE);
26297 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26298+ BYTE(0)
26299+
26300+#ifdef CONFIG_PAX_KERNEXEC
26301+ . = ALIGN(HPAGE_SIZE);
26302+#else
26303+ . = ALIGN(PAGE_SIZE);
26304+#endif
26305+
26306 __init_begin = .; /* paired with __init_end */
26307- }
26308+ } :init.begin
26309
26310-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26311+#ifdef CONFIG_SMP
26312 /*
26313 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26314 * output PHDR, so the next output section - .init.text - should
26315@@ -186,12 +251,27 @@ SECTIONS
26316 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26317 #endif
26318
26319- INIT_TEXT_SECTION(PAGE_SIZE)
26320-#ifdef CONFIG_X86_64
26321- :init
26322-#endif
26323+ . = ALIGN(PAGE_SIZE);
26324+ init_begin = .;
26325+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26326+ VMLINUX_SYMBOL(_sinittext) = .;
26327+ INIT_TEXT
26328+ VMLINUX_SYMBOL(_einittext) = .;
26329+ . = ALIGN(PAGE_SIZE);
26330+ } :text.init
26331
26332- INIT_DATA_SECTION(16)
26333+ /*
26334+ * .exit.text is discard at runtime, not link time, to deal with
26335+ * references from .altinstructions and .eh_frame
26336+ */
26337+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26338+ EXIT_TEXT
26339+ . = ALIGN(16);
26340+ } :text.exit
26341+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26342+
26343+ . = ALIGN(PAGE_SIZE);
26344+ INIT_DATA_SECTION(16) :init
26345
26346 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26347 __x86_cpu_dev_start = .;
26348@@ -253,19 +333,12 @@ SECTIONS
26349 }
26350
26351 . = ALIGN(8);
26352- /*
26353- * .exit.text is discard at runtime, not link time, to deal with
26354- * references from .altinstructions and .eh_frame
26355- */
26356- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26357- EXIT_TEXT
26358- }
26359
26360 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26361 EXIT_DATA
26362 }
26363
26364-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26365+#ifndef CONFIG_SMP
26366 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26367 #endif
26368
26369@@ -284,16 +357,10 @@ SECTIONS
26370 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26371 __smp_locks = .;
26372 *(.smp_locks)
26373- . = ALIGN(PAGE_SIZE);
26374 __smp_locks_end = .;
26375+ . = ALIGN(PAGE_SIZE);
26376 }
26377
26378-#ifdef CONFIG_X86_64
26379- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26380- NOSAVE_DATA
26381- }
26382-#endif
26383-
26384 /* BSS */
26385 . = ALIGN(PAGE_SIZE);
26386 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26387@@ -309,6 +376,7 @@ SECTIONS
26388 __brk_base = .;
26389 . += 64 * 1024; /* 64k alignment slop space */
26390 *(.brk_reservation) /* areas brk users have reserved */
26391+ . = ALIGN(HPAGE_SIZE);
26392 __brk_limit = .;
26393 }
26394
26395@@ -335,13 +403,12 @@ SECTIONS
26396 * for the boot processor.
26397 */
26398 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26399-INIT_PER_CPU(gdt_page);
26400 INIT_PER_CPU(irq_stack_union);
26401
26402 /*
26403 * Build-time check on the image size:
26404 */
26405-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26406+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26407 "kernel image bigger than KERNEL_IMAGE_SIZE");
26408
26409 #ifdef CONFIG_SMP
26410diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26411index 1f96f93..d5c8f7a 100644
26412--- a/arch/x86/kernel/vsyscall_64.c
26413+++ b/arch/x86/kernel/vsyscall_64.c
26414@@ -56,15 +56,13 @@
26415 DEFINE_VVAR(int, vgetcpu_mode);
26416 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26417
26418-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26419+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26420
26421 static int __init vsyscall_setup(char *str)
26422 {
26423 if (str) {
26424 if (!strcmp("emulate", str))
26425 vsyscall_mode = EMULATE;
26426- else if (!strcmp("native", str))
26427- vsyscall_mode = NATIVE;
26428 else if (!strcmp("none", str))
26429 vsyscall_mode = NONE;
26430 else
26431@@ -323,8 +321,7 @@ do_ret:
26432 return true;
26433
26434 sigsegv:
26435- force_sig(SIGSEGV, current);
26436- return true;
26437+ do_group_exit(SIGKILL);
26438 }
26439
26440 /*
26441@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26442 extern char __vvar_page;
26443 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26444
26445- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26446- vsyscall_mode == NATIVE
26447- ? PAGE_KERNEL_VSYSCALL
26448- : PAGE_KERNEL_VVAR);
26449+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26450 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26451 (unsigned long)VSYSCALL_START);
26452
26453diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26454index b014d94..e775258 100644
26455--- a/arch/x86/kernel/x8664_ksyms_64.c
26456+++ b/arch/x86/kernel/x8664_ksyms_64.c
26457@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26458 EXPORT_SYMBOL(copy_user_generic_unrolled);
26459 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26460 EXPORT_SYMBOL(__copy_user_nocache);
26461-EXPORT_SYMBOL(_copy_from_user);
26462-EXPORT_SYMBOL(_copy_to_user);
26463
26464 EXPORT_SYMBOL(copy_page);
26465 EXPORT_SYMBOL(clear_page);
26466@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26467 #ifndef CONFIG_PARAVIRT
26468 EXPORT_SYMBOL(native_load_gs_index);
26469 #endif
26470+
26471+#ifdef CONFIG_PAX_PER_CPU_PGD
26472+EXPORT_SYMBOL(cpu_pgd);
26473+#endif
26474diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26475index 5f24c71..1dadf09 100644
26476--- a/arch/x86/kernel/x86_init.c
26477+++ b/arch/x86/kernel/x86_init.c
26478@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26479 static void default_nmi_init(void) { };
26480 static int default_i8042_detect(void) { return 1; };
26481
26482-struct x86_platform_ops x86_platform = {
26483+struct x86_platform_ops x86_platform __read_only = {
26484 .calibrate_tsc = native_calibrate_tsc,
26485 .get_wallclock = mach_get_cmos_time,
26486 .set_wallclock = mach_set_rtc_mmss,
26487@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26488 };
26489
26490 EXPORT_SYMBOL_GPL(x86_platform);
26491-struct x86_msi_ops x86_msi = {
26492+struct x86_msi_ops x86_msi __read_only = {
26493 .setup_msi_irqs = native_setup_msi_irqs,
26494 .compose_msi_msg = native_compose_msi_msg,
26495 .teardown_msi_irq = native_teardown_msi_irq,
26496@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26497 .setup_hpet_msi = default_setup_hpet_msi,
26498 };
26499
26500-struct x86_io_apic_ops x86_io_apic_ops = {
26501+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26502 .init = native_io_apic_init_mappings,
26503 .read = native_io_apic_read,
26504 .write = native_io_apic_write,
26505diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26506index 422fd82..c3687ca 100644
26507--- a/arch/x86/kernel/xsave.c
26508+++ b/arch/x86/kernel/xsave.c
26509@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26510 {
26511 int err;
26512
26513+ buf = (struct xsave_struct __user *)____m(buf);
26514 if (use_xsave())
26515 err = xsave_user(buf);
26516 else if (use_fxsr())
26517@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26518 */
26519 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26520 {
26521+ buf = (void __user *)____m(buf);
26522 if (use_xsave()) {
26523 if ((unsigned long)buf % 64 || fx_only) {
26524 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26525diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26526index a20ecb5..d0e2194 100644
26527--- a/arch/x86/kvm/cpuid.c
26528+++ b/arch/x86/kvm/cpuid.c
26529@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26530 struct kvm_cpuid2 *cpuid,
26531 struct kvm_cpuid_entry2 __user *entries)
26532 {
26533- int r;
26534+ int r, i;
26535
26536 r = -E2BIG;
26537 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26538 goto out;
26539 r = -EFAULT;
26540- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26541- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26542+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26543 goto out;
26544+ for (i = 0; i < cpuid->nent; ++i) {
26545+ struct kvm_cpuid_entry2 cpuid_entry;
26546+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26547+ goto out;
26548+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26549+ }
26550 vcpu->arch.cpuid_nent = cpuid->nent;
26551 kvm_apic_set_version(vcpu);
26552 kvm_x86_ops->cpuid_update(vcpu);
26553@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26554 struct kvm_cpuid2 *cpuid,
26555 struct kvm_cpuid_entry2 __user *entries)
26556 {
26557- int r;
26558+ int r, i;
26559
26560 r = -E2BIG;
26561 if (cpuid->nent < vcpu->arch.cpuid_nent)
26562 goto out;
26563 r = -EFAULT;
26564- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26565- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26566+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26567 goto out;
26568+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26569+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26570+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26571+ goto out;
26572+ }
26573 return 0;
26574
26575 out:
26576diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26577index afc1124..3e431f2 100644
26578--- a/arch/x86/kvm/lapic.c
26579+++ b/arch/x86/kvm/lapic.c
26580@@ -55,7 +55,7 @@
26581 #define APIC_BUS_CYCLE_NS 1
26582
26583 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26584-#define apic_debug(fmt, arg...)
26585+#define apic_debug(fmt, arg...) do {} while (0)
26586
26587 #define APIC_LVT_NUM 6
26588 /* 14 is the version for Xeon and Pentium 8.4.8*/
26589diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26590index 7769699..c8aca4a7f 100644
26591--- a/arch/x86/kvm/paging_tmpl.h
26592+++ b/arch/x86/kvm/paging_tmpl.h
26593@@ -208,7 +208,7 @@ retry_walk:
26594 if (unlikely(kvm_is_error_hva(host_addr)))
26595 goto error;
26596
26597- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26598+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26599 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26600 goto error;
26601 walker->ptep_user[walker->level - 1] = ptep_user;
26602diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26603index c0bc803..6837a50 100644
26604--- a/arch/x86/kvm/svm.c
26605+++ b/arch/x86/kvm/svm.c
26606@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26607 int cpu = raw_smp_processor_id();
26608
26609 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26610+
26611+ pax_open_kernel();
26612 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26613+ pax_close_kernel();
26614+
26615 load_TR_desc();
26616 }
26617
26618@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26619 #endif
26620 #endif
26621
26622+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26623+ __set_fs(current_thread_info()->addr_limit);
26624+#endif
26625+
26626 reload_tss(vcpu);
26627
26628 local_irq_disable();
26629diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26630index 064d0be..f5f758e 100644
26631--- a/arch/x86/kvm/vmx.c
26632+++ b/arch/x86/kvm/vmx.c
26633@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26634 #endif
26635 }
26636
26637-static void vmcs_clear_bits(unsigned long field, u32 mask)
26638+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26639 {
26640 vmcs_writel(field, vmcs_readl(field) & ~mask);
26641 }
26642
26643-static void vmcs_set_bits(unsigned long field, u32 mask)
26644+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26645 {
26646 vmcs_writel(field, vmcs_readl(field) | mask);
26647 }
26648@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26649 struct desc_struct *descs;
26650
26651 descs = (void *)gdt->address;
26652+
26653+ pax_open_kernel();
26654 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26655+ pax_close_kernel();
26656+
26657 load_TR_desc();
26658 }
26659
26660@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26661 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26662 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26663
26664+#ifdef CONFIG_PAX_PER_CPU_PGD
26665+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26666+#endif
26667+
26668 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26669 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26670 vmx->loaded_vmcs->cpu = cpu;
26671@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26672 if (!cpu_has_vmx_flexpriority())
26673 flexpriority_enabled = 0;
26674
26675- if (!cpu_has_vmx_tpr_shadow())
26676- kvm_x86_ops->update_cr8_intercept = NULL;
26677+ if (!cpu_has_vmx_tpr_shadow()) {
26678+ pax_open_kernel();
26679+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26680+ pax_close_kernel();
26681+ }
26682
26683 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26684 kvm_disable_largepages();
26685@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26686 if (!cpu_has_vmx_apicv())
26687 enable_apicv = 0;
26688
26689+ pax_open_kernel();
26690 if (enable_apicv)
26691- kvm_x86_ops->update_cr8_intercept = NULL;
26692+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26693 else {
26694- kvm_x86_ops->hwapic_irr_update = NULL;
26695- kvm_x86_ops->deliver_posted_interrupt = NULL;
26696- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26697+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26698+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26699+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26700 }
26701+ pax_close_kernel();
26702
26703 if (nested)
26704 nested_vmx_setup_ctls_msrs();
26705@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26706
26707 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26708 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26709+
26710+#ifndef CONFIG_PAX_PER_CPU_PGD
26711 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26712+#endif
26713
26714 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26715 #ifdef CONFIG_X86_64
26716@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26717 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26718 vmx->host_idt_base = dt.address;
26719
26720- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26721+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26722
26723 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26724 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26725@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26726 "jmp 2f \n\t"
26727 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26728 "2: "
26729+
26730+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26731+ "ljmp %[cs],$3f\n\t"
26732+ "3: "
26733+#endif
26734+
26735 /* Save guest registers, load host registers, keep flags */
26736 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26737 "pop %0 \n\t"
26738@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26739 #endif
26740 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26741 [wordsize]"i"(sizeof(ulong))
26742+
26743+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26744+ ,[cs]"i"(__KERNEL_CS)
26745+#endif
26746+
26747 : "cc", "memory"
26748 #ifdef CONFIG_X86_64
26749 , "rax", "rbx", "rdi", "rsi"
26750@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26751 if (debugctlmsr)
26752 update_debugctlmsr(debugctlmsr);
26753
26754-#ifndef CONFIG_X86_64
26755+#ifdef CONFIG_X86_32
26756 /*
26757 * The sysexit path does not restore ds/es, so we must set them to
26758 * a reasonable value ourselves.
26759@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26760 * may be executed in interrupt context, which saves and restore segments
26761 * around it, nullifying its effect.
26762 */
26763- loadsegment(ds, __USER_DS);
26764- loadsegment(es, __USER_DS);
26765+ loadsegment(ds, __KERNEL_DS);
26766+ loadsegment(es, __KERNEL_DS);
26767+ loadsegment(ss, __KERNEL_DS);
26768+
26769+#ifdef CONFIG_PAX_KERNEXEC
26770+ loadsegment(fs, __KERNEL_PERCPU);
26771+#endif
26772+
26773+#ifdef CONFIG_PAX_MEMORY_UDEREF
26774+ __set_fs(current_thread_info()->addr_limit);
26775+#endif
26776+
26777 #endif
26778
26779 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26780diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26781index d21bce5..fdae9f1 100644
26782--- a/arch/x86/kvm/x86.c
26783+++ b/arch/x86/kvm/x86.c
26784@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26785 {
26786 struct kvm *kvm = vcpu->kvm;
26787 int lm = is_long_mode(vcpu);
26788- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26789- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26790+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26791+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26792 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26793 : kvm->arch.xen_hvm_config.blob_size_32;
26794 u32 page_num = data & ~PAGE_MASK;
26795@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26796 if (n < msr_list.nmsrs)
26797 goto out;
26798 r = -EFAULT;
26799+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26800+ goto out;
26801 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26802 num_msrs_to_save * sizeof(u32)))
26803 goto out;
26804@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26805 };
26806 #endif
26807
26808-int kvm_arch_init(void *opaque)
26809+int kvm_arch_init(const void *opaque)
26810 {
26811 int r;
26812 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26813diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26814index 6a22c19..1763f04 100644
26815--- a/arch/x86/lguest/boot.c
26816+++ b/arch/x86/lguest/boot.c
26817@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26818 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26819 * Launcher to reboot us.
26820 */
26821-static void lguest_restart(char *reason)
26822+static __noreturn void lguest_restart(char *reason)
26823 {
26824 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26825+ BUG();
26826 }
26827
26828 /*G:050
26829diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26830index 00933d5..3a64af9 100644
26831--- a/arch/x86/lib/atomic64_386_32.S
26832+++ b/arch/x86/lib/atomic64_386_32.S
26833@@ -48,6 +48,10 @@ BEGIN(read)
26834 movl (v), %eax
26835 movl 4(v), %edx
26836 RET_ENDP
26837+BEGIN(read_unchecked)
26838+ movl (v), %eax
26839+ movl 4(v), %edx
26840+RET_ENDP
26841 #undef v
26842
26843 #define v %esi
26844@@ -55,6 +59,10 @@ BEGIN(set)
26845 movl %ebx, (v)
26846 movl %ecx, 4(v)
26847 RET_ENDP
26848+BEGIN(set_unchecked)
26849+ movl %ebx, (v)
26850+ movl %ecx, 4(v)
26851+RET_ENDP
26852 #undef v
26853
26854 #define v %esi
26855@@ -70,6 +78,20 @@ RET_ENDP
26856 BEGIN(add)
26857 addl %eax, (v)
26858 adcl %edx, 4(v)
26859+
26860+#ifdef CONFIG_PAX_REFCOUNT
26861+ jno 0f
26862+ subl %eax, (v)
26863+ sbbl %edx, 4(v)
26864+ int $4
26865+0:
26866+ _ASM_EXTABLE(0b, 0b)
26867+#endif
26868+
26869+RET_ENDP
26870+BEGIN(add_unchecked)
26871+ addl %eax, (v)
26872+ adcl %edx, 4(v)
26873 RET_ENDP
26874 #undef v
26875
26876@@ -77,6 +99,24 @@ RET_ENDP
26877 BEGIN(add_return)
26878 addl (v), %eax
26879 adcl 4(v), %edx
26880+
26881+#ifdef CONFIG_PAX_REFCOUNT
26882+ into
26883+1234:
26884+ _ASM_EXTABLE(1234b, 2f)
26885+#endif
26886+
26887+ movl %eax, (v)
26888+ movl %edx, 4(v)
26889+
26890+#ifdef CONFIG_PAX_REFCOUNT
26891+2:
26892+#endif
26893+
26894+RET_ENDP
26895+BEGIN(add_return_unchecked)
26896+ addl (v), %eax
26897+ adcl 4(v), %edx
26898 movl %eax, (v)
26899 movl %edx, 4(v)
26900 RET_ENDP
26901@@ -86,6 +126,20 @@ RET_ENDP
26902 BEGIN(sub)
26903 subl %eax, (v)
26904 sbbl %edx, 4(v)
26905+
26906+#ifdef CONFIG_PAX_REFCOUNT
26907+ jno 0f
26908+ addl %eax, (v)
26909+ adcl %edx, 4(v)
26910+ int $4
26911+0:
26912+ _ASM_EXTABLE(0b, 0b)
26913+#endif
26914+
26915+RET_ENDP
26916+BEGIN(sub_unchecked)
26917+ subl %eax, (v)
26918+ sbbl %edx, 4(v)
26919 RET_ENDP
26920 #undef v
26921
26922@@ -96,6 +150,27 @@ BEGIN(sub_return)
26923 sbbl $0, %edx
26924 addl (v), %eax
26925 adcl 4(v), %edx
26926+
26927+#ifdef CONFIG_PAX_REFCOUNT
26928+ into
26929+1234:
26930+ _ASM_EXTABLE(1234b, 2f)
26931+#endif
26932+
26933+ movl %eax, (v)
26934+ movl %edx, 4(v)
26935+
26936+#ifdef CONFIG_PAX_REFCOUNT
26937+2:
26938+#endif
26939+
26940+RET_ENDP
26941+BEGIN(sub_return_unchecked)
26942+ negl %edx
26943+ negl %eax
26944+ sbbl $0, %edx
26945+ addl (v), %eax
26946+ adcl 4(v), %edx
26947 movl %eax, (v)
26948 movl %edx, 4(v)
26949 RET_ENDP
26950@@ -105,6 +180,20 @@ RET_ENDP
26951 BEGIN(inc)
26952 addl $1, (v)
26953 adcl $0, 4(v)
26954+
26955+#ifdef CONFIG_PAX_REFCOUNT
26956+ jno 0f
26957+ subl $1, (v)
26958+ sbbl $0, 4(v)
26959+ int $4
26960+0:
26961+ _ASM_EXTABLE(0b, 0b)
26962+#endif
26963+
26964+RET_ENDP
26965+BEGIN(inc_unchecked)
26966+ addl $1, (v)
26967+ adcl $0, 4(v)
26968 RET_ENDP
26969 #undef v
26970
26971@@ -114,6 +203,26 @@ BEGIN(inc_return)
26972 movl 4(v), %edx
26973 addl $1, %eax
26974 adcl $0, %edx
26975+
26976+#ifdef CONFIG_PAX_REFCOUNT
26977+ into
26978+1234:
26979+ _ASM_EXTABLE(1234b, 2f)
26980+#endif
26981+
26982+ movl %eax, (v)
26983+ movl %edx, 4(v)
26984+
26985+#ifdef CONFIG_PAX_REFCOUNT
26986+2:
26987+#endif
26988+
26989+RET_ENDP
26990+BEGIN(inc_return_unchecked)
26991+ movl (v), %eax
26992+ movl 4(v), %edx
26993+ addl $1, %eax
26994+ adcl $0, %edx
26995 movl %eax, (v)
26996 movl %edx, 4(v)
26997 RET_ENDP
26998@@ -123,6 +232,20 @@ RET_ENDP
26999 BEGIN(dec)
27000 subl $1, (v)
27001 sbbl $0, 4(v)
27002+
27003+#ifdef CONFIG_PAX_REFCOUNT
27004+ jno 0f
27005+ addl $1, (v)
27006+ adcl $0, 4(v)
27007+ int $4
27008+0:
27009+ _ASM_EXTABLE(0b, 0b)
27010+#endif
27011+
27012+RET_ENDP
27013+BEGIN(dec_unchecked)
27014+ subl $1, (v)
27015+ sbbl $0, 4(v)
27016 RET_ENDP
27017 #undef v
27018
27019@@ -132,6 +255,26 @@ BEGIN(dec_return)
27020 movl 4(v), %edx
27021 subl $1, %eax
27022 sbbl $0, %edx
27023+
27024+#ifdef CONFIG_PAX_REFCOUNT
27025+ into
27026+1234:
27027+ _ASM_EXTABLE(1234b, 2f)
27028+#endif
27029+
27030+ movl %eax, (v)
27031+ movl %edx, 4(v)
27032+
27033+#ifdef CONFIG_PAX_REFCOUNT
27034+2:
27035+#endif
27036+
27037+RET_ENDP
27038+BEGIN(dec_return_unchecked)
27039+ movl (v), %eax
27040+ movl 4(v), %edx
27041+ subl $1, %eax
27042+ sbbl $0, %edx
27043 movl %eax, (v)
27044 movl %edx, 4(v)
27045 RET_ENDP
27046@@ -143,6 +286,13 @@ BEGIN(add_unless)
27047 adcl %edx, %edi
27048 addl (v), %eax
27049 adcl 4(v), %edx
27050+
27051+#ifdef CONFIG_PAX_REFCOUNT
27052+ into
27053+1234:
27054+ _ASM_EXTABLE(1234b, 2f)
27055+#endif
27056+
27057 cmpl %eax, %ecx
27058 je 3f
27059 1:
27060@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27061 1:
27062 addl $1, %eax
27063 adcl $0, %edx
27064+
27065+#ifdef CONFIG_PAX_REFCOUNT
27066+ into
27067+1234:
27068+ _ASM_EXTABLE(1234b, 2f)
27069+#endif
27070+
27071 movl %eax, (v)
27072 movl %edx, 4(v)
27073 movl $1, %eax
27074@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27075 movl 4(v), %edx
27076 subl $1, %eax
27077 sbbl $0, %edx
27078+
27079+#ifdef CONFIG_PAX_REFCOUNT
27080+ into
27081+1234:
27082+ _ASM_EXTABLE(1234b, 1f)
27083+#endif
27084+
27085 js 1f
27086 movl %eax, (v)
27087 movl %edx, 4(v)
27088diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27089index f5cc9eb..51fa319 100644
27090--- a/arch/x86/lib/atomic64_cx8_32.S
27091+++ b/arch/x86/lib/atomic64_cx8_32.S
27092@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27093 CFI_STARTPROC
27094
27095 read64 %ecx
27096+ pax_force_retaddr
27097 ret
27098 CFI_ENDPROC
27099 ENDPROC(atomic64_read_cx8)
27100
27101+ENTRY(atomic64_read_unchecked_cx8)
27102+ CFI_STARTPROC
27103+
27104+ read64 %ecx
27105+ pax_force_retaddr
27106+ ret
27107+ CFI_ENDPROC
27108+ENDPROC(atomic64_read_unchecked_cx8)
27109+
27110 ENTRY(atomic64_set_cx8)
27111 CFI_STARTPROC
27112
27113@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27114 cmpxchg8b (%esi)
27115 jne 1b
27116
27117+ pax_force_retaddr
27118 ret
27119 CFI_ENDPROC
27120 ENDPROC(atomic64_set_cx8)
27121
27122+ENTRY(atomic64_set_unchecked_cx8)
27123+ CFI_STARTPROC
27124+
27125+1:
27126+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27127+ * are atomic on 586 and newer */
27128+ cmpxchg8b (%esi)
27129+ jne 1b
27130+
27131+ pax_force_retaddr
27132+ ret
27133+ CFI_ENDPROC
27134+ENDPROC(atomic64_set_unchecked_cx8)
27135+
27136 ENTRY(atomic64_xchg_cx8)
27137 CFI_STARTPROC
27138
27139@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27140 cmpxchg8b (%esi)
27141 jne 1b
27142
27143+ pax_force_retaddr
27144 ret
27145 CFI_ENDPROC
27146 ENDPROC(atomic64_xchg_cx8)
27147
27148-.macro addsub_return func ins insc
27149-ENTRY(atomic64_\func\()_return_cx8)
27150+.macro addsub_return func ins insc unchecked=""
27151+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27152 CFI_STARTPROC
27153 SAVE ebp
27154 SAVE ebx
27155@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27156 movl %edx, %ecx
27157 \ins\()l %esi, %ebx
27158 \insc\()l %edi, %ecx
27159+
27160+.ifb \unchecked
27161+#ifdef CONFIG_PAX_REFCOUNT
27162+ into
27163+2:
27164+ _ASM_EXTABLE(2b, 3f)
27165+#endif
27166+.endif
27167+
27168 LOCK_PREFIX
27169 cmpxchg8b (%ebp)
27170 jne 1b
27171-
27172-10:
27173 movl %ebx, %eax
27174 movl %ecx, %edx
27175+
27176+.ifb \unchecked
27177+#ifdef CONFIG_PAX_REFCOUNT
27178+3:
27179+#endif
27180+.endif
27181+
27182 RESTORE edi
27183 RESTORE esi
27184 RESTORE ebx
27185 RESTORE ebp
27186+ pax_force_retaddr
27187 ret
27188 CFI_ENDPROC
27189-ENDPROC(atomic64_\func\()_return_cx8)
27190+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27191 .endm
27192
27193 addsub_return add add adc
27194 addsub_return sub sub sbb
27195+addsub_return add add adc _unchecked
27196+addsub_return sub sub sbb _unchecked
27197
27198-.macro incdec_return func ins insc
27199-ENTRY(atomic64_\func\()_return_cx8)
27200+.macro incdec_return func ins insc unchecked=""
27201+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27202 CFI_STARTPROC
27203 SAVE ebx
27204
27205@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27206 movl %edx, %ecx
27207 \ins\()l $1, %ebx
27208 \insc\()l $0, %ecx
27209+
27210+.ifb \unchecked
27211+#ifdef CONFIG_PAX_REFCOUNT
27212+ into
27213+2:
27214+ _ASM_EXTABLE(2b, 3f)
27215+#endif
27216+.endif
27217+
27218 LOCK_PREFIX
27219 cmpxchg8b (%esi)
27220 jne 1b
27221
27222-10:
27223 movl %ebx, %eax
27224 movl %ecx, %edx
27225+
27226+.ifb \unchecked
27227+#ifdef CONFIG_PAX_REFCOUNT
27228+3:
27229+#endif
27230+.endif
27231+
27232 RESTORE ebx
27233+ pax_force_retaddr
27234 ret
27235 CFI_ENDPROC
27236-ENDPROC(atomic64_\func\()_return_cx8)
27237+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27238 .endm
27239
27240 incdec_return inc add adc
27241 incdec_return dec sub sbb
27242+incdec_return inc add adc _unchecked
27243+incdec_return dec sub sbb _unchecked
27244
27245 ENTRY(atomic64_dec_if_positive_cx8)
27246 CFI_STARTPROC
27247@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27248 movl %edx, %ecx
27249 subl $1, %ebx
27250 sbb $0, %ecx
27251+
27252+#ifdef CONFIG_PAX_REFCOUNT
27253+ into
27254+1234:
27255+ _ASM_EXTABLE(1234b, 2f)
27256+#endif
27257+
27258 js 2f
27259 LOCK_PREFIX
27260 cmpxchg8b (%esi)
27261@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27262 movl %ebx, %eax
27263 movl %ecx, %edx
27264 RESTORE ebx
27265+ pax_force_retaddr
27266 ret
27267 CFI_ENDPROC
27268 ENDPROC(atomic64_dec_if_positive_cx8)
27269@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27270 movl %edx, %ecx
27271 addl %ebp, %ebx
27272 adcl %edi, %ecx
27273+
27274+#ifdef CONFIG_PAX_REFCOUNT
27275+ into
27276+1234:
27277+ _ASM_EXTABLE(1234b, 3f)
27278+#endif
27279+
27280 LOCK_PREFIX
27281 cmpxchg8b (%esi)
27282 jne 1b
27283@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27284 CFI_ADJUST_CFA_OFFSET -8
27285 RESTORE ebx
27286 RESTORE ebp
27287+ pax_force_retaddr
27288 ret
27289 4:
27290 cmpl %edx, 4(%esp)
27291@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27292 xorl %ecx, %ecx
27293 addl $1, %ebx
27294 adcl %edx, %ecx
27295+
27296+#ifdef CONFIG_PAX_REFCOUNT
27297+ into
27298+1234:
27299+ _ASM_EXTABLE(1234b, 3f)
27300+#endif
27301+
27302 LOCK_PREFIX
27303 cmpxchg8b (%esi)
27304 jne 1b
27305@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27306 movl $1, %eax
27307 3:
27308 RESTORE ebx
27309+ pax_force_retaddr
27310 ret
27311 CFI_ENDPROC
27312 ENDPROC(atomic64_inc_not_zero_cx8)
27313diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27314index e78b8ee..7e173a8 100644
27315--- a/arch/x86/lib/checksum_32.S
27316+++ b/arch/x86/lib/checksum_32.S
27317@@ -29,7 +29,8 @@
27318 #include <asm/dwarf2.h>
27319 #include <asm/errno.h>
27320 #include <asm/asm.h>
27321-
27322+#include <asm/segment.h>
27323+
27324 /*
27325 * computes a partial checksum, e.g. for TCP/UDP fragments
27326 */
27327@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27328
27329 #define ARGBASE 16
27330 #define FP 12
27331-
27332-ENTRY(csum_partial_copy_generic)
27333+
27334+ENTRY(csum_partial_copy_generic_to_user)
27335 CFI_STARTPROC
27336+
27337+#ifdef CONFIG_PAX_MEMORY_UDEREF
27338+ pushl_cfi %gs
27339+ popl_cfi %es
27340+ jmp csum_partial_copy_generic
27341+#endif
27342+
27343+ENTRY(csum_partial_copy_generic_from_user)
27344+
27345+#ifdef CONFIG_PAX_MEMORY_UDEREF
27346+ pushl_cfi %gs
27347+ popl_cfi %ds
27348+#endif
27349+
27350+ENTRY(csum_partial_copy_generic)
27351 subl $4,%esp
27352 CFI_ADJUST_CFA_OFFSET 4
27353 pushl_cfi %edi
27354@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27355 jmp 4f
27356 SRC(1: movw (%esi), %bx )
27357 addl $2, %esi
27358-DST( movw %bx, (%edi) )
27359+DST( movw %bx, %es:(%edi) )
27360 addl $2, %edi
27361 addw %bx, %ax
27362 adcl $0, %eax
27363@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27364 SRC(1: movl (%esi), %ebx )
27365 SRC( movl 4(%esi), %edx )
27366 adcl %ebx, %eax
27367-DST( movl %ebx, (%edi) )
27368+DST( movl %ebx, %es:(%edi) )
27369 adcl %edx, %eax
27370-DST( movl %edx, 4(%edi) )
27371+DST( movl %edx, %es:4(%edi) )
27372
27373 SRC( movl 8(%esi), %ebx )
27374 SRC( movl 12(%esi), %edx )
27375 adcl %ebx, %eax
27376-DST( movl %ebx, 8(%edi) )
27377+DST( movl %ebx, %es:8(%edi) )
27378 adcl %edx, %eax
27379-DST( movl %edx, 12(%edi) )
27380+DST( movl %edx, %es:12(%edi) )
27381
27382 SRC( movl 16(%esi), %ebx )
27383 SRC( movl 20(%esi), %edx )
27384 adcl %ebx, %eax
27385-DST( movl %ebx, 16(%edi) )
27386+DST( movl %ebx, %es:16(%edi) )
27387 adcl %edx, %eax
27388-DST( movl %edx, 20(%edi) )
27389+DST( movl %edx, %es:20(%edi) )
27390
27391 SRC( movl 24(%esi), %ebx )
27392 SRC( movl 28(%esi), %edx )
27393 adcl %ebx, %eax
27394-DST( movl %ebx, 24(%edi) )
27395+DST( movl %ebx, %es:24(%edi) )
27396 adcl %edx, %eax
27397-DST( movl %edx, 28(%edi) )
27398+DST( movl %edx, %es:28(%edi) )
27399
27400 lea 32(%esi), %esi
27401 lea 32(%edi), %edi
27402@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27403 shrl $2, %edx # This clears CF
27404 SRC(3: movl (%esi), %ebx )
27405 adcl %ebx, %eax
27406-DST( movl %ebx, (%edi) )
27407+DST( movl %ebx, %es:(%edi) )
27408 lea 4(%esi), %esi
27409 lea 4(%edi), %edi
27410 dec %edx
27411@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27412 jb 5f
27413 SRC( movw (%esi), %cx )
27414 leal 2(%esi), %esi
27415-DST( movw %cx, (%edi) )
27416+DST( movw %cx, %es:(%edi) )
27417 leal 2(%edi), %edi
27418 je 6f
27419 shll $16,%ecx
27420 SRC(5: movb (%esi), %cl )
27421-DST( movb %cl, (%edi) )
27422+DST( movb %cl, %es:(%edi) )
27423 6: addl %ecx, %eax
27424 adcl $0, %eax
27425 7:
27426@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27427
27428 6001:
27429 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27430- movl $-EFAULT, (%ebx)
27431+ movl $-EFAULT, %ss:(%ebx)
27432
27433 # zero the complete destination - computing the rest
27434 # is too much work
27435@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27436
27437 6002:
27438 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27439- movl $-EFAULT,(%ebx)
27440+ movl $-EFAULT,%ss:(%ebx)
27441 jmp 5000b
27442
27443 .previous
27444
27445+ pushl_cfi %ss
27446+ popl_cfi %ds
27447+ pushl_cfi %ss
27448+ popl_cfi %es
27449 popl_cfi %ebx
27450 CFI_RESTORE ebx
27451 popl_cfi %esi
27452@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27453 popl_cfi %ecx # equivalent to addl $4,%esp
27454 ret
27455 CFI_ENDPROC
27456-ENDPROC(csum_partial_copy_generic)
27457+ENDPROC(csum_partial_copy_generic_to_user)
27458
27459 #else
27460
27461 /* Version for PentiumII/PPro */
27462
27463 #define ROUND1(x) \
27464+ nop; nop; nop; \
27465 SRC(movl x(%esi), %ebx ) ; \
27466 addl %ebx, %eax ; \
27467- DST(movl %ebx, x(%edi) ) ;
27468+ DST(movl %ebx, %es:x(%edi)) ;
27469
27470 #define ROUND(x) \
27471+ nop; nop; nop; \
27472 SRC(movl x(%esi), %ebx ) ; \
27473 adcl %ebx, %eax ; \
27474- DST(movl %ebx, x(%edi) ) ;
27475+ DST(movl %ebx, %es:x(%edi)) ;
27476
27477 #define ARGBASE 12
27478-
27479-ENTRY(csum_partial_copy_generic)
27480+
27481+ENTRY(csum_partial_copy_generic_to_user)
27482 CFI_STARTPROC
27483+
27484+#ifdef CONFIG_PAX_MEMORY_UDEREF
27485+ pushl_cfi %gs
27486+ popl_cfi %es
27487+ jmp csum_partial_copy_generic
27488+#endif
27489+
27490+ENTRY(csum_partial_copy_generic_from_user)
27491+
27492+#ifdef CONFIG_PAX_MEMORY_UDEREF
27493+ pushl_cfi %gs
27494+ popl_cfi %ds
27495+#endif
27496+
27497+ENTRY(csum_partial_copy_generic)
27498 pushl_cfi %ebx
27499 CFI_REL_OFFSET ebx, 0
27500 pushl_cfi %edi
27501@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27502 subl %ebx, %edi
27503 lea -1(%esi),%edx
27504 andl $-32,%edx
27505- lea 3f(%ebx,%ebx), %ebx
27506+ lea 3f(%ebx,%ebx,2), %ebx
27507 testl %esi, %esi
27508 jmp *%ebx
27509 1: addl $64,%esi
27510@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27511 jb 5f
27512 SRC( movw (%esi), %dx )
27513 leal 2(%esi), %esi
27514-DST( movw %dx, (%edi) )
27515+DST( movw %dx, %es:(%edi) )
27516 leal 2(%edi), %edi
27517 je 6f
27518 shll $16,%edx
27519 5:
27520 SRC( movb (%esi), %dl )
27521-DST( movb %dl, (%edi) )
27522+DST( movb %dl, %es:(%edi) )
27523 6: addl %edx, %eax
27524 adcl $0, %eax
27525 7:
27526 .section .fixup, "ax"
27527 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27528- movl $-EFAULT, (%ebx)
27529+ movl $-EFAULT, %ss:(%ebx)
27530 # zero the complete destination (computing the rest is too much work)
27531 movl ARGBASE+8(%esp),%edi # dst
27532 movl ARGBASE+12(%esp),%ecx # len
27533@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27534 rep; stosb
27535 jmp 7b
27536 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27537- movl $-EFAULT, (%ebx)
27538+ movl $-EFAULT, %ss:(%ebx)
27539 jmp 7b
27540 .previous
27541
27542+#ifdef CONFIG_PAX_MEMORY_UDEREF
27543+ pushl_cfi %ss
27544+ popl_cfi %ds
27545+ pushl_cfi %ss
27546+ popl_cfi %es
27547+#endif
27548+
27549 popl_cfi %esi
27550 CFI_RESTORE esi
27551 popl_cfi %edi
27552@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27553 CFI_RESTORE ebx
27554 ret
27555 CFI_ENDPROC
27556-ENDPROC(csum_partial_copy_generic)
27557+ENDPROC(csum_partial_copy_generic_to_user)
27558
27559 #undef ROUND
27560 #undef ROUND1
27561diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27562index f2145cf..cea889d 100644
27563--- a/arch/x86/lib/clear_page_64.S
27564+++ b/arch/x86/lib/clear_page_64.S
27565@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27566 movl $4096/8,%ecx
27567 xorl %eax,%eax
27568 rep stosq
27569+ pax_force_retaddr
27570 ret
27571 CFI_ENDPROC
27572 ENDPROC(clear_page_c)
27573@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27574 movl $4096,%ecx
27575 xorl %eax,%eax
27576 rep stosb
27577+ pax_force_retaddr
27578 ret
27579 CFI_ENDPROC
27580 ENDPROC(clear_page_c_e)
27581@@ -43,6 +45,7 @@ ENTRY(clear_page)
27582 leaq 64(%rdi),%rdi
27583 jnz .Lloop
27584 nop
27585+ pax_force_retaddr
27586 ret
27587 CFI_ENDPROC
27588 .Lclear_page_end:
27589@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27590
27591 #include <asm/cpufeature.h>
27592
27593- .section .altinstr_replacement,"ax"
27594+ .section .altinstr_replacement,"a"
27595 1: .byte 0xeb /* jmp <disp8> */
27596 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27597 2: .byte 0xeb /* jmp <disp8> */
27598diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27599index 1e572c5..2a162cd 100644
27600--- a/arch/x86/lib/cmpxchg16b_emu.S
27601+++ b/arch/x86/lib/cmpxchg16b_emu.S
27602@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27603
27604 popf
27605 mov $1, %al
27606+ pax_force_retaddr
27607 ret
27608
27609 not_same:
27610 popf
27611 xor %al,%al
27612+ pax_force_retaddr
27613 ret
27614
27615 CFI_ENDPROC
27616diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27617index 176cca6..1166c50 100644
27618--- a/arch/x86/lib/copy_page_64.S
27619+++ b/arch/x86/lib/copy_page_64.S
27620@@ -9,6 +9,7 @@ copy_page_rep:
27621 CFI_STARTPROC
27622 movl $4096/8, %ecx
27623 rep movsq
27624+ pax_force_retaddr
27625 ret
27626 CFI_ENDPROC
27627 ENDPROC(copy_page_rep)
27628@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27629
27630 ENTRY(copy_page)
27631 CFI_STARTPROC
27632- subq $2*8, %rsp
27633- CFI_ADJUST_CFA_OFFSET 2*8
27634+ subq $3*8, %rsp
27635+ CFI_ADJUST_CFA_OFFSET 3*8
27636 movq %rbx, (%rsp)
27637 CFI_REL_OFFSET rbx, 0
27638 movq %r12, 1*8(%rsp)
27639 CFI_REL_OFFSET r12, 1*8
27640+ movq %r13, 2*8(%rsp)
27641+ CFI_REL_OFFSET r13, 2*8
27642
27643 movl $(4096/64)-5, %ecx
27644 .p2align 4
27645@@ -36,7 +39,7 @@ ENTRY(copy_page)
27646 movq 0x8*2(%rsi), %rdx
27647 movq 0x8*3(%rsi), %r8
27648 movq 0x8*4(%rsi), %r9
27649- movq 0x8*5(%rsi), %r10
27650+ movq 0x8*5(%rsi), %r13
27651 movq 0x8*6(%rsi), %r11
27652 movq 0x8*7(%rsi), %r12
27653
27654@@ -47,7 +50,7 @@ ENTRY(copy_page)
27655 movq %rdx, 0x8*2(%rdi)
27656 movq %r8, 0x8*3(%rdi)
27657 movq %r9, 0x8*4(%rdi)
27658- movq %r10, 0x8*5(%rdi)
27659+ movq %r13, 0x8*5(%rdi)
27660 movq %r11, 0x8*6(%rdi)
27661 movq %r12, 0x8*7(%rdi)
27662
27663@@ -66,7 +69,7 @@ ENTRY(copy_page)
27664 movq 0x8*2(%rsi), %rdx
27665 movq 0x8*3(%rsi), %r8
27666 movq 0x8*4(%rsi), %r9
27667- movq 0x8*5(%rsi), %r10
27668+ movq 0x8*5(%rsi), %r13
27669 movq 0x8*6(%rsi), %r11
27670 movq 0x8*7(%rsi), %r12
27671
27672@@ -75,7 +78,7 @@ ENTRY(copy_page)
27673 movq %rdx, 0x8*2(%rdi)
27674 movq %r8, 0x8*3(%rdi)
27675 movq %r9, 0x8*4(%rdi)
27676- movq %r10, 0x8*5(%rdi)
27677+ movq %r13, 0x8*5(%rdi)
27678 movq %r11, 0x8*6(%rdi)
27679 movq %r12, 0x8*7(%rdi)
27680
27681@@ -87,8 +90,11 @@ ENTRY(copy_page)
27682 CFI_RESTORE rbx
27683 movq 1*8(%rsp), %r12
27684 CFI_RESTORE r12
27685- addq $2*8, %rsp
27686- CFI_ADJUST_CFA_OFFSET -2*8
27687+ movq 2*8(%rsp), %r13
27688+ CFI_RESTORE r13
27689+ addq $3*8, %rsp
27690+ CFI_ADJUST_CFA_OFFSET -3*8
27691+ pax_force_retaddr
27692 ret
27693 .Lcopy_page_end:
27694 CFI_ENDPROC
27695@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27696
27697 #include <asm/cpufeature.h>
27698
27699- .section .altinstr_replacement,"ax"
27700+ .section .altinstr_replacement,"a"
27701 1: .byte 0xeb /* jmp <disp8> */
27702 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27703 2:
27704diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27705index a30ca15..6b3f4e1 100644
27706--- a/arch/x86/lib/copy_user_64.S
27707+++ b/arch/x86/lib/copy_user_64.S
27708@@ -18,31 +18,7 @@
27709 #include <asm/alternative-asm.h>
27710 #include <asm/asm.h>
27711 #include <asm/smap.h>
27712-
27713-/*
27714- * By placing feature2 after feature1 in altinstructions section, we logically
27715- * implement:
27716- * If CPU has feature2, jmp to alt2 is used
27717- * else if CPU has feature1, jmp to alt1 is used
27718- * else jmp to orig is used.
27719- */
27720- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27721-0:
27722- .byte 0xe9 /* 32bit jump */
27723- .long \orig-1f /* by default jump to orig */
27724-1:
27725- .section .altinstr_replacement,"ax"
27726-2: .byte 0xe9 /* near jump with 32bit immediate */
27727- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27728-3: .byte 0xe9 /* near jump with 32bit immediate */
27729- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27730- .previous
27731-
27732- .section .altinstructions,"a"
27733- altinstruction_entry 0b,2b,\feature1,5,5
27734- altinstruction_entry 0b,3b,\feature2,5,5
27735- .previous
27736- .endm
27737+#include <asm/pgtable.h>
27738
27739 .macro ALIGN_DESTINATION
27740 #ifdef FIX_ALIGNMENT
27741@@ -70,52 +46,6 @@
27742 #endif
27743 .endm
27744
27745-/* Standard copy_to_user with segment limit checking */
27746-ENTRY(_copy_to_user)
27747- CFI_STARTPROC
27748- GET_THREAD_INFO(%rax)
27749- movq %rdi,%rcx
27750- addq %rdx,%rcx
27751- jc bad_to_user
27752- cmpq TI_addr_limit(%rax),%rcx
27753- ja bad_to_user
27754- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27755- copy_user_generic_unrolled,copy_user_generic_string, \
27756- copy_user_enhanced_fast_string
27757- CFI_ENDPROC
27758-ENDPROC(_copy_to_user)
27759-
27760-/* Standard copy_from_user with segment limit checking */
27761-ENTRY(_copy_from_user)
27762- CFI_STARTPROC
27763- GET_THREAD_INFO(%rax)
27764- movq %rsi,%rcx
27765- addq %rdx,%rcx
27766- jc bad_from_user
27767- cmpq TI_addr_limit(%rax),%rcx
27768- ja bad_from_user
27769- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27770- copy_user_generic_unrolled,copy_user_generic_string, \
27771- copy_user_enhanced_fast_string
27772- CFI_ENDPROC
27773-ENDPROC(_copy_from_user)
27774-
27775- .section .fixup,"ax"
27776- /* must zero dest */
27777-ENTRY(bad_from_user)
27778-bad_from_user:
27779- CFI_STARTPROC
27780- movl %edx,%ecx
27781- xorl %eax,%eax
27782- rep
27783- stosb
27784-bad_to_user:
27785- movl %edx,%eax
27786- ret
27787- CFI_ENDPROC
27788-ENDPROC(bad_from_user)
27789- .previous
27790-
27791 /*
27792 * copy_user_generic_unrolled - memory copy with exception handling.
27793 * This version is for CPUs like P4 that don't have efficient micro
27794@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27795 */
27796 ENTRY(copy_user_generic_unrolled)
27797 CFI_STARTPROC
27798+ ASM_PAX_OPEN_USERLAND
27799 ASM_STAC
27800 cmpl $8,%edx
27801 jb 20f /* less then 8 bytes, go to byte copy loop */
27802@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27803 jz 17f
27804 1: movq (%rsi),%r8
27805 2: movq 1*8(%rsi),%r9
27806-3: movq 2*8(%rsi),%r10
27807+3: movq 2*8(%rsi),%rax
27808 4: movq 3*8(%rsi),%r11
27809 5: movq %r8,(%rdi)
27810 6: movq %r9,1*8(%rdi)
27811-7: movq %r10,2*8(%rdi)
27812+7: movq %rax,2*8(%rdi)
27813 8: movq %r11,3*8(%rdi)
27814 9: movq 4*8(%rsi),%r8
27815 10: movq 5*8(%rsi),%r9
27816-11: movq 6*8(%rsi),%r10
27817+11: movq 6*8(%rsi),%rax
27818 12: movq 7*8(%rsi),%r11
27819 13: movq %r8,4*8(%rdi)
27820 14: movq %r9,5*8(%rdi)
27821-15: movq %r10,6*8(%rdi)
27822+15: movq %rax,6*8(%rdi)
27823 16: movq %r11,7*8(%rdi)
27824 leaq 64(%rsi),%rsi
27825 leaq 64(%rdi),%rdi
27826@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27827 jnz 21b
27828 23: xor %eax,%eax
27829 ASM_CLAC
27830+ ASM_PAX_CLOSE_USERLAND
27831+ pax_force_retaddr
27832 ret
27833
27834 .section .fixup,"ax"
27835@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27836 */
27837 ENTRY(copy_user_generic_string)
27838 CFI_STARTPROC
27839+ ASM_PAX_OPEN_USERLAND
27840 ASM_STAC
27841 andl %edx,%edx
27842 jz 4f
27843@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27844 movsb
27845 4: xorl %eax,%eax
27846 ASM_CLAC
27847+ ASM_PAX_CLOSE_USERLAND
27848+ pax_force_retaddr
27849 ret
27850
27851 .section .fixup,"ax"
27852@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27853 */
27854 ENTRY(copy_user_enhanced_fast_string)
27855 CFI_STARTPROC
27856+ ASM_PAX_OPEN_USERLAND
27857 ASM_STAC
27858 andl %edx,%edx
27859 jz 2f
27860@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27861 movsb
27862 2: xorl %eax,%eax
27863 ASM_CLAC
27864+ ASM_PAX_CLOSE_USERLAND
27865+ pax_force_retaddr
27866 ret
27867
27868 .section .fixup,"ax"
27869diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27870index 6a4f43c..55d26f2 100644
27871--- a/arch/x86/lib/copy_user_nocache_64.S
27872+++ b/arch/x86/lib/copy_user_nocache_64.S
27873@@ -8,6 +8,7 @@
27874
27875 #include <linux/linkage.h>
27876 #include <asm/dwarf2.h>
27877+#include <asm/alternative-asm.h>
27878
27879 #define FIX_ALIGNMENT 1
27880
27881@@ -16,6 +17,7 @@
27882 #include <asm/thread_info.h>
27883 #include <asm/asm.h>
27884 #include <asm/smap.h>
27885+#include <asm/pgtable.h>
27886
27887 .macro ALIGN_DESTINATION
27888 #ifdef FIX_ALIGNMENT
27889@@ -49,6 +51,16 @@
27890 */
27891 ENTRY(__copy_user_nocache)
27892 CFI_STARTPROC
27893+
27894+#ifdef CONFIG_PAX_MEMORY_UDEREF
27895+ mov pax_user_shadow_base,%rcx
27896+ cmp %rcx,%rsi
27897+ jae 1f
27898+ add %rcx,%rsi
27899+1:
27900+#endif
27901+
27902+ ASM_PAX_OPEN_USERLAND
27903 ASM_STAC
27904 cmpl $8,%edx
27905 jb 20f /* less then 8 bytes, go to byte copy loop */
27906@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27907 jz 17f
27908 1: movq (%rsi),%r8
27909 2: movq 1*8(%rsi),%r9
27910-3: movq 2*8(%rsi),%r10
27911+3: movq 2*8(%rsi),%rax
27912 4: movq 3*8(%rsi),%r11
27913 5: movnti %r8,(%rdi)
27914 6: movnti %r9,1*8(%rdi)
27915-7: movnti %r10,2*8(%rdi)
27916+7: movnti %rax,2*8(%rdi)
27917 8: movnti %r11,3*8(%rdi)
27918 9: movq 4*8(%rsi),%r8
27919 10: movq 5*8(%rsi),%r9
27920-11: movq 6*8(%rsi),%r10
27921+11: movq 6*8(%rsi),%rax
27922 12: movq 7*8(%rsi),%r11
27923 13: movnti %r8,4*8(%rdi)
27924 14: movnti %r9,5*8(%rdi)
27925-15: movnti %r10,6*8(%rdi)
27926+15: movnti %rax,6*8(%rdi)
27927 16: movnti %r11,7*8(%rdi)
27928 leaq 64(%rsi),%rsi
27929 leaq 64(%rdi),%rdi
27930@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27931 jnz 21b
27932 23: xorl %eax,%eax
27933 ASM_CLAC
27934+ ASM_PAX_CLOSE_USERLAND
27935 sfence
27936+ pax_force_retaddr
27937 ret
27938
27939 .section .fixup,"ax"
27940diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27941index 2419d5f..953ee51 100644
27942--- a/arch/x86/lib/csum-copy_64.S
27943+++ b/arch/x86/lib/csum-copy_64.S
27944@@ -9,6 +9,7 @@
27945 #include <asm/dwarf2.h>
27946 #include <asm/errno.h>
27947 #include <asm/asm.h>
27948+#include <asm/alternative-asm.h>
27949
27950 /*
27951 * Checksum copy with exception handling.
27952@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27953 CFI_RESTORE rbp
27954 addq $7*8, %rsp
27955 CFI_ADJUST_CFA_OFFSET -7*8
27956+ pax_force_retaddr 0, 1
27957 ret
27958 CFI_RESTORE_STATE
27959
27960diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27961index 7609e0e..b449b98 100644
27962--- a/arch/x86/lib/csum-wrappers_64.c
27963+++ b/arch/x86/lib/csum-wrappers_64.c
27964@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27965 len -= 2;
27966 }
27967 }
27968+ pax_open_userland();
27969 stac();
27970- isum = csum_partial_copy_generic((__force const void *)src,
27971+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27972 dst, len, isum, errp, NULL);
27973 clac();
27974+ pax_close_userland();
27975 if (unlikely(*errp))
27976 goto out_err;
27977
27978@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27979 }
27980
27981 *errp = 0;
27982+ pax_open_userland();
27983 stac();
27984- ret = csum_partial_copy_generic(src, (void __force *)dst,
27985+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27986 len, isum, NULL, errp);
27987 clac();
27988+ pax_close_userland();
27989 return ret;
27990 }
27991 EXPORT_SYMBOL(csum_partial_copy_to_user);
27992diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27993index a451235..1daa956 100644
27994--- a/arch/x86/lib/getuser.S
27995+++ b/arch/x86/lib/getuser.S
27996@@ -33,17 +33,40 @@
27997 #include <asm/thread_info.h>
27998 #include <asm/asm.h>
27999 #include <asm/smap.h>
28000+#include <asm/segment.h>
28001+#include <asm/pgtable.h>
28002+#include <asm/alternative-asm.h>
28003+
28004+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28005+#define __copyuser_seg gs;
28006+#else
28007+#define __copyuser_seg
28008+#endif
28009
28010 .text
28011 ENTRY(__get_user_1)
28012 CFI_STARTPROC
28013+
28014+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28015 GET_THREAD_INFO(%_ASM_DX)
28016 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28017 jae bad_get_user
28018 ASM_STAC
28019-1: movzbl (%_ASM_AX),%edx
28020+
28021+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28022+ mov pax_user_shadow_base,%_ASM_DX
28023+ cmp %_ASM_DX,%_ASM_AX
28024+ jae 1234f
28025+ add %_ASM_DX,%_ASM_AX
28026+1234:
28027+#endif
28028+
28029+#endif
28030+
28031+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28032 xor %eax,%eax
28033 ASM_CLAC
28034+ pax_force_retaddr
28035 ret
28036 CFI_ENDPROC
28037 ENDPROC(__get_user_1)
28038@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28039 ENTRY(__get_user_2)
28040 CFI_STARTPROC
28041 add $1,%_ASM_AX
28042+
28043+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28044 jc bad_get_user
28045 GET_THREAD_INFO(%_ASM_DX)
28046 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28047 jae bad_get_user
28048 ASM_STAC
28049-2: movzwl -1(%_ASM_AX),%edx
28050+
28051+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28052+ mov pax_user_shadow_base,%_ASM_DX
28053+ cmp %_ASM_DX,%_ASM_AX
28054+ jae 1234f
28055+ add %_ASM_DX,%_ASM_AX
28056+1234:
28057+#endif
28058+
28059+#endif
28060+
28061+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28062 xor %eax,%eax
28063 ASM_CLAC
28064+ pax_force_retaddr
28065 ret
28066 CFI_ENDPROC
28067 ENDPROC(__get_user_2)
28068@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28069 ENTRY(__get_user_4)
28070 CFI_STARTPROC
28071 add $3,%_ASM_AX
28072+
28073+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28074 jc bad_get_user
28075 GET_THREAD_INFO(%_ASM_DX)
28076 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28077 jae bad_get_user
28078 ASM_STAC
28079-3: movl -3(%_ASM_AX),%edx
28080+
28081+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28082+ mov pax_user_shadow_base,%_ASM_DX
28083+ cmp %_ASM_DX,%_ASM_AX
28084+ jae 1234f
28085+ add %_ASM_DX,%_ASM_AX
28086+1234:
28087+#endif
28088+
28089+#endif
28090+
28091+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28092 xor %eax,%eax
28093 ASM_CLAC
28094+ pax_force_retaddr
28095 ret
28096 CFI_ENDPROC
28097 ENDPROC(__get_user_4)
28098@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28099 GET_THREAD_INFO(%_ASM_DX)
28100 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28101 jae bad_get_user
28102+
28103+#ifdef CONFIG_PAX_MEMORY_UDEREF
28104+ mov pax_user_shadow_base,%_ASM_DX
28105+ cmp %_ASM_DX,%_ASM_AX
28106+ jae 1234f
28107+ add %_ASM_DX,%_ASM_AX
28108+1234:
28109+#endif
28110+
28111 ASM_STAC
28112 4: movq -7(%_ASM_AX),%rdx
28113 xor %eax,%eax
28114 ASM_CLAC
28115+ pax_force_retaddr
28116 ret
28117 #else
28118 add $7,%_ASM_AX
28119@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28120 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28121 jae bad_get_user_8
28122 ASM_STAC
28123-4: movl -7(%_ASM_AX),%edx
28124-5: movl -3(%_ASM_AX),%ecx
28125+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28126+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28127 xor %eax,%eax
28128 ASM_CLAC
28129+ pax_force_retaddr
28130 ret
28131 #endif
28132 CFI_ENDPROC
28133@@ -113,6 +175,7 @@ bad_get_user:
28134 xor %edx,%edx
28135 mov $(-EFAULT),%_ASM_AX
28136 ASM_CLAC
28137+ pax_force_retaddr
28138 ret
28139 CFI_ENDPROC
28140 END(bad_get_user)
28141@@ -124,6 +187,7 @@ bad_get_user_8:
28142 xor %ecx,%ecx
28143 mov $(-EFAULT),%_ASM_AX
28144 ASM_CLAC
28145+ pax_force_retaddr
28146 ret
28147 CFI_ENDPROC
28148 END(bad_get_user_8)
28149diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28150index 54fcffe..7be149e 100644
28151--- a/arch/x86/lib/insn.c
28152+++ b/arch/x86/lib/insn.c
28153@@ -20,8 +20,10 @@
28154
28155 #ifdef __KERNEL__
28156 #include <linux/string.h>
28157+#include <asm/pgtable_types.h>
28158 #else
28159 #include <string.h>
28160+#define ktla_ktva(addr) addr
28161 #endif
28162 #include <asm/inat.h>
28163 #include <asm/insn.h>
28164@@ -53,8 +55,8 @@
28165 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28166 {
28167 memset(insn, 0, sizeof(*insn));
28168- insn->kaddr = kaddr;
28169- insn->next_byte = kaddr;
28170+ insn->kaddr = ktla_ktva(kaddr);
28171+ insn->next_byte = ktla_ktva(kaddr);
28172 insn->x86_64 = x86_64 ? 1 : 0;
28173 insn->opnd_bytes = 4;
28174 if (x86_64)
28175diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28176index 05a95e7..326f2fa 100644
28177--- a/arch/x86/lib/iomap_copy_64.S
28178+++ b/arch/x86/lib/iomap_copy_64.S
28179@@ -17,6 +17,7 @@
28180
28181 #include <linux/linkage.h>
28182 #include <asm/dwarf2.h>
28183+#include <asm/alternative-asm.h>
28184
28185 /*
28186 * override generic version in lib/iomap_copy.c
28187@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28188 CFI_STARTPROC
28189 movl %edx,%ecx
28190 rep movsd
28191+ pax_force_retaddr
28192 ret
28193 CFI_ENDPROC
28194 ENDPROC(__iowrite32_copy)
28195diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28196index 56313a3..9b59269 100644
28197--- a/arch/x86/lib/memcpy_64.S
28198+++ b/arch/x86/lib/memcpy_64.S
28199@@ -24,7 +24,7 @@
28200 * This gets patched over the unrolled variant (below) via the
28201 * alternative instructions framework:
28202 */
28203- .section .altinstr_replacement, "ax", @progbits
28204+ .section .altinstr_replacement, "a", @progbits
28205 .Lmemcpy_c:
28206 movq %rdi, %rax
28207 movq %rdx, %rcx
28208@@ -33,6 +33,7 @@
28209 rep movsq
28210 movl %edx, %ecx
28211 rep movsb
28212+ pax_force_retaddr
28213 ret
28214 .Lmemcpy_e:
28215 .previous
28216@@ -44,11 +45,12 @@
28217 * This gets patched over the unrolled variant (below) via the
28218 * alternative instructions framework:
28219 */
28220- .section .altinstr_replacement, "ax", @progbits
28221+ .section .altinstr_replacement, "a", @progbits
28222 .Lmemcpy_c_e:
28223 movq %rdi, %rax
28224 movq %rdx, %rcx
28225 rep movsb
28226+ pax_force_retaddr
28227 ret
28228 .Lmemcpy_e_e:
28229 .previous
28230@@ -76,13 +78,13 @@ ENTRY(memcpy)
28231 */
28232 movq 0*8(%rsi), %r8
28233 movq 1*8(%rsi), %r9
28234- movq 2*8(%rsi), %r10
28235+ movq 2*8(%rsi), %rcx
28236 movq 3*8(%rsi), %r11
28237 leaq 4*8(%rsi), %rsi
28238
28239 movq %r8, 0*8(%rdi)
28240 movq %r9, 1*8(%rdi)
28241- movq %r10, 2*8(%rdi)
28242+ movq %rcx, 2*8(%rdi)
28243 movq %r11, 3*8(%rdi)
28244 leaq 4*8(%rdi), %rdi
28245 jae .Lcopy_forward_loop
28246@@ -105,12 +107,12 @@ ENTRY(memcpy)
28247 subq $0x20, %rdx
28248 movq -1*8(%rsi), %r8
28249 movq -2*8(%rsi), %r9
28250- movq -3*8(%rsi), %r10
28251+ movq -3*8(%rsi), %rcx
28252 movq -4*8(%rsi), %r11
28253 leaq -4*8(%rsi), %rsi
28254 movq %r8, -1*8(%rdi)
28255 movq %r9, -2*8(%rdi)
28256- movq %r10, -3*8(%rdi)
28257+ movq %rcx, -3*8(%rdi)
28258 movq %r11, -4*8(%rdi)
28259 leaq -4*8(%rdi), %rdi
28260 jae .Lcopy_backward_loop
28261@@ -130,12 +132,13 @@ ENTRY(memcpy)
28262 */
28263 movq 0*8(%rsi), %r8
28264 movq 1*8(%rsi), %r9
28265- movq -2*8(%rsi, %rdx), %r10
28266+ movq -2*8(%rsi, %rdx), %rcx
28267 movq -1*8(%rsi, %rdx), %r11
28268 movq %r8, 0*8(%rdi)
28269 movq %r9, 1*8(%rdi)
28270- movq %r10, -2*8(%rdi, %rdx)
28271+ movq %rcx, -2*8(%rdi, %rdx)
28272 movq %r11, -1*8(%rdi, %rdx)
28273+ pax_force_retaddr
28274 retq
28275 .p2align 4
28276 .Lless_16bytes:
28277@@ -148,6 +151,7 @@ ENTRY(memcpy)
28278 movq -1*8(%rsi, %rdx), %r9
28279 movq %r8, 0*8(%rdi)
28280 movq %r9, -1*8(%rdi, %rdx)
28281+ pax_force_retaddr
28282 retq
28283 .p2align 4
28284 .Lless_8bytes:
28285@@ -161,6 +165,7 @@ ENTRY(memcpy)
28286 movl -4(%rsi, %rdx), %r8d
28287 movl %ecx, (%rdi)
28288 movl %r8d, -4(%rdi, %rdx)
28289+ pax_force_retaddr
28290 retq
28291 .p2align 4
28292 .Lless_3bytes:
28293@@ -179,6 +184,7 @@ ENTRY(memcpy)
28294 movb %cl, (%rdi)
28295
28296 .Lend:
28297+ pax_force_retaddr
28298 retq
28299 CFI_ENDPROC
28300 ENDPROC(memcpy)
28301diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28302index 65268a6..5aa7815 100644
28303--- a/arch/x86/lib/memmove_64.S
28304+++ b/arch/x86/lib/memmove_64.S
28305@@ -61,13 +61,13 @@ ENTRY(memmove)
28306 5:
28307 sub $0x20, %rdx
28308 movq 0*8(%rsi), %r11
28309- movq 1*8(%rsi), %r10
28310+ movq 1*8(%rsi), %rcx
28311 movq 2*8(%rsi), %r9
28312 movq 3*8(%rsi), %r8
28313 leaq 4*8(%rsi), %rsi
28314
28315 movq %r11, 0*8(%rdi)
28316- movq %r10, 1*8(%rdi)
28317+ movq %rcx, 1*8(%rdi)
28318 movq %r9, 2*8(%rdi)
28319 movq %r8, 3*8(%rdi)
28320 leaq 4*8(%rdi), %rdi
28321@@ -81,10 +81,10 @@ ENTRY(memmove)
28322 4:
28323 movq %rdx, %rcx
28324 movq -8(%rsi, %rdx), %r11
28325- lea -8(%rdi, %rdx), %r10
28326+ lea -8(%rdi, %rdx), %r9
28327 shrq $3, %rcx
28328 rep movsq
28329- movq %r11, (%r10)
28330+ movq %r11, (%r9)
28331 jmp 13f
28332 .Lmemmove_end_forward:
28333
28334@@ -95,14 +95,14 @@ ENTRY(memmove)
28335 7:
28336 movq %rdx, %rcx
28337 movq (%rsi), %r11
28338- movq %rdi, %r10
28339+ movq %rdi, %r9
28340 leaq -8(%rsi, %rdx), %rsi
28341 leaq -8(%rdi, %rdx), %rdi
28342 shrq $3, %rcx
28343 std
28344 rep movsq
28345 cld
28346- movq %r11, (%r10)
28347+ movq %r11, (%r9)
28348 jmp 13f
28349
28350 /*
28351@@ -127,13 +127,13 @@ ENTRY(memmove)
28352 8:
28353 subq $0x20, %rdx
28354 movq -1*8(%rsi), %r11
28355- movq -2*8(%rsi), %r10
28356+ movq -2*8(%rsi), %rcx
28357 movq -3*8(%rsi), %r9
28358 movq -4*8(%rsi), %r8
28359 leaq -4*8(%rsi), %rsi
28360
28361 movq %r11, -1*8(%rdi)
28362- movq %r10, -2*8(%rdi)
28363+ movq %rcx, -2*8(%rdi)
28364 movq %r9, -3*8(%rdi)
28365 movq %r8, -4*8(%rdi)
28366 leaq -4*8(%rdi), %rdi
28367@@ -151,11 +151,11 @@ ENTRY(memmove)
28368 * Move data from 16 bytes to 31 bytes.
28369 */
28370 movq 0*8(%rsi), %r11
28371- movq 1*8(%rsi), %r10
28372+ movq 1*8(%rsi), %rcx
28373 movq -2*8(%rsi, %rdx), %r9
28374 movq -1*8(%rsi, %rdx), %r8
28375 movq %r11, 0*8(%rdi)
28376- movq %r10, 1*8(%rdi)
28377+ movq %rcx, 1*8(%rdi)
28378 movq %r9, -2*8(%rdi, %rdx)
28379 movq %r8, -1*8(%rdi, %rdx)
28380 jmp 13f
28381@@ -167,9 +167,9 @@ ENTRY(memmove)
28382 * Move data from 8 bytes to 15 bytes.
28383 */
28384 movq 0*8(%rsi), %r11
28385- movq -1*8(%rsi, %rdx), %r10
28386+ movq -1*8(%rsi, %rdx), %r9
28387 movq %r11, 0*8(%rdi)
28388- movq %r10, -1*8(%rdi, %rdx)
28389+ movq %r9, -1*8(%rdi, %rdx)
28390 jmp 13f
28391 10:
28392 cmpq $4, %rdx
28393@@ -178,9 +178,9 @@ ENTRY(memmove)
28394 * Move data from 4 bytes to 7 bytes.
28395 */
28396 movl (%rsi), %r11d
28397- movl -4(%rsi, %rdx), %r10d
28398+ movl -4(%rsi, %rdx), %r9d
28399 movl %r11d, (%rdi)
28400- movl %r10d, -4(%rdi, %rdx)
28401+ movl %r9d, -4(%rdi, %rdx)
28402 jmp 13f
28403 11:
28404 cmp $2, %rdx
28405@@ -189,9 +189,9 @@ ENTRY(memmove)
28406 * Move data from 2 bytes to 3 bytes.
28407 */
28408 movw (%rsi), %r11w
28409- movw -2(%rsi, %rdx), %r10w
28410+ movw -2(%rsi, %rdx), %r9w
28411 movw %r11w, (%rdi)
28412- movw %r10w, -2(%rdi, %rdx)
28413+ movw %r9w, -2(%rdi, %rdx)
28414 jmp 13f
28415 12:
28416 cmp $1, %rdx
28417@@ -202,14 +202,16 @@ ENTRY(memmove)
28418 movb (%rsi), %r11b
28419 movb %r11b, (%rdi)
28420 13:
28421+ pax_force_retaddr
28422 retq
28423 CFI_ENDPROC
28424
28425- .section .altinstr_replacement,"ax"
28426+ .section .altinstr_replacement,"a"
28427 .Lmemmove_begin_forward_efs:
28428 /* Forward moving data. */
28429 movq %rdx, %rcx
28430 rep movsb
28431+ pax_force_retaddr
28432 retq
28433 .Lmemmove_end_forward_efs:
28434 .previous
28435diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28436index 2dcb380..50a78bc 100644
28437--- a/arch/x86/lib/memset_64.S
28438+++ b/arch/x86/lib/memset_64.S
28439@@ -16,7 +16,7 @@
28440 *
28441 * rax original destination
28442 */
28443- .section .altinstr_replacement, "ax", @progbits
28444+ .section .altinstr_replacement, "a", @progbits
28445 .Lmemset_c:
28446 movq %rdi,%r9
28447 movq %rdx,%rcx
28448@@ -30,6 +30,7 @@
28449 movl %edx,%ecx
28450 rep stosb
28451 movq %r9,%rax
28452+ pax_force_retaddr
28453 ret
28454 .Lmemset_e:
28455 .previous
28456@@ -45,13 +46,14 @@
28457 *
28458 * rax original destination
28459 */
28460- .section .altinstr_replacement, "ax", @progbits
28461+ .section .altinstr_replacement, "a", @progbits
28462 .Lmemset_c_e:
28463 movq %rdi,%r9
28464 movb %sil,%al
28465 movq %rdx,%rcx
28466 rep stosb
28467 movq %r9,%rax
28468+ pax_force_retaddr
28469 ret
28470 .Lmemset_e_e:
28471 .previous
28472@@ -59,7 +61,7 @@
28473 ENTRY(memset)
28474 ENTRY(__memset)
28475 CFI_STARTPROC
28476- movq %rdi,%r10
28477+ movq %rdi,%r11
28478
28479 /* expand byte value */
28480 movzbl %sil,%ecx
28481@@ -117,7 +119,8 @@ ENTRY(__memset)
28482 jnz .Lloop_1
28483
28484 .Lende:
28485- movq %r10,%rax
28486+ movq %r11,%rax
28487+ pax_force_retaddr
28488 ret
28489
28490 CFI_RESTORE_STATE
28491diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28492index c9f2d9b..e7fd2c0 100644
28493--- a/arch/x86/lib/mmx_32.c
28494+++ b/arch/x86/lib/mmx_32.c
28495@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28496 {
28497 void *p;
28498 int i;
28499+ unsigned long cr0;
28500
28501 if (unlikely(in_interrupt()))
28502 return __memcpy(to, from, len);
28503@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28504 kernel_fpu_begin();
28505
28506 __asm__ __volatile__ (
28507- "1: prefetch (%0)\n" /* This set is 28 bytes */
28508- " prefetch 64(%0)\n"
28509- " prefetch 128(%0)\n"
28510- " prefetch 192(%0)\n"
28511- " prefetch 256(%0)\n"
28512+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28513+ " prefetch 64(%1)\n"
28514+ " prefetch 128(%1)\n"
28515+ " prefetch 192(%1)\n"
28516+ " prefetch 256(%1)\n"
28517 "2: \n"
28518 ".section .fixup, \"ax\"\n"
28519- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28520+ "3: \n"
28521+
28522+#ifdef CONFIG_PAX_KERNEXEC
28523+ " movl %%cr0, %0\n"
28524+ " movl %0, %%eax\n"
28525+ " andl $0xFFFEFFFF, %%eax\n"
28526+ " movl %%eax, %%cr0\n"
28527+#endif
28528+
28529+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28530+
28531+#ifdef CONFIG_PAX_KERNEXEC
28532+ " movl %0, %%cr0\n"
28533+#endif
28534+
28535 " jmp 2b\n"
28536 ".previous\n"
28537 _ASM_EXTABLE(1b, 3b)
28538- : : "r" (from));
28539+ : "=&r" (cr0) : "r" (from) : "ax");
28540
28541 for ( ; i > 5; i--) {
28542 __asm__ __volatile__ (
28543- "1: prefetch 320(%0)\n"
28544- "2: movq (%0), %%mm0\n"
28545- " movq 8(%0), %%mm1\n"
28546- " movq 16(%0), %%mm2\n"
28547- " movq 24(%0), %%mm3\n"
28548- " movq %%mm0, (%1)\n"
28549- " movq %%mm1, 8(%1)\n"
28550- " movq %%mm2, 16(%1)\n"
28551- " movq %%mm3, 24(%1)\n"
28552- " movq 32(%0), %%mm0\n"
28553- " movq 40(%0), %%mm1\n"
28554- " movq 48(%0), %%mm2\n"
28555- " movq 56(%0), %%mm3\n"
28556- " movq %%mm0, 32(%1)\n"
28557- " movq %%mm1, 40(%1)\n"
28558- " movq %%mm2, 48(%1)\n"
28559- " movq %%mm3, 56(%1)\n"
28560+ "1: prefetch 320(%1)\n"
28561+ "2: movq (%1), %%mm0\n"
28562+ " movq 8(%1), %%mm1\n"
28563+ " movq 16(%1), %%mm2\n"
28564+ " movq 24(%1), %%mm3\n"
28565+ " movq %%mm0, (%2)\n"
28566+ " movq %%mm1, 8(%2)\n"
28567+ " movq %%mm2, 16(%2)\n"
28568+ " movq %%mm3, 24(%2)\n"
28569+ " movq 32(%1), %%mm0\n"
28570+ " movq 40(%1), %%mm1\n"
28571+ " movq 48(%1), %%mm2\n"
28572+ " movq 56(%1), %%mm3\n"
28573+ " movq %%mm0, 32(%2)\n"
28574+ " movq %%mm1, 40(%2)\n"
28575+ " movq %%mm2, 48(%2)\n"
28576+ " movq %%mm3, 56(%2)\n"
28577 ".section .fixup, \"ax\"\n"
28578- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28579+ "3:\n"
28580+
28581+#ifdef CONFIG_PAX_KERNEXEC
28582+ " movl %%cr0, %0\n"
28583+ " movl %0, %%eax\n"
28584+ " andl $0xFFFEFFFF, %%eax\n"
28585+ " movl %%eax, %%cr0\n"
28586+#endif
28587+
28588+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28589+
28590+#ifdef CONFIG_PAX_KERNEXEC
28591+ " movl %0, %%cr0\n"
28592+#endif
28593+
28594 " jmp 2b\n"
28595 ".previous\n"
28596 _ASM_EXTABLE(1b, 3b)
28597- : : "r" (from), "r" (to) : "memory");
28598+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28599
28600 from += 64;
28601 to += 64;
28602@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28603 static void fast_copy_page(void *to, void *from)
28604 {
28605 int i;
28606+ unsigned long cr0;
28607
28608 kernel_fpu_begin();
28609
28610@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28611 * but that is for later. -AV
28612 */
28613 __asm__ __volatile__(
28614- "1: prefetch (%0)\n"
28615- " prefetch 64(%0)\n"
28616- " prefetch 128(%0)\n"
28617- " prefetch 192(%0)\n"
28618- " prefetch 256(%0)\n"
28619+ "1: prefetch (%1)\n"
28620+ " prefetch 64(%1)\n"
28621+ " prefetch 128(%1)\n"
28622+ " prefetch 192(%1)\n"
28623+ " prefetch 256(%1)\n"
28624 "2: \n"
28625 ".section .fixup, \"ax\"\n"
28626- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28627+ "3: \n"
28628+
28629+#ifdef CONFIG_PAX_KERNEXEC
28630+ " movl %%cr0, %0\n"
28631+ " movl %0, %%eax\n"
28632+ " andl $0xFFFEFFFF, %%eax\n"
28633+ " movl %%eax, %%cr0\n"
28634+#endif
28635+
28636+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28637+
28638+#ifdef CONFIG_PAX_KERNEXEC
28639+ " movl %0, %%cr0\n"
28640+#endif
28641+
28642 " jmp 2b\n"
28643 ".previous\n"
28644- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28645+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28646
28647 for (i = 0; i < (4096-320)/64; i++) {
28648 __asm__ __volatile__ (
28649- "1: prefetch 320(%0)\n"
28650- "2: movq (%0), %%mm0\n"
28651- " movntq %%mm0, (%1)\n"
28652- " movq 8(%0), %%mm1\n"
28653- " movntq %%mm1, 8(%1)\n"
28654- " movq 16(%0), %%mm2\n"
28655- " movntq %%mm2, 16(%1)\n"
28656- " movq 24(%0), %%mm3\n"
28657- " movntq %%mm3, 24(%1)\n"
28658- " movq 32(%0), %%mm4\n"
28659- " movntq %%mm4, 32(%1)\n"
28660- " movq 40(%0), %%mm5\n"
28661- " movntq %%mm5, 40(%1)\n"
28662- " movq 48(%0), %%mm6\n"
28663- " movntq %%mm6, 48(%1)\n"
28664- " movq 56(%0), %%mm7\n"
28665- " movntq %%mm7, 56(%1)\n"
28666+ "1: prefetch 320(%1)\n"
28667+ "2: movq (%1), %%mm0\n"
28668+ " movntq %%mm0, (%2)\n"
28669+ " movq 8(%1), %%mm1\n"
28670+ " movntq %%mm1, 8(%2)\n"
28671+ " movq 16(%1), %%mm2\n"
28672+ " movntq %%mm2, 16(%2)\n"
28673+ " movq 24(%1), %%mm3\n"
28674+ " movntq %%mm3, 24(%2)\n"
28675+ " movq 32(%1), %%mm4\n"
28676+ " movntq %%mm4, 32(%2)\n"
28677+ " movq 40(%1), %%mm5\n"
28678+ " movntq %%mm5, 40(%2)\n"
28679+ " movq 48(%1), %%mm6\n"
28680+ " movntq %%mm6, 48(%2)\n"
28681+ " movq 56(%1), %%mm7\n"
28682+ " movntq %%mm7, 56(%2)\n"
28683 ".section .fixup, \"ax\"\n"
28684- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28685+ "3:\n"
28686+
28687+#ifdef CONFIG_PAX_KERNEXEC
28688+ " movl %%cr0, %0\n"
28689+ " movl %0, %%eax\n"
28690+ " andl $0xFFFEFFFF, %%eax\n"
28691+ " movl %%eax, %%cr0\n"
28692+#endif
28693+
28694+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28695+
28696+#ifdef CONFIG_PAX_KERNEXEC
28697+ " movl %0, %%cr0\n"
28698+#endif
28699+
28700 " jmp 2b\n"
28701 ".previous\n"
28702- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28703+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28704
28705 from += 64;
28706 to += 64;
28707@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28708 static void fast_copy_page(void *to, void *from)
28709 {
28710 int i;
28711+ unsigned long cr0;
28712
28713 kernel_fpu_begin();
28714
28715 __asm__ __volatile__ (
28716- "1: prefetch (%0)\n"
28717- " prefetch 64(%0)\n"
28718- " prefetch 128(%0)\n"
28719- " prefetch 192(%0)\n"
28720- " prefetch 256(%0)\n"
28721+ "1: prefetch (%1)\n"
28722+ " prefetch 64(%1)\n"
28723+ " prefetch 128(%1)\n"
28724+ " prefetch 192(%1)\n"
28725+ " prefetch 256(%1)\n"
28726 "2: \n"
28727 ".section .fixup, \"ax\"\n"
28728- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28729+ "3: \n"
28730+
28731+#ifdef CONFIG_PAX_KERNEXEC
28732+ " movl %%cr0, %0\n"
28733+ " movl %0, %%eax\n"
28734+ " andl $0xFFFEFFFF, %%eax\n"
28735+ " movl %%eax, %%cr0\n"
28736+#endif
28737+
28738+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28739+
28740+#ifdef CONFIG_PAX_KERNEXEC
28741+ " movl %0, %%cr0\n"
28742+#endif
28743+
28744 " jmp 2b\n"
28745 ".previous\n"
28746- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28747+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28748
28749 for (i = 0; i < 4096/64; i++) {
28750 __asm__ __volatile__ (
28751- "1: prefetch 320(%0)\n"
28752- "2: movq (%0), %%mm0\n"
28753- " movq 8(%0), %%mm1\n"
28754- " movq 16(%0), %%mm2\n"
28755- " movq 24(%0), %%mm3\n"
28756- " movq %%mm0, (%1)\n"
28757- " movq %%mm1, 8(%1)\n"
28758- " movq %%mm2, 16(%1)\n"
28759- " movq %%mm3, 24(%1)\n"
28760- " movq 32(%0), %%mm0\n"
28761- " movq 40(%0), %%mm1\n"
28762- " movq 48(%0), %%mm2\n"
28763- " movq 56(%0), %%mm3\n"
28764- " movq %%mm0, 32(%1)\n"
28765- " movq %%mm1, 40(%1)\n"
28766- " movq %%mm2, 48(%1)\n"
28767- " movq %%mm3, 56(%1)\n"
28768+ "1: prefetch 320(%1)\n"
28769+ "2: movq (%1), %%mm0\n"
28770+ " movq 8(%1), %%mm1\n"
28771+ " movq 16(%1), %%mm2\n"
28772+ " movq 24(%1), %%mm3\n"
28773+ " movq %%mm0, (%2)\n"
28774+ " movq %%mm1, 8(%2)\n"
28775+ " movq %%mm2, 16(%2)\n"
28776+ " movq %%mm3, 24(%2)\n"
28777+ " movq 32(%1), %%mm0\n"
28778+ " movq 40(%1), %%mm1\n"
28779+ " movq 48(%1), %%mm2\n"
28780+ " movq 56(%1), %%mm3\n"
28781+ " movq %%mm0, 32(%2)\n"
28782+ " movq %%mm1, 40(%2)\n"
28783+ " movq %%mm2, 48(%2)\n"
28784+ " movq %%mm3, 56(%2)\n"
28785 ".section .fixup, \"ax\"\n"
28786- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28787+ "3:\n"
28788+
28789+#ifdef CONFIG_PAX_KERNEXEC
28790+ " movl %%cr0, %0\n"
28791+ " movl %0, %%eax\n"
28792+ " andl $0xFFFEFFFF, %%eax\n"
28793+ " movl %%eax, %%cr0\n"
28794+#endif
28795+
28796+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28797+
28798+#ifdef CONFIG_PAX_KERNEXEC
28799+ " movl %0, %%cr0\n"
28800+#endif
28801+
28802 " jmp 2b\n"
28803 ".previous\n"
28804 _ASM_EXTABLE(1b, 3b)
28805- : : "r" (from), "r" (to) : "memory");
28806+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28807
28808 from += 64;
28809 to += 64;
28810diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28811index f6d13ee..aca5f0b 100644
28812--- a/arch/x86/lib/msr-reg.S
28813+++ b/arch/x86/lib/msr-reg.S
28814@@ -3,6 +3,7 @@
28815 #include <asm/dwarf2.h>
28816 #include <asm/asm.h>
28817 #include <asm/msr.h>
28818+#include <asm/alternative-asm.h>
28819
28820 #ifdef CONFIG_X86_64
28821 /*
28822@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28823 CFI_STARTPROC
28824 pushq_cfi %rbx
28825 pushq_cfi %rbp
28826- movq %rdi, %r10 /* Save pointer */
28827+ movq %rdi, %r9 /* Save pointer */
28828 xorl %r11d, %r11d /* Return value */
28829 movl (%rdi), %eax
28830 movl 4(%rdi), %ecx
28831@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28832 movl 28(%rdi), %edi
28833 CFI_REMEMBER_STATE
28834 1: \op
28835-2: movl %eax, (%r10)
28836+2: movl %eax, (%r9)
28837 movl %r11d, %eax /* Return value */
28838- movl %ecx, 4(%r10)
28839- movl %edx, 8(%r10)
28840- movl %ebx, 12(%r10)
28841- movl %ebp, 20(%r10)
28842- movl %esi, 24(%r10)
28843- movl %edi, 28(%r10)
28844+ movl %ecx, 4(%r9)
28845+ movl %edx, 8(%r9)
28846+ movl %ebx, 12(%r9)
28847+ movl %ebp, 20(%r9)
28848+ movl %esi, 24(%r9)
28849+ movl %edi, 28(%r9)
28850 popq_cfi %rbp
28851 popq_cfi %rbx
28852+ pax_force_retaddr
28853 ret
28854 3:
28855 CFI_RESTORE_STATE
28856diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28857index fc6ba17..d4d989d 100644
28858--- a/arch/x86/lib/putuser.S
28859+++ b/arch/x86/lib/putuser.S
28860@@ -16,7 +16,9 @@
28861 #include <asm/errno.h>
28862 #include <asm/asm.h>
28863 #include <asm/smap.h>
28864-
28865+#include <asm/segment.h>
28866+#include <asm/pgtable.h>
28867+#include <asm/alternative-asm.h>
28868
28869 /*
28870 * __put_user_X
28871@@ -30,57 +32,125 @@
28872 * as they get called from within inline assembly.
28873 */
28874
28875-#define ENTER CFI_STARTPROC ; \
28876- GET_THREAD_INFO(%_ASM_BX)
28877-#define EXIT ASM_CLAC ; \
28878- ret ; \
28879+#define ENTER CFI_STARTPROC
28880+#define EXIT ASM_CLAC ; \
28881+ pax_force_retaddr ; \
28882+ ret ; \
28883 CFI_ENDPROC
28884
28885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28886+#define _DEST %_ASM_CX,%_ASM_BX
28887+#else
28888+#define _DEST %_ASM_CX
28889+#endif
28890+
28891+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28892+#define __copyuser_seg gs;
28893+#else
28894+#define __copyuser_seg
28895+#endif
28896+
28897 .text
28898 ENTRY(__put_user_1)
28899 ENTER
28900+
28901+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28902+ GET_THREAD_INFO(%_ASM_BX)
28903 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28904 jae bad_put_user
28905 ASM_STAC
28906-1: movb %al,(%_ASM_CX)
28907+
28908+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28909+ mov pax_user_shadow_base,%_ASM_BX
28910+ cmp %_ASM_BX,%_ASM_CX
28911+ jb 1234f
28912+ xor %ebx,%ebx
28913+1234:
28914+#endif
28915+
28916+#endif
28917+
28918+1: __copyuser_seg movb %al,(_DEST)
28919 xor %eax,%eax
28920 EXIT
28921 ENDPROC(__put_user_1)
28922
28923 ENTRY(__put_user_2)
28924 ENTER
28925+
28926+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28927+ GET_THREAD_INFO(%_ASM_BX)
28928 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28929 sub $1,%_ASM_BX
28930 cmp %_ASM_BX,%_ASM_CX
28931 jae bad_put_user
28932 ASM_STAC
28933-2: movw %ax,(%_ASM_CX)
28934+
28935+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28936+ mov pax_user_shadow_base,%_ASM_BX
28937+ cmp %_ASM_BX,%_ASM_CX
28938+ jb 1234f
28939+ xor %ebx,%ebx
28940+1234:
28941+#endif
28942+
28943+#endif
28944+
28945+2: __copyuser_seg movw %ax,(_DEST)
28946 xor %eax,%eax
28947 EXIT
28948 ENDPROC(__put_user_2)
28949
28950 ENTRY(__put_user_4)
28951 ENTER
28952+
28953+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28954+ GET_THREAD_INFO(%_ASM_BX)
28955 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28956 sub $3,%_ASM_BX
28957 cmp %_ASM_BX,%_ASM_CX
28958 jae bad_put_user
28959 ASM_STAC
28960-3: movl %eax,(%_ASM_CX)
28961+
28962+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28963+ mov pax_user_shadow_base,%_ASM_BX
28964+ cmp %_ASM_BX,%_ASM_CX
28965+ jb 1234f
28966+ xor %ebx,%ebx
28967+1234:
28968+#endif
28969+
28970+#endif
28971+
28972+3: __copyuser_seg movl %eax,(_DEST)
28973 xor %eax,%eax
28974 EXIT
28975 ENDPROC(__put_user_4)
28976
28977 ENTRY(__put_user_8)
28978 ENTER
28979+
28980+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28981+ GET_THREAD_INFO(%_ASM_BX)
28982 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28983 sub $7,%_ASM_BX
28984 cmp %_ASM_BX,%_ASM_CX
28985 jae bad_put_user
28986 ASM_STAC
28987-4: mov %_ASM_AX,(%_ASM_CX)
28988+
28989+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28990+ mov pax_user_shadow_base,%_ASM_BX
28991+ cmp %_ASM_BX,%_ASM_CX
28992+ jb 1234f
28993+ xor %ebx,%ebx
28994+1234:
28995+#endif
28996+
28997+#endif
28998+
28999+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29000 #ifdef CONFIG_X86_32
29001-5: movl %edx,4(%_ASM_CX)
29002+5: __copyuser_seg movl %edx,4(_DEST)
29003 #endif
29004 xor %eax,%eax
29005 EXIT
29006diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29007index 1cad221..de671ee 100644
29008--- a/arch/x86/lib/rwlock.S
29009+++ b/arch/x86/lib/rwlock.S
29010@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29011 FRAME
29012 0: LOCK_PREFIX
29013 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29014+
29015+#ifdef CONFIG_PAX_REFCOUNT
29016+ jno 1234f
29017+ LOCK_PREFIX
29018+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29019+ int $4
29020+1234:
29021+ _ASM_EXTABLE(1234b, 1234b)
29022+#endif
29023+
29024 1: rep; nop
29025 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29026 jne 1b
29027 LOCK_PREFIX
29028 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29029+
29030+#ifdef CONFIG_PAX_REFCOUNT
29031+ jno 1234f
29032+ LOCK_PREFIX
29033+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29034+ int $4
29035+1234:
29036+ _ASM_EXTABLE(1234b, 1234b)
29037+#endif
29038+
29039 jnz 0b
29040 ENDFRAME
29041+ pax_force_retaddr
29042 ret
29043 CFI_ENDPROC
29044 END(__write_lock_failed)
29045@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29046 FRAME
29047 0: LOCK_PREFIX
29048 READ_LOCK_SIZE(inc) (%__lock_ptr)
29049+
29050+#ifdef CONFIG_PAX_REFCOUNT
29051+ jno 1234f
29052+ LOCK_PREFIX
29053+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29054+ int $4
29055+1234:
29056+ _ASM_EXTABLE(1234b, 1234b)
29057+#endif
29058+
29059 1: rep; nop
29060 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29061 js 1b
29062 LOCK_PREFIX
29063 READ_LOCK_SIZE(dec) (%__lock_ptr)
29064+
29065+#ifdef CONFIG_PAX_REFCOUNT
29066+ jno 1234f
29067+ LOCK_PREFIX
29068+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29069+ int $4
29070+1234:
29071+ _ASM_EXTABLE(1234b, 1234b)
29072+#endif
29073+
29074 js 0b
29075 ENDFRAME
29076+ pax_force_retaddr
29077 ret
29078 CFI_ENDPROC
29079 END(__read_lock_failed)
29080diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29081index 5dff5f0..cadebf4 100644
29082--- a/arch/x86/lib/rwsem.S
29083+++ b/arch/x86/lib/rwsem.S
29084@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29085 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29086 CFI_RESTORE __ASM_REG(dx)
29087 restore_common_regs
29088+ pax_force_retaddr
29089 ret
29090 CFI_ENDPROC
29091 ENDPROC(call_rwsem_down_read_failed)
29092@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29093 movq %rax,%rdi
29094 call rwsem_down_write_failed
29095 restore_common_regs
29096+ pax_force_retaddr
29097 ret
29098 CFI_ENDPROC
29099 ENDPROC(call_rwsem_down_write_failed)
29100@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29101 movq %rax,%rdi
29102 call rwsem_wake
29103 restore_common_regs
29104-1: ret
29105+1: pax_force_retaddr
29106+ ret
29107 CFI_ENDPROC
29108 ENDPROC(call_rwsem_wake)
29109
29110@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29111 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29112 CFI_RESTORE __ASM_REG(dx)
29113 restore_common_regs
29114+ pax_force_retaddr
29115 ret
29116 CFI_ENDPROC
29117 ENDPROC(call_rwsem_downgrade_wake)
29118diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29119index a63efd6..ccecad8 100644
29120--- a/arch/x86/lib/thunk_64.S
29121+++ b/arch/x86/lib/thunk_64.S
29122@@ -8,6 +8,7 @@
29123 #include <linux/linkage.h>
29124 #include <asm/dwarf2.h>
29125 #include <asm/calling.h>
29126+#include <asm/alternative-asm.h>
29127
29128 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29129 .macro THUNK name, func, put_ret_addr_in_rdi=0
29130@@ -41,5 +42,6 @@
29131 SAVE_ARGS
29132 restore:
29133 RESTORE_ARGS
29134+ pax_force_retaddr
29135 ret
29136 CFI_ENDPROC
29137diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29138index 3eb18ac..6890bc3 100644
29139--- a/arch/x86/lib/usercopy_32.c
29140+++ b/arch/x86/lib/usercopy_32.c
29141@@ -42,11 +42,13 @@ do { \
29142 int __d0; \
29143 might_fault(); \
29144 __asm__ __volatile__( \
29145+ __COPYUSER_SET_ES \
29146 ASM_STAC "\n" \
29147 "0: rep; stosl\n" \
29148 " movl %2,%0\n" \
29149 "1: rep; stosb\n" \
29150 "2: " ASM_CLAC "\n" \
29151+ __COPYUSER_RESTORE_ES \
29152 ".section .fixup,\"ax\"\n" \
29153 "3: lea 0(%2,%0,4),%0\n" \
29154 " jmp 2b\n" \
29155@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29156
29157 #ifdef CONFIG_X86_INTEL_USERCOPY
29158 static unsigned long
29159-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29160+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29161 {
29162 int d0, d1;
29163 __asm__ __volatile__(
29164@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29165 " .align 2,0x90\n"
29166 "3: movl 0(%4), %%eax\n"
29167 "4: movl 4(%4), %%edx\n"
29168- "5: movl %%eax, 0(%3)\n"
29169- "6: movl %%edx, 4(%3)\n"
29170+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29171+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29172 "7: movl 8(%4), %%eax\n"
29173 "8: movl 12(%4),%%edx\n"
29174- "9: movl %%eax, 8(%3)\n"
29175- "10: movl %%edx, 12(%3)\n"
29176+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29177+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29178 "11: movl 16(%4), %%eax\n"
29179 "12: movl 20(%4), %%edx\n"
29180- "13: movl %%eax, 16(%3)\n"
29181- "14: movl %%edx, 20(%3)\n"
29182+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29183+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29184 "15: movl 24(%4), %%eax\n"
29185 "16: movl 28(%4), %%edx\n"
29186- "17: movl %%eax, 24(%3)\n"
29187- "18: movl %%edx, 28(%3)\n"
29188+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29189+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29190 "19: movl 32(%4), %%eax\n"
29191 "20: movl 36(%4), %%edx\n"
29192- "21: movl %%eax, 32(%3)\n"
29193- "22: movl %%edx, 36(%3)\n"
29194+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29195+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29196 "23: movl 40(%4), %%eax\n"
29197 "24: movl 44(%4), %%edx\n"
29198- "25: movl %%eax, 40(%3)\n"
29199- "26: movl %%edx, 44(%3)\n"
29200+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29201+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29202 "27: movl 48(%4), %%eax\n"
29203 "28: movl 52(%4), %%edx\n"
29204- "29: movl %%eax, 48(%3)\n"
29205- "30: movl %%edx, 52(%3)\n"
29206+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29207+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29208 "31: movl 56(%4), %%eax\n"
29209 "32: movl 60(%4), %%edx\n"
29210- "33: movl %%eax, 56(%3)\n"
29211- "34: movl %%edx, 60(%3)\n"
29212+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29213+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29214 " addl $-64, %0\n"
29215 " addl $64, %4\n"
29216 " addl $64, %3\n"
29217@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29218 " shrl $2, %0\n"
29219 " andl $3, %%eax\n"
29220 " cld\n"
29221+ __COPYUSER_SET_ES
29222 "99: rep; movsl\n"
29223 "36: movl %%eax, %0\n"
29224 "37: rep; movsb\n"
29225 "100:\n"
29226+ __COPYUSER_RESTORE_ES
29227 ".section .fixup,\"ax\"\n"
29228 "101: lea 0(%%eax,%0,4),%0\n"
29229 " jmp 100b\n"
29230@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29231 }
29232
29233 static unsigned long
29234+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29235+{
29236+ int d0, d1;
29237+ __asm__ __volatile__(
29238+ " .align 2,0x90\n"
29239+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29240+ " cmpl $67, %0\n"
29241+ " jbe 3f\n"
29242+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29243+ " .align 2,0x90\n"
29244+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29245+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29246+ "5: movl %%eax, 0(%3)\n"
29247+ "6: movl %%edx, 4(%3)\n"
29248+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29249+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29250+ "9: movl %%eax, 8(%3)\n"
29251+ "10: movl %%edx, 12(%3)\n"
29252+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29253+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29254+ "13: movl %%eax, 16(%3)\n"
29255+ "14: movl %%edx, 20(%3)\n"
29256+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29257+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29258+ "17: movl %%eax, 24(%3)\n"
29259+ "18: movl %%edx, 28(%3)\n"
29260+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29261+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29262+ "21: movl %%eax, 32(%3)\n"
29263+ "22: movl %%edx, 36(%3)\n"
29264+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29265+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29266+ "25: movl %%eax, 40(%3)\n"
29267+ "26: movl %%edx, 44(%3)\n"
29268+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29269+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29270+ "29: movl %%eax, 48(%3)\n"
29271+ "30: movl %%edx, 52(%3)\n"
29272+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29273+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29274+ "33: movl %%eax, 56(%3)\n"
29275+ "34: movl %%edx, 60(%3)\n"
29276+ " addl $-64, %0\n"
29277+ " addl $64, %4\n"
29278+ " addl $64, %3\n"
29279+ " cmpl $63, %0\n"
29280+ " ja 1b\n"
29281+ "35: movl %0, %%eax\n"
29282+ " shrl $2, %0\n"
29283+ " andl $3, %%eax\n"
29284+ " cld\n"
29285+ "99: rep; "__copyuser_seg" movsl\n"
29286+ "36: movl %%eax, %0\n"
29287+ "37: rep; "__copyuser_seg" movsb\n"
29288+ "100:\n"
29289+ ".section .fixup,\"ax\"\n"
29290+ "101: lea 0(%%eax,%0,4),%0\n"
29291+ " jmp 100b\n"
29292+ ".previous\n"
29293+ _ASM_EXTABLE(1b,100b)
29294+ _ASM_EXTABLE(2b,100b)
29295+ _ASM_EXTABLE(3b,100b)
29296+ _ASM_EXTABLE(4b,100b)
29297+ _ASM_EXTABLE(5b,100b)
29298+ _ASM_EXTABLE(6b,100b)
29299+ _ASM_EXTABLE(7b,100b)
29300+ _ASM_EXTABLE(8b,100b)
29301+ _ASM_EXTABLE(9b,100b)
29302+ _ASM_EXTABLE(10b,100b)
29303+ _ASM_EXTABLE(11b,100b)
29304+ _ASM_EXTABLE(12b,100b)
29305+ _ASM_EXTABLE(13b,100b)
29306+ _ASM_EXTABLE(14b,100b)
29307+ _ASM_EXTABLE(15b,100b)
29308+ _ASM_EXTABLE(16b,100b)
29309+ _ASM_EXTABLE(17b,100b)
29310+ _ASM_EXTABLE(18b,100b)
29311+ _ASM_EXTABLE(19b,100b)
29312+ _ASM_EXTABLE(20b,100b)
29313+ _ASM_EXTABLE(21b,100b)
29314+ _ASM_EXTABLE(22b,100b)
29315+ _ASM_EXTABLE(23b,100b)
29316+ _ASM_EXTABLE(24b,100b)
29317+ _ASM_EXTABLE(25b,100b)
29318+ _ASM_EXTABLE(26b,100b)
29319+ _ASM_EXTABLE(27b,100b)
29320+ _ASM_EXTABLE(28b,100b)
29321+ _ASM_EXTABLE(29b,100b)
29322+ _ASM_EXTABLE(30b,100b)
29323+ _ASM_EXTABLE(31b,100b)
29324+ _ASM_EXTABLE(32b,100b)
29325+ _ASM_EXTABLE(33b,100b)
29326+ _ASM_EXTABLE(34b,100b)
29327+ _ASM_EXTABLE(35b,100b)
29328+ _ASM_EXTABLE(36b,100b)
29329+ _ASM_EXTABLE(37b,100b)
29330+ _ASM_EXTABLE(99b,101b)
29331+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29332+ : "1"(to), "2"(from), "0"(size)
29333+ : "eax", "edx", "memory");
29334+ return size;
29335+}
29336+
29337+static unsigned long __size_overflow(3)
29338 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29339 {
29340 int d0, d1;
29341 __asm__ __volatile__(
29342 " .align 2,0x90\n"
29343- "0: movl 32(%4), %%eax\n"
29344+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29345 " cmpl $67, %0\n"
29346 " jbe 2f\n"
29347- "1: movl 64(%4), %%eax\n"
29348+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29349 " .align 2,0x90\n"
29350- "2: movl 0(%4), %%eax\n"
29351- "21: movl 4(%4), %%edx\n"
29352+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29353+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29354 " movl %%eax, 0(%3)\n"
29355 " movl %%edx, 4(%3)\n"
29356- "3: movl 8(%4), %%eax\n"
29357- "31: movl 12(%4),%%edx\n"
29358+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29359+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29360 " movl %%eax, 8(%3)\n"
29361 " movl %%edx, 12(%3)\n"
29362- "4: movl 16(%4), %%eax\n"
29363- "41: movl 20(%4), %%edx\n"
29364+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29365+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29366 " movl %%eax, 16(%3)\n"
29367 " movl %%edx, 20(%3)\n"
29368- "10: movl 24(%4), %%eax\n"
29369- "51: movl 28(%4), %%edx\n"
29370+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29371+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29372 " movl %%eax, 24(%3)\n"
29373 " movl %%edx, 28(%3)\n"
29374- "11: movl 32(%4), %%eax\n"
29375- "61: movl 36(%4), %%edx\n"
29376+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29377+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29378 " movl %%eax, 32(%3)\n"
29379 " movl %%edx, 36(%3)\n"
29380- "12: movl 40(%4), %%eax\n"
29381- "71: movl 44(%4), %%edx\n"
29382+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29383+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29384 " movl %%eax, 40(%3)\n"
29385 " movl %%edx, 44(%3)\n"
29386- "13: movl 48(%4), %%eax\n"
29387- "81: movl 52(%4), %%edx\n"
29388+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29389+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29390 " movl %%eax, 48(%3)\n"
29391 " movl %%edx, 52(%3)\n"
29392- "14: movl 56(%4), %%eax\n"
29393- "91: movl 60(%4), %%edx\n"
29394+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29395+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29396 " movl %%eax, 56(%3)\n"
29397 " movl %%edx, 60(%3)\n"
29398 " addl $-64, %0\n"
29399@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29400 " shrl $2, %0\n"
29401 " andl $3, %%eax\n"
29402 " cld\n"
29403- "6: rep; movsl\n"
29404+ "6: rep; "__copyuser_seg" movsl\n"
29405 " movl %%eax,%0\n"
29406- "7: rep; movsb\n"
29407+ "7: rep; "__copyuser_seg" movsb\n"
29408 "8:\n"
29409 ".section .fixup,\"ax\"\n"
29410 "9: lea 0(%%eax,%0,4),%0\n"
29411@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29412 * hyoshiok@miraclelinux.com
29413 */
29414
29415-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29416+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29417 const void __user *from, unsigned long size)
29418 {
29419 int d0, d1;
29420
29421 __asm__ __volatile__(
29422 " .align 2,0x90\n"
29423- "0: movl 32(%4), %%eax\n"
29424+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29425 " cmpl $67, %0\n"
29426 " jbe 2f\n"
29427- "1: movl 64(%4), %%eax\n"
29428+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29429 " .align 2,0x90\n"
29430- "2: movl 0(%4), %%eax\n"
29431- "21: movl 4(%4), %%edx\n"
29432+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29433+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29434 " movnti %%eax, 0(%3)\n"
29435 " movnti %%edx, 4(%3)\n"
29436- "3: movl 8(%4), %%eax\n"
29437- "31: movl 12(%4),%%edx\n"
29438+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29439+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29440 " movnti %%eax, 8(%3)\n"
29441 " movnti %%edx, 12(%3)\n"
29442- "4: movl 16(%4), %%eax\n"
29443- "41: movl 20(%4), %%edx\n"
29444+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29445+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29446 " movnti %%eax, 16(%3)\n"
29447 " movnti %%edx, 20(%3)\n"
29448- "10: movl 24(%4), %%eax\n"
29449- "51: movl 28(%4), %%edx\n"
29450+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29451+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29452 " movnti %%eax, 24(%3)\n"
29453 " movnti %%edx, 28(%3)\n"
29454- "11: movl 32(%4), %%eax\n"
29455- "61: movl 36(%4), %%edx\n"
29456+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29457+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29458 " movnti %%eax, 32(%3)\n"
29459 " movnti %%edx, 36(%3)\n"
29460- "12: movl 40(%4), %%eax\n"
29461- "71: movl 44(%4), %%edx\n"
29462+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29463+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29464 " movnti %%eax, 40(%3)\n"
29465 " movnti %%edx, 44(%3)\n"
29466- "13: movl 48(%4), %%eax\n"
29467- "81: movl 52(%4), %%edx\n"
29468+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29469+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29470 " movnti %%eax, 48(%3)\n"
29471 " movnti %%edx, 52(%3)\n"
29472- "14: movl 56(%4), %%eax\n"
29473- "91: movl 60(%4), %%edx\n"
29474+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29475+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29476 " movnti %%eax, 56(%3)\n"
29477 " movnti %%edx, 60(%3)\n"
29478 " addl $-64, %0\n"
29479@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29480 " shrl $2, %0\n"
29481 " andl $3, %%eax\n"
29482 " cld\n"
29483- "6: rep; movsl\n"
29484+ "6: rep; "__copyuser_seg" movsl\n"
29485 " movl %%eax,%0\n"
29486- "7: rep; movsb\n"
29487+ "7: rep; "__copyuser_seg" movsb\n"
29488 "8:\n"
29489 ".section .fixup,\"ax\"\n"
29490 "9: lea 0(%%eax,%0,4),%0\n"
29491@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29492 return size;
29493 }
29494
29495-static unsigned long __copy_user_intel_nocache(void *to,
29496+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29497 const void __user *from, unsigned long size)
29498 {
29499 int d0, d1;
29500
29501 __asm__ __volatile__(
29502 " .align 2,0x90\n"
29503- "0: movl 32(%4), %%eax\n"
29504+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29505 " cmpl $67, %0\n"
29506 " jbe 2f\n"
29507- "1: movl 64(%4), %%eax\n"
29508+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29509 " .align 2,0x90\n"
29510- "2: movl 0(%4), %%eax\n"
29511- "21: movl 4(%4), %%edx\n"
29512+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29513+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29514 " movnti %%eax, 0(%3)\n"
29515 " movnti %%edx, 4(%3)\n"
29516- "3: movl 8(%4), %%eax\n"
29517- "31: movl 12(%4),%%edx\n"
29518+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29519+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29520 " movnti %%eax, 8(%3)\n"
29521 " movnti %%edx, 12(%3)\n"
29522- "4: movl 16(%4), %%eax\n"
29523- "41: movl 20(%4), %%edx\n"
29524+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29525+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29526 " movnti %%eax, 16(%3)\n"
29527 " movnti %%edx, 20(%3)\n"
29528- "10: movl 24(%4), %%eax\n"
29529- "51: movl 28(%4), %%edx\n"
29530+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29531+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29532 " movnti %%eax, 24(%3)\n"
29533 " movnti %%edx, 28(%3)\n"
29534- "11: movl 32(%4), %%eax\n"
29535- "61: movl 36(%4), %%edx\n"
29536+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29537+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29538 " movnti %%eax, 32(%3)\n"
29539 " movnti %%edx, 36(%3)\n"
29540- "12: movl 40(%4), %%eax\n"
29541- "71: movl 44(%4), %%edx\n"
29542+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29543+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29544 " movnti %%eax, 40(%3)\n"
29545 " movnti %%edx, 44(%3)\n"
29546- "13: movl 48(%4), %%eax\n"
29547- "81: movl 52(%4), %%edx\n"
29548+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29549+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29550 " movnti %%eax, 48(%3)\n"
29551 " movnti %%edx, 52(%3)\n"
29552- "14: movl 56(%4), %%eax\n"
29553- "91: movl 60(%4), %%edx\n"
29554+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29555+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29556 " movnti %%eax, 56(%3)\n"
29557 " movnti %%edx, 60(%3)\n"
29558 " addl $-64, %0\n"
29559@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29560 " shrl $2, %0\n"
29561 " andl $3, %%eax\n"
29562 " cld\n"
29563- "6: rep; movsl\n"
29564+ "6: rep; "__copyuser_seg" movsl\n"
29565 " movl %%eax,%0\n"
29566- "7: rep; movsb\n"
29567+ "7: rep; "__copyuser_seg" movsb\n"
29568 "8:\n"
29569 ".section .fixup,\"ax\"\n"
29570 "9: lea 0(%%eax,%0,4),%0\n"
29571@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29572 */
29573 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29574 unsigned long size);
29575-unsigned long __copy_user_intel(void __user *to, const void *from,
29576+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29577+ unsigned long size);
29578+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29579 unsigned long size);
29580 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29581 const void __user *from, unsigned long size);
29582 #endif /* CONFIG_X86_INTEL_USERCOPY */
29583
29584 /* Generic arbitrary sized copy. */
29585-#define __copy_user(to, from, size) \
29586+#define __copy_user(to, from, size, prefix, set, restore) \
29587 do { \
29588 int __d0, __d1, __d2; \
29589 __asm__ __volatile__( \
29590+ set \
29591 " cmp $7,%0\n" \
29592 " jbe 1f\n" \
29593 " movl %1,%0\n" \
29594 " negl %0\n" \
29595 " andl $7,%0\n" \
29596 " subl %0,%3\n" \
29597- "4: rep; movsb\n" \
29598+ "4: rep; "prefix"movsb\n" \
29599 " movl %3,%0\n" \
29600 " shrl $2,%0\n" \
29601 " andl $3,%3\n" \
29602 " .align 2,0x90\n" \
29603- "0: rep; movsl\n" \
29604+ "0: rep; "prefix"movsl\n" \
29605 " movl %3,%0\n" \
29606- "1: rep; movsb\n" \
29607+ "1: rep; "prefix"movsb\n" \
29608 "2:\n" \
29609+ restore \
29610 ".section .fixup,\"ax\"\n" \
29611 "5: addl %3,%0\n" \
29612 " jmp 2b\n" \
29613@@ -538,14 +650,14 @@ do { \
29614 " negl %0\n" \
29615 " andl $7,%0\n" \
29616 " subl %0,%3\n" \
29617- "4: rep; movsb\n" \
29618+ "4: rep; "__copyuser_seg"movsb\n" \
29619 " movl %3,%0\n" \
29620 " shrl $2,%0\n" \
29621 " andl $3,%3\n" \
29622 " .align 2,0x90\n" \
29623- "0: rep; movsl\n" \
29624+ "0: rep; "__copyuser_seg"movsl\n" \
29625 " movl %3,%0\n" \
29626- "1: rep; movsb\n" \
29627+ "1: rep; "__copyuser_seg"movsb\n" \
29628 "2:\n" \
29629 ".section .fixup,\"ax\"\n" \
29630 "5: addl %3,%0\n" \
29631@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29632 {
29633 stac();
29634 if (movsl_is_ok(to, from, n))
29635- __copy_user(to, from, n);
29636+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29637 else
29638- n = __copy_user_intel(to, from, n);
29639+ n = __generic_copy_to_user_intel(to, from, n);
29640 clac();
29641 return n;
29642 }
29643@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29644 {
29645 stac();
29646 if (movsl_is_ok(to, from, n))
29647- __copy_user(to, from, n);
29648+ __copy_user(to, from, n, __copyuser_seg, "", "");
29649 else
29650- n = __copy_user_intel((void __user *)to,
29651- (const void *)from, n);
29652+ n = __generic_copy_from_user_intel(to, from, n);
29653 clac();
29654 return n;
29655 }
29656@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29657 if (n > 64 && cpu_has_xmm2)
29658 n = __copy_user_intel_nocache(to, from, n);
29659 else
29660- __copy_user(to, from, n);
29661+ __copy_user(to, from, n, __copyuser_seg, "", "");
29662 #else
29663- __copy_user(to, from, n);
29664+ __copy_user(to, from, n, __copyuser_seg, "", "");
29665 #endif
29666 clac();
29667 return n;
29668 }
29669 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29670
29671-/**
29672- * copy_to_user: - Copy a block of data into user space.
29673- * @to: Destination address, in user space.
29674- * @from: Source address, in kernel space.
29675- * @n: Number of bytes to copy.
29676- *
29677- * Context: User context only. This function may sleep.
29678- *
29679- * Copy data from kernel space to user space.
29680- *
29681- * Returns number of bytes that could not be copied.
29682- * On success, this will be zero.
29683- */
29684-unsigned long
29685-copy_to_user(void __user *to, const void *from, unsigned long n)
29686+#ifdef CONFIG_PAX_MEMORY_UDEREF
29687+void __set_fs(mm_segment_t x)
29688 {
29689- if (access_ok(VERIFY_WRITE, to, n))
29690- n = __copy_to_user(to, from, n);
29691- return n;
29692+ switch (x.seg) {
29693+ case 0:
29694+ loadsegment(gs, 0);
29695+ break;
29696+ case TASK_SIZE_MAX:
29697+ loadsegment(gs, __USER_DS);
29698+ break;
29699+ case -1UL:
29700+ loadsegment(gs, __KERNEL_DS);
29701+ break;
29702+ default:
29703+ BUG();
29704+ }
29705 }
29706-EXPORT_SYMBOL(copy_to_user);
29707+EXPORT_SYMBOL(__set_fs);
29708
29709-/**
29710- * copy_from_user: - Copy a block of data from user space.
29711- * @to: Destination address, in kernel space.
29712- * @from: Source address, in user space.
29713- * @n: Number of bytes to copy.
29714- *
29715- * Context: User context only. This function may sleep.
29716- *
29717- * Copy data from user space to kernel space.
29718- *
29719- * Returns number of bytes that could not be copied.
29720- * On success, this will be zero.
29721- *
29722- * If some data could not be copied, this function will pad the copied
29723- * data to the requested size using zero bytes.
29724- */
29725-unsigned long
29726-_copy_from_user(void *to, const void __user *from, unsigned long n)
29727+void set_fs(mm_segment_t x)
29728 {
29729- if (access_ok(VERIFY_READ, from, n))
29730- n = __copy_from_user(to, from, n);
29731- else
29732- memset(to, 0, n);
29733- return n;
29734+ current_thread_info()->addr_limit = x;
29735+ __set_fs(x);
29736 }
29737-EXPORT_SYMBOL(_copy_from_user);
29738+EXPORT_SYMBOL(set_fs);
29739+#endif
29740diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29741index 906fea3..0194a18 100644
29742--- a/arch/x86/lib/usercopy_64.c
29743+++ b/arch/x86/lib/usercopy_64.c
29744@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29745 might_fault();
29746 /* no memory constraint because it doesn't change any memory gcc knows
29747 about */
29748+ pax_open_userland();
29749 stac();
29750 asm volatile(
29751 " testq %[size8],%[size8]\n"
29752@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29753 _ASM_EXTABLE(0b,3b)
29754 _ASM_EXTABLE(1b,2b)
29755 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29756- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29757+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29758 [zero] "r" (0UL), [eight] "r" (8UL));
29759 clac();
29760+ pax_close_userland();
29761 return size;
29762 }
29763 EXPORT_SYMBOL(__clear_user);
29764@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29765 }
29766 EXPORT_SYMBOL(clear_user);
29767
29768-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29769+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29770 {
29771- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29772- return copy_user_generic((__force void *)to, (__force void *)from, len);
29773- }
29774- return len;
29775+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29776+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29777+ return len;
29778 }
29779 EXPORT_SYMBOL(copy_in_user);
29780
29781@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29782 * it is not necessary to optimize tail handling.
29783 */
29784 unsigned long
29785-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29786+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29787 {
29788 char c;
29789 unsigned zero_len;
29790
29791+ clac();
29792+ pax_close_userland();
29793 for (; len; --len, to++) {
29794 if (__get_user_nocheck(c, from++, sizeof(char)))
29795 break;
29796@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29797 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29798 if (__put_user_nocheck(c, to++, sizeof(char)))
29799 break;
29800- clac();
29801 return len;
29802 }
29803diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29804index 23d8e5f..9ccc13a 100644
29805--- a/arch/x86/mm/Makefile
29806+++ b/arch/x86/mm/Makefile
29807@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29808 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29809
29810 obj-$(CONFIG_MEMTEST) += memtest.o
29811+
29812+quote:="
29813+obj-$(CONFIG_X86_64) += uderef_64.o
29814+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29815diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29816index 903ec1e..c4166b2 100644
29817--- a/arch/x86/mm/extable.c
29818+++ b/arch/x86/mm/extable.c
29819@@ -6,12 +6,24 @@
29820 static inline unsigned long
29821 ex_insn_addr(const struct exception_table_entry *x)
29822 {
29823- return (unsigned long)&x->insn + x->insn;
29824+ unsigned long reloc = 0;
29825+
29826+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29827+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29828+#endif
29829+
29830+ return (unsigned long)&x->insn + x->insn + reloc;
29831 }
29832 static inline unsigned long
29833 ex_fixup_addr(const struct exception_table_entry *x)
29834 {
29835- return (unsigned long)&x->fixup + x->fixup;
29836+ unsigned long reloc = 0;
29837+
29838+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29839+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29840+#endif
29841+
29842+ return (unsigned long)&x->fixup + x->fixup + reloc;
29843 }
29844
29845 int fixup_exception(struct pt_regs *regs)
29846@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29847 unsigned long new_ip;
29848
29849 #ifdef CONFIG_PNPBIOS
29850- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29851+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29852 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29853 extern u32 pnp_bios_is_utter_crap;
29854 pnp_bios_is_utter_crap = 1;
29855@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29856 i += 4;
29857 p->fixup -= i;
29858 i += 4;
29859+
29860+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29861+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29862+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29863+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29864+#endif
29865+
29866 }
29867 }
29868
29869diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29870index 654be4a..a4a3da1 100644
29871--- a/arch/x86/mm/fault.c
29872+++ b/arch/x86/mm/fault.c
29873@@ -14,11 +14,18 @@
29874 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29875 #include <linux/prefetch.h> /* prefetchw */
29876 #include <linux/context_tracking.h> /* exception_enter(), ... */
29877+#include <linux/unistd.h>
29878+#include <linux/compiler.h>
29879
29880 #include <asm/traps.h> /* dotraplinkage, ... */
29881 #include <asm/pgalloc.h> /* pgd_*(), ... */
29882 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29883 #include <asm/fixmap.h> /* VSYSCALL_START */
29884+#include <asm/tlbflush.h>
29885+
29886+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29887+#include <asm/stacktrace.h>
29888+#endif
29889
29890 /*
29891 * Page fault error code bits:
29892@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29893 int ret = 0;
29894
29895 /* kprobe_running() needs smp_processor_id() */
29896- if (kprobes_built_in() && !user_mode_vm(regs)) {
29897+ if (kprobes_built_in() && !user_mode(regs)) {
29898 preempt_disable();
29899 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29900 ret = 1;
29901@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29902 return !instr_lo || (instr_lo>>1) == 1;
29903 case 0x00:
29904 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29905- if (probe_kernel_address(instr, opcode))
29906+ if (user_mode(regs)) {
29907+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29908+ return 0;
29909+ } else if (probe_kernel_address(instr, opcode))
29910 return 0;
29911
29912 *prefetch = (instr_lo == 0xF) &&
29913@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29914 while (instr < max_instr) {
29915 unsigned char opcode;
29916
29917- if (probe_kernel_address(instr, opcode))
29918+ if (user_mode(regs)) {
29919+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29920+ break;
29921+ } else if (probe_kernel_address(instr, opcode))
29922 break;
29923
29924 instr++;
29925@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29926 force_sig_info(si_signo, &info, tsk);
29927 }
29928
29929+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29930+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29931+#endif
29932+
29933+#ifdef CONFIG_PAX_EMUTRAMP
29934+static int pax_handle_fetch_fault(struct pt_regs *regs);
29935+#endif
29936+
29937+#ifdef CONFIG_PAX_PAGEEXEC
29938+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29939+{
29940+ pgd_t *pgd;
29941+ pud_t *pud;
29942+ pmd_t *pmd;
29943+
29944+ pgd = pgd_offset(mm, address);
29945+ if (!pgd_present(*pgd))
29946+ return NULL;
29947+ pud = pud_offset(pgd, address);
29948+ if (!pud_present(*pud))
29949+ return NULL;
29950+ pmd = pmd_offset(pud, address);
29951+ if (!pmd_present(*pmd))
29952+ return NULL;
29953+ return pmd;
29954+}
29955+#endif
29956+
29957 DEFINE_SPINLOCK(pgd_lock);
29958 LIST_HEAD(pgd_list);
29959
29960@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29961 for (address = VMALLOC_START & PMD_MASK;
29962 address >= TASK_SIZE && address < FIXADDR_TOP;
29963 address += PMD_SIZE) {
29964+
29965+#ifdef CONFIG_PAX_PER_CPU_PGD
29966+ unsigned long cpu;
29967+#else
29968 struct page *page;
29969+#endif
29970
29971 spin_lock(&pgd_lock);
29972+
29973+#ifdef CONFIG_PAX_PER_CPU_PGD
29974+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29975+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29976+ pmd_t *ret;
29977+
29978+ ret = vmalloc_sync_one(pgd, address);
29979+ if (!ret)
29980+ break;
29981+ pgd = get_cpu_pgd(cpu, kernel);
29982+#else
29983 list_for_each_entry(page, &pgd_list, lru) {
29984+ pgd_t *pgd;
29985 spinlock_t *pgt_lock;
29986 pmd_t *ret;
29987
29988@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29989 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29990
29991 spin_lock(pgt_lock);
29992- ret = vmalloc_sync_one(page_address(page), address);
29993+ pgd = page_address(page);
29994+#endif
29995+
29996+ ret = vmalloc_sync_one(pgd, address);
29997+
29998+#ifndef CONFIG_PAX_PER_CPU_PGD
29999 spin_unlock(pgt_lock);
30000+#endif
30001
30002 if (!ret)
30003 break;
30004@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30005 * an interrupt in the middle of a task switch..
30006 */
30007 pgd_paddr = read_cr3();
30008+
30009+#ifdef CONFIG_PAX_PER_CPU_PGD
30010+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30011+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30012+#endif
30013+
30014 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30015 if (!pmd_k)
30016 return -1;
30017@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30018 * happen within a race in page table update. In the later
30019 * case just flush:
30020 */
30021- pgd = pgd_offset(current->active_mm, address);
30022+
30023 pgd_ref = pgd_offset_k(address);
30024 if (pgd_none(*pgd_ref))
30025 return -1;
30026
30027+#ifdef CONFIG_PAX_PER_CPU_PGD
30028+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30029+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30030+ if (pgd_none(*pgd)) {
30031+ set_pgd(pgd, *pgd_ref);
30032+ arch_flush_lazy_mmu_mode();
30033+ } else {
30034+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30035+ }
30036+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30037+#else
30038+ pgd = pgd_offset(current->active_mm, address);
30039+#endif
30040+
30041 if (pgd_none(*pgd)) {
30042 set_pgd(pgd, *pgd_ref);
30043 arch_flush_lazy_mmu_mode();
30044@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30045 static int is_errata100(struct pt_regs *regs, unsigned long address)
30046 {
30047 #ifdef CONFIG_X86_64
30048- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30049+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30050 return 1;
30051 #endif
30052 return 0;
30053@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30054 }
30055
30056 static const char nx_warning[] = KERN_CRIT
30057-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30058+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30059
30060 static void
30061 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30062@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30063 if (!oops_may_print())
30064 return;
30065
30066- if (error_code & PF_INSTR) {
30067+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30068 unsigned int level;
30069
30070 pte_t *pte = lookup_address(address, &level);
30071
30072 if (pte && pte_present(*pte) && !pte_exec(*pte))
30073- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30074+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30075 }
30076
30077+#ifdef CONFIG_PAX_KERNEXEC
30078+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30079+ if (current->signal->curr_ip)
30080+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30081+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30082+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30083+ else
30084+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30085+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30086+ }
30087+#endif
30088+
30089 printk(KERN_ALERT "BUG: unable to handle kernel ");
30090 if (address < PAGE_SIZE)
30091 printk(KERN_CONT "NULL pointer dereference");
30092@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30093 return;
30094 }
30095 #endif
30096+
30097+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30098+ if (pax_is_fetch_fault(regs, error_code, address)) {
30099+
30100+#ifdef CONFIG_PAX_EMUTRAMP
30101+ switch (pax_handle_fetch_fault(regs)) {
30102+ case 2:
30103+ return;
30104+ }
30105+#endif
30106+
30107+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30108+ do_group_exit(SIGKILL);
30109+ }
30110+#endif
30111+
30112 /* Kernel addresses are always protection faults: */
30113 if (address >= TASK_SIZE)
30114 error_code |= PF_PROT;
30115@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30116 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30117 printk(KERN_ERR
30118 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30119- tsk->comm, tsk->pid, address);
30120+ tsk->comm, task_pid_nr(tsk), address);
30121 code = BUS_MCEERR_AR;
30122 }
30123 #endif
30124@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30125 return 1;
30126 }
30127
30128+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30129+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30130+{
30131+ pte_t *pte;
30132+ pmd_t *pmd;
30133+ spinlock_t *ptl;
30134+ unsigned char pte_mask;
30135+
30136+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30137+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30138+ return 0;
30139+
30140+ /* PaX: it's our fault, let's handle it if we can */
30141+
30142+ /* PaX: take a look at read faults before acquiring any locks */
30143+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30144+ /* instruction fetch attempt from a protected page in user mode */
30145+ up_read(&mm->mmap_sem);
30146+
30147+#ifdef CONFIG_PAX_EMUTRAMP
30148+ switch (pax_handle_fetch_fault(regs)) {
30149+ case 2:
30150+ return 1;
30151+ }
30152+#endif
30153+
30154+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30155+ do_group_exit(SIGKILL);
30156+ }
30157+
30158+ pmd = pax_get_pmd(mm, address);
30159+ if (unlikely(!pmd))
30160+ return 0;
30161+
30162+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30163+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30164+ pte_unmap_unlock(pte, ptl);
30165+ return 0;
30166+ }
30167+
30168+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30169+ /* write attempt to a protected page in user mode */
30170+ pte_unmap_unlock(pte, ptl);
30171+ return 0;
30172+ }
30173+
30174+#ifdef CONFIG_SMP
30175+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30176+#else
30177+ if (likely(address > get_limit(regs->cs)))
30178+#endif
30179+ {
30180+ set_pte(pte, pte_mkread(*pte));
30181+ __flush_tlb_one(address);
30182+ pte_unmap_unlock(pte, ptl);
30183+ up_read(&mm->mmap_sem);
30184+ return 1;
30185+ }
30186+
30187+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30188+
30189+ /*
30190+ * PaX: fill DTLB with user rights and retry
30191+ */
30192+ __asm__ __volatile__ (
30193+ "orb %2,(%1)\n"
30194+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30195+/*
30196+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30197+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30198+ * page fault when examined during a TLB load attempt. this is true not only
30199+ * for PTEs holding a non-present entry but also present entries that will
30200+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30201+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30202+ * for our target pages since their PTEs are simply not in the TLBs at all.
30203+
30204+ * the best thing in omitting it is that we gain around 15-20% speed in the
30205+ * fast path of the page fault handler and can get rid of tracing since we
30206+ * can no longer flush unintended entries.
30207+ */
30208+ "invlpg (%0)\n"
30209+#endif
30210+ __copyuser_seg"testb $0,(%0)\n"
30211+ "xorb %3,(%1)\n"
30212+ :
30213+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30214+ : "memory", "cc");
30215+ pte_unmap_unlock(pte, ptl);
30216+ up_read(&mm->mmap_sem);
30217+ return 1;
30218+}
30219+#endif
30220+
30221 /*
30222 * Handle a spurious fault caused by a stale TLB entry.
30223 *
30224@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30225 static inline int
30226 access_error(unsigned long error_code, struct vm_area_struct *vma)
30227 {
30228+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30229+ return 1;
30230+
30231 if (error_code & PF_WRITE) {
30232 /* write, present and write, not present: */
30233 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30234@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30235 if (error_code & PF_USER)
30236 return false;
30237
30238- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30239+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30240 return false;
30241
30242 return true;
30243@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30244 {
30245 struct vm_area_struct *vma;
30246 struct task_struct *tsk;
30247- unsigned long address;
30248 struct mm_struct *mm;
30249 int fault;
30250 int write = error_code & PF_WRITE;
30251 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30252 (write ? FAULT_FLAG_WRITE : 0);
30253
30254- tsk = current;
30255- mm = tsk->mm;
30256-
30257 /* Get the faulting address: */
30258- address = read_cr2();
30259+ unsigned long address = read_cr2();
30260+
30261+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30262+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30263+ if (!search_exception_tables(regs->ip)) {
30264+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30265+ bad_area_nosemaphore(regs, error_code, address);
30266+ return;
30267+ }
30268+ if (address < pax_user_shadow_base) {
30269+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30270+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30271+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30272+ } else
30273+ address -= pax_user_shadow_base;
30274+ }
30275+#endif
30276+
30277+ tsk = current;
30278+ mm = tsk->mm;
30279
30280 /*
30281 * Detect and handle instructions that would cause a page fault for
30282@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30283 * User-mode registers count as a user access even for any
30284 * potential system fault or CPU buglet:
30285 */
30286- if (user_mode_vm(regs)) {
30287+ if (user_mode(regs)) {
30288 local_irq_enable();
30289 error_code |= PF_USER;
30290 } else {
30291@@ -1142,6 +1365,11 @@ retry:
30292 might_sleep();
30293 }
30294
30295+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30296+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30297+ return;
30298+#endif
30299+
30300 vma = find_vma(mm, address);
30301 if (unlikely(!vma)) {
30302 bad_area(regs, error_code, address);
30303@@ -1153,18 +1381,24 @@ retry:
30304 bad_area(regs, error_code, address);
30305 return;
30306 }
30307- if (error_code & PF_USER) {
30308- /*
30309- * Accessing the stack below %sp is always a bug.
30310- * The large cushion allows instructions like enter
30311- * and pusha to work. ("enter $65535, $31" pushes
30312- * 32 pointers and then decrements %sp by 65535.)
30313- */
30314- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30315- bad_area(regs, error_code, address);
30316- return;
30317- }
30318+ /*
30319+ * Accessing the stack below %sp is always a bug.
30320+ * The large cushion allows instructions like enter
30321+ * and pusha to work. ("enter $65535, $31" pushes
30322+ * 32 pointers and then decrements %sp by 65535.)
30323+ */
30324+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30325+ bad_area(regs, error_code, address);
30326+ return;
30327 }
30328+
30329+#ifdef CONFIG_PAX_SEGMEXEC
30330+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30331+ bad_area(regs, error_code, address);
30332+ return;
30333+ }
30334+#endif
30335+
30336 if (unlikely(expand_stack(vma, address))) {
30337 bad_area(regs, error_code, address);
30338 return;
30339@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30340 __do_page_fault(regs, error_code);
30341 exception_exit(prev_state);
30342 }
30343+
30344+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30345+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30346+{
30347+ struct mm_struct *mm = current->mm;
30348+ unsigned long ip = regs->ip;
30349+
30350+ if (v8086_mode(regs))
30351+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30352+
30353+#ifdef CONFIG_PAX_PAGEEXEC
30354+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30355+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30356+ return true;
30357+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30358+ return true;
30359+ return false;
30360+ }
30361+#endif
30362+
30363+#ifdef CONFIG_PAX_SEGMEXEC
30364+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30365+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30366+ return true;
30367+ return false;
30368+ }
30369+#endif
30370+
30371+ return false;
30372+}
30373+#endif
30374+
30375+#ifdef CONFIG_PAX_EMUTRAMP
30376+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30377+{
30378+ int err;
30379+
30380+ do { /* PaX: libffi trampoline emulation */
30381+ unsigned char mov, jmp;
30382+ unsigned int addr1, addr2;
30383+
30384+#ifdef CONFIG_X86_64
30385+ if ((regs->ip + 9) >> 32)
30386+ break;
30387+#endif
30388+
30389+ err = get_user(mov, (unsigned char __user *)regs->ip);
30390+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30391+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30392+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30393+
30394+ if (err)
30395+ break;
30396+
30397+ if (mov == 0xB8 && jmp == 0xE9) {
30398+ regs->ax = addr1;
30399+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30400+ return 2;
30401+ }
30402+ } while (0);
30403+
30404+ do { /* PaX: gcc trampoline emulation #1 */
30405+ unsigned char mov1, mov2;
30406+ unsigned short jmp;
30407+ unsigned int addr1, addr2;
30408+
30409+#ifdef CONFIG_X86_64
30410+ if ((regs->ip + 11) >> 32)
30411+ break;
30412+#endif
30413+
30414+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30415+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30416+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30417+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30418+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30419+
30420+ if (err)
30421+ break;
30422+
30423+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30424+ regs->cx = addr1;
30425+ regs->ax = addr2;
30426+ regs->ip = addr2;
30427+ return 2;
30428+ }
30429+ } while (0);
30430+
30431+ do { /* PaX: gcc trampoline emulation #2 */
30432+ unsigned char mov, jmp;
30433+ unsigned int addr1, addr2;
30434+
30435+#ifdef CONFIG_X86_64
30436+ if ((regs->ip + 9) >> 32)
30437+ break;
30438+#endif
30439+
30440+ err = get_user(mov, (unsigned char __user *)regs->ip);
30441+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30442+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30443+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30444+
30445+ if (err)
30446+ break;
30447+
30448+ if (mov == 0xB9 && jmp == 0xE9) {
30449+ regs->cx = addr1;
30450+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30451+ return 2;
30452+ }
30453+ } while (0);
30454+
30455+ return 1; /* PaX in action */
30456+}
30457+
30458+#ifdef CONFIG_X86_64
30459+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30460+{
30461+ int err;
30462+
30463+ do { /* PaX: libffi trampoline emulation */
30464+ unsigned short mov1, mov2, jmp1;
30465+ unsigned char stcclc, jmp2;
30466+ unsigned long addr1, addr2;
30467+
30468+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30469+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30470+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30471+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30472+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30473+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30474+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30475+
30476+ if (err)
30477+ break;
30478+
30479+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30480+ regs->r11 = addr1;
30481+ regs->r10 = addr2;
30482+ if (stcclc == 0xF8)
30483+ regs->flags &= ~X86_EFLAGS_CF;
30484+ else
30485+ regs->flags |= X86_EFLAGS_CF;
30486+ regs->ip = addr1;
30487+ return 2;
30488+ }
30489+ } while (0);
30490+
30491+ do { /* PaX: gcc trampoline emulation #1 */
30492+ unsigned short mov1, mov2, jmp1;
30493+ unsigned char jmp2;
30494+ unsigned int addr1;
30495+ unsigned long addr2;
30496+
30497+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30498+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30499+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30500+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30501+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30502+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30503+
30504+ if (err)
30505+ break;
30506+
30507+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30508+ regs->r11 = addr1;
30509+ regs->r10 = addr2;
30510+ regs->ip = addr1;
30511+ return 2;
30512+ }
30513+ } while (0);
30514+
30515+ do { /* PaX: gcc trampoline emulation #2 */
30516+ unsigned short mov1, mov2, jmp1;
30517+ unsigned char jmp2;
30518+ unsigned long addr1, addr2;
30519+
30520+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30521+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30522+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30523+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30524+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30525+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30526+
30527+ if (err)
30528+ break;
30529+
30530+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30531+ regs->r11 = addr1;
30532+ regs->r10 = addr2;
30533+ regs->ip = addr1;
30534+ return 2;
30535+ }
30536+ } while (0);
30537+
30538+ return 1; /* PaX in action */
30539+}
30540+#endif
30541+
30542+/*
30543+ * PaX: decide what to do with offenders (regs->ip = fault address)
30544+ *
30545+ * returns 1 when task should be killed
30546+ * 2 when gcc trampoline was detected
30547+ */
30548+static int pax_handle_fetch_fault(struct pt_regs *regs)
30549+{
30550+ if (v8086_mode(regs))
30551+ return 1;
30552+
30553+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30554+ return 1;
30555+
30556+#ifdef CONFIG_X86_32
30557+ return pax_handle_fetch_fault_32(regs);
30558+#else
30559+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30560+ return pax_handle_fetch_fault_32(regs);
30561+ else
30562+ return pax_handle_fetch_fault_64(regs);
30563+#endif
30564+}
30565+#endif
30566+
30567+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30568+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30569+{
30570+ long i;
30571+
30572+ printk(KERN_ERR "PAX: bytes at PC: ");
30573+ for (i = 0; i < 20; i++) {
30574+ unsigned char c;
30575+ if (get_user(c, (unsigned char __force_user *)pc+i))
30576+ printk(KERN_CONT "?? ");
30577+ else
30578+ printk(KERN_CONT "%02x ", c);
30579+ }
30580+ printk("\n");
30581+
30582+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30583+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30584+ unsigned long c;
30585+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30586+#ifdef CONFIG_X86_32
30587+ printk(KERN_CONT "???????? ");
30588+#else
30589+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30590+ printk(KERN_CONT "???????? ???????? ");
30591+ else
30592+ printk(KERN_CONT "???????????????? ");
30593+#endif
30594+ } else {
30595+#ifdef CONFIG_X86_64
30596+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30597+ printk(KERN_CONT "%08x ", (unsigned int)c);
30598+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30599+ } else
30600+#endif
30601+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30602+ }
30603+ }
30604+ printk("\n");
30605+}
30606+#endif
30607+
30608+/**
30609+ * probe_kernel_write(): safely attempt to write to a location
30610+ * @dst: address to write to
30611+ * @src: pointer to the data that shall be written
30612+ * @size: size of the data chunk
30613+ *
30614+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30615+ * happens, handle that and return -EFAULT.
30616+ */
30617+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30618+{
30619+ long ret;
30620+ mm_segment_t old_fs = get_fs();
30621+
30622+ set_fs(KERNEL_DS);
30623+ pagefault_disable();
30624+ pax_open_kernel();
30625+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30626+ pax_close_kernel();
30627+ pagefault_enable();
30628+ set_fs(old_fs);
30629+
30630+ return ret ? -EFAULT : 0;
30631+}
30632diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30633index dd74e46..7d26398 100644
30634--- a/arch/x86/mm/gup.c
30635+++ b/arch/x86/mm/gup.c
30636@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30637 addr = start;
30638 len = (unsigned long) nr_pages << PAGE_SHIFT;
30639 end = start + len;
30640- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30641+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30642 (void __user *)start, len)))
30643 return 0;
30644
30645diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30646index 4500142..53a363c 100644
30647--- a/arch/x86/mm/highmem_32.c
30648+++ b/arch/x86/mm/highmem_32.c
30649@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30650 idx = type + KM_TYPE_NR*smp_processor_id();
30651 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30652 BUG_ON(!pte_none(*(kmap_pte-idx)));
30653+
30654+ pax_open_kernel();
30655 set_pte(kmap_pte-idx, mk_pte(page, prot));
30656+ pax_close_kernel();
30657+
30658 arch_flush_lazy_mmu_mode();
30659
30660 return (void *)vaddr;
30661diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30662index 7e73e8c..11d3b86 100644
30663--- a/arch/x86/mm/hugetlbpage.c
30664+++ b/arch/x86/mm/hugetlbpage.c
30665@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30666 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30667 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30668 unsigned long addr, unsigned long len,
30669- unsigned long pgoff, unsigned long flags)
30670+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30671 {
30672 struct hstate *h = hstate_file(file);
30673 struct vm_unmapped_area_info info;
30674-
30675+
30676 info.flags = 0;
30677 info.length = len;
30678 info.low_limit = TASK_UNMAPPED_BASE;
30679+
30680+#ifdef CONFIG_PAX_RANDMMAP
30681+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30682+ info.low_limit += current->mm->delta_mmap;
30683+#endif
30684+
30685 info.high_limit = TASK_SIZE;
30686 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30687 info.align_offset = 0;
30688+ info.threadstack_offset = offset;
30689 return vm_unmapped_area(&info);
30690 }
30691
30692 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30693 unsigned long addr0, unsigned long len,
30694- unsigned long pgoff, unsigned long flags)
30695+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30696 {
30697 struct hstate *h = hstate_file(file);
30698 struct vm_unmapped_area_info info;
30699@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30700 info.high_limit = current->mm->mmap_base;
30701 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30702 info.align_offset = 0;
30703+ info.threadstack_offset = offset;
30704 addr = vm_unmapped_area(&info);
30705
30706 /*
30707@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30708 VM_BUG_ON(addr != -ENOMEM);
30709 info.flags = 0;
30710 info.low_limit = TASK_UNMAPPED_BASE;
30711+
30712+#ifdef CONFIG_PAX_RANDMMAP
30713+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30714+ info.low_limit += current->mm->delta_mmap;
30715+#endif
30716+
30717 info.high_limit = TASK_SIZE;
30718 addr = vm_unmapped_area(&info);
30719 }
30720@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30721 struct hstate *h = hstate_file(file);
30722 struct mm_struct *mm = current->mm;
30723 struct vm_area_struct *vma;
30724+ unsigned long pax_task_size = TASK_SIZE;
30725+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30726
30727 if (len & ~huge_page_mask(h))
30728 return -EINVAL;
30729- if (len > TASK_SIZE)
30730+
30731+#ifdef CONFIG_PAX_SEGMEXEC
30732+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30733+ pax_task_size = SEGMEXEC_TASK_SIZE;
30734+#endif
30735+
30736+ pax_task_size -= PAGE_SIZE;
30737+
30738+ if (len > pax_task_size)
30739 return -ENOMEM;
30740
30741 if (flags & MAP_FIXED) {
30742@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30743 return addr;
30744 }
30745
30746+#ifdef CONFIG_PAX_RANDMMAP
30747+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30748+#endif
30749+
30750 if (addr) {
30751 addr = ALIGN(addr, huge_page_size(h));
30752 vma = find_vma(mm, addr);
30753- if (TASK_SIZE - len >= addr &&
30754- (!vma || addr + len <= vma->vm_start))
30755+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30756 return addr;
30757 }
30758 if (mm->get_unmapped_area == arch_get_unmapped_area)
30759 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30760- pgoff, flags);
30761+ pgoff, flags, offset);
30762 else
30763 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30764- pgoff, flags);
30765+ pgoff, flags, offset);
30766 }
30767
30768 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30769diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30770index 04664cd..dae6e5d 100644
30771--- a/arch/x86/mm/init.c
30772+++ b/arch/x86/mm/init.c
30773@@ -4,6 +4,7 @@
30774 #include <linux/swap.h>
30775 #include <linux/memblock.h>
30776 #include <linux/bootmem.h> /* for max_low_pfn */
30777+#include <linux/tboot.h>
30778
30779 #include <asm/cacheflush.h>
30780 #include <asm/e820.h>
30781@@ -17,6 +18,8 @@
30782 #include <asm/proto.h>
30783 #include <asm/dma.h> /* for MAX_DMA_PFN */
30784 #include <asm/microcode.h>
30785+#include <asm/desc.h>
30786+#include <asm/bios_ebda.h>
30787
30788 #include "mm_internal.h"
30789
30790@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30791 early_ioremap_page_table_range_init();
30792 #endif
30793
30794+#ifdef CONFIG_PAX_PER_CPU_PGD
30795+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30796+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30797+ KERNEL_PGD_PTRS);
30798+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30799+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30800+ KERNEL_PGD_PTRS);
30801+ load_cr3(get_cpu_pgd(0, kernel));
30802+#else
30803 load_cr3(swapper_pg_dir);
30804+#endif
30805+
30806 __flush_tlb_all();
30807
30808 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30809@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30810 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30811 * mmio resources as well as potential bios/acpi data regions.
30812 */
30813+
30814+#ifdef CONFIG_GRKERNSEC_KMEM
30815+static unsigned int ebda_start __read_only;
30816+static unsigned int ebda_end __read_only;
30817+#endif
30818+
30819 int devmem_is_allowed(unsigned long pagenr)
30820 {
30821- if (pagenr < 256)
30822+#ifdef CONFIG_GRKERNSEC_KMEM
30823+ /* allow BDA */
30824+ if (!pagenr)
30825 return 1;
30826+ /* allow EBDA */
30827+ if (pagenr >= ebda_start && pagenr < ebda_end)
30828+ return 1;
30829+ /* if tboot is in use, allow access to its hardcoded serial log range */
30830+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30831+ return 1;
30832+#else
30833+ if (!pagenr)
30834+ return 1;
30835+#ifdef CONFIG_VM86
30836+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30837+ return 1;
30838+#endif
30839+#endif
30840+
30841+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30842+ return 1;
30843+#ifdef CONFIG_GRKERNSEC_KMEM
30844+ /* throw out everything else below 1MB */
30845+ if (pagenr <= 256)
30846+ return 0;
30847+#endif
30848 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30849 return 0;
30850 if (!page_is_ram(pagenr))
30851@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30852 #endif
30853 }
30854
30855+#ifdef CONFIG_GRKERNSEC_KMEM
30856+static inline void gr_init_ebda(void)
30857+{
30858+ unsigned int ebda_addr;
30859+ unsigned int ebda_size = 0;
30860+
30861+ ebda_addr = get_bios_ebda();
30862+ if (ebda_addr) {
30863+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30864+ ebda_size <<= 10;
30865+ }
30866+ if (ebda_addr && ebda_size) {
30867+ ebda_start = ebda_addr >> PAGE_SHIFT;
30868+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30869+ } else {
30870+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30871+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30872+ }
30873+}
30874+#else
30875+static inline void gr_init_ebda(void) { }
30876+#endif
30877+
30878 void free_initmem(void)
30879 {
30880+#ifdef CONFIG_PAX_KERNEXEC
30881+#ifdef CONFIG_X86_32
30882+ /* PaX: limit KERNEL_CS to actual size */
30883+ unsigned long addr, limit;
30884+ struct desc_struct d;
30885+ int cpu;
30886+#else
30887+ pgd_t *pgd;
30888+ pud_t *pud;
30889+ pmd_t *pmd;
30890+ unsigned long addr, end;
30891+#endif
30892+#endif
30893+
30894+ gr_init_ebda();
30895+
30896+#ifdef CONFIG_PAX_KERNEXEC
30897+#ifdef CONFIG_X86_32
30898+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30899+ limit = (limit - 1UL) >> PAGE_SHIFT;
30900+
30901+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30902+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30903+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30904+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30905+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30906+ }
30907+
30908+ /* PaX: make KERNEL_CS read-only */
30909+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30910+ if (!paravirt_enabled())
30911+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30912+/*
30913+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30914+ pgd = pgd_offset_k(addr);
30915+ pud = pud_offset(pgd, addr);
30916+ pmd = pmd_offset(pud, addr);
30917+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30918+ }
30919+*/
30920+#ifdef CONFIG_X86_PAE
30921+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30922+/*
30923+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30924+ pgd = pgd_offset_k(addr);
30925+ pud = pud_offset(pgd, addr);
30926+ pmd = pmd_offset(pud, addr);
30927+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30928+ }
30929+*/
30930+#endif
30931+
30932+#ifdef CONFIG_MODULES
30933+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30934+#endif
30935+
30936+#else
30937+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30938+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30939+ pgd = pgd_offset_k(addr);
30940+ pud = pud_offset(pgd, addr);
30941+ pmd = pmd_offset(pud, addr);
30942+ if (!pmd_present(*pmd))
30943+ continue;
30944+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30945+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30946+ else
30947+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30948+ }
30949+
30950+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30951+ end = addr + KERNEL_IMAGE_SIZE;
30952+ for (; addr < end; addr += PMD_SIZE) {
30953+ pgd = pgd_offset_k(addr);
30954+ pud = pud_offset(pgd, addr);
30955+ pmd = pmd_offset(pud, addr);
30956+ if (!pmd_present(*pmd))
30957+ continue;
30958+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30959+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30960+ }
30961+#endif
30962+
30963+ flush_tlb_all();
30964+#endif
30965+
30966 free_init_pages("unused kernel",
30967 (unsigned long)(&__init_begin),
30968 (unsigned long)(&__init_end));
30969diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30970index 4287f1f..3b99c71 100644
30971--- a/arch/x86/mm/init_32.c
30972+++ b/arch/x86/mm/init_32.c
30973@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30974 bool __read_mostly __vmalloc_start_set = false;
30975
30976 /*
30977- * Creates a middle page table and puts a pointer to it in the
30978- * given global directory entry. This only returns the gd entry
30979- * in non-PAE compilation mode, since the middle layer is folded.
30980- */
30981-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30982-{
30983- pud_t *pud;
30984- pmd_t *pmd_table;
30985-
30986-#ifdef CONFIG_X86_PAE
30987- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30988- pmd_table = (pmd_t *)alloc_low_page();
30989- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30990- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30991- pud = pud_offset(pgd, 0);
30992- BUG_ON(pmd_table != pmd_offset(pud, 0));
30993-
30994- return pmd_table;
30995- }
30996-#endif
30997- pud = pud_offset(pgd, 0);
30998- pmd_table = pmd_offset(pud, 0);
30999-
31000- return pmd_table;
31001-}
31002-
31003-/*
31004 * Create a page table and place a pointer to it in a middle page
31005 * directory entry:
31006 */
31007@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31008 pte_t *page_table = (pte_t *)alloc_low_page();
31009
31010 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31011+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31012+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31013+#else
31014 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31015+#endif
31016 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31017 }
31018
31019 return pte_offset_kernel(pmd, 0);
31020 }
31021
31022+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31023+{
31024+ pud_t *pud;
31025+ pmd_t *pmd_table;
31026+
31027+ pud = pud_offset(pgd, 0);
31028+ pmd_table = pmd_offset(pud, 0);
31029+
31030+ return pmd_table;
31031+}
31032+
31033 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31034 {
31035 int pgd_idx = pgd_index(vaddr);
31036@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31037 int pgd_idx, pmd_idx;
31038 unsigned long vaddr;
31039 pgd_t *pgd;
31040+ pud_t *pud;
31041 pmd_t *pmd;
31042 pte_t *pte = NULL;
31043 unsigned long count = page_table_range_init_count(start, end);
31044@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31045 pgd = pgd_base + pgd_idx;
31046
31047 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31048- pmd = one_md_table_init(pgd);
31049- pmd = pmd + pmd_index(vaddr);
31050+ pud = pud_offset(pgd, vaddr);
31051+ pmd = pmd_offset(pud, vaddr);
31052+
31053+#ifdef CONFIG_X86_PAE
31054+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31055+#endif
31056+
31057 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31058 pmd++, pmd_idx++) {
31059 pte = page_table_kmap_check(one_page_table_init(pmd),
31060@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31061 }
31062 }
31063
31064-static inline int is_kernel_text(unsigned long addr)
31065+static inline int is_kernel_text(unsigned long start, unsigned long end)
31066 {
31067- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31068- return 1;
31069- return 0;
31070+ if ((start > ktla_ktva((unsigned long)_etext) ||
31071+ end <= ktla_ktva((unsigned long)_stext)) &&
31072+ (start > ktla_ktva((unsigned long)_einittext) ||
31073+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31074+
31075+#ifdef CONFIG_ACPI_SLEEP
31076+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31077+#endif
31078+
31079+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31080+ return 0;
31081+ return 1;
31082 }
31083
31084 /*
31085@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31086 unsigned long last_map_addr = end;
31087 unsigned long start_pfn, end_pfn;
31088 pgd_t *pgd_base = swapper_pg_dir;
31089- int pgd_idx, pmd_idx, pte_ofs;
31090+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31091 unsigned long pfn;
31092 pgd_t *pgd;
31093+ pud_t *pud;
31094 pmd_t *pmd;
31095 pte_t *pte;
31096 unsigned pages_2m, pages_4k;
31097@@ -291,8 +295,13 @@ repeat:
31098 pfn = start_pfn;
31099 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31100 pgd = pgd_base + pgd_idx;
31101- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31102- pmd = one_md_table_init(pgd);
31103+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31104+ pud = pud_offset(pgd, 0);
31105+ pmd = pmd_offset(pud, 0);
31106+
31107+#ifdef CONFIG_X86_PAE
31108+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31109+#endif
31110
31111 if (pfn >= end_pfn)
31112 continue;
31113@@ -304,14 +313,13 @@ repeat:
31114 #endif
31115 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31116 pmd++, pmd_idx++) {
31117- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31118+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31119
31120 /*
31121 * Map with big pages if possible, otherwise
31122 * create normal page tables:
31123 */
31124 if (use_pse) {
31125- unsigned int addr2;
31126 pgprot_t prot = PAGE_KERNEL_LARGE;
31127 /*
31128 * first pass will use the same initial
31129@@ -322,11 +330,7 @@ repeat:
31130 _PAGE_PSE);
31131
31132 pfn &= PMD_MASK >> PAGE_SHIFT;
31133- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31134- PAGE_OFFSET + PAGE_SIZE-1;
31135-
31136- if (is_kernel_text(addr) ||
31137- is_kernel_text(addr2))
31138+ if (is_kernel_text(address, address + PMD_SIZE))
31139 prot = PAGE_KERNEL_LARGE_EXEC;
31140
31141 pages_2m++;
31142@@ -343,7 +347,7 @@ repeat:
31143 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31144 pte += pte_ofs;
31145 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31146- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31147+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31148 pgprot_t prot = PAGE_KERNEL;
31149 /*
31150 * first pass will use the same initial
31151@@ -351,7 +355,7 @@ repeat:
31152 */
31153 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31154
31155- if (is_kernel_text(addr))
31156+ if (is_kernel_text(address, address + PAGE_SIZE))
31157 prot = PAGE_KERNEL_EXEC;
31158
31159 pages_4k++;
31160@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31161
31162 pud = pud_offset(pgd, va);
31163 pmd = pmd_offset(pud, va);
31164- if (!pmd_present(*pmd))
31165+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31166 break;
31167
31168 /* should not be large page here */
31169@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31170
31171 static void __init pagetable_init(void)
31172 {
31173- pgd_t *pgd_base = swapper_pg_dir;
31174-
31175- permanent_kmaps_init(pgd_base);
31176+ permanent_kmaps_init(swapper_pg_dir);
31177 }
31178
31179-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31180+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31181 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31182
31183 /* user-defined highmem size */
31184@@ -787,10 +789,10 @@ void __init mem_init(void)
31185 ((unsigned long)&__init_end -
31186 (unsigned long)&__init_begin) >> 10,
31187
31188- (unsigned long)&_etext, (unsigned long)&_edata,
31189- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31190+ (unsigned long)&_sdata, (unsigned long)&_edata,
31191+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31192
31193- (unsigned long)&_text, (unsigned long)&_etext,
31194+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31195 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31196
31197 /*
31198@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31199 if (!kernel_set_to_readonly)
31200 return;
31201
31202+ start = ktla_ktva(start);
31203 pr_debug("Set kernel text: %lx - %lx for read write\n",
31204 start, start+size);
31205
31206@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31207 if (!kernel_set_to_readonly)
31208 return;
31209
31210+ start = ktla_ktva(start);
31211 pr_debug("Set kernel text: %lx - %lx for read only\n",
31212 start, start+size);
31213
31214@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31215 unsigned long start = PFN_ALIGN(_text);
31216 unsigned long size = PFN_ALIGN(_etext) - start;
31217
31218+ start = ktla_ktva(start);
31219 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31220 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31221 size >> 10);
31222diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31223index 104d56a..62ba13f 100644
31224--- a/arch/x86/mm/init_64.c
31225+++ b/arch/x86/mm/init_64.c
31226@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31227 * around without checking the pgd every time.
31228 */
31229
31230-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31231+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31232 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31233
31234 int force_personality32;
31235@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31236
31237 for (address = start; address <= end; address += PGDIR_SIZE) {
31238 const pgd_t *pgd_ref = pgd_offset_k(address);
31239+
31240+#ifdef CONFIG_PAX_PER_CPU_PGD
31241+ unsigned long cpu;
31242+#else
31243 struct page *page;
31244+#endif
31245
31246 if (pgd_none(*pgd_ref))
31247 continue;
31248
31249 spin_lock(&pgd_lock);
31250+
31251+#ifdef CONFIG_PAX_PER_CPU_PGD
31252+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31253+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31254+
31255+ if (pgd_none(*pgd))
31256+ set_pgd(pgd, *pgd_ref);
31257+ else
31258+ BUG_ON(pgd_page_vaddr(*pgd)
31259+ != pgd_page_vaddr(*pgd_ref));
31260+ pgd = pgd_offset_cpu(cpu, kernel, address);
31261+#else
31262 list_for_each_entry(page, &pgd_list, lru) {
31263 pgd_t *pgd;
31264 spinlock_t *pgt_lock;
31265@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31266 /* the pgt_lock only for Xen */
31267 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31268 spin_lock(pgt_lock);
31269+#endif
31270
31271 if (pgd_none(*pgd))
31272 set_pgd(pgd, *pgd_ref);
31273@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31274 BUG_ON(pgd_page_vaddr(*pgd)
31275 != pgd_page_vaddr(*pgd_ref));
31276
31277+#ifndef CONFIG_PAX_PER_CPU_PGD
31278 spin_unlock(pgt_lock);
31279+#endif
31280+
31281 }
31282 spin_unlock(&pgd_lock);
31283 }
31284@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31285 {
31286 if (pgd_none(*pgd)) {
31287 pud_t *pud = (pud_t *)spp_getpage();
31288- pgd_populate(&init_mm, pgd, pud);
31289+ pgd_populate_kernel(&init_mm, pgd, pud);
31290 if (pud != pud_offset(pgd, 0))
31291 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31292 pud, pud_offset(pgd, 0));
31293@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31294 {
31295 if (pud_none(*pud)) {
31296 pmd_t *pmd = (pmd_t *) spp_getpage();
31297- pud_populate(&init_mm, pud, pmd);
31298+ pud_populate_kernel(&init_mm, pud, pmd);
31299 if (pmd != pmd_offset(pud, 0))
31300 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31301 pmd, pmd_offset(pud, 0));
31302@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31303 pmd = fill_pmd(pud, vaddr);
31304 pte = fill_pte(pmd, vaddr);
31305
31306+ pax_open_kernel();
31307 set_pte(pte, new_pte);
31308+ pax_close_kernel();
31309
31310 /*
31311 * It's enough to flush this one mapping.
31312@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31313 pgd = pgd_offset_k((unsigned long)__va(phys));
31314 if (pgd_none(*pgd)) {
31315 pud = (pud_t *) spp_getpage();
31316- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31317- _PAGE_USER));
31318+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31319 }
31320 pud = pud_offset(pgd, (unsigned long)__va(phys));
31321 if (pud_none(*pud)) {
31322 pmd = (pmd_t *) spp_getpage();
31323- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31324- _PAGE_USER));
31325+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31326 }
31327 pmd = pmd_offset(pud, phys);
31328 BUG_ON(!pmd_none(*pmd));
31329@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31330 prot);
31331
31332 spin_lock(&init_mm.page_table_lock);
31333- pud_populate(&init_mm, pud, pmd);
31334+ pud_populate_kernel(&init_mm, pud, pmd);
31335 spin_unlock(&init_mm.page_table_lock);
31336 }
31337 __flush_tlb_all();
31338@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31339 page_size_mask);
31340
31341 spin_lock(&init_mm.page_table_lock);
31342- pgd_populate(&init_mm, pgd, pud);
31343+ pgd_populate_kernel(&init_mm, pgd, pud);
31344 spin_unlock(&init_mm.page_table_lock);
31345 pgd_changed = true;
31346 }
31347@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31348 static struct vm_area_struct gate_vma = {
31349 .vm_start = VSYSCALL_START,
31350 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31351- .vm_page_prot = PAGE_READONLY_EXEC,
31352- .vm_flags = VM_READ | VM_EXEC
31353+ .vm_page_prot = PAGE_READONLY,
31354+ .vm_flags = VM_READ
31355 };
31356
31357 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31358@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31359
31360 const char *arch_vma_name(struct vm_area_struct *vma)
31361 {
31362- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31363+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31364 return "[vdso]";
31365 if (vma == &gate_vma)
31366 return "[vsyscall]";
31367diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31368index 7b179b4..6bd17777 100644
31369--- a/arch/x86/mm/iomap_32.c
31370+++ b/arch/x86/mm/iomap_32.c
31371@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31372 type = kmap_atomic_idx_push();
31373 idx = type + KM_TYPE_NR * smp_processor_id();
31374 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31375+
31376+ pax_open_kernel();
31377 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31378+ pax_close_kernel();
31379+
31380 arch_flush_lazy_mmu_mode();
31381
31382 return (void *)vaddr;
31383diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31384index 0215e2c..1c62dab 100644
31385--- a/arch/x86/mm/ioremap.c
31386+++ b/arch/x86/mm/ioremap.c
31387@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31388 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31389 int is_ram = page_is_ram(pfn);
31390
31391- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31392+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31393 return NULL;
31394 WARN_ON_ONCE(is_ram);
31395 }
31396@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31397 *
31398 * Caller must ensure there is only one unmapping for the same pointer.
31399 */
31400-void iounmap(volatile void __iomem *addr)
31401+void iounmap(const volatile void __iomem *addr)
31402 {
31403 struct vm_struct *p, *o;
31404
31405@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31406
31407 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31408 if (page_is_ram(start >> PAGE_SHIFT))
31409+#ifdef CONFIG_HIGHMEM
31410+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31411+#endif
31412 return __va(phys);
31413
31414 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31415@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31416 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31417 {
31418 if (page_is_ram(phys >> PAGE_SHIFT))
31419+#ifdef CONFIG_HIGHMEM
31420+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31421+#endif
31422 return;
31423
31424 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31425@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31426 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31427
31428 static __initdata int after_paging_init;
31429-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31430+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31431
31432 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31433 {
31434@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31435 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31436
31437 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31438- memset(bm_pte, 0, sizeof(bm_pte));
31439- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31440+ pmd_populate_user(&init_mm, pmd, bm_pte);
31441
31442 /*
31443 * The boot-ioremap range spans multiple pmds, for which
31444diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31445index d87dd6d..bf3fa66 100644
31446--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31447+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31448@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31449 * memory (e.g. tracked pages)? For now, we need this to avoid
31450 * invoking kmemcheck for PnP BIOS calls.
31451 */
31452- if (regs->flags & X86_VM_MASK)
31453+ if (v8086_mode(regs))
31454 return false;
31455- if (regs->cs != __KERNEL_CS)
31456+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31457 return false;
31458
31459 pte = kmemcheck_pte_lookup(address);
31460diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31461index 25e7e13..1964579 100644
31462--- a/arch/x86/mm/mmap.c
31463+++ b/arch/x86/mm/mmap.c
31464@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31465 * Leave an at least ~128 MB hole with possible stack randomization.
31466 */
31467 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31468-#define MAX_GAP (TASK_SIZE/6*5)
31469+#define MAX_GAP (pax_task_size/6*5)
31470
31471 static int mmap_is_legacy(void)
31472 {
31473@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31474 return rnd << PAGE_SHIFT;
31475 }
31476
31477-static unsigned long mmap_base(void)
31478+static unsigned long mmap_base(struct mm_struct *mm)
31479 {
31480 unsigned long gap = rlimit(RLIMIT_STACK);
31481+ unsigned long pax_task_size = TASK_SIZE;
31482+
31483+#ifdef CONFIG_PAX_SEGMEXEC
31484+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31485+ pax_task_size = SEGMEXEC_TASK_SIZE;
31486+#endif
31487
31488 if (gap < MIN_GAP)
31489 gap = MIN_GAP;
31490 else if (gap > MAX_GAP)
31491 gap = MAX_GAP;
31492
31493- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31494+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31495 }
31496
31497 /*
31498 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31499 * does, but not when emulating X86_32
31500 */
31501-static unsigned long mmap_legacy_base(void)
31502+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31503 {
31504- if (mmap_is_ia32())
31505+ if (mmap_is_ia32()) {
31506+
31507+#ifdef CONFIG_PAX_SEGMEXEC
31508+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31509+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31510+ else
31511+#endif
31512+
31513 return TASK_UNMAPPED_BASE;
31514- else
31515+ } else
31516 return TASK_UNMAPPED_BASE + mmap_rnd();
31517 }
31518
31519@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31520 */
31521 void arch_pick_mmap_layout(struct mm_struct *mm)
31522 {
31523- mm->mmap_legacy_base = mmap_legacy_base();
31524- mm->mmap_base = mmap_base();
31525+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31526+ mm->mmap_base = mmap_base(mm);
31527+
31528+#ifdef CONFIG_PAX_RANDMMAP
31529+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31530+ mm->mmap_legacy_base += mm->delta_mmap;
31531+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31532+ }
31533+#endif
31534
31535 if (mmap_is_legacy()) {
31536 mm->mmap_base = mm->mmap_legacy_base;
31537diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31538index 0057a7a..95c7edd 100644
31539--- a/arch/x86/mm/mmio-mod.c
31540+++ b/arch/x86/mm/mmio-mod.c
31541@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31542 break;
31543 default:
31544 {
31545- unsigned char *ip = (unsigned char *)instptr;
31546+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31547 my_trace->opcode = MMIO_UNKNOWN_OP;
31548 my_trace->width = 0;
31549 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31550@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31551 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31552 void __iomem *addr)
31553 {
31554- static atomic_t next_id;
31555+ static atomic_unchecked_t next_id;
31556 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31557 /* These are page-unaligned. */
31558 struct mmiotrace_map map = {
31559@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31560 .private = trace
31561 },
31562 .phys = offset,
31563- .id = atomic_inc_return(&next_id)
31564+ .id = atomic_inc_return_unchecked(&next_id)
31565 };
31566 map.map_id = trace->id;
31567
31568@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31569 ioremap_trace_core(offset, size, addr);
31570 }
31571
31572-static void iounmap_trace_core(volatile void __iomem *addr)
31573+static void iounmap_trace_core(const volatile void __iomem *addr)
31574 {
31575 struct mmiotrace_map map = {
31576 .phys = 0,
31577@@ -328,7 +328,7 @@ not_enabled:
31578 }
31579 }
31580
31581-void mmiotrace_iounmap(volatile void __iomem *addr)
31582+void mmiotrace_iounmap(const volatile void __iomem *addr)
31583 {
31584 might_sleep();
31585 if (is_enabled()) /* recheck and proper locking in *_core() */
31586diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31587index 8bf93ba..dbcd670 100644
31588--- a/arch/x86/mm/numa.c
31589+++ b/arch/x86/mm/numa.c
31590@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31591 return true;
31592 }
31593
31594-static int __init numa_register_memblks(struct numa_meminfo *mi)
31595+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31596 {
31597 unsigned long uninitialized_var(pfn_align);
31598 int i, nid;
31599diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31600index d0b1773..4c3327c 100644
31601--- a/arch/x86/mm/pageattr-test.c
31602+++ b/arch/x86/mm/pageattr-test.c
31603@@ -36,7 +36,7 @@ enum {
31604
31605 static int pte_testbit(pte_t pte)
31606 {
31607- return pte_flags(pte) & _PAGE_UNUSED1;
31608+ return pte_flags(pte) & _PAGE_CPA_TEST;
31609 }
31610
31611 struct split_state {
31612diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31613index bb32480..75f2f5e 100644
31614--- a/arch/x86/mm/pageattr.c
31615+++ b/arch/x86/mm/pageattr.c
31616@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31617 */
31618 #ifdef CONFIG_PCI_BIOS
31619 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31620- pgprot_val(forbidden) |= _PAGE_NX;
31621+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31622 #endif
31623
31624 /*
31625@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31626 * Does not cover __inittext since that is gone later on. On
31627 * 64bit we do not enforce !NX on the low mapping
31628 */
31629- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31630- pgprot_val(forbidden) |= _PAGE_NX;
31631+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31632+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31633
31634+#ifdef CONFIG_DEBUG_RODATA
31635 /*
31636 * The .rodata section needs to be read-only. Using the pfn
31637 * catches all aliases.
31638@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31639 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31640 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31641 pgprot_val(forbidden) |= _PAGE_RW;
31642+#endif
31643
31644 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31645 /*
31646@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31647 }
31648 #endif
31649
31650+#ifdef CONFIG_PAX_KERNEXEC
31651+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31652+ pgprot_val(forbidden) |= _PAGE_RW;
31653+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31654+ }
31655+#endif
31656+
31657 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31658
31659 return prot;
31660@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31661 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31662 {
31663 /* change init_mm */
31664+ pax_open_kernel();
31665 set_pte_atomic(kpte, pte);
31666+
31667 #ifdef CONFIG_X86_32
31668 if (!SHARED_KERNEL_PMD) {
31669+
31670+#ifdef CONFIG_PAX_PER_CPU_PGD
31671+ unsigned long cpu;
31672+#else
31673 struct page *page;
31674+#endif
31675
31676+#ifdef CONFIG_PAX_PER_CPU_PGD
31677+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31678+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31679+#else
31680 list_for_each_entry(page, &pgd_list, lru) {
31681- pgd_t *pgd;
31682+ pgd_t *pgd = (pgd_t *)page_address(page);
31683+#endif
31684+
31685 pud_t *pud;
31686 pmd_t *pmd;
31687
31688- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31689+ pgd += pgd_index(address);
31690 pud = pud_offset(pgd, address);
31691 pmd = pmd_offset(pud, address);
31692 set_pte_atomic((pte_t *)pmd, pte);
31693 }
31694 }
31695 #endif
31696+ pax_close_kernel();
31697 }
31698
31699 static int
31700diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31701index 6574388..87e9bef 100644
31702--- a/arch/x86/mm/pat.c
31703+++ b/arch/x86/mm/pat.c
31704@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31705
31706 if (!entry) {
31707 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31708- current->comm, current->pid, start, end - 1);
31709+ current->comm, task_pid_nr(current), start, end - 1);
31710 return -EINVAL;
31711 }
31712
31713@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31714
31715 while (cursor < to) {
31716 if (!devmem_is_allowed(pfn)) {
31717- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31718- current->comm, from, to - 1);
31719+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31720+ current->comm, from, to - 1, cursor);
31721 return 0;
31722 }
31723 cursor += PAGE_SIZE;
31724@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31725 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31726 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31727 "for [mem %#010Lx-%#010Lx]\n",
31728- current->comm, current->pid,
31729+ current->comm, task_pid_nr(current),
31730 cattr_name(flags),
31731 base, (unsigned long long)(base + size-1));
31732 return -EINVAL;
31733@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31734 flags = lookup_memtype(paddr);
31735 if (want_flags != flags) {
31736 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31737- current->comm, current->pid,
31738+ current->comm, task_pid_nr(current),
31739 cattr_name(want_flags),
31740 (unsigned long long)paddr,
31741 (unsigned long long)(paddr + size - 1),
31742@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31743 free_memtype(paddr, paddr + size);
31744 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31745 " for [mem %#010Lx-%#010Lx], got %s\n",
31746- current->comm, current->pid,
31747+ current->comm, task_pid_nr(current),
31748 cattr_name(want_flags),
31749 (unsigned long long)paddr,
31750 (unsigned long long)(paddr + size - 1),
31751diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31752index 415f6c4..d319983 100644
31753--- a/arch/x86/mm/pat_rbtree.c
31754+++ b/arch/x86/mm/pat_rbtree.c
31755@@ -160,7 +160,7 @@ success:
31756
31757 failure:
31758 printk(KERN_INFO "%s:%d conflicting memory types "
31759- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31760+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31761 end, cattr_name(found_type), cattr_name(match->type));
31762 return -EBUSY;
31763 }
31764diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31765index 9f0614d..92ae64a 100644
31766--- a/arch/x86/mm/pf_in.c
31767+++ b/arch/x86/mm/pf_in.c
31768@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31769 int i;
31770 enum reason_type rv = OTHERS;
31771
31772- p = (unsigned char *)ins_addr;
31773+ p = (unsigned char *)ktla_ktva(ins_addr);
31774 p += skip_prefix(p, &prf);
31775 p += get_opcode(p, &opcode);
31776
31777@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31778 struct prefix_bits prf;
31779 int i;
31780
31781- p = (unsigned char *)ins_addr;
31782+ p = (unsigned char *)ktla_ktva(ins_addr);
31783 p += skip_prefix(p, &prf);
31784 p += get_opcode(p, &opcode);
31785
31786@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31787 struct prefix_bits prf;
31788 int i;
31789
31790- p = (unsigned char *)ins_addr;
31791+ p = (unsigned char *)ktla_ktva(ins_addr);
31792 p += skip_prefix(p, &prf);
31793 p += get_opcode(p, &opcode);
31794
31795@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31796 struct prefix_bits prf;
31797 int i;
31798
31799- p = (unsigned char *)ins_addr;
31800+ p = (unsigned char *)ktla_ktva(ins_addr);
31801 p += skip_prefix(p, &prf);
31802 p += get_opcode(p, &opcode);
31803 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31804@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31805 struct prefix_bits prf;
31806 int i;
31807
31808- p = (unsigned char *)ins_addr;
31809+ p = (unsigned char *)ktla_ktva(ins_addr);
31810 p += skip_prefix(p, &prf);
31811 p += get_opcode(p, &opcode);
31812 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31813diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31814index dfa537a..fd45c64 100644
31815--- a/arch/x86/mm/pgtable.c
31816+++ b/arch/x86/mm/pgtable.c
31817@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31818 list_del(&page->lru);
31819 }
31820
31821-#define UNSHARED_PTRS_PER_PGD \
31822- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31823+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31824+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31825
31826+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31827+{
31828+ unsigned int count = USER_PGD_PTRS;
31829
31830+ if (!pax_user_shadow_base)
31831+ return;
31832+
31833+ while (count--)
31834+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31835+}
31836+#endif
31837+
31838+#ifdef CONFIG_PAX_PER_CPU_PGD
31839+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31840+{
31841+ unsigned int count = USER_PGD_PTRS;
31842+
31843+ while (count--) {
31844+ pgd_t pgd;
31845+
31846+#ifdef CONFIG_X86_64
31847+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31848+#else
31849+ pgd = *src++;
31850+#endif
31851+
31852+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31853+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31854+#endif
31855+
31856+ *dst++ = pgd;
31857+ }
31858+
31859+}
31860+#endif
31861+
31862+#ifdef CONFIG_X86_64
31863+#define pxd_t pud_t
31864+#define pyd_t pgd_t
31865+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31866+#define pxd_free(mm, pud) pud_free((mm), (pud))
31867+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31868+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31869+#define PYD_SIZE PGDIR_SIZE
31870+#else
31871+#define pxd_t pmd_t
31872+#define pyd_t pud_t
31873+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31874+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31875+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31876+#define pyd_offset(mm, address) pud_offset((mm), (address))
31877+#define PYD_SIZE PUD_SIZE
31878+#endif
31879+
31880+#ifdef CONFIG_PAX_PER_CPU_PGD
31881+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31882+static inline void pgd_dtor(pgd_t *pgd) {}
31883+#else
31884 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31885 {
31886 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31887@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31888 pgd_list_del(pgd);
31889 spin_unlock(&pgd_lock);
31890 }
31891+#endif
31892
31893 /*
31894 * List of all pgd's needed for non-PAE so it can invalidate entries
31895@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31896 * -- nyc
31897 */
31898
31899-#ifdef CONFIG_X86_PAE
31900+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31901 /*
31902 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31903 * updating the top-level pagetable entries to guarantee the
31904@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31905 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31906 * and initialize the kernel pmds here.
31907 */
31908-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31909+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31910
31911 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31912 {
31913@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31914 */
31915 flush_tlb_mm(mm);
31916 }
31917+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31918+#define PREALLOCATED_PXDS USER_PGD_PTRS
31919 #else /* !CONFIG_X86_PAE */
31920
31921 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31922-#define PREALLOCATED_PMDS 0
31923+#define PREALLOCATED_PXDS 0
31924
31925 #endif /* CONFIG_X86_PAE */
31926
31927-static void free_pmds(pmd_t *pmds[])
31928+static void free_pxds(pxd_t *pxds[])
31929 {
31930 int i;
31931
31932- for(i = 0; i < PREALLOCATED_PMDS; i++)
31933- if (pmds[i])
31934- free_page((unsigned long)pmds[i]);
31935+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31936+ if (pxds[i])
31937+ free_page((unsigned long)pxds[i]);
31938 }
31939
31940-static int preallocate_pmds(pmd_t *pmds[])
31941+static int preallocate_pxds(pxd_t *pxds[])
31942 {
31943 int i;
31944 bool failed = false;
31945
31946- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31947- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31948- if (pmd == NULL)
31949+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31950+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31951+ if (pxd == NULL)
31952 failed = true;
31953- pmds[i] = pmd;
31954+ pxds[i] = pxd;
31955 }
31956
31957 if (failed) {
31958- free_pmds(pmds);
31959+ free_pxds(pxds);
31960 return -ENOMEM;
31961 }
31962
31963@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31964 * preallocate which never got a corresponding vma will need to be
31965 * freed manually.
31966 */
31967-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31968+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31969 {
31970 int i;
31971
31972- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31973+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31974 pgd_t pgd = pgdp[i];
31975
31976 if (pgd_val(pgd) != 0) {
31977- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31978+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31979
31980- pgdp[i] = native_make_pgd(0);
31981+ set_pgd(pgdp + i, native_make_pgd(0));
31982
31983- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31984- pmd_free(mm, pmd);
31985+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31986+ pxd_free(mm, pxd);
31987 }
31988 }
31989 }
31990
31991-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31992+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31993 {
31994- pud_t *pud;
31995+ pyd_t *pyd;
31996 int i;
31997
31998- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31999+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32000 return;
32001
32002- pud = pud_offset(pgd, 0);
32003-
32004- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32005- pmd_t *pmd = pmds[i];
32006+#ifdef CONFIG_X86_64
32007+ pyd = pyd_offset(mm, 0L);
32008+#else
32009+ pyd = pyd_offset(pgd, 0L);
32010+#endif
32011
32012+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32013+ pxd_t *pxd = pxds[i];
32014 if (i >= KERNEL_PGD_BOUNDARY)
32015- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32016- sizeof(pmd_t) * PTRS_PER_PMD);
32017+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32018+ sizeof(pxd_t) * PTRS_PER_PMD);
32019
32020- pud_populate(mm, pud, pmd);
32021+ pyd_populate(mm, pyd, pxd);
32022 }
32023 }
32024
32025 pgd_t *pgd_alloc(struct mm_struct *mm)
32026 {
32027 pgd_t *pgd;
32028- pmd_t *pmds[PREALLOCATED_PMDS];
32029+ pxd_t *pxds[PREALLOCATED_PXDS];
32030
32031 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32032
32033@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32034
32035 mm->pgd = pgd;
32036
32037- if (preallocate_pmds(pmds) != 0)
32038+ if (preallocate_pxds(pxds) != 0)
32039 goto out_free_pgd;
32040
32041 if (paravirt_pgd_alloc(mm) != 0)
32042- goto out_free_pmds;
32043+ goto out_free_pxds;
32044
32045 /*
32046 * Make sure that pre-populating the pmds is atomic with
32047@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32048 spin_lock(&pgd_lock);
32049
32050 pgd_ctor(mm, pgd);
32051- pgd_prepopulate_pmd(mm, pgd, pmds);
32052+ pgd_prepopulate_pxd(mm, pgd, pxds);
32053
32054 spin_unlock(&pgd_lock);
32055
32056 return pgd;
32057
32058-out_free_pmds:
32059- free_pmds(pmds);
32060+out_free_pxds:
32061+ free_pxds(pxds);
32062 out_free_pgd:
32063 free_page((unsigned long)pgd);
32064 out:
32065@@ -300,7 +363,7 @@ out:
32066
32067 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32068 {
32069- pgd_mop_up_pmds(mm, pgd);
32070+ pgd_mop_up_pxds(mm, pgd);
32071 pgd_dtor(pgd);
32072 paravirt_pgd_free(mm, pgd);
32073 free_page((unsigned long)pgd);
32074diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32075index a69bcb8..19068ab 100644
32076--- a/arch/x86/mm/pgtable_32.c
32077+++ b/arch/x86/mm/pgtable_32.c
32078@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32079 return;
32080 }
32081 pte = pte_offset_kernel(pmd, vaddr);
32082+
32083+ pax_open_kernel();
32084 if (pte_val(pteval))
32085 set_pte_at(&init_mm, vaddr, pte, pteval);
32086 else
32087 pte_clear(&init_mm, vaddr, pte);
32088+ pax_close_kernel();
32089
32090 /*
32091 * It's enough to flush this one mapping.
32092diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32093index e666cbb..61788c45 100644
32094--- a/arch/x86/mm/physaddr.c
32095+++ b/arch/x86/mm/physaddr.c
32096@@ -10,7 +10,7 @@
32097 #ifdef CONFIG_X86_64
32098
32099 #ifdef CONFIG_DEBUG_VIRTUAL
32100-unsigned long __phys_addr(unsigned long x)
32101+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32102 {
32103 unsigned long y = x - __START_KERNEL_map;
32104
32105@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32106 #else
32107
32108 #ifdef CONFIG_DEBUG_VIRTUAL
32109-unsigned long __phys_addr(unsigned long x)
32110+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32111 {
32112 unsigned long phys_addr = x - PAGE_OFFSET;
32113 /* VMALLOC_* aren't constants */
32114diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32115index 90555bf..f5f1828 100644
32116--- a/arch/x86/mm/setup_nx.c
32117+++ b/arch/x86/mm/setup_nx.c
32118@@ -5,8 +5,10 @@
32119 #include <asm/pgtable.h>
32120 #include <asm/proto.h>
32121
32122+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32123 static int disable_nx;
32124
32125+#ifndef CONFIG_PAX_PAGEEXEC
32126 /*
32127 * noexec = on|off
32128 *
32129@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32130 return 0;
32131 }
32132 early_param("noexec", noexec_setup);
32133+#endif
32134+
32135+#endif
32136
32137 void x86_configure_nx(void)
32138 {
32139+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32140 if (cpu_has_nx && !disable_nx)
32141 __supported_pte_mask |= _PAGE_NX;
32142 else
32143+#endif
32144 __supported_pte_mask &= ~_PAGE_NX;
32145 }
32146
32147diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32148index 282375f..e03a98f 100644
32149--- a/arch/x86/mm/tlb.c
32150+++ b/arch/x86/mm/tlb.c
32151@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32152 BUG();
32153 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32154 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32155+
32156+#ifndef CONFIG_PAX_PER_CPU_PGD
32157 load_cr3(swapper_pg_dir);
32158+#endif
32159+
32160 }
32161 }
32162 EXPORT_SYMBOL_GPL(leave_mm);
32163diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32164new file mode 100644
32165index 0000000..dace51c
32166--- /dev/null
32167+++ b/arch/x86/mm/uderef_64.c
32168@@ -0,0 +1,37 @@
32169+#include <linux/mm.h>
32170+#include <asm/pgtable.h>
32171+#include <asm/uaccess.h>
32172+
32173+#ifdef CONFIG_PAX_MEMORY_UDEREF
32174+/* PaX: due to the special call convention these functions must
32175+ * - remain leaf functions under all configurations,
32176+ * - never be called directly, only dereferenced from the wrappers.
32177+ */
32178+void __pax_open_userland(void)
32179+{
32180+ unsigned int cpu;
32181+
32182+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32183+ return;
32184+
32185+ cpu = raw_get_cpu();
32186+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32187+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32188+ raw_put_cpu_no_resched();
32189+}
32190+EXPORT_SYMBOL(__pax_open_userland);
32191+
32192+void __pax_close_userland(void)
32193+{
32194+ unsigned int cpu;
32195+
32196+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32197+ return;
32198+
32199+ cpu = raw_get_cpu();
32200+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32201+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32202+ raw_put_cpu_no_resched();
32203+}
32204+EXPORT_SYMBOL(__pax_close_userland);
32205+#endif
32206diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32207index 877b9a1..a8ecf42 100644
32208--- a/arch/x86/net/bpf_jit.S
32209+++ b/arch/x86/net/bpf_jit.S
32210@@ -9,6 +9,7 @@
32211 */
32212 #include <linux/linkage.h>
32213 #include <asm/dwarf2.h>
32214+#include <asm/alternative-asm.h>
32215
32216 /*
32217 * Calling convention :
32218@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32219 jle bpf_slow_path_word
32220 mov (SKBDATA,%rsi),%eax
32221 bswap %eax /* ntohl() */
32222+ pax_force_retaddr
32223 ret
32224
32225 sk_load_half:
32226@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32227 jle bpf_slow_path_half
32228 movzwl (SKBDATA,%rsi),%eax
32229 rol $8,%ax # ntohs()
32230+ pax_force_retaddr
32231 ret
32232
32233 sk_load_byte:
32234@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32235 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32236 jle bpf_slow_path_byte
32237 movzbl (SKBDATA,%rsi),%eax
32238+ pax_force_retaddr
32239 ret
32240
32241 /**
32242@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32243 movzbl (SKBDATA,%rsi),%ebx
32244 and $15,%bl
32245 shl $2,%bl
32246+ pax_force_retaddr
32247 ret
32248
32249 /* rsi contains offset and can be scratched */
32250@@ -109,6 +114,7 @@ bpf_slow_path_word:
32251 js bpf_error
32252 mov -12(%rbp),%eax
32253 bswap %eax
32254+ pax_force_retaddr
32255 ret
32256
32257 bpf_slow_path_half:
32258@@ -117,12 +123,14 @@ bpf_slow_path_half:
32259 mov -12(%rbp),%ax
32260 rol $8,%ax
32261 movzwl %ax,%eax
32262+ pax_force_retaddr
32263 ret
32264
32265 bpf_slow_path_byte:
32266 bpf_slow_path_common(1)
32267 js bpf_error
32268 movzbl -12(%rbp),%eax
32269+ pax_force_retaddr
32270 ret
32271
32272 bpf_slow_path_byte_msh:
32273@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32274 and $15,%al
32275 shl $2,%al
32276 xchg %eax,%ebx
32277+ pax_force_retaddr
32278 ret
32279
32280 #define sk_negative_common(SIZE) \
32281@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32282 sk_negative_common(4)
32283 mov (%rax), %eax
32284 bswap %eax
32285+ pax_force_retaddr
32286 ret
32287
32288 bpf_slow_path_half_neg:
32289@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32290 mov (%rax),%ax
32291 rol $8,%ax
32292 movzwl %ax,%eax
32293+ pax_force_retaddr
32294 ret
32295
32296 bpf_slow_path_byte_neg:
32297@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32298 .globl sk_load_byte_negative_offset
32299 sk_negative_common(1)
32300 movzbl (%rax), %eax
32301+ pax_force_retaddr
32302 ret
32303
32304 bpf_slow_path_byte_msh_neg:
32305@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32306 and $15,%al
32307 shl $2,%al
32308 xchg %eax,%ebx
32309+ pax_force_retaddr
32310 ret
32311
32312 bpf_error:
32313@@ -197,4 +210,5 @@ bpf_error:
32314 xor %eax,%eax
32315 mov -8(%rbp),%rbx
32316 leaveq
32317+ pax_force_retaddr
32318 ret
32319diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32320index 79c216a..08d39cc 100644
32321--- a/arch/x86/net/bpf_jit_comp.c
32322+++ b/arch/x86/net/bpf_jit_comp.c
32323@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32324 return ptr + len;
32325 }
32326
32327+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32328+#define MAX_INSTR_CODE_SIZE 96
32329+#else
32330+#define MAX_INSTR_CODE_SIZE 64
32331+#endif
32332+
32333 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32334
32335 #define EMIT1(b1) EMIT(b1, 1)
32336 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32337 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32338 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32339+
32340+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32341+/* original constant will appear in ecx */
32342+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32343+do { \
32344+ /* mov ecx, randkey */ \
32345+ EMIT1(0xb9); \
32346+ EMIT(_key, 4); \
32347+ /* xor ecx, randkey ^ off */ \
32348+ EMIT2(0x81, 0xf1); \
32349+ EMIT((_key) ^ (_off), 4); \
32350+} while (0)
32351+
32352+#define EMIT1_off32(b1, _off) \
32353+do { \
32354+ switch (b1) { \
32355+ case 0x05: /* add eax, imm32 */ \
32356+ case 0x2d: /* sub eax, imm32 */ \
32357+ case 0x25: /* and eax, imm32 */ \
32358+ case 0x0d: /* or eax, imm32 */ \
32359+ case 0xb8: /* mov eax, imm32 */ \
32360+ case 0x35: /* xor eax, imm32 */ \
32361+ case 0x3d: /* cmp eax, imm32 */ \
32362+ case 0xa9: /* test eax, imm32 */ \
32363+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32364+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32365+ break; \
32366+ case 0xbb: /* mov ebx, imm32 */ \
32367+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32368+ /* mov ebx, ecx */ \
32369+ EMIT2(0x89, 0xcb); \
32370+ break; \
32371+ case 0xbe: /* mov esi, imm32 */ \
32372+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32373+ /* mov esi, ecx */ \
32374+ EMIT2(0x89, 0xce); \
32375+ break; \
32376+ case 0xe8: /* call rel imm32, always to known funcs */ \
32377+ EMIT1(b1); \
32378+ EMIT(_off, 4); \
32379+ break; \
32380+ case 0xe9: /* jmp rel imm32 */ \
32381+ EMIT1(b1); \
32382+ EMIT(_off, 4); \
32383+ /* prevent fall-through, we're not called if off = 0 */ \
32384+ EMIT(0xcccccccc, 4); \
32385+ EMIT(0xcccccccc, 4); \
32386+ break; \
32387+ default: \
32388+ BUILD_BUG(); \
32389+ } \
32390+} while (0)
32391+
32392+#define EMIT2_off32(b1, b2, _off) \
32393+do { \
32394+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32395+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32396+ EMIT(randkey, 4); \
32397+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32398+ EMIT((_off) - randkey, 4); \
32399+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32400+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32401+ /* imul eax, ecx */ \
32402+ EMIT3(0x0f, 0xaf, 0xc1); \
32403+ } else { \
32404+ BUILD_BUG(); \
32405+ } \
32406+} while (0)
32407+#else
32408 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32409+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32410+#endif
32411
32412 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32413 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32414@@ -91,6 +168,24 @@ do { \
32415 #define X86_JBE 0x76
32416 #define X86_JA 0x77
32417
32418+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32419+#define APPEND_FLOW_VERIFY() \
32420+do { \
32421+ /* mov ecx, randkey */ \
32422+ EMIT1(0xb9); \
32423+ EMIT(randkey, 4); \
32424+ /* cmp ecx, randkey */ \
32425+ EMIT2(0x81, 0xf9); \
32426+ EMIT(randkey, 4); \
32427+ /* jz after 8 int 3s */ \
32428+ EMIT2(0x74, 0x08); \
32429+ EMIT(0xcccccccc, 4); \
32430+ EMIT(0xcccccccc, 4); \
32431+} while (0)
32432+#else
32433+#define APPEND_FLOW_VERIFY() do { } while (0)
32434+#endif
32435+
32436 #define EMIT_COND_JMP(op, offset) \
32437 do { \
32438 if (is_near(offset)) \
32439@@ -98,6 +193,7 @@ do { \
32440 else { \
32441 EMIT2(0x0f, op + 0x10); \
32442 EMIT(offset, 4); /* jxx .+off32 */ \
32443+ APPEND_FLOW_VERIFY(); \
32444 } \
32445 } while (0)
32446
32447@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32448 return -1;
32449 }
32450
32451-struct bpf_binary_header {
32452- unsigned int pages;
32453- /* Note : for security reasons, bpf code will follow a randomly
32454- * sized amount of int3 instructions
32455- */
32456- u8 image[];
32457-};
32458-
32459-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32460+/* Note : for security reasons, bpf code will follow a randomly
32461+ * sized amount of int3 instructions
32462+ */
32463+static u8 *bpf_alloc_binary(unsigned int proglen,
32464 u8 **image_ptr)
32465 {
32466 unsigned int sz, hole;
32467- struct bpf_binary_header *header;
32468+ u8 *header;
32469
32470 /* Most of BPF filters are really small,
32471 * but if some of them fill a page, allow at least
32472 * 128 extra bytes to insert a random section of int3
32473 */
32474- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32475- header = module_alloc(sz);
32476+ sz = round_up(proglen + 128, PAGE_SIZE);
32477+ header = module_alloc_exec(sz);
32478 if (!header)
32479 return NULL;
32480
32481+ pax_open_kernel();
32482 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32483+ pax_close_kernel();
32484
32485- header->pages = sz / PAGE_SIZE;
32486- hole = sz - (proglen + sizeof(*header));
32487+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32488
32489 /* insert a random number of int3 instructions before BPF code */
32490- *image_ptr = &header->image[prandom_u32() % hole];
32491+ *image_ptr = &header[prandom_u32() % hole];
32492 return header;
32493 }
32494
32495 void bpf_jit_compile(struct sk_filter *fp)
32496 {
32497- u8 temp[64];
32498+ u8 temp[MAX_INSTR_CODE_SIZE];
32499 u8 *prog;
32500 unsigned int proglen, oldproglen = 0;
32501 int ilen, i;
32502 int t_offset, f_offset;
32503 u8 t_op, f_op, seen = 0, pass;
32504 u8 *image = NULL;
32505- struct bpf_binary_header *header = NULL;
32506+ u8 *header = NULL;
32507 u8 *func;
32508 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32509 unsigned int cleanup_addr; /* epilogue code offset */
32510 unsigned int *addrs;
32511 const struct sock_filter *filter = fp->insns;
32512 int flen = fp->len;
32513+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32514+ unsigned int randkey;
32515+#endif
32516
32517 if (!bpf_jit_enable)
32518 return;
32519@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32520 if (addrs == NULL)
32521 return;
32522
32523+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32524+ randkey = get_random_int();
32525+#endif
32526+
32527 /* Before first pass, make a rough estimation of addrs[]
32528- * each bpf instruction is translated to less than 64 bytes
32529+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32530 */
32531 for (proglen = 0, i = 0; i < flen; i++) {
32532- proglen += 64;
32533+ proglen += MAX_INSTR_CODE_SIZE;
32534 addrs[i] = proglen;
32535 }
32536 cleanup_addr = proglen; /* epilogue address */
32537@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32538 case BPF_S_ALU_MUL_K: /* A *= K */
32539 if (is_imm8(K))
32540 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32541- else {
32542- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32543- EMIT(K, 4);
32544- }
32545+ else
32546+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32547 break;
32548 case BPF_S_ALU_DIV_X: /* A /= X; */
32549 seen |= SEEN_XREG;
32550@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32551 break;
32552 case BPF_S_ALU_MOD_K: /* A %= K; */
32553 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32554+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32555+ DILUTE_CONST_SEQUENCE(K, randkey);
32556+#else
32557 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32558+#endif
32559 EMIT2(0xf7, 0xf1); /* div %ecx */
32560 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32561 break;
32562 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32563+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32564+ DILUTE_CONST_SEQUENCE(K, randkey);
32565+ // imul rax, rcx
32566+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32567+#else
32568 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32569 EMIT(K, 4);
32570+#endif
32571 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32572 break;
32573 case BPF_S_ALU_AND_X:
32574@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32575 if (is_imm8(K)) {
32576 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32577 } else {
32578- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32579- EMIT(K, 4);
32580+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32581 }
32582 } else {
32583 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32584@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32585 if (unlikely(proglen + ilen > oldproglen)) {
32586 pr_err("bpb_jit_compile fatal error\n");
32587 kfree(addrs);
32588- module_free(NULL, header);
32589+ module_free_exec(NULL, image);
32590 return;
32591 }
32592+ pax_open_kernel();
32593 memcpy(image + proglen, temp, ilen);
32594+ pax_close_kernel();
32595 }
32596 proglen += ilen;
32597 addrs[i] = proglen;
32598@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32599
32600 if (image) {
32601 bpf_flush_icache(header, image + proglen);
32602- set_memory_ro((unsigned long)header, header->pages);
32603 fp->bpf_func = (void *)image;
32604 }
32605 out:
32606@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32607 {
32608 if (fp->bpf_func != sk_run_filter) {
32609 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32610- struct bpf_binary_header *header = (void *)addr;
32611-
32612- set_memory_rw(addr, header->pages);
32613- module_free(NULL, header);
32614+ set_memory_rw(addr, 1);
32615+ module_free_exec(NULL, (void *)addr);
32616 }
32617 }
32618diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32619index d6aa6e8..266395a 100644
32620--- a/arch/x86/oprofile/backtrace.c
32621+++ b/arch/x86/oprofile/backtrace.c
32622@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32623 struct stack_frame_ia32 *fp;
32624 unsigned long bytes;
32625
32626- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32627+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32628 if (bytes != sizeof(bufhead))
32629 return NULL;
32630
32631- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32632+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32633
32634 oprofile_add_trace(bufhead[0].return_address);
32635
32636@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32637 struct stack_frame bufhead[2];
32638 unsigned long bytes;
32639
32640- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32641+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32642 if (bytes != sizeof(bufhead))
32643 return NULL;
32644
32645@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32646 {
32647 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32648
32649- if (!user_mode_vm(regs)) {
32650+ if (!user_mode(regs)) {
32651 unsigned long stack = kernel_stack_pointer(regs);
32652 if (depth)
32653 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32654diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32655index 48768df..ba9143c 100644
32656--- a/arch/x86/oprofile/nmi_int.c
32657+++ b/arch/x86/oprofile/nmi_int.c
32658@@ -23,6 +23,7 @@
32659 #include <asm/nmi.h>
32660 #include <asm/msr.h>
32661 #include <asm/apic.h>
32662+#include <asm/pgtable.h>
32663
32664 #include "op_counter.h"
32665 #include "op_x86_model.h"
32666@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32667 if (ret)
32668 return ret;
32669
32670- if (!model->num_virt_counters)
32671- model->num_virt_counters = model->num_counters;
32672+ if (!model->num_virt_counters) {
32673+ pax_open_kernel();
32674+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32675+ pax_close_kernel();
32676+ }
32677
32678 mux_init(ops);
32679
32680diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32681index b2b9443..be58856 100644
32682--- a/arch/x86/oprofile/op_model_amd.c
32683+++ b/arch/x86/oprofile/op_model_amd.c
32684@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32685 num_counters = AMD64_NUM_COUNTERS;
32686 }
32687
32688- op_amd_spec.num_counters = num_counters;
32689- op_amd_spec.num_controls = num_counters;
32690- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32691+ pax_open_kernel();
32692+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32693+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32694+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32695+ pax_close_kernel();
32696
32697 return 0;
32698 }
32699diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32700index d90528e..0127e2b 100644
32701--- a/arch/x86/oprofile/op_model_ppro.c
32702+++ b/arch/x86/oprofile/op_model_ppro.c
32703@@ -19,6 +19,7 @@
32704 #include <asm/msr.h>
32705 #include <asm/apic.h>
32706 #include <asm/nmi.h>
32707+#include <asm/pgtable.h>
32708
32709 #include "op_x86_model.h"
32710 #include "op_counter.h"
32711@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32712
32713 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32714
32715- op_arch_perfmon_spec.num_counters = num_counters;
32716- op_arch_perfmon_spec.num_controls = num_counters;
32717+ pax_open_kernel();
32718+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32719+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32720+ pax_close_kernel();
32721 }
32722
32723 static int arch_perfmon_init(struct oprofile_operations *ignore)
32724diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32725index 71e8a67..6a313bb 100644
32726--- a/arch/x86/oprofile/op_x86_model.h
32727+++ b/arch/x86/oprofile/op_x86_model.h
32728@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32729 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32730 struct op_msrs const * const msrs);
32731 #endif
32732-};
32733+} __do_const;
32734
32735 struct op_counter_config;
32736
32737diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32738index 372e9b8..e775a6c 100644
32739--- a/arch/x86/pci/irq.c
32740+++ b/arch/x86/pci/irq.c
32741@@ -50,7 +50,7 @@ struct irq_router {
32742 struct irq_router_handler {
32743 u16 vendor;
32744 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32745-};
32746+} __do_const;
32747
32748 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32749 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32750@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32751 return 0;
32752 }
32753
32754-static __initdata struct irq_router_handler pirq_routers[] = {
32755+static __initconst const struct irq_router_handler pirq_routers[] = {
32756 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32757 { PCI_VENDOR_ID_AL, ali_router_probe },
32758 { PCI_VENDOR_ID_ITE, ite_router_probe },
32759@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32760 static void __init pirq_find_router(struct irq_router *r)
32761 {
32762 struct irq_routing_table *rt = pirq_table;
32763- struct irq_router_handler *h;
32764+ const struct irq_router_handler *h;
32765
32766 #ifdef CONFIG_PCI_BIOS
32767 if (!rt->signature) {
32768@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32769 return 0;
32770 }
32771
32772-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32773+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32774 {
32775 .callback = fix_broken_hp_bios_irq9,
32776 .ident = "HP Pavilion N5400 Series Laptop",
32777diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32778index 6eb18c4..20d83de 100644
32779--- a/arch/x86/pci/mrst.c
32780+++ b/arch/x86/pci/mrst.c
32781@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32782 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32783 pci_mmcfg_late_init();
32784 pcibios_enable_irq = mrst_pci_irq_enable;
32785- pci_root_ops = pci_mrst_ops;
32786+ pax_open_kernel();
32787+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32788+ pax_close_kernel();
32789 pci_soc_mode = 1;
32790 /* Continue with standard init */
32791 return 1;
32792diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32793index c77b24a..c979855 100644
32794--- a/arch/x86/pci/pcbios.c
32795+++ b/arch/x86/pci/pcbios.c
32796@@ -79,7 +79,7 @@ union bios32 {
32797 static struct {
32798 unsigned long address;
32799 unsigned short segment;
32800-} bios32_indirect = { 0, __KERNEL_CS };
32801+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32802
32803 /*
32804 * Returns the entry point for the given service, NULL on error
32805@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32806 unsigned long length; /* %ecx */
32807 unsigned long entry; /* %edx */
32808 unsigned long flags;
32809+ struct desc_struct d, *gdt;
32810
32811 local_irq_save(flags);
32812- __asm__("lcall *(%%edi); cld"
32813+
32814+ gdt = get_cpu_gdt_table(smp_processor_id());
32815+
32816+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32817+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32818+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32819+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32820+
32821+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32822 : "=a" (return_code),
32823 "=b" (address),
32824 "=c" (length),
32825 "=d" (entry)
32826 : "0" (service),
32827 "1" (0),
32828- "D" (&bios32_indirect));
32829+ "D" (&bios32_indirect),
32830+ "r"(__PCIBIOS_DS)
32831+ : "memory");
32832+
32833+ pax_open_kernel();
32834+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32835+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32836+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32837+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32838+ pax_close_kernel();
32839+
32840 local_irq_restore(flags);
32841
32842 switch (return_code) {
32843- case 0:
32844- return address + entry;
32845- case 0x80: /* Not present */
32846- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32847- return 0;
32848- default: /* Shouldn't happen */
32849- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32850- service, return_code);
32851+ case 0: {
32852+ int cpu;
32853+ unsigned char flags;
32854+
32855+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32856+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32857+ printk(KERN_WARNING "bios32_service: not valid\n");
32858 return 0;
32859+ }
32860+ address = address + PAGE_OFFSET;
32861+ length += 16UL; /* some BIOSs underreport this... */
32862+ flags = 4;
32863+ if (length >= 64*1024*1024) {
32864+ length >>= PAGE_SHIFT;
32865+ flags |= 8;
32866+ }
32867+
32868+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32869+ gdt = get_cpu_gdt_table(cpu);
32870+ pack_descriptor(&d, address, length, 0x9b, flags);
32871+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32872+ pack_descriptor(&d, address, length, 0x93, flags);
32873+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32874+ }
32875+ return entry;
32876+ }
32877+ case 0x80: /* Not present */
32878+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32879+ return 0;
32880+ default: /* Shouldn't happen */
32881+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32882+ service, return_code);
32883+ return 0;
32884 }
32885 }
32886
32887 static struct {
32888 unsigned long address;
32889 unsigned short segment;
32890-} pci_indirect = { 0, __KERNEL_CS };
32891+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32892
32893-static int pci_bios_present;
32894+static int pci_bios_present __read_only;
32895
32896 static int check_pcibios(void)
32897 {
32898@@ -131,11 +174,13 @@ static int check_pcibios(void)
32899 unsigned long flags, pcibios_entry;
32900
32901 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32902- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32903+ pci_indirect.address = pcibios_entry;
32904
32905 local_irq_save(flags);
32906- __asm__(
32907- "lcall *(%%edi); cld\n\t"
32908+ __asm__("movw %w6, %%ds\n\t"
32909+ "lcall *%%ss:(%%edi); cld\n\t"
32910+ "push %%ss\n\t"
32911+ "pop %%ds\n\t"
32912 "jc 1f\n\t"
32913 "xor %%ah, %%ah\n"
32914 "1:"
32915@@ -144,7 +189,8 @@ static int check_pcibios(void)
32916 "=b" (ebx),
32917 "=c" (ecx)
32918 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32919- "D" (&pci_indirect)
32920+ "D" (&pci_indirect),
32921+ "r" (__PCIBIOS_DS)
32922 : "memory");
32923 local_irq_restore(flags);
32924
32925@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32926
32927 switch (len) {
32928 case 1:
32929- __asm__("lcall *(%%esi); cld\n\t"
32930+ __asm__("movw %w6, %%ds\n\t"
32931+ "lcall *%%ss:(%%esi); cld\n\t"
32932+ "push %%ss\n\t"
32933+ "pop %%ds\n\t"
32934 "jc 1f\n\t"
32935 "xor %%ah, %%ah\n"
32936 "1:"
32937@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32938 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32939 "b" (bx),
32940 "D" ((long)reg),
32941- "S" (&pci_indirect));
32942+ "S" (&pci_indirect),
32943+ "r" (__PCIBIOS_DS));
32944 /*
32945 * Zero-extend the result beyond 8 bits, do not trust the
32946 * BIOS having done it:
32947@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32948 *value &= 0xff;
32949 break;
32950 case 2:
32951- __asm__("lcall *(%%esi); cld\n\t"
32952+ __asm__("movw %w6, %%ds\n\t"
32953+ "lcall *%%ss:(%%esi); cld\n\t"
32954+ "push %%ss\n\t"
32955+ "pop %%ds\n\t"
32956 "jc 1f\n\t"
32957 "xor %%ah, %%ah\n"
32958 "1:"
32959@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32960 : "1" (PCIBIOS_READ_CONFIG_WORD),
32961 "b" (bx),
32962 "D" ((long)reg),
32963- "S" (&pci_indirect));
32964+ "S" (&pci_indirect),
32965+ "r" (__PCIBIOS_DS));
32966 /*
32967 * Zero-extend the result beyond 16 bits, do not trust the
32968 * BIOS having done it:
32969@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32970 *value &= 0xffff;
32971 break;
32972 case 4:
32973- __asm__("lcall *(%%esi); cld\n\t"
32974+ __asm__("movw %w6, %%ds\n\t"
32975+ "lcall *%%ss:(%%esi); cld\n\t"
32976+ "push %%ss\n\t"
32977+ "pop %%ds\n\t"
32978 "jc 1f\n\t"
32979 "xor %%ah, %%ah\n"
32980 "1:"
32981@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32982 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32983 "b" (bx),
32984 "D" ((long)reg),
32985- "S" (&pci_indirect));
32986+ "S" (&pci_indirect),
32987+ "r" (__PCIBIOS_DS));
32988 break;
32989 }
32990
32991@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32992
32993 switch (len) {
32994 case 1:
32995- __asm__("lcall *(%%esi); cld\n\t"
32996+ __asm__("movw %w6, %%ds\n\t"
32997+ "lcall *%%ss:(%%esi); cld\n\t"
32998+ "push %%ss\n\t"
32999+ "pop %%ds\n\t"
33000 "jc 1f\n\t"
33001 "xor %%ah, %%ah\n"
33002 "1:"
33003@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33004 "c" (value),
33005 "b" (bx),
33006 "D" ((long)reg),
33007- "S" (&pci_indirect));
33008+ "S" (&pci_indirect),
33009+ "r" (__PCIBIOS_DS));
33010 break;
33011 case 2:
33012- __asm__("lcall *(%%esi); cld\n\t"
33013+ __asm__("movw %w6, %%ds\n\t"
33014+ "lcall *%%ss:(%%esi); cld\n\t"
33015+ "push %%ss\n\t"
33016+ "pop %%ds\n\t"
33017 "jc 1f\n\t"
33018 "xor %%ah, %%ah\n"
33019 "1:"
33020@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33021 "c" (value),
33022 "b" (bx),
33023 "D" ((long)reg),
33024- "S" (&pci_indirect));
33025+ "S" (&pci_indirect),
33026+ "r" (__PCIBIOS_DS));
33027 break;
33028 case 4:
33029- __asm__("lcall *(%%esi); cld\n\t"
33030+ __asm__("movw %w6, %%ds\n\t"
33031+ "lcall *%%ss:(%%esi); cld\n\t"
33032+ "push %%ss\n\t"
33033+ "pop %%ds\n\t"
33034 "jc 1f\n\t"
33035 "xor %%ah, %%ah\n"
33036 "1:"
33037@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33038 "c" (value),
33039 "b" (bx),
33040 "D" ((long)reg),
33041- "S" (&pci_indirect));
33042+ "S" (&pci_indirect),
33043+ "r" (__PCIBIOS_DS));
33044 break;
33045 }
33046
33047@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33048
33049 DBG("PCI: Fetching IRQ routing table... ");
33050 __asm__("push %%es\n\t"
33051+ "movw %w8, %%ds\n\t"
33052 "push %%ds\n\t"
33053 "pop %%es\n\t"
33054- "lcall *(%%esi); cld\n\t"
33055+ "lcall *%%ss:(%%esi); cld\n\t"
33056 "pop %%es\n\t"
33057+ "push %%ss\n\t"
33058+ "pop %%ds\n"
33059 "jc 1f\n\t"
33060 "xor %%ah, %%ah\n"
33061 "1:"
33062@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33063 "1" (0),
33064 "D" ((long) &opt),
33065 "S" (&pci_indirect),
33066- "m" (opt)
33067+ "m" (opt),
33068+ "r" (__PCIBIOS_DS)
33069 : "memory");
33070 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33071 if (ret & 0xff00)
33072@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33073 {
33074 int ret;
33075
33076- __asm__("lcall *(%%esi); cld\n\t"
33077+ __asm__("movw %w5, %%ds\n\t"
33078+ "lcall *%%ss:(%%esi); cld\n\t"
33079+ "push %%ss\n\t"
33080+ "pop %%ds\n"
33081 "jc 1f\n\t"
33082 "xor %%ah, %%ah\n"
33083 "1:"
33084@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33085 : "0" (PCIBIOS_SET_PCI_HW_INT),
33086 "b" ((dev->bus->number << 8) | dev->devfn),
33087 "c" ((irq << 8) | (pin + 10)),
33088- "S" (&pci_indirect));
33089+ "S" (&pci_indirect),
33090+ "r" (__PCIBIOS_DS));
33091 return !(ret & 0xff00);
33092 }
33093 EXPORT_SYMBOL(pcibios_set_irq_routing);
33094diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33095index 40e4469..d915bf9 100644
33096--- a/arch/x86/platform/efi/efi_32.c
33097+++ b/arch/x86/platform/efi/efi_32.c
33098@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33099 {
33100 struct desc_ptr gdt_descr;
33101
33102+#ifdef CONFIG_PAX_KERNEXEC
33103+ struct desc_struct d;
33104+#endif
33105+
33106 local_irq_save(efi_rt_eflags);
33107
33108 load_cr3(initial_page_table);
33109 __flush_tlb_all();
33110
33111+#ifdef CONFIG_PAX_KERNEXEC
33112+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33113+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33114+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33115+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33116+#endif
33117+
33118 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33119 gdt_descr.size = GDT_SIZE - 1;
33120 load_gdt(&gdt_descr);
33121@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33122 {
33123 struct desc_ptr gdt_descr;
33124
33125+#ifdef CONFIG_PAX_KERNEXEC
33126+ struct desc_struct d;
33127+
33128+ memset(&d, 0, sizeof d);
33129+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33130+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33131+#endif
33132+
33133 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33134 gdt_descr.size = GDT_SIZE - 1;
33135 load_gdt(&gdt_descr);
33136
33137+#ifdef CONFIG_PAX_PER_CPU_PGD
33138+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33139+#else
33140 load_cr3(swapper_pg_dir);
33141+#endif
33142+
33143 __flush_tlb_all();
33144
33145 local_irq_restore(efi_rt_eflags);
33146diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33147index 39a0e7f1..872396e 100644
33148--- a/arch/x86/platform/efi/efi_64.c
33149+++ b/arch/x86/platform/efi/efi_64.c
33150@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33151 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33152 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33153 }
33154+
33155+#ifdef CONFIG_PAX_PER_CPU_PGD
33156+ load_cr3(swapper_pg_dir);
33157+#endif
33158+
33159 __flush_tlb_all();
33160 }
33161
33162@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33163 for (pgd = 0; pgd < n_pgds; pgd++)
33164 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33165 kfree(save_pgd);
33166+
33167+#ifdef CONFIG_PAX_PER_CPU_PGD
33168+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33169+#endif
33170+
33171 __flush_tlb_all();
33172 local_irq_restore(efi_flags);
33173 early_code_mapping_set_exec(0);
33174diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33175index fbe66e6..eae5e38 100644
33176--- a/arch/x86/platform/efi/efi_stub_32.S
33177+++ b/arch/x86/platform/efi/efi_stub_32.S
33178@@ -6,7 +6,9 @@
33179 */
33180
33181 #include <linux/linkage.h>
33182+#include <linux/init.h>
33183 #include <asm/page_types.h>
33184+#include <asm/segment.h>
33185
33186 /*
33187 * efi_call_phys(void *, ...) is a function with variable parameters.
33188@@ -20,7 +22,7 @@
33189 * service functions will comply with gcc calling convention, too.
33190 */
33191
33192-.text
33193+__INIT
33194 ENTRY(efi_call_phys)
33195 /*
33196 * 0. The function can only be called in Linux kernel. So CS has been
33197@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33198 * The mapping of lower virtual memory has been created in prelog and
33199 * epilog.
33200 */
33201- movl $1f, %edx
33202- subl $__PAGE_OFFSET, %edx
33203- jmp *%edx
33204+#ifdef CONFIG_PAX_KERNEXEC
33205+ movl $(__KERNEXEC_EFI_DS), %edx
33206+ mov %edx, %ds
33207+ mov %edx, %es
33208+ mov %edx, %ss
33209+ addl $2f,(1f)
33210+ ljmp *(1f)
33211+
33212+__INITDATA
33213+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33214+.previous
33215+
33216+2:
33217+ subl $2b,(1b)
33218+#else
33219+ jmp 1f-__PAGE_OFFSET
33220 1:
33221+#endif
33222
33223 /*
33224 * 2. Now on the top of stack is the return
33225@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33226 * parameter 2, ..., param n. To make things easy, we save the return
33227 * address of efi_call_phys in a global variable.
33228 */
33229- popl %edx
33230- movl %edx, saved_return_addr
33231- /* get the function pointer into ECX*/
33232- popl %ecx
33233- movl %ecx, efi_rt_function_ptr
33234- movl $2f, %edx
33235- subl $__PAGE_OFFSET, %edx
33236- pushl %edx
33237+ popl (saved_return_addr)
33238+ popl (efi_rt_function_ptr)
33239
33240 /*
33241 * 3. Clear PG bit in %CR0.
33242@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33243 /*
33244 * 5. Call the physical function.
33245 */
33246- jmp *%ecx
33247+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33248
33249-2:
33250 /*
33251 * 6. After EFI runtime service returns, control will return to
33252 * following instruction. We'd better readjust stack pointer first.
33253@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33254 movl %cr0, %edx
33255 orl $0x80000000, %edx
33256 movl %edx, %cr0
33257- jmp 1f
33258-1:
33259+
33260 /*
33261 * 8. Now restore the virtual mode from flat mode by
33262 * adding EIP with PAGE_OFFSET.
33263 */
33264- movl $1f, %edx
33265- jmp *%edx
33266+#ifdef CONFIG_PAX_KERNEXEC
33267+ movl $(__KERNEL_DS), %edx
33268+ mov %edx, %ds
33269+ mov %edx, %es
33270+ mov %edx, %ss
33271+ ljmp $(__KERNEL_CS),$1f
33272+#else
33273+ jmp 1f+__PAGE_OFFSET
33274+#endif
33275 1:
33276
33277 /*
33278 * 9. Balance the stack. And because EAX contain the return value,
33279 * we'd better not clobber it.
33280 */
33281- leal efi_rt_function_ptr, %edx
33282- movl (%edx), %ecx
33283- pushl %ecx
33284+ pushl (efi_rt_function_ptr)
33285
33286 /*
33287- * 10. Push the saved return address onto the stack and return.
33288+ * 10. Return to the saved return address.
33289 */
33290- leal saved_return_addr, %edx
33291- movl (%edx), %ecx
33292- pushl %ecx
33293- ret
33294+ jmpl *(saved_return_addr)
33295 ENDPROC(efi_call_phys)
33296 .previous
33297
33298-.data
33299+__INITDATA
33300 saved_return_addr:
33301 .long 0
33302 efi_rt_function_ptr:
33303diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33304index 4c07cca..2c8427d 100644
33305--- a/arch/x86/platform/efi/efi_stub_64.S
33306+++ b/arch/x86/platform/efi/efi_stub_64.S
33307@@ -7,6 +7,7 @@
33308 */
33309
33310 #include <linux/linkage.h>
33311+#include <asm/alternative-asm.h>
33312
33313 #define SAVE_XMM \
33314 mov %rsp, %rax; \
33315@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33316 call *%rdi
33317 addq $32, %rsp
33318 RESTORE_XMM
33319+ pax_force_retaddr 0, 1
33320 ret
33321 ENDPROC(efi_call0)
33322
33323@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33324 call *%rdi
33325 addq $32, %rsp
33326 RESTORE_XMM
33327+ pax_force_retaddr 0, 1
33328 ret
33329 ENDPROC(efi_call1)
33330
33331@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33332 call *%rdi
33333 addq $32, %rsp
33334 RESTORE_XMM
33335+ pax_force_retaddr 0, 1
33336 ret
33337 ENDPROC(efi_call2)
33338
33339@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33340 call *%rdi
33341 addq $32, %rsp
33342 RESTORE_XMM
33343+ pax_force_retaddr 0, 1
33344 ret
33345 ENDPROC(efi_call3)
33346
33347@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33348 call *%rdi
33349 addq $32, %rsp
33350 RESTORE_XMM
33351+ pax_force_retaddr 0, 1
33352 ret
33353 ENDPROC(efi_call4)
33354
33355@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33356 call *%rdi
33357 addq $48, %rsp
33358 RESTORE_XMM
33359+ pax_force_retaddr 0, 1
33360 ret
33361 ENDPROC(efi_call5)
33362
33363@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33364 call *%rdi
33365 addq $48, %rsp
33366 RESTORE_XMM
33367+ pax_force_retaddr 0, 1
33368 ret
33369 ENDPROC(efi_call6)
33370diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33371index 47fe66f..6206449 100644
33372--- a/arch/x86/platform/mrst/mrst.c
33373+++ b/arch/x86/platform/mrst/mrst.c
33374@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33375 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33376 int sfi_mrtc_num;
33377
33378-static void mrst_power_off(void)
33379+static __noreturn void mrst_power_off(void)
33380 {
33381+ BUG();
33382 }
33383
33384-static void mrst_reboot(void)
33385+static __noreturn void mrst_reboot(void)
33386 {
33387 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33388+ BUG();
33389 }
33390
33391 /* parse all the mtimer info to a static mtimer array */
33392diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33393index d6ee929..3637cb5 100644
33394--- a/arch/x86/platform/olpc/olpc_dt.c
33395+++ b/arch/x86/platform/olpc/olpc_dt.c
33396@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33397 return res;
33398 }
33399
33400-static struct of_pdt_ops prom_olpc_ops __initdata = {
33401+static struct of_pdt_ops prom_olpc_ops __initconst = {
33402 .nextprop = olpc_dt_nextprop,
33403 .getproplen = olpc_dt_getproplen,
33404 .getproperty = olpc_dt_getproperty,
33405diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33406index 1cf5b30..fd45732 100644
33407--- a/arch/x86/power/cpu.c
33408+++ b/arch/x86/power/cpu.c
33409@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33410 static void fix_processor_context(void)
33411 {
33412 int cpu = smp_processor_id();
33413- struct tss_struct *t = &per_cpu(init_tss, cpu);
33414-#ifdef CONFIG_X86_64
33415- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33416- tss_desc tss;
33417-#endif
33418+ struct tss_struct *t = init_tss + cpu;
33419+
33420 set_tss_desc(cpu, t); /*
33421 * This just modifies memory; should not be
33422 * necessary. But... This is necessary, because
33423@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33424 */
33425
33426 #ifdef CONFIG_X86_64
33427- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33428- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33429- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33430-
33431 syscall_init(); /* This sets MSR_*STAR and related */
33432 #endif
33433 load_TR_desc(); /* This does ltr */
33434diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33435index a44f457..9140171 100644
33436--- a/arch/x86/realmode/init.c
33437+++ b/arch/x86/realmode/init.c
33438@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33439 __va(real_mode_header->trampoline_header);
33440
33441 #ifdef CONFIG_X86_32
33442- trampoline_header->start = __pa_symbol(startup_32_smp);
33443+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33444+
33445+#ifdef CONFIG_PAX_KERNEXEC
33446+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33447+#endif
33448+
33449+ trampoline_header->boot_cs = __BOOT_CS;
33450 trampoline_header->gdt_limit = __BOOT_DS + 7;
33451 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33452 #else
33453@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33454 *trampoline_cr4_features = read_cr4();
33455
33456 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33457- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33458+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33459 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33460 #endif
33461 }
33462diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33463index 8869287..d577672 100644
33464--- a/arch/x86/realmode/rm/Makefile
33465+++ b/arch/x86/realmode/rm/Makefile
33466@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33467 $(call cc-option, -fno-unit-at-a-time)) \
33468 $(call cc-option, -fno-stack-protector) \
33469 $(call cc-option, -mpreferred-stack-boundary=2)
33470+ifdef CONSTIFY_PLUGIN
33471+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33472+endif
33473 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33474 GCOV_PROFILE := n
33475diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33476index a28221d..93c40f1 100644
33477--- a/arch/x86/realmode/rm/header.S
33478+++ b/arch/x86/realmode/rm/header.S
33479@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33480 #endif
33481 /* APM/BIOS reboot */
33482 .long pa_machine_real_restart_asm
33483-#ifdef CONFIG_X86_64
33484+#ifdef CONFIG_X86_32
33485+ .long __KERNEL_CS
33486+#else
33487 .long __KERNEL32_CS
33488 #endif
33489 END(real_mode_header)
33490diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33491index c1b2791..f9e31c7 100644
33492--- a/arch/x86/realmode/rm/trampoline_32.S
33493+++ b/arch/x86/realmode/rm/trampoline_32.S
33494@@ -25,6 +25,12 @@
33495 #include <asm/page_types.h>
33496 #include "realmode.h"
33497
33498+#ifdef CONFIG_PAX_KERNEXEC
33499+#define ta(X) (X)
33500+#else
33501+#define ta(X) (pa_ ## X)
33502+#endif
33503+
33504 .text
33505 .code16
33506
33507@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33508
33509 cli # We should be safe anyway
33510
33511- movl tr_start, %eax # where we need to go
33512-
33513 movl $0xA5A5A5A5, trampoline_status
33514 # write marker for master knows we're running
33515
33516@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33517 movw $1, %dx # protected mode (PE) bit
33518 lmsw %dx # into protected mode
33519
33520- ljmpl $__BOOT_CS, $pa_startup_32
33521+ ljmpl *(trampoline_header)
33522
33523 .section ".text32","ax"
33524 .code32
33525@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33526 .balign 8
33527 GLOBAL(trampoline_header)
33528 tr_start: .space 4
33529- tr_gdt_pad: .space 2
33530+ tr_boot_cs: .space 2
33531 tr_gdt: .space 6
33532 END(trampoline_header)
33533
33534diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33535index bb360dc..d0fd8f8 100644
33536--- a/arch/x86/realmode/rm/trampoline_64.S
33537+++ b/arch/x86/realmode/rm/trampoline_64.S
33538@@ -94,6 +94,7 @@ ENTRY(startup_32)
33539 movl %edx, %gs
33540
33541 movl pa_tr_cr4, %eax
33542+ andl $~X86_CR4_PCIDE, %eax
33543 movl %eax, %cr4 # Enable PAE mode
33544
33545 # Setup trampoline 4 level pagetables
33546@@ -107,7 +108,7 @@ ENTRY(startup_32)
33547 wrmsr
33548
33549 # Enable paging and in turn activate Long Mode
33550- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33551+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33552 movl %eax, %cr0
33553
33554 /*
33555diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33556index e812034..c747134 100644
33557--- a/arch/x86/tools/Makefile
33558+++ b/arch/x86/tools/Makefile
33559@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33560
33561 $(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
33562
33563-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33564+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33565 hostprogs-y += relocs
33566 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33567 relocs: $(obj)/relocs
33568diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33569index f7bab68..b6d9886 100644
33570--- a/arch/x86/tools/relocs.c
33571+++ b/arch/x86/tools/relocs.c
33572@@ -1,5 +1,7 @@
33573 /* This is included from relocs_32/64.c */
33574
33575+#include "../../../include/generated/autoconf.h"
33576+
33577 #define ElfW(type) _ElfW(ELF_BITS, type)
33578 #define _ElfW(bits, type) __ElfW(bits, type)
33579 #define __ElfW(bits, type) Elf##bits##_##type
33580@@ -11,6 +13,7 @@
33581 #define Elf_Sym ElfW(Sym)
33582
33583 static Elf_Ehdr ehdr;
33584+static Elf_Phdr *phdr;
33585
33586 struct relocs {
33587 uint32_t *offset;
33588@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33589 }
33590 }
33591
33592+static void read_phdrs(FILE *fp)
33593+{
33594+ unsigned int i;
33595+
33596+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33597+ if (!phdr) {
33598+ die("Unable to allocate %d program headers\n",
33599+ ehdr.e_phnum);
33600+ }
33601+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33602+ die("Seek to %d failed: %s\n",
33603+ ehdr.e_phoff, strerror(errno));
33604+ }
33605+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33606+ die("Cannot read ELF program headers: %s\n",
33607+ strerror(errno));
33608+ }
33609+ for(i = 0; i < ehdr.e_phnum; i++) {
33610+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33611+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33612+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33613+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33614+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33615+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33616+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33617+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33618+ }
33619+
33620+}
33621+
33622 static void read_shdrs(FILE *fp)
33623 {
33624- int i;
33625+ unsigned int i;
33626 Elf_Shdr shdr;
33627
33628 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33629@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33630
33631 static void read_strtabs(FILE *fp)
33632 {
33633- int i;
33634+ unsigned int i;
33635 for (i = 0; i < ehdr.e_shnum; i++) {
33636 struct section *sec = &secs[i];
33637 if (sec->shdr.sh_type != SHT_STRTAB) {
33638@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33639
33640 static void read_symtabs(FILE *fp)
33641 {
33642- int i,j;
33643+ unsigned int i,j;
33644 for (i = 0; i < ehdr.e_shnum; i++) {
33645 struct section *sec = &secs[i];
33646 if (sec->shdr.sh_type != SHT_SYMTAB) {
33647@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33648 }
33649
33650
33651-static void read_relocs(FILE *fp)
33652+static void read_relocs(FILE *fp, int use_real_mode)
33653 {
33654- int i,j;
33655+ unsigned int i,j;
33656+ uint32_t base;
33657+
33658 for (i = 0; i < ehdr.e_shnum; i++) {
33659 struct section *sec = &secs[i];
33660 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33661@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33662 die("Cannot read symbol table: %s\n",
33663 strerror(errno));
33664 }
33665+ base = 0;
33666+
33667+#ifdef CONFIG_X86_32
33668+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33669+ if (phdr[j].p_type != PT_LOAD )
33670+ continue;
33671+ 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)
33672+ continue;
33673+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33674+ break;
33675+ }
33676+#endif
33677+
33678 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33679 Elf_Rel *rel = &sec->reltab[j];
33680- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33681+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33682 rel->r_info = elf_xword_to_cpu(rel->r_info);
33683 #if (SHT_REL_TYPE == SHT_RELA)
33684 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33685@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33686
33687 static void print_absolute_symbols(void)
33688 {
33689- int i;
33690+ unsigned int i;
33691 const char *format;
33692
33693 if (ELF_BITS == 64)
33694@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33695 for (i = 0; i < ehdr.e_shnum; i++) {
33696 struct section *sec = &secs[i];
33697 char *sym_strtab;
33698- int j;
33699+ unsigned int j;
33700
33701 if (sec->shdr.sh_type != SHT_SYMTAB) {
33702 continue;
33703@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33704
33705 static void print_absolute_relocs(void)
33706 {
33707- int i, printed = 0;
33708+ unsigned int i, printed = 0;
33709 const char *format;
33710
33711 if (ELF_BITS == 64)
33712@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33713 struct section *sec_applies, *sec_symtab;
33714 char *sym_strtab;
33715 Elf_Sym *sh_symtab;
33716- int j;
33717+ unsigned int j;
33718 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33719 continue;
33720 }
33721@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33722 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33723 Elf_Sym *sym, const char *symname))
33724 {
33725- int i;
33726+ unsigned int i;
33727 /* Walk through the relocations */
33728 for (i = 0; i < ehdr.e_shnum; i++) {
33729 char *sym_strtab;
33730 Elf_Sym *sh_symtab;
33731 struct section *sec_applies, *sec_symtab;
33732- int j;
33733+ unsigned int j;
33734 struct section *sec = &secs[i];
33735
33736 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33737@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33738 {
33739 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33740 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33741+ char *sym_strtab = sec->link->link->strtab;
33742+
33743+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33744+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33745+ return 0;
33746+
33747+#ifdef CONFIG_PAX_KERNEXEC
33748+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33749+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33750+ return 0;
33751+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33752+ return 0;
33753+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33754+ return 0;
33755+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33756+ return 0;
33757+#endif
33758
33759 switch (r_type) {
33760 case R_386_NONE:
33761@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33762
33763 static void emit_relocs(int as_text, int use_real_mode)
33764 {
33765- int i;
33766+ unsigned int i;
33767 int (*write_reloc)(uint32_t, FILE *) = write32;
33768 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33769 const char *symname);
33770@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33771 {
33772 regex_init(use_real_mode);
33773 read_ehdr(fp);
33774+ read_phdrs(fp);
33775 read_shdrs(fp);
33776 read_strtabs(fp);
33777 read_symtabs(fp);
33778- read_relocs(fp);
33779+ read_relocs(fp, use_real_mode);
33780 if (ELF_BITS == 64)
33781 percpu_init();
33782 if (show_absolute_syms) {
33783diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33784index 80ffa5b..a33bd15 100644
33785--- a/arch/x86/um/tls_32.c
33786+++ b/arch/x86/um/tls_32.c
33787@@ -260,7 +260,7 @@ out:
33788 if (unlikely(task == current &&
33789 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33790 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33791- "without flushed TLS.", current->pid);
33792+ "without flushed TLS.", task_pid_nr(current));
33793 }
33794
33795 return 0;
33796diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33797index fd14be1..e3c79c0 100644
33798--- a/arch/x86/vdso/Makefile
33799+++ b/arch/x86/vdso/Makefile
33800@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33801 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33802 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33803
33804-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33805+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33806 GCOV_PROFILE := n
33807
33808 #
33809diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33810index d6bfb87..876ee18 100644
33811--- a/arch/x86/vdso/vdso32-setup.c
33812+++ b/arch/x86/vdso/vdso32-setup.c
33813@@ -25,6 +25,7 @@
33814 #include <asm/tlbflush.h>
33815 #include <asm/vdso.h>
33816 #include <asm/proto.h>
33817+#include <asm/mman.h>
33818
33819 enum {
33820 VDSO_DISABLED = 0,
33821@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33822 void enable_sep_cpu(void)
33823 {
33824 int cpu = get_cpu();
33825- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33826+ struct tss_struct *tss = init_tss + cpu;
33827
33828 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33829 put_cpu();
33830@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33831 gate_vma.vm_start = FIXADDR_USER_START;
33832 gate_vma.vm_end = FIXADDR_USER_END;
33833 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33834- gate_vma.vm_page_prot = __P101;
33835+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33836
33837 return 0;
33838 }
33839@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33840 if (compat)
33841 addr = VDSO_HIGH_BASE;
33842 else {
33843- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33844+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33845 if (IS_ERR_VALUE(addr)) {
33846 ret = addr;
33847 goto up_fail;
33848 }
33849 }
33850
33851- current->mm->context.vdso = (void *)addr;
33852+ current->mm->context.vdso = addr;
33853
33854 if (compat_uses_vma || !compat) {
33855 /*
33856@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33857 }
33858
33859 current_thread_info()->sysenter_return =
33860- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33861+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33862
33863 up_fail:
33864 if (ret)
33865- current->mm->context.vdso = NULL;
33866+ current->mm->context.vdso = 0;
33867
33868 up_write(&mm->mmap_sem);
33869
33870@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33871
33872 const char *arch_vma_name(struct vm_area_struct *vma)
33873 {
33874- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33875+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33876 return "[vdso]";
33877+
33878+#ifdef CONFIG_PAX_SEGMEXEC
33879+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33880+ return "[vdso]";
33881+#endif
33882+
33883 return NULL;
33884 }
33885
33886@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33887 * Check to see if the corresponding task was created in compat vdso
33888 * mode.
33889 */
33890- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33891+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33892 return &gate_vma;
33893 return NULL;
33894 }
33895diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33896index 431e875..cbb23f3 100644
33897--- a/arch/x86/vdso/vma.c
33898+++ b/arch/x86/vdso/vma.c
33899@@ -16,8 +16,6 @@
33900 #include <asm/vdso.h>
33901 #include <asm/page.h>
33902
33903-unsigned int __read_mostly vdso_enabled = 1;
33904-
33905 extern char vdso_start[], vdso_end[];
33906 extern unsigned short vdso_sync_cpuid;
33907
33908@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33909 * unaligned here as a result of stack start randomization.
33910 */
33911 addr = PAGE_ALIGN(addr);
33912- addr = align_vdso_addr(addr);
33913
33914 return addr;
33915 }
33916@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33917 unsigned size)
33918 {
33919 struct mm_struct *mm = current->mm;
33920- unsigned long addr;
33921+ unsigned long addr = 0;
33922 int ret;
33923
33924- if (!vdso_enabled)
33925- return 0;
33926-
33927 down_write(&mm->mmap_sem);
33928+
33929+#ifdef CONFIG_PAX_RANDMMAP
33930+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33931+#endif
33932+
33933 addr = vdso_addr(mm->start_stack, size);
33934+ addr = align_vdso_addr(addr);
33935 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33936 if (IS_ERR_VALUE(addr)) {
33937 ret = addr;
33938 goto up_fail;
33939 }
33940
33941- current->mm->context.vdso = (void *)addr;
33942+ mm->context.vdso = addr;
33943
33944 ret = install_special_mapping(mm, addr, size,
33945 VM_READ|VM_EXEC|
33946 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33947 pages);
33948- if (ret) {
33949- current->mm->context.vdso = NULL;
33950- goto up_fail;
33951- }
33952+ if (ret)
33953+ mm->context.vdso = 0;
33954
33955 up_fail:
33956 up_write(&mm->mmap_sem);
33957@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33958 vdsox32_size);
33959 }
33960 #endif
33961-
33962-static __init int vdso_setup(char *s)
33963-{
33964- vdso_enabled = simple_strtoul(s, NULL, 0);
33965- return 0;
33966-}
33967-__setup("vdso=", vdso_setup);
33968diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33969index 193097e..7590269 100644
33970--- a/arch/x86/xen/enlighten.c
33971+++ b/arch/x86/xen/enlighten.c
33972@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33973
33974 struct shared_info xen_dummy_shared_info;
33975
33976-void *xen_initial_gdt;
33977-
33978 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33979 __read_mostly int xen_have_vector_callback;
33980 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33981@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33982 {
33983 unsigned long va = dtr->address;
33984 unsigned int size = dtr->size + 1;
33985- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33986- unsigned long frames[pages];
33987+ unsigned long frames[65536 / PAGE_SIZE];
33988 int f;
33989
33990 /*
33991@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33992 {
33993 unsigned long va = dtr->address;
33994 unsigned int size = dtr->size + 1;
33995- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33996- unsigned long frames[pages];
33997+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33998 int f;
33999
34000 /*
34001@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34002 * 8-byte entries, or 16 4k pages..
34003 */
34004
34005- BUG_ON(size > 65536);
34006+ BUG_ON(size > GDT_SIZE);
34007 BUG_ON(va & ~PAGE_MASK);
34008
34009 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34010@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34011 return 0;
34012 }
34013
34014-static void set_xen_basic_apic_ops(void)
34015+static void __init set_xen_basic_apic_ops(void)
34016 {
34017 apic->read = xen_apic_read;
34018 apic->write = xen_apic_write;
34019@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34020 #endif
34021 };
34022
34023-static void xen_reboot(int reason)
34024+static __noreturn void xen_reboot(int reason)
34025 {
34026 struct sched_shutdown r = { .reason = reason };
34027
34028- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34029- BUG();
34030+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34031+ BUG();
34032 }
34033
34034-static void xen_restart(char *msg)
34035+static __noreturn void xen_restart(char *msg)
34036 {
34037 xen_reboot(SHUTDOWN_reboot);
34038 }
34039
34040-static void xen_emergency_restart(void)
34041+static __noreturn void xen_emergency_restart(void)
34042 {
34043 xen_reboot(SHUTDOWN_reboot);
34044 }
34045
34046-static void xen_machine_halt(void)
34047+static __noreturn void xen_machine_halt(void)
34048 {
34049 xen_reboot(SHUTDOWN_poweroff);
34050 }
34051
34052-static void xen_machine_power_off(void)
34053+static __noreturn void xen_machine_power_off(void)
34054 {
34055 if (pm_power_off)
34056 pm_power_off();
34057@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34058 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34059
34060 /* Work out if we support NX */
34061- x86_configure_nx();
34062+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34063+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34064+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34065+ unsigned l, h;
34066+
34067+ __supported_pte_mask |= _PAGE_NX;
34068+ rdmsr(MSR_EFER, l, h);
34069+ l |= EFER_NX;
34070+ wrmsr(MSR_EFER, l, h);
34071+ }
34072+#endif
34073
34074 xen_setup_features();
34075
34076@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34077
34078 machine_ops = xen_machine_ops;
34079
34080- /*
34081- * The only reliable way to retain the initial address of the
34082- * percpu gdt_page is to remember it here, so we can go and
34083- * mark it RW later, when the initial percpu area is freed.
34084- */
34085- xen_initial_gdt = &per_cpu(gdt_page, 0);
34086-
34087 xen_smp_init();
34088
34089 #ifdef CONFIG_ACPI_NUMA
34090diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34091index fdc3ba2..3daee39 100644
34092--- a/arch/x86/xen/mmu.c
34093+++ b/arch/x86/xen/mmu.c
34094@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34095 /* L3_k[510] -> level2_kernel_pgt
34096 * L3_i[511] -> level2_fixmap_pgt */
34097 convert_pfn_mfn(level3_kernel_pgt);
34098+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34099+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34100+ convert_pfn_mfn(level3_vmemmap_pgt);
34101
34102 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34103 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34104@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34105 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34106 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34107 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34108+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34109+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34110+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34111 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34112 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34113+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34114 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34115 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34116
34117@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34118 pv_mmu_ops.set_pud = xen_set_pud;
34119 #if PAGETABLE_LEVELS == 4
34120 pv_mmu_ops.set_pgd = xen_set_pgd;
34121+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34122 #endif
34123
34124 /* This will work as long as patching hasn't happened yet
34125@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34126 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34127 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34128 .set_pgd = xen_set_pgd_hyper,
34129+ .set_pgd_batched = xen_set_pgd_hyper,
34130
34131 .alloc_pud = xen_alloc_pmd_init,
34132 .release_pud = xen_release_pmd_init,
34133diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34134index b81c88e..2cbe7b8 100644
34135--- a/arch/x86/xen/smp.c
34136+++ b/arch/x86/xen/smp.c
34137@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34138 {
34139 BUG_ON(smp_processor_id() != 0);
34140 native_smp_prepare_boot_cpu();
34141-
34142- /* We've switched to the "real" per-cpu gdt, so make sure the
34143- old memory can be recycled */
34144- make_lowmem_page_readwrite(xen_initial_gdt);
34145-
34146 xen_filter_cpu_maps();
34147 xen_setup_vcpu_info_placement();
34148 }
34149@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34150 ctxt->user_regs.ss = __KERNEL_DS;
34151 #ifdef CONFIG_X86_32
34152 ctxt->user_regs.fs = __KERNEL_PERCPU;
34153- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34154+ savesegment(gs, ctxt->user_regs.gs);
34155 #else
34156 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34157 #endif
34158@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34159
34160 {
34161 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34162- ctxt->user_regs.ds = __USER_DS;
34163- ctxt->user_regs.es = __USER_DS;
34164+ ctxt->user_regs.ds = __KERNEL_DS;
34165+ ctxt->user_regs.es = __KERNEL_DS;
34166
34167 xen_copy_trap_info(ctxt->trap_ctxt);
34168
34169@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34170 int rc;
34171
34172 per_cpu(current_task, cpu) = idle;
34173+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34174 #ifdef CONFIG_X86_32
34175 irq_ctx_init(cpu);
34176 #else
34177 clear_tsk_thread_flag(idle, TIF_FORK);
34178- per_cpu(kernel_stack, cpu) =
34179- (unsigned long)task_stack_page(idle) -
34180- KERNEL_STACK_OFFSET + THREAD_SIZE;
34181+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34182 #endif
34183 xen_setup_runstate_info(cpu);
34184 xen_setup_timer(cpu);
34185@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34186
34187 void __init xen_smp_init(void)
34188 {
34189- smp_ops = xen_smp_ops;
34190+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34191 xen_fill_possible_map();
34192 xen_init_spinlocks();
34193 }
34194diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34195index 33ca6e4..0ded929 100644
34196--- a/arch/x86/xen/xen-asm_32.S
34197+++ b/arch/x86/xen/xen-asm_32.S
34198@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34199 ESP_OFFSET=4 # bytes pushed onto stack
34200
34201 /*
34202- * Store vcpu_info pointer for easy access. Do it this way to
34203- * avoid having to reload %fs
34204+ * Store vcpu_info pointer for easy access.
34205 */
34206 #ifdef CONFIG_SMP
34207- GET_THREAD_INFO(%eax)
34208- movl %ss:TI_cpu(%eax), %eax
34209- movl %ss:__per_cpu_offset(,%eax,4), %eax
34210- mov %ss:xen_vcpu(%eax), %eax
34211+ push %fs
34212+ mov $(__KERNEL_PERCPU), %eax
34213+ mov %eax, %fs
34214+ mov PER_CPU_VAR(xen_vcpu), %eax
34215+ pop %fs
34216 #else
34217 movl %ss:xen_vcpu, %eax
34218 #endif
34219diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34220index 7faed58..ba4427c 100644
34221--- a/arch/x86/xen/xen-head.S
34222+++ b/arch/x86/xen/xen-head.S
34223@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34224 #ifdef CONFIG_X86_32
34225 mov %esi,xen_start_info
34226 mov $init_thread_union+THREAD_SIZE,%esp
34227+#ifdef CONFIG_SMP
34228+ movl $cpu_gdt_table,%edi
34229+ movl $__per_cpu_load,%eax
34230+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34231+ rorl $16,%eax
34232+ movb %al,__KERNEL_PERCPU + 4(%edi)
34233+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34234+ movl $__per_cpu_end - 1,%eax
34235+ subl $__per_cpu_start,%eax
34236+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34237+#endif
34238 #else
34239 mov %rsi,xen_start_info
34240 mov $init_thread_union+THREAD_SIZE,%rsp
34241diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34242index 86782c5..fa272c8 100644
34243--- a/arch/x86/xen/xen-ops.h
34244+++ b/arch/x86/xen/xen-ops.h
34245@@ -10,8 +10,6 @@
34246 extern const char xen_hypervisor_callback[];
34247 extern const char xen_failsafe_callback[];
34248
34249-extern void *xen_initial_gdt;
34250-
34251 struct trap_info;
34252 void xen_copy_trap_info(struct trap_info *traps);
34253
34254diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34255index 525bd3d..ef888b1 100644
34256--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34257+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34258@@ -119,9 +119,9 @@
34259 ----------------------------------------------------------------------*/
34260
34261 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34262-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34263 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34264 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34265+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34266
34267 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34268 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34269diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34270index 2f33760..835e50a 100644
34271--- a/arch/xtensa/variants/fsf/include/variant/core.h
34272+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34273@@ -11,6 +11,7 @@
34274 #ifndef _XTENSA_CORE_H
34275 #define _XTENSA_CORE_H
34276
34277+#include <linux/const.h>
34278
34279 /****************************************************************************
34280 Parameters Useful for Any Code, USER or PRIVILEGED
34281@@ -112,9 +113,9 @@
34282 ----------------------------------------------------------------------*/
34283
34284 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34285-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34286 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34287 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34288+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34289
34290 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34291 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34292diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34293index af00795..2bb8105 100644
34294--- a/arch/xtensa/variants/s6000/include/variant/core.h
34295+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34296@@ -11,6 +11,7 @@
34297 #ifndef _XTENSA_CORE_CONFIGURATION_H
34298 #define _XTENSA_CORE_CONFIGURATION_H
34299
34300+#include <linux/const.h>
34301
34302 /****************************************************************************
34303 Parameters Useful for Any Code, USER or PRIVILEGED
34304@@ -118,9 +119,9 @@
34305 ----------------------------------------------------------------------*/
34306
34307 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34308-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34309 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34310 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34311+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34312
34313 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34314 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34315diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34316index 290792a..416f287 100644
34317--- a/block/blk-cgroup.c
34318+++ b/block/blk-cgroup.c
34319@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34320
34321 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34322 {
34323- static atomic64_t id_seq = ATOMIC64_INIT(0);
34324+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34325 struct blkcg *blkcg;
34326 struct cgroup *parent = cgroup->parent;
34327
34328@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34329
34330 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34331 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34332- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34333+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34334 done:
34335 spin_lock_init(&blkcg->lock);
34336 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34337diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34338index 4b8d9b54..a7178c0 100644
34339--- a/block/blk-iopoll.c
34340+++ b/block/blk-iopoll.c
34341@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34342 }
34343 EXPORT_SYMBOL(blk_iopoll_complete);
34344
34345-static void blk_iopoll_softirq(struct softirq_action *h)
34346+static __latent_entropy void blk_iopoll_softirq(void)
34347 {
34348 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34349 int rearm = 0, budget = blk_iopoll_budget;
34350diff --git a/block/blk-map.c b/block/blk-map.c
34351index 623e1cd..ca1e109 100644
34352--- a/block/blk-map.c
34353+++ b/block/blk-map.c
34354@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34355 if (!len || !kbuf)
34356 return -EINVAL;
34357
34358- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34359+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34360 if (do_copy)
34361 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34362 else
34363diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34364index ec9e606..3f38839 100644
34365--- a/block/blk-softirq.c
34366+++ b/block/blk-softirq.c
34367@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34368 * Softirq action handler - move entries to local list and loop over them
34369 * while passing them to the queue registered handler.
34370 */
34371-static void blk_done_softirq(struct softirq_action *h)
34372+static __latent_entropy void blk_done_softirq(void)
34373 {
34374 struct list_head *cpu_list, local_list;
34375
34376diff --git a/block/bsg.c b/block/bsg.c
34377index 420a5a9..23834aa 100644
34378--- a/block/bsg.c
34379+++ b/block/bsg.c
34380@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34381 struct sg_io_v4 *hdr, struct bsg_device *bd,
34382 fmode_t has_write_perm)
34383 {
34384+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34385+ unsigned char *cmdptr;
34386+
34387 if (hdr->request_len > BLK_MAX_CDB) {
34388 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34389 if (!rq->cmd)
34390 return -ENOMEM;
34391- }
34392+ cmdptr = rq->cmd;
34393+ } else
34394+ cmdptr = tmpcmd;
34395
34396- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34397+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34398 hdr->request_len))
34399 return -EFAULT;
34400
34401+ if (cmdptr != rq->cmd)
34402+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34403+
34404 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34405 if (blk_verify_command(rq->cmd, has_write_perm))
34406 return -EPERM;
34407diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34408index 7e5d474..0cf0017 100644
34409--- a/block/compat_ioctl.c
34410+++ b/block/compat_ioctl.c
34411@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34412 err |= __get_user(f->spec1, &uf->spec1);
34413 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34414 err |= __get_user(name, &uf->name);
34415- f->name = compat_ptr(name);
34416+ f->name = (void __force_kernel *)compat_ptr(name);
34417 if (err) {
34418 err = -EFAULT;
34419 goto out;
34420diff --git a/block/genhd.c b/block/genhd.c
34421index dadf42b..48dc887 100644
34422--- a/block/genhd.c
34423+++ b/block/genhd.c
34424@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34425
34426 /*
34427 * Register device numbers dev..(dev+range-1)
34428- * range must be nonzero
34429+ * Noop if @range is zero.
34430 * The hash chain is sorted on range, so that subranges can override.
34431 */
34432 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34433 struct kobject *(*probe)(dev_t, int *, void *),
34434 int (*lock)(dev_t, void *), void *data)
34435 {
34436- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34437+ if (range)
34438+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34439 }
34440
34441 EXPORT_SYMBOL(blk_register_region);
34442
34443+/* undo blk_register_region(), noop if @range is zero */
34444 void blk_unregister_region(dev_t devt, unsigned long range)
34445 {
34446- kobj_unmap(bdev_map, devt, range);
34447+ if (range)
34448+ kobj_unmap(bdev_map, devt, range);
34449 }
34450
34451 EXPORT_SYMBOL(blk_unregister_region);
34452diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34453index c85fc89..51e690b 100644
34454--- a/block/partitions/efi.c
34455+++ b/block/partitions/efi.c
34456@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34457 if (!gpt)
34458 return NULL;
34459
34460+ if (!le32_to_cpu(gpt->num_partition_entries))
34461+ return NULL;
34462+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34463+ if (!pte)
34464+ return NULL;
34465+
34466 count = le32_to_cpu(gpt->num_partition_entries) *
34467 le32_to_cpu(gpt->sizeof_partition_entry);
34468- if (!count)
34469- return NULL;
34470- pte = kmalloc(count, GFP_KERNEL);
34471- if (!pte)
34472- return NULL;
34473-
34474 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34475 (u8 *) pte,
34476 count) < count) {
34477diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34478index a5ffcc9..3cedc9c 100644
34479--- a/block/scsi_ioctl.c
34480+++ b/block/scsi_ioctl.c
34481@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34482 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34483 struct sg_io_hdr *hdr, fmode_t mode)
34484 {
34485- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34486+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34487+ unsigned char *cmdptr;
34488+
34489+ if (rq->cmd != rq->__cmd)
34490+ cmdptr = rq->cmd;
34491+ else
34492+ cmdptr = tmpcmd;
34493+
34494+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34495 return -EFAULT;
34496+
34497+ if (cmdptr != rq->cmd)
34498+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34499+
34500 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34501 return -EPERM;
34502
34503@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34504 int err;
34505 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34506 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34507+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34508+ unsigned char *cmdptr;
34509
34510 if (!sic)
34511 return -EINVAL;
34512@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34513 */
34514 err = -EFAULT;
34515 rq->cmd_len = cmdlen;
34516- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34517+
34518+ if (rq->cmd != rq->__cmd)
34519+ cmdptr = rq->cmd;
34520+ else
34521+ cmdptr = tmpcmd;
34522+
34523+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34524 goto error;
34525
34526+ if (rq->cmd != cmdptr)
34527+ memcpy(rq->cmd, cmdptr, cmdlen);
34528+
34529 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34530 goto error;
34531
34532diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34533index 7bdd61b..afec999 100644
34534--- a/crypto/cryptd.c
34535+++ b/crypto/cryptd.c
34536@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34537
34538 struct cryptd_blkcipher_request_ctx {
34539 crypto_completion_t complete;
34540-};
34541+} __no_const;
34542
34543 struct cryptd_hash_ctx {
34544 struct crypto_shash *child;
34545@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34546
34547 struct cryptd_aead_request_ctx {
34548 crypto_completion_t complete;
34549-};
34550+} __no_const;
34551
34552 static void cryptd_queue_worker(struct work_struct *work);
34553
34554diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34555index f8c920c..ab2cb5a 100644
34556--- a/crypto/pcrypt.c
34557+++ b/crypto/pcrypt.c
34558@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34559 int ret;
34560
34561 pinst->kobj.kset = pcrypt_kset;
34562- ret = kobject_add(&pinst->kobj, NULL, name);
34563+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34564 if (!ret)
34565 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34566
34567diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34568index f220d64..d359ad6 100644
34569--- a/drivers/acpi/apei/apei-internal.h
34570+++ b/drivers/acpi/apei/apei-internal.h
34571@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34572 struct apei_exec_ins_type {
34573 u32 flags;
34574 apei_exec_ins_func_t run;
34575-};
34576+} __do_const;
34577
34578 struct apei_exec_context {
34579 u32 ip;
34580diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34581index 33dc6a0..4b24b47 100644
34582--- a/drivers/acpi/apei/cper.c
34583+++ b/drivers/acpi/apei/cper.c
34584@@ -39,12 +39,12 @@
34585 */
34586 u64 cper_next_record_id(void)
34587 {
34588- static atomic64_t seq;
34589+ static atomic64_unchecked_t seq;
34590
34591- if (!atomic64_read(&seq))
34592- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34593+ if (!atomic64_read_unchecked(&seq))
34594+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34595
34596- return atomic64_inc_return(&seq);
34597+ return atomic64_inc_return_unchecked(&seq);
34598 }
34599 EXPORT_SYMBOL_GPL(cper_next_record_id);
34600
34601diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34602index ec9b57d..9682b3a 100644
34603--- a/drivers/acpi/apei/ghes.c
34604+++ b/drivers/acpi/apei/ghes.c
34605@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34606 const struct acpi_hest_generic *generic,
34607 const struct acpi_hest_generic_status *estatus)
34608 {
34609- static atomic_t seqno;
34610+ static atomic_unchecked_t seqno;
34611 unsigned int curr_seqno;
34612 char pfx_seq[64];
34613
34614@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34615 else
34616 pfx = KERN_ERR;
34617 }
34618- curr_seqno = atomic_inc_return(&seqno);
34619+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34620 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34621 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34622 pfx_seq, generic->header.source_id);
34623diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34624index be60399..778b33e8 100644
34625--- a/drivers/acpi/bgrt.c
34626+++ b/drivers/acpi/bgrt.c
34627@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34628 return -ENODEV;
34629
34630 sysfs_bin_attr_init(&image_attr);
34631- image_attr.private = bgrt_image;
34632- image_attr.size = bgrt_image_size;
34633+ pax_open_kernel();
34634+ *(void **)&image_attr.private = bgrt_image;
34635+ *(size_t *)&image_attr.size = bgrt_image_size;
34636+ pax_close_kernel();
34637
34638 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34639 if (!bgrt_kobj)
34640diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34641index cb96296..b81293b 100644
34642--- a/drivers/acpi/blacklist.c
34643+++ b/drivers/acpi/blacklist.c
34644@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34645 u32 is_critical_error;
34646 };
34647
34648-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34649+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34650
34651 /*
34652 * POLICY: If *anything* doesn't work, put it on the blacklist.
34653@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34654 return 0;
34655 }
34656
34657-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34658+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34659 {
34660 .callback = dmi_disable_osi_vista,
34661 .ident = "Fujitsu Siemens",
34662diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34663index f98dd00..7b69865 100644
34664--- a/drivers/acpi/processor_idle.c
34665+++ b/drivers/acpi/processor_idle.c
34666@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34667 {
34668 int i, count = CPUIDLE_DRIVER_STATE_START;
34669 struct acpi_processor_cx *cx;
34670- struct cpuidle_state *state;
34671+ cpuidle_state_no_const *state;
34672 struct cpuidle_driver *drv = &acpi_idle_driver;
34673
34674 if (!pr->flags.power_setup_done)
34675diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34676index 05306a5..733d1f0 100644
34677--- a/drivers/acpi/sysfs.c
34678+++ b/drivers/acpi/sysfs.c
34679@@ -423,11 +423,11 @@ static u32 num_counters;
34680 static struct attribute **all_attrs;
34681 static u32 acpi_gpe_count;
34682
34683-static struct attribute_group interrupt_stats_attr_group = {
34684+static attribute_group_no_const interrupt_stats_attr_group = {
34685 .name = "interrupts",
34686 };
34687
34688-static struct kobj_attribute *counter_attrs;
34689+static kobj_attribute_no_const *counter_attrs;
34690
34691 static void delete_gpe_attr_array(void)
34692 {
34693diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34694index acfd0f7..e5acb08 100644
34695--- a/drivers/ata/libahci.c
34696+++ b/drivers/ata/libahci.c
34697@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34698 }
34699 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34700
34701-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34702+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34703 struct ata_taskfile *tf, int is_cmd, u16 flags,
34704 unsigned long timeout_msec)
34705 {
34706diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34707index c24354d..335c975 100644
34708--- a/drivers/ata/libata-core.c
34709+++ b/drivers/ata/libata-core.c
34710@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34711 static void ata_dev_xfermask(struct ata_device *dev);
34712 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34713
34714-atomic_t ata_print_id = ATOMIC_INIT(0);
34715+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34716
34717 struct ata_force_param {
34718 const char *name;
34719@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34720 struct ata_port *ap;
34721 unsigned int tag;
34722
34723- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34724+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34725 ap = qc->ap;
34726
34727 qc->flags = 0;
34728@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34729 struct ata_port *ap;
34730 struct ata_link *link;
34731
34732- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34733+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34734 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34735 ap = qc->ap;
34736 link = qc->dev->link;
34737@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34738 return;
34739
34740 spin_lock(&lock);
34741+ pax_open_kernel();
34742
34743 for (cur = ops->inherits; cur; cur = cur->inherits) {
34744 void **inherit = (void **)cur;
34745@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34746 if (IS_ERR(*pp))
34747 *pp = NULL;
34748
34749- ops->inherits = NULL;
34750+ *(struct ata_port_operations **)&ops->inherits = NULL;
34751
34752+ pax_close_kernel();
34753 spin_unlock(&lock);
34754 }
34755
34756@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34757
34758 /* give ports names and add SCSI hosts */
34759 for (i = 0; i < host->n_ports; i++) {
34760- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34761+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34762 host->ports[i]->local_port_no = i + 1;
34763 }
34764
34765diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34766index b1e880a..8cf82e1 100644
34767--- a/drivers/ata/libata-scsi.c
34768+++ b/drivers/ata/libata-scsi.c
34769@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34770
34771 if (rc)
34772 return rc;
34773- ap->print_id = atomic_inc_return(&ata_print_id);
34774+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34775 return 0;
34776 }
34777 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34778diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34779index 577d902b..cb4781e 100644
34780--- a/drivers/ata/libata.h
34781+++ b/drivers/ata/libata.h
34782@@ -53,7 +53,7 @@ enum {
34783 ATA_DNXFER_QUIET = (1 << 31),
34784 };
34785
34786-extern atomic_t ata_print_id;
34787+extern atomic_unchecked_t ata_print_id;
34788 extern int atapi_passthru16;
34789 extern int libata_fua;
34790 extern int libata_noacpi;
34791diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34792index 848ed32..132f39d 100644
34793--- a/drivers/ata/pata_arasan_cf.c
34794+++ b/drivers/ata/pata_arasan_cf.c
34795@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34796 /* Handle platform specific quirks */
34797 if (quirk) {
34798 if (quirk & CF_BROKEN_PIO) {
34799- ap->ops->set_piomode = NULL;
34800+ pax_open_kernel();
34801+ *(void **)&ap->ops->set_piomode = NULL;
34802+ pax_close_kernel();
34803 ap->pio_mask = 0;
34804 }
34805 if (quirk & CF_BROKEN_MWDMA)
34806diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34807index f9b983a..887b9d8 100644
34808--- a/drivers/atm/adummy.c
34809+++ b/drivers/atm/adummy.c
34810@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34811 vcc->pop(vcc, skb);
34812 else
34813 dev_kfree_skb_any(skb);
34814- atomic_inc(&vcc->stats->tx);
34815+ atomic_inc_unchecked(&vcc->stats->tx);
34816
34817 return 0;
34818 }
34819diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34820index 62a7607..cc4be104 100644
34821--- a/drivers/atm/ambassador.c
34822+++ b/drivers/atm/ambassador.c
34823@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34824 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34825
34826 // VC layer stats
34827- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34828+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34829
34830 // free the descriptor
34831 kfree (tx_descr);
34832@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34833 dump_skb ("<<<", vc, skb);
34834
34835 // VC layer stats
34836- atomic_inc(&atm_vcc->stats->rx);
34837+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34838 __net_timestamp(skb);
34839 // end of our responsibility
34840 atm_vcc->push (atm_vcc, skb);
34841@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34842 } else {
34843 PRINTK (KERN_INFO, "dropped over-size frame");
34844 // should we count this?
34845- atomic_inc(&atm_vcc->stats->rx_drop);
34846+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34847 }
34848
34849 } else {
34850@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34851 }
34852
34853 if (check_area (skb->data, skb->len)) {
34854- atomic_inc(&atm_vcc->stats->tx_err);
34855+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34856 return -ENOMEM; // ?
34857 }
34858
34859diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34860index 0e3f8f9..765a7a5 100644
34861--- a/drivers/atm/atmtcp.c
34862+++ b/drivers/atm/atmtcp.c
34863@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34864 if (vcc->pop) vcc->pop(vcc,skb);
34865 else dev_kfree_skb(skb);
34866 if (dev_data) return 0;
34867- atomic_inc(&vcc->stats->tx_err);
34868+ atomic_inc_unchecked(&vcc->stats->tx_err);
34869 return -ENOLINK;
34870 }
34871 size = skb->len+sizeof(struct atmtcp_hdr);
34872@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34873 if (!new_skb) {
34874 if (vcc->pop) vcc->pop(vcc,skb);
34875 else dev_kfree_skb(skb);
34876- atomic_inc(&vcc->stats->tx_err);
34877+ atomic_inc_unchecked(&vcc->stats->tx_err);
34878 return -ENOBUFS;
34879 }
34880 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34881@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34882 if (vcc->pop) vcc->pop(vcc,skb);
34883 else dev_kfree_skb(skb);
34884 out_vcc->push(out_vcc,new_skb);
34885- atomic_inc(&vcc->stats->tx);
34886- atomic_inc(&out_vcc->stats->rx);
34887+ atomic_inc_unchecked(&vcc->stats->tx);
34888+ atomic_inc_unchecked(&out_vcc->stats->rx);
34889 return 0;
34890 }
34891
34892@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34893 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34894 read_unlock(&vcc_sklist_lock);
34895 if (!out_vcc) {
34896- atomic_inc(&vcc->stats->tx_err);
34897+ atomic_inc_unchecked(&vcc->stats->tx_err);
34898 goto done;
34899 }
34900 skb_pull(skb,sizeof(struct atmtcp_hdr));
34901@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34902 __net_timestamp(new_skb);
34903 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34904 out_vcc->push(out_vcc,new_skb);
34905- atomic_inc(&vcc->stats->tx);
34906- atomic_inc(&out_vcc->stats->rx);
34907+ atomic_inc_unchecked(&vcc->stats->tx);
34908+ atomic_inc_unchecked(&out_vcc->stats->rx);
34909 done:
34910 if (vcc->pop) vcc->pop(vcc,skb);
34911 else dev_kfree_skb(skb);
34912diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34913index b1955ba..b179940 100644
34914--- a/drivers/atm/eni.c
34915+++ b/drivers/atm/eni.c
34916@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34917 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34918 vcc->dev->number);
34919 length = 0;
34920- atomic_inc(&vcc->stats->rx_err);
34921+ atomic_inc_unchecked(&vcc->stats->rx_err);
34922 }
34923 else {
34924 length = ATM_CELL_SIZE-1; /* no HEC */
34925@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34926 size);
34927 }
34928 eff = length = 0;
34929- atomic_inc(&vcc->stats->rx_err);
34930+ atomic_inc_unchecked(&vcc->stats->rx_err);
34931 }
34932 else {
34933 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34934@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34935 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34936 vcc->dev->number,vcc->vci,length,size << 2,descr);
34937 length = eff = 0;
34938- atomic_inc(&vcc->stats->rx_err);
34939+ atomic_inc_unchecked(&vcc->stats->rx_err);
34940 }
34941 }
34942 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34943@@ -767,7 +767,7 @@ rx_dequeued++;
34944 vcc->push(vcc,skb);
34945 pushed++;
34946 }
34947- atomic_inc(&vcc->stats->rx);
34948+ atomic_inc_unchecked(&vcc->stats->rx);
34949 }
34950 wake_up(&eni_dev->rx_wait);
34951 }
34952@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34953 PCI_DMA_TODEVICE);
34954 if (vcc->pop) vcc->pop(vcc,skb);
34955 else dev_kfree_skb_irq(skb);
34956- atomic_inc(&vcc->stats->tx);
34957+ atomic_inc_unchecked(&vcc->stats->tx);
34958 wake_up(&eni_dev->tx_wait);
34959 dma_complete++;
34960 }
34961diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34962index b41c948..a002b17 100644
34963--- a/drivers/atm/firestream.c
34964+++ b/drivers/atm/firestream.c
34965@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34966 }
34967 }
34968
34969- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34970+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34971
34972 fs_dprintk (FS_DEBUG_TXMEM, "i");
34973 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34974@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34975 #endif
34976 skb_put (skb, qe->p1 & 0xffff);
34977 ATM_SKB(skb)->vcc = atm_vcc;
34978- atomic_inc(&atm_vcc->stats->rx);
34979+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34980 __net_timestamp(skb);
34981 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34982 atm_vcc->push (atm_vcc, skb);
34983@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34984 kfree (pe);
34985 }
34986 if (atm_vcc)
34987- atomic_inc(&atm_vcc->stats->rx_drop);
34988+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34989 break;
34990 case 0x1f: /* Reassembly abort: no buffers. */
34991 /* Silently increment error counter. */
34992 if (atm_vcc)
34993- atomic_inc(&atm_vcc->stats->rx_drop);
34994+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34995 break;
34996 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34997 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34998diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34999index 204814e..cede831 100644
35000--- a/drivers/atm/fore200e.c
35001+++ b/drivers/atm/fore200e.c
35002@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35003 #endif
35004 /* check error condition */
35005 if (*entry->status & STATUS_ERROR)
35006- atomic_inc(&vcc->stats->tx_err);
35007+ atomic_inc_unchecked(&vcc->stats->tx_err);
35008 else
35009- atomic_inc(&vcc->stats->tx);
35010+ atomic_inc_unchecked(&vcc->stats->tx);
35011 }
35012 }
35013
35014@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35015 if (skb == NULL) {
35016 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35017
35018- atomic_inc(&vcc->stats->rx_drop);
35019+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35020 return -ENOMEM;
35021 }
35022
35023@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35024
35025 dev_kfree_skb_any(skb);
35026
35027- atomic_inc(&vcc->stats->rx_drop);
35028+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35029 return -ENOMEM;
35030 }
35031
35032 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35033
35034 vcc->push(vcc, skb);
35035- atomic_inc(&vcc->stats->rx);
35036+ atomic_inc_unchecked(&vcc->stats->rx);
35037
35038 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35039
35040@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35041 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35042 fore200e->atm_dev->number,
35043 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35044- atomic_inc(&vcc->stats->rx_err);
35045+ atomic_inc_unchecked(&vcc->stats->rx_err);
35046 }
35047 }
35048
35049@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35050 goto retry_here;
35051 }
35052
35053- atomic_inc(&vcc->stats->tx_err);
35054+ atomic_inc_unchecked(&vcc->stats->tx_err);
35055
35056 fore200e->tx_sat++;
35057 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35058diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35059index 507362a..a845e57 100644
35060--- a/drivers/atm/he.c
35061+++ b/drivers/atm/he.c
35062@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35063
35064 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35065 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35066- atomic_inc(&vcc->stats->rx_drop);
35067+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35068 goto return_host_buffers;
35069 }
35070
35071@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35072 RBRQ_LEN_ERR(he_dev->rbrq_head)
35073 ? "LEN_ERR" : "",
35074 vcc->vpi, vcc->vci);
35075- atomic_inc(&vcc->stats->rx_err);
35076+ atomic_inc_unchecked(&vcc->stats->rx_err);
35077 goto return_host_buffers;
35078 }
35079
35080@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35081 vcc->push(vcc, skb);
35082 spin_lock(&he_dev->global_lock);
35083
35084- atomic_inc(&vcc->stats->rx);
35085+ atomic_inc_unchecked(&vcc->stats->rx);
35086
35087 return_host_buffers:
35088 ++pdus_assembled;
35089@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35090 tpd->vcc->pop(tpd->vcc, tpd->skb);
35091 else
35092 dev_kfree_skb_any(tpd->skb);
35093- atomic_inc(&tpd->vcc->stats->tx_err);
35094+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35095 }
35096 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35097 return;
35098@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35099 vcc->pop(vcc, skb);
35100 else
35101 dev_kfree_skb_any(skb);
35102- atomic_inc(&vcc->stats->tx_err);
35103+ atomic_inc_unchecked(&vcc->stats->tx_err);
35104 return -EINVAL;
35105 }
35106
35107@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35108 vcc->pop(vcc, skb);
35109 else
35110 dev_kfree_skb_any(skb);
35111- atomic_inc(&vcc->stats->tx_err);
35112+ atomic_inc_unchecked(&vcc->stats->tx_err);
35113 return -EINVAL;
35114 }
35115 #endif
35116@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35117 vcc->pop(vcc, skb);
35118 else
35119 dev_kfree_skb_any(skb);
35120- atomic_inc(&vcc->stats->tx_err);
35121+ atomic_inc_unchecked(&vcc->stats->tx_err);
35122 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35123 return -ENOMEM;
35124 }
35125@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35126 vcc->pop(vcc, skb);
35127 else
35128 dev_kfree_skb_any(skb);
35129- atomic_inc(&vcc->stats->tx_err);
35130+ atomic_inc_unchecked(&vcc->stats->tx_err);
35131 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35132 return -ENOMEM;
35133 }
35134@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35135 __enqueue_tpd(he_dev, tpd, cid);
35136 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35137
35138- atomic_inc(&vcc->stats->tx);
35139+ atomic_inc_unchecked(&vcc->stats->tx);
35140
35141 return 0;
35142 }
35143diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35144index 1dc0519..1aadaf7 100644
35145--- a/drivers/atm/horizon.c
35146+++ b/drivers/atm/horizon.c
35147@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35148 {
35149 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35150 // VC layer stats
35151- atomic_inc(&vcc->stats->rx);
35152+ atomic_inc_unchecked(&vcc->stats->rx);
35153 __net_timestamp(skb);
35154 // end of our responsibility
35155 vcc->push (vcc, skb);
35156@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35157 dev->tx_iovec = NULL;
35158
35159 // VC layer stats
35160- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35161+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35162
35163 // free the skb
35164 hrz_kfree_skb (skb);
35165diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35166index 272f009..a18ba55 100644
35167--- a/drivers/atm/idt77252.c
35168+++ b/drivers/atm/idt77252.c
35169@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35170 else
35171 dev_kfree_skb(skb);
35172
35173- atomic_inc(&vcc->stats->tx);
35174+ atomic_inc_unchecked(&vcc->stats->tx);
35175 }
35176
35177 atomic_dec(&scq->used);
35178@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35179 if ((sb = dev_alloc_skb(64)) == NULL) {
35180 printk("%s: Can't allocate buffers for aal0.\n",
35181 card->name);
35182- atomic_add(i, &vcc->stats->rx_drop);
35183+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35184 break;
35185 }
35186 if (!atm_charge(vcc, sb->truesize)) {
35187 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35188 card->name);
35189- atomic_add(i - 1, &vcc->stats->rx_drop);
35190+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35191 dev_kfree_skb(sb);
35192 break;
35193 }
35194@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35195 ATM_SKB(sb)->vcc = vcc;
35196 __net_timestamp(sb);
35197 vcc->push(vcc, sb);
35198- atomic_inc(&vcc->stats->rx);
35199+ atomic_inc_unchecked(&vcc->stats->rx);
35200
35201 cell += ATM_CELL_PAYLOAD;
35202 }
35203@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35204 "(CDC: %08x)\n",
35205 card->name, len, rpp->len, readl(SAR_REG_CDC));
35206 recycle_rx_pool_skb(card, rpp);
35207- atomic_inc(&vcc->stats->rx_err);
35208+ atomic_inc_unchecked(&vcc->stats->rx_err);
35209 return;
35210 }
35211 if (stat & SAR_RSQE_CRC) {
35212 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35213 recycle_rx_pool_skb(card, rpp);
35214- atomic_inc(&vcc->stats->rx_err);
35215+ atomic_inc_unchecked(&vcc->stats->rx_err);
35216 return;
35217 }
35218 if (skb_queue_len(&rpp->queue) > 1) {
35219@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35220 RXPRINTK("%s: Can't alloc RX skb.\n",
35221 card->name);
35222 recycle_rx_pool_skb(card, rpp);
35223- atomic_inc(&vcc->stats->rx_err);
35224+ atomic_inc_unchecked(&vcc->stats->rx_err);
35225 return;
35226 }
35227 if (!atm_charge(vcc, skb->truesize)) {
35228@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35229 __net_timestamp(skb);
35230
35231 vcc->push(vcc, skb);
35232- atomic_inc(&vcc->stats->rx);
35233+ atomic_inc_unchecked(&vcc->stats->rx);
35234
35235 return;
35236 }
35237@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35238 __net_timestamp(skb);
35239
35240 vcc->push(vcc, skb);
35241- atomic_inc(&vcc->stats->rx);
35242+ atomic_inc_unchecked(&vcc->stats->rx);
35243
35244 if (skb->truesize > SAR_FB_SIZE_3)
35245 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35246@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35247 if (vcc->qos.aal != ATM_AAL0) {
35248 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35249 card->name, vpi, vci);
35250- atomic_inc(&vcc->stats->rx_drop);
35251+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35252 goto drop;
35253 }
35254
35255 if ((sb = dev_alloc_skb(64)) == NULL) {
35256 printk("%s: Can't allocate buffers for AAL0.\n",
35257 card->name);
35258- atomic_inc(&vcc->stats->rx_err);
35259+ atomic_inc_unchecked(&vcc->stats->rx_err);
35260 goto drop;
35261 }
35262
35263@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35264 ATM_SKB(sb)->vcc = vcc;
35265 __net_timestamp(sb);
35266 vcc->push(vcc, sb);
35267- atomic_inc(&vcc->stats->rx);
35268+ atomic_inc_unchecked(&vcc->stats->rx);
35269
35270 drop:
35271 skb_pull(queue, 64);
35272@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35273
35274 if (vc == NULL) {
35275 printk("%s: NULL connection in send().\n", card->name);
35276- atomic_inc(&vcc->stats->tx_err);
35277+ atomic_inc_unchecked(&vcc->stats->tx_err);
35278 dev_kfree_skb(skb);
35279 return -EINVAL;
35280 }
35281 if (!test_bit(VCF_TX, &vc->flags)) {
35282 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35283- atomic_inc(&vcc->stats->tx_err);
35284+ atomic_inc_unchecked(&vcc->stats->tx_err);
35285 dev_kfree_skb(skb);
35286 return -EINVAL;
35287 }
35288@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35289 break;
35290 default:
35291 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35292- atomic_inc(&vcc->stats->tx_err);
35293+ atomic_inc_unchecked(&vcc->stats->tx_err);
35294 dev_kfree_skb(skb);
35295 return -EINVAL;
35296 }
35297
35298 if (skb_shinfo(skb)->nr_frags != 0) {
35299 printk("%s: No scatter-gather yet.\n", card->name);
35300- atomic_inc(&vcc->stats->tx_err);
35301+ atomic_inc_unchecked(&vcc->stats->tx_err);
35302 dev_kfree_skb(skb);
35303 return -EINVAL;
35304 }
35305@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35306
35307 err = queue_skb(card, vc, skb, oam);
35308 if (err) {
35309- atomic_inc(&vcc->stats->tx_err);
35310+ atomic_inc_unchecked(&vcc->stats->tx_err);
35311 dev_kfree_skb(skb);
35312 return err;
35313 }
35314@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35315 skb = dev_alloc_skb(64);
35316 if (!skb) {
35317 printk("%s: Out of memory in send_oam().\n", card->name);
35318- atomic_inc(&vcc->stats->tx_err);
35319+ atomic_inc_unchecked(&vcc->stats->tx_err);
35320 return -ENOMEM;
35321 }
35322 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35323diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35324index 4217f29..88f547a 100644
35325--- a/drivers/atm/iphase.c
35326+++ b/drivers/atm/iphase.c
35327@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35328 status = (u_short) (buf_desc_ptr->desc_mode);
35329 if (status & (RX_CER | RX_PTE | RX_OFL))
35330 {
35331- atomic_inc(&vcc->stats->rx_err);
35332+ atomic_inc_unchecked(&vcc->stats->rx_err);
35333 IF_ERR(printk("IA: bad packet, dropping it");)
35334 if (status & RX_CER) {
35335 IF_ERR(printk(" cause: packet CRC error\n");)
35336@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35337 len = dma_addr - buf_addr;
35338 if (len > iadev->rx_buf_sz) {
35339 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35340- atomic_inc(&vcc->stats->rx_err);
35341+ atomic_inc_unchecked(&vcc->stats->rx_err);
35342 goto out_free_desc;
35343 }
35344
35345@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35346 ia_vcc = INPH_IA_VCC(vcc);
35347 if (ia_vcc == NULL)
35348 {
35349- atomic_inc(&vcc->stats->rx_err);
35350+ atomic_inc_unchecked(&vcc->stats->rx_err);
35351 atm_return(vcc, skb->truesize);
35352 dev_kfree_skb_any(skb);
35353 goto INCR_DLE;
35354@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35355 if ((length > iadev->rx_buf_sz) || (length >
35356 (skb->len - sizeof(struct cpcs_trailer))))
35357 {
35358- atomic_inc(&vcc->stats->rx_err);
35359+ atomic_inc_unchecked(&vcc->stats->rx_err);
35360 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35361 length, skb->len);)
35362 atm_return(vcc, skb->truesize);
35363@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35364
35365 IF_RX(printk("rx_dle_intr: skb push");)
35366 vcc->push(vcc,skb);
35367- atomic_inc(&vcc->stats->rx);
35368+ atomic_inc_unchecked(&vcc->stats->rx);
35369 iadev->rx_pkt_cnt++;
35370 }
35371 INCR_DLE:
35372@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35373 {
35374 struct k_sonet_stats *stats;
35375 stats = &PRIV(_ia_dev[board])->sonet_stats;
35376- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35377- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35378- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35379- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35380- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35381- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35382- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35383- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35384- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35385+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35386+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35387+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35388+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35389+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35390+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35391+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35392+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35393+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35394 }
35395 ia_cmds.status = 0;
35396 break;
35397@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35398 if ((desc == 0) || (desc > iadev->num_tx_desc))
35399 {
35400 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35401- atomic_inc(&vcc->stats->tx);
35402+ atomic_inc_unchecked(&vcc->stats->tx);
35403 if (vcc->pop)
35404 vcc->pop(vcc, skb);
35405 else
35406@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35407 ATM_DESC(skb) = vcc->vci;
35408 skb_queue_tail(&iadev->tx_dma_q, skb);
35409
35410- atomic_inc(&vcc->stats->tx);
35411+ atomic_inc_unchecked(&vcc->stats->tx);
35412 iadev->tx_pkt_cnt++;
35413 /* Increment transaction counter */
35414 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35415
35416 #if 0
35417 /* add flow control logic */
35418- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35419+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35420 if (iavcc->vc_desc_cnt > 10) {
35421 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35422 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35423diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35424index fa7d701..1e404c7 100644
35425--- a/drivers/atm/lanai.c
35426+++ b/drivers/atm/lanai.c
35427@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35428 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35429 lanai_endtx(lanai, lvcc);
35430 lanai_free_skb(lvcc->tx.atmvcc, skb);
35431- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35432+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35433 }
35434
35435 /* Try to fill the buffer - don't call unless there is backlog */
35436@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35437 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35438 __net_timestamp(skb);
35439 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35440- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35441+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35442 out:
35443 lvcc->rx.buf.ptr = end;
35444 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35445@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35446 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35447 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35448 lanai->stats.service_rxnotaal5++;
35449- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35450+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35451 return 0;
35452 }
35453 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35454@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35455 int bytes;
35456 read_unlock(&vcc_sklist_lock);
35457 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35458- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35459+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35460 lvcc->stats.x.aal5.service_trash++;
35461 bytes = (SERVICE_GET_END(s) * 16) -
35462 (((unsigned long) lvcc->rx.buf.ptr) -
35463@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35464 }
35465 if (s & SERVICE_STREAM) {
35466 read_unlock(&vcc_sklist_lock);
35467- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35468+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35469 lvcc->stats.x.aal5.service_stream++;
35470 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35471 "PDU on VCI %d!\n", lanai->number, vci);
35472@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35473 return 0;
35474 }
35475 DPRINTK("got rx crc error on vci %d\n", vci);
35476- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35477+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35478 lvcc->stats.x.aal5.service_rxcrc++;
35479 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35480 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35481diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35482index 6587dc2..149833d 100644
35483--- a/drivers/atm/nicstar.c
35484+++ b/drivers/atm/nicstar.c
35485@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35486 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35487 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35488 card->index);
35489- atomic_inc(&vcc->stats->tx_err);
35490+ atomic_inc_unchecked(&vcc->stats->tx_err);
35491 dev_kfree_skb_any(skb);
35492 return -EINVAL;
35493 }
35494@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35495 if (!vc->tx) {
35496 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35497 card->index);
35498- atomic_inc(&vcc->stats->tx_err);
35499+ atomic_inc_unchecked(&vcc->stats->tx_err);
35500 dev_kfree_skb_any(skb);
35501 return -EINVAL;
35502 }
35503@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35504 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35505 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35506 card->index);
35507- atomic_inc(&vcc->stats->tx_err);
35508+ atomic_inc_unchecked(&vcc->stats->tx_err);
35509 dev_kfree_skb_any(skb);
35510 return -EINVAL;
35511 }
35512
35513 if (skb_shinfo(skb)->nr_frags != 0) {
35514 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35515- atomic_inc(&vcc->stats->tx_err);
35516+ atomic_inc_unchecked(&vcc->stats->tx_err);
35517 dev_kfree_skb_any(skb);
35518 return -EINVAL;
35519 }
35520@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35521 }
35522
35523 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35524- atomic_inc(&vcc->stats->tx_err);
35525+ atomic_inc_unchecked(&vcc->stats->tx_err);
35526 dev_kfree_skb_any(skb);
35527 return -EIO;
35528 }
35529- atomic_inc(&vcc->stats->tx);
35530+ atomic_inc_unchecked(&vcc->stats->tx);
35531
35532 return 0;
35533 }
35534@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35535 printk
35536 ("nicstar%d: Can't allocate buffers for aal0.\n",
35537 card->index);
35538- atomic_add(i, &vcc->stats->rx_drop);
35539+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35540 break;
35541 }
35542 if (!atm_charge(vcc, sb->truesize)) {
35543 RXPRINTK
35544 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35545 card->index);
35546- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35547+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35548 dev_kfree_skb_any(sb);
35549 break;
35550 }
35551@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35552 ATM_SKB(sb)->vcc = vcc;
35553 __net_timestamp(sb);
35554 vcc->push(vcc, sb);
35555- atomic_inc(&vcc->stats->rx);
35556+ atomic_inc_unchecked(&vcc->stats->rx);
35557 cell += ATM_CELL_PAYLOAD;
35558 }
35559
35560@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35561 if (iovb == NULL) {
35562 printk("nicstar%d: Out of iovec buffers.\n",
35563 card->index);
35564- atomic_inc(&vcc->stats->rx_drop);
35565+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35566 recycle_rx_buf(card, skb);
35567 return;
35568 }
35569@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35570 small or large buffer itself. */
35571 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35572 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35573- atomic_inc(&vcc->stats->rx_err);
35574+ atomic_inc_unchecked(&vcc->stats->rx_err);
35575 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35576 NS_MAX_IOVECS);
35577 NS_PRV_IOVCNT(iovb) = 0;
35578@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35579 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35580 card->index);
35581 which_list(card, skb);
35582- atomic_inc(&vcc->stats->rx_err);
35583+ atomic_inc_unchecked(&vcc->stats->rx_err);
35584 recycle_rx_buf(card, skb);
35585 vc->rx_iov = NULL;
35586 recycle_iov_buf(card, iovb);
35587@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35588 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35589 card->index);
35590 which_list(card, skb);
35591- atomic_inc(&vcc->stats->rx_err);
35592+ atomic_inc_unchecked(&vcc->stats->rx_err);
35593 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35594 NS_PRV_IOVCNT(iovb));
35595 vc->rx_iov = NULL;
35596@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35597 printk(" - PDU size mismatch.\n");
35598 else
35599 printk(".\n");
35600- atomic_inc(&vcc->stats->rx_err);
35601+ atomic_inc_unchecked(&vcc->stats->rx_err);
35602 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35603 NS_PRV_IOVCNT(iovb));
35604 vc->rx_iov = NULL;
35605@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35606 /* skb points to a small buffer */
35607 if (!atm_charge(vcc, skb->truesize)) {
35608 push_rxbufs(card, skb);
35609- atomic_inc(&vcc->stats->rx_drop);
35610+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35611 } else {
35612 skb_put(skb, len);
35613 dequeue_sm_buf(card, skb);
35614@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35615 ATM_SKB(skb)->vcc = vcc;
35616 __net_timestamp(skb);
35617 vcc->push(vcc, skb);
35618- atomic_inc(&vcc->stats->rx);
35619+ atomic_inc_unchecked(&vcc->stats->rx);
35620 }
35621 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35622 struct sk_buff *sb;
35623@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35624 if (len <= NS_SMBUFSIZE) {
35625 if (!atm_charge(vcc, sb->truesize)) {
35626 push_rxbufs(card, sb);
35627- atomic_inc(&vcc->stats->rx_drop);
35628+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35629 } else {
35630 skb_put(sb, len);
35631 dequeue_sm_buf(card, sb);
35632@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35633 ATM_SKB(sb)->vcc = vcc;
35634 __net_timestamp(sb);
35635 vcc->push(vcc, sb);
35636- atomic_inc(&vcc->stats->rx);
35637+ atomic_inc_unchecked(&vcc->stats->rx);
35638 }
35639
35640 push_rxbufs(card, skb);
35641@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35642
35643 if (!atm_charge(vcc, skb->truesize)) {
35644 push_rxbufs(card, skb);
35645- atomic_inc(&vcc->stats->rx_drop);
35646+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35647 } else {
35648 dequeue_lg_buf(card, skb);
35649 #ifdef NS_USE_DESTRUCTORS
35650@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35651 ATM_SKB(skb)->vcc = vcc;
35652 __net_timestamp(skb);
35653 vcc->push(vcc, skb);
35654- atomic_inc(&vcc->stats->rx);
35655+ atomic_inc_unchecked(&vcc->stats->rx);
35656 }
35657
35658 push_rxbufs(card, sb);
35659@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35660 printk
35661 ("nicstar%d: Out of huge buffers.\n",
35662 card->index);
35663- atomic_inc(&vcc->stats->rx_drop);
35664+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35665 recycle_iovec_rx_bufs(card,
35666 (struct iovec *)
35667 iovb->data,
35668@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35669 card->hbpool.count++;
35670 } else
35671 dev_kfree_skb_any(hb);
35672- atomic_inc(&vcc->stats->rx_drop);
35673+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35674 } else {
35675 /* Copy the small buffer to the huge buffer */
35676 sb = (struct sk_buff *)iov->iov_base;
35677@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35678 #endif /* NS_USE_DESTRUCTORS */
35679 __net_timestamp(hb);
35680 vcc->push(vcc, hb);
35681- atomic_inc(&vcc->stats->rx);
35682+ atomic_inc_unchecked(&vcc->stats->rx);
35683 }
35684 }
35685
35686diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35687index 32784d1..4a8434a 100644
35688--- a/drivers/atm/solos-pci.c
35689+++ b/drivers/atm/solos-pci.c
35690@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35691 }
35692 atm_charge(vcc, skb->truesize);
35693 vcc->push(vcc, skb);
35694- atomic_inc(&vcc->stats->rx);
35695+ atomic_inc_unchecked(&vcc->stats->rx);
35696 break;
35697
35698 case PKT_STATUS:
35699@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35700 vcc = SKB_CB(oldskb)->vcc;
35701
35702 if (vcc) {
35703- atomic_inc(&vcc->stats->tx);
35704+ atomic_inc_unchecked(&vcc->stats->tx);
35705 solos_pop(vcc, oldskb);
35706 } else {
35707 dev_kfree_skb_irq(oldskb);
35708diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35709index 0215934..ce9f5b1 100644
35710--- a/drivers/atm/suni.c
35711+++ b/drivers/atm/suni.c
35712@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35713
35714
35715 #define ADD_LIMITED(s,v) \
35716- atomic_add((v),&stats->s); \
35717- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35718+ atomic_add_unchecked((v),&stats->s); \
35719+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35720
35721
35722 static void suni_hz(unsigned long from_timer)
35723diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35724index 5120a96..e2572bd 100644
35725--- a/drivers/atm/uPD98402.c
35726+++ b/drivers/atm/uPD98402.c
35727@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35728 struct sonet_stats tmp;
35729 int error = 0;
35730
35731- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35732+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35733 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35734 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35735 if (zero && !error) {
35736@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35737
35738
35739 #define ADD_LIMITED(s,v) \
35740- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35741- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35742- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35743+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35744+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35745+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35746
35747
35748 static void stat_event(struct atm_dev *dev)
35749@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35750 if (reason & uPD98402_INT_PFM) stat_event(dev);
35751 if (reason & uPD98402_INT_PCO) {
35752 (void) GET(PCOCR); /* clear interrupt cause */
35753- atomic_add(GET(HECCT),
35754+ atomic_add_unchecked(GET(HECCT),
35755 &PRIV(dev)->sonet_stats.uncorr_hcs);
35756 }
35757 if ((reason & uPD98402_INT_RFO) &&
35758@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35759 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35760 uPD98402_INT_LOS),PIMR); /* enable them */
35761 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35762- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35763- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35764- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35765+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35766+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35767+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35768 return 0;
35769 }
35770
35771diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35772index 969c3c2..9b72956 100644
35773--- a/drivers/atm/zatm.c
35774+++ b/drivers/atm/zatm.c
35775@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35776 }
35777 if (!size) {
35778 dev_kfree_skb_irq(skb);
35779- if (vcc) atomic_inc(&vcc->stats->rx_err);
35780+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35781 continue;
35782 }
35783 if (!atm_charge(vcc,skb->truesize)) {
35784@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35785 skb->len = size;
35786 ATM_SKB(skb)->vcc = vcc;
35787 vcc->push(vcc,skb);
35788- atomic_inc(&vcc->stats->rx);
35789+ atomic_inc_unchecked(&vcc->stats->rx);
35790 }
35791 zout(pos & 0xffff,MTA(mbx));
35792 #if 0 /* probably a stupid idea */
35793@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35794 skb_queue_head(&zatm_vcc->backlog,skb);
35795 break;
35796 }
35797- atomic_inc(&vcc->stats->tx);
35798+ atomic_inc_unchecked(&vcc->stats->tx);
35799 wake_up(&zatm_vcc->tx_wait);
35800 }
35801
35802diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35803index d414331..b4dd4ba 100644
35804--- a/drivers/base/bus.c
35805+++ b/drivers/base/bus.c
35806@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35807 return -EINVAL;
35808
35809 mutex_lock(&subsys->p->mutex);
35810- list_add_tail(&sif->node, &subsys->p->interfaces);
35811+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35812 if (sif->add_dev) {
35813 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35814 while ((dev = subsys_dev_iter_next(&iter)))
35815@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35816 subsys = sif->subsys;
35817
35818 mutex_lock(&subsys->p->mutex);
35819- list_del_init(&sif->node);
35820+ pax_list_del_init((struct list_head *)&sif->node);
35821 if (sif->remove_dev) {
35822 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35823 while ((dev = subsys_dev_iter_next(&iter)))
35824diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35825index 7413d06..79155fa 100644
35826--- a/drivers/base/devtmpfs.c
35827+++ b/drivers/base/devtmpfs.c
35828@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35829 if (!thread)
35830 return 0;
35831
35832- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35833+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35834 if (err)
35835 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35836 else
35837@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35838 *err = sys_unshare(CLONE_NEWNS);
35839 if (*err)
35840 goto out;
35841- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35842+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35843 if (*err)
35844 goto out;
35845- sys_chdir("/.."); /* will traverse into overmounted root */
35846- sys_chroot(".");
35847+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35848+ sys_chroot((char __force_user *)".");
35849 complete(&setup_done);
35850 while (1) {
35851 spin_lock(&req_lock);
35852diff --git a/drivers/base/node.c b/drivers/base/node.c
35853index 7616a77c..8f57f51 100644
35854--- a/drivers/base/node.c
35855+++ b/drivers/base/node.c
35856@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35857 struct node_attr {
35858 struct device_attribute attr;
35859 enum node_states state;
35860-};
35861+} __do_const;
35862
35863 static ssize_t show_node_state(struct device *dev,
35864 struct device_attribute *attr, char *buf)
35865diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35866index bfb8955..42c9b9a 100644
35867--- a/drivers/base/power/domain.c
35868+++ b/drivers/base/power/domain.c
35869@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35870 {
35871 struct cpuidle_driver *cpuidle_drv;
35872 struct gpd_cpu_data *cpu_data;
35873- struct cpuidle_state *idle_state;
35874+ cpuidle_state_no_const *idle_state;
35875 int ret = 0;
35876
35877 if (IS_ERR_OR_NULL(genpd) || state < 0)
35878@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35879 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35880 {
35881 struct gpd_cpu_data *cpu_data;
35882- struct cpuidle_state *idle_state;
35883+ cpuidle_state_no_const *idle_state;
35884 int ret = 0;
35885
35886 if (IS_ERR_OR_NULL(genpd))
35887diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35888index a53ebd2..8f73eeb 100644
35889--- a/drivers/base/power/sysfs.c
35890+++ b/drivers/base/power/sysfs.c
35891@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35892 return -EIO;
35893 }
35894 }
35895- return sprintf(buf, p);
35896+ return sprintf(buf, "%s", p);
35897 }
35898
35899 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35900diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35901index 2d56f41..8830f19 100644
35902--- a/drivers/base/power/wakeup.c
35903+++ b/drivers/base/power/wakeup.c
35904@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35905 * They need to be modified together atomically, so it's better to use one
35906 * atomic variable to hold them both.
35907 */
35908-static atomic_t combined_event_count = ATOMIC_INIT(0);
35909+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35910
35911 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35912 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35913
35914 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35915 {
35916- unsigned int comb = atomic_read(&combined_event_count);
35917+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35918
35919 *cnt = (comb >> IN_PROGRESS_BITS);
35920 *inpr = comb & MAX_IN_PROGRESS;
35921@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35922 ws->start_prevent_time = ws->last_time;
35923
35924 /* Increment the counter of events in progress. */
35925- cec = atomic_inc_return(&combined_event_count);
35926+ cec = atomic_inc_return_unchecked(&combined_event_count);
35927
35928 trace_wakeup_source_activate(ws->name, cec);
35929 }
35930@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35931 * Increment the counter of registered wakeup events and decrement the
35932 * couter of wakeup events in progress simultaneously.
35933 */
35934- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35935+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35936 trace_wakeup_source_deactivate(ws->name, cec);
35937
35938 split_counters(&cnt, &inpr);
35939diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35940index e8d11b6..7b1b36f 100644
35941--- a/drivers/base/syscore.c
35942+++ b/drivers/base/syscore.c
35943@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35944 void register_syscore_ops(struct syscore_ops *ops)
35945 {
35946 mutex_lock(&syscore_ops_lock);
35947- list_add_tail(&ops->node, &syscore_ops_list);
35948+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35949 mutex_unlock(&syscore_ops_lock);
35950 }
35951 EXPORT_SYMBOL_GPL(register_syscore_ops);
35952@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35953 void unregister_syscore_ops(struct syscore_ops *ops)
35954 {
35955 mutex_lock(&syscore_ops_lock);
35956- list_del(&ops->node);
35957+ pax_list_del((struct list_head *)&ops->node);
35958 mutex_unlock(&syscore_ops_lock);
35959 }
35960 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35961diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35962index 90a4e6b..002d10f 100644
35963--- a/drivers/block/cciss.c
35964+++ b/drivers/block/cciss.c
35965@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
35966 while (!list_empty(&h->reqQ)) {
35967 c = list_entry(h->reqQ.next, CommandList_struct, list);
35968 /* can't do anything if fifo is full */
35969- if ((h->access.fifo_full(h))) {
35970+ if ((h->access->fifo_full(h))) {
35971 dev_warn(&h->pdev->dev, "fifo full\n");
35972 break;
35973 }
35974@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
35975 h->Qdepth--;
35976
35977 /* Tell the controller execute command */
35978- h->access.submit_command(h, c);
35979+ h->access->submit_command(h, c);
35980
35981 /* Put job onto the completed Q */
35982 addQ(&h->cmpQ, c);
35983@@ -3447,17 +3447,17 @@ startio:
35984
35985 static inline unsigned long get_next_completion(ctlr_info_t *h)
35986 {
35987- return h->access.command_completed(h);
35988+ return h->access->command_completed(h);
35989 }
35990
35991 static inline int interrupt_pending(ctlr_info_t *h)
35992 {
35993- return h->access.intr_pending(h);
35994+ return h->access->intr_pending(h);
35995 }
35996
35997 static inline long interrupt_not_for_us(ctlr_info_t *h)
35998 {
35999- return ((h->access.intr_pending(h) == 0) ||
36000+ return ((h->access->intr_pending(h) == 0) ||
36001 (h->interrupts_enabled == 0));
36002 }
36003
36004@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36005 u32 a;
36006
36007 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36008- return h->access.command_completed(h);
36009+ return h->access->command_completed(h);
36010
36011 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36012 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36013@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36014 trans_support & CFGTBL_Trans_use_short_tags);
36015
36016 /* Change the access methods to the performant access methods */
36017- h->access = SA5_performant_access;
36018+ h->access = &SA5_performant_access;
36019 h->transMethod = CFGTBL_Trans_Performant;
36020
36021 return;
36022@@ -4320,7 +4320,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36023 if (prod_index < 0)
36024 return -ENODEV;
36025 h->product_name = products[prod_index].product_name;
36026- h->access = *(products[prod_index].access);
36027+ h->access = products[prod_index].access;
36028
36029 if (cciss_board_disabled(h)) {
36030 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36031@@ -5052,7 +5052,7 @@ reinit_after_soft_reset:
36032 }
36033
36034 /* make sure the board interrupts are off */
36035- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36036+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36037 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36038 if (rc)
36039 goto clean2;
36040@@ -5102,7 +5102,7 @@ reinit_after_soft_reset:
36041 * fake ones to scoop up any residual completions.
36042 */
36043 spin_lock_irqsave(&h->lock, flags);
36044- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36045+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36046 spin_unlock_irqrestore(&h->lock, flags);
36047 free_irq(h->intr[h->intr_mode], h);
36048 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36049@@ -5122,9 +5122,9 @@ reinit_after_soft_reset:
36050 dev_info(&h->pdev->dev, "Board READY.\n");
36051 dev_info(&h->pdev->dev,
36052 "Waiting for stale completions to drain.\n");
36053- h->access.set_intr_mask(h, CCISS_INTR_ON);
36054+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36055 msleep(10000);
36056- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36057+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36058
36059 rc = controller_reset_failed(h->cfgtable);
36060 if (rc)
36061@@ -5147,7 +5147,7 @@ reinit_after_soft_reset:
36062 cciss_scsi_setup(h);
36063
36064 /* Turn the interrupts on so we can service requests */
36065- h->access.set_intr_mask(h, CCISS_INTR_ON);
36066+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36067
36068 /* Get the firmware version */
36069 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36070@@ -5219,7 +5219,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36071 kfree(flush_buf);
36072 if (return_code != IO_OK)
36073 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36074- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36075+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36076 free_irq(h->intr[h->intr_mode], h);
36077 }
36078
36079diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36080index 7fda30e..eb5dfe0 100644
36081--- a/drivers/block/cciss.h
36082+++ b/drivers/block/cciss.h
36083@@ -101,7 +101,7 @@ struct ctlr_info
36084 /* information about each logical volume */
36085 drive_info_struct *drv[CISS_MAX_LUN];
36086
36087- struct access_method access;
36088+ struct access_method *access;
36089
36090 /* queue and queue Info */
36091 struct list_head reqQ;
36092diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36093index 2b94403..fd6ad1f 100644
36094--- a/drivers/block/cpqarray.c
36095+++ b/drivers/block/cpqarray.c
36096@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36097 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36098 goto Enomem4;
36099 }
36100- hba[i]->access.set_intr_mask(hba[i], 0);
36101+ hba[i]->access->set_intr_mask(hba[i], 0);
36102 if (request_irq(hba[i]->intr, do_ida_intr,
36103 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36104 {
36105@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36106 add_timer(&hba[i]->timer);
36107
36108 /* Enable IRQ now that spinlock and rate limit timer are set up */
36109- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36110+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36111
36112 for(j=0; j<NWD; j++) {
36113 struct gendisk *disk = ida_gendisk[i][j];
36114@@ -694,7 +694,7 @@ DBGINFO(
36115 for(i=0; i<NR_PRODUCTS; i++) {
36116 if (board_id == products[i].board_id) {
36117 c->product_name = products[i].product_name;
36118- c->access = *(products[i].access);
36119+ c->access = products[i].access;
36120 break;
36121 }
36122 }
36123@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36124 hba[ctlr]->intr = intr;
36125 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36126 hba[ctlr]->product_name = products[j].product_name;
36127- hba[ctlr]->access = *(products[j].access);
36128+ hba[ctlr]->access = products[j].access;
36129 hba[ctlr]->ctlr = ctlr;
36130 hba[ctlr]->board_id = board_id;
36131 hba[ctlr]->pci_dev = NULL; /* not PCI */
36132@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36133
36134 while((c = h->reqQ) != NULL) {
36135 /* Can't do anything if we're busy */
36136- if (h->access.fifo_full(h) == 0)
36137+ if (h->access->fifo_full(h) == 0)
36138 return;
36139
36140 /* Get the first entry from the request Q */
36141@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36142 h->Qdepth--;
36143
36144 /* Tell the controller to do our bidding */
36145- h->access.submit_command(h, c);
36146+ h->access->submit_command(h, c);
36147
36148 /* Get onto the completion Q */
36149 addQ(&h->cmpQ, c);
36150@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36151 unsigned long flags;
36152 __u32 a,a1;
36153
36154- istat = h->access.intr_pending(h);
36155+ istat = h->access->intr_pending(h);
36156 /* Is this interrupt for us? */
36157 if (istat == 0)
36158 return IRQ_NONE;
36159@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36160 */
36161 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36162 if (istat & FIFO_NOT_EMPTY) {
36163- while((a = h->access.command_completed(h))) {
36164+ while((a = h->access->command_completed(h))) {
36165 a1 = a; a &= ~3;
36166 if ((c = h->cmpQ) == NULL)
36167 {
36168@@ -1448,11 +1448,11 @@ static int sendcmd(
36169 /*
36170 * Disable interrupt
36171 */
36172- info_p->access.set_intr_mask(info_p, 0);
36173+ info_p->access->set_intr_mask(info_p, 0);
36174 /* Make sure there is room in the command FIFO */
36175 /* Actually it should be completely empty at this time. */
36176 for (i = 200000; i > 0; i--) {
36177- temp = info_p->access.fifo_full(info_p);
36178+ temp = info_p->access->fifo_full(info_p);
36179 if (temp != 0) {
36180 break;
36181 }
36182@@ -1465,7 +1465,7 @@ DBG(
36183 /*
36184 * Send the cmd
36185 */
36186- info_p->access.submit_command(info_p, c);
36187+ info_p->access->submit_command(info_p, c);
36188 complete = pollcomplete(ctlr);
36189
36190 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36191@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36192 * we check the new geometry. Then turn interrupts back on when
36193 * we're done.
36194 */
36195- host->access.set_intr_mask(host, 0);
36196+ host->access->set_intr_mask(host, 0);
36197 getgeometry(ctlr);
36198- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36199+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36200
36201 for(i=0; i<NWD; i++) {
36202 struct gendisk *disk = ida_gendisk[ctlr][i];
36203@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36204 /* Wait (up to 2 seconds) for a command to complete */
36205
36206 for (i = 200000; i > 0; i--) {
36207- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36208+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36209 if (done == 0) {
36210 udelay(10); /* a short fixed delay */
36211 } else
36212diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36213index be73e9d..7fbf140 100644
36214--- a/drivers/block/cpqarray.h
36215+++ b/drivers/block/cpqarray.h
36216@@ -99,7 +99,7 @@ struct ctlr_info {
36217 drv_info_t drv[NWD];
36218 struct proc_dir_entry *proc;
36219
36220- struct access_method access;
36221+ struct access_method *access;
36222
36223 cmdlist_t *reqQ;
36224 cmdlist_t *cmpQ;
36225diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36226index 2d7f608..11245fe 100644
36227--- a/drivers/block/drbd/drbd_int.h
36228+++ b/drivers/block/drbd/drbd_int.h
36229@@ -582,7 +582,7 @@ struct drbd_epoch {
36230 struct drbd_tconn *tconn;
36231 struct list_head list;
36232 unsigned int barrier_nr;
36233- atomic_t epoch_size; /* increased on every request added. */
36234+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36235 atomic_t active; /* increased on every req. added, and dec on every finished. */
36236 unsigned long flags;
36237 };
36238@@ -1022,7 +1022,7 @@ struct drbd_conf {
36239 unsigned int al_tr_number;
36240 int al_tr_cycle;
36241 wait_queue_head_t seq_wait;
36242- atomic_t packet_seq;
36243+ atomic_unchecked_t packet_seq;
36244 unsigned int peer_seq;
36245 spinlock_t peer_seq_lock;
36246 unsigned int minor;
36247@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36248 char __user *uoptval;
36249 int err;
36250
36251- uoptval = (char __user __force *)optval;
36252+ uoptval = (char __force_user *)optval;
36253
36254 set_fs(KERNEL_DS);
36255 if (level == SOL_SOCKET)
36256diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36257index 55635ed..40e837c 100644
36258--- a/drivers/block/drbd/drbd_main.c
36259+++ b/drivers/block/drbd/drbd_main.c
36260@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36261 p->sector = sector;
36262 p->block_id = block_id;
36263 p->blksize = blksize;
36264- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36265+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36266 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36267 }
36268
36269@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36270 return -EIO;
36271 p->sector = cpu_to_be64(req->i.sector);
36272 p->block_id = (unsigned long)req;
36273- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36274+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36275 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36276 if (mdev->state.conn >= C_SYNC_SOURCE &&
36277 mdev->state.conn <= C_PAUSED_SYNC_T)
36278@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36279 {
36280 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36281
36282- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36283- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36284+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36285+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36286 kfree(tconn->current_epoch);
36287
36288 idr_destroy(&tconn->volumes);
36289diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36290index 8cc1e64..ba7ffa9 100644
36291--- a/drivers/block/drbd/drbd_nl.c
36292+++ b/drivers/block/drbd/drbd_nl.c
36293@@ -3440,7 +3440,7 @@ out:
36294
36295 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36296 {
36297- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36298+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36299 struct sk_buff *msg;
36300 struct drbd_genlmsghdr *d_out;
36301 unsigned seq;
36302@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36303 return;
36304 }
36305
36306- seq = atomic_inc_return(&drbd_genl_seq);
36307+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36308 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36309 if (!msg)
36310 goto failed;
36311diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36312index cc29cd3..d4b058b 100644
36313--- a/drivers/block/drbd/drbd_receiver.c
36314+++ b/drivers/block/drbd/drbd_receiver.c
36315@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36316 {
36317 int err;
36318
36319- atomic_set(&mdev->packet_seq, 0);
36320+ atomic_set_unchecked(&mdev->packet_seq, 0);
36321 mdev->peer_seq = 0;
36322
36323 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36324@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36325 do {
36326 next_epoch = NULL;
36327
36328- epoch_size = atomic_read(&epoch->epoch_size);
36329+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36330
36331 switch (ev & ~EV_CLEANUP) {
36332 case EV_PUT:
36333@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36334 rv = FE_DESTROYED;
36335 } else {
36336 epoch->flags = 0;
36337- atomic_set(&epoch->epoch_size, 0);
36338+ atomic_set_unchecked(&epoch->epoch_size, 0);
36339 /* atomic_set(&epoch->active, 0); is already zero */
36340 if (rv == FE_STILL_LIVE)
36341 rv = FE_RECYCLED;
36342@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36343 conn_wait_active_ee_empty(tconn);
36344 drbd_flush(tconn);
36345
36346- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36347+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36348 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36349 if (epoch)
36350 break;
36351@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36352 }
36353
36354 epoch->flags = 0;
36355- atomic_set(&epoch->epoch_size, 0);
36356+ atomic_set_unchecked(&epoch->epoch_size, 0);
36357 atomic_set(&epoch->active, 0);
36358
36359 spin_lock(&tconn->epoch_lock);
36360- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36361+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36362 list_add(&epoch->list, &tconn->current_epoch->list);
36363 tconn->current_epoch = epoch;
36364 tconn->epochs++;
36365@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36366
36367 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36368 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36369- atomic_inc(&tconn->current_epoch->epoch_size);
36370+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36371 err2 = drbd_drain_block(mdev, pi->size);
36372 if (!err)
36373 err = err2;
36374@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36375
36376 spin_lock(&tconn->epoch_lock);
36377 peer_req->epoch = tconn->current_epoch;
36378- atomic_inc(&peer_req->epoch->epoch_size);
36379+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36380 atomic_inc(&peer_req->epoch->active);
36381 spin_unlock(&tconn->epoch_lock);
36382
36383@@ -4347,7 +4347,7 @@ struct data_cmd {
36384 int expect_payload;
36385 size_t pkt_size;
36386 int (*fn)(struct drbd_tconn *, struct packet_info *);
36387-};
36388+} __do_const;
36389
36390 static struct data_cmd drbd_cmd_handler[] = {
36391 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36392@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36393 if (!list_empty(&tconn->current_epoch->list))
36394 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36395 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36396- atomic_set(&tconn->current_epoch->epoch_size, 0);
36397+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36398 tconn->send.seen_any_write_yet = false;
36399
36400 conn_info(tconn, "Connection closed\n");
36401@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36402 struct asender_cmd {
36403 size_t pkt_size;
36404 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36405-};
36406+} __do_const;
36407
36408 static struct asender_cmd asender_tbl[] = {
36409 [P_PING] = { 0, got_Ping },
36410diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36411index 40e7155..df5c79a 100644
36412--- a/drivers/block/loop.c
36413+++ b/drivers/block/loop.c
36414@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36415
36416 file_start_write(file);
36417 set_fs(get_ds());
36418- bw = file->f_op->write(file, buf, len, &pos);
36419+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36420 set_fs(old_fs);
36421 file_end_write(file);
36422 if (likely(bw == len))
36423diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36424index f5d0ea1..c62380a 100644
36425--- a/drivers/block/pktcdvd.c
36426+++ b/drivers/block/pktcdvd.c
36427@@ -84,7 +84,7 @@
36428 #define MAX_SPEED 0xffff
36429
36430 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36431- ~(sector_t)((pd)->settings.size - 1))
36432+ ~(sector_t)((pd)->settings.size - 1UL))
36433
36434 static DEFINE_MUTEX(pktcdvd_mutex);
36435 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36436diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36437index 7332889..9ece19e 100644
36438--- a/drivers/bus/arm-cci.c
36439+++ b/drivers/bus/arm-cci.c
36440@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36441
36442 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36443
36444- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36445+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36446 if (!ports)
36447 return -ENOMEM;
36448
36449diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36450index 8a3aff7..d7538c2 100644
36451--- a/drivers/cdrom/cdrom.c
36452+++ b/drivers/cdrom/cdrom.c
36453@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36454 ENSURE(reset, CDC_RESET);
36455 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36456 cdi->mc_flags = 0;
36457- cdo->n_minors = 0;
36458 cdi->options = CDO_USE_FFLAGS;
36459
36460 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36461@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36462 else
36463 cdi->cdda_method = CDDA_OLD;
36464
36465- if (!cdo->generic_packet)
36466- cdo->generic_packet = cdrom_dummy_generic_packet;
36467+ if (!cdo->generic_packet) {
36468+ pax_open_kernel();
36469+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36470+ pax_close_kernel();
36471+ }
36472
36473 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36474 mutex_lock(&cdrom_mutex);
36475@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36476 if (cdi->exit)
36477 cdi->exit(cdi);
36478
36479- cdi->ops->n_minors--;
36480 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36481 }
36482
36483@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36484 */
36485 nr = nframes;
36486 do {
36487- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36488+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36489 if (cgc.buffer)
36490 break;
36491
36492@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36493 struct cdrom_device_info *cdi;
36494 int ret;
36495
36496- ret = scnprintf(info + *pos, max_size - *pos, header);
36497+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36498 if (!ret)
36499 return 1;
36500
36501diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36502index 5980cb9..6d7bd7e 100644
36503--- a/drivers/cdrom/gdrom.c
36504+++ b/drivers/cdrom/gdrom.c
36505@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36506 .audio_ioctl = gdrom_audio_ioctl,
36507 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36508 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36509- .n_minors = 1,
36510 };
36511
36512 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36513diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36514index 1421997..33f5d6d 100644
36515--- a/drivers/char/Kconfig
36516+++ b/drivers/char/Kconfig
36517@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36518
36519 config DEVKMEM
36520 bool "/dev/kmem virtual device support"
36521- default y
36522+ default n
36523+ depends on !GRKERNSEC_KMEM
36524 help
36525 Say Y here if you want to support the /dev/kmem device. The
36526 /dev/kmem device is rarely used, but can be used for certain
36527@@ -570,6 +571,7 @@ config DEVPORT
36528 bool
36529 depends on !M68K
36530 depends on ISA || PCI
36531+ depends on !GRKERNSEC_KMEM
36532 default y
36533
36534 source "drivers/s390/char/Kconfig"
36535diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36536index a48e05b..6bac831 100644
36537--- a/drivers/char/agp/compat_ioctl.c
36538+++ b/drivers/char/agp/compat_ioctl.c
36539@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36540 return -ENOMEM;
36541 }
36542
36543- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36544+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36545 sizeof(*usegment) * ureserve.seg_count)) {
36546 kfree(usegment);
36547 kfree(ksegment);
36548diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36549index 1b19239..b87b143 100644
36550--- a/drivers/char/agp/frontend.c
36551+++ b/drivers/char/agp/frontend.c
36552@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36553 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36554 return -EFAULT;
36555
36556- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36557+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36558 return -EFAULT;
36559
36560 client = agp_find_client_by_pid(reserve.pid);
36561@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36562 if (segment == NULL)
36563 return -ENOMEM;
36564
36565- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36566+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36567 sizeof(struct agp_segment) * reserve.seg_count)) {
36568 kfree(segment);
36569 return -EFAULT;
36570diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36571index 4f94375..413694e 100644
36572--- a/drivers/char/genrtc.c
36573+++ b/drivers/char/genrtc.c
36574@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36575 switch (cmd) {
36576
36577 case RTC_PLL_GET:
36578+ memset(&pll, 0, sizeof(pll));
36579 if (get_rtc_pll(&pll))
36580 return -EINVAL;
36581 else
36582diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36583index 448ce5e..3a76625 100644
36584--- a/drivers/char/hpet.c
36585+++ b/drivers/char/hpet.c
36586@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36587 }
36588
36589 static int
36590-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36591+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36592 struct hpet_info *info)
36593 {
36594 struct hpet_timer __iomem *timer;
36595diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36596index 86fe45c..c0ea948 100644
36597--- a/drivers/char/hw_random/intel-rng.c
36598+++ b/drivers/char/hw_random/intel-rng.c
36599@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36600
36601 if (no_fwh_detect)
36602 return -ENODEV;
36603- printk(warning);
36604+ printk("%s", warning);
36605 return -EBUSY;
36606 }
36607
36608diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36609index 4445fa1..7c6de37 100644
36610--- a/drivers/char/ipmi/ipmi_msghandler.c
36611+++ b/drivers/char/ipmi/ipmi_msghandler.c
36612@@ -420,7 +420,7 @@ struct ipmi_smi {
36613 struct proc_dir_entry *proc_dir;
36614 char proc_dir_name[10];
36615
36616- atomic_t stats[IPMI_NUM_STATS];
36617+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36618
36619 /*
36620 * run_to_completion duplicate of smb_info, smi_info
36621@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36622
36623
36624 #define ipmi_inc_stat(intf, stat) \
36625- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36626+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36627 #define ipmi_get_stat(intf, stat) \
36628- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36629+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36630
36631 static int is_lan_addr(struct ipmi_addr *addr)
36632 {
36633@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36634 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36635 init_waitqueue_head(&intf->waitq);
36636 for (i = 0; i < IPMI_NUM_STATS; i++)
36637- atomic_set(&intf->stats[i], 0);
36638+ atomic_set_unchecked(&intf->stats[i], 0);
36639
36640 intf->proc_dir = NULL;
36641
36642diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36643index af4b23f..79806fc 100644
36644--- a/drivers/char/ipmi/ipmi_si_intf.c
36645+++ b/drivers/char/ipmi/ipmi_si_intf.c
36646@@ -275,7 +275,7 @@ struct smi_info {
36647 unsigned char slave_addr;
36648
36649 /* Counters and things for the proc filesystem. */
36650- atomic_t stats[SI_NUM_STATS];
36651+ atomic_unchecked_t stats[SI_NUM_STATS];
36652
36653 struct task_struct *thread;
36654
36655@@ -284,9 +284,9 @@ struct smi_info {
36656 };
36657
36658 #define smi_inc_stat(smi, stat) \
36659- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36660+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36661 #define smi_get_stat(smi, stat) \
36662- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36663+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36664
36665 #define SI_MAX_PARMS 4
36666
36667@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36668 atomic_set(&new_smi->req_events, 0);
36669 new_smi->run_to_completion = 0;
36670 for (i = 0; i < SI_NUM_STATS; i++)
36671- atomic_set(&new_smi->stats[i], 0);
36672+ atomic_set_unchecked(&new_smi->stats[i], 0);
36673
36674 new_smi->interrupt_disabled = 1;
36675 atomic_set(&new_smi->stop_operation, 0);
36676diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36677index f895a8c..2bc9147 100644
36678--- a/drivers/char/mem.c
36679+++ b/drivers/char/mem.c
36680@@ -18,6 +18,7 @@
36681 #include <linux/raw.h>
36682 #include <linux/tty.h>
36683 #include <linux/capability.h>
36684+#include <linux/security.h>
36685 #include <linux/ptrace.h>
36686 #include <linux/device.h>
36687 #include <linux/highmem.h>
36688@@ -37,6 +38,10 @@
36689
36690 #define DEVPORT_MINOR 4
36691
36692+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36693+extern const struct file_operations grsec_fops;
36694+#endif
36695+
36696 static inline unsigned long size_inside_page(unsigned long start,
36697 unsigned long size)
36698 {
36699@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36700
36701 while (cursor < to) {
36702 if (!devmem_is_allowed(pfn)) {
36703+#ifdef CONFIG_GRKERNSEC_KMEM
36704+ gr_handle_mem_readwrite(from, to);
36705+#else
36706 printk(KERN_INFO
36707 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36708 current->comm, from, to);
36709+#endif
36710 return 0;
36711 }
36712 cursor += PAGE_SIZE;
36713@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36714 }
36715 return 1;
36716 }
36717+#elif defined(CONFIG_GRKERNSEC_KMEM)
36718+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36719+{
36720+ return 0;
36721+}
36722 #else
36723 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36724 {
36725@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36726
36727 while (count > 0) {
36728 unsigned long remaining;
36729+ char *temp;
36730
36731 sz = size_inside_page(p, count);
36732
36733@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36734 if (!ptr)
36735 return -EFAULT;
36736
36737- remaining = copy_to_user(buf, ptr, sz);
36738+#ifdef CONFIG_PAX_USERCOPY
36739+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36740+ if (!temp) {
36741+ unxlate_dev_mem_ptr(p, ptr);
36742+ return -ENOMEM;
36743+ }
36744+ memcpy(temp, ptr, sz);
36745+#else
36746+ temp = ptr;
36747+#endif
36748+
36749+ remaining = copy_to_user(buf, temp, sz);
36750+
36751+#ifdef CONFIG_PAX_USERCOPY
36752+ kfree(temp);
36753+#endif
36754+
36755 unxlate_dev_mem_ptr(p, ptr);
36756 if (remaining)
36757 return -EFAULT;
36758@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36759 size_t count, loff_t *ppos)
36760 {
36761 unsigned long p = *ppos;
36762- ssize_t low_count, read, sz;
36763+ ssize_t low_count, read, sz, err = 0;
36764 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36765- int err = 0;
36766
36767 read = 0;
36768 if (p < (unsigned long) high_memory) {
36769@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36770 }
36771 #endif
36772 while (low_count > 0) {
36773+ char *temp;
36774+
36775 sz = size_inside_page(p, low_count);
36776
36777 /*
36778@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36779 */
36780 kbuf = xlate_dev_kmem_ptr((char *)p);
36781
36782- if (copy_to_user(buf, kbuf, sz))
36783+#ifdef CONFIG_PAX_USERCOPY
36784+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36785+ if (!temp)
36786+ return -ENOMEM;
36787+ memcpy(temp, kbuf, sz);
36788+#else
36789+ temp = kbuf;
36790+#endif
36791+
36792+ err = copy_to_user(buf, temp, sz);
36793+
36794+#ifdef CONFIG_PAX_USERCOPY
36795+ kfree(temp);
36796+#endif
36797+
36798+ if (err)
36799 return -EFAULT;
36800 buf += sz;
36801 p += sz;
36802@@ -822,6 +869,9 @@ static const struct memdev {
36803 #ifdef CONFIG_PRINTK
36804 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36805 #endif
36806+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36807+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36808+#endif
36809 };
36810
36811 static int memory_open(struct inode *inode, struct file *filp)
36812@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36813 continue;
36814
36815 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36816- NULL, devlist[minor].name);
36817+ NULL, "%s", devlist[minor].name);
36818 }
36819
36820 return tty_init();
36821diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36822index 9df78e2..01ba9ae 100644
36823--- a/drivers/char/nvram.c
36824+++ b/drivers/char/nvram.c
36825@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36826
36827 spin_unlock_irq(&rtc_lock);
36828
36829- if (copy_to_user(buf, contents, tmp - contents))
36830+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36831 return -EFAULT;
36832
36833 *ppos = i;
36834diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36835index 5c5cc00..ac9edb7 100644
36836--- a/drivers/char/pcmcia/synclink_cs.c
36837+++ b/drivers/char/pcmcia/synclink_cs.c
36838@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36839
36840 if (debug_level >= DEBUG_LEVEL_INFO)
36841 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36842- __FILE__, __LINE__, info->device_name, port->count);
36843+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36844
36845- WARN_ON(!port->count);
36846+ WARN_ON(!atomic_read(&port->count));
36847
36848 if (tty_port_close_start(port, tty, filp) == 0)
36849 goto cleanup;
36850@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36851 cleanup:
36852 if (debug_level >= DEBUG_LEVEL_INFO)
36853 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36854- tty->driver->name, port->count);
36855+ tty->driver->name, atomic_read(&port->count));
36856 }
36857
36858 /* Wait until the transmitter is empty.
36859@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36860
36861 if (debug_level >= DEBUG_LEVEL_INFO)
36862 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36863- __FILE__, __LINE__, tty->driver->name, port->count);
36864+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36865
36866 /* If port is closing, signal caller to try again */
36867 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36868@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36869 goto cleanup;
36870 }
36871 spin_lock(&port->lock);
36872- port->count++;
36873+ atomic_inc(&port->count);
36874 spin_unlock(&port->lock);
36875 spin_unlock_irqrestore(&info->netlock, flags);
36876
36877- if (port->count == 1) {
36878+ if (atomic_read(&port->count) == 1) {
36879 /* 1st open on this device, init hardware */
36880 retval = startup(info, tty);
36881 if (retval < 0)
36882@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36883 unsigned short new_crctype;
36884
36885 /* return error if TTY interface open */
36886- if (info->port.count)
36887+ if (atomic_read(&info->port.count))
36888 return -EBUSY;
36889
36890 switch (encoding)
36891@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36892
36893 /* arbitrate between network and tty opens */
36894 spin_lock_irqsave(&info->netlock, flags);
36895- if (info->port.count != 0 || info->netcount != 0) {
36896+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36897 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36898 spin_unlock_irqrestore(&info->netlock, flags);
36899 return -EBUSY;
36900@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36901 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36902
36903 /* return error if TTY interface open */
36904- if (info->port.count)
36905+ if (atomic_read(&info->port.count))
36906 return -EBUSY;
36907
36908 if (cmd != SIOCWANDEV)
36909diff --git a/drivers/char/random.c b/drivers/char/random.c
36910index 92e6c67..c640ec3 100644
36911--- a/drivers/char/random.c
36912+++ b/drivers/char/random.c
36913@@ -272,8 +272,13 @@
36914 /*
36915 * Configuration information
36916 */
36917+#ifdef CONFIG_GRKERNSEC_RANDNET
36918+#define INPUT_POOL_WORDS 512
36919+#define OUTPUT_POOL_WORDS 128
36920+#else
36921 #define INPUT_POOL_WORDS 128
36922 #define OUTPUT_POOL_WORDS 32
36923+#endif
36924 #define SEC_XFER_SIZE 512
36925 #define EXTRACT_SIZE 10
36926
36927@@ -313,10 +318,17 @@ static struct poolinfo {
36928 int poolwords;
36929 int tap1, tap2, tap3, tap4, tap5;
36930 } poolinfo_table[] = {
36931+#ifdef CONFIG_GRKERNSEC_RANDNET
36932+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36933+ { 512, 411, 308, 208, 104, 1 },
36934+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36935+ { 128, 103, 76, 51, 25, 1 },
36936+#else
36937 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36938 { 128, 103, 76, 51, 25, 1 },
36939 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36940 { 32, 26, 20, 14, 7, 1 },
36941+#endif
36942 #if 0
36943 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36944 { 2048, 1638, 1231, 819, 411, 1 },
36945@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36946 input_rotate += i ? 7 : 14;
36947 }
36948
36949- ACCESS_ONCE(r->input_rotate) = input_rotate;
36950- ACCESS_ONCE(r->add_ptr) = i;
36951+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36952+ ACCESS_ONCE_RW(r->add_ptr) = i;
36953 smp_wmb();
36954
36955 if (out)
36956@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36957
36958 extract_buf(r, tmp);
36959 i = min_t(int, nbytes, EXTRACT_SIZE);
36960- if (copy_to_user(buf, tmp, i)) {
36961+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36962 ret = -EFAULT;
36963 break;
36964 }
36965@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36966 #include <linux/sysctl.h>
36967
36968 static int min_read_thresh = 8, min_write_thresh;
36969-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36970+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36971 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36972 static char sysctl_bootid[16];
36973
36974@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36975 static int proc_do_uuid(struct ctl_table *table, int write,
36976 void __user *buffer, size_t *lenp, loff_t *ppos)
36977 {
36978- struct ctl_table fake_table;
36979+ ctl_table_no_const fake_table;
36980 unsigned char buf[64], tmp_uuid[16], *uuid;
36981
36982 uuid = table->data;
36983diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36984index bf2349db..5456d53 100644
36985--- a/drivers/char/sonypi.c
36986+++ b/drivers/char/sonypi.c
36987@@ -54,6 +54,7 @@
36988
36989 #include <asm/uaccess.h>
36990 #include <asm/io.h>
36991+#include <asm/local.h>
36992
36993 #include <linux/sonypi.h>
36994
36995@@ -490,7 +491,7 @@ static struct sonypi_device {
36996 spinlock_t fifo_lock;
36997 wait_queue_head_t fifo_proc_list;
36998 struct fasync_struct *fifo_async;
36999- int open_count;
37000+ local_t open_count;
37001 int model;
37002 struct input_dev *input_jog_dev;
37003 struct input_dev *input_key_dev;
37004@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37005 static int sonypi_misc_release(struct inode *inode, struct file *file)
37006 {
37007 mutex_lock(&sonypi_device.lock);
37008- sonypi_device.open_count--;
37009+ local_dec(&sonypi_device.open_count);
37010 mutex_unlock(&sonypi_device.lock);
37011 return 0;
37012 }
37013@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37014 {
37015 mutex_lock(&sonypi_device.lock);
37016 /* Flush input queue on first open */
37017- if (!sonypi_device.open_count)
37018+ if (!local_read(&sonypi_device.open_count))
37019 kfifo_reset(&sonypi_device.fifo);
37020- sonypi_device.open_count++;
37021+ local_inc(&sonypi_device.open_count);
37022 mutex_unlock(&sonypi_device.lock);
37023
37024 return 0;
37025diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37026index 64420b3..5c40b56 100644
37027--- a/drivers/char/tpm/tpm_acpi.c
37028+++ b/drivers/char/tpm/tpm_acpi.c
37029@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37030 virt = acpi_os_map_memory(start, len);
37031 if (!virt) {
37032 kfree(log->bios_event_log);
37033+ log->bios_event_log = NULL;
37034 printk("%s: ERROR - Unable to map memory\n", __func__);
37035 return -EIO;
37036 }
37037
37038- memcpy_fromio(log->bios_event_log, virt, len);
37039+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37040
37041 acpi_os_unmap_memory(virt, len);
37042 return 0;
37043diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37044index 84ddc55..1d32f1e 100644
37045--- a/drivers/char/tpm/tpm_eventlog.c
37046+++ b/drivers/char/tpm/tpm_eventlog.c
37047@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37048 event = addr;
37049
37050 if ((event->event_type == 0 && event->event_size == 0) ||
37051- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37052+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37053 return NULL;
37054
37055 return addr;
37056@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37057 return NULL;
37058
37059 if ((event->event_type == 0 && event->event_size == 0) ||
37060- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37061+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37062 return NULL;
37063
37064 (*pos)++;
37065@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37066 int i;
37067
37068 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37069- seq_putc(m, data[i]);
37070+ if (!seq_putc(m, data[i]))
37071+ return -EFAULT;
37072
37073 return 0;
37074 }
37075diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37076index fc45567..fa2a590 100644
37077--- a/drivers/char/virtio_console.c
37078+++ b/drivers/char/virtio_console.c
37079@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37080 if (to_user) {
37081 ssize_t ret;
37082
37083- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37084+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37085 if (ret)
37086 return -EFAULT;
37087 } else {
37088@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37089 if (!port_has_data(port) && !port->host_connected)
37090 return 0;
37091
37092- return fill_readbuf(port, ubuf, count, true);
37093+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37094 }
37095
37096 static int wait_port_writable(struct port *port, bool nonblock)
37097diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37098index a33f46f..a720eed 100644
37099--- a/drivers/clk/clk-composite.c
37100+++ b/drivers/clk/clk-composite.c
37101@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37102 struct clk *clk;
37103 struct clk_init_data init;
37104 struct clk_composite *composite;
37105- struct clk_ops *clk_composite_ops;
37106+ clk_ops_no_const *clk_composite_ops;
37107
37108 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37109 if (!composite) {
37110diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37111index 5bb848c..f1d4fc9 100644
37112--- a/drivers/clk/socfpga/clk.c
37113+++ b/drivers/clk/socfpga/clk.c
37114@@ -22,6 +22,7 @@
37115 #include <linux/clk-provider.h>
37116 #include <linux/io.h>
37117 #include <linux/of.h>
37118+#include <asm/pgtable.h>
37119
37120 /* Clock Manager offsets */
37121 #define CLKMGR_CTRL 0x0
37122@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37123 streq(clk_name, "periph_pll") ||
37124 streq(clk_name, "sdram_pll")) {
37125 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37126- clk_pll_ops.enable = clk_gate_ops.enable;
37127- clk_pll_ops.disable = clk_gate_ops.disable;
37128+ pax_open_kernel();
37129+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37130+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37131+ pax_close_kernel();
37132 }
37133
37134 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37135@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37136 return parent_rate / div;
37137 }
37138
37139-static struct clk_ops gateclk_ops = {
37140+static clk_ops_no_const gateclk_ops __read_only = {
37141 .recalc_rate = socfpga_clk_recalc_rate,
37142 .get_parent = socfpga_clk_get_parent,
37143 .set_parent = socfpga_clk_set_parent,
37144diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
37145index 08ae128..c73fc2b 100644
37146--- a/drivers/connector/cn_proc.c
37147+++ b/drivers/connector/cn_proc.c
37148@@ -65,6 +65,7 @@ void proc_fork_connector(struct task_struct *task)
37149
37150 msg = (struct cn_msg *)buffer;
37151 ev = (struct proc_event *)msg->data;
37152+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37153 get_seq(&msg->seq, &ev->cpu);
37154 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37155 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37156@@ -80,6 +81,7 @@ void proc_fork_connector(struct task_struct *task)
37157 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37158 msg->ack = 0; /* not used */
37159 msg->len = sizeof(*ev);
37160+ msg->flags = 0; /* not used */
37161 /* If cn_netlink_send() failed, the data is not sent */
37162 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37163 }
37164@@ -96,6 +98,7 @@ void proc_exec_connector(struct task_struct *task)
37165
37166 msg = (struct cn_msg *)buffer;
37167 ev = (struct proc_event *)msg->data;
37168+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37169 get_seq(&msg->seq, &ev->cpu);
37170 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37171 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37172@@ -106,6 +109,7 @@ void proc_exec_connector(struct task_struct *task)
37173 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37174 msg->ack = 0; /* not used */
37175 msg->len = sizeof(*ev);
37176+ msg->flags = 0; /* not used */
37177 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37178 }
37179
37180@@ -122,6 +126,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
37181
37182 msg = (struct cn_msg *)buffer;
37183 ev = (struct proc_event *)msg->data;
37184+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37185 ev->what = which_id;
37186 ev->event_data.id.process_pid = task->pid;
37187 ev->event_data.id.process_tgid = task->tgid;
37188@@ -145,6 +150,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
37189 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37190 msg->ack = 0; /* not used */
37191 msg->len = sizeof(*ev);
37192+ msg->flags = 0; /* not used */
37193 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37194 }
37195
37196@@ -160,6 +166,7 @@ void proc_sid_connector(struct task_struct *task)
37197
37198 msg = (struct cn_msg *)buffer;
37199 ev = (struct proc_event *)msg->data;
37200+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37201 get_seq(&msg->seq, &ev->cpu);
37202 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37203 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37204@@ -170,6 +177,7 @@ void proc_sid_connector(struct task_struct *task)
37205 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37206 msg->ack = 0; /* not used */
37207 msg->len = sizeof(*ev);
37208+ msg->flags = 0; /* not used */
37209 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37210 }
37211
37212@@ -185,6 +193,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
37213
37214 msg = (struct cn_msg *)buffer;
37215 ev = (struct proc_event *)msg->data;
37216+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37217 get_seq(&msg->seq, &ev->cpu);
37218 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37219 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37220@@ -203,6 +212,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
37221 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37222 msg->ack = 0; /* not used */
37223 msg->len = sizeof(*ev);
37224+ msg->flags = 0; /* not used */
37225 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37226 }
37227
37228@@ -218,6 +228,7 @@ void proc_comm_connector(struct task_struct *task)
37229
37230 msg = (struct cn_msg *)buffer;
37231 ev = (struct proc_event *)msg->data;
37232+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37233 get_seq(&msg->seq, &ev->cpu);
37234 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37235 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37236@@ -229,6 +240,7 @@ void proc_comm_connector(struct task_struct *task)
37237 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37238 msg->ack = 0; /* not used */
37239 msg->len = sizeof(*ev);
37240+ msg->flags = 0; /* not used */
37241 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37242 }
37243
37244@@ -244,6 +256,7 @@ void proc_coredump_connector(struct task_struct *task)
37245
37246 msg = (struct cn_msg *)buffer;
37247 ev = (struct proc_event *)msg->data;
37248+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37249 get_seq(&msg->seq, &ev->cpu);
37250 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37251 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37252@@ -254,6 +267,7 @@ void proc_coredump_connector(struct task_struct *task)
37253 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37254 msg->ack = 0; /* not used */
37255 msg->len = sizeof(*ev);
37256+ msg->flags = 0; /* not used */
37257 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37258 }
37259
37260@@ -269,6 +283,7 @@ void proc_exit_connector(struct task_struct *task)
37261
37262 msg = (struct cn_msg *)buffer;
37263 ev = (struct proc_event *)msg->data;
37264+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37265 get_seq(&msg->seq, &ev->cpu);
37266 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37267 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37268@@ -281,6 +296,7 @@ void proc_exit_connector(struct task_struct *task)
37269 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37270 msg->ack = 0; /* not used */
37271 msg->len = sizeof(*ev);
37272+ msg->flags = 0; /* not used */
37273 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37274 }
37275
37276@@ -304,6 +320,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
37277
37278 msg = (struct cn_msg *)buffer;
37279 ev = (struct proc_event *)msg->data;
37280+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37281 msg->seq = rcvd_seq;
37282 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37283 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37284@@ -313,6 +330,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
37285 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37286 msg->ack = rcvd_ack + 1;
37287 msg->len = sizeof(*ev);
37288+ msg->flags = 0; /* not used */
37289 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37290 }
37291
37292diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
37293index 6ecfa75..0daa11e 100644
37294--- a/drivers/connector/connector.c
37295+++ b/drivers/connector/connector.c
37296@@ -157,17 +157,18 @@ static int cn_call_callback(struct sk_buff *skb)
37297 static void cn_rx_skb(struct sk_buff *__skb)
37298 {
37299 struct nlmsghdr *nlh;
37300- int err;
37301 struct sk_buff *skb;
37302+ int len, err;
37303
37304 skb = skb_get(__skb);
37305
37306 if (skb->len >= NLMSG_HDRLEN) {
37307 nlh = nlmsg_hdr(skb);
37308+ len = nlmsg_len(nlh);
37309
37310- if (nlh->nlmsg_len < sizeof(struct cn_msg) ||
37311+ if (len < (int)sizeof(struct cn_msg) ||
37312 skb->len < nlh->nlmsg_len ||
37313- nlh->nlmsg_len > CONNECTOR_MAX_MSG_SIZE) {
37314+ len > CONNECTOR_MAX_MSG_SIZE) {
37315 kfree_skb(skb);
37316 return;
37317 }
37318diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37319index 3926402..37b580d 100644
37320--- a/drivers/cpufreq/acpi-cpufreq.c
37321+++ b/drivers/cpufreq/acpi-cpufreq.c
37322@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37323 return sprintf(buf, "%u\n", boost_enabled);
37324 }
37325
37326-static struct global_attr global_boost = __ATTR(boost, 0644,
37327+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37328 show_global_boost,
37329 store_global_boost);
37330
37331@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37332 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37333 per_cpu(acfreq_data, cpu) = data;
37334
37335- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37336- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37337+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37338+ pax_open_kernel();
37339+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37340+ pax_close_kernel();
37341+ }
37342
37343 result = acpi_processor_register_performance(data->acpi_data, cpu);
37344 if (result)
37345@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37346 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37347 break;
37348 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37349- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37350+ pax_open_kernel();
37351+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37352+ pax_close_kernel();
37353 policy->cur = get_cur_freq_on_cpu(cpu);
37354 break;
37355 default:
37356@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37357 acpi_processor_notify_smm(THIS_MODULE);
37358
37359 /* Check for APERF/MPERF support in hardware */
37360- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37361- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37362+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37363+ pax_open_kernel();
37364+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37365+ pax_close_kernel();
37366+ }
37367
37368 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37369 for (i = 0; i < perf->state_count; i++)
37370diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37371index f0a5e2b..0a7ee46 100644
37372--- a/drivers/cpufreq/cpufreq.c
37373+++ b/drivers/cpufreq/cpufreq.c
37374@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37375 return NOTIFY_OK;
37376 }
37377
37378-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37379+static struct notifier_block cpufreq_cpu_notifier = {
37380 .notifier_call = cpufreq_cpu_callback,
37381 };
37382
37383@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37384
37385 pr_debug("trying to register driver %s\n", driver_data->name);
37386
37387- if (driver_data->setpolicy)
37388- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37389+ if (driver_data->setpolicy) {
37390+ pax_open_kernel();
37391+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37392+ pax_close_kernel();
37393+ }
37394
37395 write_lock_irqsave(&cpufreq_driver_lock, flags);
37396 if (cpufreq_driver) {
37397diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37398index e59afaa..a53a3ff 100644
37399--- a/drivers/cpufreq/cpufreq_governor.c
37400+++ b/drivers/cpufreq/cpufreq_governor.c
37401@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37402 struct dbs_data *dbs_data;
37403 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37404 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37405- struct od_ops *od_ops = NULL;
37406+ const struct od_ops *od_ops = NULL;
37407 struct od_dbs_tuners *od_tuners = NULL;
37408 struct cs_dbs_tuners *cs_tuners = NULL;
37409 struct cpu_dbs_common_info *cpu_cdbs;
37410@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37411
37412 if ((cdata->governor == GOV_CONSERVATIVE) &&
37413 (!policy->governor->initialized)) {
37414- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37415+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37416
37417 cpufreq_register_notifier(cs_ops->notifier_block,
37418 CPUFREQ_TRANSITION_NOTIFIER);
37419@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37420
37421 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37422 (policy->governor->initialized == 1)) {
37423- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37424+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37425
37426 cpufreq_unregister_notifier(cs_ops->notifier_block,
37427 CPUFREQ_TRANSITION_NOTIFIER);
37428diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37429index d5f12b4..eb30af1 100644
37430--- a/drivers/cpufreq/cpufreq_governor.h
37431+++ b/drivers/cpufreq/cpufreq_governor.h
37432@@ -204,7 +204,7 @@ struct common_dbs_data {
37433 void (*exit)(struct dbs_data *dbs_data);
37434
37435 /* Governor specific ops, see below */
37436- void *gov_ops;
37437+ const void *gov_ops;
37438 };
37439
37440 /* Governer Per policy data */
37441@@ -224,7 +224,7 @@ struct od_ops {
37442 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37443 unsigned int freq_next, unsigned int relation);
37444 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37445-};
37446+} __no_const;
37447
37448 struct cs_ops {
37449 struct notifier_block *notifier_block;
37450diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37451index c087347..989aa2e 100644
37452--- a/drivers/cpufreq/cpufreq_ondemand.c
37453+++ b/drivers/cpufreq/cpufreq_ondemand.c
37454@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37455
37456 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37457
37458-static struct od_ops od_ops = {
37459+static struct od_ops od_ops __read_only = {
37460 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37461 .powersave_bias_target = generic_powersave_bias_target,
37462 .freq_increase = dbs_freq_increase,
37463@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37464 (struct cpufreq_policy *, unsigned int, unsigned int),
37465 unsigned int powersave_bias)
37466 {
37467- od_ops.powersave_bias_target = f;
37468+ pax_open_kernel();
37469+ *(void **)&od_ops.powersave_bias_target = f;
37470+ pax_close_kernel();
37471 od_set_powersave_bias(powersave_bias);
37472 }
37473 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37474
37475 void od_unregister_powersave_bias_handler(void)
37476 {
37477- od_ops.powersave_bias_target = generic_powersave_bias_target;
37478+ pax_open_kernel();
37479+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37480+ pax_close_kernel();
37481 od_set_powersave_bias(0);
37482 }
37483 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37484diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37485index d37568c..fbb19a1 100644
37486--- a/drivers/cpufreq/cpufreq_stats.c
37487+++ b/drivers/cpufreq/cpufreq_stats.c
37488@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37489 }
37490
37491 /* priority=1 so this will get called before cpufreq_remove_dev */
37492-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37493+static struct notifier_block cpufreq_stat_cpu_notifier = {
37494 .notifier_call = cpufreq_stat_cpu_callback,
37495 .priority = 1,
37496 };
37497diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37498index 9ee7817..17b658e 100644
37499--- a/drivers/cpufreq/p4-clockmod.c
37500+++ b/drivers/cpufreq/p4-clockmod.c
37501@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37502 case 0x0F: /* Core Duo */
37503 case 0x16: /* Celeron Core */
37504 case 0x1C: /* Atom */
37505- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37506+ pax_open_kernel();
37507+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37508+ pax_close_kernel();
37509 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37510 case 0x0D: /* Pentium M (Dothan) */
37511- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37512+ pax_open_kernel();
37513+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37514+ pax_close_kernel();
37515 /* fall through */
37516 case 0x09: /* Pentium M (Banias) */
37517 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37518@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37519
37520 /* on P-4s, the TSC runs with constant frequency independent whether
37521 * throttling is active or not. */
37522- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37523+ pax_open_kernel();
37524+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37525+ pax_close_kernel();
37526
37527 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37528 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37529diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37530index 880ee29..2445bc6 100644
37531--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37532+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37533@@ -18,14 +18,12 @@
37534 #include <asm/head.h>
37535 #include <asm/timer.h>
37536
37537-static struct cpufreq_driver *cpufreq_us3_driver;
37538-
37539 struct us3_freq_percpu_info {
37540 struct cpufreq_frequency_table table[4];
37541 };
37542
37543 /* Indexed by cpu number. */
37544-static struct us3_freq_percpu_info *us3_freq_table;
37545+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37546
37547 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37548 * in the Safari config register.
37549@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37550
37551 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37552 {
37553- if (cpufreq_us3_driver)
37554- us3_set_cpu_divider_index(policy, 0);
37555+ us3_set_cpu_divider_index(policy->cpu, 0);
37556
37557 return 0;
37558 }
37559
37560+static int __init us3_freq_init(void);
37561+static void __exit us3_freq_exit(void);
37562+
37563+static struct cpufreq_driver cpufreq_us3_driver = {
37564+ .init = us3_freq_cpu_init,
37565+ .verify = us3_freq_verify,
37566+ .target = us3_freq_target,
37567+ .get = us3_freq_get,
37568+ .exit = us3_freq_cpu_exit,
37569+ .owner = THIS_MODULE,
37570+ .name = "UltraSPARC-III",
37571+
37572+};
37573+
37574 static int __init us3_freq_init(void)
37575 {
37576 unsigned long manuf, impl, ver;
37577@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37578 (impl == CHEETAH_IMPL ||
37579 impl == CHEETAH_PLUS_IMPL ||
37580 impl == JAGUAR_IMPL ||
37581- impl == PANTHER_IMPL)) {
37582- struct cpufreq_driver *driver;
37583-
37584- ret = -ENOMEM;
37585- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37586- if (!driver)
37587- goto err_out;
37588-
37589- us3_freq_table = kzalloc(
37590- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37591- GFP_KERNEL);
37592- if (!us3_freq_table)
37593- goto err_out;
37594-
37595- driver->init = us3_freq_cpu_init;
37596- driver->verify = us3_freq_verify;
37597- driver->target = us3_freq_target;
37598- driver->get = us3_freq_get;
37599- driver->exit = us3_freq_cpu_exit;
37600- driver->owner = THIS_MODULE,
37601- strcpy(driver->name, "UltraSPARC-III");
37602-
37603- cpufreq_us3_driver = driver;
37604- ret = cpufreq_register_driver(driver);
37605- if (ret)
37606- goto err_out;
37607-
37608- return 0;
37609-
37610-err_out:
37611- if (driver) {
37612- kfree(driver);
37613- cpufreq_us3_driver = NULL;
37614- }
37615- kfree(us3_freq_table);
37616- us3_freq_table = NULL;
37617- return ret;
37618- }
37619+ impl == PANTHER_IMPL))
37620+ return cpufreq_register_driver(&cpufreq_us3_driver);
37621
37622 return -ENODEV;
37623 }
37624
37625 static void __exit us3_freq_exit(void)
37626 {
37627- if (cpufreq_us3_driver) {
37628- cpufreq_unregister_driver(cpufreq_us3_driver);
37629- kfree(cpufreq_us3_driver);
37630- cpufreq_us3_driver = NULL;
37631- kfree(us3_freq_table);
37632- us3_freq_table = NULL;
37633- }
37634+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37635 }
37636
37637 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37638diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37639index 0915e71..53376ed 100644
37640--- a/drivers/cpufreq/speedstep-centrino.c
37641+++ b/drivers/cpufreq/speedstep-centrino.c
37642@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37643 !cpu_has(cpu, X86_FEATURE_EST))
37644 return -ENODEV;
37645
37646- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37647- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37648+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37649+ pax_open_kernel();
37650+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37651+ pax_close_kernel();
37652+ }
37653
37654 if (policy->cpu != 0)
37655 return -ENODEV;
37656diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37657index fdc432f..98e64e2 100644
37658--- a/drivers/cpuidle/cpuidle.c
37659+++ b/drivers/cpuidle/cpuidle.c
37660@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37661
37662 static void poll_idle_init(struct cpuidle_driver *drv)
37663 {
37664- struct cpuidle_state *state = &drv->states[0];
37665+ cpuidle_state_no_const *state = &drv->states[0];
37666
37667 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37668 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37669diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37670index ea2f8e7..70ac501 100644
37671--- a/drivers/cpuidle/governor.c
37672+++ b/drivers/cpuidle/governor.c
37673@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37674 mutex_lock(&cpuidle_lock);
37675 if (__cpuidle_find_governor(gov->name) == NULL) {
37676 ret = 0;
37677- list_add_tail(&gov->governor_list, &cpuidle_governors);
37678+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37679 if (!cpuidle_curr_governor ||
37680 cpuidle_curr_governor->rating < gov->rating)
37681 cpuidle_switch_governor(gov);
37682@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37683 new_gov = cpuidle_replace_governor(gov->rating);
37684 cpuidle_switch_governor(new_gov);
37685 }
37686- list_del(&gov->governor_list);
37687+ pax_list_del((struct list_head *)&gov->governor_list);
37688 mutex_unlock(&cpuidle_lock);
37689 }
37690
37691diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37692index 428754a..8bdf9cc 100644
37693--- a/drivers/cpuidle/sysfs.c
37694+++ b/drivers/cpuidle/sysfs.c
37695@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37696 NULL
37697 };
37698
37699-static struct attribute_group cpuidle_attr_group = {
37700+static attribute_group_no_const cpuidle_attr_group = {
37701 .attrs = cpuidle_default_attrs,
37702 .name = "cpuidle",
37703 };
37704diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37705index 12fea3e..1e28f47 100644
37706--- a/drivers/crypto/hifn_795x.c
37707+++ b/drivers/crypto/hifn_795x.c
37708@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37709 MODULE_PARM_DESC(hifn_pll_ref,
37710 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37711
37712-static atomic_t hifn_dev_number;
37713+static atomic_unchecked_t hifn_dev_number;
37714
37715 #define ACRYPTO_OP_DECRYPT 0
37716 #define ACRYPTO_OP_ENCRYPT 1
37717@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37718 goto err_out_disable_pci_device;
37719
37720 snprintf(name, sizeof(name), "hifn%d",
37721- atomic_inc_return(&hifn_dev_number)-1);
37722+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37723
37724 err = pci_request_regions(pdev, name);
37725 if (err)
37726diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37727index e94e619..f7e249c 100644
37728--- a/drivers/devfreq/devfreq.c
37729+++ b/drivers/devfreq/devfreq.c
37730@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37731 goto err_out;
37732 }
37733
37734- list_add(&governor->node, &devfreq_governor_list);
37735+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37736
37737 list_for_each_entry(devfreq, &devfreq_list, node) {
37738 int ret = 0;
37739@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37740 }
37741 }
37742
37743- list_del(&governor->node);
37744+ pax_list_del((struct list_head *)&governor->node);
37745 err_out:
37746 mutex_unlock(&devfreq_list_lock);
37747
37748diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37749index 5039fbc..841169f 100644
37750--- a/drivers/dma/sh/shdma.c
37751+++ b/drivers/dma/sh/shdma.c
37752@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37753 return ret;
37754 }
37755
37756-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37757+static struct notifier_block sh_dmae_nmi_notifier = {
37758 .notifier_call = sh_dmae_nmi_handler,
37759
37760 /* Run before NMI debug handler and KGDB */
37761diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37762index 211021d..201d47f 100644
37763--- a/drivers/edac/edac_device.c
37764+++ b/drivers/edac/edac_device.c
37765@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37766 */
37767 int edac_device_alloc_index(void)
37768 {
37769- static atomic_t device_indexes = ATOMIC_INIT(0);
37770+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37771
37772- return atomic_inc_return(&device_indexes) - 1;
37773+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37774 }
37775 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37776
37777diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37778index e7c32c4..6397af1 100644
37779--- a/drivers/edac/edac_mc_sysfs.c
37780+++ b/drivers/edac/edac_mc_sysfs.c
37781@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37782 struct dev_ch_attribute {
37783 struct device_attribute attr;
37784 int channel;
37785-};
37786+} __do_const;
37787
37788 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37789 struct dev_ch_attribute dev_attr_legacy_##_name = \
37790@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37791 }
37792
37793 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37794+ pax_open_kernel();
37795 if (mci->get_sdram_scrub_rate) {
37796- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37797- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37798+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37799+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37800 }
37801 if (mci->set_sdram_scrub_rate) {
37802- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37803- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37804+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37805+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37806 }
37807+ pax_close_kernel();
37808 err = device_create_file(&mci->dev,
37809 &dev_attr_sdram_scrub_rate);
37810 if (err) {
37811diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37812index dd370f9..0281629 100644
37813--- a/drivers/edac/edac_pci.c
37814+++ b/drivers/edac/edac_pci.c
37815@@ -29,7 +29,7 @@
37816
37817 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37818 static LIST_HEAD(edac_pci_list);
37819-static atomic_t pci_indexes = ATOMIC_INIT(0);
37820+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37821
37822 /*
37823 * edac_pci_alloc_ctl_info
37824@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37825 */
37826 int edac_pci_alloc_index(void)
37827 {
37828- return atomic_inc_return(&pci_indexes) - 1;
37829+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37830 }
37831 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37832
37833diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37834index e8658e4..22746d6 100644
37835--- a/drivers/edac/edac_pci_sysfs.c
37836+++ b/drivers/edac/edac_pci_sysfs.c
37837@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37838 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37839 static int edac_pci_poll_msec = 1000; /* one second workq period */
37840
37841-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37842-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37843+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37844+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37845
37846 static struct kobject *edac_pci_top_main_kobj;
37847 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37848@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37849 void *value;
37850 ssize_t(*show) (void *, char *);
37851 ssize_t(*store) (void *, const char *, size_t);
37852-};
37853+} __do_const;
37854
37855 /* Set of show/store abstract level functions for PCI Parity object */
37856 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37857@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37858 edac_printk(KERN_CRIT, EDAC_PCI,
37859 "Signaled System Error on %s\n",
37860 pci_name(dev));
37861- atomic_inc(&pci_nonparity_count);
37862+ atomic_inc_unchecked(&pci_nonparity_count);
37863 }
37864
37865 if (status & (PCI_STATUS_PARITY)) {
37866@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37867 "Master Data Parity Error on %s\n",
37868 pci_name(dev));
37869
37870- atomic_inc(&pci_parity_count);
37871+ atomic_inc_unchecked(&pci_parity_count);
37872 }
37873
37874 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37875@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37876 "Detected Parity Error on %s\n",
37877 pci_name(dev));
37878
37879- atomic_inc(&pci_parity_count);
37880+ atomic_inc_unchecked(&pci_parity_count);
37881 }
37882 }
37883
37884@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37885 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37886 "Signaled System Error on %s\n",
37887 pci_name(dev));
37888- atomic_inc(&pci_nonparity_count);
37889+ atomic_inc_unchecked(&pci_nonparity_count);
37890 }
37891
37892 if (status & (PCI_STATUS_PARITY)) {
37893@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37894 "Master Data Parity Error on "
37895 "%s\n", pci_name(dev));
37896
37897- atomic_inc(&pci_parity_count);
37898+ atomic_inc_unchecked(&pci_parity_count);
37899 }
37900
37901 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37902@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37903 "Detected Parity Error on %s\n",
37904 pci_name(dev));
37905
37906- atomic_inc(&pci_parity_count);
37907+ atomic_inc_unchecked(&pci_parity_count);
37908 }
37909 }
37910 }
37911@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37912 if (!check_pci_errors)
37913 return;
37914
37915- before_count = atomic_read(&pci_parity_count);
37916+ before_count = atomic_read_unchecked(&pci_parity_count);
37917
37918 /* scan all PCI devices looking for a Parity Error on devices and
37919 * bridges.
37920@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37921 /* Only if operator has selected panic on PCI Error */
37922 if (edac_pci_get_panic_on_pe()) {
37923 /* If the count is different 'after' from 'before' */
37924- if (before_count != atomic_read(&pci_parity_count))
37925+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37926 panic("EDAC: PCI Parity Error");
37927 }
37928 }
37929diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37930index 51b7e3a..aa8a3e8 100644
37931--- a/drivers/edac/mce_amd.h
37932+++ b/drivers/edac/mce_amd.h
37933@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37934 bool (*mc0_mce)(u16, u8);
37935 bool (*mc1_mce)(u16, u8);
37936 bool (*mc2_mce)(u16, u8);
37937-};
37938+} __no_const;
37939
37940 void amd_report_gart_errors(bool);
37941 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37942diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37943index 57ea7f4..af06b76 100644
37944--- a/drivers/firewire/core-card.c
37945+++ b/drivers/firewire/core-card.c
37946@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37947 const struct fw_card_driver *driver,
37948 struct device *device)
37949 {
37950- static atomic_t index = ATOMIC_INIT(-1);
37951+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37952
37953- card->index = atomic_inc_return(&index);
37954+ card->index = atomic_inc_return_unchecked(&index);
37955 card->driver = driver;
37956 card->device = device;
37957 card->current_tlabel = 0;
37958@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37959
37960 void fw_core_remove_card(struct fw_card *card)
37961 {
37962- struct fw_card_driver dummy_driver = dummy_driver_template;
37963+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37964
37965 card->driver->update_phy_reg(card, 4,
37966 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37967diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37968index de4aa40..49ab1f2 100644
37969--- a/drivers/firewire/core-device.c
37970+++ b/drivers/firewire/core-device.c
37971@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37972 struct config_rom_attribute {
37973 struct device_attribute attr;
37974 u32 key;
37975-};
37976+} __do_const;
37977
37978 static ssize_t show_immediate(struct device *dev,
37979 struct device_attribute *dattr, char *buf)
37980diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37981index 28a94c7..58da63a 100644
37982--- a/drivers/firewire/core-transaction.c
37983+++ b/drivers/firewire/core-transaction.c
37984@@ -38,6 +38,7 @@
37985 #include <linux/timer.h>
37986 #include <linux/types.h>
37987 #include <linux/workqueue.h>
37988+#include <linux/sched.h>
37989
37990 #include <asm/byteorder.h>
37991
37992diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37993index 515a42c..5ecf3ba 100644
37994--- a/drivers/firewire/core.h
37995+++ b/drivers/firewire/core.h
37996@@ -111,6 +111,7 @@ struct fw_card_driver {
37997
37998 int (*stop_iso)(struct fw_iso_context *ctx);
37999 };
38000+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38001
38002 void fw_card_initialize(struct fw_card *card,
38003 const struct fw_card_driver *driver, struct device *device);
38004diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38005index 94a58a0..f5eba42 100644
38006--- a/drivers/firmware/dmi-id.c
38007+++ b/drivers/firmware/dmi-id.c
38008@@ -16,7 +16,7 @@
38009 struct dmi_device_attribute{
38010 struct device_attribute dev_attr;
38011 int field;
38012-};
38013+} __do_const;
38014 #define to_dmi_dev_attr(_dev_attr) \
38015 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38016
38017diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38018index 232fa8f..386c255 100644
38019--- a/drivers/firmware/dmi_scan.c
38020+++ b/drivers/firmware/dmi_scan.c
38021@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
38022 }
38023 }
38024 else {
38025- /*
38026- * no iounmap() for that ioremap(); it would be a no-op, but
38027- * it's so early in setup that sucker gets confused into doing
38028- * what it shouldn't if we actually call it.
38029- */
38030 p = dmi_ioremap(0xF0000, 0x10000);
38031 if (p == NULL)
38032 goto error;
38033@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38034 if (buf == NULL)
38035 return -1;
38036
38037- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38038+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38039
38040 iounmap(buf);
38041 return 0;
38042diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38043index 5145fa3..0d3babd 100644
38044--- a/drivers/firmware/efi/efi.c
38045+++ b/drivers/firmware/efi/efi.c
38046@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38047 };
38048
38049 static struct efivars generic_efivars;
38050-static struct efivar_operations generic_ops;
38051+static efivar_operations_no_const generic_ops __read_only;
38052
38053 static int generic_ops_register(void)
38054 {
38055- generic_ops.get_variable = efi.get_variable;
38056- generic_ops.set_variable = efi.set_variable;
38057- generic_ops.get_next_variable = efi.get_next_variable;
38058- generic_ops.query_variable_store = efi_query_variable_store;
38059+ pax_open_kernel();
38060+ *(void **)&generic_ops.get_variable = efi.get_variable;
38061+ *(void **)&generic_ops.set_variable = efi.set_variable;
38062+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38063+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38064+ pax_close_kernel();
38065
38066 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38067 }
38068diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38069index 8a7432a..28fb839 100644
38070--- a/drivers/firmware/efi/efivars.c
38071+++ b/drivers/firmware/efi/efivars.c
38072@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38073 static int
38074 create_efivars_bin_attributes(void)
38075 {
38076- struct bin_attribute *attr;
38077+ bin_attribute_no_const *attr;
38078 int error;
38079
38080 /* new_var */
38081diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38082index 2a90ba6..07f3733 100644
38083--- a/drivers/firmware/google/memconsole.c
38084+++ b/drivers/firmware/google/memconsole.c
38085@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38086 if (!found_memconsole())
38087 return -ENODEV;
38088
38089- memconsole_bin_attr.size = memconsole_length;
38090+ pax_open_kernel();
38091+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38092+ pax_close_kernel();
38093
38094 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38095
38096diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38097index 2729e3d..f9deca1 100644
38098--- a/drivers/gpio/gpio-ich.c
38099+++ b/drivers/gpio/gpio-ich.c
38100@@ -71,7 +71,7 @@ struct ichx_desc {
38101 /* Some chipsets have quirks, let these use their own request/get */
38102 int (*request)(struct gpio_chip *chip, unsigned offset);
38103 int (*get)(struct gpio_chip *chip, unsigned offset);
38104-};
38105+} __do_const;
38106
38107 static struct {
38108 spinlock_t lock;
38109diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38110index 9902732..64b62dd 100644
38111--- a/drivers/gpio/gpio-vr41xx.c
38112+++ b/drivers/gpio/gpio-vr41xx.c
38113@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38114 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38115 maskl, pendl, maskh, pendh);
38116
38117- atomic_inc(&irq_err_count);
38118+ atomic_inc_unchecked(&irq_err_count);
38119
38120 return -EINVAL;
38121 }
38122diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38123index 6a64749..0767a9f 100644
38124--- a/drivers/gpu/drm/drm_crtc_helper.c
38125+++ b/drivers/gpu/drm/drm_crtc_helper.c
38126@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38127 struct drm_crtc *tmp;
38128 int crtc_mask = 1;
38129
38130- WARN(!crtc, "checking null crtc?\n");
38131+ BUG_ON(!crtc);
38132
38133 dev = crtc->dev;
38134
38135diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38136index 99fcd7c..13cf6c5 100644
38137--- a/drivers/gpu/drm/drm_drv.c
38138+++ b/drivers/gpu/drm/drm_drv.c
38139@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
38140 /**
38141 * Copy and IOCTL return string to user space
38142 */
38143-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38144+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38145 {
38146 int len;
38147
38148@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
38149 struct drm_file *file_priv = filp->private_data;
38150 struct drm_device *dev;
38151 const struct drm_ioctl_desc *ioctl = NULL;
38152- drm_ioctl_t *func;
38153+ drm_ioctl_no_const_t func;
38154 unsigned int nr = DRM_IOCTL_NR(cmd);
38155 int retcode = -EINVAL;
38156 char stack_kdata[128];
38157@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
38158 return -ENODEV;
38159
38160 atomic_inc(&dev->ioctl_count);
38161- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38162+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38163 ++file_priv->ioctl_count;
38164
38165 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38166diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38167index 3a24385..4e426e0 100644
38168--- a/drivers/gpu/drm/drm_fops.c
38169+++ b/drivers/gpu/drm/drm_fops.c
38170@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38171 }
38172
38173 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38174- atomic_set(&dev->counts[i], 0);
38175+ atomic_set_unchecked(&dev->counts[i], 0);
38176
38177 dev->sigdata.lock = NULL;
38178
38179@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38180 if (drm_device_is_unplugged(dev))
38181 return -ENODEV;
38182
38183- if (!dev->open_count++)
38184+ if (local_inc_return(&dev->open_count) == 1)
38185 need_setup = 1;
38186 mutex_lock(&dev->struct_mutex);
38187 old_imapping = inode->i_mapping;
38188@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38189 retcode = drm_open_helper(inode, filp, dev);
38190 if (retcode)
38191 goto err_undo;
38192- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38193+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38194 if (need_setup) {
38195 retcode = drm_setup(dev);
38196 if (retcode)
38197@@ -166,7 +166,7 @@ err_undo:
38198 iput(container_of(dev->dev_mapping, struct inode, i_data));
38199 dev->dev_mapping = old_mapping;
38200 mutex_unlock(&dev->struct_mutex);
38201- dev->open_count--;
38202+ local_dec(&dev->open_count);
38203 return retcode;
38204 }
38205 EXPORT_SYMBOL(drm_open);
38206@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38207
38208 mutex_lock(&drm_global_mutex);
38209
38210- DRM_DEBUG("open_count = %d\n", dev->open_count);
38211+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38212
38213 if (dev->driver->preclose)
38214 dev->driver->preclose(dev, file_priv);
38215@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38216 * Begin inline drm_release
38217 */
38218
38219- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38220+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38221 task_pid_nr(current),
38222 (long)old_encode_dev(file_priv->minor->device),
38223- dev->open_count);
38224+ local_read(&dev->open_count));
38225
38226 /* Release any auth tokens that might point to this file_priv,
38227 (do that under the drm_global_mutex) */
38228@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38229 * End inline drm_release
38230 */
38231
38232- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38233- if (!--dev->open_count) {
38234+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38235+ if (local_dec_and_test(&dev->open_count)) {
38236 if (atomic_read(&dev->ioctl_count)) {
38237 DRM_ERROR("Device busy: %d\n",
38238 atomic_read(&dev->ioctl_count));
38239diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38240index f731116..629842c 100644
38241--- a/drivers/gpu/drm/drm_global.c
38242+++ b/drivers/gpu/drm/drm_global.c
38243@@ -36,7 +36,7 @@
38244 struct drm_global_item {
38245 struct mutex mutex;
38246 void *object;
38247- int refcount;
38248+ atomic_t refcount;
38249 };
38250
38251 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38252@@ -49,7 +49,7 @@ void drm_global_init(void)
38253 struct drm_global_item *item = &glob[i];
38254 mutex_init(&item->mutex);
38255 item->object = NULL;
38256- item->refcount = 0;
38257+ atomic_set(&item->refcount, 0);
38258 }
38259 }
38260
38261@@ -59,7 +59,7 @@ void drm_global_release(void)
38262 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38263 struct drm_global_item *item = &glob[i];
38264 BUG_ON(item->object != NULL);
38265- BUG_ON(item->refcount != 0);
38266+ BUG_ON(atomic_read(&item->refcount) != 0);
38267 }
38268 }
38269
38270@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38271 void *object;
38272
38273 mutex_lock(&item->mutex);
38274- if (item->refcount == 0) {
38275+ if (atomic_read(&item->refcount) == 0) {
38276 item->object = kzalloc(ref->size, GFP_KERNEL);
38277 if (unlikely(item->object == NULL)) {
38278 ret = -ENOMEM;
38279@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38280 goto out_err;
38281
38282 }
38283- ++item->refcount;
38284+ atomic_inc(&item->refcount);
38285 ref->object = item->object;
38286 object = item->object;
38287 mutex_unlock(&item->mutex);
38288@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38289 struct drm_global_item *item = &glob[ref->global_type];
38290
38291 mutex_lock(&item->mutex);
38292- BUG_ON(item->refcount == 0);
38293+ BUG_ON(atomic_read(&item->refcount) == 0);
38294 BUG_ON(ref->object != item->object);
38295- if (--item->refcount == 0) {
38296+ if (atomic_dec_and_test(&item->refcount)) {
38297 ref->release(ref);
38298 item->object = NULL;
38299 }
38300diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38301index d4b20ce..77a8d41 100644
38302--- a/drivers/gpu/drm/drm_info.c
38303+++ b/drivers/gpu/drm/drm_info.c
38304@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38305 struct drm_local_map *map;
38306 struct drm_map_list *r_list;
38307
38308- /* Hardcoded from _DRM_FRAME_BUFFER,
38309- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38310- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38311- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38312+ static const char * const types[] = {
38313+ [_DRM_FRAME_BUFFER] = "FB",
38314+ [_DRM_REGISTERS] = "REG",
38315+ [_DRM_SHM] = "SHM",
38316+ [_DRM_AGP] = "AGP",
38317+ [_DRM_SCATTER_GATHER] = "SG",
38318+ [_DRM_CONSISTENT] = "PCI",
38319+ [_DRM_GEM] = "GEM" };
38320 const char *type;
38321 int i;
38322
38323@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38324 map = r_list->map;
38325 if (!map)
38326 continue;
38327- if (map->type < 0 || map->type > 5)
38328+ if (map->type >= ARRAY_SIZE(types))
38329 type = "??";
38330 else
38331 type = types[map->type];
38332@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38333 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38334 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38335 vma->vm_flags & VM_IO ? 'i' : '-',
38336+#ifdef CONFIG_GRKERNSEC_HIDESYM
38337+ 0);
38338+#else
38339 vma->vm_pgoff);
38340+#endif
38341
38342 #if defined(__i386__)
38343 pgprot = pgprot_val(vma->vm_page_prot);
38344diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38345index 2f4c434..dd12cd2 100644
38346--- a/drivers/gpu/drm/drm_ioc32.c
38347+++ b/drivers/gpu/drm/drm_ioc32.c
38348@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38349 request = compat_alloc_user_space(nbytes);
38350 if (!access_ok(VERIFY_WRITE, request, nbytes))
38351 return -EFAULT;
38352- list = (struct drm_buf_desc *) (request + 1);
38353+ list = (struct drm_buf_desc __user *) (request + 1);
38354
38355 if (__put_user(count, &request->count)
38356 || __put_user(list, &request->list))
38357@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38358 request = compat_alloc_user_space(nbytes);
38359 if (!access_ok(VERIFY_WRITE, request, nbytes))
38360 return -EFAULT;
38361- list = (struct drm_buf_pub *) (request + 1);
38362+ list = (struct drm_buf_pub __user *) (request + 1);
38363
38364 if (__put_user(count, &request->count)
38365 || __put_user(list, &request->list))
38366@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38367 return 0;
38368 }
38369
38370-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38371+drm_ioctl_compat_t drm_compat_ioctls[] = {
38372 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38373 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38374 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38375@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38376 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38377 {
38378 unsigned int nr = DRM_IOCTL_NR(cmd);
38379- drm_ioctl_compat_t *fn;
38380 int ret;
38381
38382 /* Assume that ioctls without an explicit compat routine will just
38383@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38384 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38385 return drm_ioctl(filp, cmd, arg);
38386
38387- fn = drm_compat_ioctls[nr];
38388-
38389- if (fn != NULL)
38390- ret = (*fn) (filp, cmd, arg);
38391+ if (drm_compat_ioctls[nr] != NULL)
38392+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38393 else
38394 ret = drm_ioctl(filp, cmd, arg);
38395
38396diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38397index ffd7a7b..a64643e 100644
38398--- a/drivers/gpu/drm/drm_ioctl.c
38399+++ b/drivers/gpu/drm/drm_ioctl.c
38400@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38401 stats->data[i].value =
38402 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38403 else
38404- stats->data[i].value = atomic_read(&dev->counts[i]);
38405+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38406 stats->data[i].type = dev->types[i];
38407 }
38408
38409diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38410index d752c96..fe08455 100644
38411--- a/drivers/gpu/drm/drm_lock.c
38412+++ b/drivers/gpu/drm/drm_lock.c
38413@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38414 if (drm_lock_take(&master->lock, lock->context)) {
38415 master->lock.file_priv = file_priv;
38416 master->lock.lock_time = jiffies;
38417- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38418+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38419 break; /* Got lock */
38420 }
38421
38422@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38423 return -EINVAL;
38424 }
38425
38426- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38427+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38428
38429 if (drm_lock_free(&master->lock, lock->context)) {
38430 /* FIXME: Should really bail out here. */
38431diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38432index 327ca19..684d3c0 100644
38433--- a/drivers/gpu/drm/drm_stub.c
38434+++ b/drivers/gpu/drm/drm_stub.c
38435@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38436
38437 drm_device_set_unplugged(dev);
38438
38439- if (dev->open_count == 0) {
38440+ if (local_read(&dev->open_count) == 0) {
38441 drm_put_dev(dev);
38442 }
38443 mutex_unlock(&drm_global_mutex);
38444diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38445index 2290b3b..22056a1 100644
38446--- a/drivers/gpu/drm/drm_sysfs.c
38447+++ b/drivers/gpu/drm/drm_sysfs.c
38448@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38449 int drm_sysfs_device_add(struct drm_minor *minor)
38450 {
38451 int err;
38452- char *minor_str;
38453+ const char *minor_str;
38454
38455 minor->kdev.parent = minor->dev->dev;
38456
38457diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38458index ada49ed..29275a0 100644
38459--- a/drivers/gpu/drm/i810/i810_dma.c
38460+++ b/drivers/gpu/drm/i810/i810_dma.c
38461@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38462 dma->buflist[vertex->idx],
38463 vertex->discard, vertex->used);
38464
38465- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38466- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38467+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38468+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38469 sarea_priv->last_enqueue = dev_priv->counter - 1;
38470 sarea_priv->last_dispatch = (int)hw_status[5];
38471
38472@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38473 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38474 mc->last_render);
38475
38476- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38477- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38478+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38479+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38480 sarea_priv->last_enqueue = dev_priv->counter - 1;
38481 sarea_priv->last_dispatch = (int)hw_status[5];
38482
38483diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38484index 6e0acad..93c8289 100644
38485--- a/drivers/gpu/drm/i810/i810_drv.h
38486+++ b/drivers/gpu/drm/i810/i810_drv.h
38487@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38488 int page_flipping;
38489
38490 wait_queue_head_t irq_queue;
38491- atomic_t irq_received;
38492- atomic_t irq_emitted;
38493+ atomic_unchecked_t irq_received;
38494+ atomic_unchecked_t irq_emitted;
38495
38496 int front_offset;
38497 } drm_i810_private_t;
38498diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38499index 47d6c74..279123f 100644
38500--- a/drivers/gpu/drm/i915/i915_debugfs.c
38501+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38502@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38503 I915_READ(GTIMR));
38504 }
38505 seq_printf(m, "Interrupts received: %d\n",
38506- atomic_read(&dev_priv->irq_received));
38507+ atomic_read_unchecked(&dev_priv->irq_received));
38508 for_each_ring(ring, dev_priv, i) {
38509 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38510 seq_printf(m,
38511diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38512index f466980..8f2883f 100644
38513--- a/drivers/gpu/drm/i915/i915_dma.c
38514+++ b/drivers/gpu/drm/i915/i915_dma.c
38515@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38516 bool can_switch;
38517
38518 spin_lock(&dev->count_lock);
38519- can_switch = (dev->open_count == 0);
38520+ can_switch = (local_read(&dev->open_count) == 0);
38521 spin_unlock(&dev->count_lock);
38522 return can_switch;
38523 }
38524diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38525index 2f09e80..077876d 100644
38526--- a/drivers/gpu/drm/i915/i915_drv.h
38527+++ b/drivers/gpu/drm/i915/i915_drv.h
38528@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38529 drm_dma_handle_t *status_page_dmah;
38530 struct resource mch_res;
38531
38532- atomic_t irq_received;
38533+ atomic_unchecked_t irq_received;
38534
38535 /* protects the irq masks */
38536 spinlock_t irq_lock;
38537diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38538index 87a3227..cd13d8f 100644
38539--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38540+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38541@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38542
38543 static int
38544 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38545- int count)
38546+ unsigned int count)
38547 {
38548- int i;
38549+ unsigned int i;
38550 int relocs_total = 0;
38551 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38552
38553diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38554index 3c59584..500f2e9 100644
38555--- a/drivers/gpu/drm/i915/i915_ioc32.c
38556+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38557@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38558 (unsigned long)request);
38559 }
38560
38561-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38562+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38563 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38564 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38565 [DRM_I915_GETPARAM] = compat_i915_getparam,
38566@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38567 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38568 {
38569 unsigned int nr = DRM_IOCTL_NR(cmd);
38570- drm_ioctl_compat_t *fn = NULL;
38571 int ret;
38572
38573 if (nr < DRM_COMMAND_BASE)
38574 return drm_compat_ioctl(filp, cmd, arg);
38575
38576- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38577- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38578-
38579- if (fn != NULL)
38580+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38581+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38582 ret = (*fn) (filp, cmd, arg);
38583- else
38584+ } else
38585 ret = drm_ioctl(filp, cmd, arg);
38586
38587 return ret;
38588diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38589index 46d46ba..6e49848 100644
38590--- a/drivers/gpu/drm/i915/i915_irq.c
38591+++ b/drivers/gpu/drm/i915/i915_irq.c
38592@@ -975,7 +975,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38593 int pipe;
38594 u32 pipe_stats[I915_MAX_PIPES];
38595
38596- atomic_inc(&dev_priv->irq_received);
38597+ atomic_inc_unchecked(&dev_priv->irq_received);
38598
38599 while (true) {
38600 iir = I915_READ(VLV_IIR);
38601@@ -1192,7 +1192,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38602 irqreturn_t ret = IRQ_NONE;
38603 int i;
38604
38605- atomic_inc(&dev_priv->irq_received);
38606+ atomic_inc_unchecked(&dev_priv->irq_received);
38607
38608 /* We get interrupts on unclaimed registers, so check for this before we
38609 * do any I915_{READ,WRITE}. */
38610@@ -1312,7 +1312,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38611 int ret = IRQ_NONE;
38612 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38613
38614- atomic_inc(&dev_priv->irq_received);
38615+ atomic_inc_unchecked(&dev_priv->irq_received);
38616
38617 /* disable master interrupt before clearing iir */
38618 de_ier = I915_READ(DEIER);
38619@@ -2617,7 +2617,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38620 {
38621 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38622
38623- atomic_set(&dev_priv->irq_received, 0);
38624+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38625
38626 I915_WRITE(HWSTAM, 0xeffe);
38627
38628@@ -2639,7 +2639,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38629 {
38630 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38631
38632- atomic_set(&dev_priv->irq_received, 0);
38633+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38634
38635 I915_WRITE(HWSTAM, 0xeffe);
38636
38637@@ -2667,7 +2667,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38638 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38639 int pipe;
38640
38641- atomic_set(&dev_priv->irq_received, 0);
38642+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38643
38644 /* VLV magic */
38645 I915_WRITE(VLV_IMR, 0);
38646@@ -2979,7 +2979,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38647 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38648 int pipe;
38649
38650- atomic_set(&dev_priv->irq_received, 0);
38651+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38652
38653 for_each_pipe(pipe)
38654 I915_WRITE(PIPESTAT(pipe), 0);
38655@@ -3058,7 +3058,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38656 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38657 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38658
38659- atomic_inc(&dev_priv->irq_received);
38660+ atomic_inc_unchecked(&dev_priv->irq_received);
38661
38662 iir = I915_READ16(IIR);
38663 if (iir == 0)
38664@@ -3133,7 +3133,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38665 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38666 int pipe;
38667
38668- atomic_set(&dev_priv->irq_received, 0);
38669+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38670
38671 if (I915_HAS_HOTPLUG(dev)) {
38672 I915_WRITE(PORT_HOTPLUG_EN, 0);
38673@@ -3232,7 +3232,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38674 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38675 int pipe, ret = IRQ_NONE;
38676
38677- atomic_inc(&dev_priv->irq_received);
38678+ atomic_inc_unchecked(&dev_priv->irq_received);
38679
38680 iir = I915_READ(IIR);
38681 do {
38682@@ -3356,7 +3356,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38683 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38684 int pipe;
38685
38686- atomic_set(&dev_priv->irq_received, 0);
38687+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38688
38689 I915_WRITE(PORT_HOTPLUG_EN, 0);
38690 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38691@@ -3465,7 +3465,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38692 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38693 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38694
38695- atomic_inc(&dev_priv->irq_received);
38696+ atomic_inc_unchecked(&dev_priv->irq_received);
38697
38698 iir = I915_READ(IIR);
38699
38700diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38701index 90a7c17..ecedc6a 100644
38702--- a/drivers/gpu/drm/i915/intel_display.c
38703+++ b/drivers/gpu/drm/i915/intel_display.c
38704@@ -9424,13 +9424,13 @@ struct intel_quirk {
38705 int subsystem_vendor;
38706 int subsystem_device;
38707 void (*hook)(struct drm_device *dev);
38708-};
38709+} __do_const;
38710
38711 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38712 struct intel_dmi_quirk {
38713 void (*hook)(struct drm_device *dev);
38714 const struct dmi_system_id (*dmi_id_list)[];
38715-};
38716+} __do_const;
38717
38718 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38719 {
38720@@ -9438,18 +9438,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38721 return 1;
38722 }
38723
38724-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38725+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38726 {
38727- .dmi_id_list = &(const struct dmi_system_id[]) {
38728- {
38729- .callback = intel_dmi_reverse_brightness,
38730- .ident = "NCR Corporation",
38731- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38732- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38733- },
38734- },
38735- { } /* terminating entry */
38736+ .callback = intel_dmi_reverse_brightness,
38737+ .ident = "NCR Corporation",
38738+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38739+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38740 },
38741+ },
38742+ { } /* terminating entry */
38743+};
38744+
38745+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38746+ {
38747+ .dmi_id_list = &intel_dmi_quirks_table,
38748 .hook = quirk_invert_brightness,
38749 },
38750 };
38751diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38752index 54558a0..2d97005 100644
38753--- a/drivers/gpu/drm/mga/mga_drv.h
38754+++ b/drivers/gpu/drm/mga/mga_drv.h
38755@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38756 u32 clear_cmd;
38757 u32 maccess;
38758
38759- atomic_t vbl_received; /**< Number of vblanks received. */
38760+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38761 wait_queue_head_t fence_queue;
38762- atomic_t last_fence_retired;
38763+ atomic_unchecked_t last_fence_retired;
38764 u32 next_fence_to_post;
38765
38766 unsigned int fb_cpp;
38767diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38768index 709e90d..89a1c0d 100644
38769--- a/drivers/gpu/drm/mga/mga_ioc32.c
38770+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38771@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38772 return 0;
38773 }
38774
38775-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38776+drm_ioctl_compat_t mga_compat_ioctls[] = {
38777 [DRM_MGA_INIT] = compat_mga_init,
38778 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38779 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38780@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38781 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38782 {
38783 unsigned int nr = DRM_IOCTL_NR(cmd);
38784- drm_ioctl_compat_t *fn = NULL;
38785 int ret;
38786
38787 if (nr < DRM_COMMAND_BASE)
38788 return drm_compat_ioctl(filp, cmd, arg);
38789
38790- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38791- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38792-
38793- if (fn != NULL)
38794+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38795+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38796 ret = (*fn) (filp, cmd, arg);
38797- else
38798+ } else
38799 ret = drm_ioctl(filp, cmd, arg);
38800
38801 return ret;
38802diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38803index 598c281..60d590e 100644
38804--- a/drivers/gpu/drm/mga/mga_irq.c
38805+++ b/drivers/gpu/drm/mga/mga_irq.c
38806@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38807 if (crtc != 0)
38808 return 0;
38809
38810- return atomic_read(&dev_priv->vbl_received);
38811+ return atomic_read_unchecked(&dev_priv->vbl_received);
38812 }
38813
38814
38815@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38816 /* VBLANK interrupt */
38817 if (status & MGA_VLINEPEN) {
38818 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38819- atomic_inc(&dev_priv->vbl_received);
38820+ atomic_inc_unchecked(&dev_priv->vbl_received);
38821 drm_handle_vblank(dev, 0);
38822 handled = 1;
38823 }
38824@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38825 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38826 MGA_WRITE(MGA_PRIMEND, prim_end);
38827
38828- atomic_inc(&dev_priv->last_fence_retired);
38829+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38830 DRM_WAKEUP(&dev_priv->fence_queue);
38831 handled = 1;
38832 }
38833@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38834 * using fences.
38835 */
38836 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38837- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38838+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38839 - *sequence) <= (1 << 23)));
38840
38841 *sequence = cur_fence;
38842diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38843index 3e72876..d1c15ad 100644
38844--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38845+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38846@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38847 struct bit_table {
38848 const char id;
38849 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38850-};
38851+} __no_const;
38852
38853 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38854
38855diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38856index 41ff7e0..fa854ef 100644
38857--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38858+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38859@@ -92,7 +92,6 @@ struct nouveau_drm {
38860 struct drm_global_reference mem_global_ref;
38861 struct ttm_bo_global_ref bo_global_ref;
38862 struct ttm_bo_device bdev;
38863- atomic_t validate_sequence;
38864 int (*move)(struct nouveau_channel *,
38865 struct ttm_buffer_object *,
38866 struct ttm_mem_reg *, struct ttm_mem_reg *);
38867diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38868index 08214bc..9208577 100644
38869--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38870+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38871@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38872 unsigned long arg)
38873 {
38874 unsigned int nr = DRM_IOCTL_NR(cmd);
38875- drm_ioctl_compat_t *fn = NULL;
38876+ drm_ioctl_compat_t fn = NULL;
38877 int ret;
38878
38879 if (nr < DRM_COMMAND_BASE)
38880diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38881index 25d3495..d81aaf6 100644
38882--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38883+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38884@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38885 bool can_switch;
38886
38887 spin_lock(&dev->count_lock);
38888- can_switch = (dev->open_count == 0);
38889+ can_switch = (local_read(&dev->open_count) == 0);
38890 spin_unlock(&dev->count_lock);
38891 return can_switch;
38892 }
38893diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38894index 1dfd84c..104896c 100644
38895--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38896+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38897@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38898 }
38899 }
38900
38901-static struct vm_operations_struct qxl_ttm_vm_ops;
38902+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38903 static const struct vm_operations_struct *ttm_vm_ops;
38904
38905 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38906@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38907 return r;
38908 if (unlikely(ttm_vm_ops == NULL)) {
38909 ttm_vm_ops = vma->vm_ops;
38910+ pax_open_kernel();
38911 qxl_ttm_vm_ops = *ttm_vm_ops;
38912 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38913+ pax_close_kernel();
38914 }
38915 vma->vm_ops = &qxl_ttm_vm_ops;
38916 return 0;
38917@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38918 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38919 {
38920 #if defined(CONFIG_DEBUG_FS)
38921- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38922- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38923- unsigned i;
38924+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38925+ {
38926+ .name = "qxl_mem_mm",
38927+ .show = &qxl_mm_dump_table,
38928+ },
38929+ {
38930+ .name = "qxl_surf_mm",
38931+ .show = &qxl_mm_dump_table,
38932+ }
38933+ };
38934
38935- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38936- if (i == 0)
38937- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38938- else
38939- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38940- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38941- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38942- qxl_mem_types_list[i].driver_features = 0;
38943- if (i == 0)
38944- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38945- else
38946- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38947+ pax_open_kernel();
38948+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38949+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38950+ pax_close_kernel();
38951
38952- }
38953- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38954+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38955 #else
38956 return 0;
38957 #endif
38958diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38959index d4660cf..70dbe65 100644
38960--- a/drivers/gpu/drm/r128/r128_cce.c
38961+++ b/drivers/gpu/drm/r128/r128_cce.c
38962@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38963
38964 /* GH: Simple idle check.
38965 */
38966- atomic_set(&dev_priv->idle_count, 0);
38967+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38968
38969 /* We don't support anything other than bus-mastering ring mode,
38970 * but the ring can be in either AGP or PCI space for the ring
38971diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38972index 930c71b..499aded 100644
38973--- a/drivers/gpu/drm/r128/r128_drv.h
38974+++ b/drivers/gpu/drm/r128/r128_drv.h
38975@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38976 int is_pci;
38977 unsigned long cce_buffers_offset;
38978
38979- atomic_t idle_count;
38980+ atomic_unchecked_t idle_count;
38981
38982 int page_flipping;
38983 int current_page;
38984 u32 crtc_offset;
38985 u32 crtc_offset_cntl;
38986
38987- atomic_t vbl_received;
38988+ atomic_unchecked_t vbl_received;
38989
38990 u32 color_fmt;
38991 unsigned int front_offset;
38992diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38993index a954c54..9cc595c 100644
38994--- a/drivers/gpu/drm/r128/r128_ioc32.c
38995+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38996@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38997 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38998 }
38999
39000-drm_ioctl_compat_t *r128_compat_ioctls[] = {
39001+drm_ioctl_compat_t r128_compat_ioctls[] = {
39002 [DRM_R128_INIT] = compat_r128_init,
39003 [DRM_R128_DEPTH] = compat_r128_depth,
39004 [DRM_R128_STIPPLE] = compat_r128_stipple,
39005@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39006 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39007 {
39008 unsigned int nr = DRM_IOCTL_NR(cmd);
39009- drm_ioctl_compat_t *fn = NULL;
39010 int ret;
39011
39012 if (nr < DRM_COMMAND_BASE)
39013 return drm_compat_ioctl(filp, cmd, arg);
39014
39015- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39016- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39017-
39018- if (fn != NULL)
39019+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39020+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39021 ret = (*fn) (filp, cmd, arg);
39022- else
39023+ } else
39024 ret = drm_ioctl(filp, cmd, arg);
39025
39026 return ret;
39027diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39028index 2ea4f09..d391371 100644
39029--- a/drivers/gpu/drm/r128/r128_irq.c
39030+++ b/drivers/gpu/drm/r128/r128_irq.c
39031@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39032 if (crtc != 0)
39033 return 0;
39034
39035- return atomic_read(&dev_priv->vbl_received);
39036+ return atomic_read_unchecked(&dev_priv->vbl_received);
39037 }
39038
39039 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39040@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39041 /* VBLANK interrupt */
39042 if (status & R128_CRTC_VBLANK_INT) {
39043 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39044- atomic_inc(&dev_priv->vbl_received);
39045+ atomic_inc_unchecked(&dev_priv->vbl_received);
39046 drm_handle_vblank(dev, 0);
39047 return IRQ_HANDLED;
39048 }
39049diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39050index 19bb7e6..de7e2a2 100644
39051--- a/drivers/gpu/drm/r128/r128_state.c
39052+++ b/drivers/gpu/drm/r128/r128_state.c
39053@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39054
39055 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39056 {
39057- if (atomic_read(&dev_priv->idle_count) == 0)
39058+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39059 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39060 else
39061- atomic_set(&dev_priv->idle_count, 0);
39062+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39063 }
39064
39065 #endif
39066diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39067index af85299..ed9ac8d 100644
39068--- a/drivers/gpu/drm/radeon/mkregtable.c
39069+++ b/drivers/gpu/drm/radeon/mkregtable.c
39070@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
39071 regex_t mask_rex;
39072 regmatch_t match[4];
39073 char buf[1024];
39074- size_t end;
39075+ long end;
39076 int len;
39077 int done = 0;
39078 int r;
39079 unsigned o;
39080 struct offset *offset;
39081 char last_reg_s[10];
39082- int last_reg;
39083+ unsigned long last_reg;
39084
39085 if (regcomp
39086 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39087diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39088index d15f27e..ef11ffc 100644
39089--- a/drivers/gpu/drm/radeon/radeon_device.c
39090+++ b/drivers/gpu/drm/radeon/radeon_device.c
39091@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39092 bool can_switch;
39093
39094 spin_lock(&dev->count_lock);
39095- can_switch = (dev->open_count == 0);
39096+ can_switch = (local_read(&dev->open_count) == 0);
39097 spin_unlock(&dev->count_lock);
39098 return can_switch;
39099 }
39100diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39101index b369d42..8dd04eb 100644
39102--- a/drivers/gpu/drm/radeon/radeon_drv.h
39103+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39104@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39105
39106 /* SW interrupt */
39107 wait_queue_head_t swi_queue;
39108- atomic_t swi_emitted;
39109+ atomic_unchecked_t swi_emitted;
39110 int vblank_crtc;
39111 uint32_t irq_enable_reg;
39112 uint32_t r500_disp_irq_reg;
39113diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39114index c180df8..5fd8186 100644
39115--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39116+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39117@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39118 request = compat_alloc_user_space(sizeof(*request));
39119 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39120 || __put_user(req32.param, &request->param)
39121- || __put_user((void __user *)(unsigned long)req32.value,
39122+ || __put_user((unsigned long)req32.value,
39123 &request->value))
39124 return -EFAULT;
39125
39126@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39127 #define compat_radeon_cp_setparam NULL
39128 #endif /* X86_64 || IA64 */
39129
39130-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39131+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39132 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39133 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39134 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39135@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39136 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39137 {
39138 unsigned int nr = DRM_IOCTL_NR(cmd);
39139- drm_ioctl_compat_t *fn = NULL;
39140 int ret;
39141
39142 if (nr < DRM_COMMAND_BASE)
39143 return drm_compat_ioctl(filp, cmd, arg);
39144
39145- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39146- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39147-
39148- if (fn != NULL)
39149+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39150+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39151 ret = (*fn) (filp, cmd, arg);
39152- else
39153+ } else
39154 ret = drm_ioctl(filp, cmd, arg);
39155
39156 return ret;
39157diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39158index 8d68e97..9dcfed8 100644
39159--- a/drivers/gpu/drm/radeon/radeon_irq.c
39160+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39161@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39162 unsigned int ret;
39163 RING_LOCALS;
39164
39165- atomic_inc(&dev_priv->swi_emitted);
39166- ret = atomic_read(&dev_priv->swi_emitted);
39167+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39168+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39169
39170 BEGIN_RING(4);
39171 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39172@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39173 drm_radeon_private_t *dev_priv =
39174 (drm_radeon_private_t *) dev->dev_private;
39175
39176- atomic_set(&dev_priv->swi_emitted, 0);
39177+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39178 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39179
39180 dev->max_vblank_count = 0x001fffff;
39181diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39182index 4d20910..6726b6d 100644
39183--- a/drivers/gpu/drm/radeon/radeon_state.c
39184+++ b/drivers/gpu/drm/radeon/radeon_state.c
39185@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39186 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39187 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39188
39189- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39190+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39191 sarea_priv->nbox * sizeof(depth_boxes[0])))
39192 return -EFAULT;
39193
39194@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39195 {
39196 drm_radeon_private_t *dev_priv = dev->dev_private;
39197 drm_radeon_getparam_t *param = data;
39198- int value;
39199+ int value = 0;
39200
39201 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39202
39203diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39204index 6c0ce89..57a2529 100644
39205--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39206+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39207@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39208 man->size = size >> PAGE_SHIFT;
39209 }
39210
39211-static struct vm_operations_struct radeon_ttm_vm_ops;
39212+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39213 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39214
39215 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39216@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39217 }
39218 if (unlikely(ttm_vm_ops == NULL)) {
39219 ttm_vm_ops = vma->vm_ops;
39220+ pax_open_kernel();
39221 radeon_ttm_vm_ops = *ttm_vm_ops;
39222 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39223+ pax_close_kernel();
39224 }
39225 vma->vm_ops = &radeon_ttm_vm_ops;
39226 return 0;
39227@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39228 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39229 {
39230 #if defined(CONFIG_DEBUG_FS)
39231- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39232- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39233+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39234+ {
39235+ .name = "radeon_vram_mm",
39236+ .show = &radeon_mm_dump_table,
39237+ },
39238+ {
39239+ .name = "radeon_gtt_mm",
39240+ .show = &radeon_mm_dump_table,
39241+ },
39242+ {
39243+ .name = "ttm_page_pool",
39244+ .show = &ttm_page_alloc_debugfs,
39245+ },
39246+ {
39247+ .name = "ttm_dma_page_pool",
39248+ .show = &ttm_dma_page_alloc_debugfs,
39249+ },
39250+ };
39251 unsigned i;
39252
39253- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39254- if (i == 0)
39255- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39256- else
39257- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39258- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39259- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39260- radeon_mem_types_list[i].driver_features = 0;
39261- if (i == 0)
39262- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39263- else
39264- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39265-
39266- }
39267- /* Add ttm page pool to debugfs */
39268- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39269- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39270- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39271- radeon_mem_types_list[i].driver_features = 0;
39272- radeon_mem_types_list[i++].data = NULL;
39273+ pax_open_kernel();
39274+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39275+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39276+ pax_close_kernel();
39277 #ifdef CONFIG_SWIOTLB
39278- if (swiotlb_nr_tbl()) {
39279- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39280- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39281- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39282- radeon_mem_types_list[i].driver_features = 0;
39283- radeon_mem_types_list[i++].data = NULL;
39284- }
39285+ if (swiotlb_nr_tbl())
39286+ i++;
39287 #endif
39288 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39289
39290diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39291index d8ddfb3..609de1d 100644
39292--- a/drivers/gpu/drm/radeon/rs690.c
39293+++ b/drivers/gpu/drm/radeon/rs690.c
39294@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39295 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39296 rdev->pm.sideport_bandwidth.full)
39297 max_bandwidth = rdev->pm.sideport_bandwidth;
39298- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39299+ read_delay_latency.full = dfixed_const(800 * 1000);
39300 read_delay_latency.full = dfixed_div(read_delay_latency,
39301 rdev->pm.igp_sideport_mclk);
39302+ a.full = dfixed_const(370);
39303+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39304 } else {
39305 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39306 rdev->pm.k8_bandwidth.full)
39307diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39308index dbc2def..0a9f710 100644
39309--- a/drivers/gpu/drm/ttm/ttm_memory.c
39310+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39311@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39312 zone->glob = glob;
39313 glob->zone_kernel = zone;
39314 ret = kobject_init_and_add(
39315- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39316+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39317 if (unlikely(ret != 0)) {
39318 kobject_put(&zone->kobj);
39319 return ret;
39320@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39321 zone->glob = glob;
39322 glob->zone_dma32 = zone;
39323 ret = kobject_init_and_add(
39324- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39325+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39326 if (unlikely(ret != 0)) {
39327 kobject_put(&zone->kobj);
39328 return ret;
39329diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39330index bd2a3b4..122d9ad 100644
39331--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39332+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39333@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39334 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39335 struct shrink_control *sc)
39336 {
39337- static atomic_t start_pool = ATOMIC_INIT(0);
39338+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39339 unsigned i;
39340- unsigned pool_offset = atomic_add_return(1, &start_pool);
39341+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39342 struct ttm_page_pool *pool;
39343 int shrink_pages = sc->nr_to_scan;
39344
39345diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39346index 97e9d61..bf23c461 100644
39347--- a/drivers/gpu/drm/udl/udl_fb.c
39348+++ b/drivers/gpu/drm/udl/udl_fb.c
39349@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39350 fb_deferred_io_cleanup(info);
39351 kfree(info->fbdefio);
39352 info->fbdefio = NULL;
39353- info->fbops->fb_mmap = udl_fb_mmap;
39354 }
39355
39356 pr_warn("released /dev/fb%d user=%d count=%d\n",
39357diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39358index 893a650..6190d3b 100644
39359--- a/drivers/gpu/drm/via/via_drv.h
39360+++ b/drivers/gpu/drm/via/via_drv.h
39361@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39362 typedef uint32_t maskarray_t[5];
39363
39364 typedef struct drm_via_irq {
39365- atomic_t irq_received;
39366+ atomic_unchecked_t irq_received;
39367 uint32_t pending_mask;
39368 uint32_t enable_mask;
39369 wait_queue_head_t irq_queue;
39370@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39371 struct timeval last_vblank;
39372 int last_vblank_valid;
39373 unsigned usec_per_vblank;
39374- atomic_t vbl_received;
39375+ atomic_unchecked_t vbl_received;
39376 drm_via_state_t hc_state;
39377 char pci_buf[VIA_PCI_BUF_SIZE];
39378 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39379diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39380index ac98964..5dbf512 100644
39381--- a/drivers/gpu/drm/via/via_irq.c
39382+++ b/drivers/gpu/drm/via/via_irq.c
39383@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39384 if (crtc != 0)
39385 return 0;
39386
39387- return atomic_read(&dev_priv->vbl_received);
39388+ return atomic_read_unchecked(&dev_priv->vbl_received);
39389 }
39390
39391 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39392@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39393
39394 status = VIA_READ(VIA_REG_INTERRUPT);
39395 if (status & VIA_IRQ_VBLANK_PENDING) {
39396- atomic_inc(&dev_priv->vbl_received);
39397- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39398+ atomic_inc_unchecked(&dev_priv->vbl_received);
39399+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39400 do_gettimeofday(&cur_vblank);
39401 if (dev_priv->last_vblank_valid) {
39402 dev_priv->usec_per_vblank =
39403@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39404 dev_priv->last_vblank = cur_vblank;
39405 dev_priv->last_vblank_valid = 1;
39406 }
39407- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39408+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39409 DRM_DEBUG("US per vblank is: %u\n",
39410 dev_priv->usec_per_vblank);
39411 }
39412@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39413
39414 for (i = 0; i < dev_priv->num_irqs; ++i) {
39415 if (status & cur_irq->pending_mask) {
39416- atomic_inc(&cur_irq->irq_received);
39417+ atomic_inc_unchecked(&cur_irq->irq_received);
39418 DRM_WAKEUP(&cur_irq->irq_queue);
39419 handled = 1;
39420 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39421@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39422 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39423 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39424 masks[irq][4]));
39425- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39426+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39427 } else {
39428 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39429 (((cur_irq_sequence =
39430- atomic_read(&cur_irq->irq_received)) -
39431+ atomic_read_unchecked(&cur_irq->irq_received)) -
39432 *sequence) <= (1 << 23)));
39433 }
39434 *sequence = cur_irq_sequence;
39435@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39436 }
39437
39438 for (i = 0; i < dev_priv->num_irqs; ++i) {
39439- atomic_set(&cur_irq->irq_received, 0);
39440+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39441 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39442 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39443 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39444@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39445 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39446 case VIA_IRQ_RELATIVE:
39447 irqwait->request.sequence +=
39448- atomic_read(&cur_irq->irq_received);
39449+ atomic_read_unchecked(&cur_irq->irq_received);
39450 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39451 case VIA_IRQ_ABSOLUTE:
39452 break;
39453diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39454index 13aeda7..4a952d1 100644
39455--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39456+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39457@@ -290,7 +290,7 @@ struct vmw_private {
39458 * Fencing and IRQs.
39459 */
39460
39461- atomic_t marker_seq;
39462+ atomic_unchecked_t marker_seq;
39463 wait_queue_head_t fence_queue;
39464 wait_queue_head_t fifo_queue;
39465 int fence_queue_waiters; /* Protected by hw_mutex */
39466diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39467index 3eb1486..0a47ee9 100644
39468--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39469+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39470@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39471 (unsigned int) min,
39472 (unsigned int) fifo->capabilities);
39473
39474- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39475+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39476 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39477 vmw_marker_queue_init(&fifo->marker_queue);
39478 return vmw_fifo_send_fence(dev_priv, &dummy);
39479@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39480 if (reserveable)
39481 iowrite32(bytes, fifo_mem +
39482 SVGA_FIFO_RESERVED);
39483- return fifo_mem + (next_cmd >> 2);
39484+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39485 } else {
39486 need_bounce = true;
39487 }
39488@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39489
39490 fm = vmw_fifo_reserve(dev_priv, bytes);
39491 if (unlikely(fm == NULL)) {
39492- *seqno = atomic_read(&dev_priv->marker_seq);
39493+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39494 ret = -ENOMEM;
39495 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39496 false, 3*HZ);
39497@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39498 }
39499
39500 do {
39501- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39502+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39503 } while (*seqno == 0);
39504
39505 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39506diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39507index c509d40..3b640c3 100644
39508--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39509+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39510@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39511 int ret;
39512
39513 num_clips = arg->num_clips;
39514- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39515+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39516
39517 if (unlikely(num_clips == 0))
39518 return 0;
39519@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39520 int ret;
39521
39522 num_clips = arg->num_clips;
39523- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39524+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39525
39526 if (unlikely(num_clips == 0))
39527 return 0;
39528diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39529index 4640adb..e1384ed 100644
39530--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39531+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39532@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39533 * emitted. Then the fence is stale and signaled.
39534 */
39535
39536- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39537+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39538 > VMW_FENCE_WRAP);
39539
39540 return ret;
39541@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39542
39543 if (fifo_idle)
39544 down_read(&fifo_state->rwsem);
39545- signal_seq = atomic_read(&dev_priv->marker_seq);
39546+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39547 ret = 0;
39548
39549 for (;;) {
39550diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39551index 8a8725c2..afed796 100644
39552--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39553+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39554@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39555 while (!vmw_lag_lt(queue, us)) {
39556 spin_lock(&queue->lock);
39557 if (list_empty(&queue->head))
39558- seqno = atomic_read(&dev_priv->marker_seq);
39559+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39560 else {
39561 marker = list_first_entry(&queue->head,
39562 struct vmw_marker, head);
39563diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39564index 5360e5a..c2c0d26 100644
39565--- a/drivers/gpu/host1x/drm/dc.c
39566+++ b/drivers/gpu/host1x/drm/dc.c
39567@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39568 }
39569
39570 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39571- dc->debugfs_files[i].data = dc;
39572+ *(void **)&dc->debugfs_files[i].data = dc;
39573
39574 err = drm_debugfs_create_files(dc->debugfs_files,
39575 ARRAY_SIZE(debugfs_files),
39576diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39577index 9f60d63..c89e0b7 100644
39578--- a/drivers/hid/hid-core.c
39579+++ b/drivers/hid/hid-core.c
39580@@ -2370,7 +2370,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39581
39582 int hid_add_device(struct hid_device *hdev)
39583 {
39584- static atomic_t id = ATOMIC_INIT(0);
39585+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39586 int ret;
39587
39588 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39589@@ -2404,7 +2404,7 @@ int hid_add_device(struct hid_device *hdev)
39590 /* XXX hack, any other cleaner solution after the driver core
39591 * is converted to allow more than 20 bytes as the device name? */
39592 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39593- hdev->vendor, hdev->product, atomic_inc_return(&id));
39594+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39595
39596 hid_debug_register(hdev, dev_name(&hdev->dev));
39597 ret = device_add(&hdev->dev);
39598diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39599index c13fb5b..55a3802 100644
39600--- a/drivers/hid/hid-wiimote-debug.c
39601+++ b/drivers/hid/hid-wiimote-debug.c
39602@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39603 else if (size == 0)
39604 return -EIO;
39605
39606- if (copy_to_user(u, buf, size))
39607+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39608 return -EFAULT;
39609
39610 *off += size;
39611diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39612index 145a4cb..2353a3e 100644
39613--- a/drivers/hid/uhid.c
39614+++ b/drivers/hid/uhid.c
39615@@ -47,7 +47,7 @@ struct uhid_device {
39616 struct mutex report_lock;
39617 wait_queue_head_t report_wait;
39618 atomic_t report_done;
39619- atomic_t report_id;
39620+ atomic_unchecked_t report_id;
39621 struct uhid_event report_buf;
39622 };
39623
39624@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39625
39626 spin_lock_irqsave(&uhid->qlock, flags);
39627 ev->type = UHID_FEATURE;
39628- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39629+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39630 ev->u.feature.rnum = rnum;
39631 ev->u.feature.rtype = report_type;
39632
39633@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39634 spin_lock_irqsave(&uhid->qlock, flags);
39635
39636 /* id for old report; drop it silently */
39637- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39638+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39639 goto unlock;
39640 if (atomic_read(&uhid->report_done))
39641 goto unlock;
39642diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39643index 6de6c98..18319e9 100644
39644--- a/drivers/hv/channel.c
39645+++ b/drivers/hv/channel.c
39646@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39647 int ret = 0;
39648 int t;
39649
39650- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39651- atomic_inc(&vmbus_connection.next_gpadl_handle);
39652+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39653+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39654
39655 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39656 if (ret)
39657diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39658index 88f4096..e50452e 100644
39659--- a/drivers/hv/hv.c
39660+++ b/drivers/hv/hv.c
39661@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39662 u64 output_address = (output) ? virt_to_phys(output) : 0;
39663 u32 output_address_hi = output_address >> 32;
39664 u32 output_address_lo = output_address & 0xFFFFFFFF;
39665- void *hypercall_page = hv_context.hypercall_page;
39666+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39667
39668 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39669 "=a"(hv_status_lo) : "d" (control_hi),
39670diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39671index deb5c25..ed2d4fd 100644
39672--- a/drivers/hv/hv_balloon.c
39673+++ b/drivers/hv/hv_balloon.c
39674@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39675
39676 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39677 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39678-static atomic_t trans_id = ATOMIC_INIT(0);
39679+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39680
39681 static int dm_ring_size = (5 * PAGE_SIZE);
39682
39683@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39684 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39685 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39686 resp.hdr.size = sizeof(struct dm_hot_add_response);
39687- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39688+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39689
39690 #ifdef CONFIG_MEMORY_HOTPLUG
39691 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39692@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39693 memset(&status, 0, sizeof(struct dm_status));
39694 status.hdr.type = DM_STATUS_REPORT;
39695 status.hdr.size = sizeof(struct dm_status);
39696- status.hdr.trans_id = atomic_inc_return(&trans_id);
39697+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39698
39699 /*
39700 * The host expects the guest to report free memory.
39701@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39702 * send the status. This can happen if we were interrupted
39703 * after we picked our transaction ID.
39704 */
39705- if (status.hdr.trans_id != atomic_read(&trans_id))
39706+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39707 return;
39708
39709 vmbus_sendpacket(dm->dev->channel, &status,
39710@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39711 bl_resp = (struct dm_balloon_response *)send_buffer;
39712 memset(send_buffer, 0, PAGE_SIZE);
39713 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39714- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39715+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39716 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39717 bl_resp->more_pages = 1;
39718
39719@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39720
39721 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39722 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39723- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39724+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39725 resp.hdr.size = sizeof(struct dm_unballoon_response);
39726
39727 vmbus_sendpacket(dm_device.dev->channel, &resp,
39728@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39729 memset(&version_req, 0, sizeof(struct dm_version_request));
39730 version_req.hdr.type = DM_VERSION_REQUEST;
39731 version_req.hdr.size = sizeof(struct dm_version_request);
39732- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39733+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39734 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39735 version_req.is_last_attempt = 1;
39736
39737@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39738 memset(&version_req, 0, sizeof(struct dm_version_request));
39739 version_req.hdr.type = DM_VERSION_REQUEST;
39740 version_req.hdr.size = sizeof(struct dm_version_request);
39741- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39742+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39743 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39744 version_req.is_last_attempt = 0;
39745
39746@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39747 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39748 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39749 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39750- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39751+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39752
39753 cap_msg.caps.cap_bits.balloon = 1;
39754 cap_msg.caps.cap_bits.hot_add = 1;
39755diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39756index d84918f..7f38f9f 100644
39757--- a/drivers/hv/hyperv_vmbus.h
39758+++ b/drivers/hv/hyperv_vmbus.h
39759@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39760 struct vmbus_connection {
39761 enum vmbus_connect_state conn_state;
39762
39763- atomic_t next_gpadl_handle;
39764+ atomic_unchecked_t next_gpadl_handle;
39765
39766 /*
39767 * Represents channel interrupts. Each bit position represents a
39768diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39769index e8e071f..5b4b245 100644
39770--- a/drivers/hv/vmbus_drv.c
39771+++ b/drivers/hv/vmbus_drv.c
39772@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39773 {
39774 int ret = 0;
39775
39776- static atomic_t device_num = ATOMIC_INIT(0);
39777+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39778
39779 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39780- atomic_inc_return(&device_num));
39781+ atomic_inc_return_unchecked(&device_num));
39782
39783 child_device_obj->device.bus = &hv_bus;
39784 child_device_obj->device.parent = &hv_acpi_dev->dev;
39785diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39786index 6351aba..dc4aaf4 100644
39787--- a/drivers/hwmon/acpi_power_meter.c
39788+++ b/drivers/hwmon/acpi_power_meter.c
39789@@ -117,7 +117,7 @@ struct sensor_template {
39790 struct device_attribute *devattr,
39791 const char *buf, size_t count);
39792 int index;
39793-};
39794+} __do_const;
39795
39796 /* Averaging interval */
39797 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39798@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39799 struct sensor_template *attrs)
39800 {
39801 struct device *dev = &resource->acpi_dev->dev;
39802- struct sensor_device_attribute *sensors =
39803+ sensor_device_attribute_no_const *sensors =
39804 &resource->sensors[resource->num_sensors];
39805 int res = 0;
39806
39807diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39808index 3288f13..71cfb4e 100644
39809--- a/drivers/hwmon/applesmc.c
39810+++ b/drivers/hwmon/applesmc.c
39811@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39812 {
39813 struct applesmc_node_group *grp;
39814 struct applesmc_dev_attr *node;
39815- struct attribute *attr;
39816+ attribute_no_const *attr;
39817 int ret, i;
39818
39819 for (grp = groups; grp->format; grp++) {
39820diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39821index b25c643..a13460d 100644
39822--- a/drivers/hwmon/asus_atk0110.c
39823+++ b/drivers/hwmon/asus_atk0110.c
39824@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39825 struct atk_sensor_data {
39826 struct list_head list;
39827 struct atk_data *data;
39828- struct device_attribute label_attr;
39829- struct device_attribute input_attr;
39830- struct device_attribute limit1_attr;
39831- struct device_attribute limit2_attr;
39832+ device_attribute_no_const label_attr;
39833+ device_attribute_no_const input_attr;
39834+ device_attribute_no_const limit1_attr;
39835+ device_attribute_no_const limit2_attr;
39836 char label_attr_name[ATTR_NAME_SIZE];
39837 char input_attr_name[ATTR_NAME_SIZE];
39838 char limit1_attr_name[ATTR_NAME_SIZE];
39839@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39840 static struct device_attribute atk_name_attr =
39841 __ATTR(name, 0444, atk_name_show, NULL);
39842
39843-static void atk_init_attribute(struct device_attribute *attr, char *name,
39844+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39845 sysfs_show_func show)
39846 {
39847 sysfs_attr_init(&attr->attr);
39848diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39849index 2e5e2dc..5208b31 100644
39850--- a/drivers/hwmon/coretemp.c
39851+++ b/drivers/hwmon/coretemp.c
39852@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39853 return NOTIFY_OK;
39854 }
39855
39856-static struct notifier_block coretemp_cpu_notifier __refdata = {
39857+static struct notifier_block coretemp_cpu_notifier = {
39858 .notifier_call = coretemp_cpu_callback,
39859 };
39860
39861diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39862index 1429f6e..ee03d59 100644
39863--- a/drivers/hwmon/ibmaem.c
39864+++ b/drivers/hwmon/ibmaem.c
39865@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39866 struct aem_rw_sensor_template *rw)
39867 {
39868 struct device *dev = &data->pdev->dev;
39869- struct sensor_device_attribute *sensors = data->sensors;
39870+ sensor_device_attribute_no_const *sensors = data->sensors;
39871 int err;
39872
39873 /* Set up read-only sensors */
39874diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39875index 708081b..fe2d4ab 100644
39876--- a/drivers/hwmon/iio_hwmon.c
39877+++ b/drivers/hwmon/iio_hwmon.c
39878@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39879 {
39880 struct device *dev = &pdev->dev;
39881 struct iio_hwmon_state *st;
39882- struct sensor_device_attribute *a;
39883+ sensor_device_attribute_no_const *a;
39884 int ret, i;
39885 int in_i = 1, temp_i = 1, curr_i = 1;
39886 enum iio_chan_type type;
39887diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39888index 9add6092..ee7ba3f 100644
39889--- a/drivers/hwmon/pmbus/pmbus_core.c
39890+++ b/drivers/hwmon/pmbus/pmbus_core.c
39891@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39892 return 0;
39893 }
39894
39895-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39896+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39897 const char *name,
39898 umode_t mode,
39899 ssize_t (*show)(struct device *dev,
39900@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39901 dev_attr->store = store;
39902 }
39903
39904-static void pmbus_attr_init(struct sensor_device_attribute *a,
39905+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39906 const char *name,
39907 umode_t mode,
39908 ssize_t (*show)(struct device *dev,
39909@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39910 u16 reg, u8 mask)
39911 {
39912 struct pmbus_boolean *boolean;
39913- struct sensor_device_attribute *a;
39914+ sensor_device_attribute_no_const *a;
39915
39916 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39917 if (!boolean)
39918@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39919 bool update, bool readonly)
39920 {
39921 struct pmbus_sensor *sensor;
39922- struct device_attribute *a;
39923+ device_attribute_no_const *a;
39924
39925 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39926 if (!sensor)
39927@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39928 const char *lstring, int index)
39929 {
39930 struct pmbus_label *label;
39931- struct device_attribute *a;
39932+ device_attribute_no_const *a;
39933
39934 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39935 if (!label)
39936diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39937index 2507f90..1645765 100644
39938--- a/drivers/hwmon/sht15.c
39939+++ b/drivers/hwmon/sht15.c
39940@@ -169,7 +169,7 @@ struct sht15_data {
39941 int supply_uv;
39942 bool supply_uv_valid;
39943 struct work_struct update_supply_work;
39944- atomic_t interrupt_handled;
39945+ atomic_unchecked_t interrupt_handled;
39946 };
39947
39948 /**
39949@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39950 ret = gpio_direction_input(data->pdata->gpio_data);
39951 if (ret)
39952 return ret;
39953- atomic_set(&data->interrupt_handled, 0);
39954+ atomic_set_unchecked(&data->interrupt_handled, 0);
39955
39956 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39957 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39958 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39959 /* Only relevant if the interrupt hasn't occurred. */
39960- if (!atomic_read(&data->interrupt_handled))
39961+ if (!atomic_read_unchecked(&data->interrupt_handled))
39962 schedule_work(&data->read_work);
39963 }
39964 ret = wait_event_timeout(data->wait_queue,
39965@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
39966
39967 /* First disable the interrupt */
39968 disable_irq_nosync(irq);
39969- atomic_inc(&data->interrupt_handled);
39970+ atomic_inc_unchecked(&data->interrupt_handled);
39971 /* Then schedule a reading work struct */
39972 if (data->state != SHT15_READING_NOTHING)
39973 schedule_work(&data->read_work);
39974@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
39975 * If not, then start the interrupt again - care here as could
39976 * have gone low in meantime so verify it hasn't!
39977 */
39978- atomic_set(&data->interrupt_handled, 0);
39979+ atomic_set_unchecked(&data->interrupt_handled, 0);
39980 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39981 /* If still not occurred or another handler was scheduled */
39982 if (gpio_get_value(data->pdata->gpio_data)
39983- || atomic_read(&data->interrupt_handled))
39984+ || atomic_read_unchecked(&data->interrupt_handled))
39985 return;
39986 }
39987
39988diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
39989index 38944e9..ae9e5ed 100644
39990--- a/drivers/hwmon/via-cputemp.c
39991+++ b/drivers/hwmon/via-cputemp.c
39992@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
39993 return NOTIFY_OK;
39994 }
39995
39996-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
39997+static struct notifier_block via_cputemp_cpu_notifier = {
39998 .notifier_call = via_cputemp_cpu_callback,
39999 };
40000
40001diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40002index 07f01ac..d79ad3d 100644
40003--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40004+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40005@@ -43,7 +43,7 @@
40006 extern struct i2c_adapter amd756_smbus;
40007
40008 static struct i2c_adapter *s4882_adapter;
40009-static struct i2c_algorithm *s4882_algo;
40010+static i2c_algorithm_no_const *s4882_algo;
40011
40012 /* Wrapper access functions for multiplexed SMBus */
40013 static DEFINE_MUTEX(amd756_lock);
40014diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40015index 2ca268d..c6acbdf 100644
40016--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40017+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40018@@ -41,7 +41,7 @@
40019 extern struct i2c_adapter *nforce2_smbus;
40020
40021 static struct i2c_adapter *s4985_adapter;
40022-static struct i2c_algorithm *s4985_algo;
40023+static i2c_algorithm_no_const *s4985_algo;
40024
40025 /* Wrapper access functions for multiplexed SMBus */
40026 static DEFINE_MUTEX(nforce2_lock);
40027diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40028index c3ccdea..5b3dc1a 100644
40029--- a/drivers/i2c/i2c-dev.c
40030+++ b/drivers/i2c/i2c-dev.c
40031@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40032 break;
40033 }
40034
40035- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40036+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40037 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40038 if (IS_ERR(rdwr_pa[i].buf)) {
40039 res = PTR_ERR(rdwr_pa[i].buf);
40040diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40041index 0b510ba..4fbb5085 100644
40042--- a/drivers/ide/ide-cd.c
40043+++ b/drivers/ide/ide-cd.c
40044@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40045 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40046 if ((unsigned long)buf & alignment
40047 || blk_rq_bytes(rq) & q->dma_pad_mask
40048- || object_is_on_stack(buf))
40049+ || object_starts_on_stack(buf))
40050 drive->dma = 0;
40051 }
40052 }
40053diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40054index e145931..08bfc59 100644
40055--- a/drivers/iio/industrialio-core.c
40056+++ b/drivers/iio/industrialio-core.c
40057@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40058 }
40059
40060 static
40061-int __iio_device_attr_init(struct device_attribute *dev_attr,
40062+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40063 const char *postfix,
40064 struct iio_chan_spec const *chan,
40065 ssize_t (*readfunc)(struct device *dev,
40066diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40067index 784b97c..c9ceadf 100644
40068--- a/drivers/infiniband/core/cm.c
40069+++ b/drivers/infiniband/core/cm.c
40070@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40071
40072 struct cm_counter_group {
40073 struct kobject obj;
40074- atomic_long_t counter[CM_ATTR_COUNT];
40075+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40076 };
40077
40078 struct cm_counter_attribute {
40079@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40080 struct ib_mad_send_buf *msg = NULL;
40081 int ret;
40082
40083- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40084+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40085 counter[CM_REQ_COUNTER]);
40086
40087 /* Quick state check to discard duplicate REQs. */
40088@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40089 if (!cm_id_priv)
40090 return;
40091
40092- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40093+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40094 counter[CM_REP_COUNTER]);
40095 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40096 if (ret)
40097@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40098 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40099 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40100 spin_unlock_irq(&cm_id_priv->lock);
40101- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40102+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40103 counter[CM_RTU_COUNTER]);
40104 goto out;
40105 }
40106@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40107 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40108 dreq_msg->local_comm_id);
40109 if (!cm_id_priv) {
40110- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40111+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40112 counter[CM_DREQ_COUNTER]);
40113 cm_issue_drep(work->port, work->mad_recv_wc);
40114 return -EINVAL;
40115@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40116 case IB_CM_MRA_REP_RCVD:
40117 break;
40118 case IB_CM_TIMEWAIT:
40119- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40120+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40121 counter[CM_DREQ_COUNTER]);
40122 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40123 goto unlock;
40124@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40125 cm_free_msg(msg);
40126 goto deref;
40127 case IB_CM_DREQ_RCVD:
40128- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40129+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40130 counter[CM_DREQ_COUNTER]);
40131 goto unlock;
40132 default:
40133@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40134 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40135 cm_id_priv->msg, timeout)) {
40136 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40137- atomic_long_inc(&work->port->
40138+ atomic_long_inc_unchecked(&work->port->
40139 counter_group[CM_RECV_DUPLICATES].
40140 counter[CM_MRA_COUNTER]);
40141 goto out;
40142@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40143 break;
40144 case IB_CM_MRA_REQ_RCVD:
40145 case IB_CM_MRA_REP_RCVD:
40146- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40147+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40148 counter[CM_MRA_COUNTER]);
40149 /* fall through */
40150 default:
40151@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40152 case IB_CM_LAP_IDLE:
40153 break;
40154 case IB_CM_MRA_LAP_SENT:
40155- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40156+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40157 counter[CM_LAP_COUNTER]);
40158 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40159 goto unlock;
40160@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40161 cm_free_msg(msg);
40162 goto deref;
40163 case IB_CM_LAP_RCVD:
40164- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40165+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40166 counter[CM_LAP_COUNTER]);
40167 goto unlock;
40168 default:
40169@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40170 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40171 if (cur_cm_id_priv) {
40172 spin_unlock_irq(&cm.lock);
40173- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40174+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40175 counter[CM_SIDR_REQ_COUNTER]);
40176 goto out; /* Duplicate message. */
40177 }
40178@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40179 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40180 msg->retries = 1;
40181
40182- atomic_long_add(1 + msg->retries,
40183+ atomic_long_add_unchecked(1 + msg->retries,
40184 &port->counter_group[CM_XMIT].counter[attr_index]);
40185 if (msg->retries)
40186- atomic_long_add(msg->retries,
40187+ atomic_long_add_unchecked(msg->retries,
40188 &port->counter_group[CM_XMIT_RETRIES].
40189 counter[attr_index]);
40190
40191@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40192 }
40193
40194 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40195- atomic_long_inc(&port->counter_group[CM_RECV].
40196+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40197 counter[attr_id - CM_ATTR_ID_OFFSET]);
40198
40199 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40200@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40201 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40202
40203 return sprintf(buf, "%ld\n",
40204- atomic_long_read(&group->counter[cm_attr->index]));
40205+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40206 }
40207
40208 static const struct sysfs_ops cm_counter_ops = {
40209diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40210index 9f5ad7c..588cd84 100644
40211--- a/drivers/infiniband/core/fmr_pool.c
40212+++ b/drivers/infiniband/core/fmr_pool.c
40213@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40214
40215 struct task_struct *thread;
40216
40217- atomic_t req_ser;
40218- atomic_t flush_ser;
40219+ atomic_unchecked_t req_ser;
40220+ atomic_unchecked_t flush_ser;
40221
40222 wait_queue_head_t force_wait;
40223 };
40224@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40225 struct ib_fmr_pool *pool = pool_ptr;
40226
40227 do {
40228- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40229+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40230 ib_fmr_batch_release(pool);
40231
40232- atomic_inc(&pool->flush_ser);
40233+ atomic_inc_unchecked(&pool->flush_ser);
40234 wake_up_interruptible(&pool->force_wait);
40235
40236 if (pool->flush_function)
40237@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40238 }
40239
40240 set_current_state(TASK_INTERRUPTIBLE);
40241- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40242+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40243 !kthread_should_stop())
40244 schedule();
40245 __set_current_state(TASK_RUNNING);
40246@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40247 pool->dirty_watermark = params->dirty_watermark;
40248 pool->dirty_len = 0;
40249 spin_lock_init(&pool->pool_lock);
40250- atomic_set(&pool->req_ser, 0);
40251- atomic_set(&pool->flush_ser, 0);
40252+ atomic_set_unchecked(&pool->req_ser, 0);
40253+ atomic_set_unchecked(&pool->flush_ser, 0);
40254 init_waitqueue_head(&pool->force_wait);
40255
40256 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40257@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40258 }
40259 spin_unlock_irq(&pool->pool_lock);
40260
40261- serial = atomic_inc_return(&pool->req_ser);
40262+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40263 wake_up_process(pool->thread);
40264
40265 if (wait_event_interruptible(pool->force_wait,
40266- atomic_read(&pool->flush_ser) - serial >= 0))
40267+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40268 return -EINTR;
40269
40270 return 0;
40271@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40272 } else {
40273 list_add_tail(&fmr->list, &pool->dirty_list);
40274 if (++pool->dirty_len >= pool->dirty_watermark) {
40275- atomic_inc(&pool->req_ser);
40276+ atomic_inc_unchecked(&pool->req_ser);
40277 wake_up_process(pool->thread);
40278 }
40279 }
40280diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40281index 4cb8eb2..146bf60 100644
40282--- a/drivers/infiniband/hw/cxgb4/mem.c
40283+++ b/drivers/infiniband/hw/cxgb4/mem.c
40284@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40285 int err;
40286 struct fw_ri_tpte tpt;
40287 u32 stag_idx;
40288- static atomic_t key;
40289+ static atomic_unchecked_t key;
40290
40291 if (c4iw_fatal_error(rdev))
40292 return -EIO;
40293@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40294 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40295 rdev->stats.stag.max = rdev->stats.stag.cur;
40296 mutex_unlock(&rdev->stats.lock);
40297- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40298+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40299 }
40300 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40301 __func__, stag_state, type, pdid, stag_idx);
40302diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40303index 79b3dbc..96e5fcc 100644
40304--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40305+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40306@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40307 struct ib_atomic_eth *ateth;
40308 struct ipath_ack_entry *e;
40309 u64 vaddr;
40310- atomic64_t *maddr;
40311+ atomic64_unchecked_t *maddr;
40312 u64 sdata;
40313 u32 rkey;
40314 u8 next;
40315@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40316 IB_ACCESS_REMOTE_ATOMIC)))
40317 goto nack_acc_unlck;
40318 /* Perform atomic OP and save result. */
40319- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40320+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40321 sdata = be64_to_cpu(ateth->swap_data);
40322 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40323 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40324- (u64) atomic64_add_return(sdata, maddr) - sdata :
40325+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40326 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40327 be64_to_cpu(ateth->compare_data),
40328 sdata);
40329diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40330index 1f95bba..9530f87 100644
40331--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40332+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40333@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40334 unsigned long flags;
40335 struct ib_wc wc;
40336 u64 sdata;
40337- atomic64_t *maddr;
40338+ atomic64_unchecked_t *maddr;
40339 enum ib_wc_status send_status;
40340
40341 /*
40342@@ -382,11 +382,11 @@ again:
40343 IB_ACCESS_REMOTE_ATOMIC)))
40344 goto acc_err;
40345 /* Perform atomic OP and save result. */
40346- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40347+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40348 sdata = wqe->wr.wr.atomic.compare_add;
40349 *(u64 *) sqp->s_sge.sge.vaddr =
40350 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40351- (u64) atomic64_add_return(sdata, maddr) - sdata :
40352+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40353 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40354 sdata, wqe->wr.wr.atomic.swap);
40355 goto send_comp;
40356diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40357index f2a3f48..673ec79 100644
40358--- a/drivers/infiniband/hw/mlx4/mad.c
40359+++ b/drivers/infiniband/hw/mlx4/mad.c
40360@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40361
40362 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40363 {
40364- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40365+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40366 cpu_to_be64(0xff00000000000000LL);
40367 }
40368
40369diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40370index 25b2cdf..099ff97 100644
40371--- a/drivers/infiniband/hw/mlx4/mcg.c
40372+++ b/drivers/infiniband/hw/mlx4/mcg.c
40373@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40374 {
40375 char name[20];
40376
40377- atomic_set(&ctx->tid, 0);
40378+ atomic_set_unchecked(&ctx->tid, 0);
40379 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40380 ctx->mcg_wq = create_singlethread_workqueue(name);
40381 if (!ctx->mcg_wq)
40382diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40383index f61ec26..ebf72cf 100644
40384--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40385+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40386@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40387 struct list_head mcg_mgid0_list;
40388 struct workqueue_struct *mcg_wq;
40389 struct mlx4_ib_demux_pv_ctx **tun;
40390- atomic_t tid;
40391+ atomic_unchecked_t tid;
40392 int flushing; /* flushing the work queue */
40393 };
40394
40395diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40396index 9d3e5c1..d9afe4a 100644
40397--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40398+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40399@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40400 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40401 }
40402
40403-int mthca_QUERY_FW(struct mthca_dev *dev)
40404+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40405 {
40406 struct mthca_mailbox *mailbox;
40407 u32 *outbox;
40408diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40409index ed9a989..e0c5871 100644
40410--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40411+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40412@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40413 return key;
40414 }
40415
40416-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40417+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40418 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40419 {
40420 struct mthca_mailbox *mailbox;
40421diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40422index 4291410..d2ab1fb 100644
40423--- a/drivers/infiniband/hw/nes/nes.c
40424+++ b/drivers/infiniband/hw/nes/nes.c
40425@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40426 LIST_HEAD(nes_adapter_list);
40427 static LIST_HEAD(nes_dev_list);
40428
40429-atomic_t qps_destroyed;
40430+atomic_unchecked_t qps_destroyed;
40431
40432 static unsigned int ee_flsh_adapter;
40433 static unsigned int sysfs_nonidx_addr;
40434@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40435 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40436 struct nes_adapter *nesadapter = nesdev->nesadapter;
40437
40438- atomic_inc(&qps_destroyed);
40439+ atomic_inc_unchecked(&qps_destroyed);
40440
40441 /* Free the control structures */
40442
40443diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40444index 33cc589..3bd6538 100644
40445--- a/drivers/infiniband/hw/nes/nes.h
40446+++ b/drivers/infiniband/hw/nes/nes.h
40447@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40448 extern unsigned int wqm_quanta;
40449 extern struct list_head nes_adapter_list;
40450
40451-extern atomic_t cm_connects;
40452-extern atomic_t cm_accepts;
40453-extern atomic_t cm_disconnects;
40454-extern atomic_t cm_closes;
40455-extern atomic_t cm_connecteds;
40456-extern atomic_t cm_connect_reqs;
40457-extern atomic_t cm_rejects;
40458-extern atomic_t mod_qp_timouts;
40459-extern atomic_t qps_created;
40460-extern atomic_t qps_destroyed;
40461-extern atomic_t sw_qps_destroyed;
40462+extern atomic_unchecked_t cm_connects;
40463+extern atomic_unchecked_t cm_accepts;
40464+extern atomic_unchecked_t cm_disconnects;
40465+extern atomic_unchecked_t cm_closes;
40466+extern atomic_unchecked_t cm_connecteds;
40467+extern atomic_unchecked_t cm_connect_reqs;
40468+extern atomic_unchecked_t cm_rejects;
40469+extern atomic_unchecked_t mod_qp_timouts;
40470+extern atomic_unchecked_t qps_created;
40471+extern atomic_unchecked_t qps_destroyed;
40472+extern atomic_unchecked_t sw_qps_destroyed;
40473 extern u32 mh_detected;
40474 extern u32 mh_pauses_sent;
40475 extern u32 cm_packets_sent;
40476@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40477 extern u32 cm_packets_received;
40478 extern u32 cm_packets_dropped;
40479 extern u32 cm_packets_retrans;
40480-extern atomic_t cm_listens_created;
40481-extern atomic_t cm_listens_destroyed;
40482+extern atomic_unchecked_t cm_listens_created;
40483+extern atomic_unchecked_t cm_listens_destroyed;
40484 extern u32 cm_backlog_drops;
40485-extern atomic_t cm_loopbacks;
40486-extern atomic_t cm_nodes_created;
40487-extern atomic_t cm_nodes_destroyed;
40488-extern atomic_t cm_accel_dropped_pkts;
40489-extern atomic_t cm_resets_recvd;
40490-extern atomic_t pau_qps_created;
40491-extern atomic_t pau_qps_destroyed;
40492+extern atomic_unchecked_t cm_loopbacks;
40493+extern atomic_unchecked_t cm_nodes_created;
40494+extern atomic_unchecked_t cm_nodes_destroyed;
40495+extern atomic_unchecked_t cm_accel_dropped_pkts;
40496+extern atomic_unchecked_t cm_resets_recvd;
40497+extern atomic_unchecked_t pau_qps_created;
40498+extern atomic_unchecked_t pau_qps_destroyed;
40499
40500 extern u32 int_mod_timer_init;
40501 extern u32 int_mod_cq_depth_256;
40502diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40503index 24b9f1a..00fd004 100644
40504--- a/drivers/infiniband/hw/nes/nes_cm.c
40505+++ b/drivers/infiniband/hw/nes/nes_cm.c
40506@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40507 u32 cm_packets_retrans;
40508 u32 cm_packets_created;
40509 u32 cm_packets_received;
40510-atomic_t cm_listens_created;
40511-atomic_t cm_listens_destroyed;
40512+atomic_unchecked_t cm_listens_created;
40513+atomic_unchecked_t cm_listens_destroyed;
40514 u32 cm_backlog_drops;
40515-atomic_t cm_loopbacks;
40516-atomic_t cm_nodes_created;
40517-atomic_t cm_nodes_destroyed;
40518-atomic_t cm_accel_dropped_pkts;
40519-atomic_t cm_resets_recvd;
40520+atomic_unchecked_t cm_loopbacks;
40521+atomic_unchecked_t cm_nodes_created;
40522+atomic_unchecked_t cm_nodes_destroyed;
40523+atomic_unchecked_t cm_accel_dropped_pkts;
40524+atomic_unchecked_t cm_resets_recvd;
40525
40526 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40527 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40528@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40529
40530 static struct nes_cm_core *g_cm_core;
40531
40532-atomic_t cm_connects;
40533-atomic_t cm_accepts;
40534-atomic_t cm_disconnects;
40535-atomic_t cm_closes;
40536-atomic_t cm_connecteds;
40537-atomic_t cm_connect_reqs;
40538-atomic_t cm_rejects;
40539+atomic_unchecked_t cm_connects;
40540+atomic_unchecked_t cm_accepts;
40541+atomic_unchecked_t cm_disconnects;
40542+atomic_unchecked_t cm_closes;
40543+atomic_unchecked_t cm_connecteds;
40544+atomic_unchecked_t cm_connect_reqs;
40545+atomic_unchecked_t cm_rejects;
40546
40547 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40548 {
40549@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40550 kfree(listener);
40551 listener = NULL;
40552 ret = 0;
40553- atomic_inc(&cm_listens_destroyed);
40554+ atomic_inc_unchecked(&cm_listens_destroyed);
40555 } else {
40556 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40557 }
40558@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40559 cm_node->rem_mac);
40560
40561 add_hte_node(cm_core, cm_node);
40562- atomic_inc(&cm_nodes_created);
40563+ atomic_inc_unchecked(&cm_nodes_created);
40564
40565 return cm_node;
40566 }
40567@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40568 }
40569
40570 atomic_dec(&cm_core->node_cnt);
40571- atomic_inc(&cm_nodes_destroyed);
40572+ atomic_inc_unchecked(&cm_nodes_destroyed);
40573 nesqp = cm_node->nesqp;
40574 if (nesqp) {
40575 nesqp->cm_node = NULL;
40576@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40577
40578 static void drop_packet(struct sk_buff *skb)
40579 {
40580- atomic_inc(&cm_accel_dropped_pkts);
40581+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40582 dev_kfree_skb_any(skb);
40583 }
40584
40585@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40586 {
40587
40588 int reset = 0; /* whether to send reset in case of err.. */
40589- atomic_inc(&cm_resets_recvd);
40590+ atomic_inc_unchecked(&cm_resets_recvd);
40591 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40592 " refcnt=%d\n", cm_node, cm_node->state,
40593 atomic_read(&cm_node->ref_count));
40594@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40595 rem_ref_cm_node(cm_node->cm_core, cm_node);
40596 return NULL;
40597 }
40598- atomic_inc(&cm_loopbacks);
40599+ atomic_inc_unchecked(&cm_loopbacks);
40600 loopbackremotenode->loopbackpartner = cm_node;
40601 loopbackremotenode->tcp_cntxt.rcv_wscale =
40602 NES_CM_DEFAULT_RCV_WND_SCALE;
40603@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40604 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40605 else {
40606 rem_ref_cm_node(cm_core, cm_node);
40607- atomic_inc(&cm_accel_dropped_pkts);
40608+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40609 dev_kfree_skb_any(skb);
40610 }
40611 break;
40612@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40613
40614 if ((cm_id) && (cm_id->event_handler)) {
40615 if (issue_disconn) {
40616- atomic_inc(&cm_disconnects);
40617+ atomic_inc_unchecked(&cm_disconnects);
40618 cm_event.event = IW_CM_EVENT_DISCONNECT;
40619 cm_event.status = disconn_status;
40620 cm_event.local_addr = cm_id->local_addr;
40621@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40622 }
40623
40624 if (issue_close) {
40625- atomic_inc(&cm_closes);
40626+ atomic_inc_unchecked(&cm_closes);
40627 nes_disconnect(nesqp, 1);
40628
40629 cm_id->provider_data = nesqp;
40630@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40631
40632 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40633 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40634- atomic_inc(&cm_accepts);
40635+ atomic_inc_unchecked(&cm_accepts);
40636
40637 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40638 netdev_refcnt_read(nesvnic->netdev));
40639@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40640 struct nes_cm_core *cm_core;
40641 u8 *start_buff;
40642
40643- atomic_inc(&cm_rejects);
40644+ atomic_inc_unchecked(&cm_rejects);
40645 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40646 loopback = cm_node->loopbackpartner;
40647 cm_core = cm_node->cm_core;
40648@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40649 ntohl(cm_id->local_addr.sin_addr.s_addr),
40650 ntohs(cm_id->local_addr.sin_port));
40651
40652- atomic_inc(&cm_connects);
40653+ atomic_inc_unchecked(&cm_connects);
40654 nesqp->active_conn = 1;
40655
40656 /* cache the cm_id in the qp */
40657@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40658 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40659 return err;
40660 }
40661- atomic_inc(&cm_listens_created);
40662+ atomic_inc_unchecked(&cm_listens_created);
40663 }
40664
40665 cm_id->add_ref(cm_id);
40666@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40667
40668 if (nesqp->destroyed)
40669 return;
40670- atomic_inc(&cm_connecteds);
40671+ atomic_inc_unchecked(&cm_connecteds);
40672 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40673 " local port 0x%04X. jiffies = %lu.\n",
40674 nesqp->hwqp.qp_id,
40675@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40676
40677 cm_id->add_ref(cm_id);
40678 ret = cm_id->event_handler(cm_id, &cm_event);
40679- atomic_inc(&cm_closes);
40680+ atomic_inc_unchecked(&cm_closes);
40681 cm_event.event = IW_CM_EVENT_CLOSE;
40682 cm_event.status = 0;
40683 cm_event.provider_data = cm_id->provider_data;
40684@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40685 return;
40686 cm_id = cm_node->cm_id;
40687
40688- atomic_inc(&cm_connect_reqs);
40689+ atomic_inc_unchecked(&cm_connect_reqs);
40690 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40691 cm_node, cm_id, jiffies);
40692
40693@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40694 return;
40695 cm_id = cm_node->cm_id;
40696
40697- atomic_inc(&cm_connect_reqs);
40698+ atomic_inc_unchecked(&cm_connect_reqs);
40699 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40700 cm_node, cm_id, jiffies);
40701
40702diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40703index 4166452..fc952c3 100644
40704--- a/drivers/infiniband/hw/nes/nes_mgt.c
40705+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40706@@ -40,8 +40,8 @@
40707 #include "nes.h"
40708 #include "nes_mgt.h"
40709
40710-atomic_t pau_qps_created;
40711-atomic_t pau_qps_destroyed;
40712+atomic_unchecked_t pau_qps_created;
40713+atomic_unchecked_t pau_qps_destroyed;
40714
40715 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40716 {
40717@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40718 {
40719 struct sk_buff *skb;
40720 unsigned long flags;
40721- atomic_inc(&pau_qps_destroyed);
40722+ atomic_inc_unchecked(&pau_qps_destroyed);
40723
40724 /* Free packets that have not yet been forwarded */
40725 /* Lock is acquired by skb_dequeue when removing the skb */
40726@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40727 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40728 skb_queue_head_init(&nesqp->pau_list);
40729 spin_lock_init(&nesqp->pau_lock);
40730- atomic_inc(&pau_qps_created);
40731+ atomic_inc_unchecked(&pau_qps_created);
40732 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40733 }
40734
40735diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40736index 49eb511..a774366 100644
40737--- a/drivers/infiniband/hw/nes/nes_nic.c
40738+++ b/drivers/infiniband/hw/nes/nes_nic.c
40739@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40740 target_stat_values[++index] = mh_detected;
40741 target_stat_values[++index] = mh_pauses_sent;
40742 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40743- target_stat_values[++index] = atomic_read(&cm_connects);
40744- target_stat_values[++index] = atomic_read(&cm_accepts);
40745- target_stat_values[++index] = atomic_read(&cm_disconnects);
40746- target_stat_values[++index] = atomic_read(&cm_connecteds);
40747- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40748- target_stat_values[++index] = atomic_read(&cm_rejects);
40749- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40750- target_stat_values[++index] = atomic_read(&qps_created);
40751- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40752- target_stat_values[++index] = atomic_read(&qps_destroyed);
40753- target_stat_values[++index] = atomic_read(&cm_closes);
40754+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40755+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40756+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40757+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40758+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40759+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40760+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40761+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40762+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40763+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40764+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40765 target_stat_values[++index] = cm_packets_sent;
40766 target_stat_values[++index] = cm_packets_bounced;
40767 target_stat_values[++index] = cm_packets_created;
40768 target_stat_values[++index] = cm_packets_received;
40769 target_stat_values[++index] = cm_packets_dropped;
40770 target_stat_values[++index] = cm_packets_retrans;
40771- target_stat_values[++index] = atomic_read(&cm_listens_created);
40772- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40773+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40774+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40775 target_stat_values[++index] = cm_backlog_drops;
40776- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40777- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40778- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40779- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40780- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40781+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40782+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40783+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40784+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40785+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40786 target_stat_values[++index] = nesadapter->free_4kpbl;
40787 target_stat_values[++index] = nesadapter->free_256pbl;
40788 target_stat_values[++index] = int_mod_timer_init;
40789 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40790 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40791 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40792- target_stat_values[++index] = atomic_read(&pau_qps_created);
40793- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40794+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40795+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40796 }
40797
40798 /**
40799diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40800index 5b53ca5..443da3c 100644
40801--- a/drivers/infiniband/hw/nes/nes_verbs.c
40802+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40803@@ -46,9 +46,9 @@
40804
40805 #include <rdma/ib_umem.h>
40806
40807-atomic_t mod_qp_timouts;
40808-atomic_t qps_created;
40809-atomic_t sw_qps_destroyed;
40810+atomic_unchecked_t mod_qp_timouts;
40811+atomic_unchecked_t qps_created;
40812+atomic_unchecked_t sw_qps_destroyed;
40813
40814 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40815
40816@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40817 if (init_attr->create_flags)
40818 return ERR_PTR(-EINVAL);
40819
40820- atomic_inc(&qps_created);
40821+ atomic_inc_unchecked(&qps_created);
40822 switch (init_attr->qp_type) {
40823 case IB_QPT_RC:
40824 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40825@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40826 struct iw_cm_event cm_event;
40827 int ret = 0;
40828
40829- atomic_inc(&sw_qps_destroyed);
40830+ atomic_inc_unchecked(&sw_qps_destroyed);
40831 nesqp->destroyed = 1;
40832
40833 /* Blow away the connection if it exists. */
40834diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40835index 4a9af79..b993f75 100644
40836--- a/drivers/infiniband/hw/qib/qib.h
40837+++ b/drivers/infiniband/hw/qib/qib.h
40838@@ -52,6 +52,7 @@
40839 #include <linux/kref.h>
40840 #include <linux/sched.h>
40841 #include <linux/kthread.h>
40842+#include <linux/slab.h>
40843
40844 #include "qib_common.h"
40845 #include "qib_verbs.h"
40846diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40847index da739d9..da1c7f4 100644
40848--- a/drivers/input/gameport/gameport.c
40849+++ b/drivers/input/gameport/gameport.c
40850@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40851 */
40852 static void gameport_init_port(struct gameport *gameport)
40853 {
40854- static atomic_t gameport_no = ATOMIC_INIT(0);
40855+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40856
40857 __module_get(THIS_MODULE);
40858
40859 mutex_init(&gameport->drv_mutex);
40860 device_initialize(&gameport->dev);
40861 dev_set_name(&gameport->dev, "gameport%lu",
40862- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40863+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40864 gameport->dev.bus = &gameport_bus;
40865 gameport->dev.release = gameport_release_port;
40866 if (gameport->parent)
40867diff --git a/drivers/input/input.c b/drivers/input/input.c
40868index c044699..174d71a 100644
40869--- a/drivers/input/input.c
40870+++ b/drivers/input/input.c
40871@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
40872 */
40873 int input_register_device(struct input_dev *dev)
40874 {
40875- static atomic_t input_no = ATOMIC_INIT(0);
40876+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40877 struct input_devres *devres = NULL;
40878 struct input_handler *handler;
40879 unsigned int packet_size;
40880@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
40881 dev->setkeycode = input_default_setkeycode;
40882
40883 dev_set_name(&dev->dev, "input%ld",
40884- (unsigned long) atomic_inc_return(&input_no) - 1);
40885+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40886
40887 error = device_add(&dev->dev);
40888 if (error)
40889diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40890index 04c69af..5f92d00 100644
40891--- a/drivers/input/joystick/sidewinder.c
40892+++ b/drivers/input/joystick/sidewinder.c
40893@@ -30,6 +30,7 @@
40894 #include <linux/kernel.h>
40895 #include <linux/module.h>
40896 #include <linux/slab.h>
40897+#include <linux/sched.h>
40898 #include <linux/init.h>
40899 #include <linux/input.h>
40900 #include <linux/gameport.h>
40901diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
40902index 75e3b10..fb390fd 100644
40903--- a/drivers/input/joystick/xpad.c
40904+++ b/drivers/input/joystick/xpad.c
40905@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
40906
40907 static int xpad_led_probe(struct usb_xpad *xpad)
40908 {
40909- static atomic_t led_seq = ATOMIC_INIT(0);
40910+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
40911 long led_no;
40912 struct xpad_led *led;
40913 struct led_classdev *led_cdev;
40914@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
40915 if (!led)
40916 return -ENOMEM;
40917
40918- led_no = (long)atomic_inc_return(&led_seq) - 1;
40919+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
40920
40921 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
40922 led->xpad = xpad;
40923diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
40924index e204f26..8459f15 100644
40925--- a/drivers/input/misc/ims-pcu.c
40926+++ b/drivers/input/misc/ims-pcu.c
40927@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
40928
40929 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40930 {
40931- static atomic_t device_no = ATOMIC_INIT(0);
40932+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
40933
40934 const struct ims_pcu_device_info *info;
40935 u8 device_id;
40936@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40937 }
40938
40939 /* Device appears to be operable, complete initialization */
40940- pcu->device_no = atomic_inc_return(&device_no) - 1;
40941+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
40942
40943 error = ims_pcu_setup_backlight(pcu);
40944 if (error)
40945diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
40946index 2f0b39d..7370f13 100644
40947--- a/drivers/input/mouse/psmouse.h
40948+++ b/drivers/input/mouse/psmouse.h
40949@@ -116,7 +116,7 @@ struct psmouse_attribute {
40950 ssize_t (*set)(struct psmouse *psmouse, void *data,
40951 const char *buf, size_t count);
40952 bool protect;
40953-};
40954+} __do_const;
40955 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
40956
40957 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
40958diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
40959index 4c842c3..590b0bf 100644
40960--- a/drivers/input/mousedev.c
40961+++ b/drivers/input/mousedev.c
40962@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
40963
40964 spin_unlock_irq(&client->packet_lock);
40965
40966- if (copy_to_user(buffer, data, count))
40967+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
40968 return -EFAULT;
40969
40970 return count;
40971diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
40972index 25fc597..558bf3b3 100644
40973--- a/drivers/input/serio/serio.c
40974+++ b/drivers/input/serio/serio.c
40975@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
40976 */
40977 static void serio_init_port(struct serio *serio)
40978 {
40979- static atomic_t serio_no = ATOMIC_INIT(0);
40980+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
40981
40982 __module_get(THIS_MODULE);
40983
40984@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
40985 mutex_init(&serio->drv_mutex);
40986 device_initialize(&serio->dev);
40987 dev_set_name(&serio->dev, "serio%ld",
40988- (long)atomic_inc_return(&serio_no) - 1);
40989+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
40990 serio->dev.bus = &serio_bus;
40991 serio->dev.release = serio_release_port;
40992 serio->dev.groups = serio_device_attr_groups;
40993diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
40994index 59df2e7..8f1cafb 100644
40995--- a/drivers/input/serio/serio_raw.c
40996+++ b/drivers/input/serio/serio_raw.c
40997@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
40998
40999 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41000 {
41001- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41002+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41003 struct serio_raw *serio_raw;
41004 int err;
41005
41006@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41007 }
41008
41009 snprintf(serio_raw->name, sizeof(serio_raw->name),
41010- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41011+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41012 kref_init(&serio_raw->kref);
41013 INIT_LIST_HEAD(&serio_raw->client_list);
41014 init_waitqueue_head(&serio_raw->wait);
41015diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41016index fbe9ca7..dbee61d 100644
41017--- a/drivers/iommu/iommu.c
41018+++ b/drivers/iommu/iommu.c
41019@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41020 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41021 {
41022 bus_register_notifier(bus, &iommu_bus_nb);
41023- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41024+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41025 }
41026
41027 /**
41028diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41029index 39f81ae..2660096 100644
41030--- a/drivers/iommu/irq_remapping.c
41031+++ b/drivers/iommu/irq_remapping.c
41032@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41033 void panic_if_irq_remap(const char *msg)
41034 {
41035 if (irq_remapping_enabled)
41036- panic(msg);
41037+ panic("%s", msg);
41038 }
41039
41040 static void ir_ack_apic_edge(struct irq_data *data)
41041@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41042
41043 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41044 {
41045- chip->irq_print_chip = ir_print_prefix;
41046- chip->irq_ack = ir_ack_apic_edge;
41047- chip->irq_eoi = ir_ack_apic_level;
41048- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41049+ pax_open_kernel();
41050+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41051+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41052+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41053+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41054+ pax_close_kernel();
41055 }
41056
41057 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41058diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41059index ee7c503..5d4ce08 100644
41060--- a/drivers/irqchip/irq-gic.c
41061+++ b/drivers/irqchip/irq-gic.c
41062@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41063 * Supported arch specific GIC irq extension.
41064 * Default make them NULL.
41065 */
41066-struct irq_chip gic_arch_extn = {
41067+irq_chip_no_const gic_arch_extn = {
41068 .irq_eoi = NULL,
41069 .irq_mask = NULL,
41070 .irq_unmask = NULL,
41071@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41072 chained_irq_exit(chip, desc);
41073 }
41074
41075-static struct irq_chip gic_chip = {
41076+static irq_chip_no_const gic_chip __read_only = {
41077 .name = "GIC",
41078 .irq_mask = gic_mask_irq,
41079 .irq_unmask = gic_unmask_irq,
41080diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41081index ac6f72b..81150f2 100644
41082--- a/drivers/isdn/capi/capi.c
41083+++ b/drivers/isdn/capi/capi.c
41084@@ -81,8 +81,8 @@ struct capiminor {
41085
41086 struct capi20_appl *ap;
41087 u32 ncci;
41088- atomic_t datahandle;
41089- atomic_t msgid;
41090+ atomic_unchecked_t datahandle;
41091+ atomic_unchecked_t msgid;
41092
41093 struct tty_port port;
41094 int ttyinstop;
41095@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41096 capimsg_setu16(s, 2, mp->ap->applid);
41097 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41098 capimsg_setu8 (s, 5, CAPI_RESP);
41099- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41100+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41101 capimsg_setu32(s, 8, mp->ncci);
41102 capimsg_setu16(s, 12, datahandle);
41103 }
41104@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41105 mp->outbytes -= len;
41106 spin_unlock_bh(&mp->outlock);
41107
41108- datahandle = atomic_inc_return(&mp->datahandle);
41109+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41110 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41111 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41112 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41113 capimsg_setu16(skb->data, 2, mp->ap->applid);
41114 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41115 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41116- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41117+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41118 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41119 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41120 capimsg_setu16(skb->data, 16, len); /* Data length */
41121diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41122index 600c79b..3752bab 100644
41123--- a/drivers/isdn/gigaset/interface.c
41124+++ b/drivers/isdn/gigaset/interface.c
41125@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41126 }
41127 tty->driver_data = cs;
41128
41129- ++cs->port.count;
41130+ atomic_inc(&cs->port.count);
41131
41132- if (cs->port.count == 1) {
41133+ if (atomic_read(&cs->port.count) == 1) {
41134 tty_port_tty_set(&cs->port, tty);
41135 cs->port.low_latency = 1;
41136 }
41137@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41138
41139 if (!cs->connected)
41140 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41141- else if (!cs->port.count)
41142+ else if (!atomic_read(&cs->port.count))
41143 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41144- else if (!--cs->port.count)
41145+ else if (!atomic_dec_return(&cs->port.count))
41146 tty_port_tty_set(&cs->port, NULL);
41147
41148 mutex_unlock(&cs->mutex);
41149diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41150index d0a41cb..f0cdb8c 100644
41151--- a/drivers/isdn/gigaset/usb-gigaset.c
41152+++ b/drivers/isdn/gigaset/usb-gigaset.c
41153@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41154 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41155 memcpy(cs->hw.usb->bchars, buf, 6);
41156 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41157- 0, 0, &buf, 6, 2000);
41158+ 0, 0, buf, 6, 2000);
41159 }
41160
41161 static void gigaset_freebcshw(struct bc_state *bcs)
41162diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41163index 4d9b195..455075c 100644
41164--- a/drivers/isdn/hardware/avm/b1.c
41165+++ b/drivers/isdn/hardware/avm/b1.c
41166@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41167 }
41168 if (left) {
41169 if (t4file->user) {
41170- if (copy_from_user(buf, dp, left))
41171+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41172 return -EFAULT;
41173 } else {
41174 memcpy(buf, dp, left);
41175@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41176 }
41177 if (left) {
41178 if (config->user) {
41179- if (copy_from_user(buf, dp, left))
41180+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41181 return -EFAULT;
41182 } else {
41183 memcpy(buf, dp, left);
41184diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41185index 1063bab..36817e0 100644
41186--- a/drivers/isdn/hisax/amd7930_fn.c
41187+++ b/drivers/isdn/hisax/amd7930_fn.c
41188@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41189
41190 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41191 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41192- debugl1(cs, cs->dlog);
41193+ debugl1(cs, "%s", cs->dlog);
41194 }
41195 /* moves received data in sk-buffer */
41196 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41197@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41198
41199 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41200 QuickHex(t, deb_ptr, count);
41201- debugl1(cs, cs->dlog);
41202+ debugl1(cs, "%s", cs->dlog);
41203 }
41204 /* AMD interrupts on */
41205 AmdIrqOn(cs);
41206diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41207index ee9b9a0..d1427bd 100644
41208--- a/drivers/isdn/hisax/avm_pci.c
41209+++ b/drivers/isdn/hisax/avm_pci.c
41210@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41211 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41212 bcs->channel ? 'B' : 'A', count);
41213 QuickHex(t, p, count);
41214- debugl1(cs, bcs->blog);
41215+ debugl1(cs, "%s", bcs->blog);
41216 }
41217 }
41218
41219@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41220 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41221 bcs->channel ? 'B' : 'A', count);
41222 QuickHex(t, p, count);
41223- debugl1(cs, bcs->blog);
41224+ debugl1(cs, "%s", bcs->blog);
41225 }
41226 }
41227
41228diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41229index bf04d2a..b33f53b 100644
41230--- a/drivers/isdn/hisax/config.c
41231+++ b/drivers/isdn/hisax/config.c
41232@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41233 ptr--;
41234 *ptr++ = '\n';
41235 *ptr = 0;
41236- HiSax_putstatus(cs, NULL, cs->dlog);
41237+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41238 } else
41239 HiSax_putstatus(cs, "LogEcho: ",
41240 "warning Frame too big (%d)",
41241diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41242index 8d0cf6e..4fc90de 100644
41243--- a/drivers/isdn/hisax/diva.c
41244+++ b/drivers/isdn/hisax/diva.c
41245@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41246 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41247 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41248 QuickHex(t, ptr, count);
41249- debugl1(cs, bcs->blog);
41250+ debugl1(cs, "%s", bcs->blog);
41251 }
41252 }
41253
41254@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41255 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41256 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41257 QuickHex(t, ptr, count);
41258- debugl1(cs, bcs->blog);
41259+ debugl1(cs, "%s", bcs->blog);
41260 }
41261 }
41262
41263diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41264index 1df6f9a..2be1c8a 100644
41265--- a/drivers/isdn/hisax/elsa.c
41266+++ b/drivers/isdn/hisax/elsa.c
41267@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41268 t = tmp;
41269 t += sprintf(tmp, "Arcofi data");
41270 QuickHex(t, p, cs->dc.isac.mon_rxp);
41271- debugl1(cs, tmp);
41272+ debugl1(cs, "%s", tmp);
41273 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41274 switch (cs->dc.isac.mon_rx[1]) {
41275 case 0x80:
41276diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41277index d4c98d3..3f84dd8 100644
41278--- a/drivers/isdn/hisax/elsa_ser.c
41279+++ b/drivers/isdn/hisax/elsa_ser.c
41280@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41281
41282 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41283 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41284- debugl1(cs, tmp);
41285+ debugl1(cs, "%s", tmp);
41286 }
41287 cs->hw.elsa.rcvcnt = 0;
41288 }
41289diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41290index 3ccd724..497bd02 100644
41291--- a/drivers/isdn/hisax/hfc_pci.c
41292+++ b/drivers/isdn/hisax/hfc_pci.c
41293@@ -901,7 +901,7 @@ Begin:
41294 ptr--;
41295 *ptr++ = '\n';
41296 *ptr = 0;
41297- HiSax_putstatus(cs, NULL, cs->dlog);
41298+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41299 } else
41300 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41301 }
41302diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41303index dc4574f..fa1fefd 100644
41304--- a/drivers/isdn/hisax/hfc_sx.c
41305+++ b/drivers/isdn/hisax/hfc_sx.c
41306@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41307 ptr--;
41308 *ptr++ = '\n';
41309 *ptr = 0;
41310- HiSax_putstatus(cs, NULL, cs->dlog);
41311+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41312 } else
41313 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41314 }
41315diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41316index f398d48..a8d6188 100644
41317--- a/drivers/isdn/hisax/hscx_irq.c
41318+++ b/drivers/isdn/hisax/hscx_irq.c
41319@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41320 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41321 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41322 QuickHex(t, ptr, count);
41323- debugl1(cs, bcs->blog);
41324+ debugl1(cs, "%s", bcs->blog);
41325 }
41326 }
41327
41328@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41329 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41330 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41331 QuickHex(t, ptr, count);
41332- debugl1(cs, bcs->blog);
41333+ debugl1(cs, "%s", bcs->blog);
41334 }
41335 }
41336
41337diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41338index db5321f..51dae91 100644
41339--- a/drivers/isdn/hisax/icc.c
41340+++ b/drivers/isdn/hisax/icc.c
41341@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41342
41343 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41344 QuickHex(t, ptr, count);
41345- debugl1(cs, cs->dlog);
41346+ debugl1(cs, "%s", cs->dlog);
41347 }
41348 }
41349
41350@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41351
41352 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41353 QuickHex(t, ptr, count);
41354- debugl1(cs, cs->dlog);
41355+ debugl1(cs, "%s", cs->dlog);
41356 }
41357 }
41358
41359diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41360index 74feb5c..5faa5de 100644
41361--- a/drivers/isdn/hisax/ipacx.c
41362+++ b/drivers/isdn/hisax/ipacx.c
41363@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41364
41365 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41366 QuickHex(t, ptr, count);
41367- debugl1(cs, cs->dlog);
41368+ debugl1(cs, "%s", cs->dlog);
41369 }
41370 }
41371
41372@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41373
41374 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41375 QuickHex(t, ptr, count);
41376- debugl1(cs, cs->dlog);
41377+ debugl1(cs, "%s", cs->dlog);
41378 }
41379 }
41380
41381@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41382
41383 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41384 QuickHex(t, ptr, count);
41385- debugl1(cs, bcs->blog);
41386+ debugl1(cs, "%s", bcs->blog);
41387 }
41388 }
41389
41390@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41391
41392 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41393 QuickHex(t, ptr, count);
41394- debugl1(cs, bcs->blog);
41395+ debugl1(cs, "%s", bcs->blog);
41396 }
41397 }
41398
41399diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41400index a365ccc..7fdf78f 100644
41401--- a/drivers/isdn/hisax/isac.c
41402+++ b/drivers/isdn/hisax/isac.c
41403@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41404
41405 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41406 QuickHex(t, ptr, count);
41407- debugl1(cs, cs->dlog);
41408+ debugl1(cs, "%s", cs->dlog);
41409 }
41410 }
41411
41412@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41413
41414 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41415 QuickHex(t, ptr, count);
41416- debugl1(cs, cs->dlog);
41417+ debugl1(cs, "%s", cs->dlog);
41418 }
41419 }
41420
41421diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41422index 7fdf347..f4956c7 100644
41423--- a/drivers/isdn/hisax/isar.c
41424+++ b/drivers/isdn/hisax/isar.c
41425@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41426 t = tmp;
41427 t += sprintf(t, "sendmbox cnt %d", len);
41428 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41429- debugl1(cs, tmp);
41430+ debugl1(cs, "%s", tmp);
41431 i -= 64;
41432 }
41433 }
41434@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41435 t = tmp;
41436 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41437 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41438- debugl1(cs, tmp);
41439+ debugl1(cs, "%s", tmp);
41440 i -= 64;
41441 }
41442 }
41443@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41444 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41445 ireg->iis, ireg->cmsb);
41446 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41447- debugl1(cs, debbuf);
41448+ debugl1(cs, "%s", debbuf);
41449 }
41450 break;
41451 case ISAR_IIS_INVMSG:
41452diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41453index f946c58..e2ae787 100644
41454--- a/drivers/isdn/hisax/jade.c
41455+++ b/drivers/isdn/hisax/jade.c
41456@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41457 int jade = bcs->hw.hscx.hscx;
41458
41459 if (cs->debug & L1_DEB_HSCX) {
41460- char tmp[40];
41461- sprintf(tmp, "jade %c mode %d ichan %d",
41462- 'A' + jade, mode, bc);
41463- debugl1(cs, tmp);
41464+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41465 }
41466 bcs->mode = mode;
41467 bcs->channel = bc;
41468@@ -257,23 +254,18 @@ void
41469 clear_pending_jade_ints(struct IsdnCardState *cs)
41470 {
41471 int val;
41472- char tmp[64];
41473
41474 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41475 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41476
41477 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41478- sprintf(tmp, "jade B ISTA %x", val);
41479- debugl1(cs, tmp);
41480+ debugl1(cs, "jade B ISTA %x", val);
41481 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41482- sprintf(tmp, "jade A ISTA %x", val);
41483- debugl1(cs, tmp);
41484+ debugl1(cs, "jade A ISTA %x", val);
41485 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41486- sprintf(tmp, "jade B STAR %x", val);
41487- debugl1(cs, tmp);
41488+ debugl1(cs, "jade B STAR %x", val);
41489 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41490- sprintf(tmp, "jade A STAR %x", val);
41491- debugl1(cs, tmp);
41492+ debugl1(cs, "jade A STAR %x", val);
41493 /* Unmask ints */
41494 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41495 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41496diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41497index f521fc8..b930da9 100644
41498--- a/drivers/isdn/hisax/jade_irq.c
41499+++ b/drivers/isdn/hisax/jade_irq.c
41500@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41501 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41502 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41503 QuickHex(t, ptr, count);
41504- debugl1(cs, bcs->blog);
41505+ debugl1(cs, "%s", bcs->blog);
41506 }
41507 }
41508
41509@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41510 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41511 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41512 QuickHex(t, ptr, count);
41513- debugl1(cs, bcs->blog);
41514+ debugl1(cs, "%s", bcs->blog);
41515 }
41516 }
41517
41518diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41519index 4c1bca5..875402e 100644
41520--- a/drivers/isdn/hisax/l3_1tr6.c
41521+++ b/drivers/isdn/hisax/l3_1tr6.c
41522@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41523 {
41524 dev_kfree_skb(skb);
41525 if (pc->st->l3.debug & L3_DEB_WARN)
41526- l3_debug(pc->st, msg);
41527+ l3_debug(pc->st, "%s", msg);
41528 l3_1tr6_release_req(pc, 0, NULL);
41529 }
41530
41531@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41532 {
41533 u_char *p;
41534 int bcfound = 0;
41535- char tmp[80];
41536 struct sk_buff *skb = arg;
41537
41538 /* Channel Identification */
41539@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41540 /* Signal all services, linklevel takes care of Service-Indicator */
41541 if (bcfound) {
41542 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41543- sprintf(tmp, "non-digital call: %s -> %s",
41544+ l3_debug(pc->st, "non-digital call: %s -> %s",
41545 pc->para.setup.phone,
41546 pc->para.setup.eazmsn);
41547- l3_debug(pc->st, tmp);
41548 }
41549 newl3state(pc, 6);
41550 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41551@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41552 {
41553 u_char *p;
41554 int i, tmpcharge = 0;
41555- char a_charge[8], tmp[32];
41556+ char a_charge[8];
41557 struct sk_buff *skb = arg;
41558
41559 p = skb->data;
41560@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41561 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41562 }
41563 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41564- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41565- l3_debug(pc->st, tmp);
41566+ l3_debug(pc->st, "charging info %d",
41567+ pc->para.chargeinfo);
41568 }
41569 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41570 l3_debug(pc->st, "charging info not found");
41571@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41572 struct sk_buff *skb = arg;
41573 u_char *p;
41574 int i, tmpcharge = 0;
41575- char a_charge[8], tmp[32];
41576+ char a_charge[8];
41577
41578 StopAllL3Timer(pc);
41579 p = skb->data;
41580@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41581 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41582 }
41583 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41584- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41585- l3_debug(pc->st, tmp);
41586+ l3_debug(pc->st, "charging info %d",
41587+ pc->para.chargeinfo);
41588 }
41589 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41590 l3_debug(pc->st, "charging info not found");
41591@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41592 int i, mt, cr;
41593 struct l3_process *proc;
41594 struct sk_buff *skb = arg;
41595- char tmp[80];
41596
41597 switch (pr) {
41598 case (DL_DATA | INDICATION):
41599@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41600 }
41601 if (skb->len < 4) {
41602 if (st->l3.debug & L3_DEB_PROTERR) {
41603- sprintf(tmp, "up1tr6 len only %d", skb->len);
41604- l3_debug(st, tmp);
41605+ l3_debug(st, "up1tr6 len only %d", skb->len);
41606 }
41607 dev_kfree_skb(skb);
41608 return;
41609 }
41610 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41611 if (st->l3.debug & L3_DEB_PROTERR) {
41612- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41613+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41614 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41615 skb->data[0], skb->len);
41616- l3_debug(st, tmp);
41617 }
41618 dev_kfree_skb(skb);
41619 return;
41620 }
41621 if (skb->data[1] != 1) {
41622 if (st->l3.debug & L3_DEB_PROTERR) {
41623- sprintf(tmp, "up1tr6 CR len not 1");
41624- l3_debug(st, tmp);
41625+ l3_debug(st, "up1tr6 CR len not 1");
41626 }
41627 dev_kfree_skb(skb);
41628 return;
41629@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41630 if (skb->data[0] == PROTO_DIS_N0) {
41631 dev_kfree_skb(skb);
41632 if (st->l3.debug & L3_DEB_STATE) {
41633- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41634+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41635 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41636- l3_debug(st, tmp);
41637 }
41638 } else if (skb->data[0] == PROTO_DIS_N1) {
41639 if (!(proc = getl3proc(st, cr))) {
41640@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41641 if (cr < 128) {
41642 if (!(proc = new_l3_process(st, cr))) {
41643 if (st->l3.debug & L3_DEB_PROTERR) {
41644- sprintf(tmp, "up1tr6 no roc mem");
41645- l3_debug(st, tmp);
41646+ l3_debug(st, "up1tr6 no roc mem");
41647 }
41648 dev_kfree_skb(skb);
41649 return;
41650@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41651 } else {
41652 if (!(proc = new_l3_process(st, cr))) {
41653 if (st->l3.debug & L3_DEB_PROTERR) {
41654- sprintf(tmp, "up1tr6 no roc mem");
41655- l3_debug(st, tmp);
41656+ l3_debug(st, "up1tr6 no roc mem");
41657 }
41658 dev_kfree_skb(skb);
41659 return;
41660@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41661 if (i == ARRAY_SIZE(datastln1)) {
41662 dev_kfree_skb(skb);
41663 if (st->l3.debug & L3_DEB_STATE) {
41664- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41665+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41666 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41667 proc->state, mt);
41668- l3_debug(st, tmp);
41669 }
41670 return;
41671 } else {
41672 if (st->l3.debug & L3_DEB_STATE) {
41673- sprintf(tmp, "up1tr6%sstate %d mt %x",
41674+ l3_debug(st, "up1tr6%sstate %d mt %x",
41675 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41676 proc->state, mt);
41677- l3_debug(st, tmp);
41678 }
41679 datastln1[i].rout(proc, pr, skb);
41680 }
41681@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41682 int i, cr;
41683 struct l3_process *proc;
41684 struct Channel *chan;
41685- char tmp[80];
41686
41687 if ((DL_ESTABLISH | REQUEST) == pr) {
41688 l3_msg(st, pr, NULL);
41689@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41690 break;
41691 if (i == ARRAY_SIZE(downstl)) {
41692 if (st->l3.debug & L3_DEB_STATE) {
41693- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41694+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41695 proc->state, pr);
41696- l3_debug(st, tmp);
41697 }
41698 } else {
41699 if (st->l3.debug & L3_DEB_STATE) {
41700- sprintf(tmp, "down1tr6 state %d prim %d",
41701+ l3_debug(st, "down1tr6 state %d prim %d",
41702 proc->state, pr);
41703- l3_debug(st, tmp);
41704 }
41705 downstl[i].rout(proc, pr, arg);
41706 }
41707diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41708index b646eed..233e432 100644
41709--- a/drivers/isdn/hisax/netjet.c
41710+++ b/drivers/isdn/hisax/netjet.c
41711@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41712 else
41713 j = i;
41714 QuickHex(t, p, j);
41715- debugl1(cs, tmp);
41716+ debugl1(cs, "%s", tmp);
41717 p += j;
41718 i -= j;
41719 t = tmp;
41720diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41721index 041bf52..af1b020 100644
41722--- a/drivers/isdn/hisax/q931.c
41723+++ b/drivers/isdn/hisax/q931.c
41724@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41725 dp--;
41726 *dp++ = '\n';
41727 *dp = 0;
41728- HiSax_putstatus(cs, NULL, cs->dlog);
41729+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41730 } else
41731 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41732 }
41733@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41734 }
41735 if (finish) {
41736 *dp = 0;
41737- HiSax_putstatus(cs, NULL, cs->dlog);
41738+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41739 return;
41740 }
41741 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41742@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41743 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41744 }
41745 *dp = 0;
41746- HiSax_putstatus(cs, NULL, cs->dlog);
41747+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41748 }
41749diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41750index d8cac69..a858955 100644
41751--- a/drivers/isdn/hisax/w6692.c
41752+++ b/drivers/isdn/hisax/w6692.c
41753@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41754
41755 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41756 QuickHex(t, ptr, count);
41757- debugl1(cs, cs->dlog);
41758+ debugl1(cs, "%s", cs->dlog);
41759 }
41760 }
41761
41762@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41763
41764 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41765 QuickHex(t, ptr, count);
41766- debugl1(cs, cs->dlog);
41767+ debugl1(cs, "%s", cs->dlog);
41768 }
41769 }
41770
41771@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
41772 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
41773 bcs->channel + '1', count);
41774 QuickHex(t, ptr, count);
41775- debugl1(cs, bcs->blog);
41776+ debugl1(cs, "%s", bcs->blog);
41777 }
41778 }
41779
41780@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
41781 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
41782 bcs->channel + '1', count);
41783 QuickHex(t, ptr, count);
41784- debugl1(cs, bcs->blog);
41785+ debugl1(cs, "%s", bcs->blog);
41786 }
41787 }
41788
41789diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41790index 9bb12ba..d4262f7 100644
41791--- a/drivers/isdn/i4l/isdn_common.c
41792+++ b/drivers/isdn/i4l/isdn_common.c
41793@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41794 } else
41795 return -EINVAL;
41796 case IIOCDBGVAR:
41797+ if (!capable(CAP_SYS_RAWIO))
41798+ return -EPERM;
41799 if (arg) {
41800 if (copy_to_user(argp, &dev, sizeof(ulong)))
41801 return -EFAULT;
41802diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41803index 3c5f249..5fac4d0 100644
41804--- a/drivers/isdn/i4l/isdn_tty.c
41805+++ b/drivers/isdn/i4l/isdn_tty.c
41806@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41807
41808 #ifdef ISDN_DEBUG_MODEM_OPEN
41809 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41810- port->count);
41811+ atomic_read(&port->count));
41812 #endif
41813- port->count++;
41814+ atomic_inc(&port->count);
41815 port->tty = tty;
41816 /*
41817 * Start up serial port
41818@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41819 #endif
41820 return;
41821 }
41822- if ((tty->count == 1) && (port->count != 1)) {
41823+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41824 /*
41825 * Uh, oh. tty->count is 1, which means that the tty
41826 * structure will be freed. Info->count should always
41827@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41828 * serial port won't be shutdown.
41829 */
41830 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41831- "info->count is %d\n", port->count);
41832- port->count = 1;
41833+ "info->count is %d\n", atomic_read(&port->count));
41834+ atomic_set(&port->count, 1);
41835 }
41836- if (--port->count < 0) {
41837+ if (atomic_dec_return(&port->count) < 0) {
41838 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41839- info->line, port->count);
41840- port->count = 0;
41841+ info->line, atomic_read(&port->count));
41842+ atomic_set(&port->count, 0);
41843 }
41844- if (port->count) {
41845+ if (atomic_read(&port->count)) {
41846 #ifdef ISDN_DEBUG_MODEM_OPEN
41847 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41848 #endif
41849@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41850 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41851 return;
41852 isdn_tty_shutdown(info);
41853- port->count = 0;
41854+ atomic_set(&port->count, 0);
41855 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41856 port->tty = NULL;
41857 wake_up_interruptible(&port->open_wait);
41858@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41859 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41860 modem_info *info = &dev->mdm.info[i];
41861
41862- if (info->port.count == 0)
41863+ if (atomic_read(&info->port.count) == 0)
41864 continue;
41865 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41866 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41867diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41868index e74df7c..03a03ba 100644
41869--- a/drivers/isdn/icn/icn.c
41870+++ b/drivers/isdn/icn/icn.c
41871@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41872 if (count > len)
41873 count = len;
41874 if (user) {
41875- if (copy_from_user(msg, buf, count))
41876+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41877 return -EFAULT;
41878 } else
41879 memcpy(msg, buf, count);
41880diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41881index 6a8405d..0bd1c7e 100644
41882--- a/drivers/leds/leds-clevo-mail.c
41883+++ b/drivers/leds/leds-clevo-mail.c
41884@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41885 * detected as working, but in reality it is not) as low as
41886 * possible.
41887 */
41888-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
41889+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
41890 {
41891 .callback = clevo_mail_led_dmi_callback,
41892 .ident = "Clevo D410J",
41893diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41894index 64e204e..c6bf189 100644
41895--- a/drivers/leds/leds-ss4200.c
41896+++ b/drivers/leds/leds-ss4200.c
41897@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41898 * detected as working, but in reality it is not) as low as
41899 * possible.
41900 */
41901-static struct dmi_system_id __initdata nas_led_whitelist[] = {
41902+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
41903 {
41904 .callback = ss4200_led_dmi_callback,
41905 .ident = "Intel SS4200-E",
41906diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41907index 0bf1e4e..b4bf44e 100644
41908--- a/drivers/lguest/core.c
41909+++ b/drivers/lguest/core.c
41910@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41911 * The end address needs +1 because __get_vm_area allocates an
41912 * extra guard page, so we need space for that.
41913 */
41914+
41915+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41916+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41917+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41918+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41919+#else
41920 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41921 VM_ALLOC, switcher_addr, switcher_addr
41922 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41923+#endif
41924+
41925 if (!switcher_vma) {
41926 err = -ENOMEM;
41927 printk("lguest: could not map switcher pages high\n");
41928@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41929 * Now the Switcher is mapped at the right address, we can't fail!
41930 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41931 */
41932- memcpy(switcher_vma->addr, start_switcher_text,
41933+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41934 end_switcher_text - start_switcher_text);
41935
41936 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41937diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41938index a35d8d1..59fb772 100644
41939--- a/drivers/lguest/page_tables.c
41940+++ b/drivers/lguest/page_tables.c
41941@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41942 /*:*/
41943
41944 #ifdef CONFIG_X86_PAE
41945-static void release_pmd(pmd_t *spmd)
41946+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41947 {
41948 /* If the entry's not present, there's nothing to release. */
41949 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41950diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41951index 5169239..47cb4db 100644
41952--- a/drivers/lguest/x86/core.c
41953+++ b/drivers/lguest/x86/core.c
41954@@ -59,7 +59,7 @@ static struct {
41955 /* Offset from where switcher.S was compiled to where we've copied it */
41956 static unsigned long switcher_offset(void)
41957 {
41958- return switcher_addr - (unsigned long)start_switcher_text;
41959+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41960 }
41961
41962 /* This cpu's struct lguest_pages (after the Switcher text page) */
41963@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
41964 * These copies are pretty cheap, so we do them unconditionally: */
41965 /* Save the current Host top-level page directory.
41966 */
41967+
41968+#ifdef CONFIG_PAX_PER_CPU_PGD
41969+ pages->state.host_cr3 = read_cr3();
41970+#else
41971 pages->state.host_cr3 = __pa(current->mm->pgd);
41972+#endif
41973+
41974 /*
41975 * Set up the Guest's page tables to see this CPU's pages (and no
41976 * other CPU's pages).
41977@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
41978 * compiled-in switcher code and the high-mapped copy we just made.
41979 */
41980 for (i = 0; i < IDT_ENTRIES; i++)
41981- default_idt_entries[i] += switcher_offset();
41982+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
41983
41984 /*
41985 * Set up the Switcher's per-cpu areas.
41986@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
41987 * it will be undisturbed when we switch. To change %cs and jump we
41988 * need this structure to feed to Intel's "lcall" instruction.
41989 */
41990- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
41991+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
41992 lguest_entry.segment = LGUEST_CS;
41993
41994 /*
41995diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
41996index 40634b0..4f5855e 100644
41997--- a/drivers/lguest/x86/switcher_32.S
41998+++ b/drivers/lguest/x86/switcher_32.S
41999@@ -87,6 +87,7 @@
42000 #include <asm/page.h>
42001 #include <asm/segment.h>
42002 #include <asm/lguest.h>
42003+#include <asm/processor-flags.h>
42004
42005 // We mark the start of the code to copy
42006 // It's placed in .text tho it's never run here
42007@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42008 // Changes type when we load it: damn Intel!
42009 // For after we switch over our page tables
42010 // That entry will be read-only: we'd crash.
42011+
42012+#ifdef CONFIG_PAX_KERNEXEC
42013+ mov %cr0, %edx
42014+ xor $X86_CR0_WP, %edx
42015+ mov %edx, %cr0
42016+#endif
42017+
42018 movl $(GDT_ENTRY_TSS*8), %edx
42019 ltr %dx
42020
42021@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42022 // Let's clear it again for our return.
42023 // The GDT descriptor of the Host
42024 // Points to the table after two "size" bytes
42025- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42026+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42027 // Clear "used" from type field (byte 5, bit 2)
42028- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42029+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42030+
42031+#ifdef CONFIG_PAX_KERNEXEC
42032+ mov %cr0, %eax
42033+ xor $X86_CR0_WP, %eax
42034+ mov %eax, %cr0
42035+#endif
42036
42037 // Once our page table's switched, the Guest is live!
42038 // The Host fades as we run this final step.
42039@@ -295,13 +309,12 @@ deliver_to_host:
42040 // I consulted gcc, and it gave
42041 // These instructions, which I gladly credit:
42042 leal (%edx,%ebx,8), %eax
42043- movzwl (%eax),%edx
42044- movl 4(%eax), %eax
42045- xorw %ax, %ax
42046- orl %eax, %edx
42047+ movl 4(%eax), %edx
42048+ movw (%eax), %dx
42049 // Now the address of the handler's in %edx
42050 // We call it now: its "iret" drops us home.
42051- jmp *%edx
42052+ ljmp $__KERNEL_CS, $1f
42053+1: jmp *%edx
42054
42055 // Every interrupt can come to us here
42056 // But we must truly tell each apart.
42057diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42058index 0003992..854bbce 100644
42059--- a/drivers/md/bcache/closure.h
42060+++ b/drivers/md/bcache/closure.h
42061@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42062 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42063 struct workqueue_struct *wq)
42064 {
42065- BUG_ON(object_is_on_stack(cl));
42066+ BUG_ON(object_starts_on_stack(cl));
42067 closure_set_ip(cl);
42068 cl->fn = fn;
42069 cl->wq = wq;
42070diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42071index 547c4c5..5be1de4 100644
42072--- a/drivers/md/bcache/super.c
42073+++ b/drivers/md/bcache/super.c
42074@@ -1644,7 +1644,7 @@ err_unlock_gc:
42075 err:
42076 closure_sync(&op.cl);
42077 /* XXX: test this, it's broken */
42078- bch_cache_set_error(c, err);
42079+ bch_cache_set_error(c, "%s", err);
42080 }
42081
42082 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42083diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42084index a7fd821..9dcf6c3 100644
42085--- a/drivers/md/bitmap.c
42086+++ b/drivers/md/bitmap.c
42087@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42088 chunk_kb ? "KB" : "B");
42089 if (bitmap->storage.file) {
42090 seq_printf(seq, ", file: ");
42091- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42092+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42093 }
42094
42095 seq_printf(seq, "\n");
42096diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42097index f1b7586..a49c4bd 100644
42098--- a/drivers/md/dm-ioctl.c
42099+++ b/drivers/md/dm-ioctl.c
42100@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42101 cmd == DM_LIST_VERSIONS_CMD)
42102 return 0;
42103
42104- if ((cmd == DM_DEV_CREATE_CMD)) {
42105+ if (cmd == DM_DEV_CREATE_CMD) {
42106 if (!*param->name) {
42107 DMWARN("name not supplied when creating device");
42108 return -EINVAL;
42109diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42110index 699b5be..eac0a15 100644
42111--- a/drivers/md/dm-raid1.c
42112+++ b/drivers/md/dm-raid1.c
42113@@ -40,7 +40,7 @@ enum dm_raid1_error {
42114
42115 struct mirror {
42116 struct mirror_set *ms;
42117- atomic_t error_count;
42118+ atomic_unchecked_t error_count;
42119 unsigned long error_type;
42120 struct dm_dev *dev;
42121 sector_t offset;
42122@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42123 struct mirror *m;
42124
42125 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42126- if (!atomic_read(&m->error_count))
42127+ if (!atomic_read_unchecked(&m->error_count))
42128 return m;
42129
42130 return NULL;
42131@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42132 * simple way to tell if a device has encountered
42133 * errors.
42134 */
42135- atomic_inc(&m->error_count);
42136+ atomic_inc_unchecked(&m->error_count);
42137
42138 if (test_and_set_bit(error_type, &m->error_type))
42139 return;
42140@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42141 struct mirror *m = get_default_mirror(ms);
42142
42143 do {
42144- if (likely(!atomic_read(&m->error_count)))
42145+ if (likely(!atomic_read_unchecked(&m->error_count)))
42146 return m;
42147
42148 if (m-- == ms->mirror)
42149@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42150 {
42151 struct mirror *default_mirror = get_default_mirror(m->ms);
42152
42153- return !atomic_read(&default_mirror->error_count);
42154+ return !atomic_read_unchecked(&default_mirror->error_count);
42155 }
42156
42157 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42158@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42159 */
42160 if (likely(region_in_sync(ms, region, 1)))
42161 m = choose_mirror(ms, bio->bi_sector);
42162- else if (m && atomic_read(&m->error_count))
42163+ else if (m && atomic_read_unchecked(&m->error_count))
42164 m = NULL;
42165
42166 if (likely(m))
42167@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42168 }
42169
42170 ms->mirror[mirror].ms = ms;
42171- atomic_set(&(ms->mirror[mirror].error_count), 0);
42172+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42173 ms->mirror[mirror].error_type = 0;
42174 ms->mirror[mirror].offset = offset;
42175
42176@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42177 */
42178 static char device_status_char(struct mirror *m)
42179 {
42180- if (!atomic_read(&(m->error_count)))
42181+ if (!atomic_read_unchecked(&(m->error_count)))
42182 return 'A';
42183
42184 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42185diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42186index d907ca6..cfb8384 100644
42187--- a/drivers/md/dm-stripe.c
42188+++ b/drivers/md/dm-stripe.c
42189@@ -20,7 +20,7 @@ struct stripe {
42190 struct dm_dev *dev;
42191 sector_t physical_start;
42192
42193- atomic_t error_count;
42194+ atomic_unchecked_t error_count;
42195 };
42196
42197 struct stripe_c {
42198@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42199 kfree(sc);
42200 return r;
42201 }
42202- atomic_set(&(sc->stripe[i].error_count), 0);
42203+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42204 }
42205
42206 ti->private = sc;
42207@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42208 DMEMIT("%d ", sc->stripes);
42209 for (i = 0; i < sc->stripes; i++) {
42210 DMEMIT("%s ", sc->stripe[i].dev->name);
42211- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42212+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42213 'D' : 'A';
42214 }
42215 buffer[i] = '\0';
42216@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42217 */
42218 for (i = 0; i < sc->stripes; i++)
42219 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42220- atomic_inc(&(sc->stripe[i].error_count));
42221- if (atomic_read(&(sc->stripe[i].error_count)) <
42222+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42223+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42224 DM_IO_ERROR_THRESHOLD)
42225 schedule_work(&sc->trigger_event);
42226 }
42227diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42228index f221812..aca962b 100644
42229--- a/drivers/md/dm-table.c
42230+++ b/drivers/md/dm-table.c
42231@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42232 if (!dev_size)
42233 return 0;
42234
42235- if ((start >= dev_size) || (start + len > dev_size)) {
42236+ if ((start >= dev_size) || (len > dev_size - start)) {
42237 DMWARN("%s: %s too small for target: "
42238 "start=%llu, len=%llu, dev_size=%llu",
42239 dm_device_name(ti->table->md), bdevname(bdev, b),
42240diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42241index 60bce43..9b997d0 100644
42242--- a/drivers/md/dm-thin-metadata.c
42243+++ b/drivers/md/dm-thin-metadata.c
42244@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42245 {
42246 pmd->info.tm = pmd->tm;
42247 pmd->info.levels = 2;
42248- pmd->info.value_type.context = pmd->data_sm;
42249+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42250 pmd->info.value_type.size = sizeof(__le64);
42251 pmd->info.value_type.inc = data_block_inc;
42252 pmd->info.value_type.dec = data_block_dec;
42253@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42254
42255 pmd->bl_info.tm = pmd->tm;
42256 pmd->bl_info.levels = 1;
42257- pmd->bl_info.value_type.context = pmd->data_sm;
42258+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42259 pmd->bl_info.value_type.size = sizeof(__le64);
42260 pmd->bl_info.value_type.inc = data_block_inc;
42261 pmd->bl_info.value_type.dec = data_block_dec;
42262diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42263index 995e1fc..2468cec 100644
42264--- a/drivers/md/dm.c
42265+++ b/drivers/md/dm.c
42266@@ -178,9 +178,9 @@ struct mapped_device {
42267 /*
42268 * Event handling.
42269 */
42270- atomic_t event_nr;
42271+ atomic_unchecked_t event_nr;
42272 wait_queue_head_t eventq;
42273- atomic_t uevent_seq;
42274+ atomic_unchecked_t uevent_seq;
42275 struct list_head uevent_list;
42276 spinlock_t uevent_lock; /* Protect access to uevent_list */
42277
42278@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42279 spin_lock_init(&md->deferred_lock);
42280 atomic_set(&md->holders, 1);
42281 atomic_set(&md->open_count, 0);
42282- atomic_set(&md->event_nr, 0);
42283- atomic_set(&md->uevent_seq, 0);
42284+ atomic_set_unchecked(&md->event_nr, 0);
42285+ atomic_set_unchecked(&md->uevent_seq, 0);
42286 INIT_LIST_HEAD(&md->uevent_list);
42287 spin_lock_init(&md->uevent_lock);
42288
42289@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42290
42291 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42292
42293- atomic_inc(&md->event_nr);
42294+ atomic_inc_unchecked(&md->event_nr);
42295 wake_up(&md->eventq);
42296 }
42297
42298@@ -2727,18 +2727,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42299
42300 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42301 {
42302- return atomic_add_return(1, &md->uevent_seq);
42303+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42304 }
42305
42306 uint32_t dm_get_event_nr(struct mapped_device *md)
42307 {
42308- return atomic_read(&md->event_nr);
42309+ return atomic_read_unchecked(&md->event_nr);
42310 }
42311
42312 int dm_wait_event(struct mapped_device *md, int event_nr)
42313 {
42314 return wait_event_interruptible(md->eventq,
42315- (event_nr != atomic_read(&md->event_nr)));
42316+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42317 }
42318
42319 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42320diff --git a/drivers/md/md.c b/drivers/md/md.c
42321index 9f13e13..411a5b8 100644
42322--- a/drivers/md/md.c
42323+++ b/drivers/md/md.c
42324@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42325 * start build, activate spare
42326 */
42327 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42328-static atomic_t md_event_count;
42329+static atomic_unchecked_t md_event_count;
42330 void md_new_event(struct mddev *mddev)
42331 {
42332- atomic_inc(&md_event_count);
42333+ atomic_inc_unchecked(&md_event_count);
42334 wake_up(&md_event_waiters);
42335 }
42336 EXPORT_SYMBOL_GPL(md_new_event);
42337@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42338 */
42339 static void md_new_event_inintr(struct mddev *mddev)
42340 {
42341- atomic_inc(&md_event_count);
42342+ atomic_inc_unchecked(&md_event_count);
42343 wake_up(&md_event_waiters);
42344 }
42345
42346@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42347 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42348 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42349 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42350- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42351+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42352
42353 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42354 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42355@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42356 else
42357 sb->resync_offset = cpu_to_le64(0);
42358
42359- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42360+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42361
42362 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42363 sb->size = cpu_to_le64(mddev->dev_sectors);
42364@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42365 static ssize_t
42366 errors_show(struct md_rdev *rdev, char *page)
42367 {
42368- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42369+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42370 }
42371
42372 static ssize_t
42373@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42374 char *e;
42375 unsigned long n = simple_strtoul(buf, &e, 10);
42376 if (*buf && (*e == 0 || *e == '\n')) {
42377- atomic_set(&rdev->corrected_errors, n);
42378+ atomic_set_unchecked(&rdev->corrected_errors, n);
42379 return len;
42380 }
42381 return -EINVAL;
42382@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42383 rdev->sb_loaded = 0;
42384 rdev->bb_page = NULL;
42385 atomic_set(&rdev->nr_pending, 0);
42386- atomic_set(&rdev->read_errors, 0);
42387- atomic_set(&rdev->corrected_errors, 0);
42388+ atomic_set_unchecked(&rdev->read_errors, 0);
42389+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42390
42391 INIT_LIST_HEAD(&rdev->same_set);
42392 init_waitqueue_head(&rdev->blocked_wait);
42393@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42394
42395 spin_unlock(&pers_lock);
42396 seq_printf(seq, "\n");
42397- seq->poll_event = atomic_read(&md_event_count);
42398+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42399 return 0;
42400 }
42401 if (v == (void*)2) {
42402@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42403 return error;
42404
42405 seq = file->private_data;
42406- seq->poll_event = atomic_read(&md_event_count);
42407+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42408 return error;
42409 }
42410
42411@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42412 /* always allow read */
42413 mask = POLLIN | POLLRDNORM;
42414
42415- if (seq->poll_event != atomic_read(&md_event_count))
42416+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42417 mask |= POLLERR | POLLPRI;
42418 return mask;
42419 }
42420@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42421 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42422 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42423 (int)part_stat_read(&disk->part0, sectors[1]) -
42424- atomic_read(&disk->sync_io);
42425+ atomic_read_unchecked(&disk->sync_io);
42426 /* sync IO will cause sync_io to increase before the disk_stats
42427 * as sync_io is counted when a request starts, and
42428 * disk_stats is counted when it completes.
42429diff --git a/drivers/md/md.h b/drivers/md/md.h
42430index 20f02c0..fd8c821 100644
42431--- a/drivers/md/md.h
42432+++ b/drivers/md/md.h
42433@@ -94,13 +94,13 @@ struct md_rdev {
42434 * only maintained for arrays that
42435 * support hot removal
42436 */
42437- atomic_t read_errors; /* number of consecutive read errors that
42438+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42439 * we have tried to ignore.
42440 */
42441 struct timespec last_read_error; /* monotonic time since our
42442 * last read error
42443 */
42444- atomic_t corrected_errors; /* number of corrected read errors,
42445+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42446 * for reporting to userspace and storing
42447 * in superblock.
42448 */
42449@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42450
42451 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42452 {
42453- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42454+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42455 }
42456
42457 struct md_personality
42458diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42459index 3e6d115..ffecdeb 100644
42460--- a/drivers/md/persistent-data/dm-space-map.h
42461+++ b/drivers/md/persistent-data/dm-space-map.h
42462@@ -71,6 +71,7 @@ struct dm_space_map {
42463 dm_sm_threshold_fn fn,
42464 void *context);
42465 };
42466+typedef struct dm_space_map __no_const dm_space_map_no_const;
42467
42468 /*----------------------------------------------------------------*/
42469
42470diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42471index d60412c..8d4c982 100644
42472--- a/drivers/md/raid1.c
42473+++ b/drivers/md/raid1.c
42474@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42475 if (r1_sync_page_io(rdev, sect, s,
42476 bio->bi_io_vec[idx].bv_page,
42477 READ) != 0)
42478- atomic_add(s, &rdev->corrected_errors);
42479+ atomic_add_unchecked(s, &rdev->corrected_errors);
42480 }
42481 sectors -= s;
42482 sect += s;
42483@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42484 test_bit(In_sync, &rdev->flags)) {
42485 if (r1_sync_page_io(rdev, sect, s,
42486 conf->tmppage, READ)) {
42487- atomic_add(s, &rdev->corrected_errors);
42488+ atomic_add_unchecked(s, &rdev->corrected_errors);
42489 printk(KERN_INFO
42490 "md/raid1:%s: read error corrected "
42491 "(%d sectors at %llu on %s)\n",
42492diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42493index df7b0a0..a257495 100644
42494--- a/drivers/md/raid10.c
42495+++ b/drivers/md/raid10.c
42496@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42497 /* The write handler will notice the lack of
42498 * R10BIO_Uptodate and record any errors etc
42499 */
42500- atomic_add(r10_bio->sectors,
42501+ atomic_add_unchecked(r10_bio->sectors,
42502 &conf->mirrors[d].rdev->corrected_errors);
42503
42504 /* for reconstruct, we always reschedule after a read.
42505@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42506 {
42507 struct timespec cur_time_mon;
42508 unsigned long hours_since_last;
42509- unsigned int read_errors = atomic_read(&rdev->read_errors);
42510+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42511
42512 ktime_get_ts(&cur_time_mon);
42513
42514@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42515 * overflowing the shift of read_errors by hours_since_last.
42516 */
42517 if (hours_since_last >= 8 * sizeof(read_errors))
42518- atomic_set(&rdev->read_errors, 0);
42519+ atomic_set_unchecked(&rdev->read_errors, 0);
42520 else
42521- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42522+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42523 }
42524
42525 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42526@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42527 return;
42528
42529 check_decay_read_errors(mddev, rdev);
42530- atomic_inc(&rdev->read_errors);
42531- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42532+ atomic_inc_unchecked(&rdev->read_errors);
42533+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42534 char b[BDEVNAME_SIZE];
42535 bdevname(rdev->bdev, b);
42536
42537@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42538 "md/raid10:%s: %s: Raid device exceeded "
42539 "read_error threshold [cur %d:max %d]\n",
42540 mdname(mddev), b,
42541- atomic_read(&rdev->read_errors), max_read_errors);
42542+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42543 printk(KERN_NOTICE
42544 "md/raid10:%s: %s: Failing raid device\n",
42545 mdname(mddev), b);
42546@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42547 sect +
42548 choose_data_offset(r10_bio, rdev)),
42549 bdevname(rdev->bdev, b));
42550- atomic_add(s, &rdev->corrected_errors);
42551+ atomic_add_unchecked(s, &rdev->corrected_errors);
42552 }
42553
42554 rdev_dec_pending(rdev, mddev);
42555diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42556index 78ea443..7d57513 100644
42557--- a/drivers/md/raid5.c
42558+++ b/drivers/md/raid5.c
42559@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42560 mdname(conf->mddev), STRIPE_SECTORS,
42561 (unsigned long long)s,
42562 bdevname(rdev->bdev, b));
42563- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42564+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42565 clear_bit(R5_ReadError, &sh->dev[i].flags);
42566 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42567 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42568 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42569
42570- if (atomic_read(&rdev->read_errors))
42571- atomic_set(&rdev->read_errors, 0);
42572+ if (atomic_read_unchecked(&rdev->read_errors))
42573+ atomic_set_unchecked(&rdev->read_errors, 0);
42574 } else {
42575 const char *bdn = bdevname(rdev->bdev, b);
42576 int retry = 0;
42577 int set_bad = 0;
42578
42579 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42580- atomic_inc(&rdev->read_errors);
42581+ atomic_inc_unchecked(&rdev->read_errors);
42582 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42583 printk_ratelimited(
42584 KERN_WARNING
42585@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42586 mdname(conf->mddev),
42587 (unsigned long long)s,
42588 bdn);
42589- } else if (atomic_read(&rdev->read_errors)
42590+ } else if (atomic_read_unchecked(&rdev->read_errors)
42591 > conf->max_nr_stripes)
42592 printk(KERN_WARNING
42593 "md/raid:%s: Too many read errors, failing device %s.\n",
42594diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42595index 401ef64..836e563 100644
42596--- a/drivers/media/dvb-core/dvbdev.c
42597+++ b/drivers/media/dvb-core/dvbdev.c
42598@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42599 const struct dvb_device *template, void *priv, int type)
42600 {
42601 struct dvb_device *dvbdev;
42602- struct file_operations *dvbdevfops;
42603+ file_operations_no_const *dvbdevfops;
42604 struct device *clsdev;
42605 int minor;
42606 int id;
42607diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42608index 9b6c3bb..baeb5c7 100644
42609--- a/drivers/media/dvb-frontends/dib3000.h
42610+++ b/drivers/media/dvb-frontends/dib3000.h
42611@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42612 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42613 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42614 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42615-};
42616+} __no_const;
42617
42618 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42619 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42620diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42621index ecf21d9..b992428d 100644
42622--- a/drivers/media/pci/cx88/cx88-video.c
42623+++ b/drivers/media/pci/cx88/cx88-video.c
42624@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42625
42626 /* ------------------------------------------------------------------ */
42627
42628-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42629-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42630-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42631+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42632+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42633+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42634
42635 module_param_array(video_nr, int, NULL, 0444);
42636 module_param_array(vbi_nr, int, NULL, 0444);
42637diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42638index c08ae3e..eb59af1 100644
42639--- a/drivers/media/pci/ivtv/ivtv-driver.c
42640+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42641@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42642 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42643
42644 /* ivtv instance counter */
42645-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42646+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42647
42648 /* Parameter declarations */
42649 static int cardtype[IVTV_MAX_CARDS];
42650diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42651index dfd0a21..6bbb465 100644
42652--- a/drivers/media/platform/omap/omap_vout.c
42653+++ b/drivers/media/platform/omap/omap_vout.c
42654@@ -63,7 +63,6 @@ enum omap_vout_channels {
42655 OMAP_VIDEO2,
42656 };
42657
42658-static struct videobuf_queue_ops video_vbq_ops;
42659 /* Variables configurable through module params*/
42660 static u32 video1_numbuffers = 3;
42661 static u32 video2_numbuffers = 3;
42662@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42663 {
42664 struct videobuf_queue *q;
42665 struct omap_vout_device *vout = NULL;
42666+ static struct videobuf_queue_ops video_vbq_ops = {
42667+ .buf_setup = omap_vout_buffer_setup,
42668+ .buf_prepare = omap_vout_buffer_prepare,
42669+ .buf_release = omap_vout_buffer_release,
42670+ .buf_queue = omap_vout_buffer_queue,
42671+ };
42672
42673 vout = video_drvdata(file);
42674 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42675@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42676 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42677
42678 q = &vout->vbq;
42679- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42680- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42681- video_vbq_ops.buf_release = omap_vout_buffer_release;
42682- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42683 spin_lock_init(&vout->vbq_lock);
42684
42685 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42686diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42687index 04e6490..2df65bf 100644
42688--- a/drivers/media/platform/s5p-tv/mixer.h
42689+++ b/drivers/media/platform/s5p-tv/mixer.h
42690@@ -156,7 +156,7 @@ struct mxr_layer {
42691 /** layer index (unique identifier) */
42692 int idx;
42693 /** callbacks for layer methods */
42694- struct mxr_layer_ops ops;
42695+ struct mxr_layer_ops *ops;
42696 /** format array */
42697 const struct mxr_format **fmt_array;
42698 /** size of format array */
42699diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42700index b93a21f..2535195 100644
42701--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42702+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42703@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42704 {
42705 struct mxr_layer *layer;
42706 int ret;
42707- struct mxr_layer_ops ops = {
42708+ static struct mxr_layer_ops ops = {
42709 .release = mxr_graph_layer_release,
42710 .buffer_set = mxr_graph_buffer_set,
42711 .stream_set = mxr_graph_stream_set,
42712diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42713index b713403..53cb5ad 100644
42714--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42715+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42716@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42717 layer->update_buf = next;
42718 }
42719
42720- layer->ops.buffer_set(layer, layer->update_buf);
42721+ layer->ops->buffer_set(layer, layer->update_buf);
42722
42723 if (done && done != layer->shadow_buf)
42724 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42725diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42726index 641b1f0..49cff30 100644
42727--- a/drivers/media/platform/s5p-tv/mixer_video.c
42728+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42729@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42730 layer->geo.src.height = layer->geo.src.full_height;
42731
42732 mxr_geometry_dump(mdev, &layer->geo);
42733- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42734+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42735 mxr_geometry_dump(mdev, &layer->geo);
42736 }
42737
42738@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42739 layer->geo.dst.full_width = mbus_fmt.width;
42740 layer->geo.dst.full_height = mbus_fmt.height;
42741 layer->geo.dst.field = mbus_fmt.field;
42742- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42743+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42744
42745 mxr_geometry_dump(mdev, &layer->geo);
42746 }
42747@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42748 /* set source size to highest accepted value */
42749 geo->src.full_width = max(geo->dst.full_width, pix->width);
42750 geo->src.full_height = max(geo->dst.full_height, pix->height);
42751- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42752+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42753 mxr_geometry_dump(mdev, &layer->geo);
42754 /* set cropping to total visible screen */
42755 geo->src.width = pix->width;
42756@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42757 geo->src.x_offset = 0;
42758 geo->src.y_offset = 0;
42759 /* assure consistency of geometry */
42760- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42761+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42762 mxr_geometry_dump(mdev, &layer->geo);
42763 /* set full size to lowest possible value */
42764 geo->src.full_width = 0;
42765 geo->src.full_height = 0;
42766- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42767+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42768 mxr_geometry_dump(mdev, &layer->geo);
42769
42770 /* returning results */
42771@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42772 target->width = s->r.width;
42773 target->height = s->r.height;
42774
42775- layer->ops.fix_geometry(layer, stage, s->flags);
42776+ layer->ops->fix_geometry(layer, stage, s->flags);
42777
42778 /* retrieve update selection rectangle */
42779 res.left = target->x_offset;
42780@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42781 mxr_output_get(mdev);
42782
42783 mxr_layer_update_output(layer);
42784- layer->ops.format_set(layer);
42785+ layer->ops->format_set(layer);
42786 /* enabling layer in hardware */
42787 spin_lock_irqsave(&layer->enq_slock, flags);
42788 layer->state = MXR_LAYER_STREAMING;
42789 spin_unlock_irqrestore(&layer->enq_slock, flags);
42790
42791- layer->ops.stream_set(layer, MXR_ENABLE);
42792+ layer->ops->stream_set(layer, MXR_ENABLE);
42793 mxr_streamer_get(mdev);
42794
42795 return 0;
42796@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42797 spin_unlock_irqrestore(&layer->enq_slock, flags);
42798
42799 /* disabling layer in hardware */
42800- layer->ops.stream_set(layer, MXR_DISABLE);
42801+ layer->ops->stream_set(layer, MXR_DISABLE);
42802 /* remove one streamer */
42803 mxr_streamer_put(mdev);
42804 /* allow changes in output configuration */
42805@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42806
42807 void mxr_layer_release(struct mxr_layer *layer)
42808 {
42809- if (layer->ops.release)
42810- layer->ops.release(layer);
42811+ if (layer->ops->release)
42812+ layer->ops->release(layer);
42813 }
42814
42815 void mxr_base_layer_release(struct mxr_layer *layer)
42816@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42817
42818 layer->mdev = mdev;
42819 layer->idx = idx;
42820- layer->ops = *ops;
42821+ layer->ops = ops;
42822
42823 spin_lock_init(&layer->enq_slock);
42824 INIT_LIST_HEAD(&layer->enq_list);
42825diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42826index 3d13a63..da31bf1 100644
42827--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42828+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42829@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42830 {
42831 struct mxr_layer *layer;
42832 int ret;
42833- struct mxr_layer_ops ops = {
42834+ static struct mxr_layer_ops ops = {
42835 .release = mxr_vp_layer_release,
42836 .buffer_set = mxr_vp_buffer_set,
42837 .stream_set = mxr_vp_stream_set,
42838diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42839index 545c04c..a14bded 100644
42840--- a/drivers/media/radio/radio-cadet.c
42841+++ b/drivers/media/radio/radio-cadet.c
42842@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42843 unsigned char readbuf[RDS_BUFFER];
42844 int i = 0;
42845
42846+ if (count > RDS_BUFFER)
42847+ return -EFAULT;
42848 mutex_lock(&dev->lock);
42849 if (dev->rdsstat == 0)
42850 cadet_start_rds(dev);
42851@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42852 while (i < count && dev->rdsin != dev->rdsout)
42853 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42854
42855- if (i && copy_to_user(data, readbuf, i))
42856+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42857 i = -EFAULT;
42858 unlock:
42859 mutex_unlock(&dev->lock);
42860diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42861index bd4d3a7..ffc0b9d 100644
42862--- a/drivers/media/radio/radio-maxiradio.c
42863+++ b/drivers/media/radio/radio-maxiradio.c
42864@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42865 /* TEA5757 pin mappings */
42866 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42867
42868-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42869+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42870
42871 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42872 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42873diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42874index 8fa18ab..caee70f 100644
42875--- a/drivers/media/radio/radio-shark.c
42876+++ b/drivers/media/radio/radio-shark.c
42877@@ -79,7 +79,7 @@ struct shark_device {
42878 u32 last_val;
42879 };
42880
42881-static atomic_t shark_instance = ATOMIC_INIT(0);
42882+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42883
42884 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42885 {
42886diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42887index 9fb6697..f167415 100644
42888--- a/drivers/media/radio/radio-shark2.c
42889+++ b/drivers/media/radio/radio-shark2.c
42890@@ -74,7 +74,7 @@ struct shark_device {
42891 u8 *transfer_buffer;
42892 };
42893
42894-static atomic_t shark_instance = ATOMIC_INIT(0);
42895+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42896
42897 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42898 {
42899diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42900index 9c9084c..a9e8dfb 100644
42901--- a/drivers/media/radio/radio-si476x.c
42902+++ b/drivers/media/radio/radio-si476x.c
42903@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42904 struct si476x_radio *radio;
42905 struct v4l2_ctrl *ctrl;
42906
42907- static atomic_t instance = ATOMIC_INIT(0);
42908+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42909
42910 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42911 if (!radio)
42912diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42913index 1cf382a..c22998c 100644
42914--- a/drivers/media/rc/rc-main.c
42915+++ b/drivers/media/rc/rc-main.c
42916@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42917 int rc_register_device(struct rc_dev *dev)
42918 {
42919 static bool raw_init = false; /* raw decoders loaded? */
42920- static atomic_t devno = ATOMIC_INIT(0);
42921+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42922 struct rc_map *rc_map;
42923 const char *path;
42924 int rc;
42925@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
42926 */
42927 mutex_lock(&dev->lock);
42928
42929- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42930+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42931 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42932 dev_set_drvdata(&dev->dev, dev);
42933 rc = device_add(&dev->dev);
42934diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42935index 3940bb0..fb3952a 100644
42936--- a/drivers/media/usb/dvb-usb/cxusb.c
42937+++ b/drivers/media/usb/dvb-usb/cxusb.c
42938@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42939
42940 struct dib0700_adapter_state {
42941 int (*set_param_save) (struct dvb_frontend *);
42942-};
42943+} __no_const;
42944
42945 static int dib7070_set_param_override(struct dvb_frontend *fe)
42946 {
42947diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42948index 6e237b6..dc25556 100644
42949--- a/drivers/media/usb/dvb-usb/dw2102.c
42950+++ b/drivers/media/usb/dvb-usb/dw2102.c
42951@@ -118,7 +118,7 @@ struct su3000_state {
42952
42953 struct s6x0_state {
42954 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42955-};
42956+} __no_const;
42957
42958 /* debug */
42959 static int dvb_usb_dw2102_debug;
42960diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42961index 8f7a6a4..59502dd 100644
42962--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42963+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42964@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
42965 __u32 reserved;
42966 };
42967
42968-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42969+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42970 enum v4l2_memory memory)
42971 {
42972 void __user *up_pln;
42973@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42974 return 0;
42975 }
42976
42977-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42978+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42979 enum v4l2_memory memory)
42980 {
42981 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
42982@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
42983 put_user(kp->start_block, &up->start_block) ||
42984 put_user(kp->blocks, &up->blocks) ||
42985 put_user(tmp, &up->edid) ||
42986- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
42987+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
42988 return -EFAULT;
42989 return 0;
42990 }
42991diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
42992index 02d1b63..5fd6b16 100644
42993--- a/drivers/media/v4l2-core/v4l2-device.c
42994+++ b/drivers/media/v4l2-core/v4l2-device.c
42995@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
42996 EXPORT_SYMBOL_GPL(v4l2_device_put);
42997
42998 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
42999- atomic_t *instance)
43000+ atomic_unchecked_t *instance)
43001 {
43002- int num = atomic_inc_return(instance) - 1;
43003+ int num = atomic_inc_return_unchecked(instance) - 1;
43004 int len = strlen(basename);
43005
43006 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43007diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43008index 68e6b5e..d8b923e 100644
43009--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43010+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43011@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43012 struct file *file, void *fh, void *p);
43013 } u;
43014 void (*debug)(const void *arg, bool write_only);
43015-};
43016+} __do_const;
43017+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43018
43019 /* This control needs a priority check */
43020 #define INFO_FL_PRIO (1 << 0)
43021@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43022 struct video_device *vfd = video_devdata(file);
43023 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43024 bool write_only = false;
43025- struct v4l2_ioctl_info default_info;
43026+ v4l2_ioctl_info_no_const default_info;
43027 const struct v4l2_ioctl_info *info;
43028 void *fh = file->private_data;
43029 struct v4l2_fh *vfh = NULL;
43030@@ -2194,7 +2195,7 @@ done:
43031 }
43032
43033 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43034- void * __user *user_ptr, void ***kernel_ptr)
43035+ void __user **user_ptr, void ***kernel_ptr)
43036 {
43037 int ret = 0;
43038
43039@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43040 ret = -EINVAL;
43041 break;
43042 }
43043- *user_ptr = (void __user *)buf->m.planes;
43044+ *user_ptr = (void __force_user *)buf->m.planes;
43045 *kernel_ptr = (void *)&buf->m.planes;
43046 *array_size = sizeof(struct v4l2_plane) * buf->length;
43047 ret = 1;
43048@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43049 ret = -EINVAL;
43050 break;
43051 }
43052- *user_ptr = (void __user *)ctrls->controls;
43053+ *user_ptr = (void __force_user *)ctrls->controls;
43054 *kernel_ptr = (void *)&ctrls->controls;
43055 *array_size = sizeof(struct v4l2_ext_control)
43056 * ctrls->count;
43057diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43058index 767ff4d..c69d259 100644
43059--- a/drivers/message/fusion/mptbase.c
43060+++ b/drivers/message/fusion/mptbase.c
43061@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43062 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43063 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43064
43065+#ifdef CONFIG_GRKERNSEC_HIDESYM
43066+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43067+#else
43068 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43069 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43070+#endif
43071+
43072 /*
43073 * Rounding UP to nearest 4-kB boundary here...
43074 */
43075@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43076 ioc->facts.GlobalCredits);
43077
43078 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43079+#ifdef CONFIG_GRKERNSEC_HIDESYM
43080+ NULL, NULL);
43081+#else
43082 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43083+#endif
43084 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43085 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43086 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43087diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43088index dd239bd..689c4f7 100644
43089--- a/drivers/message/fusion/mptsas.c
43090+++ b/drivers/message/fusion/mptsas.c
43091@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43092 return 0;
43093 }
43094
43095+static inline void
43096+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43097+{
43098+ if (phy_info->port_details) {
43099+ phy_info->port_details->rphy = rphy;
43100+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43101+ ioc->name, rphy));
43102+ }
43103+
43104+ if (rphy) {
43105+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43106+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43107+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43108+ ioc->name, rphy, rphy->dev.release));
43109+ }
43110+}
43111+
43112 /* no mutex */
43113 static void
43114 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43115@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43116 return NULL;
43117 }
43118
43119-static inline void
43120-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43121-{
43122- if (phy_info->port_details) {
43123- phy_info->port_details->rphy = rphy;
43124- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43125- ioc->name, rphy));
43126- }
43127-
43128- if (rphy) {
43129- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43130- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43131- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43132- ioc->name, rphy, rphy->dev.release));
43133- }
43134-}
43135-
43136 static inline struct sas_port *
43137 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43138 {
43139diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43140index 727819c..ad74694 100644
43141--- a/drivers/message/fusion/mptscsih.c
43142+++ b/drivers/message/fusion/mptscsih.c
43143@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43144
43145 h = shost_priv(SChost);
43146
43147- if (h) {
43148- if (h->info_kbuf == NULL)
43149- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43150- return h->info_kbuf;
43151- h->info_kbuf[0] = '\0';
43152+ if (!h)
43153+ return NULL;
43154
43155- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43156- h->info_kbuf[size-1] = '\0';
43157- }
43158+ if (h->info_kbuf == NULL)
43159+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43160+ return h->info_kbuf;
43161+ h->info_kbuf[0] = '\0';
43162+
43163+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43164+ h->info_kbuf[size-1] = '\0';
43165
43166 return h->info_kbuf;
43167 }
43168diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43169index b7d87cd..9890039 100644
43170--- a/drivers/message/i2o/i2o_proc.c
43171+++ b/drivers/message/i2o/i2o_proc.c
43172@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43173 "Array Controller Device"
43174 };
43175
43176-static char *chtostr(char *tmp, u8 *chars, int n)
43177-{
43178- tmp[0] = 0;
43179- return strncat(tmp, (char *)chars, n);
43180-}
43181-
43182 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43183 char *group)
43184 {
43185@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43186 } *result;
43187
43188 i2o_exec_execute_ddm_table ddm_table;
43189- char tmp[28 + 1];
43190
43191 result = kmalloc(sizeof(*result), GFP_KERNEL);
43192 if (!result)
43193@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43194
43195 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43196 seq_printf(seq, "%-#8x", ddm_table.module_id);
43197- seq_printf(seq, "%-29s",
43198- chtostr(tmp, ddm_table.module_name_version, 28));
43199+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43200 seq_printf(seq, "%9d ", ddm_table.data_size);
43201 seq_printf(seq, "%8d", ddm_table.code_size);
43202
43203@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43204
43205 i2o_driver_result_table *result;
43206 i2o_driver_store_table *dst;
43207- char tmp[28 + 1];
43208
43209 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43210 if (result == NULL)
43211@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43212
43213 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43214 seq_printf(seq, "%-#8x", dst->module_id);
43215- seq_printf(seq, "%-29s",
43216- chtostr(tmp, dst->module_name_version, 28));
43217- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43218+ seq_printf(seq, "%-.28s", dst->module_name_version);
43219+ seq_printf(seq, "%-.8s", dst->date);
43220 seq_printf(seq, "%8d ", dst->module_size);
43221 seq_printf(seq, "%8d ", dst->mpb_size);
43222 seq_printf(seq, "0x%04x", dst->module_flags);
43223@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43224 // == (allow) 512d bytes (max)
43225 static u16 *work16 = (u16 *) work32;
43226 int token;
43227- char tmp[16 + 1];
43228
43229 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43230
43231@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43232 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43233 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43234 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43235- seq_printf(seq, "Vendor info : %s\n",
43236- chtostr(tmp, (u8 *) (work32 + 2), 16));
43237- seq_printf(seq, "Product info : %s\n",
43238- chtostr(tmp, (u8 *) (work32 + 6), 16));
43239- seq_printf(seq, "Description : %s\n",
43240- chtostr(tmp, (u8 *) (work32 + 10), 16));
43241- seq_printf(seq, "Product rev. : %s\n",
43242- chtostr(tmp, (u8 *) (work32 + 14), 8));
43243+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43244+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43245+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43246+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43247
43248 seq_printf(seq, "Serial number : ");
43249 print_serial_number(seq, (u8 *) (work32 + 16),
43250@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43251 u8 pad[256]; // allow up to 256 byte (max) serial number
43252 } result;
43253
43254- char tmp[24 + 1];
43255-
43256 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43257
43258 if (token < 0) {
43259@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43260 }
43261
43262 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43263- seq_printf(seq, "Module name : %s\n",
43264- chtostr(tmp, result.module_name, 24));
43265- seq_printf(seq, "Module revision : %s\n",
43266- chtostr(tmp, result.module_rev, 8));
43267+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43268+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43269
43270 seq_printf(seq, "Serial number : ");
43271 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43272@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43273 u8 instance_number[4];
43274 } result;
43275
43276- char tmp[64 + 1];
43277-
43278 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43279
43280 if (token < 0) {
43281@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43282 return 0;
43283 }
43284
43285- seq_printf(seq, "Device name : %s\n",
43286- chtostr(tmp, result.device_name, 64));
43287- seq_printf(seq, "Service name : %s\n",
43288- chtostr(tmp, result.service_name, 64));
43289- seq_printf(seq, "Physical name : %s\n",
43290- chtostr(tmp, result.physical_location, 64));
43291- seq_printf(seq, "Instance number : %s\n",
43292- chtostr(tmp, result.instance_number, 4));
43293+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43294+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43295+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43296+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43297
43298 return 0;
43299 }
43300diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43301index a8c08f3..155fe3d 100644
43302--- a/drivers/message/i2o/iop.c
43303+++ b/drivers/message/i2o/iop.c
43304@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43305
43306 spin_lock_irqsave(&c->context_list_lock, flags);
43307
43308- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43309- atomic_inc(&c->context_list_counter);
43310+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43311+ atomic_inc_unchecked(&c->context_list_counter);
43312
43313- entry->context = atomic_read(&c->context_list_counter);
43314+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43315
43316 list_add(&entry->list, &c->context_list);
43317
43318@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43319
43320 #if BITS_PER_LONG == 64
43321 spin_lock_init(&c->context_list_lock);
43322- atomic_set(&c->context_list_counter, 0);
43323+ atomic_set_unchecked(&c->context_list_counter, 0);
43324 INIT_LIST_HEAD(&c->context_list);
43325 #endif
43326
43327diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43328index fcbb2e9..2635e11 100644
43329--- a/drivers/mfd/janz-cmodio.c
43330+++ b/drivers/mfd/janz-cmodio.c
43331@@ -13,6 +13,7 @@
43332
43333 #include <linux/kernel.h>
43334 #include <linux/module.h>
43335+#include <linux/slab.h>
43336 #include <linux/init.h>
43337 #include <linux/pci.h>
43338 #include <linux/interrupt.h>
43339diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43340index 9aa6d1e..1631bfc 100644
43341--- a/drivers/mfd/twl4030-irq.c
43342+++ b/drivers/mfd/twl4030-irq.c
43343@@ -35,6 +35,7 @@
43344 #include <linux/of.h>
43345 #include <linux/irqdomain.h>
43346 #include <linux/i2c/twl.h>
43347+#include <asm/pgtable.h>
43348
43349 #include "twl-core.h"
43350
43351@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43352 * Install an irq handler for each of the SIH modules;
43353 * clone dummy irq_chip since PIH can't *do* anything
43354 */
43355- twl4030_irq_chip = dummy_irq_chip;
43356- twl4030_irq_chip.name = "twl4030";
43357+ pax_open_kernel();
43358+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43359+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43360
43361- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43362+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43363+ pax_close_kernel();
43364
43365 for (i = irq_base; i < irq_end; i++) {
43366 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43367diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43368index 277a8db..0e0b754 100644
43369--- a/drivers/mfd/twl6030-irq.c
43370+++ b/drivers/mfd/twl6030-irq.c
43371@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43372 * install an irq handler for each of the modules;
43373 * clone dummy irq_chip since PIH can't *do* anything
43374 */
43375- twl6030_irq_chip = dummy_irq_chip;
43376- twl6030_irq_chip.name = "twl6030";
43377- twl6030_irq_chip.irq_set_type = NULL;
43378- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43379+ pax_open_kernel();
43380+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43381+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43382+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43383+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43384+ pax_close_kernel();
43385
43386 for (i = irq_base; i < irq_end; i++) {
43387 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43388diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43389index f32550a..e3e52a2 100644
43390--- a/drivers/misc/c2port/core.c
43391+++ b/drivers/misc/c2port/core.c
43392@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43393 mutex_init(&c2dev->mutex);
43394
43395 /* Create binary file */
43396- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43397+ pax_open_kernel();
43398+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43399+ pax_close_kernel();
43400 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43401 if (unlikely(ret))
43402 goto error_device_create_bin_file;
43403diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43404index 36f5d52..32311c3 100644
43405--- a/drivers/misc/kgdbts.c
43406+++ b/drivers/misc/kgdbts.c
43407@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43408 char before[BREAK_INSTR_SIZE];
43409 char after[BREAK_INSTR_SIZE];
43410
43411- probe_kernel_read(before, (char *)kgdbts_break_test,
43412+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43413 BREAK_INSTR_SIZE);
43414 init_simple_test();
43415 ts.tst = plant_and_detach_test;
43416@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43417 /* Activate test with initial breakpoint */
43418 if (!is_early)
43419 kgdb_breakpoint();
43420- probe_kernel_read(after, (char *)kgdbts_break_test,
43421+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43422 BREAK_INSTR_SIZE);
43423 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43424 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43425diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43426index 036effe..b3a6336 100644
43427--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43428+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43429@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43430 * the lid is closed. This leads to interrupts as soon as a little move
43431 * is done.
43432 */
43433- atomic_inc(&lis3->count);
43434+ atomic_inc_unchecked(&lis3->count);
43435
43436 wake_up_interruptible(&lis3->misc_wait);
43437 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43438@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43439 if (lis3->pm_dev)
43440 pm_runtime_get_sync(lis3->pm_dev);
43441
43442- atomic_set(&lis3->count, 0);
43443+ atomic_set_unchecked(&lis3->count, 0);
43444 return 0;
43445 }
43446
43447@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43448 add_wait_queue(&lis3->misc_wait, &wait);
43449 while (true) {
43450 set_current_state(TASK_INTERRUPTIBLE);
43451- data = atomic_xchg(&lis3->count, 0);
43452+ data = atomic_xchg_unchecked(&lis3->count, 0);
43453 if (data)
43454 break;
43455
43456@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43457 struct lis3lv02d, miscdev);
43458
43459 poll_wait(file, &lis3->misc_wait, wait);
43460- if (atomic_read(&lis3->count))
43461+ if (atomic_read_unchecked(&lis3->count))
43462 return POLLIN | POLLRDNORM;
43463 return 0;
43464 }
43465diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43466index c439c82..1f20f57 100644
43467--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43468+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43469@@ -297,7 +297,7 @@ struct lis3lv02d {
43470 struct input_polled_dev *idev; /* input device */
43471 struct platform_device *pdev; /* platform device */
43472 struct regulator_bulk_data regulators[2];
43473- atomic_t count; /* interrupt count after last read */
43474+ atomic_unchecked_t count; /* interrupt count after last read */
43475 union axis_conversion ac; /* hw -> logical axis */
43476 int mapped_btns[3];
43477
43478diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43479index 2f30bad..c4c13d0 100644
43480--- a/drivers/misc/sgi-gru/gruhandles.c
43481+++ b/drivers/misc/sgi-gru/gruhandles.c
43482@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43483 unsigned long nsec;
43484
43485 nsec = CLKS2NSEC(clks);
43486- atomic_long_inc(&mcs_op_statistics[op].count);
43487- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43488+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43489+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43490 if (mcs_op_statistics[op].max < nsec)
43491 mcs_op_statistics[op].max = nsec;
43492 }
43493diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43494index 4f76359..cdfcb2e 100644
43495--- a/drivers/misc/sgi-gru/gruprocfs.c
43496+++ b/drivers/misc/sgi-gru/gruprocfs.c
43497@@ -32,9 +32,9 @@
43498
43499 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43500
43501-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43502+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43503 {
43504- unsigned long val = atomic_long_read(v);
43505+ unsigned long val = atomic_long_read_unchecked(v);
43506
43507 seq_printf(s, "%16lu %s\n", val, id);
43508 }
43509@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43510
43511 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43512 for (op = 0; op < mcsop_last; op++) {
43513- count = atomic_long_read(&mcs_op_statistics[op].count);
43514- total = atomic_long_read(&mcs_op_statistics[op].total);
43515+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43516+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43517 max = mcs_op_statistics[op].max;
43518 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43519 count ? total / count : 0, max);
43520diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43521index 5c3ce24..4915ccb 100644
43522--- a/drivers/misc/sgi-gru/grutables.h
43523+++ b/drivers/misc/sgi-gru/grutables.h
43524@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43525 * GRU statistics.
43526 */
43527 struct gru_stats_s {
43528- atomic_long_t vdata_alloc;
43529- atomic_long_t vdata_free;
43530- atomic_long_t gts_alloc;
43531- atomic_long_t gts_free;
43532- atomic_long_t gms_alloc;
43533- atomic_long_t gms_free;
43534- atomic_long_t gts_double_allocate;
43535- atomic_long_t assign_context;
43536- atomic_long_t assign_context_failed;
43537- atomic_long_t free_context;
43538- atomic_long_t load_user_context;
43539- atomic_long_t load_kernel_context;
43540- atomic_long_t lock_kernel_context;
43541- atomic_long_t unlock_kernel_context;
43542- atomic_long_t steal_user_context;
43543- atomic_long_t steal_kernel_context;
43544- atomic_long_t steal_context_failed;
43545- atomic_long_t nopfn;
43546- atomic_long_t asid_new;
43547- atomic_long_t asid_next;
43548- atomic_long_t asid_wrap;
43549- atomic_long_t asid_reuse;
43550- atomic_long_t intr;
43551- atomic_long_t intr_cbr;
43552- atomic_long_t intr_tfh;
43553- atomic_long_t intr_spurious;
43554- atomic_long_t intr_mm_lock_failed;
43555- atomic_long_t call_os;
43556- atomic_long_t call_os_wait_queue;
43557- atomic_long_t user_flush_tlb;
43558- atomic_long_t user_unload_context;
43559- atomic_long_t user_exception;
43560- atomic_long_t set_context_option;
43561- atomic_long_t check_context_retarget_intr;
43562- atomic_long_t check_context_unload;
43563- atomic_long_t tlb_dropin;
43564- atomic_long_t tlb_preload_page;
43565- atomic_long_t tlb_dropin_fail_no_asid;
43566- atomic_long_t tlb_dropin_fail_upm;
43567- atomic_long_t tlb_dropin_fail_invalid;
43568- atomic_long_t tlb_dropin_fail_range_active;
43569- atomic_long_t tlb_dropin_fail_idle;
43570- atomic_long_t tlb_dropin_fail_fmm;
43571- atomic_long_t tlb_dropin_fail_no_exception;
43572- atomic_long_t tfh_stale_on_fault;
43573- atomic_long_t mmu_invalidate_range;
43574- atomic_long_t mmu_invalidate_page;
43575- atomic_long_t flush_tlb;
43576- atomic_long_t flush_tlb_gru;
43577- atomic_long_t flush_tlb_gru_tgh;
43578- atomic_long_t flush_tlb_gru_zero_asid;
43579+ atomic_long_unchecked_t vdata_alloc;
43580+ atomic_long_unchecked_t vdata_free;
43581+ atomic_long_unchecked_t gts_alloc;
43582+ atomic_long_unchecked_t gts_free;
43583+ atomic_long_unchecked_t gms_alloc;
43584+ atomic_long_unchecked_t gms_free;
43585+ atomic_long_unchecked_t gts_double_allocate;
43586+ atomic_long_unchecked_t assign_context;
43587+ atomic_long_unchecked_t assign_context_failed;
43588+ atomic_long_unchecked_t free_context;
43589+ atomic_long_unchecked_t load_user_context;
43590+ atomic_long_unchecked_t load_kernel_context;
43591+ atomic_long_unchecked_t lock_kernel_context;
43592+ atomic_long_unchecked_t unlock_kernel_context;
43593+ atomic_long_unchecked_t steal_user_context;
43594+ atomic_long_unchecked_t steal_kernel_context;
43595+ atomic_long_unchecked_t steal_context_failed;
43596+ atomic_long_unchecked_t nopfn;
43597+ atomic_long_unchecked_t asid_new;
43598+ atomic_long_unchecked_t asid_next;
43599+ atomic_long_unchecked_t asid_wrap;
43600+ atomic_long_unchecked_t asid_reuse;
43601+ atomic_long_unchecked_t intr;
43602+ atomic_long_unchecked_t intr_cbr;
43603+ atomic_long_unchecked_t intr_tfh;
43604+ atomic_long_unchecked_t intr_spurious;
43605+ atomic_long_unchecked_t intr_mm_lock_failed;
43606+ atomic_long_unchecked_t call_os;
43607+ atomic_long_unchecked_t call_os_wait_queue;
43608+ atomic_long_unchecked_t user_flush_tlb;
43609+ atomic_long_unchecked_t user_unload_context;
43610+ atomic_long_unchecked_t user_exception;
43611+ atomic_long_unchecked_t set_context_option;
43612+ atomic_long_unchecked_t check_context_retarget_intr;
43613+ atomic_long_unchecked_t check_context_unload;
43614+ atomic_long_unchecked_t tlb_dropin;
43615+ atomic_long_unchecked_t tlb_preload_page;
43616+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43617+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43618+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43619+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43620+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43621+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43622+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43623+ atomic_long_unchecked_t tfh_stale_on_fault;
43624+ atomic_long_unchecked_t mmu_invalidate_range;
43625+ atomic_long_unchecked_t mmu_invalidate_page;
43626+ atomic_long_unchecked_t flush_tlb;
43627+ atomic_long_unchecked_t flush_tlb_gru;
43628+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43629+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43630
43631- atomic_long_t copy_gpa;
43632- atomic_long_t read_gpa;
43633+ atomic_long_unchecked_t copy_gpa;
43634+ atomic_long_unchecked_t read_gpa;
43635
43636- atomic_long_t mesq_receive;
43637- atomic_long_t mesq_receive_none;
43638- atomic_long_t mesq_send;
43639- atomic_long_t mesq_send_failed;
43640- atomic_long_t mesq_noop;
43641- atomic_long_t mesq_send_unexpected_error;
43642- atomic_long_t mesq_send_lb_overflow;
43643- atomic_long_t mesq_send_qlimit_reached;
43644- atomic_long_t mesq_send_amo_nacked;
43645- atomic_long_t mesq_send_put_nacked;
43646- atomic_long_t mesq_page_overflow;
43647- atomic_long_t mesq_qf_locked;
43648- atomic_long_t mesq_qf_noop_not_full;
43649- atomic_long_t mesq_qf_switch_head_failed;
43650- atomic_long_t mesq_qf_unexpected_error;
43651- atomic_long_t mesq_noop_unexpected_error;
43652- atomic_long_t mesq_noop_lb_overflow;
43653- atomic_long_t mesq_noop_qlimit_reached;
43654- atomic_long_t mesq_noop_amo_nacked;
43655- atomic_long_t mesq_noop_put_nacked;
43656- atomic_long_t mesq_noop_page_overflow;
43657+ atomic_long_unchecked_t mesq_receive;
43658+ atomic_long_unchecked_t mesq_receive_none;
43659+ atomic_long_unchecked_t mesq_send;
43660+ atomic_long_unchecked_t mesq_send_failed;
43661+ atomic_long_unchecked_t mesq_noop;
43662+ atomic_long_unchecked_t mesq_send_unexpected_error;
43663+ atomic_long_unchecked_t mesq_send_lb_overflow;
43664+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43665+ atomic_long_unchecked_t mesq_send_amo_nacked;
43666+ atomic_long_unchecked_t mesq_send_put_nacked;
43667+ atomic_long_unchecked_t mesq_page_overflow;
43668+ atomic_long_unchecked_t mesq_qf_locked;
43669+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43670+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43671+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43672+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43673+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43674+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43675+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43676+ atomic_long_unchecked_t mesq_noop_put_nacked;
43677+ atomic_long_unchecked_t mesq_noop_page_overflow;
43678
43679 };
43680
43681@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43682 tghop_invalidate, mcsop_last};
43683
43684 struct mcs_op_statistic {
43685- atomic_long_t count;
43686- atomic_long_t total;
43687+ atomic_long_unchecked_t count;
43688+ atomic_long_unchecked_t total;
43689 unsigned long max;
43690 };
43691
43692@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43693
43694 #define STAT(id) do { \
43695 if (gru_options & OPT_STATS) \
43696- atomic_long_inc(&gru_stats.id); \
43697+ atomic_long_inc_unchecked(&gru_stats.id); \
43698 } while (0)
43699
43700 #ifdef CONFIG_SGI_GRU_DEBUG
43701diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43702index c862cd4..0d176fe 100644
43703--- a/drivers/misc/sgi-xp/xp.h
43704+++ b/drivers/misc/sgi-xp/xp.h
43705@@ -288,7 +288,7 @@ struct xpc_interface {
43706 xpc_notify_func, void *);
43707 void (*received) (short, int, void *);
43708 enum xp_retval (*partid_to_nasids) (short, void *);
43709-};
43710+} __no_const;
43711
43712 extern struct xpc_interface xpc_interface;
43713
43714diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43715index b94d5f7..7f494c5 100644
43716--- a/drivers/misc/sgi-xp/xpc.h
43717+++ b/drivers/misc/sgi-xp/xpc.h
43718@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43719 void (*received_payload) (struct xpc_channel *, void *);
43720 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43721 };
43722+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43723
43724 /* struct xpc_partition act_state values (for XPC HB) */
43725
43726@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43727 /* found in xpc_main.c */
43728 extern struct device *xpc_part;
43729 extern struct device *xpc_chan;
43730-extern struct xpc_arch_operations xpc_arch_ops;
43731+extern xpc_arch_operations_no_const xpc_arch_ops;
43732 extern int xpc_disengage_timelimit;
43733 extern int xpc_disengage_timedout;
43734 extern int xpc_activate_IRQ_rcvd;
43735diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43736index 82dc574..8539ab2 100644
43737--- a/drivers/misc/sgi-xp/xpc_main.c
43738+++ b/drivers/misc/sgi-xp/xpc_main.c
43739@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43740 .notifier_call = xpc_system_die,
43741 };
43742
43743-struct xpc_arch_operations xpc_arch_ops;
43744+xpc_arch_operations_no_const xpc_arch_ops;
43745
43746 /*
43747 * Timer function to enforce the timelimit on the partition disengage.
43748@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43749
43750 if (((die_args->trapnr == X86_TRAP_MF) ||
43751 (die_args->trapnr == X86_TRAP_XF)) &&
43752- !user_mode_vm(die_args->regs))
43753+ !user_mode(die_args->regs))
43754 xpc_die_deactivate();
43755
43756 break;
43757diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43758index 837fc73..acb5862 100644
43759--- a/drivers/mmc/core/mmc_ops.c
43760+++ b/drivers/mmc/core/mmc_ops.c
43761@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43762 void *data_buf;
43763 int is_on_stack;
43764
43765- is_on_stack = object_is_on_stack(buf);
43766+ is_on_stack = object_starts_on_stack(buf);
43767 if (is_on_stack) {
43768 /*
43769 * dma onto stack is unsafe/nonportable, but callers to this
43770diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43771index 81b2994..dce857e 100644
43772--- a/drivers/mmc/host/dw_mmc.h
43773+++ b/drivers/mmc/host/dw_mmc.h
43774@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43775 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43776 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43777 int (*parse_dt)(struct dw_mci *host);
43778-};
43779+} __do_const;
43780 #endif /* _DW_MMC_H_ */
43781diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43782index c3785ed..1984c44 100644
43783--- a/drivers/mmc/host/mmci.c
43784+++ b/drivers/mmc/host/mmci.c
43785@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43786 }
43787
43788 if (variant->busy_detect) {
43789- mmci_ops.card_busy = mmci_card_busy;
43790+ pax_open_kernel();
43791+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43792+ pax_close_kernel();
43793 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43794 }
43795
43796diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43797index 926aaf6..8e153e2 100644
43798--- a/drivers/mmc/host/sdhci-s3c.c
43799+++ b/drivers/mmc/host/sdhci-s3c.c
43800@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43801 * we can use overriding functions instead of default.
43802 */
43803 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43804- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43805- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43806- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43807+ pax_open_kernel();
43808+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43809+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43810+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43811+ pax_close_kernel();
43812 }
43813
43814 /* It supports additional host capabilities if needed */
43815diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43816index 0c8bb6b..6f35deb 100644
43817--- a/drivers/mtd/nand/denali.c
43818+++ b/drivers/mtd/nand/denali.c
43819@@ -24,6 +24,7 @@
43820 #include <linux/slab.h>
43821 #include <linux/mtd/mtd.h>
43822 #include <linux/module.h>
43823+#include <linux/slab.h>
43824
43825 #include "denali.h"
43826
43827diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43828index 51b9d6a..52af9a7 100644
43829--- a/drivers/mtd/nftlmount.c
43830+++ b/drivers/mtd/nftlmount.c
43831@@ -24,6 +24,7 @@
43832 #include <asm/errno.h>
43833 #include <linux/delay.h>
43834 #include <linux/slab.h>
43835+#include <linux/sched.h>
43836 #include <linux/mtd/mtd.h>
43837 #include <linux/mtd/nand.h>
43838 #include <linux/mtd/nftl.h>
43839diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43840index f9d5615..99dd95f 100644
43841--- a/drivers/mtd/sm_ftl.c
43842+++ b/drivers/mtd/sm_ftl.c
43843@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43844 #define SM_CIS_VENDOR_OFFSET 0x59
43845 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43846 {
43847- struct attribute_group *attr_group;
43848+ attribute_group_no_const *attr_group;
43849 struct attribute **attributes;
43850 struct sm_sysfs_attribute *vendor_attribute;
43851
43852diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43853index 5e31046..82f8ddc 100644
43854--- a/drivers/net/bonding/bond_main.c
43855+++ b/drivers/net/bonding/bond_main.c
43856@@ -4839,7 +4839,7 @@ static unsigned int bond_get_num_tx_queues(void)
43857 return tx_queues;
43858 }
43859
43860-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43861+static struct rtnl_link_ops bond_link_ops = {
43862 .kind = "bond",
43863 .priv_size = sizeof(struct bonding),
43864 .setup = bond_setup,
43865@@ -4964,8 +4964,8 @@ static void __exit bonding_exit(void)
43866
43867 bond_destroy_debugfs();
43868
43869- rtnl_link_unregister(&bond_link_ops);
43870 unregister_pernet_subsys(&bond_net_ops);
43871+ rtnl_link_unregister(&bond_link_ops);
43872
43873 #ifdef CONFIG_NET_POLL_CONTROLLER
43874 /*
43875diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43876index e1d2643..7f4133b 100644
43877--- a/drivers/net/ethernet/8390/ax88796.c
43878+++ b/drivers/net/ethernet/8390/ax88796.c
43879@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43880 if (ax->plat->reg_offsets)
43881 ei_local->reg_offset = ax->plat->reg_offsets;
43882 else {
43883+ resource_size_t _mem_size = mem_size;
43884+ do_div(_mem_size, 0x18);
43885 ei_local->reg_offset = ax->reg_offsets;
43886 for (ret = 0; ret < 0x18; ret++)
43887- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43888+ ax->reg_offsets[ret] = _mem_size * ret;
43889 }
43890
43891 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43892diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43893index c07a6d0..ca88c45 100644
43894--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43895+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43896@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43897 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43898 {
43899 /* RX_MODE controlling object */
43900- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43901+ bnx2x_init_rx_mode_obj(bp);
43902
43903 /* multicast configuration controlling object */
43904 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43905diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43906index 8f03c98..dd0ef10 100644
43907--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43908+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43909@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43910 return rc;
43911 }
43912
43913-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43914- struct bnx2x_rx_mode_obj *o)
43915+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43916 {
43917 if (CHIP_IS_E1x(bp)) {
43918- o->wait_comp = bnx2x_empty_rx_mode_wait;
43919- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43920+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43921+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43922 } else {
43923- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43924- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43925+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43926+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43927 }
43928 }
43929
43930diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43931index 798dfe9..05d0a44 100644
43932--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43933+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43934@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43935
43936 /********************* RX MODE ****************/
43937
43938-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43939- struct bnx2x_rx_mode_obj *o);
43940+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43941
43942 /**
43943 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43944diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43945index cd63d11..b67dd78 100644
43946--- a/drivers/net/ethernet/broadcom/tg3.h
43947+++ b/drivers/net/ethernet/broadcom/tg3.h
43948@@ -147,6 +147,7 @@
43949 #define CHIPREV_ID_5750_A0 0x4000
43950 #define CHIPREV_ID_5750_A1 0x4001
43951 #define CHIPREV_ID_5750_A3 0x4003
43952+#define CHIPREV_ID_5750_C1 0x4201
43953 #define CHIPREV_ID_5750_C2 0x4202
43954 #define CHIPREV_ID_5752_A0_HW 0x5000
43955 #define CHIPREV_ID_5752_A0 0x6000
43956diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43957index 8cffcdf..aadf043 100644
43958--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43959+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43960@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
43961 */
43962 struct l2t_skb_cb {
43963 arp_failure_handler_func arp_failure_handler;
43964-};
43965+} __no_const;
43966
43967 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
43968
43969diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43970index 9c89dc8..725ecc3 100644
43971--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
43972+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43973@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
43974 flits = skb_transport_offset(skb) / 8;
43975 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
43976 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
43977- skb->tail - skb->transport_header,
43978+ skb_tail_pointer(skb) - skb_transport_header(skb),
43979 adap->pdev);
43980 if (need_skb_unmap()) {
43981 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
43982diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
43983index 4c83003..2a2a5b9 100644
43984--- a/drivers/net/ethernet/dec/tulip/de4x5.c
43985+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
43986@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43987 for (i=0; i<ETH_ALEN; i++) {
43988 tmp.addr[i] = dev->dev_addr[i];
43989 }
43990- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43991+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43992 break;
43993
43994 case DE4X5_SET_HWADDR: /* Set the hardware address */
43995@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43996 spin_lock_irqsave(&lp->lock, flags);
43997 memcpy(&statbuf, &lp->pktStats, ioc->len);
43998 spin_unlock_irqrestore(&lp->lock, flags);
43999- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44000+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44001 return -EFAULT;
44002 break;
44003 }
44004diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44005index 3d91a5e..1014702 100644
44006--- a/drivers/net/ethernet/emulex/benet/be_main.c
44007+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44008@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44009
44010 if (wrapped)
44011 newacc += 65536;
44012- ACCESS_ONCE(*acc) = newacc;
44013+ ACCESS_ONCE_RW(*acc) = newacc;
44014 }
44015
44016 void populate_erx_stats(struct be_adapter *adapter,
44017diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44018index 934e1ae..b262e6b 100644
44019--- a/drivers/net/ethernet/faraday/ftgmac100.c
44020+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44021@@ -31,6 +31,8 @@
44022 #include <linux/netdevice.h>
44023 #include <linux/phy.h>
44024 #include <linux/platform_device.h>
44025+#include <linux/interrupt.h>
44026+#include <linux/irqreturn.h>
44027 #include <net/ip.h>
44028
44029 #include "ftgmac100.h"
44030diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44031index 4658f4c..407d155 100644
44032--- a/drivers/net/ethernet/faraday/ftmac100.c
44033+++ b/drivers/net/ethernet/faraday/ftmac100.c
44034@@ -31,6 +31,8 @@
44035 #include <linux/module.h>
44036 #include <linux/netdevice.h>
44037 #include <linux/platform_device.h>
44038+#include <linux/interrupt.h>
44039+#include <linux/irqreturn.h>
44040
44041 #include "ftmac100.h"
44042
44043diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44044index 331987d..3be1135 100644
44045--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44046+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44047@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44048 }
44049
44050 /* update the base incval used to calculate frequency adjustment */
44051- ACCESS_ONCE(adapter->base_incval) = incval;
44052+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44053 smp_mb();
44054
44055 /* need lock to prevent incorrect read while modifying cyclecounter */
44056diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44057index fbe5363..266b4e3 100644
44058--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44059+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44060@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44061 struct __vxge_hw_fifo *fifo;
44062 struct vxge_hw_fifo_config *config;
44063 u32 txdl_size, txdl_per_memblock;
44064- struct vxge_hw_mempool_cbs fifo_mp_callback;
44065+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44066+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44067+ };
44068+
44069 struct __vxge_hw_virtualpath *vpath;
44070
44071 if ((vp == NULL) || (attr == NULL)) {
44072@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44073 goto exit;
44074 }
44075
44076- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44077-
44078 fifo->mempool =
44079 __vxge_hw_mempool_create(vpath->hldev,
44080 fifo->config->memblock_size,
44081diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44082index 345d987..af69721 100644
44083--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44084+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44085@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44086 op_mode = QLC_83XX_DEFAULT_OPMODE;
44087
44088 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44089- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44090+ pax_open_kernel();
44091+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44092+ pax_close_kernel();
44093 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44094 } else {
44095 return -EIO;
44096diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44097index 599d1fd..59868fe 100644
44098--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44099+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44100@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44101 case QLCNIC_NON_PRIV_FUNC:
44102 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44103 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44104- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44105+ pax_open_kernel();
44106+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44107+ pax_close_kernel();
44108 break;
44109 case QLCNIC_PRIV_FUNC:
44110 ahw->op_mode = QLCNIC_PRIV_FUNC;
44111 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44112- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44113+ pax_open_kernel();
44114+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44115+ pax_close_kernel();
44116 break;
44117 case QLCNIC_MGMT_FUNC:
44118 ahw->op_mode = QLCNIC_MGMT_FUNC;
44119 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44120- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44121+ pax_open_kernel();
44122+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44123+ pax_close_kernel();
44124 break;
44125 default:
44126 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44127diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44128index 7ba68e0..618c73d 100644
44129--- a/drivers/net/ethernet/realtek/r8169.c
44130+++ b/drivers/net/ethernet/realtek/r8169.c
44131@@ -759,22 +759,22 @@ struct rtl8169_private {
44132 struct mdio_ops {
44133 void (*write)(struct rtl8169_private *, int, int);
44134 int (*read)(struct rtl8169_private *, int);
44135- } mdio_ops;
44136+ } __no_const mdio_ops;
44137
44138 struct pll_power_ops {
44139 void (*down)(struct rtl8169_private *);
44140 void (*up)(struct rtl8169_private *);
44141- } pll_power_ops;
44142+ } __no_const pll_power_ops;
44143
44144 struct jumbo_ops {
44145 void (*enable)(struct rtl8169_private *);
44146 void (*disable)(struct rtl8169_private *);
44147- } jumbo_ops;
44148+ } __no_const jumbo_ops;
44149
44150 struct csi_ops {
44151 void (*write)(struct rtl8169_private *, int, int);
44152 u32 (*read)(struct rtl8169_private *, int);
44153- } csi_ops;
44154+ } __no_const csi_ops;
44155
44156 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44157 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44158diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44159index b495394..0748c54 100644
44160--- a/drivers/net/ethernet/sfc/ptp.c
44161+++ b/drivers/net/ethernet/sfc/ptp.c
44162@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44163 (u32)((u64)ptp->start.dma_addr >> 32));
44164
44165 /* Clear flag that signals MC ready */
44166- ACCESS_ONCE(*start) = 0;
44167+ ACCESS_ONCE_RW(*start) = 0;
44168 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44169 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44170
44171diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44172index 50617c5..b13724c 100644
44173--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44174+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44175@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44176
44177 writel(value, ioaddr + MMC_CNTRL);
44178
44179- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44180- MMC_CNTRL, value);
44181+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44182+// MMC_CNTRL, value);
44183 }
44184
44185 /* To mask all all interrupts.*/
44186diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44187index e6fe0d8..2b7d752 100644
44188--- a/drivers/net/hyperv/hyperv_net.h
44189+++ b/drivers/net/hyperv/hyperv_net.h
44190@@ -101,7 +101,7 @@ struct rndis_device {
44191
44192 enum rndis_device_state state;
44193 bool link_state;
44194- atomic_t new_req_id;
44195+ atomic_unchecked_t new_req_id;
44196
44197 spinlock_t request_lock;
44198 struct list_head req_list;
44199diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44200index 0775f0a..d4fb316 100644
44201--- a/drivers/net/hyperv/rndis_filter.c
44202+++ b/drivers/net/hyperv/rndis_filter.c
44203@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44204 * template
44205 */
44206 set = &rndis_msg->msg.set_req;
44207- set->req_id = atomic_inc_return(&dev->new_req_id);
44208+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44209
44210 /* Add to the request list */
44211 spin_lock_irqsave(&dev->request_lock, flags);
44212@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44213
44214 /* Setup the rndis set */
44215 halt = &request->request_msg.msg.halt_req;
44216- halt->req_id = atomic_inc_return(&dev->new_req_id);
44217+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44218
44219 /* Ignore return since this msg is optional. */
44220 rndis_filter_send_request(dev, request);
44221diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44222index bf0d55e..82bcfbd1 100644
44223--- a/drivers/net/ieee802154/fakehard.c
44224+++ b/drivers/net/ieee802154/fakehard.c
44225@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44226 phy->transmit_power = 0xbf;
44227
44228 dev->netdev_ops = &fake_ops;
44229- dev->ml_priv = &fake_mlme;
44230+ dev->ml_priv = (void *)&fake_mlme;
44231
44232 priv = netdev_priv(dev);
44233 priv->phy = phy;
44234diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44235index 16b43bf..ead0c35 100644
44236--- a/drivers/net/macvlan.c
44237+++ b/drivers/net/macvlan.c
44238@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44239 int macvlan_link_register(struct rtnl_link_ops *ops)
44240 {
44241 /* common fields */
44242- ops->priv_size = sizeof(struct macvlan_dev);
44243- ops->validate = macvlan_validate;
44244- ops->maxtype = IFLA_MACVLAN_MAX;
44245- ops->policy = macvlan_policy;
44246- ops->changelink = macvlan_changelink;
44247- ops->get_size = macvlan_get_size;
44248- ops->fill_info = macvlan_fill_info;
44249+ pax_open_kernel();
44250+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44251+ *(void **)&ops->validate = macvlan_validate;
44252+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44253+ *(const void **)&ops->policy = macvlan_policy;
44254+ *(void **)&ops->changelink = macvlan_changelink;
44255+ *(void **)&ops->get_size = macvlan_get_size;
44256+ *(void **)&ops->fill_info = macvlan_fill_info;
44257+ pax_close_kernel();
44258
44259 return rtnl_link_register(ops);
44260 };
44261@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44262 return NOTIFY_DONE;
44263 }
44264
44265-static struct notifier_block macvlan_notifier_block __read_mostly = {
44266+static struct notifier_block macvlan_notifier_block = {
44267 .notifier_call = macvlan_device_event,
44268 };
44269
44270diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44271index ea53abb..2e4d087 100644
44272--- a/drivers/net/macvtap.c
44273+++ b/drivers/net/macvtap.c
44274@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44275 return NOTIFY_DONE;
44276 }
44277
44278-static struct notifier_block macvtap_notifier_block __read_mostly = {
44279+static struct notifier_block macvtap_notifier_block = {
44280 .notifier_call = macvtap_device_event,
44281 };
44282
44283diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44284index daec9b0..6428fcb 100644
44285--- a/drivers/net/phy/mdio-bitbang.c
44286+++ b/drivers/net/phy/mdio-bitbang.c
44287@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44288 struct mdiobb_ctrl *ctrl = bus->priv;
44289
44290 module_put(ctrl->ops->owner);
44291+ mdiobus_unregister(bus);
44292 mdiobus_free(bus);
44293 }
44294 EXPORT_SYMBOL(free_mdio_bitbang);
44295diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44296index 72ff14b..11d442d 100644
44297--- a/drivers/net/ppp/ppp_generic.c
44298+++ b/drivers/net/ppp/ppp_generic.c
44299@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44300 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44301 struct ppp_stats stats;
44302 struct ppp_comp_stats cstats;
44303- char *vers;
44304
44305 switch (cmd) {
44306 case SIOCGPPPSTATS:
44307@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44308 break;
44309
44310 case SIOCGPPPVER:
44311- vers = PPP_VERSION;
44312- if (copy_to_user(addr, vers, strlen(vers) + 1))
44313+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44314 break;
44315 err = 0;
44316 break;
44317diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44318index 1252d9c..80e660b 100644
44319--- a/drivers/net/slip/slhc.c
44320+++ b/drivers/net/slip/slhc.c
44321@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44322 register struct tcphdr *thp;
44323 register struct iphdr *ip;
44324 register struct cstate *cs;
44325- int len, hdrlen;
44326+ long len, hdrlen;
44327 unsigned char *cp = icp;
44328
44329 /* We've got a compressed packet; read the change byte */
44330diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44331index bff7e0b..7315137 100644
44332--- a/drivers/net/team/team.c
44333+++ b/drivers/net/team/team.c
44334@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44335 return NOTIFY_DONE;
44336 }
44337
44338-static struct notifier_block team_notifier_block __read_mostly = {
44339+static struct notifier_block team_notifier_block = {
44340 .notifier_call = team_device_event,
44341 };
44342
44343diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44344index 68b9aa3..b3c20f3 100644
44345--- a/drivers/net/tun.c
44346+++ b/drivers/net/tun.c
44347@@ -1874,7 +1874,7 @@ unlock:
44348 }
44349
44350 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44351- unsigned long arg, int ifreq_len)
44352+ unsigned long arg, size_t ifreq_len)
44353 {
44354 struct tun_file *tfile = file->private_data;
44355 struct tun_struct *tun;
44356@@ -1886,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44357 int vnet_hdr_sz;
44358 int ret;
44359
44360+ if (ifreq_len > sizeof ifr)
44361+ return -EFAULT;
44362+
44363 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44364 if (copy_from_user(&ifr, argp, ifreq_len))
44365 return -EFAULT;
44366diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44367index 86292e6..8d34433 100644
44368--- a/drivers/net/usb/hso.c
44369+++ b/drivers/net/usb/hso.c
44370@@ -71,7 +71,7 @@
44371 #include <asm/byteorder.h>
44372 #include <linux/serial_core.h>
44373 #include <linux/serial.h>
44374-
44375+#include <asm/local.h>
44376
44377 #define MOD_AUTHOR "Option Wireless"
44378 #define MOD_DESCRIPTION "USB High Speed Option driver"
44379@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44380 struct urb *urb;
44381
44382 urb = serial->rx_urb[0];
44383- if (serial->port.count > 0) {
44384+ if (atomic_read(&serial->port.count) > 0) {
44385 count = put_rxbuf_data(urb, serial);
44386 if (count == -1)
44387 return;
44388@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44389 DUMP1(urb->transfer_buffer, urb->actual_length);
44390
44391 /* Anyone listening? */
44392- if (serial->port.count == 0)
44393+ if (atomic_read(&serial->port.count) == 0)
44394 return;
44395
44396 if (status == 0) {
44397@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44398 tty_port_tty_set(&serial->port, tty);
44399
44400 /* check for port already opened, if not set the termios */
44401- serial->port.count++;
44402- if (serial->port.count == 1) {
44403+ if (atomic_inc_return(&serial->port.count) == 1) {
44404 serial->rx_state = RX_IDLE;
44405 /* Force default termio settings */
44406 _hso_serial_set_termios(tty, NULL);
44407@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44408 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44409 if (result) {
44410 hso_stop_serial_device(serial->parent);
44411- serial->port.count--;
44412+ atomic_dec(&serial->port.count);
44413 kref_put(&serial->parent->ref, hso_serial_ref_free);
44414 }
44415 } else {
44416@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44417
44418 /* reset the rts and dtr */
44419 /* do the actual close */
44420- serial->port.count--;
44421+ atomic_dec(&serial->port.count);
44422
44423- if (serial->port.count <= 0) {
44424- serial->port.count = 0;
44425+ if (atomic_read(&serial->port.count) <= 0) {
44426+ atomic_set(&serial->port.count, 0);
44427 tty_port_tty_set(&serial->port, NULL);
44428 if (!usb_gone)
44429 hso_stop_serial_device(serial->parent);
44430@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44431
44432 /* the actual setup */
44433 spin_lock_irqsave(&serial->serial_lock, flags);
44434- if (serial->port.count)
44435+ if (atomic_read(&serial->port.count))
44436 _hso_serial_set_termios(tty, old);
44437 else
44438 tty->termios = *old;
44439@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44440 D1("Pending read interrupt on port %d\n", i);
44441 spin_lock(&serial->serial_lock);
44442 if (serial->rx_state == RX_IDLE &&
44443- serial->port.count > 0) {
44444+ atomic_read(&serial->port.count) > 0) {
44445 /* Setup and send a ctrl req read on
44446 * port i */
44447 if (!serial->rx_urb_filled[0]) {
44448@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44449 /* Start all serial ports */
44450 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44451 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44452- if (dev2ser(serial_table[i])->port.count) {
44453+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44454 result =
44455 hso_start_serial_device(serial_table[i], GFP_NOIO);
44456 hso_kick_transmit(dev2ser(serial_table[i]));
44457diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44458index a79e9d3..78cd4fa 100644
44459--- a/drivers/net/usb/sierra_net.c
44460+++ b/drivers/net/usb/sierra_net.c
44461@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44462 /* atomic counter partially included in MAC address to make sure 2 devices
44463 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44464 */
44465-static atomic_t iface_counter = ATOMIC_INIT(0);
44466+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44467
44468 /*
44469 * SYNC Timer Delay definition used to set the expiry time
44470@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44471 dev->net->netdev_ops = &sierra_net_device_ops;
44472
44473 /* change MAC addr to include, ifacenum, and to be unique */
44474- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44475+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44476 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44477
44478 /* we will have to manufacture ethernet headers, prepare template */
44479diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44480index 8a05d77..ba8b9c5 100644
44481--- a/drivers/net/vxlan.c
44482+++ b/drivers/net/vxlan.c
44483@@ -1870,7 +1870,7 @@ nla_put_failure:
44484 return -EMSGSIZE;
44485 }
44486
44487-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44488+static struct rtnl_link_ops vxlan_link_ops = {
44489 .kind = "vxlan",
44490 .maxtype = IFLA_VXLAN_MAX,
44491 .policy = vxlan_policy,
44492diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
44493index 3f0c4f2..bcfff0d 100644
44494--- a/drivers/net/wan/farsync.c
44495+++ b/drivers/net/wan/farsync.c
44496@@ -1972,6 +1972,7 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port,
44497 }
44498
44499 i = port->index;
44500+ memset(&sync, 0, sizeof(sync));
44501 sync.clock_rate = FST_RDL(card, portConfig[i].lineSpeed);
44502 /* Lucky card and linux use same encoding here */
44503 sync.clock_type = FST_RDB(card, portConfig[i].internalClock) ==
44504diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44505index 0b60295..b8bfa5b 100644
44506--- a/drivers/net/wimax/i2400m/rx.c
44507+++ b/drivers/net/wimax/i2400m/rx.c
44508@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44509 if (i2400m->rx_roq == NULL)
44510 goto error_roq_alloc;
44511
44512- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44513+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44514 GFP_KERNEL);
44515 if (rd == NULL) {
44516 result = -ENOMEM;
44517diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44518index 34c8a33..3261fdc 100644
44519--- a/drivers/net/wireless/at76c50x-usb.c
44520+++ b/drivers/net/wireless/at76c50x-usb.c
44521@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44522 }
44523
44524 /* Convert timeout from the DFU status to jiffies */
44525-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44526+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44527 {
44528 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44529 | (s->poll_timeout[1] << 8)
44530diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44531index 2b3426b..1f564be 100644
44532--- a/drivers/net/wireless/ath/ath10k/core.c
44533+++ b/drivers/net/wireless/ath/ath10k/core.c
44534@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44535
44536 int ath10k_core_register(struct ath10k *ar)
44537 {
44538- struct ath10k_htc_ops htc_ops;
44539+ static struct ath10k_htc_ops htc_ops = {
44540+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44541+ };
44542 struct bmi_target_info target_info;
44543 int status;
44544
44545@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44546 if (status)
44547 goto err;
44548
44549- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44550-
44551 ar->htc = ath10k_htc_create(ar, &htc_ops);
44552 if (IS_ERR(ar->htc)) {
44553 status = PTR_ERR(ar->htc);
44554diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44555index 74363c9..237b926 100644
44556--- a/drivers/net/wireless/ath/ath10k/htc.c
44557+++ b/drivers/net/wireless/ath/ath10k/htc.c
44558@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44559 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44560 struct ath10k_htc_ops *htc_ops)
44561 {
44562- struct ath10k_hif_cb htc_callbacks;
44563+ static struct ath10k_hif_cb htc_callbacks = {
44564+ .rx_completion = ath10k_htc_rx_completion_handler,
44565+ .tx_completion = ath10k_htc_tx_completion_handler,
44566+ };
44567 struct ath10k_htc_ep *ep = NULL;
44568 struct ath10k_htc *htc = NULL;
44569
44570@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44571 ath10k_htc_reset_endpoint_states(htc);
44572
44573 /* setup HIF layer callbacks */
44574- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44575- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44576 htc->ar = ar;
44577
44578 /* Get HIF default pipe for HTC message exchange */
44579diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44580index 8d78253..bebbb68 100644
44581--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44582+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44583@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44584 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44585 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44586
44587- ACCESS_ONCE(ads->ds_link) = i->link;
44588- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44589+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44590+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44591
44592 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44593 ctl6 = SM(i->keytype, AR_EncrType);
44594@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44595
44596 if ((i->is_first || i->is_last) &&
44597 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44598- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44599+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44600 | set11nTries(i->rates, 1)
44601 | set11nTries(i->rates, 2)
44602 | set11nTries(i->rates, 3)
44603 | (i->dur_update ? AR_DurUpdateEna : 0)
44604 | SM(0, AR_BurstDur);
44605
44606- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44607+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44608 | set11nRate(i->rates, 1)
44609 | set11nRate(i->rates, 2)
44610 | set11nRate(i->rates, 3);
44611 } else {
44612- ACCESS_ONCE(ads->ds_ctl2) = 0;
44613- ACCESS_ONCE(ads->ds_ctl3) = 0;
44614+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44615+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44616 }
44617
44618 if (!i->is_first) {
44619- ACCESS_ONCE(ads->ds_ctl0) = 0;
44620- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44621- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44622+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44623+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44624+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44625 return;
44626 }
44627
44628@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44629 break;
44630 }
44631
44632- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44633+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44634 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44635 | SM(i->txpower, AR_XmitPower)
44636 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44637@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44638 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44639 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44640
44641- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44642- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44643+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44644+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44645
44646 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44647 return;
44648
44649- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44650+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44651 | set11nPktDurRTSCTS(i->rates, 1);
44652
44653- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44654+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44655 | set11nPktDurRTSCTS(i->rates, 3);
44656
44657- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44658+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44659 | set11nRateFlags(i->rates, 1)
44660 | set11nRateFlags(i->rates, 2)
44661 | set11nRateFlags(i->rates, 3)
44662diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44663index 5163abd..3ada4c2 100644
44664--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44665+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44666@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44667 (i->qcu << AR_TxQcuNum_S) | desc_len;
44668
44669 checksum += val;
44670- ACCESS_ONCE(ads->info) = val;
44671+ ACCESS_ONCE_RW(ads->info) = val;
44672
44673 checksum += i->link;
44674- ACCESS_ONCE(ads->link) = i->link;
44675+ ACCESS_ONCE_RW(ads->link) = i->link;
44676
44677 checksum += i->buf_addr[0];
44678- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44679+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44680 checksum += i->buf_addr[1];
44681- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44682+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44683 checksum += i->buf_addr[2];
44684- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44685+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44686 checksum += i->buf_addr[3];
44687- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44688+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44689
44690 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44691- ACCESS_ONCE(ads->ctl3) = val;
44692+ ACCESS_ONCE_RW(ads->ctl3) = val;
44693 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44694- ACCESS_ONCE(ads->ctl5) = val;
44695+ ACCESS_ONCE_RW(ads->ctl5) = val;
44696 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44697- ACCESS_ONCE(ads->ctl7) = val;
44698+ ACCESS_ONCE_RW(ads->ctl7) = val;
44699 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44700- ACCESS_ONCE(ads->ctl9) = val;
44701+ ACCESS_ONCE_RW(ads->ctl9) = val;
44702
44703 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44704- ACCESS_ONCE(ads->ctl10) = checksum;
44705+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44706
44707 if (i->is_first || i->is_last) {
44708- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44709+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44710 | set11nTries(i->rates, 1)
44711 | set11nTries(i->rates, 2)
44712 | set11nTries(i->rates, 3)
44713 | (i->dur_update ? AR_DurUpdateEna : 0)
44714 | SM(0, AR_BurstDur);
44715
44716- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44717+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44718 | set11nRate(i->rates, 1)
44719 | set11nRate(i->rates, 2)
44720 | set11nRate(i->rates, 3);
44721 } else {
44722- ACCESS_ONCE(ads->ctl13) = 0;
44723- ACCESS_ONCE(ads->ctl14) = 0;
44724+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44725+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44726 }
44727
44728 ads->ctl20 = 0;
44729@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44730
44731 ctl17 = SM(i->keytype, AR_EncrType);
44732 if (!i->is_first) {
44733- ACCESS_ONCE(ads->ctl11) = 0;
44734- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44735- ACCESS_ONCE(ads->ctl15) = 0;
44736- ACCESS_ONCE(ads->ctl16) = 0;
44737- ACCESS_ONCE(ads->ctl17) = ctl17;
44738- ACCESS_ONCE(ads->ctl18) = 0;
44739- ACCESS_ONCE(ads->ctl19) = 0;
44740+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44741+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44742+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44743+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44744+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44745+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44746+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44747 return;
44748 }
44749
44750- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44751+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44752 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44753 | SM(i->txpower, AR_XmitPower)
44754 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44755@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44756 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44757 ctl12 |= SM(val, AR_PAPRDChainMask);
44758
44759- ACCESS_ONCE(ads->ctl12) = ctl12;
44760- ACCESS_ONCE(ads->ctl17) = ctl17;
44761+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44762+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44763
44764- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44765+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44766 | set11nPktDurRTSCTS(i->rates, 1);
44767
44768- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44769+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44770 | set11nPktDurRTSCTS(i->rates, 3);
44771
44772- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44773+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44774 | set11nRateFlags(i->rates, 1)
44775 | set11nRateFlags(i->rates, 2)
44776 | set11nRateFlags(i->rates, 3)
44777 | SM(i->rtscts_rate, AR_RTSCTSRate);
44778
44779- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44780+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44781 }
44782
44783 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44784diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44785index cd74b3a..6a28d24 100644
44786--- a/drivers/net/wireless/ath/ath9k/hw.h
44787+++ b/drivers/net/wireless/ath/ath9k/hw.h
44788@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44789
44790 /* ANI */
44791 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44792-};
44793+} __no_const;
44794
44795 /**
44796 * struct ath_spec_scan - parameters for Atheros spectral scan
44797@@ -721,7 +721,7 @@ struct ath_hw_ops {
44798 struct ath_spec_scan *param);
44799 void (*spectral_scan_trigger)(struct ath_hw *ah);
44800 void (*spectral_scan_wait)(struct ath_hw *ah);
44801-};
44802+} __no_const;
44803
44804 struct ath_nf_limits {
44805 s16 max;
44806diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44807index 9581d07..84f6a76 100644
44808--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44809+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44810@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44811 */
44812 if (il3945_mod_params.disable_hw_scan) {
44813 D_INFO("Disabling hw_scan\n");
44814- il3945_mac_ops.hw_scan = NULL;
44815+ pax_open_kernel();
44816+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44817+ pax_close_kernel();
44818 }
44819
44820 D_INFO("*** LOAD DRIVER ***\n");
44821diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44822index d532948..e0d8bb1 100644
44823--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44824+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44825@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44826 {
44827 struct iwl_priv *priv = file->private_data;
44828 char buf[64];
44829- int buf_size;
44830+ size_t buf_size;
44831 u32 offset, len;
44832
44833 memset(buf, 0, sizeof(buf));
44834@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44835 struct iwl_priv *priv = file->private_data;
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@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44844 {
44845 struct iwl_priv *priv = file->private_data;
44846 char buf[8];
44847- int buf_size;
44848+ size_t buf_size;
44849 int ht40;
44850
44851 memset(buf, 0, sizeof(buf));
44852@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44853 {
44854 struct iwl_priv *priv = file->private_data;
44855 char buf[8];
44856- int buf_size;
44857+ size_t buf_size;
44858 int value;
44859
44860 memset(buf, 0, sizeof(buf));
44861@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44862 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44863 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44864
44865-static const char *fmt_value = " %-30s %10u\n";
44866-static const char *fmt_hex = " %-30s 0x%02X\n";
44867-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44868-static const char *fmt_header =
44869+static const char fmt_value[] = " %-30s %10u\n";
44870+static const char fmt_hex[] = " %-30s 0x%02X\n";
44871+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44872+static const char fmt_header[] =
44873 "%-32s current cumulative delta max\n";
44874
44875 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44876@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44877 {
44878 struct iwl_priv *priv = file->private_data;
44879 char buf[8];
44880- int buf_size;
44881+ size_t buf_size;
44882 int clear;
44883
44884 memset(buf, 0, sizeof(buf));
44885@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44886 {
44887 struct iwl_priv *priv = file->private_data;
44888 char buf[8];
44889- int buf_size;
44890+ size_t buf_size;
44891 int trace;
44892
44893 memset(buf, 0, sizeof(buf));
44894@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44895 {
44896 struct iwl_priv *priv = file->private_data;
44897 char buf[8];
44898- int buf_size;
44899+ size_t buf_size;
44900 int missed;
44901
44902 memset(buf, 0, sizeof(buf));
44903@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44904
44905 struct iwl_priv *priv = file->private_data;
44906 char buf[8];
44907- int buf_size;
44908+ size_t buf_size;
44909 int plcp;
44910
44911 memset(buf, 0, sizeof(buf));
44912@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44913
44914 struct iwl_priv *priv = file->private_data;
44915 char buf[8];
44916- int buf_size;
44917+ size_t buf_size;
44918 int flush;
44919
44920 memset(buf, 0, sizeof(buf));
44921@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44922
44923 struct iwl_priv *priv = file->private_data;
44924 char buf[8];
44925- int buf_size;
44926+ size_t buf_size;
44927 int rts;
44928
44929 if (!priv->cfg->ht_params)
44930@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44931 {
44932 struct iwl_priv *priv = file->private_data;
44933 char buf[8];
44934- int buf_size;
44935+ size_t buf_size;
44936
44937 memset(buf, 0, sizeof(buf));
44938 buf_size = min(count, sizeof(buf) - 1);
44939@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44940 struct iwl_priv *priv = file->private_data;
44941 u32 event_log_flag;
44942 char buf[8];
44943- int buf_size;
44944+ size_t buf_size;
44945
44946 /* check that the interface is up */
44947 if (!iwl_is_ready(priv))
44948@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44949 struct iwl_priv *priv = file->private_data;
44950 char buf[8];
44951 u32 calib_disabled;
44952- int buf_size;
44953+ size_t buf_size;
44954
44955 memset(buf, 0, sizeof(buf));
44956 buf_size = min(count, sizeof(buf) - 1);
44957diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44958index 1531a4f..21d2641 100644
44959--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44960+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44961@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44962 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44963 {
44964 struct iwl_nvm_data *data = priv->nvm_data;
44965- char *debug_msg;
44966+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44967
44968 if (data->sku_cap_11n_enable &&
44969 !priv->cfg->ht_params) {
44970@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44971 return -EINVAL;
44972 }
44973
44974- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44975 IWL_DEBUG_INFO(priv, debug_msg,
44976 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44977 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
44978diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
44979index 390e2f0..75cfbaf 100644
44980--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
44981+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
44982@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
44983 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
44984
44985 char buf[8];
44986- int buf_size;
44987+ size_t buf_size;
44988 u32 reset_flag;
44989
44990 memset(buf, 0, sizeof(buf));
44991@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
44992 {
44993 struct iwl_trans *trans = file->private_data;
44994 char buf[8];
44995- int buf_size;
44996+ size_t buf_size;
44997 int csr;
44998
44999 memset(buf, 0, sizeof(buf));
45000diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45001index cb34c78..9fec0dc 100644
45002--- a/drivers/net/wireless/mac80211_hwsim.c
45003+++ b/drivers/net/wireless/mac80211_hwsim.c
45004@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45005
45006 if (channels > 1) {
45007 hwsim_if_comb.num_different_channels = channels;
45008- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45009- mac80211_hwsim_ops.cancel_hw_scan =
45010- mac80211_hwsim_cancel_hw_scan;
45011- mac80211_hwsim_ops.sw_scan_start = NULL;
45012- mac80211_hwsim_ops.sw_scan_complete = NULL;
45013- mac80211_hwsim_ops.remain_on_channel =
45014- mac80211_hwsim_roc;
45015- mac80211_hwsim_ops.cancel_remain_on_channel =
45016- mac80211_hwsim_croc;
45017- mac80211_hwsim_ops.add_chanctx =
45018- mac80211_hwsim_add_chanctx;
45019- mac80211_hwsim_ops.remove_chanctx =
45020- mac80211_hwsim_remove_chanctx;
45021- mac80211_hwsim_ops.change_chanctx =
45022- mac80211_hwsim_change_chanctx;
45023- mac80211_hwsim_ops.assign_vif_chanctx =
45024- mac80211_hwsim_assign_vif_chanctx;
45025- mac80211_hwsim_ops.unassign_vif_chanctx =
45026- mac80211_hwsim_unassign_vif_chanctx;
45027+ pax_open_kernel();
45028+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45029+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45030+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45031+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45032+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45033+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45034+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45035+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45036+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45037+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45038+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45039+ pax_close_kernel();
45040 }
45041
45042 spin_lock_init(&hwsim_radio_lock);
45043diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45044index 8169a85..7fa3b47 100644
45045--- a/drivers/net/wireless/rndis_wlan.c
45046+++ b/drivers/net/wireless/rndis_wlan.c
45047@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45048
45049 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45050
45051- if (rts_threshold < 0 || rts_threshold > 2347)
45052+ if (rts_threshold > 2347)
45053 rts_threshold = 2347;
45054
45055 tmp = cpu_to_le32(rts_threshold);
45056diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45057index ee3fc57..ed5ddc9 100644
45058--- a/drivers/net/wireless/rt2x00/rt2x00.h
45059+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45060@@ -386,7 +386,7 @@ struct rt2x00_intf {
45061 * for hardware which doesn't support hardware
45062 * sequence counting.
45063 */
45064- atomic_t seqno;
45065+ atomic_unchecked_t seqno;
45066 };
45067
45068 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45069diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45070index aa95c6c..a59dd67 100644
45071--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45072+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45073@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45074 * sequence counter given by mac80211.
45075 */
45076 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45077- seqno = atomic_add_return(0x10, &intf->seqno);
45078+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45079 else
45080- seqno = atomic_read(&intf->seqno);
45081+ seqno = atomic_read_unchecked(&intf->seqno);
45082
45083 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45084 hdr->seq_ctrl |= cpu_to_le16(seqno);
45085diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45086index e2b3d9c..67a5184 100644
45087--- a/drivers/net/wireless/ti/wl1251/sdio.c
45088+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45089@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45090
45091 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45092
45093- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45094- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45095+ pax_open_kernel();
45096+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45097+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45098+ pax_close_kernel();
45099
45100 wl1251_info("using dedicated interrupt line");
45101 } else {
45102- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45103- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45104+ pax_open_kernel();
45105+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45106+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45107+ pax_close_kernel();
45108
45109 wl1251_info("using SDIO interrupt");
45110 }
45111diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45112index 1c627da..69f7d17 100644
45113--- a/drivers/net/wireless/ti/wl12xx/main.c
45114+++ b/drivers/net/wireless/ti/wl12xx/main.c
45115@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45116 sizeof(wl->conf.mem));
45117
45118 /* read data preparation is only needed by wl127x */
45119- wl->ops->prepare_read = wl127x_prepare_read;
45120+ pax_open_kernel();
45121+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45122+ pax_close_kernel();
45123
45124 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45125 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45126@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45127 sizeof(wl->conf.mem));
45128
45129 /* read data preparation is only needed by wl127x */
45130- wl->ops->prepare_read = wl127x_prepare_read;
45131+ pax_open_kernel();
45132+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45133+ pax_close_kernel();
45134
45135 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45136 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45137diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45138index 7aa0eb8..5a9ef38 100644
45139--- a/drivers/net/wireless/ti/wl18xx/main.c
45140+++ b/drivers/net/wireless/ti/wl18xx/main.c
45141@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45142 }
45143
45144 if (!checksum_param) {
45145- wl18xx_ops.set_rx_csum = NULL;
45146- wl18xx_ops.init_vif = NULL;
45147+ pax_open_kernel();
45148+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45149+ *(void **)&wl18xx_ops.init_vif = NULL;
45150+ pax_close_kernel();
45151 }
45152
45153 /* Enable 11a Band only if we have 5G antennas */
45154diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45155index 7ef0b4a..ff65c28 100644
45156--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45157+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45158@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45159 {
45160 struct zd_usb *usb = urb->context;
45161 struct zd_usb_interrupt *intr = &usb->intr;
45162- int len;
45163+ unsigned int len;
45164 u16 int_num;
45165
45166 ZD_ASSERT(in_interrupt());
45167diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45168index d93b2b6..ae50401 100644
45169--- a/drivers/oprofile/buffer_sync.c
45170+++ b/drivers/oprofile/buffer_sync.c
45171@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45172 if (cookie == NO_COOKIE)
45173 offset = pc;
45174 if (cookie == INVALID_COOKIE) {
45175- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45176+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45177 offset = pc;
45178 }
45179 if (cookie != last_cookie) {
45180@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45181 /* add userspace sample */
45182
45183 if (!mm) {
45184- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45185+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45186 return 0;
45187 }
45188
45189 cookie = lookup_dcookie(mm, s->eip, &offset);
45190
45191 if (cookie == INVALID_COOKIE) {
45192- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45193+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45194 return 0;
45195 }
45196
45197@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45198 /* ignore backtraces if failed to add a sample */
45199 if (state == sb_bt_start) {
45200 state = sb_bt_ignore;
45201- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45202+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45203 }
45204 }
45205 release_mm(mm);
45206diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45207index c0cc4e7..44d4e54 100644
45208--- a/drivers/oprofile/event_buffer.c
45209+++ b/drivers/oprofile/event_buffer.c
45210@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45211 }
45212
45213 if (buffer_pos == buffer_size) {
45214- atomic_inc(&oprofile_stats.event_lost_overflow);
45215+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45216 return;
45217 }
45218
45219diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45220index ed2c3ec..deda85a 100644
45221--- a/drivers/oprofile/oprof.c
45222+++ b/drivers/oprofile/oprof.c
45223@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45224 if (oprofile_ops.switch_events())
45225 return;
45226
45227- atomic_inc(&oprofile_stats.multiplex_counter);
45228+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45229 start_switch_worker();
45230 }
45231
45232diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45233index 84a208d..d61b0a1 100644
45234--- a/drivers/oprofile/oprofile_files.c
45235+++ b/drivers/oprofile/oprofile_files.c
45236@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45237
45238 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45239
45240-static ssize_t timeout_read(struct file *file, char __user *buf,
45241+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45242 size_t count, loff_t *offset)
45243 {
45244 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45245diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45246index 917d28e..d62d981 100644
45247--- a/drivers/oprofile/oprofile_stats.c
45248+++ b/drivers/oprofile/oprofile_stats.c
45249@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45250 cpu_buf->sample_invalid_eip = 0;
45251 }
45252
45253- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45254- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45255- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45256- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45257- atomic_set(&oprofile_stats.multiplex_counter, 0);
45258+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45259+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45260+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45261+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45262+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45263 }
45264
45265
45266diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45267index 38b6fc0..b5cbfce 100644
45268--- a/drivers/oprofile/oprofile_stats.h
45269+++ b/drivers/oprofile/oprofile_stats.h
45270@@ -13,11 +13,11 @@
45271 #include <linux/atomic.h>
45272
45273 struct oprofile_stat_struct {
45274- atomic_t sample_lost_no_mm;
45275- atomic_t sample_lost_no_mapping;
45276- atomic_t bt_lost_no_mapping;
45277- atomic_t event_lost_overflow;
45278- atomic_t multiplex_counter;
45279+ atomic_unchecked_t sample_lost_no_mm;
45280+ atomic_unchecked_t sample_lost_no_mapping;
45281+ atomic_unchecked_t bt_lost_no_mapping;
45282+ atomic_unchecked_t event_lost_overflow;
45283+ atomic_unchecked_t multiplex_counter;
45284 };
45285
45286 extern struct oprofile_stat_struct oprofile_stats;
45287diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45288index 7c12d9c..558bf3bb 100644
45289--- a/drivers/oprofile/oprofilefs.c
45290+++ b/drivers/oprofile/oprofilefs.c
45291@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45292
45293
45294 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45295- char const *name, atomic_t *val)
45296+ char const *name, atomic_unchecked_t *val)
45297 {
45298 return __oprofilefs_create_file(sb, root, name,
45299 &atomic_ro_fops, 0444, val);
45300diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45301index 61be1d9..dec05d7 100644
45302--- a/drivers/oprofile/timer_int.c
45303+++ b/drivers/oprofile/timer_int.c
45304@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45305 return NOTIFY_OK;
45306 }
45307
45308-static struct notifier_block __refdata oprofile_cpu_notifier = {
45309+static struct notifier_block oprofile_cpu_notifier = {
45310 .notifier_call = oprofile_cpu_notify,
45311 };
45312
45313diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45314index 92ed045..62d39bd7 100644
45315--- a/drivers/parport/procfs.c
45316+++ b/drivers/parport/procfs.c
45317@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45318
45319 *ppos += len;
45320
45321- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45322+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45323 }
45324
45325 #ifdef CONFIG_PARPORT_1284
45326@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45327
45328 *ppos += len;
45329
45330- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45331+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45332 }
45333 #endif /* IEEE1284.3 support. */
45334
45335diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45336index c35e8ad..fc33beb 100644
45337--- a/drivers/pci/hotplug/acpiphp_ibm.c
45338+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45339@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45340 goto init_cleanup;
45341 }
45342
45343- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45344+ pax_open_kernel();
45345+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45346+ pax_close_kernel();
45347 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45348
45349 return retval;
45350diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45351index a6a71c4..c91097b 100644
45352--- a/drivers/pci/hotplug/cpcihp_generic.c
45353+++ b/drivers/pci/hotplug/cpcihp_generic.c
45354@@ -73,7 +73,6 @@ static u16 port;
45355 static unsigned int enum_bit;
45356 static u8 enum_mask;
45357
45358-static struct cpci_hp_controller_ops generic_hpc_ops;
45359 static struct cpci_hp_controller generic_hpc;
45360
45361 static int __init validate_parameters(void)
45362@@ -139,6 +138,10 @@ static int query_enum(void)
45363 return ((value & enum_mask) == enum_mask);
45364 }
45365
45366+static struct cpci_hp_controller_ops generic_hpc_ops = {
45367+ .query_enum = query_enum,
45368+};
45369+
45370 static int __init cpcihp_generic_init(void)
45371 {
45372 int status;
45373@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45374 pci_dev_put(dev);
45375
45376 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45377- generic_hpc_ops.query_enum = query_enum;
45378 generic_hpc.ops = &generic_hpc_ops;
45379
45380 status = cpci_hp_register_controller(&generic_hpc);
45381diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45382index 449b4bb..257e2e8 100644
45383--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45384+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45385@@ -59,7 +59,6 @@
45386 /* local variables */
45387 static bool debug;
45388 static bool poll;
45389-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45390 static struct cpci_hp_controller zt5550_hpc;
45391
45392 /* Primary cPCI bus bridge device */
45393@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45394 return 0;
45395 }
45396
45397+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45398+ .query_enum = zt5550_hc_query_enum,
45399+};
45400+
45401 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45402 {
45403 int status;
45404@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45405 dbg("returned from zt5550_hc_config");
45406
45407 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45408- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45409 zt5550_hpc.ops = &zt5550_hpc_ops;
45410 if(!poll) {
45411 zt5550_hpc.irq = hc_dev->irq;
45412 zt5550_hpc.irq_flags = IRQF_SHARED;
45413 zt5550_hpc.dev_id = hc_dev;
45414
45415- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45416- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45417- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45418+ pax_open_kernel();
45419+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45420+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45421+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45422+ pax_open_kernel();
45423 } else {
45424 info("using ENUM# polling mode");
45425 }
45426diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45427index 76ba8a1..20ca857 100644
45428--- a/drivers/pci/hotplug/cpqphp_nvram.c
45429+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45430@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45431
45432 void compaq_nvram_init (void __iomem *rom_start)
45433 {
45434+
45435+#ifndef CONFIG_PAX_KERNEXEC
45436 if (rom_start) {
45437 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45438 }
45439+#endif
45440+
45441 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45442
45443 /* initialize our int15 lock */
45444diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45445index ec20f74..c1d961e 100644
45446--- a/drivers/pci/hotplug/pci_hotplug_core.c
45447+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45448@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45449 return -EINVAL;
45450 }
45451
45452- slot->ops->owner = owner;
45453- slot->ops->mod_name = mod_name;
45454+ pax_open_kernel();
45455+ *(struct module **)&slot->ops->owner = owner;
45456+ *(const char **)&slot->ops->mod_name = mod_name;
45457+ pax_close_kernel();
45458
45459 mutex_lock(&pci_hp_mutex);
45460 /*
45461diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45462index 7d72c5e..edce02c 100644
45463--- a/drivers/pci/hotplug/pciehp_core.c
45464+++ b/drivers/pci/hotplug/pciehp_core.c
45465@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45466 struct slot *slot = ctrl->slot;
45467 struct hotplug_slot *hotplug = NULL;
45468 struct hotplug_slot_info *info = NULL;
45469- struct hotplug_slot_ops *ops = NULL;
45470+ hotplug_slot_ops_no_const *ops = NULL;
45471 char name[SLOT_NAME_SIZE];
45472 int retval = -ENOMEM;
45473
45474diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45475index c0dbe1f..94cf3d8 100644
45476--- a/drivers/pci/pci-sysfs.c
45477+++ b/drivers/pci/pci-sysfs.c
45478@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45479 {
45480 /* allocate attribute structure, piggyback attribute name */
45481 int name_len = write_combine ? 13 : 10;
45482- struct bin_attribute *res_attr;
45483+ bin_attribute_no_const *res_attr;
45484 int retval;
45485
45486 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45487@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45488 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45489 {
45490 int retval;
45491- struct bin_attribute *attr;
45492+ bin_attribute_no_const *attr;
45493
45494 /* If the device has VPD, try to expose it in sysfs. */
45495 if (dev->vpd) {
45496@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45497 {
45498 int retval;
45499 int rom_size = 0;
45500- struct bin_attribute *attr;
45501+ bin_attribute_no_const *attr;
45502
45503 if (!sysfs_initialized)
45504 return -EACCES;
45505diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45506index d1182c4..2a138ec 100644
45507--- a/drivers/pci/pci.h
45508+++ b/drivers/pci/pci.h
45509@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45510 struct pci_vpd {
45511 unsigned int len;
45512 const struct pci_vpd_ops *ops;
45513- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45514+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45515 };
45516
45517 int pci_vpd_pci22_init(struct pci_dev *dev);
45518diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45519index 403a443..034e050 100644
45520--- a/drivers/pci/pcie/aspm.c
45521+++ b/drivers/pci/pcie/aspm.c
45522@@ -27,9 +27,9 @@
45523 #define MODULE_PARAM_PREFIX "pcie_aspm."
45524
45525 /* Note: those are not register definitions */
45526-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45527-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45528-#define ASPM_STATE_L1 (4) /* L1 state */
45529+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45530+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45531+#define ASPM_STATE_L1 (4U) /* L1 state */
45532 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45533 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45534
45535diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45536index 46ada5c..20da716 100644
45537--- a/drivers/pci/probe.c
45538+++ b/drivers/pci/probe.c
45539@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45540 struct pci_bus_region region, inverted_region;
45541 bool bar_too_big = false, bar_disabled = false;
45542
45543- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45544+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45545
45546 /* No printks while decoding is disabled! */
45547 if (!dev->mmio_always_on) {
45548diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45549index cdc7836..528635c 100644
45550--- a/drivers/pci/proc.c
45551+++ b/drivers/pci/proc.c
45552@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45553 static int __init pci_proc_init(void)
45554 {
45555 struct pci_dev *dev = NULL;
45556+
45557+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45558+#ifdef CONFIG_GRKERNSEC_PROC_USER
45559+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45560+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45561+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45562+#endif
45563+#else
45564 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45565+#endif
45566 proc_create("devices", 0, proc_bus_pci_dir,
45567 &proc_bus_pci_dev_operations);
45568 proc_initialized = 1;
45569diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45570index 3e5b4497..dcdfb70 100644
45571--- a/drivers/platform/x86/chromeos_laptop.c
45572+++ b/drivers/platform/x86/chromeos_laptop.c
45573@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45574 return 0;
45575 }
45576
45577-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45578+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45579 {
45580 .ident = "Samsung Series 5 550 - Touchpad",
45581 .matches = {
45582diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45583index 62f8030..c7f2a45 100644
45584--- a/drivers/platform/x86/msi-laptop.c
45585+++ b/drivers/platform/x86/msi-laptop.c
45586@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45587
45588 if (!quirks->ec_read_only) {
45589 /* allow userland write sysfs file */
45590- dev_attr_bluetooth.store = store_bluetooth;
45591- dev_attr_wlan.store = store_wlan;
45592- dev_attr_threeg.store = store_threeg;
45593- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45594- dev_attr_wlan.attr.mode |= S_IWUSR;
45595- dev_attr_threeg.attr.mode |= S_IWUSR;
45596+ pax_open_kernel();
45597+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45598+ *(void **)&dev_attr_wlan.store = store_wlan;
45599+ *(void **)&dev_attr_threeg.store = store_threeg;
45600+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45601+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45602+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45603+ pax_close_kernel();
45604 }
45605
45606 /* disable hardware control by fn key */
45607diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45608index 3a1b6bf..b453930 100644
45609--- a/drivers/platform/x86/sony-laptop.c
45610+++ b/drivers/platform/x86/sony-laptop.c
45611@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45612 }
45613
45614 /* High speed charging function */
45615-static struct device_attribute *hsc_handle;
45616+static device_attribute_no_const *hsc_handle;
45617
45618 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45619 struct device_attribute *attr,
45620diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45621index 54d31c0..3f896d3 100644
45622--- a/drivers/platform/x86/thinkpad_acpi.c
45623+++ b/drivers/platform/x86/thinkpad_acpi.c
45624@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45625 return 0;
45626 }
45627
45628-void static hotkey_mask_warn_incomplete_mask(void)
45629+static void hotkey_mask_warn_incomplete_mask(void)
45630 {
45631 /* log only what the user can fix... */
45632 const u32 wantedmask = hotkey_driver_mask &
45633@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45634 }
45635 }
45636
45637-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45638- struct tp_nvram_state *newn,
45639- const u32 event_mask)
45640-{
45641-
45642 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45643 do { \
45644 if ((event_mask & (1 << __scancode)) && \
45645@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45646 tpacpi_hotkey_send_key(__scancode); \
45647 } while (0)
45648
45649- void issue_volchange(const unsigned int oldvol,
45650- const unsigned int newvol)
45651- {
45652- unsigned int i = oldvol;
45653+static void issue_volchange(const unsigned int oldvol,
45654+ const unsigned int newvol,
45655+ const u32 event_mask)
45656+{
45657+ unsigned int i = oldvol;
45658
45659- while (i > newvol) {
45660- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45661- i--;
45662- }
45663- while (i < newvol) {
45664- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45665- i++;
45666- }
45667+ while (i > newvol) {
45668+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45669+ i--;
45670 }
45671+ while (i < newvol) {
45672+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45673+ i++;
45674+ }
45675+}
45676
45677- void issue_brightnesschange(const unsigned int oldbrt,
45678- const unsigned int newbrt)
45679- {
45680- unsigned int i = oldbrt;
45681+static void issue_brightnesschange(const unsigned int oldbrt,
45682+ const unsigned int newbrt,
45683+ const u32 event_mask)
45684+{
45685+ unsigned int i = oldbrt;
45686
45687- while (i > newbrt) {
45688- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45689- i--;
45690- }
45691- while (i < newbrt) {
45692- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45693- i++;
45694- }
45695+ while (i > newbrt) {
45696+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45697+ i--;
45698+ }
45699+ while (i < newbrt) {
45700+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45701+ i++;
45702 }
45703+}
45704
45705+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45706+ struct tp_nvram_state *newn,
45707+ const u32 event_mask)
45708+{
45709 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45710 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45711 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45712@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45713 oldn->volume_level != newn->volume_level) {
45714 /* recently muted, or repeated mute keypress, or
45715 * multiple presses ending in mute */
45716- issue_volchange(oldn->volume_level, newn->volume_level);
45717+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45718 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45719 }
45720 } else {
45721@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45722 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45723 }
45724 if (oldn->volume_level != newn->volume_level) {
45725- issue_volchange(oldn->volume_level, newn->volume_level);
45726+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45727 } else if (oldn->volume_toggle != newn->volume_toggle) {
45728 /* repeated vol up/down keypress at end of scale ? */
45729 if (newn->volume_level == 0)
45730@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45731 /* handle brightness */
45732 if (oldn->brightness_level != newn->brightness_level) {
45733 issue_brightnesschange(oldn->brightness_level,
45734- newn->brightness_level);
45735+ newn->brightness_level,
45736+ event_mask);
45737 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45738 /* repeated key presses that didn't change state */
45739 if (newn->brightness_level == 0)
45740@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45741 && !tp_features.bright_unkfw)
45742 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45743 }
45744+}
45745
45746 #undef TPACPI_COMPARE_KEY
45747 #undef TPACPI_MAY_SEND_KEY
45748-}
45749
45750 /*
45751 * Polling driver
45752diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45753index 769d265..a3a05ca 100644
45754--- a/drivers/pnp/pnpbios/bioscalls.c
45755+++ b/drivers/pnp/pnpbios/bioscalls.c
45756@@ -58,7 +58,7 @@ do { \
45757 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45758 } while(0)
45759
45760-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45761+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45762 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45763
45764 /*
45765@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45766
45767 cpu = get_cpu();
45768 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45769+
45770+ pax_open_kernel();
45771 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45772+ pax_close_kernel();
45773
45774 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45775 spin_lock_irqsave(&pnp_bios_lock, flags);
45776@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45777 :"memory");
45778 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45779
45780+ pax_open_kernel();
45781 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45782+ pax_close_kernel();
45783+
45784 put_cpu();
45785
45786 /* If we get here and this is set then the PnP BIOS faulted on us. */
45787@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45788 return status;
45789 }
45790
45791-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45792+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45793 {
45794 int i;
45795
45796@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45797 pnp_bios_callpoint.offset = header->fields.pm16offset;
45798 pnp_bios_callpoint.segment = PNP_CS16;
45799
45800+ pax_open_kernel();
45801+
45802 for_each_possible_cpu(i) {
45803 struct desc_struct *gdt = get_cpu_gdt_table(i);
45804 if (!gdt)
45805@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45806 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45807 (unsigned long)__va(header->fields.pm16dseg));
45808 }
45809+
45810+ pax_close_kernel();
45811 }
45812diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45813index d95e101..67f0c3f 100644
45814--- a/drivers/pnp/resource.c
45815+++ b/drivers/pnp/resource.c
45816@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45817 return 1;
45818
45819 /* check if the resource is valid */
45820- if (*irq < 0 || *irq > 15)
45821+ if (*irq > 15)
45822 return 0;
45823
45824 /* check if the resource is reserved */
45825@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45826 return 1;
45827
45828 /* check if the resource is valid */
45829- if (*dma < 0 || *dma == 4 || *dma > 7)
45830+ if (*dma == 4 || *dma > 7)
45831 return 0;
45832
45833 /* check if the resource is reserved */
45834diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45835index 0c52e2a..3421ab7 100644
45836--- a/drivers/power/pda_power.c
45837+++ b/drivers/power/pda_power.c
45838@@ -37,7 +37,11 @@ static int polling;
45839
45840 #if IS_ENABLED(CONFIG_USB_PHY)
45841 static struct usb_phy *transceiver;
45842-static struct notifier_block otg_nb;
45843+static int otg_handle_notification(struct notifier_block *nb,
45844+ unsigned long event, void *unused);
45845+static struct notifier_block otg_nb = {
45846+ .notifier_call = otg_handle_notification
45847+};
45848 #endif
45849
45850 static struct regulator *ac_draw;
45851@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45852
45853 #if IS_ENABLED(CONFIG_USB_PHY)
45854 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45855- otg_nb.notifier_call = otg_handle_notification;
45856 ret = usb_register_notifier(transceiver, &otg_nb);
45857 if (ret) {
45858 dev_err(dev, "failure to register otg notifier\n");
45859diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45860index cc439fd..8fa30df 100644
45861--- a/drivers/power/power_supply.h
45862+++ b/drivers/power/power_supply.h
45863@@ -16,12 +16,12 @@ struct power_supply;
45864
45865 #ifdef CONFIG_SYSFS
45866
45867-extern void power_supply_init_attrs(struct device_type *dev_type);
45868+extern void power_supply_init_attrs(void);
45869 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45870
45871 #else
45872
45873-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45874+static inline void power_supply_init_attrs(void) {}
45875 #define power_supply_uevent NULL
45876
45877 #endif /* CONFIG_SYSFS */
45878diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45879index 3b2d5df..3207114 100644
45880--- a/drivers/power/power_supply_core.c
45881+++ b/drivers/power/power_supply_core.c
45882@@ -24,7 +24,10 @@
45883 struct class *power_supply_class;
45884 EXPORT_SYMBOL_GPL(power_supply_class);
45885
45886-static struct device_type power_supply_dev_type;
45887+extern const struct attribute_group *power_supply_attr_groups[];
45888+static struct device_type power_supply_dev_type = {
45889+ .groups = power_supply_attr_groups,
45890+};
45891
45892 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45893 struct power_supply *supply)
45894@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
45895 return PTR_ERR(power_supply_class);
45896
45897 power_supply_class->dev_uevent = power_supply_uevent;
45898- power_supply_init_attrs(&power_supply_dev_type);
45899+ power_supply_init_attrs();
45900
45901 return 0;
45902 }
45903diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45904index 29178f7..c65f324 100644
45905--- a/drivers/power/power_supply_sysfs.c
45906+++ b/drivers/power/power_supply_sysfs.c
45907@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45908 .is_visible = power_supply_attr_is_visible,
45909 };
45910
45911-static const struct attribute_group *power_supply_attr_groups[] = {
45912+const struct attribute_group *power_supply_attr_groups[] = {
45913 &power_supply_attr_group,
45914 NULL,
45915 };
45916
45917-void power_supply_init_attrs(struct device_type *dev_type)
45918+void power_supply_init_attrs(void)
45919 {
45920 int i;
45921
45922- dev_type->groups = power_supply_attr_groups;
45923-
45924 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45925 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45926 }
45927diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45928index 288c75a..065bc84 100644
45929--- a/drivers/regulator/core.c
45930+++ b/drivers/regulator/core.c
45931@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45932 {
45933 const struct regulation_constraints *constraints = NULL;
45934 const struct regulator_init_data *init_data;
45935- static atomic_t regulator_no = ATOMIC_INIT(0);
45936+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45937 struct regulator_dev *rdev;
45938 struct device *dev;
45939 int ret, i;
45940@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45941 rdev->dev.of_node = config->of_node;
45942 rdev->dev.parent = dev;
45943 dev_set_name(&rdev->dev, "regulator.%d",
45944- atomic_inc_return(&regulator_no) - 1);
45945+ atomic_inc_return_unchecked(&regulator_no) - 1);
45946 ret = device_register(&rdev->dev);
45947 if (ret != 0) {
45948 put_device(&rdev->dev);
45949diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45950index d428ef9..fdc0357 100644
45951--- a/drivers/regulator/max8660.c
45952+++ b/drivers/regulator/max8660.c
45953@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
45954 max8660->shadow_regs[MAX8660_OVER1] = 5;
45955 } else {
45956 /* Otherwise devices can be toggled via software */
45957- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45958- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45959+ pax_open_kernel();
45960+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45961+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45962+ pax_close_kernel();
45963 }
45964
45965 /*
45966diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45967index 0c5195a..637a453d 100644
45968--- a/drivers/regulator/max8973-regulator.c
45969+++ b/drivers/regulator/max8973-regulator.c
45970@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45971 if (!pdata || !pdata->enable_ext_control) {
45972 max->desc.enable_reg = MAX8973_VOUT;
45973 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45974- max->ops.enable = regulator_enable_regmap;
45975- max->ops.disable = regulator_disable_regmap;
45976- max->ops.is_enabled = regulator_is_enabled_regmap;
45977+ pax_open_kernel();
45978+ *(void **)&max->ops.enable = regulator_enable_regmap;
45979+ *(void **)&max->ops.disable = regulator_disable_regmap;
45980+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
45981+ pax_close_kernel();
45982 }
45983
45984 if (pdata) {
45985diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
45986index 1037e07..e64dea1 100644
45987--- a/drivers/regulator/mc13892-regulator.c
45988+++ b/drivers/regulator/mc13892-regulator.c
45989@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
45990 }
45991 mc13xxx_unlock(mc13892);
45992
45993- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45994+ pax_open_kernel();
45995+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45996 = mc13892_vcam_set_mode;
45997- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45998+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45999 = mc13892_vcam_get_mode;
46000+ pax_close_kernel();
46001
46002 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46003 ARRAY_SIZE(mc13892_regulators));
46004diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46005index be06d71..264aee9 100644
46006--- a/drivers/rtc/rtc-cmos.c
46007+++ b/drivers/rtc/rtc-cmos.c
46008@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46009 hpet_rtc_timer_init();
46010
46011 /* export at least the first block of NVRAM */
46012- nvram.size = address_space - NVRAM_OFFSET;
46013+ pax_open_kernel();
46014+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46015+ pax_close_kernel();
46016 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46017 if (retval < 0) {
46018 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46019diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46020index d049393..bb20be0 100644
46021--- a/drivers/rtc/rtc-dev.c
46022+++ b/drivers/rtc/rtc-dev.c
46023@@ -16,6 +16,7 @@
46024 #include <linux/module.h>
46025 #include <linux/rtc.h>
46026 #include <linux/sched.h>
46027+#include <linux/grsecurity.h>
46028 #include "rtc-core.h"
46029
46030 static dev_t rtc_devt;
46031@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46032 if (copy_from_user(&tm, uarg, sizeof(tm)))
46033 return -EFAULT;
46034
46035+ gr_log_timechange();
46036+
46037 return rtc_set_time(rtc, &tm);
46038
46039 case RTC_PIE_ON:
46040diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46041index ca18fd1..055e42d 100644
46042--- a/drivers/rtc/rtc-ds1307.c
46043+++ b/drivers/rtc/rtc-ds1307.c
46044@@ -107,7 +107,7 @@ struct ds1307 {
46045 u8 offset; /* register's offset */
46046 u8 regs[11];
46047 u16 nvram_offset;
46048- struct bin_attribute *nvram;
46049+ bin_attribute_no_const *nvram;
46050 enum ds_type type;
46051 unsigned long flags;
46052 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46053diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46054index fcb0329..d77b7f2 100644
46055--- a/drivers/rtc/rtc-m48t59.c
46056+++ b/drivers/rtc/rtc-m48t59.c
46057@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46058 if (IS_ERR(m48t59->rtc))
46059 return PTR_ERR(m48t59->rtc);
46060
46061- m48t59_nvram_attr.size = pdata->offset;
46062+ pax_open_kernel();
46063+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46064+ pax_close_kernel();
46065
46066 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46067 if (ret)
46068diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46069index e693af6..2e525b6 100644
46070--- a/drivers/scsi/bfa/bfa_fcpim.h
46071+++ b/drivers/scsi/bfa/bfa_fcpim.h
46072@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46073
46074 struct bfa_itn_s {
46075 bfa_isr_func_t isr;
46076-};
46077+} __no_const;
46078
46079 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46080 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46081diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46082index 90814fe..4384138 100644
46083--- a/drivers/scsi/bfa/bfa_ioc.h
46084+++ b/drivers/scsi/bfa/bfa_ioc.h
46085@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46086 bfa_ioc_disable_cbfn_t disable_cbfn;
46087 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46088 bfa_ioc_reset_cbfn_t reset_cbfn;
46089-};
46090+} __no_const;
46091
46092 /*
46093 * IOC event notification mechanism.
46094@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46095 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46096 enum bfi_ioc_state fwstate);
46097 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46098-};
46099+} __no_const;
46100
46101 /*
46102 * Queue element to wait for room in request queue. FIFO order is
46103diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46104index c9382d6..6619864 100644
46105--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46106+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46107@@ -33,8 +33,8 @@
46108 */
46109 #include "libfcoe.h"
46110
46111-static atomic_t ctlr_num;
46112-static atomic_t fcf_num;
46113+static atomic_unchecked_t ctlr_num;
46114+static atomic_unchecked_t fcf_num;
46115
46116 /*
46117 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46118@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46119 if (!ctlr)
46120 goto out;
46121
46122- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46123+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46124 ctlr->f = f;
46125 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46126 INIT_LIST_HEAD(&ctlr->fcfs);
46127@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46128 fcf->dev.parent = &ctlr->dev;
46129 fcf->dev.bus = &fcoe_bus_type;
46130 fcf->dev.type = &fcoe_fcf_device_type;
46131- fcf->id = atomic_inc_return(&fcf_num) - 1;
46132+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46133 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46134
46135 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46136@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46137 {
46138 int error;
46139
46140- atomic_set(&ctlr_num, 0);
46141- atomic_set(&fcf_num, 0);
46142+ atomic_set_unchecked(&ctlr_num, 0);
46143+ atomic_set_unchecked(&fcf_num, 0);
46144
46145 error = bus_register(&fcoe_bus_type);
46146 if (error)
46147diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46148index df0c3c7..b00e1d0 100644
46149--- a/drivers/scsi/hosts.c
46150+++ b/drivers/scsi/hosts.c
46151@@ -42,7 +42,7 @@
46152 #include "scsi_logging.h"
46153
46154
46155-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46156+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46157
46158
46159 static void scsi_host_cls_release(struct device *dev)
46160@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46161 * subtract one because we increment first then return, but we need to
46162 * know what the next host number was before increment
46163 */
46164- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46165+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46166 shost->dma_channel = 0xff;
46167
46168 /* These three are default values which can be overridden */
46169diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46170index 7f4f790..b75b92a 100644
46171--- a/drivers/scsi/hpsa.c
46172+++ b/drivers/scsi/hpsa.c
46173@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46174 unsigned long flags;
46175
46176 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46177- return h->access.command_completed(h, q);
46178+ return h->access->command_completed(h, q);
46179
46180 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46181 a = rq->head[rq->current_entry];
46182@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46183 while (!list_empty(&h->reqQ)) {
46184 c = list_entry(h->reqQ.next, struct CommandList, list);
46185 /* can't do anything if fifo is full */
46186- if ((h->access.fifo_full(h))) {
46187+ if ((h->access->fifo_full(h))) {
46188 dev_warn(&h->pdev->dev, "fifo full\n");
46189 break;
46190 }
46191@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46192
46193 /* Tell the controller execute command */
46194 spin_unlock_irqrestore(&h->lock, flags);
46195- h->access.submit_command(h, c);
46196+ h->access->submit_command(h, c);
46197 spin_lock_irqsave(&h->lock, flags);
46198 }
46199 spin_unlock_irqrestore(&h->lock, flags);
46200@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46201
46202 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46203 {
46204- return h->access.command_completed(h, q);
46205+ return h->access->command_completed(h, q);
46206 }
46207
46208 static inline bool interrupt_pending(struct ctlr_info *h)
46209 {
46210- return h->access.intr_pending(h);
46211+ return h->access->intr_pending(h);
46212 }
46213
46214 static inline long interrupt_not_for_us(struct ctlr_info *h)
46215 {
46216- return (h->access.intr_pending(h) == 0) ||
46217+ return (h->access->intr_pending(h) == 0) ||
46218 (h->interrupts_enabled == 0);
46219 }
46220
46221@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46222 if (prod_index < 0)
46223 return -ENODEV;
46224 h->product_name = products[prod_index].product_name;
46225- h->access = *(products[prod_index].access);
46226+ h->access = products[prod_index].access;
46227
46228 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46229 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46230@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46231
46232 assert_spin_locked(&lockup_detector_lock);
46233 remove_ctlr_from_lockup_detector_list(h);
46234- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46235+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46236 spin_lock_irqsave(&h->lock, flags);
46237 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46238 spin_unlock_irqrestore(&h->lock, flags);
46239@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46240 }
46241
46242 /* make sure the board interrupts are off */
46243- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46244+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46245
46246 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46247 goto clean2;
46248@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46249 * fake ones to scoop up any residual completions.
46250 */
46251 spin_lock_irqsave(&h->lock, flags);
46252- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46253+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46254 spin_unlock_irqrestore(&h->lock, flags);
46255 free_irqs(h);
46256 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46257@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46258 dev_info(&h->pdev->dev, "Board READY.\n");
46259 dev_info(&h->pdev->dev,
46260 "Waiting for stale completions to drain.\n");
46261- h->access.set_intr_mask(h, HPSA_INTR_ON);
46262+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46263 msleep(10000);
46264- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46265+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46266
46267 rc = controller_reset_failed(h->cfgtable);
46268 if (rc)
46269@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46270 }
46271
46272 /* Turn the interrupts on so we can service requests */
46273- h->access.set_intr_mask(h, HPSA_INTR_ON);
46274+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46275
46276 hpsa_hba_inquiry(h);
46277 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46278@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46279 * To write all data in the battery backed cache to disks
46280 */
46281 hpsa_flush_cache(h);
46282- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46283+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46284 hpsa_free_irqs_and_disable_msix(h);
46285 }
46286
46287@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46288 return;
46289 }
46290 /* Change the access methods to the performant access methods */
46291- h->access = SA5_performant_access;
46292+ h->access = &SA5_performant_access;
46293 h->transMethod = CFGTBL_Trans_Performant;
46294 }
46295
46296diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46297index 9816479..c5d4e97 100644
46298--- a/drivers/scsi/hpsa.h
46299+++ b/drivers/scsi/hpsa.h
46300@@ -79,7 +79,7 @@ struct ctlr_info {
46301 unsigned int msix_vector;
46302 unsigned int msi_vector;
46303 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46304- struct access_method access;
46305+ struct access_method *access;
46306
46307 /* queue and queue Info */
46308 struct list_head reqQ;
46309diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46310index 5879929..32b241d 100644
46311--- a/drivers/scsi/libfc/fc_exch.c
46312+++ b/drivers/scsi/libfc/fc_exch.c
46313@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46314 u16 pool_max_index;
46315
46316 struct {
46317- atomic_t no_free_exch;
46318- atomic_t no_free_exch_xid;
46319- atomic_t xid_not_found;
46320- atomic_t xid_busy;
46321- atomic_t seq_not_found;
46322- atomic_t non_bls_resp;
46323+ atomic_unchecked_t no_free_exch;
46324+ atomic_unchecked_t no_free_exch_xid;
46325+ atomic_unchecked_t xid_not_found;
46326+ atomic_unchecked_t xid_busy;
46327+ atomic_unchecked_t seq_not_found;
46328+ atomic_unchecked_t non_bls_resp;
46329 } stats;
46330 };
46331
46332@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46333 /* allocate memory for exchange */
46334 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46335 if (!ep) {
46336- atomic_inc(&mp->stats.no_free_exch);
46337+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46338 goto out;
46339 }
46340 memset(ep, 0, sizeof(*ep));
46341@@ -797,7 +797,7 @@ out:
46342 return ep;
46343 err:
46344 spin_unlock_bh(&pool->lock);
46345- atomic_inc(&mp->stats.no_free_exch_xid);
46346+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46347 mempool_free(ep, mp->ep_pool);
46348 return NULL;
46349 }
46350@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46351 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46352 ep = fc_exch_find(mp, xid);
46353 if (!ep) {
46354- atomic_inc(&mp->stats.xid_not_found);
46355+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46356 reject = FC_RJT_OX_ID;
46357 goto out;
46358 }
46359@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46360 ep = fc_exch_find(mp, xid);
46361 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46362 if (ep) {
46363- atomic_inc(&mp->stats.xid_busy);
46364+ atomic_inc_unchecked(&mp->stats.xid_busy);
46365 reject = FC_RJT_RX_ID;
46366 goto rel;
46367 }
46368@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46369 }
46370 xid = ep->xid; /* get our XID */
46371 } else if (!ep) {
46372- atomic_inc(&mp->stats.xid_not_found);
46373+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46374 reject = FC_RJT_RX_ID; /* XID not found */
46375 goto out;
46376 }
46377@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46378 } else {
46379 sp = &ep->seq;
46380 if (sp->id != fh->fh_seq_id) {
46381- atomic_inc(&mp->stats.seq_not_found);
46382+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46383 if (f_ctl & FC_FC_END_SEQ) {
46384 /*
46385 * Update sequence_id based on incoming last
46386@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46387
46388 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46389 if (!ep) {
46390- atomic_inc(&mp->stats.xid_not_found);
46391+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46392 goto out;
46393 }
46394 if (ep->esb_stat & ESB_ST_COMPLETE) {
46395- atomic_inc(&mp->stats.xid_not_found);
46396+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46397 goto rel;
46398 }
46399 if (ep->rxid == FC_XID_UNKNOWN)
46400 ep->rxid = ntohs(fh->fh_rx_id);
46401 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46402- atomic_inc(&mp->stats.xid_not_found);
46403+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46404 goto rel;
46405 }
46406 if (ep->did != ntoh24(fh->fh_s_id) &&
46407 ep->did != FC_FID_FLOGI) {
46408- atomic_inc(&mp->stats.xid_not_found);
46409+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46410 goto rel;
46411 }
46412 sof = fr_sof(fp);
46413@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46414 sp->ssb_stat |= SSB_ST_RESP;
46415 sp->id = fh->fh_seq_id;
46416 } else if (sp->id != fh->fh_seq_id) {
46417- atomic_inc(&mp->stats.seq_not_found);
46418+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46419 goto rel;
46420 }
46421
46422@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46423 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46424
46425 if (!sp)
46426- atomic_inc(&mp->stats.xid_not_found);
46427+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46428 else
46429- atomic_inc(&mp->stats.non_bls_resp);
46430+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46431
46432 fc_frame_free(fp);
46433 }
46434@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46435
46436 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46437 mp = ema->mp;
46438- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46439+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46440 st->fc_no_free_exch_xid +=
46441- atomic_read(&mp->stats.no_free_exch_xid);
46442- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46443- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46444- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46445- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46446+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46447+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46448+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46449+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46450+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46451 }
46452 }
46453 EXPORT_SYMBOL(fc_exch_update_stats);
46454diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46455index 161c98e..6d563b3 100644
46456--- a/drivers/scsi/libsas/sas_ata.c
46457+++ b/drivers/scsi/libsas/sas_ata.c
46458@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46459 .postreset = ata_std_postreset,
46460 .error_handler = ata_std_error_handler,
46461 .post_internal_cmd = sas_ata_post_internal,
46462- .qc_defer = ata_std_qc_defer,
46463+ .qc_defer = ata_std_qc_defer,
46464 .qc_prep = ata_noop_qc_prep,
46465 .qc_issue = sas_ata_qc_issue,
46466 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46467diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46468index 93f222d..73e977b 100644
46469--- a/drivers/scsi/lpfc/lpfc.h
46470+++ b/drivers/scsi/lpfc/lpfc.h
46471@@ -431,7 +431,7 @@ struct lpfc_vport {
46472 struct dentry *debug_nodelist;
46473 struct dentry *vport_debugfs_root;
46474 struct lpfc_debugfs_trc *disc_trc;
46475- atomic_t disc_trc_cnt;
46476+ atomic_unchecked_t disc_trc_cnt;
46477 #endif
46478 uint8_t stat_data_enabled;
46479 uint8_t stat_data_blocked;
46480@@ -865,8 +865,8 @@ struct lpfc_hba {
46481 struct timer_list fabric_block_timer;
46482 unsigned long bit_flags;
46483 #define FABRIC_COMANDS_BLOCKED 0
46484- atomic_t num_rsrc_err;
46485- atomic_t num_cmd_success;
46486+ atomic_unchecked_t num_rsrc_err;
46487+ atomic_unchecked_t num_cmd_success;
46488 unsigned long last_rsrc_error_time;
46489 unsigned long last_ramp_down_time;
46490 unsigned long last_ramp_up_time;
46491@@ -902,7 +902,7 @@ struct lpfc_hba {
46492
46493 struct dentry *debug_slow_ring_trc;
46494 struct lpfc_debugfs_trc *slow_ring_trc;
46495- atomic_t slow_ring_trc_cnt;
46496+ atomic_unchecked_t slow_ring_trc_cnt;
46497 /* iDiag debugfs sub-directory */
46498 struct dentry *idiag_root;
46499 struct dentry *idiag_pci_cfg;
46500diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46501index 60084e6..0e2e700 100644
46502--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46503+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46504@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46505
46506 #include <linux/debugfs.h>
46507
46508-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46509+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46510 static unsigned long lpfc_debugfs_start_time = 0L;
46511
46512 /* iDiag */
46513@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46514 lpfc_debugfs_enable = 0;
46515
46516 len = 0;
46517- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46518+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46519 (lpfc_debugfs_max_disc_trc - 1);
46520 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46521 dtp = vport->disc_trc + i;
46522@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46523 lpfc_debugfs_enable = 0;
46524
46525 len = 0;
46526- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46527+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46528 (lpfc_debugfs_max_slow_ring_trc - 1);
46529 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46530 dtp = phba->slow_ring_trc + i;
46531@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46532 !vport || !vport->disc_trc)
46533 return;
46534
46535- index = atomic_inc_return(&vport->disc_trc_cnt) &
46536+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46537 (lpfc_debugfs_max_disc_trc - 1);
46538 dtp = vport->disc_trc + index;
46539 dtp->fmt = fmt;
46540 dtp->data1 = data1;
46541 dtp->data2 = data2;
46542 dtp->data3 = data3;
46543- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46544+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46545 dtp->jif = jiffies;
46546 #endif
46547 return;
46548@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46549 !phba || !phba->slow_ring_trc)
46550 return;
46551
46552- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46553+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46554 (lpfc_debugfs_max_slow_ring_trc - 1);
46555 dtp = phba->slow_ring_trc + index;
46556 dtp->fmt = fmt;
46557 dtp->data1 = data1;
46558 dtp->data2 = data2;
46559 dtp->data3 = data3;
46560- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46561+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46562 dtp->jif = jiffies;
46563 #endif
46564 return;
46565@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46566 "slow_ring buffer\n");
46567 goto debug_failed;
46568 }
46569- atomic_set(&phba->slow_ring_trc_cnt, 0);
46570+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46571 memset(phba->slow_ring_trc, 0,
46572 (sizeof(struct lpfc_debugfs_trc) *
46573 lpfc_debugfs_max_slow_ring_trc));
46574@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46575 "buffer\n");
46576 goto debug_failed;
46577 }
46578- atomic_set(&vport->disc_trc_cnt, 0);
46579+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46580
46581 snprintf(name, sizeof(name), "discovery_trace");
46582 vport->debug_disc_trc =
46583diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46584index e0b20fa..30c2c0d 100644
46585--- a/drivers/scsi/lpfc/lpfc_init.c
46586+++ b/drivers/scsi/lpfc/lpfc_init.c
46587@@ -10936,8 +10936,10 @@ lpfc_init(void)
46588 "misc_register returned with status %d", error);
46589
46590 if (lpfc_enable_npiv) {
46591- lpfc_transport_functions.vport_create = lpfc_vport_create;
46592- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46593+ pax_open_kernel();
46594+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46595+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46596+ pax_close_kernel();
46597 }
46598 lpfc_transport_template =
46599 fc_attach_transport(&lpfc_transport_functions);
46600diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46601index 243de1d..f40e3e5 100644
46602--- a/drivers/scsi/lpfc/lpfc_scsi.c
46603+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46604@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46605 uint32_t evt_posted;
46606
46607 spin_lock_irqsave(&phba->hbalock, flags);
46608- atomic_inc(&phba->num_rsrc_err);
46609+ atomic_inc_unchecked(&phba->num_rsrc_err);
46610 phba->last_rsrc_error_time = jiffies;
46611
46612 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46613@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46614 unsigned long flags;
46615 struct lpfc_hba *phba = vport->phba;
46616 uint32_t evt_posted;
46617- atomic_inc(&phba->num_cmd_success);
46618+ atomic_inc_unchecked(&phba->num_cmd_success);
46619
46620 if (vport->cfg_lun_queue_depth <= queue_depth)
46621 return;
46622@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46623 unsigned long num_rsrc_err, num_cmd_success;
46624 int i;
46625
46626- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46627- num_cmd_success = atomic_read(&phba->num_cmd_success);
46628+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46629+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46630
46631 /*
46632 * The error and success command counters are global per
46633@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46634 }
46635 }
46636 lpfc_destroy_vport_work_array(phba, vports);
46637- atomic_set(&phba->num_rsrc_err, 0);
46638- atomic_set(&phba->num_cmd_success, 0);
46639+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46640+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46641 }
46642
46643 /**
46644@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46645 }
46646 }
46647 lpfc_destroy_vport_work_array(phba, vports);
46648- atomic_set(&phba->num_rsrc_err, 0);
46649- atomic_set(&phba->num_cmd_success, 0);
46650+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46651+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46652 }
46653
46654 /**
46655diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46656index 1eb7b028..b2a6080 100644
46657--- a/drivers/scsi/pmcraid.c
46658+++ b/drivers/scsi/pmcraid.c
46659@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46660 res->scsi_dev = scsi_dev;
46661 scsi_dev->hostdata = res;
46662 res->change_detected = 0;
46663- atomic_set(&res->read_failures, 0);
46664- atomic_set(&res->write_failures, 0);
46665+ atomic_set_unchecked(&res->read_failures, 0);
46666+ atomic_set_unchecked(&res->write_failures, 0);
46667 rc = 0;
46668 }
46669 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46670@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46671
46672 /* If this was a SCSI read/write command keep count of errors */
46673 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46674- atomic_inc(&res->read_failures);
46675+ atomic_inc_unchecked(&res->read_failures);
46676 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46677- atomic_inc(&res->write_failures);
46678+ atomic_inc_unchecked(&res->write_failures);
46679
46680 if (!RES_IS_GSCSI(res->cfg_entry) &&
46681 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46682@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46683 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46684 * hrrq_id assigned here in queuecommand
46685 */
46686- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46687+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46688 pinstance->num_hrrq;
46689 cmd->cmd_done = pmcraid_io_done;
46690
46691@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46692 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46693 * hrrq_id assigned here in queuecommand
46694 */
46695- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46696+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46697 pinstance->num_hrrq;
46698
46699 if (request_size) {
46700@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46701
46702 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46703 /* add resources only after host is added into system */
46704- if (!atomic_read(&pinstance->expose_resources))
46705+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46706 return;
46707
46708 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46709@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46710 init_waitqueue_head(&pinstance->reset_wait_q);
46711
46712 atomic_set(&pinstance->outstanding_cmds, 0);
46713- atomic_set(&pinstance->last_message_id, 0);
46714- atomic_set(&pinstance->expose_resources, 0);
46715+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46716+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46717
46718 INIT_LIST_HEAD(&pinstance->free_res_q);
46719 INIT_LIST_HEAD(&pinstance->used_res_q);
46720@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46721 /* Schedule worker thread to handle CCN and take care of adding and
46722 * removing devices to OS
46723 */
46724- atomic_set(&pinstance->expose_resources, 1);
46725+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46726 schedule_work(&pinstance->worker_q);
46727 return rc;
46728
46729diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46730index e1d150f..6c6df44 100644
46731--- a/drivers/scsi/pmcraid.h
46732+++ b/drivers/scsi/pmcraid.h
46733@@ -748,7 +748,7 @@ struct pmcraid_instance {
46734 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46735
46736 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46737- atomic_t last_message_id;
46738+ atomic_unchecked_t last_message_id;
46739
46740 /* configuration table */
46741 struct pmcraid_config_table *cfg_table;
46742@@ -777,7 +777,7 @@ struct pmcraid_instance {
46743 atomic_t outstanding_cmds;
46744
46745 /* should add/delete resources to mid-layer now ?*/
46746- atomic_t expose_resources;
46747+ atomic_unchecked_t expose_resources;
46748
46749
46750
46751@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46752 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46753 };
46754 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46755- atomic_t read_failures; /* count of failed READ commands */
46756- atomic_t write_failures; /* count of failed WRITE commands */
46757+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46758+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46759
46760 /* To indicate add/delete/modify during CCN */
46761 u8 change_detected;
46762diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46763index d7a99ae..801df70 100644
46764--- a/drivers/scsi/qla2xxx/qla_attr.c
46765+++ b/drivers/scsi/qla2xxx/qla_attr.c
46766@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46767 return 0;
46768 }
46769
46770-struct fc_function_template qla2xxx_transport_functions = {
46771+fc_function_template_no_const qla2xxx_transport_functions = {
46772
46773 .show_host_node_name = 1,
46774 .show_host_port_name = 1,
46775@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46776 .bsg_timeout = qla24xx_bsg_timeout,
46777 };
46778
46779-struct fc_function_template qla2xxx_transport_vport_functions = {
46780+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46781
46782 .show_host_node_name = 1,
46783 .show_host_port_name = 1,
46784diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46785index 2d98232..a84298e 100644
46786--- a/drivers/scsi/qla2xxx/qla_gbl.h
46787+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46788@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46789 struct device_attribute;
46790 extern struct device_attribute *qla2x00_host_attrs[];
46791 struct fc_function_template;
46792-extern struct fc_function_template qla2xxx_transport_functions;
46793-extern struct fc_function_template qla2xxx_transport_vport_functions;
46794+extern fc_function_template_no_const qla2xxx_transport_functions;
46795+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46796 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46797 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46798 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46799diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46800index 3e21e9f..426ba79 100644
46801--- a/drivers/scsi/qla2xxx/qla_os.c
46802+++ b/drivers/scsi/qla2xxx/qla_os.c
46803@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46804 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46805 /* Ok, a 64bit DMA mask is applicable. */
46806 ha->flags.enable_64bit_addressing = 1;
46807- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46808- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46809+ pax_open_kernel();
46810+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46811+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46812+ pax_close_kernel();
46813 return;
46814 }
46815 }
46816diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46817index ddf16a8..80f4dd0 100644
46818--- a/drivers/scsi/qla4xxx/ql4_def.h
46819+++ b/drivers/scsi/qla4xxx/ql4_def.h
46820@@ -291,7 +291,7 @@ struct ddb_entry {
46821 * (4000 only) */
46822 atomic_t relogin_timer; /* Max Time to wait for
46823 * relogin to complete */
46824- atomic_t relogin_retry_count; /* Num of times relogin has been
46825+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46826 * retried */
46827 uint32_t default_time2wait; /* Default Min time between
46828 * relogins (+aens) */
46829diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46830index b246b3c..897004d 100644
46831--- a/drivers/scsi/qla4xxx/ql4_os.c
46832+++ b/drivers/scsi/qla4xxx/ql4_os.c
46833@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46834 */
46835 if (!iscsi_is_session_online(cls_sess)) {
46836 /* Reset retry relogin timer */
46837- atomic_inc(&ddb_entry->relogin_retry_count);
46838+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46839 DEBUG2(ql4_printk(KERN_INFO, ha,
46840 "%s: index[%d] relogin timed out-retrying"
46841 " relogin (%d), retry (%d)\n", __func__,
46842 ddb_entry->fw_ddb_index,
46843- atomic_read(&ddb_entry->relogin_retry_count),
46844+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46845 ddb_entry->default_time2wait + 4));
46846 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46847 atomic_set(&ddb_entry->retry_relogin_timer,
46848@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46849
46850 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46851 atomic_set(&ddb_entry->relogin_timer, 0);
46852- atomic_set(&ddb_entry->relogin_retry_count, 0);
46853+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46854 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46855 ddb_entry->default_relogin_timeout =
46856 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46857diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46858index eaa808e..95f8841 100644
46859--- a/drivers/scsi/scsi.c
46860+++ b/drivers/scsi/scsi.c
46861@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46862 unsigned long timeout;
46863 int rtn = 0;
46864
46865- atomic_inc(&cmd->device->iorequest_cnt);
46866+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46867
46868 /* check if the device is still usable */
46869 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46870diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46871index 124392f..75eb43e 100644
46872--- a/drivers/scsi/scsi_lib.c
46873+++ b/drivers/scsi/scsi_lib.c
46874@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46875 shost = sdev->host;
46876 scsi_init_cmd_errh(cmd);
46877 cmd->result = DID_NO_CONNECT << 16;
46878- atomic_inc(&cmd->device->iorequest_cnt);
46879+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46880
46881 /*
46882 * SCSI request completion path will do scsi_device_unbusy(),
46883@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46884
46885 INIT_LIST_HEAD(&cmd->eh_entry);
46886
46887- atomic_inc(&cmd->device->iodone_cnt);
46888+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46889 if (cmd->result)
46890- atomic_inc(&cmd->device->ioerr_cnt);
46891+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46892
46893 disposition = scsi_decide_disposition(cmd);
46894 if (disposition != SUCCESS &&
46895diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46896index 7e50061..71db7a6 100644
46897--- a/drivers/scsi/scsi_sysfs.c
46898+++ b/drivers/scsi/scsi_sysfs.c
46899@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46900 char *buf) \
46901 { \
46902 struct scsi_device *sdev = to_scsi_device(dev); \
46903- unsigned long long count = atomic_read(&sdev->field); \
46904+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46905 return snprintf(buf, 20, "0x%llx\n", count); \
46906 } \
46907 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46908diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46909index 84a1fdf..693b0d6 100644
46910--- a/drivers/scsi/scsi_tgt_lib.c
46911+++ b/drivers/scsi/scsi_tgt_lib.c
46912@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46913 int err;
46914
46915 dprintk("%lx %u\n", uaddr, len);
46916- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46917+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46918 if (err) {
46919 /*
46920 * TODO: need to fixup sg_tablesize, max_segment_size,
46921diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46922index 4628fd5..a94a1c2 100644
46923--- a/drivers/scsi/scsi_transport_fc.c
46924+++ b/drivers/scsi/scsi_transport_fc.c
46925@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46926 * Netlink Infrastructure
46927 */
46928
46929-static atomic_t fc_event_seq;
46930+static atomic_unchecked_t fc_event_seq;
46931
46932 /**
46933 * fc_get_event_number - Obtain the next sequential FC event number
46934@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46935 u32
46936 fc_get_event_number(void)
46937 {
46938- return atomic_add_return(1, &fc_event_seq);
46939+ return atomic_add_return_unchecked(1, &fc_event_seq);
46940 }
46941 EXPORT_SYMBOL(fc_get_event_number);
46942
46943@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46944 {
46945 int error;
46946
46947- atomic_set(&fc_event_seq, 0);
46948+ atomic_set_unchecked(&fc_event_seq, 0);
46949
46950 error = transport_class_register(&fc_host_class);
46951 if (error)
46952@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46953 char *cp;
46954
46955 *val = simple_strtoul(buf, &cp, 0);
46956- if ((*cp && (*cp != '\n')) || (*val < 0))
46957+ if (*cp && (*cp != '\n'))
46958 return -EINVAL;
46959 /*
46960 * Check for overflow; dev_loss_tmo is u32
46961diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46962index abf7c40..c3240ed 100644
46963--- a/drivers/scsi/scsi_transport_iscsi.c
46964+++ b/drivers/scsi/scsi_transport_iscsi.c
46965@@ -80,7 +80,7 @@ struct iscsi_internal {
46966 struct transport_container session_cont;
46967 };
46968
46969-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46970+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46971 static struct workqueue_struct *iscsi_eh_timer_workq;
46972
46973 static DEFINE_IDA(iscsi_sess_ida);
46974@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46975 int err;
46976
46977 ihost = shost->shost_data;
46978- session->sid = atomic_add_return(1, &iscsi_session_nr);
46979+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
46980
46981 if (target_id == ISCSI_MAX_TARGET) {
46982 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
46983@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
46984 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
46985 ISCSI_TRANSPORT_VERSION);
46986
46987- atomic_set(&iscsi_session_nr, 0);
46988+ atomic_set_unchecked(&iscsi_session_nr, 0);
46989
46990 err = class_register(&iscsi_transport_class);
46991 if (err)
46992diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
46993index f379c7f..e8fc69c 100644
46994--- a/drivers/scsi/scsi_transport_srp.c
46995+++ b/drivers/scsi/scsi_transport_srp.c
46996@@ -33,7 +33,7 @@
46997 #include "scsi_transport_srp_internal.h"
46998
46999 struct srp_host_attrs {
47000- atomic_t next_port_id;
47001+ atomic_unchecked_t next_port_id;
47002 };
47003 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47004
47005@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47006 struct Scsi_Host *shost = dev_to_shost(dev);
47007 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47008
47009- atomic_set(&srp_host->next_port_id, 0);
47010+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47011 return 0;
47012 }
47013
47014@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47015 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47016 rport->roles = ids->roles;
47017
47018- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47019+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47020 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47021
47022 transport_setup_device(&rport->dev);
47023diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47024index 2783dd7..d20395b 100644
47025--- a/drivers/scsi/sd.c
47026+++ b/drivers/scsi/sd.c
47027@@ -2933,7 +2933,7 @@ static int sd_probe(struct device *dev)
47028 sdkp->disk = gd;
47029 sdkp->index = index;
47030 atomic_set(&sdkp->openers, 0);
47031- atomic_set(&sdkp->device->ioerr_cnt, 0);
47032+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47033
47034 if (!sdp->request_queue->rq_timeout) {
47035 if (sdp->type != TYPE_MOD)
47036diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47037index df5e961..df6b97f 100644
47038--- a/drivers/scsi/sg.c
47039+++ b/drivers/scsi/sg.c
47040@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47041 sdp->disk->disk_name,
47042 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47043 NULL,
47044- (char *)arg);
47045+ (char __user *)arg);
47046 case BLKTRACESTART:
47047 return blk_trace_startstop(sdp->device->request_queue, 1);
47048 case BLKTRACESTOP:
47049diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47050index 978dda2..cb19aa0 100644
47051--- a/drivers/spi/spi.c
47052+++ b/drivers/spi/spi.c
47053@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47054 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47055
47056 /* portable code must never pass more than 32 bytes */
47057-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47058+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47059
47060 static u8 *buf;
47061
47062diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47063index ee3a57f..18368c1 100644
47064--- a/drivers/staging/android/timed_output.c
47065+++ b/drivers/staging/android/timed_output.c
47066@@ -25,7 +25,7 @@
47067 #include "timed_output.h"
47068
47069 static struct class *timed_output_class;
47070-static atomic_t device_count;
47071+static atomic_unchecked_t device_count;
47072
47073 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47074 char *buf)
47075@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47076 timed_output_class = class_create(THIS_MODULE, "timed_output");
47077 if (IS_ERR(timed_output_class))
47078 return PTR_ERR(timed_output_class);
47079- atomic_set(&device_count, 0);
47080+ atomic_set_unchecked(&device_count, 0);
47081 }
47082
47083 return 0;
47084@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47085 if (ret < 0)
47086 return ret;
47087
47088- tdev->index = atomic_inc_return(&device_count);
47089+ tdev->index = atomic_inc_return_unchecked(&device_count);
47090 tdev->dev = device_create(timed_output_class, NULL,
47091 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47092 if (IS_ERR(tdev->dev))
47093diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47094index 3675020..e80d92c 100644
47095--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47096+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47097@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47098
47099 static int solo_sysfs_init(struct solo_dev *solo_dev)
47100 {
47101- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47102+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47103 struct device *dev = &solo_dev->dev;
47104 const char *driver;
47105 int i;
47106diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47107index 3335941..2b26186 100644
47108--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47109+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47110@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47111
47112 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47113 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47114- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47115+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47116 if (p2m_id < 0)
47117 p2m_id = -p2m_id;
47118 }
47119diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47120index 6f91d2e..3f011d2 100644
47121--- a/drivers/staging/media/solo6x10/solo6x10.h
47122+++ b/drivers/staging/media/solo6x10/solo6x10.h
47123@@ -238,7 +238,7 @@ struct solo_dev {
47124
47125 /* P2M DMA Engine */
47126 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47127- atomic_t p2m_count;
47128+ atomic_unchecked_t p2m_count;
47129 int p2m_jiffies;
47130 unsigned int p2m_timeouts;
47131
47132diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47133index 34afc16..ffe44dd 100644
47134--- a/drivers/staging/octeon/ethernet-rx.c
47135+++ b/drivers/staging/octeon/ethernet-rx.c
47136@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47137 /* Increment RX stats for virtual ports */
47138 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47139 #ifdef CONFIG_64BIT
47140- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47141- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47142+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47143+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47144 #else
47145- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47146- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47147+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47148+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47149 #endif
47150 }
47151 netif_receive_skb(skb);
47152@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47153 dev->name);
47154 */
47155 #ifdef CONFIG_64BIT
47156- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47157+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47158 #else
47159- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47160+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47161 #endif
47162 dev_kfree_skb_irq(skb);
47163 }
47164diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47165index c3a90e7..023619a 100644
47166--- a/drivers/staging/octeon/ethernet.c
47167+++ b/drivers/staging/octeon/ethernet.c
47168@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47169 * since the RX tasklet also increments it.
47170 */
47171 #ifdef CONFIG_64BIT
47172- atomic64_add(rx_status.dropped_packets,
47173- (atomic64_t *)&priv->stats.rx_dropped);
47174+ atomic64_add_unchecked(rx_status.dropped_packets,
47175+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47176 #else
47177- atomic_add(rx_status.dropped_packets,
47178- (atomic_t *)&priv->stats.rx_dropped);
47179+ atomic_add_unchecked(rx_status.dropped_packets,
47180+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47181 #endif
47182 }
47183
47184diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47185index dc23395..cf7e9b1 100644
47186--- a/drivers/staging/rtl8712/rtl871x_io.h
47187+++ b/drivers/staging/rtl8712/rtl871x_io.h
47188@@ -108,7 +108,7 @@ struct _io_ops {
47189 u8 *pmem);
47190 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47191 u8 *pmem);
47192-};
47193+} __no_const;
47194
47195 struct io_req {
47196 struct list_head list;
47197diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47198index 1f5088b..0e59820 100644
47199--- a/drivers/staging/sbe-2t3e3/netdev.c
47200+++ b/drivers/staging/sbe-2t3e3/netdev.c
47201@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47202 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47203
47204 if (rlen)
47205- if (copy_to_user(data, &resp, rlen))
47206+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47207 return -EFAULT;
47208
47209 return 0;
47210diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47211index a863a98..d272795 100644
47212--- a/drivers/staging/usbip/vhci.h
47213+++ b/drivers/staging/usbip/vhci.h
47214@@ -83,7 +83,7 @@ struct vhci_hcd {
47215 unsigned resuming:1;
47216 unsigned long re_timeout;
47217
47218- atomic_t seqnum;
47219+ atomic_unchecked_t seqnum;
47220
47221 /*
47222 * NOTE:
47223diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47224index d7974cb..d78076b 100644
47225--- a/drivers/staging/usbip/vhci_hcd.c
47226+++ b/drivers/staging/usbip/vhci_hcd.c
47227@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47228
47229 spin_lock(&vdev->priv_lock);
47230
47231- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47232+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47233 if (priv->seqnum == 0xffff)
47234 dev_info(&urb->dev->dev, "seqnum max\n");
47235
47236@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47237 return -ENOMEM;
47238 }
47239
47240- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47241+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47242 if (unlink->seqnum == 0xffff)
47243 pr_info("seqnum max\n");
47244
47245@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47246 vdev->rhport = rhport;
47247 }
47248
47249- atomic_set(&vhci->seqnum, 0);
47250+ atomic_set_unchecked(&vhci->seqnum, 0);
47251 spin_lock_init(&vhci->lock);
47252
47253 hcd->power_budget = 0; /* no limit */
47254diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47255index d07fcb5..358e1e1 100644
47256--- a/drivers/staging/usbip/vhci_rx.c
47257+++ b/drivers/staging/usbip/vhci_rx.c
47258@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47259 if (!urb) {
47260 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47261 pr_info("max seqnum %d\n",
47262- atomic_read(&the_controller->seqnum));
47263+ atomic_read_unchecked(&the_controller->seqnum));
47264 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47265 return;
47266 }
47267diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47268index 57a08c5..5b4bb7c 100644
47269--- a/drivers/staging/vt6655/hostap.c
47270+++ b/drivers/staging/vt6655/hostap.c
47271@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47272 *
47273 */
47274
47275+static net_device_ops_no_const apdev_netdev_ops;
47276+
47277 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47278 {
47279 PSDevice apdev_priv;
47280 struct net_device *dev = pDevice->dev;
47281 int ret;
47282- const struct net_device_ops apdev_netdev_ops = {
47283- .ndo_start_xmit = pDevice->tx_80211,
47284- };
47285
47286 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47287
47288@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47289 *apdev_priv = *pDevice;
47290 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47291
47292+ /* only half broken now */
47293+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47294 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47295
47296 pDevice->apdev->type = ARPHRD_IEEE80211;
47297diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47298index c699a30..b90a5fd 100644
47299--- a/drivers/staging/vt6656/hostap.c
47300+++ b/drivers/staging/vt6656/hostap.c
47301@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47302 *
47303 */
47304
47305+static net_device_ops_no_const apdev_netdev_ops;
47306+
47307 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47308 {
47309 struct vnt_private *apdev_priv;
47310 struct net_device *dev = pDevice->dev;
47311 int ret;
47312- const struct net_device_ops apdev_netdev_ops = {
47313- .ndo_start_xmit = pDevice->tx_80211,
47314- };
47315
47316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47317
47318@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47319 *apdev_priv = *pDevice;
47320 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47321
47322+ /* only half broken now */
47323+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47324 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47325
47326 pDevice->apdev->type = ARPHRD_IEEE80211;
47327diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47328index d128ce2..fc1f9a1 100644
47329--- a/drivers/staging/zcache/tmem.h
47330+++ b/drivers/staging/zcache/tmem.h
47331@@ -225,7 +225,7 @@ struct tmem_pamops {
47332 bool (*is_remote)(void *);
47333 int (*replace_in_obj)(void *, struct tmem_obj *);
47334 #endif
47335-};
47336+} __no_const;
47337 extern void tmem_register_pamops(struct tmem_pamops *m);
47338
47339 /* memory allocation methods provided by the host implementation */
47340@@ -234,7 +234,7 @@ struct tmem_hostops {
47341 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47342 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47343 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47344-};
47345+} __no_const;
47346 extern void tmem_register_hostops(struct tmem_hostops *m);
47347
47348 /* core tmem accessor functions */
47349diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47350index e51b09a..5ebac31 100644
47351--- a/drivers/target/sbp/sbp_target.c
47352+++ b/drivers/target/sbp/sbp_target.c
47353@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47354
47355 #define SESSION_MAINTENANCE_INTERVAL HZ
47356
47357-static atomic_t login_id = ATOMIC_INIT(0);
47358+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47359
47360 static void session_maintenance_work(struct work_struct *);
47361 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47362@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47363 login->lun = se_lun;
47364 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47365 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47366- login->login_id = atomic_inc_return(&login_id);
47367+ login->login_id = atomic_inc_return_unchecked(&login_id);
47368
47369 login->tgt_agt = sbp_target_agent_register(login);
47370 if (IS_ERR(login->tgt_agt)) {
47371diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47372index 8f4142f..b127f7d 100644
47373--- a/drivers/target/target_core_device.c
47374+++ b/drivers/target/target_core_device.c
47375@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47376 spin_lock_init(&dev->se_port_lock);
47377 spin_lock_init(&dev->se_tmr_lock);
47378 spin_lock_init(&dev->qf_cmd_lock);
47379- atomic_set(&dev->dev_ordered_id, 0);
47380+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47381 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47382 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47383 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47384diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47385index d8e49d7..6fcfdec 100644
47386--- a/drivers/target/target_core_transport.c
47387+++ b/drivers/target/target_core_transport.c
47388@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47389 * Used to determine when ORDERED commands should go from
47390 * Dormant to Active status.
47391 */
47392- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47393+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47394 smp_mb__after_atomic_inc();
47395 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47396 cmd->se_ordered_id, cmd->sam_task_attr,
47397diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47398index 33f83fe..d80f8e1 100644
47399--- a/drivers/tty/cyclades.c
47400+++ b/drivers/tty/cyclades.c
47401@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47402 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47403 info->port.count);
47404 #endif
47405- info->port.count++;
47406+ atomic_inc(&info->port.count);
47407 #ifdef CY_DEBUG_COUNT
47408 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47409- current->pid, info->port.count);
47410+ current->pid, atomic_read(&info->port.count));
47411 #endif
47412
47413 /*
47414@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47415 for (j = 0; j < cy_card[i].nports; j++) {
47416 info = &cy_card[i].ports[j];
47417
47418- if (info->port.count) {
47419+ if (atomic_read(&info->port.count)) {
47420 /* XXX is the ldisc num worth this? */
47421 struct tty_struct *tty;
47422 struct tty_ldisc *ld;
47423diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47424index eb255e8..f637a57 100644
47425--- a/drivers/tty/hvc/hvc_console.c
47426+++ b/drivers/tty/hvc/hvc_console.c
47427@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47428
47429 spin_lock_irqsave(&hp->port.lock, flags);
47430 /* Check and then increment for fast path open. */
47431- if (hp->port.count++ > 0) {
47432+ if (atomic_inc_return(&hp->port.count) > 1) {
47433 spin_unlock_irqrestore(&hp->port.lock, flags);
47434 hvc_kick();
47435 return 0;
47436@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47437
47438 spin_lock_irqsave(&hp->port.lock, flags);
47439
47440- if (--hp->port.count == 0) {
47441+ if (atomic_dec_return(&hp->port.count) == 0) {
47442 spin_unlock_irqrestore(&hp->port.lock, flags);
47443 /* We are done with the tty pointer now. */
47444 tty_port_tty_set(&hp->port, NULL);
47445@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47446 */
47447 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47448 } else {
47449- if (hp->port.count < 0)
47450+ if (atomic_read(&hp->port.count) < 0)
47451 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47452- hp->vtermno, hp->port.count);
47453+ hp->vtermno, atomic_read(&hp->port.count));
47454 spin_unlock_irqrestore(&hp->port.lock, flags);
47455 }
47456 }
47457@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47458 * open->hangup case this can be called after the final close so prevent
47459 * that from happening for now.
47460 */
47461- if (hp->port.count <= 0) {
47462+ if (atomic_read(&hp->port.count) <= 0) {
47463 spin_unlock_irqrestore(&hp->port.lock, flags);
47464 return;
47465 }
47466
47467- hp->port.count = 0;
47468+ atomic_set(&hp->port.count, 0);
47469 spin_unlock_irqrestore(&hp->port.lock, flags);
47470 tty_port_tty_set(&hp->port, NULL);
47471
47472@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47473 return -EPIPE;
47474
47475 /* FIXME what's this (unprotected) check for? */
47476- if (hp->port.count <= 0)
47477+ if (atomic_read(&hp->port.count) <= 0)
47478 return -EIO;
47479
47480 spin_lock_irqsave(&hp->lock, flags);
47481diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47482index 81e939e..95ead10 100644
47483--- a/drivers/tty/hvc/hvcs.c
47484+++ b/drivers/tty/hvc/hvcs.c
47485@@ -83,6 +83,7 @@
47486 #include <asm/hvcserver.h>
47487 #include <asm/uaccess.h>
47488 #include <asm/vio.h>
47489+#include <asm/local.h>
47490
47491 /*
47492 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47493@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47494
47495 spin_lock_irqsave(&hvcsd->lock, flags);
47496
47497- if (hvcsd->port.count > 0) {
47498+ if (atomic_read(&hvcsd->port.count) > 0) {
47499 spin_unlock_irqrestore(&hvcsd->lock, flags);
47500 printk(KERN_INFO "HVCS: vterm state unchanged. "
47501 "The hvcs device node is still in use.\n");
47502@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47503 }
47504 }
47505
47506- hvcsd->port.count = 0;
47507+ atomic_set(&hvcsd->port.count, 0);
47508 hvcsd->port.tty = tty;
47509 tty->driver_data = hvcsd;
47510
47511@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47512 unsigned long flags;
47513
47514 spin_lock_irqsave(&hvcsd->lock, flags);
47515- hvcsd->port.count++;
47516+ atomic_inc(&hvcsd->port.count);
47517 hvcsd->todo_mask |= HVCS_SCHED_READ;
47518 spin_unlock_irqrestore(&hvcsd->lock, flags);
47519
47520@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47521 hvcsd = tty->driver_data;
47522
47523 spin_lock_irqsave(&hvcsd->lock, flags);
47524- if (--hvcsd->port.count == 0) {
47525+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47526
47527 vio_disable_interrupts(hvcsd->vdev);
47528
47529@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47530
47531 free_irq(irq, hvcsd);
47532 return;
47533- } else if (hvcsd->port.count < 0) {
47534+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47535 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47536 " is missmanaged.\n",
47537- hvcsd->vdev->unit_address, hvcsd->port.count);
47538+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47539 }
47540
47541 spin_unlock_irqrestore(&hvcsd->lock, flags);
47542@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47543
47544 spin_lock_irqsave(&hvcsd->lock, flags);
47545 /* Preserve this so that we know how many kref refs to put */
47546- temp_open_count = hvcsd->port.count;
47547+ temp_open_count = atomic_read(&hvcsd->port.count);
47548
47549 /*
47550 * Don't kref put inside the spinlock because the destruction
47551@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47552 tty->driver_data = NULL;
47553 hvcsd->port.tty = NULL;
47554
47555- hvcsd->port.count = 0;
47556+ atomic_set(&hvcsd->port.count, 0);
47557
47558 /* This will drop any buffered data on the floor which is OK in a hangup
47559 * scenario. */
47560@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47561 * the middle of a write operation? This is a crummy place to do this
47562 * but we want to keep it all in the spinlock.
47563 */
47564- if (hvcsd->port.count <= 0) {
47565+ if (atomic_read(&hvcsd->port.count) <= 0) {
47566 spin_unlock_irqrestore(&hvcsd->lock, flags);
47567 return -ENODEV;
47568 }
47569@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47570 {
47571 struct hvcs_struct *hvcsd = tty->driver_data;
47572
47573- if (!hvcsd || hvcsd->port.count <= 0)
47574+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47575 return 0;
47576
47577 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47578diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47579index 4190199..48f2920 100644
47580--- a/drivers/tty/hvc/hvsi.c
47581+++ b/drivers/tty/hvc/hvsi.c
47582@@ -85,7 +85,7 @@ struct hvsi_struct {
47583 int n_outbuf;
47584 uint32_t vtermno;
47585 uint32_t virq;
47586- atomic_t seqno; /* HVSI packet sequence number */
47587+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47588 uint16_t mctrl;
47589 uint8_t state; /* HVSI protocol state */
47590 uint8_t flags;
47591@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47592
47593 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47594 packet.hdr.len = sizeof(struct hvsi_query_response);
47595- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47596+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47597 packet.verb = VSV_SEND_VERSION_NUMBER;
47598 packet.u.version = HVSI_VERSION;
47599 packet.query_seqno = query_seqno+1;
47600@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47601
47602 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47603 packet.hdr.len = sizeof(struct hvsi_query);
47604- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47605+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47606 packet.verb = verb;
47607
47608 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47609@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47610 int wrote;
47611
47612 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47613- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47614+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47615 packet.hdr.len = sizeof(struct hvsi_control);
47616 packet.verb = VSV_SET_MODEM_CTL;
47617 packet.mask = HVSI_TSDTR;
47618@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47619 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47620
47621 packet.hdr.type = VS_DATA_PACKET_HEADER;
47622- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47623+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47624 packet.hdr.len = count + sizeof(struct hvsi_header);
47625 memcpy(&packet.data, buf, count);
47626
47627@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47628 struct hvsi_control packet __ALIGNED__;
47629
47630 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47631- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47632+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47633 packet.hdr.len = 6;
47634 packet.verb = VSV_CLOSE_PROTOCOL;
47635
47636diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47637index ac27671..0f627ee 100644
47638--- a/drivers/tty/hvc/hvsi_lib.c
47639+++ b/drivers/tty/hvc/hvsi_lib.c
47640@@ -9,7 +9,7 @@
47641
47642 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47643 {
47644- packet->seqno = atomic_inc_return(&pv->seqno);
47645+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47646
47647 /* Assumes that always succeeds, works in practice */
47648 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47649@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47650
47651 /* Reset state */
47652 pv->established = 0;
47653- atomic_set(&pv->seqno, 0);
47654+ atomic_set_unchecked(&pv->seqno, 0);
47655
47656 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47657
47658@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47659 pv->mctrl_update = 0;
47660 q.hdr.type = VS_QUERY_PACKET_HEADER;
47661 q.hdr.len = sizeof(struct hvsi_query);
47662- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47663+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47664 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47665 rc = hvsi_send_packet(pv, &q.hdr);
47666 if (rc <= 0) {
47667diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47668index 8fd72ff..34a0bed 100644
47669--- a/drivers/tty/ipwireless/tty.c
47670+++ b/drivers/tty/ipwireless/tty.c
47671@@ -29,6 +29,7 @@
47672 #include <linux/tty_driver.h>
47673 #include <linux/tty_flip.h>
47674 #include <linux/uaccess.h>
47675+#include <asm/local.h>
47676
47677 #include "tty.h"
47678 #include "network.h"
47679@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47680 mutex_unlock(&tty->ipw_tty_mutex);
47681 return -ENODEV;
47682 }
47683- if (tty->port.count == 0)
47684+ if (atomic_read(&tty->port.count) == 0)
47685 tty->tx_bytes_queued = 0;
47686
47687- tty->port.count++;
47688+ atomic_inc(&tty->port.count);
47689
47690 tty->port.tty = linux_tty;
47691 linux_tty->driver_data = tty;
47692@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47693
47694 static void do_ipw_close(struct ipw_tty *tty)
47695 {
47696- tty->port.count--;
47697-
47698- if (tty->port.count == 0) {
47699+ if (atomic_dec_return(&tty->port.count) == 0) {
47700 struct tty_struct *linux_tty = tty->port.tty;
47701
47702 if (linux_tty != NULL) {
47703@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47704 return;
47705
47706 mutex_lock(&tty->ipw_tty_mutex);
47707- if (tty->port.count == 0) {
47708+ if (atomic_read(&tty->port.count) == 0) {
47709 mutex_unlock(&tty->ipw_tty_mutex);
47710 return;
47711 }
47712@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47713
47714 mutex_lock(&tty->ipw_tty_mutex);
47715
47716- if (!tty->port.count) {
47717+ if (!atomic_read(&tty->port.count)) {
47718 mutex_unlock(&tty->ipw_tty_mutex);
47719 return;
47720 }
47721@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47722 return -ENODEV;
47723
47724 mutex_lock(&tty->ipw_tty_mutex);
47725- if (!tty->port.count) {
47726+ if (!atomic_read(&tty->port.count)) {
47727 mutex_unlock(&tty->ipw_tty_mutex);
47728 return -EINVAL;
47729 }
47730@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47731 if (!tty)
47732 return -ENODEV;
47733
47734- if (!tty->port.count)
47735+ if (!atomic_read(&tty->port.count))
47736 return -EINVAL;
47737
47738 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47739@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47740 if (!tty)
47741 return 0;
47742
47743- if (!tty->port.count)
47744+ if (!atomic_read(&tty->port.count))
47745 return 0;
47746
47747 return tty->tx_bytes_queued;
47748@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47749 if (!tty)
47750 return -ENODEV;
47751
47752- if (!tty->port.count)
47753+ if (!atomic_read(&tty->port.count))
47754 return -EINVAL;
47755
47756 return get_control_lines(tty);
47757@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47758 if (!tty)
47759 return -ENODEV;
47760
47761- if (!tty->port.count)
47762+ if (!atomic_read(&tty->port.count))
47763 return -EINVAL;
47764
47765 return set_control_lines(tty, set, clear);
47766@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47767 if (!tty)
47768 return -ENODEV;
47769
47770- if (!tty->port.count)
47771+ if (!atomic_read(&tty->port.count))
47772 return -EINVAL;
47773
47774 /* FIXME: Exactly how is the tty object locked here .. */
47775@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47776 * are gone */
47777 mutex_lock(&ttyj->ipw_tty_mutex);
47778 }
47779- while (ttyj->port.count)
47780+ while (atomic_read(&ttyj->port.count))
47781 do_ipw_close(ttyj);
47782 ipwireless_disassociate_network_ttys(network,
47783 ttyj->channel_idx);
47784diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47785index 1deaca4..c8582d4 100644
47786--- a/drivers/tty/moxa.c
47787+++ b/drivers/tty/moxa.c
47788@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47789 }
47790
47791 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47792- ch->port.count++;
47793+ atomic_inc(&ch->port.count);
47794 tty->driver_data = ch;
47795 tty_port_tty_set(&ch->port, tty);
47796 mutex_lock(&ch->port.mutex);
47797diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47798index 6422390..49003ac8 100644
47799--- a/drivers/tty/n_gsm.c
47800+++ b/drivers/tty/n_gsm.c
47801@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47802 spin_lock_init(&dlci->lock);
47803 mutex_init(&dlci->mutex);
47804 dlci->fifo = &dlci->_fifo;
47805- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47806+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47807 kfree(dlci);
47808 return NULL;
47809 }
47810@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47811 struct gsm_dlci *dlci = tty->driver_data;
47812 struct tty_port *port = &dlci->port;
47813
47814- port->count++;
47815+ atomic_inc(&port->count);
47816 dlci_get(dlci);
47817 dlci_get(dlci->gsm->dlci[0]);
47818 mux_get(dlci->gsm);
47819diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47820index 4bf0fc0..433bd58 100644
47821--- a/drivers/tty/n_tty.c
47822+++ b/drivers/tty/n_tty.c
47823@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47824 {
47825 *ops = tty_ldisc_N_TTY;
47826 ops->owner = NULL;
47827- ops->refcount = ops->flags = 0;
47828+ atomic_set(&ops->refcount, 0);
47829+ ops->flags = 0;
47830 }
47831 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47832diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47833index abfd990..5ab5da9 100644
47834--- a/drivers/tty/pty.c
47835+++ b/drivers/tty/pty.c
47836@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
47837 panic("Couldn't register Unix98 pts driver");
47838
47839 /* Now create the /dev/ptmx special device */
47840+ pax_open_kernel();
47841 tty_default_fops(&ptmx_fops);
47842- ptmx_fops.open = ptmx_open;
47843+ *(void **)&ptmx_fops.open = ptmx_open;
47844+ pax_close_kernel();
47845
47846 cdev_init(&ptmx_cdev, &ptmx_fops);
47847 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47848diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47849index 354564e..fe50d9a 100644
47850--- a/drivers/tty/rocket.c
47851+++ b/drivers/tty/rocket.c
47852@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47853 tty->driver_data = info;
47854 tty_port_tty_set(port, tty);
47855
47856- if (port->count++ == 0) {
47857+ if (atomic_inc_return(&port->count) == 1) {
47858 atomic_inc(&rp_num_ports_open);
47859
47860 #ifdef ROCKET_DEBUG_OPEN
47861@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47862 #endif
47863 }
47864 #ifdef ROCKET_DEBUG_OPEN
47865- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47866+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47867 #endif
47868
47869 /*
47870@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47871 spin_unlock_irqrestore(&info->port.lock, flags);
47872 return;
47873 }
47874- if (info->port.count)
47875+ if (atomic_read(&info->port.count))
47876 atomic_dec(&rp_num_ports_open);
47877 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47878 spin_unlock_irqrestore(&info->port.lock, flags);
47879diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47880index e2520ab..034e20b 100644
47881--- a/drivers/tty/serial/ioc4_serial.c
47882+++ b/drivers/tty/serial/ioc4_serial.c
47883@@ -437,7 +437,7 @@ struct ioc4_soft {
47884 } is_intr_info[MAX_IOC4_INTR_ENTS];
47885
47886 /* Number of entries active in the above array */
47887- atomic_t is_num_intrs;
47888+ atomic_unchecked_t is_num_intrs;
47889 } is_intr_type[IOC4_NUM_INTR_TYPES];
47890
47891 /* is_ir_lock must be held while
47892@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47893 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47894 || (type == IOC4_OTHER_INTR_TYPE)));
47895
47896- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47897+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47898 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47899
47900 /* Save off the lower level interrupt handler */
47901@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47902
47903 soft = arg;
47904 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47905- num_intrs = (int)atomic_read(
47906+ num_intrs = (int)atomic_read_unchecked(
47907 &soft->is_intr_type[intr_type].is_num_intrs);
47908
47909 this_mir = this_ir = pending_intrs(soft, intr_type);
47910diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47911index 1002054..dd644a8 100644
47912--- a/drivers/tty/serial/kgdboc.c
47913+++ b/drivers/tty/serial/kgdboc.c
47914@@ -24,8 +24,9 @@
47915 #define MAX_CONFIG_LEN 40
47916
47917 static struct kgdb_io kgdboc_io_ops;
47918+static struct kgdb_io kgdboc_io_ops_console;
47919
47920-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47921+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47922 static int configured = -1;
47923
47924 static char config[MAX_CONFIG_LEN];
47925@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47926 kgdboc_unregister_kbd();
47927 if (configured == 1)
47928 kgdb_unregister_io_module(&kgdboc_io_ops);
47929+ else if (configured == 2)
47930+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47931 }
47932
47933 static int configure_kgdboc(void)
47934@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47935 int err;
47936 char *cptr = config;
47937 struct console *cons;
47938+ int is_console = 0;
47939
47940 err = kgdboc_option_setup(config);
47941 if (err || !strlen(config) || isspace(config[0]))
47942 goto noconfig;
47943
47944 err = -ENODEV;
47945- kgdboc_io_ops.is_console = 0;
47946 kgdb_tty_driver = NULL;
47947
47948 kgdboc_use_kms = 0;
47949@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47950 int idx;
47951 if (cons->device && cons->device(cons, &idx) == p &&
47952 idx == tty_line) {
47953- kgdboc_io_ops.is_console = 1;
47954+ is_console = 1;
47955 break;
47956 }
47957 cons = cons->next;
47958@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47959 kgdb_tty_line = tty_line;
47960
47961 do_register:
47962- err = kgdb_register_io_module(&kgdboc_io_ops);
47963+ if (is_console) {
47964+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47965+ configured = 2;
47966+ } else {
47967+ err = kgdb_register_io_module(&kgdboc_io_ops);
47968+ configured = 1;
47969+ }
47970 if (err)
47971 goto noconfig;
47972
47973@@ -205,8 +214,6 @@ do_register:
47974 if (err)
47975 goto nmi_con_failed;
47976
47977- configured = 1;
47978-
47979 return 0;
47980
47981 nmi_con_failed:
47982@@ -223,7 +230,7 @@ noconfig:
47983 static int __init init_kgdboc(void)
47984 {
47985 /* Already configured? */
47986- if (configured == 1)
47987+ if (configured >= 1)
47988 return 0;
47989
47990 return configure_kgdboc();
47991@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
47992 if (config[len - 1] == '\n')
47993 config[len - 1] = '\0';
47994
47995- if (configured == 1)
47996+ if (configured >= 1)
47997 cleanup_kgdboc();
47998
47999 /* Go and configure with the new params. */
48000@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48001 .post_exception = kgdboc_post_exp_handler,
48002 };
48003
48004+static struct kgdb_io kgdboc_io_ops_console = {
48005+ .name = "kgdboc",
48006+ .read_char = kgdboc_get_char,
48007+ .write_char = kgdboc_put_char,
48008+ .pre_exception = kgdboc_pre_exp_handler,
48009+ .post_exception = kgdboc_post_exp_handler,
48010+ .is_console = 1
48011+};
48012+
48013 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48014 /* This is only available if kgdboc is a built in for early debugging */
48015 static int __init kgdboc_early_init(char *opt)
48016diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48017index 2c6cfb3..048274e 100644
48018--- a/drivers/tty/serial/msm_serial.c
48019+++ b/drivers/tty/serial/msm_serial.c
48020@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48021 .cons = MSM_CONSOLE,
48022 };
48023
48024-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48025+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48026
48027 static int __init msm_serial_probe(struct platform_device *pdev)
48028 {
48029@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48030 int irq;
48031
48032 if (pdev->id == -1)
48033- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48034+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48035
48036 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48037 return -ENXIO;
48038diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48039index 376079b..d8de7aa 100644
48040--- a/drivers/tty/serial/samsung.c
48041+++ b/drivers/tty/serial/samsung.c
48042@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48043 }
48044 }
48045
48046+static int s3c64xx_serial_startup(struct uart_port *port);
48047 static int s3c24xx_serial_startup(struct uart_port *port)
48048 {
48049 struct s3c24xx_uart_port *ourport = to_ourport(port);
48050 int ret;
48051
48052+ /* Startup sequence is different for s3c64xx and higher SoC's */
48053+ if (s3c24xx_serial_has_interrupt_mask(port))
48054+ return s3c64xx_serial_startup(port);
48055+
48056 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48057 port->mapbase, port->membase);
48058
48059@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48060 /* setup info for port */
48061 port->dev = &platdev->dev;
48062
48063- /* Startup sequence is different for s3c64xx and higher SoC's */
48064- if (s3c24xx_serial_has_interrupt_mask(port))
48065- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48066-
48067 port->uartclk = 1;
48068
48069 if (cfg->uart_flags & UPF_CONS_FLOW) {
48070diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48071index 28cdd28..56f1d60 100644
48072--- a/drivers/tty/serial/serial_core.c
48073+++ b/drivers/tty/serial/serial_core.c
48074@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48075 uart_flush_buffer(tty);
48076 uart_shutdown(tty, state);
48077 spin_lock_irqsave(&port->lock, flags);
48078- port->count = 0;
48079+ atomic_set(&port->count, 0);
48080 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48081 spin_unlock_irqrestore(&port->lock, flags);
48082 tty_port_tty_set(port, NULL);
48083@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48084 goto end;
48085 }
48086
48087- port->count++;
48088+ atomic_inc(&port->count);
48089 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48090 retval = -ENXIO;
48091 goto err_dec_count;
48092@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48093 /*
48094 * Make sure the device is in D0 state.
48095 */
48096- if (port->count == 1)
48097+ if (atomic_read(&port->count) == 1)
48098 uart_change_pm(state, UART_PM_STATE_ON);
48099
48100 /*
48101@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48102 end:
48103 return retval;
48104 err_dec_count:
48105- port->count--;
48106+ atomic_inc(&port->count);
48107 mutex_unlock(&port->mutex);
48108 goto end;
48109 }
48110diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48111index 8eaf1ab..85c030d 100644
48112--- a/drivers/tty/synclink.c
48113+++ b/drivers/tty/synclink.c
48114@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48115
48116 if (debug_level >= DEBUG_LEVEL_INFO)
48117 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48118- __FILE__,__LINE__, info->device_name, info->port.count);
48119+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48120
48121 if (tty_port_close_start(&info->port, tty, filp) == 0)
48122 goto cleanup;
48123@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48124 cleanup:
48125 if (debug_level >= DEBUG_LEVEL_INFO)
48126 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48127- tty->driver->name, info->port.count);
48128+ tty->driver->name, atomic_read(&info->port.count));
48129
48130 } /* end of mgsl_close() */
48131
48132@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48133
48134 mgsl_flush_buffer(tty);
48135 shutdown(info);
48136-
48137- info->port.count = 0;
48138+
48139+ atomic_set(&info->port.count, 0);
48140 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48141 info->port.tty = NULL;
48142
48143@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48144
48145 if (debug_level >= DEBUG_LEVEL_INFO)
48146 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48147- __FILE__,__LINE__, tty->driver->name, port->count );
48148+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48149
48150 spin_lock_irqsave(&info->irq_spinlock, flags);
48151 if (!tty_hung_up_p(filp)) {
48152 extra_count = true;
48153- port->count--;
48154+ atomic_dec(&port->count);
48155 }
48156 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48157 port->blocked_open++;
48158@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48159
48160 if (debug_level >= DEBUG_LEVEL_INFO)
48161 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48162- __FILE__,__LINE__, tty->driver->name, port->count );
48163+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48164
48165 tty_unlock(tty);
48166 schedule();
48167@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48168
48169 /* FIXME: Racy on hangup during close wait */
48170 if (extra_count)
48171- port->count++;
48172+ atomic_inc(&port->count);
48173 port->blocked_open--;
48174
48175 if (debug_level >= DEBUG_LEVEL_INFO)
48176 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48177- __FILE__,__LINE__, tty->driver->name, port->count );
48178+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48179
48180 if (!retval)
48181 port->flags |= ASYNC_NORMAL_ACTIVE;
48182@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48183
48184 if (debug_level >= DEBUG_LEVEL_INFO)
48185 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48186- __FILE__,__LINE__,tty->driver->name, info->port.count);
48187+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48188
48189 /* If port is closing, signal caller to try again */
48190 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48191@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48192 spin_unlock_irqrestore(&info->netlock, flags);
48193 goto cleanup;
48194 }
48195- info->port.count++;
48196+ atomic_inc(&info->port.count);
48197 spin_unlock_irqrestore(&info->netlock, flags);
48198
48199- if (info->port.count == 1) {
48200+ if (atomic_read(&info->port.count) == 1) {
48201 /* 1st open on this device, init hardware */
48202 retval = startup(info);
48203 if (retval < 0)
48204@@ -3446,8 +3446,8 @@ cleanup:
48205 if (retval) {
48206 if (tty->count == 1)
48207 info->port.tty = NULL; /* tty layer will release tty struct */
48208- if(info->port.count)
48209- info->port.count--;
48210+ if (atomic_read(&info->port.count))
48211+ atomic_dec(&info->port.count);
48212 }
48213
48214 return retval;
48215@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48216 unsigned short new_crctype;
48217
48218 /* return error if TTY interface open */
48219- if (info->port.count)
48220+ if (atomic_read(&info->port.count))
48221 return -EBUSY;
48222
48223 switch (encoding)
48224@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48225
48226 /* arbitrate between network and tty opens */
48227 spin_lock_irqsave(&info->netlock, flags);
48228- if (info->port.count != 0 || info->netcount != 0) {
48229+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48230 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48231 spin_unlock_irqrestore(&info->netlock, flags);
48232 return -EBUSY;
48233@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48234 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48235
48236 /* return error if TTY interface open */
48237- if (info->port.count)
48238+ if (atomic_read(&info->port.count))
48239 return -EBUSY;
48240
48241 if (cmd != SIOCWANDEV)
48242diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48243index 1abf946..1ee34fc 100644
48244--- a/drivers/tty/synclink_gt.c
48245+++ b/drivers/tty/synclink_gt.c
48246@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48247 tty->driver_data = info;
48248 info->port.tty = tty;
48249
48250- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48251+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48252
48253 /* If port is closing, signal caller to try again */
48254 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48255@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48256 mutex_unlock(&info->port.mutex);
48257 goto cleanup;
48258 }
48259- info->port.count++;
48260+ atomic_inc(&info->port.count);
48261 spin_unlock_irqrestore(&info->netlock, flags);
48262
48263- if (info->port.count == 1) {
48264+ if (atomic_read(&info->port.count) == 1) {
48265 /* 1st open on this device, init hardware */
48266 retval = startup(info);
48267 if (retval < 0) {
48268@@ -715,8 +715,8 @@ cleanup:
48269 if (retval) {
48270 if (tty->count == 1)
48271 info->port.tty = NULL; /* tty layer will release tty struct */
48272- if(info->port.count)
48273- info->port.count--;
48274+ if(atomic_read(&info->port.count))
48275+ atomic_dec(&info->port.count);
48276 }
48277
48278 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48279@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48280
48281 if (sanity_check(info, tty->name, "close"))
48282 return;
48283- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48284+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48285
48286 if (tty_port_close_start(&info->port, tty, filp) == 0)
48287 goto cleanup;
48288@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48289 tty_port_close_end(&info->port, tty);
48290 info->port.tty = NULL;
48291 cleanup:
48292- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48293+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48294 }
48295
48296 static void hangup(struct tty_struct *tty)
48297@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48298 shutdown(info);
48299
48300 spin_lock_irqsave(&info->port.lock, flags);
48301- info->port.count = 0;
48302+ atomic_set(&info->port.count, 0);
48303 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48304 info->port.tty = NULL;
48305 spin_unlock_irqrestore(&info->port.lock, flags);
48306@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48307 unsigned short new_crctype;
48308
48309 /* return error if TTY interface open */
48310- if (info->port.count)
48311+ if (atomic_read(&info->port.count))
48312 return -EBUSY;
48313
48314 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48315@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48316
48317 /* arbitrate between network and tty opens */
48318 spin_lock_irqsave(&info->netlock, flags);
48319- if (info->port.count != 0 || info->netcount != 0) {
48320+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48321 DBGINFO(("%s hdlc_open busy\n", dev->name));
48322 spin_unlock_irqrestore(&info->netlock, flags);
48323 return -EBUSY;
48324@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48325 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48326
48327 /* return error if TTY interface open */
48328- if (info->port.count)
48329+ if (atomic_read(&info->port.count))
48330 return -EBUSY;
48331
48332 if (cmd != SIOCWANDEV)
48333@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48334 if (port == NULL)
48335 continue;
48336 spin_lock(&port->lock);
48337- if ((port->port.count || port->netcount) &&
48338+ if ((atomic_read(&port->port.count) || port->netcount) &&
48339 port->pending_bh && !port->bh_running &&
48340 !port->bh_requested) {
48341 DBGISR(("%s bh queued\n", port->device_name));
48342@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48343 spin_lock_irqsave(&info->lock, flags);
48344 if (!tty_hung_up_p(filp)) {
48345 extra_count = true;
48346- port->count--;
48347+ atomic_dec(&port->count);
48348 }
48349 spin_unlock_irqrestore(&info->lock, flags);
48350 port->blocked_open++;
48351@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48352 remove_wait_queue(&port->open_wait, &wait);
48353
48354 if (extra_count)
48355- port->count++;
48356+ atomic_inc(&port->count);
48357 port->blocked_open--;
48358
48359 if (!retval)
48360diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48361index dc6e969..5dc8786 100644
48362--- a/drivers/tty/synclinkmp.c
48363+++ b/drivers/tty/synclinkmp.c
48364@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48365
48366 if (debug_level >= DEBUG_LEVEL_INFO)
48367 printk("%s(%d):%s open(), old ref count = %d\n",
48368- __FILE__,__LINE__,tty->driver->name, info->port.count);
48369+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48370
48371 /* If port is closing, signal caller to try again */
48372 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48373@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48374 spin_unlock_irqrestore(&info->netlock, flags);
48375 goto cleanup;
48376 }
48377- info->port.count++;
48378+ atomic_inc(&info->port.count);
48379 spin_unlock_irqrestore(&info->netlock, flags);
48380
48381- if (info->port.count == 1) {
48382+ if (atomic_read(&info->port.count) == 1) {
48383 /* 1st open on this device, init hardware */
48384 retval = startup(info);
48385 if (retval < 0)
48386@@ -796,8 +796,8 @@ cleanup:
48387 if (retval) {
48388 if (tty->count == 1)
48389 info->port.tty = NULL; /* tty layer will release tty struct */
48390- if(info->port.count)
48391- info->port.count--;
48392+ if(atomic_read(&info->port.count))
48393+ atomic_dec(&info->port.count);
48394 }
48395
48396 return retval;
48397@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48398
48399 if (debug_level >= DEBUG_LEVEL_INFO)
48400 printk("%s(%d):%s close() entry, count=%d\n",
48401- __FILE__,__LINE__, info->device_name, info->port.count);
48402+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48403
48404 if (tty_port_close_start(&info->port, tty, filp) == 0)
48405 goto cleanup;
48406@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48407 cleanup:
48408 if (debug_level >= DEBUG_LEVEL_INFO)
48409 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48410- tty->driver->name, info->port.count);
48411+ tty->driver->name, atomic_read(&info->port.count));
48412 }
48413
48414 /* Called by tty_hangup() when a hangup is signaled.
48415@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48416 shutdown(info);
48417
48418 spin_lock_irqsave(&info->port.lock, flags);
48419- info->port.count = 0;
48420+ atomic_set(&info->port.count, 0);
48421 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48422 info->port.tty = NULL;
48423 spin_unlock_irqrestore(&info->port.lock, flags);
48424@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48425 unsigned short new_crctype;
48426
48427 /* return error if TTY interface open */
48428- if (info->port.count)
48429+ if (atomic_read(&info->port.count))
48430 return -EBUSY;
48431
48432 switch (encoding)
48433@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48434
48435 /* arbitrate between network and tty opens */
48436 spin_lock_irqsave(&info->netlock, flags);
48437- if (info->port.count != 0 || info->netcount != 0) {
48438+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48439 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48440 spin_unlock_irqrestore(&info->netlock, flags);
48441 return -EBUSY;
48442@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48443 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48444
48445 /* return error if TTY interface open */
48446- if (info->port.count)
48447+ if (atomic_read(&info->port.count))
48448 return -EBUSY;
48449
48450 if (cmd != SIOCWANDEV)
48451@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48452 * do not request bottom half processing if the
48453 * device is not open in a normal mode.
48454 */
48455- if ( port && (port->port.count || port->netcount) &&
48456+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48457 port->pending_bh && !port->bh_running &&
48458 !port->bh_requested ) {
48459 if ( debug_level >= DEBUG_LEVEL_ISR )
48460@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48461
48462 if (debug_level >= DEBUG_LEVEL_INFO)
48463 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48464- __FILE__,__LINE__, tty->driver->name, port->count );
48465+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48466
48467 spin_lock_irqsave(&info->lock, flags);
48468 if (!tty_hung_up_p(filp)) {
48469 extra_count = true;
48470- port->count--;
48471+ atomic_dec(&port->count);
48472 }
48473 spin_unlock_irqrestore(&info->lock, flags);
48474 port->blocked_open++;
48475@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48476
48477 if (debug_level >= DEBUG_LEVEL_INFO)
48478 printk("%s(%d):%s block_til_ready() count=%d\n",
48479- __FILE__,__LINE__, tty->driver->name, port->count );
48480+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48481
48482 tty_unlock(tty);
48483 schedule();
48484@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48485 remove_wait_queue(&port->open_wait, &wait);
48486
48487 if (extra_count)
48488- port->count++;
48489+ atomic_inc(&port->count);
48490 port->blocked_open--;
48491
48492 if (debug_level >= DEBUG_LEVEL_INFO)
48493 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48494- __FILE__,__LINE__, tty->driver->name, port->count );
48495+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48496
48497 if (!retval)
48498 port->flags |= ASYNC_NORMAL_ACTIVE;
48499diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48500index d5cc3ac..3263411 100644
48501--- a/drivers/tty/sysrq.c
48502+++ b/drivers/tty/sysrq.c
48503@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48504 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48505 size_t count, loff_t *ppos)
48506 {
48507- if (count) {
48508+ if (count && capable(CAP_SYS_ADMIN)) {
48509 char c;
48510
48511 if (get_user(c, buf))
48512diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48513index 20689b9..7fd3a31 100644
48514--- a/drivers/tty/tty_io.c
48515+++ b/drivers/tty/tty_io.c
48516@@ -3468,7 +3468,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48517
48518 void tty_default_fops(struct file_operations *fops)
48519 {
48520- *fops = tty_fops;
48521+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48522 }
48523
48524 /*
48525diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48526index 1afe192..73d2c20 100644
48527--- a/drivers/tty/tty_ldisc.c
48528+++ b/drivers/tty/tty_ldisc.c
48529@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48530 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48531 tty_ldiscs[disc] = new_ldisc;
48532 new_ldisc->num = disc;
48533- new_ldisc->refcount = 0;
48534+ atomic_set(&new_ldisc->refcount, 0);
48535 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48536
48537 return ret;
48538@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48539 return -EINVAL;
48540
48541 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48542- if (tty_ldiscs[disc]->refcount)
48543+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48544 ret = -EBUSY;
48545 else
48546 tty_ldiscs[disc] = NULL;
48547@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48548 if (ldops) {
48549 ret = ERR_PTR(-EAGAIN);
48550 if (try_module_get(ldops->owner)) {
48551- ldops->refcount++;
48552+ atomic_inc(&ldops->refcount);
48553 ret = ldops;
48554 }
48555 }
48556@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48557 unsigned long flags;
48558
48559 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48560- ldops->refcount--;
48561+ atomic_dec(&ldops->refcount);
48562 module_put(ldops->owner);
48563 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48564 }
48565@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48566 /* unreleased reader reference(s) will cause this WARN */
48567 WARN_ON(!atomic_dec_and_test(&ld->users));
48568
48569- ld->ops->refcount--;
48570+ atomic_dec(&ld->ops->refcount);
48571 module_put(ld->ops->owner);
48572 kfree(ld);
48573 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48574diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48575index f597e88..b7f68ed 100644
48576--- a/drivers/tty/tty_port.c
48577+++ b/drivers/tty/tty_port.c
48578@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48579 unsigned long flags;
48580
48581 spin_lock_irqsave(&port->lock, flags);
48582- port->count = 0;
48583+ atomic_set(&port->count, 0);
48584 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48585 tty = port->tty;
48586 if (tty)
48587@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48588 /* The port lock protects the port counts */
48589 spin_lock_irqsave(&port->lock, flags);
48590 if (!tty_hung_up_p(filp))
48591- port->count--;
48592+ atomic_dec(&port->count);
48593 port->blocked_open++;
48594 spin_unlock_irqrestore(&port->lock, flags);
48595
48596@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48597 we must not mess that up further */
48598 spin_lock_irqsave(&port->lock, flags);
48599 if (!tty_hung_up_p(filp))
48600- port->count++;
48601+ atomic_inc(&port->count);
48602 port->blocked_open--;
48603 if (retval == 0)
48604 port->flags |= ASYNC_NORMAL_ACTIVE;
48605@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48606 return 0;
48607 }
48608
48609- if (tty->count == 1 && port->count != 1) {
48610+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48611 printk(KERN_WARNING
48612 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48613- port->count);
48614- port->count = 1;
48615+ atomic_read(&port->count));
48616+ atomic_set(&port->count, 1);
48617 }
48618- if (--port->count < 0) {
48619+ if (atomic_dec_return(&port->count) < 0) {
48620 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48621- port->count);
48622- port->count = 0;
48623+ atomic_read(&port->count));
48624+ atomic_set(&port->count, 0);
48625 }
48626
48627- if (port->count) {
48628+ if (atomic_read(&port->count)) {
48629 spin_unlock_irqrestore(&port->lock, flags);
48630 if (port->ops->drop)
48631 port->ops->drop(port);
48632@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48633 {
48634 spin_lock_irq(&port->lock);
48635 if (!tty_hung_up_p(filp))
48636- ++port->count;
48637+ atomic_inc(&port->count);
48638 spin_unlock_irq(&port->lock);
48639 tty_port_tty_set(port, tty);
48640
48641diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48642index a9af1b9a..1e08e7f 100644
48643--- a/drivers/tty/vt/keyboard.c
48644+++ b/drivers/tty/vt/keyboard.c
48645@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48646 kbd->kbdmode == VC_OFF) &&
48647 value != KVAL(K_SAK))
48648 return; /* SAK is allowed even in raw mode */
48649+
48650+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48651+ {
48652+ void *func = fn_handler[value];
48653+ if (func == fn_show_state || func == fn_show_ptregs ||
48654+ func == fn_show_mem)
48655+ return;
48656+ }
48657+#endif
48658+
48659 fn_handler[value](vc);
48660 }
48661
48662@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48663 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48664 return -EFAULT;
48665
48666- if (!capable(CAP_SYS_TTY_CONFIG))
48667- perm = 0;
48668-
48669 switch (cmd) {
48670 case KDGKBENT:
48671 /* Ensure another thread doesn't free it under us */
48672@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48673 spin_unlock_irqrestore(&kbd_event_lock, flags);
48674 return put_user(val, &user_kbe->kb_value);
48675 case KDSKBENT:
48676+ if (!capable(CAP_SYS_TTY_CONFIG))
48677+ perm = 0;
48678+
48679 if (!perm)
48680 return -EPERM;
48681 if (!i && v == K_NOSUCHMAP) {
48682@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48683 int i, j, k;
48684 int ret;
48685
48686- if (!capable(CAP_SYS_TTY_CONFIG))
48687- perm = 0;
48688-
48689 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48690 if (!kbs) {
48691 ret = -ENOMEM;
48692@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48693 kfree(kbs);
48694 return ((p && *p) ? -EOVERFLOW : 0);
48695 case KDSKBSENT:
48696+ if (!capable(CAP_SYS_TTY_CONFIG))
48697+ perm = 0;
48698+
48699 if (!perm) {
48700 ret = -EPERM;
48701 goto reterr;
48702diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48703index 3b96f18..026a9bf 100644
48704--- a/drivers/uio/uio.c
48705+++ b/drivers/uio/uio.c
48706@@ -25,6 +25,7 @@
48707 #include <linux/kobject.h>
48708 #include <linux/cdev.h>
48709 #include <linux/uio_driver.h>
48710+#include <asm/local.h>
48711
48712 #define UIO_MAX_DEVICES (1U << MINORBITS)
48713
48714@@ -32,10 +33,10 @@ struct uio_device {
48715 struct module *owner;
48716 struct device *dev;
48717 int minor;
48718- atomic_t event;
48719+ atomic_unchecked_t event;
48720 struct fasync_struct *async_queue;
48721 wait_queue_head_t wait;
48722- int vma_count;
48723+ local_t vma_count;
48724 struct uio_info *info;
48725 struct kobject *map_dir;
48726 struct kobject *portio_dir;
48727@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48728 struct device_attribute *attr, char *buf)
48729 {
48730 struct uio_device *idev = dev_get_drvdata(dev);
48731- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48732+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48733 }
48734
48735 static struct device_attribute uio_class_attributes[] = {
48736@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48737 {
48738 struct uio_device *idev = info->uio_dev;
48739
48740- atomic_inc(&idev->event);
48741+ atomic_inc_unchecked(&idev->event);
48742 wake_up_interruptible(&idev->wait);
48743 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48744 }
48745@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48746 }
48747
48748 listener->dev = idev;
48749- listener->event_count = atomic_read(&idev->event);
48750+ listener->event_count = atomic_read_unchecked(&idev->event);
48751 filep->private_data = listener;
48752
48753 if (idev->info->open) {
48754@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48755 return -EIO;
48756
48757 poll_wait(filep, &idev->wait, wait);
48758- if (listener->event_count != atomic_read(&idev->event))
48759+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48760 return POLLIN | POLLRDNORM;
48761 return 0;
48762 }
48763@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48764 do {
48765 set_current_state(TASK_INTERRUPTIBLE);
48766
48767- event_count = atomic_read(&idev->event);
48768+ event_count = atomic_read_unchecked(&idev->event);
48769 if (event_count != listener->event_count) {
48770 if (copy_to_user(buf, &event_count, count))
48771 retval = -EFAULT;
48772@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48773 static void uio_vma_open(struct vm_area_struct *vma)
48774 {
48775 struct uio_device *idev = vma->vm_private_data;
48776- idev->vma_count++;
48777+ local_inc(&idev->vma_count);
48778 }
48779
48780 static void uio_vma_close(struct vm_area_struct *vma)
48781 {
48782 struct uio_device *idev = vma->vm_private_data;
48783- idev->vma_count--;
48784+ local_dec(&idev->vma_count);
48785 }
48786
48787 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48788@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
48789 idev->owner = owner;
48790 idev->info = info;
48791 init_waitqueue_head(&idev->wait);
48792- atomic_set(&idev->event, 0);
48793+ atomic_set_unchecked(&idev->event, 0);
48794
48795 ret = uio_get_minor(idev);
48796 if (ret)
48797diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48798index 8a7eb77..c00402f 100644
48799--- a/drivers/usb/atm/cxacru.c
48800+++ b/drivers/usb/atm/cxacru.c
48801@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48802 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48803 if (ret < 2)
48804 return -EINVAL;
48805- if (index < 0 || index > 0x7f)
48806+ if (index > 0x7f)
48807 return -EINVAL;
48808 pos += tmp;
48809
48810diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48811index 5e0d33a..cc10579 100644
48812--- a/drivers/usb/atm/usbatm.c
48813+++ b/drivers/usb/atm/usbatm.c
48814@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48815 if (printk_ratelimit())
48816 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48817 __func__, vpi, vci);
48818- atomic_inc(&vcc->stats->rx_err);
48819+ atomic_inc_unchecked(&vcc->stats->rx_err);
48820 return;
48821 }
48822
48823@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48824 if (length > ATM_MAX_AAL5_PDU) {
48825 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48826 __func__, length, vcc);
48827- atomic_inc(&vcc->stats->rx_err);
48828+ atomic_inc_unchecked(&vcc->stats->rx_err);
48829 goto out;
48830 }
48831
48832@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48833 if (sarb->len < pdu_length) {
48834 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48835 __func__, pdu_length, sarb->len, vcc);
48836- atomic_inc(&vcc->stats->rx_err);
48837+ atomic_inc_unchecked(&vcc->stats->rx_err);
48838 goto out;
48839 }
48840
48841 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48842 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48843 __func__, vcc);
48844- atomic_inc(&vcc->stats->rx_err);
48845+ atomic_inc_unchecked(&vcc->stats->rx_err);
48846 goto out;
48847 }
48848
48849@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48850 if (printk_ratelimit())
48851 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48852 __func__, length);
48853- atomic_inc(&vcc->stats->rx_drop);
48854+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48855 goto out;
48856 }
48857
48858@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48859
48860 vcc->push(vcc, skb);
48861
48862- atomic_inc(&vcc->stats->rx);
48863+ atomic_inc_unchecked(&vcc->stats->rx);
48864 out:
48865 skb_trim(sarb, 0);
48866 }
48867@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
48868 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48869
48870 usbatm_pop(vcc, skb);
48871- atomic_inc(&vcc->stats->tx);
48872+ atomic_inc_unchecked(&vcc->stats->tx);
48873
48874 skb = skb_dequeue(&instance->sndqueue);
48875 }
48876@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48877 if (!left--)
48878 return sprintf(page,
48879 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48880- atomic_read(&atm_dev->stats.aal5.tx),
48881- atomic_read(&atm_dev->stats.aal5.tx_err),
48882- atomic_read(&atm_dev->stats.aal5.rx),
48883- atomic_read(&atm_dev->stats.aal5.rx_err),
48884- atomic_read(&atm_dev->stats.aal5.rx_drop));
48885+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48886+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48887+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48888+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48889+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48890
48891 if (!left--) {
48892 if (instance->disconnected)
48893diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48894index 2a3bbdf..91d72cf 100644
48895--- a/drivers/usb/core/devices.c
48896+++ b/drivers/usb/core/devices.c
48897@@ -126,7 +126,7 @@ static const char format_endpt[] =
48898 * time it gets called.
48899 */
48900 static struct device_connect_event {
48901- atomic_t count;
48902+ atomic_unchecked_t count;
48903 wait_queue_head_t wait;
48904 } device_event = {
48905 .count = ATOMIC_INIT(1),
48906@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48907
48908 void usbfs_conn_disc_event(void)
48909 {
48910- atomic_add(2, &device_event.count);
48911+ atomic_add_unchecked(2, &device_event.count);
48912 wake_up(&device_event.wait);
48913 }
48914
48915@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48916
48917 poll_wait(file, &device_event.wait, wait);
48918
48919- event_count = atomic_read(&device_event.count);
48920+ event_count = atomic_read_unchecked(&device_event.count);
48921 if (file->f_version != event_count) {
48922 file->f_version = event_count;
48923 return POLLIN | POLLRDNORM;
48924diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48925index 014dc99..4d25fd7 100644
48926--- a/drivers/usb/core/hcd.c
48927+++ b/drivers/usb/core/hcd.c
48928@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48929 */
48930 usb_get_urb(urb);
48931 atomic_inc(&urb->use_count);
48932- atomic_inc(&urb->dev->urbnum);
48933+ atomic_inc_unchecked(&urb->dev->urbnum);
48934 usbmon_urb_submit(&hcd->self, urb);
48935
48936 /* NOTE requirements on root-hub callers (usbfs and the hub
48937@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48938 urb->hcpriv = NULL;
48939 INIT_LIST_HEAD(&urb->urb_list);
48940 atomic_dec(&urb->use_count);
48941- atomic_dec(&urb->dev->urbnum);
48942+ atomic_dec_unchecked(&urb->dev->urbnum);
48943 if (atomic_read(&urb->reject))
48944 wake_up(&usb_kill_urb_queue);
48945 usb_put_urb(urb);
48946diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48947index 17c3785..deffb11 100644
48948--- a/drivers/usb/core/hub.c
48949+++ b/drivers/usb/core/hub.c
48950@@ -27,6 +27,7 @@
48951 #include <linux/freezer.h>
48952 #include <linux/random.h>
48953 #include <linux/pm_qos.h>
48954+#include <linux/grsecurity.h>
48955
48956 #include <asm/uaccess.h>
48957 #include <asm/byteorder.h>
48958@@ -4421,6 +4422,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48959 goto done;
48960 return;
48961 }
48962+
48963+ if (gr_handle_new_usb())
48964+ goto done;
48965+
48966 if (hub_is_superspeed(hub->hdev))
48967 unit_load = 150;
48968 else
48969diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48970index e7ee1e4..1dfc9ea4 100644
48971--- a/drivers/usb/core/message.c
48972+++ b/drivers/usb/core/message.c
48973@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48974 * method can wait for it to complete. Since you don't have a handle on the
48975 * URB used, you can't cancel the request.
48976 */
48977-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48978+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48979 __u8 requesttype, __u16 value, __u16 index, void *data,
48980 __u16 size, int timeout)
48981 {
48982diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
48983index d9284b9..17023c7 100644
48984--- a/drivers/usb/core/sysfs.c
48985+++ b/drivers/usb/core/sysfs.c
48986@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
48987 struct usb_device *udev;
48988
48989 udev = to_usb_device(dev);
48990- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
48991+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
48992 }
48993 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
48994
48995diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
48996index 7dad603..350f7a9 100644
48997--- a/drivers/usb/core/usb.c
48998+++ b/drivers/usb/core/usb.c
48999@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49000 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49001 dev->state = USB_STATE_ATTACHED;
49002 dev->lpm_disable_count = 1;
49003- atomic_set(&dev->urbnum, 0);
49004+ atomic_set_unchecked(&dev->urbnum, 0);
49005
49006 INIT_LIST_HEAD(&dev->ep0.urb_list);
49007 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49008diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49009index 14d28d6..5f511ac 100644
49010--- a/drivers/usb/dwc3/gadget.c
49011+++ b/drivers/usb/dwc3/gadget.c
49012@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49013 if (!usb_endpoint_xfer_isoc(desc))
49014 return 0;
49015
49016- memset(&trb_link, 0, sizeof(trb_link));
49017-
49018 /* Link TRB for ISOC. The HWO bit is never reset */
49019 trb_st_hw = &dep->trb_pool[0];
49020
49021diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49022index 5e29dde..eca992f 100644
49023--- a/drivers/usb/early/ehci-dbgp.c
49024+++ b/drivers/usb/early/ehci-dbgp.c
49025@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49026
49027 #ifdef CONFIG_KGDB
49028 static struct kgdb_io kgdbdbgp_io_ops;
49029-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49030+static struct kgdb_io kgdbdbgp_io_ops_console;
49031+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49032 #else
49033 #define dbgp_kgdb_mode (0)
49034 #endif
49035@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49036 .write_char = kgdbdbgp_write_char,
49037 };
49038
49039+static struct kgdb_io kgdbdbgp_io_ops_console = {
49040+ .name = "kgdbdbgp",
49041+ .read_char = kgdbdbgp_read_char,
49042+ .write_char = kgdbdbgp_write_char,
49043+ .is_console = 1
49044+};
49045+
49046 static int kgdbdbgp_wait_time;
49047
49048 static int __init kgdbdbgp_parse_config(char *str)
49049@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49050 ptr++;
49051 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49052 }
49053- kgdb_register_io_module(&kgdbdbgp_io_ops);
49054- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49055+ if (early_dbgp_console.index != -1)
49056+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49057+ else
49058+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49059
49060 return 0;
49061 }
49062diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49063index b369292..9f3ba40 100644
49064--- a/drivers/usb/gadget/u_serial.c
49065+++ b/drivers/usb/gadget/u_serial.c
49066@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49067 spin_lock_irq(&port->port_lock);
49068
49069 /* already open? Great. */
49070- if (port->port.count) {
49071+ if (atomic_read(&port->port.count)) {
49072 status = 0;
49073- port->port.count++;
49074+ atomic_inc(&port->port.count);
49075
49076 /* currently opening/closing? wait ... */
49077 } else if (port->openclose) {
49078@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49079 tty->driver_data = port;
49080 port->port.tty = tty;
49081
49082- port->port.count = 1;
49083+ atomic_set(&port->port.count, 1);
49084 port->openclose = false;
49085
49086 /* if connected, start the I/O stream */
49087@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49088
49089 spin_lock_irq(&port->port_lock);
49090
49091- if (port->port.count != 1) {
49092- if (port->port.count == 0)
49093+ if (atomic_read(&port->port.count) != 1) {
49094+ if (atomic_read(&port->port.count) == 0)
49095 WARN_ON(1);
49096 else
49097- --port->port.count;
49098+ atomic_dec(&port->port.count);
49099 goto exit;
49100 }
49101
49102@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49103 * and sleep if necessary
49104 */
49105 port->openclose = true;
49106- port->port.count = 0;
49107+ atomic_set(&port->port.count, 0);
49108
49109 gser = port->port_usb;
49110 if (gser && gser->disconnect)
49111@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49112 int cond;
49113
49114 spin_lock_irq(&port->port_lock);
49115- cond = (port->port.count == 0) && !port->openclose;
49116+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49117 spin_unlock_irq(&port->port_lock);
49118 return cond;
49119 }
49120@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49121 /* if it's already open, start I/O ... and notify the serial
49122 * protocol about open/close status (connect/disconnect).
49123 */
49124- if (port->port.count) {
49125+ if (atomic_read(&port->port.count)) {
49126 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49127 gs_start_io(port);
49128 if (gser->connect)
49129@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49130
49131 port->port_usb = NULL;
49132 gser->ioport = NULL;
49133- if (port->port.count > 0 || port->openclose) {
49134+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49135 wake_up_interruptible(&port->drain_wait);
49136 if (port->port.tty)
49137 tty_hangup(port->port.tty);
49138@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49139
49140 /* finally, free any unused/unusable I/O buffers */
49141 spin_lock_irqsave(&port->port_lock, flags);
49142- if (port->port.count == 0 && !port->openclose)
49143+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49144 gs_buf_free(&port->port_write_buf);
49145 gs_free_requests(gser->out, &port->read_pool, NULL);
49146 gs_free_requests(gser->out, &port->read_queue, NULL);
49147diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49148index ba6a5d6..f88f7f3 100644
49149--- a/drivers/usb/misc/appledisplay.c
49150+++ b/drivers/usb/misc/appledisplay.c
49151@@ -83,7 +83,7 @@ struct appledisplay {
49152 spinlock_t lock;
49153 };
49154
49155-static atomic_t count_displays = ATOMIC_INIT(0);
49156+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49157 static struct workqueue_struct *wq;
49158
49159 static void appledisplay_complete(struct urb *urb)
49160@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49161
49162 /* Register backlight device */
49163 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49164- atomic_inc_return(&count_displays) - 1);
49165+ atomic_inc_return_unchecked(&count_displays) - 1);
49166 memset(&props, 0, sizeof(struct backlight_properties));
49167 props.type = BACKLIGHT_RAW;
49168 props.max_brightness = 0xff;
49169diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49170index afb50ea..7b0b1cf 100644
49171--- a/drivers/usb/serial/console.c
49172+++ b/drivers/usb/serial/console.c
49173@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49174
49175 info->port = port;
49176
49177- ++port->port.count;
49178+ atomic_inc(&port->port.count);
49179 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49180 if (serial->type->set_termios) {
49181 /*
49182@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49183 }
49184 /* Now that any required fake tty operations are completed restore
49185 * the tty port count */
49186- --port->port.count;
49187+ atomic_dec(&port->port.count);
49188 /* The console is special in terms of closing the device so
49189 * indicate this port is now acting as a system console. */
49190 port->port.console = 1;
49191@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49192 free_tty:
49193 kfree(tty);
49194 reset_open_count:
49195- port->port.count = 0;
49196+ atomic_set(&port->port.count, 0);
49197 usb_autopm_put_interface(serial->interface);
49198 error_get_interface:
49199 usb_serial_put(serial);
49200diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49201index 75f70f0..d467e1a 100644
49202--- a/drivers/usb/storage/usb.h
49203+++ b/drivers/usb/storage/usb.h
49204@@ -63,7 +63,7 @@ struct us_unusual_dev {
49205 __u8 useProtocol;
49206 __u8 useTransport;
49207 int (*initFunction)(struct us_data *);
49208-};
49209+} __do_const;
49210
49211
49212 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49213diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49214index d6bea3e..60b250e 100644
49215--- a/drivers/usb/wusbcore/wa-hc.h
49216+++ b/drivers/usb/wusbcore/wa-hc.h
49217@@ -192,7 +192,7 @@ struct wahc {
49218 struct list_head xfer_delayed_list;
49219 spinlock_t xfer_list_lock;
49220 struct work_struct xfer_work;
49221- atomic_t xfer_id_count;
49222+ atomic_unchecked_t xfer_id_count;
49223 };
49224
49225
49226@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49227 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49228 spin_lock_init(&wa->xfer_list_lock);
49229 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49230- atomic_set(&wa->xfer_id_count, 1);
49231+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49232 }
49233
49234 /**
49235diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49236index d3493ca..0c33b7e 100644
49237--- a/drivers/usb/wusbcore/wa-xfer.c
49238+++ b/drivers/usb/wusbcore/wa-xfer.c
49239@@ -297,7 +297,7 @@ out:
49240 */
49241 static void wa_xfer_id_init(struct wa_xfer *xfer)
49242 {
49243- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49244+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49245 }
49246
49247 /*
49248diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49249index 842f450..d1d7409 100644
49250--- a/drivers/vfio/vfio.c
49251+++ b/drivers/vfio/vfio.c
49252@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49253 return 0;
49254
49255 /* TODO Prevent device auto probing */
49256- WARN("Device %s added to live group %d!\n", dev_name(dev),
49257+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49258 iommu_group_id(group->iommu_group));
49259
49260 return 0;
49261diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49262index 5174eba..86e764a 100644
49263--- a/drivers/vhost/vringh.c
49264+++ b/drivers/vhost/vringh.c
49265@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49266
49267 static inline int putu16_kern(u16 *p, u16 val)
49268 {
49269- ACCESS_ONCE(*p) = val;
49270+ ACCESS_ONCE_RW(*p) = val;
49271 return 0;
49272 }
49273
49274diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49275index a4dfe8c..297ddd9 100644
49276--- a/drivers/video/aty/aty128fb.c
49277+++ b/drivers/video/aty/aty128fb.c
49278@@ -149,7 +149,7 @@ enum {
49279 };
49280
49281 /* Must match above enum */
49282-static char * const r128_family[] = {
49283+static const char * const r128_family[] = {
49284 "AGP",
49285 "PCI",
49286 "PRO AGP",
49287diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49288index 9b0f12c..024673d 100644
49289--- a/drivers/video/aty/atyfb_base.c
49290+++ b/drivers/video/aty/atyfb_base.c
49291@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49292 par->accel_flags = var->accel_flags; /* hack */
49293
49294 if (var->accel_flags) {
49295- info->fbops->fb_sync = atyfb_sync;
49296+ pax_open_kernel();
49297+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49298+ pax_close_kernel();
49299 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49300 } else {
49301- info->fbops->fb_sync = NULL;
49302+ pax_open_kernel();
49303+ *(void **)&info->fbops->fb_sync = NULL;
49304+ pax_close_kernel();
49305 info->flags |= FBINFO_HWACCEL_DISABLED;
49306 }
49307
49308diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49309index 95ec042..e6affdd 100644
49310--- a/drivers/video/aty/mach64_cursor.c
49311+++ b/drivers/video/aty/mach64_cursor.c
49312@@ -7,6 +7,7 @@
49313 #include <linux/string.h>
49314
49315 #include <asm/io.h>
49316+#include <asm/pgtable.h>
49317
49318 #ifdef __sparc__
49319 #include <asm/fbio.h>
49320@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49321 info->sprite.buf_align = 16; /* and 64 lines tall. */
49322 info->sprite.flags = FB_PIXMAP_IO;
49323
49324- info->fbops->fb_cursor = atyfb_cursor;
49325+ pax_open_kernel();
49326+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49327+ pax_close_kernel();
49328
49329 return 0;
49330 }
49331diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49332index bca6ccc..252107e 100644
49333--- a/drivers/video/backlight/kb3886_bl.c
49334+++ b/drivers/video/backlight/kb3886_bl.c
49335@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49336 static unsigned long kb3886bl_flags;
49337 #define KB3886BL_SUSPENDED 0x01
49338
49339-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49340+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49341 {
49342 .ident = "Sahara Touch-iT",
49343 .matches = {
49344diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49345index 900aa4e..6d49418 100644
49346--- a/drivers/video/fb_defio.c
49347+++ b/drivers/video/fb_defio.c
49348@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49349
49350 BUG_ON(!fbdefio);
49351 mutex_init(&fbdefio->lock);
49352- info->fbops->fb_mmap = fb_deferred_io_mmap;
49353+ pax_open_kernel();
49354+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49355+ pax_close_kernel();
49356 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49357 INIT_LIST_HEAD(&fbdefio->pagelist);
49358 if (fbdefio->delay == 0) /* set a default of 1 s */
49359@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49360 page->mapping = NULL;
49361 }
49362
49363- info->fbops->fb_mmap = NULL;
49364+ *(void **)&info->fbops->fb_mmap = NULL;
49365 mutex_destroy(&fbdefio->lock);
49366 }
49367 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49368diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49369index 5c3960d..15cf8fc 100644
49370--- a/drivers/video/fbcmap.c
49371+++ b/drivers/video/fbcmap.c
49372@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49373 rc = -ENODEV;
49374 goto out;
49375 }
49376- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49377- !info->fbops->fb_setcmap)) {
49378+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49379 rc = -EINVAL;
49380 goto out1;
49381 }
49382diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49383index 36e1fe2..c744820 100644
49384--- a/drivers/video/fbmem.c
49385+++ b/drivers/video/fbmem.c
49386@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49387 image->dx += image->width + 8;
49388 }
49389 } else if (rotate == FB_ROTATE_UD) {
49390- for (x = 0; x < num && image->dx >= 0; x++) {
49391+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49392 info->fbops->fb_imageblit(info, image);
49393 image->dx -= image->width + 8;
49394 }
49395@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49396 image->dy += image->height + 8;
49397 }
49398 } else if (rotate == FB_ROTATE_CCW) {
49399- for (x = 0; x < num && image->dy >= 0; x++) {
49400+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49401 info->fbops->fb_imageblit(info, image);
49402 image->dy -= image->height + 8;
49403 }
49404@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49405 return -EFAULT;
49406 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49407 return -EINVAL;
49408- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49409+ if (con2fb.framebuffer >= FB_MAX)
49410 return -EINVAL;
49411 if (!registered_fb[con2fb.framebuffer])
49412 request_module("fb%d", con2fb.framebuffer);
49413diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49414index d4d2c5f..ebbd113 100644
49415--- a/drivers/video/hyperv_fb.c
49416+++ b/drivers/video/hyperv_fb.c
49417@@ -233,7 +233,7 @@ static uint screen_fb_size;
49418 static inline int synthvid_send(struct hv_device *hdev,
49419 struct synthvid_msg *msg)
49420 {
49421- static atomic64_t request_id = ATOMIC64_INIT(0);
49422+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49423 int ret;
49424
49425 msg->pipe_hdr.type = PIPE_MSG_DATA;
49426@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49427
49428 ret = vmbus_sendpacket(hdev->channel, msg,
49429 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49430- atomic64_inc_return(&request_id),
49431+ atomic64_inc_return_unchecked(&request_id),
49432 VM_PKT_DATA_INBAND, 0);
49433
49434 if (ret)
49435diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49436index 7672d2e..b56437f 100644
49437--- a/drivers/video/i810/i810_accel.c
49438+++ b/drivers/video/i810/i810_accel.c
49439@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49440 }
49441 }
49442 printk("ringbuffer lockup!!!\n");
49443+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49444 i810_report_error(mmio);
49445 par->dev_flags |= LOCKUP;
49446 info->pixmap.scan_align = 1;
49447diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49448index 285d552..eafa544 100644
49449--- a/drivers/video/logo/logo_linux_clut224.ppm
49450+++ b/drivers/video/logo/logo_linux_clut224.ppm
49451@@ -1,883 +1,1123 @@
49452 P3
49453 80 80
49454 255
49455-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49456-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49457-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 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 6 6 6 6 6 6 10 10 10 10 10 10
49460-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49461-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49462-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49463-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49464-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49465-
49466-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49467-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49468-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 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 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49471-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49472-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49473-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49474-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49475-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49476-
49477-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49478-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49479-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 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-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49482-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49483-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49484-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49485-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49486-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49487-
49488-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49489-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49490-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 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 10 10 10
49492-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49493-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49494-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49495-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49496-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49497-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49498-
49499-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49500-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49501-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49502-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49503-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49504-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49505-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49506-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49507-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49508-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49509-
49510-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49511-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49512-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49513-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49514-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49515-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49516-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49517-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49518-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49519-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49520-
49521-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49522-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49523-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49524-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49525-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49526-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49527-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49528-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49529-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49530-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49531-
49532-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49533-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49534-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49535-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49536-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49537-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49538-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49539-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49540-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49541-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49542-
49543-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49544-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49545-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49546-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49547-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49548-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49549-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49550-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49551-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49552-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49553-
49554-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49555-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49556-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49557-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49558-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49559-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49560-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49561-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49562-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49563-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49564-
49565-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49566-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49567-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49568-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49569-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49570-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49571-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49572-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49573-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49574-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49575-
49576-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49577-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49578-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49579-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49580-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49581-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49582-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49583-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49584-0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49586-
49587-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49588-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49589-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49590-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49591-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49592-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49593-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49594-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49597-
49598-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49599-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49600-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49601-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49602-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49603-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49604-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49605-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49608-
49609-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49610-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49611-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49612-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49613-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49614-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49615-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49616-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49619-
49620-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49621-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49622-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49623-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49624-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49625-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49626-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49627-0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49630-
49631-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49632-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49633-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49634-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49635-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49636-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49637-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49638-0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49641-
49642-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49643-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49644-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49645-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49646-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49647-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49648-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49649-0 0 0 0 0 0 0 0 0 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-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49652-
49653-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49654-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49655-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49656-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49657-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49658-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49659-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49660-0 0 0 0 0 0 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 0 0 0
49662-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49663-
49664-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49665-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49666-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49667-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49668-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49669-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49670-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49671-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49672-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49673-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49674-
49675-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49676-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49677-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49678-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49679-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49680-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49681-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49682-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49683-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49684-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49685-
49686-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49687-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49688-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49689-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49690-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49691-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49692-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49693-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49694-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49695-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49696-
49697-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49698-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49699-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49700-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49701-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49702-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49703-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49704-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49705-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49706-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49707-
49708-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49709-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49710-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49711-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49712-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49713-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49714-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49715-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49716-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49717-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49718-
49719-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49720-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49721-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49722-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49723-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49724-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49725-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49726-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49727-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49728-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49729-
49730-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49731-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49732-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49733-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49734-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49735-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49736-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49737-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49738-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49739-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49740-
49741-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49742-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49743-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49744-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49745-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49746-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49747-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49748-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49749-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49750-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49751-
49752-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49753-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49754-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49755-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49756-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49757-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49758-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49759-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49760-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49761-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49762-
49763-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49764-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49765-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49766-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49767-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49768-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49769-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49770-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49771-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49772-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49773-
49774-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49775-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49776-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49777-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49778-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49779-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49780-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49781-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49782-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49783-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49784-
49785-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49786-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49787-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49788-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49789-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49790-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49791-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
49792-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49793-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49794-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49795-
49796-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
49797-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49798-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49799-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
49800-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
49801-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49802-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49803-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49804-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49805-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49806-
49807-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
49808-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49809-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49810-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
49811-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
49812-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49813-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49814-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
49815-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49816-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49817-
49818-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49819-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49820-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
49821-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
49822-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
49823-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49824-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49825-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
49826-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49827-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49828-
49829-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49830-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49831-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49832-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
49833-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
49834-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49835-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49836-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
49837-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49838-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49839-
49840-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49841-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
49842-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49843-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
49844-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49845-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49846-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49847-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
49848-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49849-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49850-
49851-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49852-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
49853-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
49854-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
49855-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
49856-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
49857-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49858-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
49859-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49860-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49861-
49862-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49863-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
49864-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
49865-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
49866-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
49867-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
49868-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
49869-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
49870-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49871-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49872-
49873-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49874-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
49875-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
49876-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
49877-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
49878-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
49879-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
49880-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
49881-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49882-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49883-
49884-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49885-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
49886-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
49887-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
49888-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
49889-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
49890-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
49891-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
49892-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49893-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49894-
49895-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49896-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
49897-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
49898-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
49899-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49900-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49901-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
49902-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
49903-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49904-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49905-
49906-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49907-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
49908-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
49909-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
49910-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49911-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49912-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
49913-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
49914-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49915-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49916-
49917-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49918-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
49919-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
49920-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49921-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49922-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49923-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
49924-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
49925-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49926-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49927-
49928-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49929-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
49930-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
49931-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49932-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49933-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49934-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
49935-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
49936-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49937-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49938-
49939-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49940-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49941-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
49942-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49943-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49944-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49945-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
49946-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
49947-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49948-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49949-
49950-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49951-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49952-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
49953-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49954-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49955-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49956-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
49957-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49958-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49959-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49960-
49961-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49962-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49963-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
49964-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49965-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49966-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49967-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
49968-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49969-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49970-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49971-
49972-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49973-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49974-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
49975-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49976-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49977-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49978-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
49979-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
49980-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
49981-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49982-
49983-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49984-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49985-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
49986-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49987-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49988-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49989-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
49990-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
49991-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49992-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49993-
49994-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49995-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49996-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
49997-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49998-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49999-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50000-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50001-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50002-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50003-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50004-
50005-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50006-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50007-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50008-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50009-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50010-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50011-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50012-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50013-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50014-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50015-
50016-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50017-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50018-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50019-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50020-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50021-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50022-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50023-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50024-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50025-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50026-
50027-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50028-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50029-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50030-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50031-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50032-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50033-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50034-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50035-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50036-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50037-
50038-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50039-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50040-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50041-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50042-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50043-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50044-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50045-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50046-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50047-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50048-
50049-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50050-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50051-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50052-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50053-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50054-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50055-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50056-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50057-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50058-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50059-
50060-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50061-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50062-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50063-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50064-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50065-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50066-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50067-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50068-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50069-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50070-
50071-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50072-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50073-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50074-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50075-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50076-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50077-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50078-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50079-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50080-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50081-
50082-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50083-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50084-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50085-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50086-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50087-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50088-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50089-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50090-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50091-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50092-
50093-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50094-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50095-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50096-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50097-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50098-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50099-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50100-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50101-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50102-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50103-
50104-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50105-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50106-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50107-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50108-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50109-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50110-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50111-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50112-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50113-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50114-
50115-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50116-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50117-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50118-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50119-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50120-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50121-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50122-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50123-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50124-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50125-
50126-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50127-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50128-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50129-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50130-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50131-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50132-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50133-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50134-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50135-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50136-
50137-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50138-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50139-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50140-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50141-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50142-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50143-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50144-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50145-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50146-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50147-
50148-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50149-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50150-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50151-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50152-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50153-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50154-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50155-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50156-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50157-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50158-
50159-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50160-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50161-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50162-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50163-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50164-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50165-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50166-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50167-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50168-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50169-
50170-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50171-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50172-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50173-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50174-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50175-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50176-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50177-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50178-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50179-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50180-
50181-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50182-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50183-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50184-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50185-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50186-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50187-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50188-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50189-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50190-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50191-
50192-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50193-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50194-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50195-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50196-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50197-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50198-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50199-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50200-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50201-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50202-
50203-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50204-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50205-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50206-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50207-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50208-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50209-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50210-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50211-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50212-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50213-
50214-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50215-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50216-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50217-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50218-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50219-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50220-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50221-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50222-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50223-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50224-
50225-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50226-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50227-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50228-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50229-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50230-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50231-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50232-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50233-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50234-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50235-
50236-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50237-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50238-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50239-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50240-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50241-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50242-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50243-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50244-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50245-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50246-
50247-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50248-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50249-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50250-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50251-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50252-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50253-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50254-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50255-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50256-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50257-
50258-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50259-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50260-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50261-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50262-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50263-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50264-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50265-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50266-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50267-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50268-
50269-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50270-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50271-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50272-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50273-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50274-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50275-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50276-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50277-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50278-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50279-
50280-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50281-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50282-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50283-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50284-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50285-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50286-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50287-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50288-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50289-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50290-
50291-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50292-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50293-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50294-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50295-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50296-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50297-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50298-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50299-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50300-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50301-
50302-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50303-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50304-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50305-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50306-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50307-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50308-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50309-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50310-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50311-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50312-
50313-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50314-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50315-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50316-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50317-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50318-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50319-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50320-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50321-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50322-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50323-
50324-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50325-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50326-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50327-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50328-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50329-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50330-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50331-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50332-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50333-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50334-
50335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50340+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
50344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50348+4 4 4 4 4 4
50349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50354+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
50358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50362+4 4 4 4 4 4
50363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50368+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
50372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50376+4 4 4 4 4 4
50377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50382+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50390+4 4 4 4 4 4
50391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50396+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50404+4 4 4 4 4 4
50405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50410+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
50413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50418+4 4 4 4 4 4
50419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50423+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50424+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50428+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50429+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50430+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50432+4 4 4 4 4 4
50433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50437+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50438+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50439+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50442+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50443+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50444+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50445+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50446+4 4 4 4 4 4
50447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50451+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50452+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50453+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50456+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50457+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50458+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50459+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50460+4 4 4 4 4 4
50461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50464+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50465+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50466+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50467+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50469+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50470+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50471+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50472+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50473+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50474+4 4 4 4 4 4
50475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50478+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50479+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50480+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50481+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50482+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50483+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50484+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50485+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50486+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50487+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50488+4 4 4 4 4 4
50489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50492+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50493+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50494+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50495+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50496+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50497+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50498+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50499+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50500+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50501+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50502+4 4 4 4 4 4
50503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50505+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50506+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50507+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50508+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50509+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50510+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50511+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50512+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50513+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50514+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50515+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50516+4 4 4 4 4 4
50517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50519+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50520+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50521+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50522+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50523+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50524+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50525+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50526+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50527+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50528+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50529+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50530+4 4 4 4 4 4
50531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50533+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50534+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50535+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50536+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50537+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50538+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50539+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50540+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50541+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50542+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50543+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50544+4 4 4 4 4 4
50545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50547+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50548+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50549+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50550+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50551+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50552+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50553+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50554+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50555+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50556+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50557+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50558+4 4 4 4 4 4
50559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50560+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50561+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50562+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50563+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50564+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50565+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50566+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50567+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50568+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50569+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50570+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50571+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50572+4 4 4 4 4 4
50573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50574+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50575+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50576+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50577+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50578+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50579+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50580+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50581+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50582+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50583+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50584+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50585+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50586+0 0 0 4 4 4
50587+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50588+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50589+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50590+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50591+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50592+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50593+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50594+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50595+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50596+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50597+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50598+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50599+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50600+2 0 0 0 0 0
50601+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50602+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50603+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50604+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50605+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50606+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50607+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50608+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50609+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50610+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50611+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50612+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50613+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50614+37 38 37 0 0 0
50615+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50616+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50617+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50618+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50619+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50620+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50621+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50622+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50623+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50624+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50625+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50626+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50627+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50628+85 115 134 4 0 0
50629+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50630+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50631+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50632+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50633+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50634+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50635+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50636+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50637+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50638+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50639+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50640+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50641+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50642+60 73 81 4 0 0
50643+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50644+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50645+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50646+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50647+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50648+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50649+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50650+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50651+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50652+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50653+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50654+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50655+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50656+16 19 21 4 0 0
50657+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50658+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50659+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50660+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50661+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50662+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50663+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50664+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50665+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50666+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50667+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50668+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50669+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50670+4 0 0 4 3 3
50671+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50672+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50673+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50675+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50676+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50677+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50678+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50679+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50680+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50681+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50682+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50683+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50684+3 2 2 4 4 4
50685+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50686+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50687+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50688+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50689+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50690+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50691+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50692+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50693+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50694+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50695+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50696+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50697+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50698+4 4 4 4 4 4
50699+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50700+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50701+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50702+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50703+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50704+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50705+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50706+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50707+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50708+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50709+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50710+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50711+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50712+4 4 4 4 4 4
50713+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50714+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50715+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50716+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50717+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50718+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50719+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50720+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50721+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50722+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50723+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50724+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50725+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50726+5 5 5 5 5 5
50727+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50728+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50729+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50730+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50731+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50732+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50733+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50734+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50735+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50736+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50737+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50738+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50739+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50740+5 5 5 4 4 4
50741+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50742+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50743+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50744+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50745+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50746+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50747+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50748+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50749+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50750+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50751+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50752+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50754+4 4 4 4 4 4
50755+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50756+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50757+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50758+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50759+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50760+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50761+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50762+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50763+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50764+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50765+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50766+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50768+4 4 4 4 4 4
50769+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50770+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50771+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50772+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50773+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50774+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50775+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50776+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50777+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50778+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50779+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
50780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50782+4 4 4 4 4 4
50783+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50784+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50785+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50786+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50787+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50788+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50789+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50790+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50791+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
50792+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
50793+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
50794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50796+4 4 4 4 4 4
50797+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
50798+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
50799+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
50800+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
50801+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50802+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
50803+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50804+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
50805+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
50806+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
50807+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50810+4 4 4 4 4 4
50811+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
50812+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
50813+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
50814+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
50815+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50816+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
50817+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
50818+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
50819+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
50820+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
50821+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
50822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50824+4 4 4 4 4 4
50825+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
50826+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
50827+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
50828+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
50829+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50830+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
50831+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
50832+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
50833+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
50834+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
50835+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
50836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50838+4 4 4 4 4 4
50839+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
50840+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
50841+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
50842+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50843+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
50844+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
50845+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
50846+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
50847+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
50848+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
50849+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50852+4 4 4 4 4 4
50853+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
50854+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
50855+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
50856+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50857+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50858+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
50859+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
50860+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
50861+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
50862+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
50863+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50866+4 4 4 4 4 4
50867+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
50868+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
50869+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50870+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50871+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50872+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
50873+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
50874+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
50875+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
50876+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
50877+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50880+4 4 4 4 4 4
50881+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
50882+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
50883+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50884+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50885+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50886+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
50887+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
50888+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
50889+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50890+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50891+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50894+4 4 4 4 4 4
50895+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50896+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
50897+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50898+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
50899+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
50900+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
50901+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
50902+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
50903+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50904+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50905+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50908+4 4 4 4 4 4
50909+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50910+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
50911+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50912+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
50913+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50914+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
50915+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
50916+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
50917+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50918+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50919+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50922+4 4 4 4 4 4
50923+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
50924+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
50925+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50926+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
50927+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
50928+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
50929+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
50930+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
50931+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50932+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50933+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50936+4 4 4 4 4 4
50937+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
50938+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
50939+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50940+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
50941+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
50942+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
50943+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
50944+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
50945+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50946+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50947+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50950+4 4 4 4 4 4
50951+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50952+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
50953+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50954+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
50955+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
50956+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
50957+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
50958+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
50959+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50960+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50961+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50964+4 4 4 4 4 4
50965+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
50966+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
50967+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50968+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
50969+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
50970+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
50971+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
50972+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
50973+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
50974+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50975+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50978+4 4 4 4 4 4
50979+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50980+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
50981+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
50982+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
50983+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
50984+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
50985+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
50986+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
50987+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50988+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50989+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50992+4 4 4 4 4 4
50993+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
50994+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
50995+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50996+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
50997+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
50998+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
50999+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51000+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51001+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51002+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51003+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51006+4 4 4 4 4 4
51007+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51008+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51009+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51010+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51011+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51012+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51013+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51014+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51015+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51016+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51017+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51020+4 4 4 4 4 4
51021+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51022+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51023+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51024+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51025+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51026+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51027+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51028+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51029+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51030+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51031+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51034+4 4 4 4 4 4
51035+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51036+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51037+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51038+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51039+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51040+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51041+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51042+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51043+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51044+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51045+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51048+4 4 4 4 4 4
51049+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51050+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51051+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51052+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51053+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51054+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51055+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51056+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51057+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51058+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51059+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51062+4 4 4 4 4 4
51063+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51064+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51065+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51066+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51067+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51068+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51069+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51070+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51071+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51072+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51073+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51076+4 4 4 4 4 4
51077+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51078+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51079+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51080+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51081+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51082+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51083+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51084+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51085+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51086+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51087+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51090+4 4 4 4 4 4
51091+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51092+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51093+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51094+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51095+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51096+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51097+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51098+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51099+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51100+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51101+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51104+4 4 4 4 4 4
51105+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51106+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51107+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51108+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51109+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51110+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51111+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51112+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51113+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51114+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51115+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51118+4 4 4 4 4 4
51119+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51120+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51121+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51122+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51123+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51124+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51125+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51126+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51127+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51128+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51129+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51132+4 4 4 4 4 4
51133+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51134+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51135+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51136+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51137+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51138+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51139+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51140+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51141+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51142+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51143+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51146+4 4 4 4 4 4
51147+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51148+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51149+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51150+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51151+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51152+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51153+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51154+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51155+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51156+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51160+4 4 4 4 4 4
51161+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51162+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51163+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51164+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51165+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51166+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51167+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51168+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51169+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51170+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51174+4 4 4 4 4 4
51175+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51176+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51177+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51178+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51179+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51180+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51181+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51182+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51183+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51184+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51188+4 4 4 4 4 4
51189+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51190+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51191+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51192+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51193+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51194+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51195+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51196+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51197+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51198+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51202+4 4 4 4 4 4
51203+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51204+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51205+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51206+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51207+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51208+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51209+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51210+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51211+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51216+4 4 4 4 4 4
51217+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51218+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51219+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51220+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51221+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51222+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51223+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51224+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51225+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51230+4 4 4 4 4 4
51231+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51232+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51233+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51234+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51235+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51236+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51237+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51238+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51239+4 0 0 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 4 4 4
51241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51244+4 4 4 4 4 4
51245+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51246+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51247+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51248+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51249+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51250+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51251+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51252+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51258+4 4 4 4 4 4
51259+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51260+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51261+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51262+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51263+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51264+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51265+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51266+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51272+4 4 4 4 4 4
51273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51274+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51275+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51276+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51277+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51278+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51279+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51280+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4
51284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51286+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51289+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51290+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51291+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51292+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51293+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51294+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4
51298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51300+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 5 5 5 5 5 5 5 5 5
51303+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51304+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51305+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51306+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51307+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51308+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51314+4 4 4 4 4 4
51315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51317+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51318+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51319+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51320+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51321+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51322+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51328+4 4 4 4 4 4
51329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51332+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51333+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51334+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51335+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51342+4 4 4 4 4 4
51343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51346+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51347+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51348+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51349+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51356+4 4 4 4 4 4
51357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51360+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51361+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51362+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51363+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51370+4 4 4 4 4 4
51371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51374+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51375+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51376+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51377+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51384+4 4 4 4 4 4
51385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51389+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51390+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51391+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51398+4 4 4 4 4 4
51399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51403+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51404+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51405+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51412+4 4 4 4 4 4
51413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51417+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51418+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51419+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51426+4 4 4 4 4 4
51427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51431+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51432+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51440+4 4 4 4 4 4
51441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51445+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51446+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51454+4 4 4 4 4 4
51455diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51456index fe92eed..106e085 100644
51457--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51458+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51459@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51460 struct mb862xxfb_par *par = info->par;
51461
51462 if (info->var.bits_per_pixel == 32) {
51463- info->fbops->fb_fillrect = cfb_fillrect;
51464- info->fbops->fb_copyarea = cfb_copyarea;
51465- info->fbops->fb_imageblit = cfb_imageblit;
51466+ pax_open_kernel();
51467+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51468+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51469+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51470+ pax_close_kernel();
51471 } else {
51472 outreg(disp, GC_L0EM, 3);
51473- info->fbops->fb_fillrect = mb86290fb_fillrect;
51474- info->fbops->fb_copyarea = mb86290fb_copyarea;
51475- info->fbops->fb_imageblit = mb86290fb_imageblit;
51476+ pax_open_kernel();
51477+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51478+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51479+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51480+ pax_close_kernel();
51481 }
51482 outreg(draw, GDC_REG_DRAW_BASE, 0);
51483 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51484diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51485index ff22871..b129bed 100644
51486--- a/drivers/video/nvidia/nvidia.c
51487+++ b/drivers/video/nvidia/nvidia.c
51488@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51489 info->fix.line_length = (info->var.xres_virtual *
51490 info->var.bits_per_pixel) >> 3;
51491 if (info->var.accel_flags) {
51492- info->fbops->fb_imageblit = nvidiafb_imageblit;
51493- info->fbops->fb_fillrect = nvidiafb_fillrect;
51494- info->fbops->fb_copyarea = nvidiafb_copyarea;
51495- info->fbops->fb_sync = nvidiafb_sync;
51496+ pax_open_kernel();
51497+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51498+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51499+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51500+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51501+ pax_close_kernel();
51502 info->pixmap.scan_align = 4;
51503 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51504 info->flags |= FBINFO_READS_FAST;
51505 NVResetGraphics(info);
51506 } else {
51507- info->fbops->fb_imageblit = cfb_imageblit;
51508- info->fbops->fb_fillrect = cfb_fillrect;
51509- info->fbops->fb_copyarea = cfb_copyarea;
51510- info->fbops->fb_sync = NULL;
51511+ pax_open_kernel();
51512+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51513+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51514+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51515+ *(void **)&info->fbops->fb_sync = NULL;
51516+ pax_close_kernel();
51517 info->pixmap.scan_align = 1;
51518 info->flags |= FBINFO_HWACCEL_DISABLED;
51519 info->flags &= ~FBINFO_READS_FAST;
51520@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51521 info->pixmap.size = 8 * 1024;
51522 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51523
51524- if (!hwcur)
51525- info->fbops->fb_cursor = NULL;
51526+ if (!hwcur) {
51527+ pax_open_kernel();
51528+ *(void **)&info->fbops->fb_cursor = NULL;
51529+ pax_close_kernel();
51530+ }
51531
51532 info->var.accel_flags = (!noaccel);
51533
51534diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51535index 05c2dc3..ea1f391 100644
51536--- a/drivers/video/s1d13xxxfb.c
51537+++ b/drivers/video/s1d13xxxfb.c
51538@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51539
51540 switch(prod_id) {
51541 case S1D13506_PROD_ID: /* activate acceleration */
51542- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51543- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51544+ pax_open_kernel();
51545+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51546+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51547+ pax_close_kernel();
51548 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51549 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51550 break;
51551diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51552index e188ada..aac63c8 100644
51553--- a/drivers/video/smscufx.c
51554+++ b/drivers/video/smscufx.c
51555@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51556 fb_deferred_io_cleanup(info);
51557 kfree(info->fbdefio);
51558 info->fbdefio = NULL;
51559- info->fbops->fb_mmap = ufx_ops_mmap;
51560+ pax_open_kernel();
51561+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51562+ pax_close_kernel();
51563 }
51564
51565 pr_debug("released /dev/fb%d user=%d count=%d",
51566diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51567index d2e5bc3..4cb05d1 100644
51568--- a/drivers/video/udlfb.c
51569+++ b/drivers/video/udlfb.c
51570@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51571 dlfb_urb_completion(urb);
51572
51573 error:
51574- atomic_add(bytes_sent, &dev->bytes_sent);
51575- atomic_add(bytes_identical, &dev->bytes_identical);
51576- atomic_add(width*height*2, &dev->bytes_rendered);
51577+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51578+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51579+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51580 end_cycles = get_cycles();
51581- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51582+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51583 >> 10)), /* Kcycles */
51584 &dev->cpu_kcycles_used);
51585
51586@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51587 dlfb_urb_completion(urb);
51588
51589 error:
51590- atomic_add(bytes_sent, &dev->bytes_sent);
51591- atomic_add(bytes_identical, &dev->bytes_identical);
51592- atomic_add(bytes_rendered, &dev->bytes_rendered);
51593+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51594+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51595+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51596 end_cycles = get_cycles();
51597- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51598+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51599 >> 10)), /* Kcycles */
51600 &dev->cpu_kcycles_used);
51601 }
51602@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51603 fb_deferred_io_cleanup(info);
51604 kfree(info->fbdefio);
51605 info->fbdefio = NULL;
51606- info->fbops->fb_mmap = dlfb_ops_mmap;
51607+ pax_open_kernel();
51608+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51609+ pax_close_kernel();
51610 }
51611
51612 pr_warn("released /dev/fb%d user=%d count=%d\n",
51613@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51614 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51615 struct dlfb_data *dev = fb_info->par;
51616 return snprintf(buf, PAGE_SIZE, "%u\n",
51617- atomic_read(&dev->bytes_rendered));
51618+ atomic_read_unchecked(&dev->bytes_rendered));
51619 }
51620
51621 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51622@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51623 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51624 struct dlfb_data *dev = fb_info->par;
51625 return snprintf(buf, PAGE_SIZE, "%u\n",
51626- atomic_read(&dev->bytes_identical));
51627+ atomic_read_unchecked(&dev->bytes_identical));
51628 }
51629
51630 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51631@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51632 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51633 struct dlfb_data *dev = fb_info->par;
51634 return snprintf(buf, PAGE_SIZE, "%u\n",
51635- atomic_read(&dev->bytes_sent));
51636+ atomic_read_unchecked(&dev->bytes_sent));
51637 }
51638
51639 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51640@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51641 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51642 struct dlfb_data *dev = fb_info->par;
51643 return snprintf(buf, PAGE_SIZE, "%u\n",
51644- atomic_read(&dev->cpu_kcycles_used));
51645+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51646 }
51647
51648 static ssize_t edid_show(
51649@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51650 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51651 struct dlfb_data *dev = fb_info->par;
51652
51653- atomic_set(&dev->bytes_rendered, 0);
51654- atomic_set(&dev->bytes_identical, 0);
51655- atomic_set(&dev->bytes_sent, 0);
51656- atomic_set(&dev->cpu_kcycles_used, 0);
51657+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51658+ atomic_set_unchecked(&dev->bytes_identical, 0);
51659+ atomic_set_unchecked(&dev->bytes_sent, 0);
51660+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51661
51662 return count;
51663 }
51664diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51665index 7aec6f3..e3b2d55 100644
51666--- a/drivers/video/uvesafb.c
51667+++ b/drivers/video/uvesafb.c
51668@@ -19,6 +19,7 @@
51669 #include <linux/io.h>
51670 #include <linux/mutex.h>
51671 #include <linux/slab.h>
51672+#include <linux/moduleloader.h>
51673 #include <video/edid.h>
51674 #include <video/uvesafb.h>
51675 #ifdef CONFIG_X86
51676@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51677 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51678 par->pmi_setpal = par->ypan = 0;
51679 } else {
51680+
51681+#ifdef CONFIG_PAX_KERNEXEC
51682+#ifdef CONFIG_MODULES
51683+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51684+#endif
51685+ if (!par->pmi_code) {
51686+ par->pmi_setpal = par->ypan = 0;
51687+ return 0;
51688+ }
51689+#endif
51690+
51691 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51692 + task->t.regs.edi);
51693+
51694+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51695+ pax_open_kernel();
51696+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51697+ pax_close_kernel();
51698+
51699+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51700+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51701+#else
51702 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51703 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51704+#endif
51705+
51706 printk(KERN_INFO "uvesafb: protected mode interface info at "
51707 "%04x:%04x\n",
51708 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51709@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51710 par->ypan = ypan;
51711
51712 if (par->pmi_setpal || par->ypan) {
51713+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51714 if (__supported_pte_mask & _PAGE_NX) {
51715 par->pmi_setpal = par->ypan = 0;
51716 printk(KERN_WARNING "uvesafb: NX protection is active, "
51717 "better not use the PMI.\n");
51718- } else {
51719+ } else
51720+#endif
51721 uvesafb_vbe_getpmi(task, par);
51722- }
51723 }
51724 #else
51725 /* The protected mode interface is not available on non-x86. */
51726@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51727 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51728
51729 /* Disable blanking if the user requested so. */
51730- if (!blank)
51731- info->fbops->fb_blank = NULL;
51732+ if (!blank) {
51733+ pax_open_kernel();
51734+ *(void **)&info->fbops->fb_blank = NULL;
51735+ pax_close_kernel();
51736+ }
51737
51738 /*
51739 * Find out how much IO memory is required for the mode with
51740@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51741 info->flags = FBINFO_FLAG_DEFAULT |
51742 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51743
51744- if (!par->ypan)
51745- info->fbops->fb_pan_display = NULL;
51746+ if (!par->ypan) {
51747+ pax_open_kernel();
51748+ *(void **)&info->fbops->fb_pan_display = NULL;
51749+ pax_close_kernel();
51750+ }
51751 }
51752
51753 static void uvesafb_init_mtrr(struct fb_info *info)
51754@@ -1796,6 +1826,11 @@ out:
51755 if (par->vbe_modes)
51756 kfree(par->vbe_modes);
51757
51758+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51759+ if (par->pmi_code)
51760+ module_free_exec(NULL, par->pmi_code);
51761+#endif
51762+
51763 framebuffer_release(info);
51764 return err;
51765 }
51766@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51767 kfree(par->vbe_state_orig);
51768 if (par->vbe_state_saved)
51769 kfree(par->vbe_state_saved);
51770+
51771+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51772+ if (par->pmi_code)
51773+ module_free_exec(NULL, par->pmi_code);
51774+#endif
51775+
51776 }
51777
51778 framebuffer_release(info);
51779diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51780index 501b340..d80aa17 100644
51781--- a/drivers/video/vesafb.c
51782+++ b/drivers/video/vesafb.c
51783@@ -9,6 +9,7 @@
51784 */
51785
51786 #include <linux/module.h>
51787+#include <linux/moduleloader.h>
51788 #include <linux/kernel.h>
51789 #include <linux/errno.h>
51790 #include <linux/string.h>
51791@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
51792 static int vram_total __initdata; /* Set total amount of memory */
51793 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
51794 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
51795-static void (*pmi_start)(void) __read_mostly;
51796-static void (*pmi_pal) (void) __read_mostly;
51797+static void (*pmi_start)(void) __read_only;
51798+static void (*pmi_pal) (void) __read_only;
51799 static int depth __read_mostly;
51800 static int vga_compat __read_mostly;
51801 /* --------------------------------------------------------------------- */
51802@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
51803 unsigned int size_vmode;
51804 unsigned int size_remap;
51805 unsigned int size_total;
51806+ void *pmi_code = NULL;
51807
51808 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
51809 return -ENODEV;
51810@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
51811 size_remap = size_total;
51812 vesafb_fix.smem_len = size_remap;
51813
51814-#ifndef __i386__
51815- screen_info.vesapm_seg = 0;
51816-#endif
51817-
51818 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
51819 printk(KERN_WARNING
51820 "vesafb: cannot reserve video memory at 0x%lx\n",
51821@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
51822 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
51823 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
51824
51825+#ifdef __i386__
51826+
51827+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51828+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
51829+ if (!pmi_code)
51830+#elif !defined(CONFIG_PAX_KERNEXEC)
51831+ if (0)
51832+#endif
51833+
51834+#endif
51835+ screen_info.vesapm_seg = 0;
51836+
51837 if (screen_info.vesapm_seg) {
51838- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
51839- screen_info.vesapm_seg,screen_info.vesapm_off);
51840+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
51841+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
51842 }
51843
51844 if (screen_info.vesapm_seg < 0xc000)
51845@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
51846
51847 if (ypan || pmi_setpal) {
51848 unsigned short *pmi_base;
51849+
51850 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
51851- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
51852- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
51853+
51854+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51855+ pax_open_kernel();
51856+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
51857+#else
51858+ pmi_code = pmi_base;
51859+#endif
51860+
51861+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
51862+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
51863+
51864+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51865+ pmi_start = ktva_ktla(pmi_start);
51866+ pmi_pal = ktva_ktla(pmi_pal);
51867+ pax_close_kernel();
51868+#endif
51869+
51870 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
51871 if (pmi_base[3]) {
51872 printk(KERN_INFO "vesafb: pmi: ports = ");
51873@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51874 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
51875 (ypan ? FBINFO_HWACCEL_YPAN : 0);
51876
51877- if (!ypan)
51878- info->fbops->fb_pan_display = NULL;
51879+ if (!ypan) {
51880+ pax_open_kernel();
51881+ *(void **)&info->fbops->fb_pan_display = NULL;
51882+ pax_close_kernel();
51883+ }
51884
51885 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
51886 err = -ENOMEM;
51887@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51888 info->node, info->fix.id);
51889 return 0;
51890 err:
51891+
51892+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51893+ module_free_exec(NULL, pmi_code);
51894+#endif
51895+
51896 if (info->screen_base)
51897 iounmap(info->screen_base);
51898 framebuffer_release(info);
51899diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
51900index 88714ae..16c2e11 100644
51901--- a/drivers/video/via/via_clock.h
51902+++ b/drivers/video/via/via_clock.h
51903@@ -56,7 +56,7 @@ struct via_clock {
51904
51905 void (*set_engine_pll_state)(u8 state);
51906 void (*set_engine_pll)(struct via_pll_config config);
51907-};
51908+} __no_const;
51909
51910
51911 static inline u32 get_pll_internal_frequency(u32 ref_freq,
51912diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
51913index fef20db..d28b1ab 100644
51914--- a/drivers/xen/xenfs/xenstored.c
51915+++ b/drivers/xen/xenfs/xenstored.c
51916@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
51917 static int xsd_kva_open(struct inode *inode, struct file *file)
51918 {
51919 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
51920+#ifdef CONFIG_GRKERNSEC_HIDESYM
51921+ NULL);
51922+#else
51923 xen_store_interface);
51924+#endif
51925+
51926 if (!file->private_data)
51927 return -ENOMEM;
51928 return 0;
51929diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
51930index 9ff073f..05cef23 100644
51931--- a/fs/9p/vfs_addr.c
51932+++ b/fs/9p/vfs_addr.c
51933@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
51934
51935 retval = v9fs_file_write_internal(inode,
51936 v9inode->writeback_fid,
51937- (__force const char __user *)buffer,
51938+ (const char __force_user *)buffer,
51939 len, &offset, 0);
51940 if (retval > 0)
51941 retval = 0;
51942diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
51943index 25b018e..b941525 100644
51944--- a/fs/9p/vfs_inode.c
51945+++ b/fs/9p/vfs_inode.c
51946@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51947 void
51948 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51949 {
51950- char *s = nd_get_link(nd);
51951+ const char *s = nd_get_link(nd);
51952
51953 p9_debug(P9_DEBUG_VFS, " %s %s\n",
51954 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
51955diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
51956index 370b24c..ff0be7b 100644
51957--- a/fs/Kconfig.binfmt
51958+++ b/fs/Kconfig.binfmt
51959@@ -103,7 +103,7 @@ config HAVE_AOUT
51960
51961 config BINFMT_AOUT
51962 tristate "Kernel support for a.out and ECOFF binaries"
51963- depends on HAVE_AOUT
51964+ depends on HAVE_AOUT && BROKEN
51965 ---help---
51966 A.out (Assembler.OUTput) is a set of formats for libraries and
51967 executables used in the earliest versions of UNIX. Linux used
51968diff --git a/fs/afs/inode.c b/fs/afs/inode.c
51969index 789bc25..fafaeea 100644
51970--- a/fs/afs/inode.c
51971+++ b/fs/afs/inode.c
51972@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51973 struct afs_vnode *vnode;
51974 struct super_block *sb;
51975 struct inode *inode;
51976- static atomic_t afs_autocell_ino;
51977+ static atomic_unchecked_t afs_autocell_ino;
51978
51979 _enter("{%x:%u},%*.*s,",
51980 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
51981@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51982 data.fid.unique = 0;
51983 data.fid.vnode = 0;
51984
51985- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
51986+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
51987 afs_iget5_autocell_test, afs_iget5_set,
51988 &data);
51989 if (!inode) {
51990diff --git a/fs/aio.c b/fs/aio.c
51991index 9b5ca11..c530886 100644
51992--- a/fs/aio.c
51993+++ b/fs/aio.c
51994@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
51995 size += sizeof(struct io_event) * nr_events;
51996 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
51997
51998- if (nr_pages < 0)
51999+ if (nr_pages <= 0)
52000 return -EINVAL;
52001
52002 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52003@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52004 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52005 {
52006 ssize_t ret;
52007+ struct iovec iovstack;
52008
52009 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52010
52011@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52012 if (compat)
52013 ret = compat_rw_copy_check_uvector(rw,
52014 (struct compat_iovec __user *)kiocb->ki_buf,
52015- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52016+ kiocb->ki_nr_segs, 1, &iovstack,
52017 &kiocb->ki_iovec);
52018 else
52019 #endif
52020 ret = rw_copy_check_uvector(rw,
52021 (struct iovec __user *)kiocb->ki_buf,
52022- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52023+ kiocb->ki_nr_segs, 1, &iovstack,
52024 &kiocb->ki_iovec);
52025 if (ret < 0)
52026 return ret;
52027
52028+ if (kiocb->ki_iovec == &iovstack) {
52029+ kiocb->ki_inline_vec = iovstack;
52030+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52031+ }
52032+
52033 /* ki_nbytes now reflect bytes instead of segs */
52034 kiocb->ki_nbytes = ret;
52035 return 0;
52036diff --git a/fs/attr.c b/fs/attr.c
52037index 1449adb..a2038c2 100644
52038--- a/fs/attr.c
52039+++ b/fs/attr.c
52040@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52041 unsigned long limit;
52042
52043 limit = rlimit(RLIMIT_FSIZE);
52044+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52045 if (limit != RLIM_INFINITY && offset > limit)
52046 goto out_sig;
52047 if (offset > inode->i_sb->s_maxbytes)
52048diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52049index 3db70da..7aeec5b 100644
52050--- a/fs/autofs4/waitq.c
52051+++ b/fs/autofs4/waitq.c
52052@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52053 {
52054 unsigned long sigpipe, flags;
52055 mm_segment_t fs;
52056- const char *data = (const char *)addr;
52057+ const char __user *data = (const char __force_user *)addr;
52058 ssize_t wr = 0;
52059
52060 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52061@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52062 return 1;
52063 }
52064
52065+#ifdef CONFIG_GRKERNSEC_HIDESYM
52066+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52067+#endif
52068+
52069 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52070 enum autofs_notify notify)
52071 {
52072@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52073
52074 /* If this is a direct mount request create a dummy name */
52075 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52076+#ifdef CONFIG_GRKERNSEC_HIDESYM
52077+ /* this name does get written to userland via autofs4_write() */
52078+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52079+#else
52080 qstr.len = sprintf(name, "%p", dentry);
52081+#endif
52082 else {
52083 qstr.len = autofs4_getpath(sbi, dentry, &name);
52084 if (!qstr.len) {
52085diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52086index 2722387..c8dd2a7 100644
52087--- a/fs/befs/endian.h
52088+++ b/fs/befs/endian.h
52089@@ -11,7 +11,7 @@
52090
52091 #include <asm/byteorder.h>
52092
52093-static inline u64
52094+static inline u64 __intentional_overflow(-1)
52095 fs64_to_cpu(const struct super_block *sb, fs64 n)
52096 {
52097 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52098@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52099 return (__force fs64)cpu_to_be64(n);
52100 }
52101
52102-static inline u32
52103+static inline u32 __intentional_overflow(-1)
52104 fs32_to_cpu(const struct super_block *sb, fs32 n)
52105 {
52106 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52107diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52108index e9c75e2..1baece1 100644
52109--- a/fs/befs/linuxvfs.c
52110+++ b/fs/befs/linuxvfs.c
52111@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52112 {
52113 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52114 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52115- char *link = nd_get_link(nd);
52116+ const char *link = nd_get_link(nd);
52117 if (!IS_ERR(link))
52118 kfree(link);
52119 }
52120diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52121index 89dec7f..361b0d75 100644
52122--- a/fs/binfmt_aout.c
52123+++ b/fs/binfmt_aout.c
52124@@ -16,6 +16,7 @@
52125 #include <linux/string.h>
52126 #include <linux/fs.h>
52127 #include <linux/file.h>
52128+#include <linux/security.h>
52129 #include <linux/stat.h>
52130 #include <linux/fcntl.h>
52131 #include <linux/ptrace.h>
52132@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52133 #endif
52134 # define START_STACK(u) ((void __user *)u.start_stack)
52135
52136+ memset(&dump, 0, sizeof(dump));
52137+
52138 fs = get_fs();
52139 set_fs(KERNEL_DS);
52140 has_dumped = 1;
52141@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52142
52143 /* If the size of the dump file exceeds the rlimit, then see what would happen
52144 if we wrote the stack, but not the data area. */
52145+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52146 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52147 dump.u_dsize = 0;
52148
52149 /* Make sure we have enough room to write the stack and data areas. */
52150+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52151 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52152 dump.u_ssize = 0;
52153
52154@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52155 rlim = rlimit(RLIMIT_DATA);
52156 if (rlim >= RLIM_INFINITY)
52157 rlim = ~0;
52158+
52159+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52160 if (ex.a_data + ex.a_bss > rlim)
52161 return -ENOMEM;
52162
52163@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52164
52165 install_exec_creds(bprm);
52166
52167+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52168+ current->mm->pax_flags = 0UL;
52169+#endif
52170+
52171+#ifdef CONFIG_PAX_PAGEEXEC
52172+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52173+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52174+
52175+#ifdef CONFIG_PAX_EMUTRAMP
52176+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52177+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52178+#endif
52179+
52180+#ifdef CONFIG_PAX_MPROTECT
52181+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52182+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52183+#endif
52184+
52185+ }
52186+#endif
52187+
52188 if (N_MAGIC(ex) == OMAGIC) {
52189 unsigned long text_addr, map_size;
52190 loff_t pos;
52191@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52192 }
52193
52194 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52195- PROT_READ | PROT_WRITE | PROT_EXEC,
52196+ PROT_READ | PROT_WRITE,
52197 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52198 fd_offset + ex.a_text);
52199 if (error != N_DATADDR(ex)) {
52200diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52201index 4c94a79..f428019 100644
52202--- a/fs/binfmt_elf.c
52203+++ b/fs/binfmt_elf.c
52204@@ -34,6 +34,7 @@
52205 #include <linux/utsname.h>
52206 #include <linux/coredump.h>
52207 #include <linux/sched.h>
52208+#include <linux/xattr.h>
52209 #include <asm/uaccess.h>
52210 #include <asm/param.h>
52211 #include <asm/page.h>
52212@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52213 #define elf_core_dump NULL
52214 #endif
52215
52216+#ifdef CONFIG_PAX_MPROTECT
52217+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52218+#endif
52219+
52220+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52221+static void elf_handle_mmap(struct file *file);
52222+#endif
52223+
52224 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52225 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52226 #else
52227@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52228 .load_binary = load_elf_binary,
52229 .load_shlib = load_elf_library,
52230 .core_dump = elf_core_dump,
52231+
52232+#ifdef CONFIG_PAX_MPROTECT
52233+ .handle_mprotect= elf_handle_mprotect,
52234+#endif
52235+
52236+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52237+ .handle_mmap = elf_handle_mmap,
52238+#endif
52239+
52240 .min_coredump = ELF_EXEC_PAGESIZE,
52241 };
52242
52243@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52244
52245 static int set_brk(unsigned long start, unsigned long end)
52246 {
52247+ unsigned long e = end;
52248+
52249 start = ELF_PAGEALIGN(start);
52250 end = ELF_PAGEALIGN(end);
52251 if (end > start) {
52252@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52253 if (BAD_ADDR(addr))
52254 return addr;
52255 }
52256- current->mm->start_brk = current->mm->brk = end;
52257+ current->mm->start_brk = current->mm->brk = e;
52258 return 0;
52259 }
52260
52261@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52262 elf_addr_t __user *u_rand_bytes;
52263 const char *k_platform = ELF_PLATFORM;
52264 const char *k_base_platform = ELF_BASE_PLATFORM;
52265- unsigned char k_rand_bytes[16];
52266+ u32 k_rand_bytes[4];
52267 int items;
52268 elf_addr_t *elf_info;
52269 int ei_index = 0;
52270 const struct cred *cred = current_cred();
52271 struct vm_area_struct *vma;
52272+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52273
52274 /*
52275 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52276@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52277 * Generate 16 random bytes for userspace PRNG seeding.
52278 */
52279 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52280- u_rand_bytes = (elf_addr_t __user *)
52281- STACK_ALLOC(p, sizeof(k_rand_bytes));
52282+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52283+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52284+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52285+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52286+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52287+ u_rand_bytes = (elf_addr_t __user *) p;
52288 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52289 return -EFAULT;
52290
52291@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52292 return -EFAULT;
52293 current->mm->env_end = p;
52294
52295+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52296+
52297 /* Put the elf_info on the stack in the right place. */
52298 sp = (elf_addr_t __user *)envp + 1;
52299- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52300+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52301 return -EFAULT;
52302 return 0;
52303 }
52304@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52305 an ELF header */
52306
52307 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52308- struct file *interpreter, unsigned long *interp_map_addr,
52309- unsigned long no_base)
52310+ struct file *interpreter, unsigned long no_base)
52311 {
52312 struct elf_phdr *elf_phdata;
52313 struct elf_phdr *eppnt;
52314- unsigned long load_addr = 0;
52315+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52316 int load_addr_set = 0;
52317 unsigned long last_bss = 0, elf_bss = 0;
52318- unsigned long error = ~0UL;
52319+ unsigned long error = -EINVAL;
52320 unsigned long total_size;
52321 int retval, i, size;
52322
52323@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52324 goto out_close;
52325 }
52326
52327+#ifdef CONFIG_PAX_SEGMEXEC
52328+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52329+ pax_task_size = SEGMEXEC_TASK_SIZE;
52330+#endif
52331+
52332 eppnt = elf_phdata;
52333 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52334 if (eppnt->p_type == PT_LOAD) {
52335@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52336 map_addr = elf_map(interpreter, load_addr + vaddr,
52337 eppnt, elf_prot, elf_type, total_size);
52338 total_size = 0;
52339- if (!*interp_map_addr)
52340- *interp_map_addr = map_addr;
52341 error = map_addr;
52342 if (BAD_ADDR(map_addr))
52343 goto out_close;
52344@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52345 k = load_addr + eppnt->p_vaddr;
52346 if (BAD_ADDR(k) ||
52347 eppnt->p_filesz > eppnt->p_memsz ||
52348- eppnt->p_memsz > TASK_SIZE ||
52349- TASK_SIZE - eppnt->p_memsz < k) {
52350+ eppnt->p_memsz > pax_task_size ||
52351+ pax_task_size - eppnt->p_memsz < k) {
52352 error = -ENOMEM;
52353 goto out_close;
52354 }
52355@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52356 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52357
52358 /* Map the last of the bss segment */
52359- error = vm_brk(elf_bss, last_bss - elf_bss);
52360- if (BAD_ADDR(error))
52361- goto out_close;
52362+ if (last_bss > elf_bss) {
52363+ error = vm_brk(elf_bss, last_bss - elf_bss);
52364+ if (BAD_ADDR(error))
52365+ goto out_close;
52366+ }
52367 }
52368
52369 error = load_addr;
52370@@ -538,6 +569,315 @@ out:
52371 return error;
52372 }
52373
52374+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52375+#ifdef CONFIG_PAX_SOFTMODE
52376+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52377+{
52378+ unsigned long pax_flags = 0UL;
52379+
52380+#ifdef CONFIG_PAX_PAGEEXEC
52381+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52382+ pax_flags |= MF_PAX_PAGEEXEC;
52383+#endif
52384+
52385+#ifdef CONFIG_PAX_SEGMEXEC
52386+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52387+ pax_flags |= MF_PAX_SEGMEXEC;
52388+#endif
52389+
52390+#ifdef CONFIG_PAX_EMUTRAMP
52391+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52392+ pax_flags |= MF_PAX_EMUTRAMP;
52393+#endif
52394+
52395+#ifdef CONFIG_PAX_MPROTECT
52396+ if (elf_phdata->p_flags & PF_MPROTECT)
52397+ pax_flags |= MF_PAX_MPROTECT;
52398+#endif
52399+
52400+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52401+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52402+ pax_flags |= MF_PAX_RANDMMAP;
52403+#endif
52404+
52405+ return pax_flags;
52406+}
52407+#endif
52408+
52409+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52410+{
52411+ unsigned long pax_flags = 0UL;
52412+
52413+#ifdef CONFIG_PAX_PAGEEXEC
52414+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52415+ pax_flags |= MF_PAX_PAGEEXEC;
52416+#endif
52417+
52418+#ifdef CONFIG_PAX_SEGMEXEC
52419+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52420+ pax_flags |= MF_PAX_SEGMEXEC;
52421+#endif
52422+
52423+#ifdef CONFIG_PAX_EMUTRAMP
52424+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52425+ pax_flags |= MF_PAX_EMUTRAMP;
52426+#endif
52427+
52428+#ifdef CONFIG_PAX_MPROTECT
52429+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52430+ pax_flags |= MF_PAX_MPROTECT;
52431+#endif
52432+
52433+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52434+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52435+ pax_flags |= MF_PAX_RANDMMAP;
52436+#endif
52437+
52438+ return pax_flags;
52439+}
52440+#endif
52441+
52442+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52443+#ifdef CONFIG_PAX_SOFTMODE
52444+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52445+{
52446+ unsigned long pax_flags = 0UL;
52447+
52448+#ifdef CONFIG_PAX_PAGEEXEC
52449+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52450+ pax_flags |= MF_PAX_PAGEEXEC;
52451+#endif
52452+
52453+#ifdef CONFIG_PAX_SEGMEXEC
52454+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52455+ pax_flags |= MF_PAX_SEGMEXEC;
52456+#endif
52457+
52458+#ifdef CONFIG_PAX_EMUTRAMP
52459+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52460+ pax_flags |= MF_PAX_EMUTRAMP;
52461+#endif
52462+
52463+#ifdef CONFIG_PAX_MPROTECT
52464+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52465+ pax_flags |= MF_PAX_MPROTECT;
52466+#endif
52467+
52468+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52469+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52470+ pax_flags |= MF_PAX_RANDMMAP;
52471+#endif
52472+
52473+ return pax_flags;
52474+}
52475+#endif
52476+
52477+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52478+{
52479+ unsigned long pax_flags = 0UL;
52480+
52481+#ifdef CONFIG_PAX_PAGEEXEC
52482+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52483+ pax_flags |= MF_PAX_PAGEEXEC;
52484+#endif
52485+
52486+#ifdef CONFIG_PAX_SEGMEXEC
52487+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52488+ pax_flags |= MF_PAX_SEGMEXEC;
52489+#endif
52490+
52491+#ifdef CONFIG_PAX_EMUTRAMP
52492+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52493+ pax_flags |= MF_PAX_EMUTRAMP;
52494+#endif
52495+
52496+#ifdef CONFIG_PAX_MPROTECT
52497+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52498+ pax_flags |= MF_PAX_MPROTECT;
52499+#endif
52500+
52501+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52502+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52503+ pax_flags |= MF_PAX_RANDMMAP;
52504+#endif
52505+
52506+ return pax_flags;
52507+}
52508+#endif
52509+
52510+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52511+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52512+{
52513+ unsigned long pax_flags = 0UL;
52514+
52515+#ifdef CONFIG_PAX_EI_PAX
52516+
52517+#ifdef CONFIG_PAX_PAGEEXEC
52518+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52519+ pax_flags |= MF_PAX_PAGEEXEC;
52520+#endif
52521+
52522+#ifdef CONFIG_PAX_SEGMEXEC
52523+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52524+ pax_flags |= MF_PAX_SEGMEXEC;
52525+#endif
52526+
52527+#ifdef CONFIG_PAX_EMUTRAMP
52528+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52529+ pax_flags |= MF_PAX_EMUTRAMP;
52530+#endif
52531+
52532+#ifdef CONFIG_PAX_MPROTECT
52533+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52534+ pax_flags |= MF_PAX_MPROTECT;
52535+#endif
52536+
52537+#ifdef CONFIG_PAX_ASLR
52538+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52539+ pax_flags |= MF_PAX_RANDMMAP;
52540+#endif
52541+
52542+#else
52543+
52544+#ifdef CONFIG_PAX_PAGEEXEC
52545+ pax_flags |= MF_PAX_PAGEEXEC;
52546+#endif
52547+
52548+#ifdef CONFIG_PAX_SEGMEXEC
52549+ pax_flags |= MF_PAX_SEGMEXEC;
52550+#endif
52551+
52552+#ifdef CONFIG_PAX_MPROTECT
52553+ pax_flags |= MF_PAX_MPROTECT;
52554+#endif
52555+
52556+#ifdef CONFIG_PAX_RANDMMAP
52557+ if (randomize_va_space)
52558+ pax_flags |= MF_PAX_RANDMMAP;
52559+#endif
52560+
52561+#endif
52562+
52563+ return pax_flags;
52564+}
52565+
52566+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52567+{
52568+
52569+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52570+ unsigned long i;
52571+
52572+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52573+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52574+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52575+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52576+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52577+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52578+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52579+ return ~0UL;
52580+
52581+#ifdef CONFIG_PAX_SOFTMODE
52582+ if (pax_softmode)
52583+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52584+ else
52585+#endif
52586+
52587+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52588+ break;
52589+ }
52590+#endif
52591+
52592+ return ~0UL;
52593+}
52594+
52595+static unsigned long pax_parse_xattr_pax(struct file * const file)
52596+{
52597+
52598+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52599+ ssize_t xattr_size, i;
52600+ unsigned char xattr_value[sizeof("pemrs") - 1];
52601+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52602+
52603+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52604+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52605+ return ~0UL;
52606+
52607+ for (i = 0; i < xattr_size; i++)
52608+ switch (xattr_value[i]) {
52609+ default:
52610+ return ~0UL;
52611+
52612+#define parse_flag(option1, option2, flag) \
52613+ case option1: \
52614+ if (pax_flags_hardmode & MF_PAX_##flag) \
52615+ return ~0UL; \
52616+ pax_flags_hardmode |= MF_PAX_##flag; \
52617+ break; \
52618+ case option2: \
52619+ if (pax_flags_softmode & MF_PAX_##flag) \
52620+ return ~0UL; \
52621+ pax_flags_softmode |= MF_PAX_##flag; \
52622+ break;
52623+
52624+ parse_flag('p', 'P', PAGEEXEC);
52625+ parse_flag('e', 'E', EMUTRAMP);
52626+ parse_flag('m', 'M', MPROTECT);
52627+ parse_flag('r', 'R', RANDMMAP);
52628+ parse_flag('s', 'S', SEGMEXEC);
52629+
52630+#undef parse_flag
52631+ }
52632+
52633+ if (pax_flags_hardmode & pax_flags_softmode)
52634+ return ~0UL;
52635+
52636+#ifdef CONFIG_PAX_SOFTMODE
52637+ if (pax_softmode)
52638+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52639+ else
52640+#endif
52641+
52642+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52643+#else
52644+ return ~0UL;
52645+#endif
52646+
52647+}
52648+
52649+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52650+{
52651+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52652+
52653+ pax_flags = pax_parse_ei_pax(elf_ex);
52654+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52655+ xattr_pax_flags = pax_parse_xattr_pax(file);
52656+
52657+ if (pt_pax_flags == ~0UL)
52658+ pt_pax_flags = xattr_pax_flags;
52659+ else if (xattr_pax_flags == ~0UL)
52660+ xattr_pax_flags = pt_pax_flags;
52661+ if (pt_pax_flags != xattr_pax_flags)
52662+ return -EINVAL;
52663+ if (pt_pax_flags != ~0UL)
52664+ pax_flags = pt_pax_flags;
52665+
52666+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52667+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52668+ if ((__supported_pte_mask & _PAGE_NX))
52669+ pax_flags &= ~MF_PAX_SEGMEXEC;
52670+ else
52671+ pax_flags &= ~MF_PAX_PAGEEXEC;
52672+ }
52673+#endif
52674+
52675+ if (0 > pax_check_flags(&pax_flags))
52676+ return -EINVAL;
52677+
52678+ current->mm->pax_flags = pax_flags;
52679+ return 0;
52680+}
52681+#endif
52682+
52683 /*
52684 * These are the functions used to load ELF style executables and shared
52685 * libraries. There is no binary dependent code anywhere else.
52686@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52687 {
52688 unsigned int random_variable = 0;
52689
52690+#ifdef CONFIG_PAX_RANDUSTACK
52691+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52692+ return stack_top - current->mm->delta_stack;
52693+#endif
52694+
52695 if ((current->flags & PF_RANDOMIZE) &&
52696 !(current->personality & ADDR_NO_RANDOMIZE)) {
52697 random_variable = get_random_int() & STACK_RND_MASK;
52698@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52699 unsigned long load_addr = 0, load_bias = 0;
52700 int load_addr_set = 0;
52701 char * elf_interpreter = NULL;
52702- unsigned long error;
52703+ unsigned long error = 0;
52704 struct elf_phdr *elf_ppnt, *elf_phdata;
52705 unsigned long elf_bss, elf_brk;
52706 int retval, i;
52707@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52708 unsigned long start_code, end_code, start_data, end_data;
52709 unsigned long reloc_func_desc __maybe_unused = 0;
52710 int executable_stack = EXSTACK_DEFAULT;
52711- unsigned long def_flags = 0;
52712 struct pt_regs *regs = current_pt_regs();
52713 struct {
52714 struct elfhdr elf_ex;
52715 struct elfhdr interp_elf_ex;
52716 } *loc;
52717+ unsigned long pax_task_size = TASK_SIZE;
52718
52719 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52720 if (!loc) {
52721@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52722 goto out_free_dentry;
52723
52724 /* OK, This is the point of no return */
52725- current->mm->def_flags = def_flags;
52726+
52727+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52728+ current->mm->pax_flags = 0UL;
52729+#endif
52730+
52731+#ifdef CONFIG_PAX_DLRESOLVE
52732+ current->mm->call_dl_resolve = 0UL;
52733+#endif
52734+
52735+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52736+ current->mm->call_syscall = 0UL;
52737+#endif
52738+
52739+#ifdef CONFIG_PAX_ASLR
52740+ current->mm->delta_mmap = 0UL;
52741+ current->mm->delta_stack = 0UL;
52742+#endif
52743+
52744+ current->mm->def_flags = 0;
52745+
52746+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52747+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52748+ send_sig(SIGKILL, current, 0);
52749+ goto out_free_dentry;
52750+ }
52751+#endif
52752+
52753+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52754+ pax_set_initial_flags(bprm);
52755+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52756+ if (pax_set_initial_flags_func)
52757+ (pax_set_initial_flags_func)(bprm);
52758+#endif
52759+
52760+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52761+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52762+ current->mm->context.user_cs_limit = PAGE_SIZE;
52763+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52764+ }
52765+#endif
52766+
52767+#ifdef CONFIG_PAX_SEGMEXEC
52768+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52769+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52770+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52771+ pax_task_size = SEGMEXEC_TASK_SIZE;
52772+ current->mm->def_flags |= VM_NOHUGEPAGE;
52773+ }
52774+#endif
52775+
52776+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52777+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52778+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52779+ put_cpu();
52780+ }
52781+#endif
52782
52783 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52784 may depend on the personality. */
52785 SET_PERSONALITY(loc->elf_ex);
52786+
52787+#ifdef CONFIG_PAX_ASLR
52788+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52789+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52790+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52791+ }
52792+#endif
52793+
52794+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52795+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52796+ executable_stack = EXSTACK_DISABLE_X;
52797+ current->personality &= ~READ_IMPLIES_EXEC;
52798+ } else
52799+#endif
52800+
52801 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52802 current->personality |= READ_IMPLIES_EXEC;
52803
52804@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52805 #else
52806 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
52807 #endif
52808+
52809+#ifdef CONFIG_PAX_RANDMMAP
52810+ /* PaX: randomize base address at the default exe base if requested */
52811+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
52812+#ifdef CONFIG_SPARC64
52813+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
52814+#else
52815+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
52816+#endif
52817+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
52818+ elf_flags |= MAP_FIXED;
52819+ }
52820+#endif
52821+
52822 }
52823
52824 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
52825@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
52826 * allowed task size. Note that p_filesz must always be
52827 * <= p_memsz so it is only necessary to check p_memsz.
52828 */
52829- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52830- elf_ppnt->p_memsz > TASK_SIZE ||
52831- TASK_SIZE - elf_ppnt->p_memsz < k) {
52832+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52833+ elf_ppnt->p_memsz > pax_task_size ||
52834+ pax_task_size - elf_ppnt->p_memsz < k) {
52835 /* set_brk can never work. Avoid overflows. */
52836 send_sig(SIGKILL, current, 0);
52837 retval = -EINVAL;
52838@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
52839 goto out_free_dentry;
52840 }
52841 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
52842- send_sig(SIGSEGV, current, 0);
52843- retval = -EFAULT; /* Nobody gets to see this, but.. */
52844- goto out_free_dentry;
52845+ /*
52846+ * This bss-zeroing can fail if the ELF
52847+ * file specifies odd protections. So
52848+ * we don't check the return value
52849+ */
52850 }
52851
52852+#ifdef CONFIG_PAX_RANDMMAP
52853+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52854+ unsigned long start, size, flags;
52855+ vm_flags_t vm_flags;
52856+
52857+ start = ELF_PAGEALIGN(elf_brk);
52858+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
52859+ flags = MAP_FIXED | MAP_PRIVATE;
52860+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
52861+
52862+ down_write(&current->mm->mmap_sem);
52863+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
52864+ retval = -ENOMEM;
52865+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
52866+// if (current->personality & ADDR_NO_RANDOMIZE)
52867+// vm_flags |= VM_READ | VM_MAYREAD;
52868+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
52869+ retval = IS_ERR_VALUE(start) ? start : 0;
52870+ }
52871+ up_write(&current->mm->mmap_sem);
52872+ if (retval == 0)
52873+ retval = set_brk(start + size, start + size + PAGE_SIZE);
52874+ if (retval < 0) {
52875+ send_sig(SIGKILL, current, 0);
52876+ goto out_free_dentry;
52877+ }
52878+ }
52879+#endif
52880+
52881 if (elf_interpreter) {
52882- unsigned long interp_map_addr = 0;
52883-
52884 elf_entry = load_elf_interp(&loc->interp_elf_ex,
52885 interpreter,
52886- &interp_map_addr,
52887 load_bias);
52888 if (!IS_ERR((void *)elf_entry)) {
52889 /*
52890@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
52891 * Decide what to dump of a segment, part, all or none.
52892 */
52893 static unsigned long vma_dump_size(struct vm_area_struct *vma,
52894- unsigned long mm_flags)
52895+ unsigned long mm_flags, long signr)
52896 {
52897 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
52898
52899@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
52900 if (vma->vm_file == NULL)
52901 return 0;
52902
52903- if (FILTER(MAPPED_PRIVATE))
52904+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
52905 goto whole;
52906
52907 /*
52908@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
52909 {
52910 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
52911 int i = 0;
52912- do
52913+ do {
52914 i += 2;
52915- while (auxv[i - 2] != AT_NULL);
52916+ } while (auxv[i - 2] != AT_NULL);
52917 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
52918 }
52919
52920@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
52921 {
52922 mm_segment_t old_fs = get_fs();
52923 set_fs(KERNEL_DS);
52924- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
52925+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
52926 set_fs(old_fs);
52927 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
52928 }
52929@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
52930 }
52931
52932 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
52933- unsigned long mm_flags)
52934+ struct coredump_params *cprm)
52935 {
52936 struct vm_area_struct *vma;
52937 size_t size = 0;
52938
52939 for (vma = first_vma(current, gate_vma); vma != NULL;
52940 vma = next_vma(vma, gate_vma))
52941- size += vma_dump_size(vma, mm_flags);
52942+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52943 return size;
52944 }
52945
52946@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52947
52948 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
52949
52950- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
52951+ offset += elf_core_vma_data_size(gate_vma, cprm);
52952 offset += elf_core_extra_data_size();
52953 e_shoff = offset;
52954
52955@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
52956 offset = dataoff;
52957
52958 size += sizeof(*elf);
52959+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52960 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
52961 goto end_coredump;
52962
52963 size += sizeof(*phdr4note);
52964+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52965 if (size > cprm->limit
52966 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
52967 goto end_coredump;
52968@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52969 phdr.p_offset = offset;
52970 phdr.p_vaddr = vma->vm_start;
52971 phdr.p_paddr = 0;
52972- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
52973+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52974 phdr.p_memsz = vma->vm_end - vma->vm_start;
52975 offset += phdr.p_filesz;
52976 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
52977@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52978 phdr.p_align = ELF_EXEC_PAGESIZE;
52979
52980 size += sizeof(phdr);
52981+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52982 if (size > cprm->limit
52983 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
52984 goto end_coredump;
52985@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52986 unsigned long addr;
52987 unsigned long end;
52988
52989- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
52990+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52991
52992 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
52993 struct page *page;
52994@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52995 page = get_dump_page(addr);
52996 if (page) {
52997 void *kaddr = kmap(page);
52998+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
52999 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53000 !dump_write(cprm->file, kaddr,
53001 PAGE_SIZE);
53002@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53003
53004 if (e_phnum == PN_XNUM) {
53005 size += sizeof(*shdr4extnum);
53006+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53007 if (size > cprm->limit
53008 || !dump_write(cprm->file, shdr4extnum,
53009 sizeof(*shdr4extnum)))
53010@@ -2235,6 +2697,167 @@ out:
53011
53012 #endif /* CONFIG_ELF_CORE */
53013
53014+#ifdef CONFIG_PAX_MPROTECT
53015+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53016+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53017+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53018+ *
53019+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53020+ * basis because we want to allow the common case and not the special ones.
53021+ */
53022+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53023+{
53024+ struct elfhdr elf_h;
53025+ struct elf_phdr elf_p;
53026+ unsigned long i;
53027+ unsigned long oldflags;
53028+ bool is_textrel_rw, is_textrel_rx, is_relro;
53029+
53030+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53031+ return;
53032+
53033+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53034+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53035+
53036+#ifdef CONFIG_PAX_ELFRELOCS
53037+ /* possible TEXTREL */
53038+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53039+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53040+#else
53041+ is_textrel_rw = false;
53042+ is_textrel_rx = false;
53043+#endif
53044+
53045+ /* possible RELRO */
53046+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53047+
53048+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53049+ return;
53050+
53051+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53052+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53053+
53054+#ifdef CONFIG_PAX_ETEXECRELOCS
53055+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53056+#else
53057+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53058+#endif
53059+
53060+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53061+ !elf_check_arch(&elf_h) ||
53062+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53063+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53064+ return;
53065+
53066+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53067+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53068+ return;
53069+ switch (elf_p.p_type) {
53070+ case PT_DYNAMIC:
53071+ if (!is_textrel_rw && !is_textrel_rx)
53072+ continue;
53073+ i = 0UL;
53074+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53075+ elf_dyn dyn;
53076+
53077+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53078+ break;
53079+ if (dyn.d_tag == DT_NULL)
53080+ break;
53081+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53082+ gr_log_textrel(vma);
53083+ if (is_textrel_rw)
53084+ vma->vm_flags |= VM_MAYWRITE;
53085+ else
53086+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53087+ vma->vm_flags &= ~VM_MAYWRITE;
53088+ break;
53089+ }
53090+ i++;
53091+ }
53092+ is_textrel_rw = false;
53093+ is_textrel_rx = false;
53094+ continue;
53095+
53096+ case PT_GNU_RELRO:
53097+ if (!is_relro)
53098+ continue;
53099+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53100+ vma->vm_flags &= ~VM_MAYWRITE;
53101+ is_relro = false;
53102+ continue;
53103+
53104+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53105+ case PT_PAX_FLAGS: {
53106+ const char *msg_mprotect = "", *msg_emutramp = "";
53107+ char *buffer_lib, *buffer_exe;
53108+
53109+ if (elf_p.p_flags & PF_NOMPROTECT)
53110+ msg_mprotect = "MPROTECT disabled";
53111+
53112+#ifdef CONFIG_PAX_EMUTRAMP
53113+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53114+ msg_emutramp = "EMUTRAMP enabled";
53115+#endif
53116+
53117+ if (!msg_mprotect[0] && !msg_emutramp[0])
53118+ continue;
53119+
53120+ if (!printk_ratelimit())
53121+ continue;
53122+
53123+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53124+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53125+ if (buffer_lib && buffer_exe) {
53126+ char *path_lib, *path_exe;
53127+
53128+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53129+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53130+
53131+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53132+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53133+
53134+ }
53135+ free_page((unsigned long)buffer_exe);
53136+ free_page((unsigned long)buffer_lib);
53137+ continue;
53138+ }
53139+#endif
53140+
53141+ }
53142+ }
53143+}
53144+#endif
53145+
53146+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53147+
53148+extern int grsec_enable_log_rwxmaps;
53149+
53150+static void elf_handle_mmap(struct file *file)
53151+{
53152+ struct elfhdr elf_h;
53153+ struct elf_phdr elf_p;
53154+ unsigned long i;
53155+
53156+ if (!grsec_enable_log_rwxmaps)
53157+ return;
53158+
53159+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53160+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53161+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53162+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53163+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53164+ return;
53165+
53166+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53167+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53168+ return;
53169+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53170+ gr_log_ptgnustack(file);
53171+ }
53172+}
53173+#endif
53174+
53175 static int __init init_elf_binfmt(void)
53176 {
53177 register_binfmt(&elf_format);
53178diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53179index d50bbe5..af3b649 100644
53180--- a/fs/binfmt_flat.c
53181+++ b/fs/binfmt_flat.c
53182@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53183 realdatastart = (unsigned long) -ENOMEM;
53184 printk("Unable to allocate RAM for process data, errno %d\n",
53185 (int)-realdatastart);
53186+ down_write(&current->mm->mmap_sem);
53187 vm_munmap(textpos, text_len);
53188+ up_write(&current->mm->mmap_sem);
53189 ret = realdatastart;
53190 goto err;
53191 }
53192@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53193 }
53194 if (IS_ERR_VALUE(result)) {
53195 printk("Unable to read data+bss, errno %d\n", (int)-result);
53196+ down_write(&current->mm->mmap_sem);
53197 vm_munmap(textpos, text_len);
53198 vm_munmap(realdatastart, len);
53199+ up_write(&current->mm->mmap_sem);
53200 ret = result;
53201 goto err;
53202 }
53203@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53204 }
53205 if (IS_ERR_VALUE(result)) {
53206 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53207+ down_write(&current->mm->mmap_sem);
53208 vm_munmap(textpos, text_len + data_len + extra +
53209 MAX_SHARED_LIBS * sizeof(unsigned long));
53210+ up_write(&current->mm->mmap_sem);
53211 ret = result;
53212 goto err;
53213 }
53214diff --git a/fs/bio.c b/fs/bio.c
53215index 5e7507d..418c639 100644
53216--- a/fs/bio.c
53217+++ b/fs/bio.c
53218@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53219 /*
53220 * Overflow, abort
53221 */
53222- if (end < start)
53223+ if (end < start || end - start > INT_MAX - nr_pages)
53224 return ERR_PTR(-EINVAL);
53225
53226 nr_pages += end - start;
53227@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53228 /*
53229 * Overflow, abort
53230 */
53231- if (end < start)
53232+ if (end < start || end - start > INT_MAX - nr_pages)
53233 return ERR_PTR(-EINVAL);
53234
53235 nr_pages += end - start;
53236@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53237 const int read = bio_data_dir(bio) == READ;
53238 struct bio_map_data *bmd = bio->bi_private;
53239 int i;
53240- char *p = bmd->sgvecs[0].iov_base;
53241+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53242
53243 bio_for_each_segment_all(bvec, bio, i) {
53244 char *addr = page_address(bvec->bv_page);
53245diff --git a/fs/block_dev.c b/fs/block_dev.c
53246index c7bda5c..2121e94 100644
53247--- a/fs/block_dev.c
53248+++ b/fs/block_dev.c
53249@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53250 else if (bdev->bd_contains == bdev)
53251 return true; /* is a whole device which isn't held */
53252
53253- else if (whole->bd_holder == bd_may_claim)
53254+ else if (whole->bd_holder == (void *)bd_may_claim)
53255 return true; /* is a partition of a device that is being partitioned */
53256 else if (whole->bd_holder != NULL)
53257 return false; /* is a partition of a held device */
53258diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53259index ed50460..fe84385 100644
53260--- a/fs/btrfs/ctree.c
53261+++ b/fs/btrfs/ctree.c
53262@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53263 free_extent_buffer(buf);
53264 add_root_to_dirty_list(root);
53265 } else {
53266- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53267- parent_start = parent->start;
53268- else
53269+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53270+ if (parent)
53271+ parent_start = parent->start;
53272+ else
53273+ parent_start = 0;
53274+ } else
53275 parent_start = 0;
53276
53277 WARN_ON(trans->transid != btrfs_header_generation(parent));
53278diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53279index 3755109..e3d457f 100644
53280--- a/fs/btrfs/delayed-inode.c
53281+++ b/fs/btrfs/delayed-inode.c
53282@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53283
53284 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53285 {
53286- int seq = atomic_inc_return(&delayed_root->items_seq);
53287+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53288 if ((atomic_dec_return(&delayed_root->items) <
53289 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53290 waitqueue_active(&delayed_root->wait))
53291@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53292 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53293 int seq, int count)
53294 {
53295- int val = atomic_read(&delayed_root->items_seq);
53296+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53297
53298 if (val < seq || val >= seq + count)
53299 return 1;
53300@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53301 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53302 return;
53303
53304- seq = atomic_read(&delayed_root->items_seq);
53305+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53306
53307 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53308 int ret;
53309diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53310index a4b38f9..f86a509 100644
53311--- a/fs/btrfs/delayed-inode.h
53312+++ b/fs/btrfs/delayed-inode.h
53313@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53314 */
53315 struct list_head prepare_list;
53316 atomic_t items; /* for delayed items */
53317- atomic_t items_seq; /* for delayed items */
53318+ atomic_unchecked_t items_seq; /* for delayed items */
53319 int nodes; /* for delayed nodes */
53320 wait_queue_head_t wait;
53321 };
53322@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53323 struct btrfs_delayed_root *delayed_root)
53324 {
53325 atomic_set(&delayed_root->items, 0);
53326- atomic_set(&delayed_root->items_seq, 0);
53327+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53328 delayed_root->nodes = 0;
53329 spin_lock_init(&delayed_root->lock);
53330 init_waitqueue_head(&delayed_root->wait);
53331diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53332index 9877a2a..7ebf9ab 100644
53333--- a/fs/btrfs/ioctl.c
53334+++ b/fs/btrfs/ioctl.c
53335@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53336 for (i = 0; i < num_types; i++) {
53337 struct btrfs_space_info *tmp;
53338
53339+ /* Don't copy in more than we allocated */
53340 if (!slot_count)
53341 break;
53342
53343+ slot_count--;
53344+
53345 info = NULL;
53346 rcu_read_lock();
53347 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53348@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53349 memcpy(dest, &space, sizeof(space));
53350 dest++;
53351 space_args.total_spaces++;
53352- slot_count--;
53353 }
53354- if (!slot_count)
53355- break;
53356 }
53357 up_read(&info->groups_sem);
53358 }
53359diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53360index 8eb6191..eda91e2 100644
53361--- a/fs/btrfs/super.c
53362+++ b/fs/btrfs/super.c
53363@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53364 function, line, errstr);
53365 return;
53366 }
53367- ACCESS_ONCE(trans->transaction->aborted) = errno;
53368+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53369 /* Wake up anybody who may be waiting on this transaction */
53370 wake_up(&root->fs_info->transaction_wait);
53371 wake_up(&root->fs_info->transaction_blocked_wait);
53372diff --git a/fs/buffer.c b/fs/buffer.c
53373index 4d74335..7bd000a 100644
53374--- a/fs/buffer.c
53375+++ b/fs/buffer.c
53376@@ -1005,9 +1005,19 @@ grow_dev_page(struct block_device *bdev, sector_t block,
53377 struct buffer_head *bh;
53378 sector_t end_block;
53379 int ret = 0; /* Will call free_more_memory() */
53380+ gfp_t gfp_mask;
53381
53382- page = find_or_create_page(inode->i_mapping, index,
53383- (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE);
53384+ gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS;
53385+ gfp_mask |= __GFP_MOVABLE;
53386+ /*
53387+ * XXX: __getblk_slow() can not really deal with failure and
53388+ * will endlessly loop on improvised global reclaim. Prefer
53389+ * looping in the allocator rather than here, at least that
53390+ * code knows what it's doing.
53391+ */
53392+ gfp_mask |= __GFP_NOFAIL;
53393+
53394+ page = find_or_create_page(inode->i_mapping, index, gfp_mask);
53395 if (!page)
53396 return ret;
53397
53398@@ -3416,7 +3426,7 @@ void __init buffer_init(void)
53399 bh_cachep = kmem_cache_create("buffer_head",
53400 sizeof(struct buffer_head), 0,
53401 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53402- SLAB_MEM_SPREAD),
53403+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53404 NULL);
53405
53406 /*
53407diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53408index 622f469..e8d2d55 100644
53409--- a/fs/cachefiles/bind.c
53410+++ b/fs/cachefiles/bind.c
53411@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53412 args);
53413
53414 /* start by checking things over */
53415- ASSERT(cache->fstop_percent >= 0 &&
53416- cache->fstop_percent < cache->fcull_percent &&
53417+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53418 cache->fcull_percent < cache->frun_percent &&
53419 cache->frun_percent < 100);
53420
53421- ASSERT(cache->bstop_percent >= 0 &&
53422- cache->bstop_percent < cache->bcull_percent &&
53423+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53424 cache->bcull_percent < cache->brun_percent &&
53425 cache->brun_percent < 100);
53426
53427diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53428index 0a1467b..6a53245 100644
53429--- a/fs/cachefiles/daemon.c
53430+++ b/fs/cachefiles/daemon.c
53431@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53432 if (n > buflen)
53433 return -EMSGSIZE;
53434
53435- if (copy_to_user(_buffer, buffer, n) != 0)
53436+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53437 return -EFAULT;
53438
53439 return n;
53440@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53441 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53442 return -EIO;
53443
53444- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53445+ if (datalen > PAGE_SIZE - 1)
53446 return -EOPNOTSUPP;
53447
53448 /* drag the command string into the kernel so we can parse it */
53449@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53450 if (args[0] != '%' || args[1] != '\0')
53451 return -EINVAL;
53452
53453- if (fstop < 0 || fstop >= cache->fcull_percent)
53454+ if (fstop >= cache->fcull_percent)
53455 return cachefiles_daemon_range_error(cache, args);
53456
53457 cache->fstop_percent = fstop;
53458@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53459 if (args[0] != '%' || args[1] != '\0')
53460 return -EINVAL;
53461
53462- if (bstop < 0 || bstop >= cache->bcull_percent)
53463+ if (bstop >= cache->bcull_percent)
53464 return cachefiles_daemon_range_error(cache, args);
53465
53466 cache->bstop_percent = bstop;
53467diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53468index 4938251..7e01445 100644
53469--- a/fs/cachefiles/internal.h
53470+++ b/fs/cachefiles/internal.h
53471@@ -59,7 +59,7 @@ struct cachefiles_cache {
53472 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53473 struct rb_root active_nodes; /* active nodes (can't be culled) */
53474 rwlock_t active_lock; /* lock for active_nodes */
53475- atomic_t gravecounter; /* graveyard uniquifier */
53476+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53477 unsigned frun_percent; /* when to stop culling (% files) */
53478 unsigned fcull_percent; /* when to start culling (% files) */
53479 unsigned fstop_percent; /* when to stop allocating (% files) */
53480@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53481 * proc.c
53482 */
53483 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53484-extern atomic_t cachefiles_lookup_histogram[HZ];
53485-extern atomic_t cachefiles_mkdir_histogram[HZ];
53486-extern atomic_t cachefiles_create_histogram[HZ];
53487+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53488+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53489+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53490
53491 extern int __init cachefiles_proc_init(void);
53492 extern void cachefiles_proc_cleanup(void);
53493 static inline
53494-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53495+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53496 {
53497 unsigned long jif = jiffies - start_jif;
53498 if (jif >= HZ)
53499 jif = HZ - 1;
53500- atomic_inc(&histogram[jif]);
53501+ atomic_inc_unchecked(&histogram[jif]);
53502 }
53503
53504 #else
53505diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53506index 25badd1..d70d918 100644
53507--- a/fs/cachefiles/namei.c
53508+++ b/fs/cachefiles/namei.c
53509@@ -317,7 +317,7 @@ try_again:
53510 /* first step is to make up a grave dentry in the graveyard */
53511 sprintf(nbuffer, "%08x%08x",
53512 (uint32_t) get_seconds(),
53513- (uint32_t) atomic_inc_return(&cache->gravecounter));
53514+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53515
53516 /* do the multiway lock magic */
53517 trap = lock_rename(cache->graveyard, dir);
53518diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53519index eccd339..4c1d995 100644
53520--- a/fs/cachefiles/proc.c
53521+++ b/fs/cachefiles/proc.c
53522@@ -14,9 +14,9 @@
53523 #include <linux/seq_file.h>
53524 #include "internal.h"
53525
53526-atomic_t cachefiles_lookup_histogram[HZ];
53527-atomic_t cachefiles_mkdir_histogram[HZ];
53528-atomic_t cachefiles_create_histogram[HZ];
53529+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53530+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53531+atomic_unchecked_t cachefiles_create_histogram[HZ];
53532
53533 /*
53534 * display the latency histogram
53535@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53536 return 0;
53537 default:
53538 index = (unsigned long) v - 3;
53539- x = atomic_read(&cachefiles_lookup_histogram[index]);
53540- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53541- z = atomic_read(&cachefiles_create_histogram[index]);
53542+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53543+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53544+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53545 if (x == 0 && y == 0 && z == 0)
53546 return 0;
53547
53548diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53549index ebaff36..7e3ea26 100644
53550--- a/fs/cachefiles/rdwr.c
53551+++ b/fs/cachefiles/rdwr.c
53552@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53553 old_fs = get_fs();
53554 set_fs(KERNEL_DS);
53555 ret = file->f_op->write(
53556- file, (const void __user *) data, len, &pos);
53557+ file, (const void __force_user *) data, len, &pos);
53558 set_fs(old_fs);
53559 kunmap(page);
53560 file_end_write(file);
53561diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53562index a40ceda..f43d17c 100644
53563--- a/fs/ceph/dir.c
53564+++ b/fs/ceph/dir.c
53565@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53566 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53567 struct ceph_mds_client *mdsc = fsc->mdsc;
53568 unsigned frag = fpos_frag(ctx->pos);
53569- int off = fpos_off(ctx->pos);
53570+ unsigned int off = fpos_off(ctx->pos);
53571 int err;
53572 u32 ftype;
53573 struct ceph_mds_reply_info_parsed *rinfo;
53574diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53575index 6627b26..634ec4b 100644
53576--- a/fs/ceph/super.c
53577+++ b/fs/ceph/super.c
53578@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53579 /*
53580 * construct our own bdi so we can control readahead, etc.
53581 */
53582-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53583+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53584
53585 static int ceph_register_bdi(struct super_block *sb,
53586 struct ceph_fs_client *fsc)
53587@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53588 default_backing_dev_info.ra_pages;
53589
53590 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53591- atomic_long_inc_return(&bdi_seq));
53592+ atomic_long_inc_return_unchecked(&bdi_seq));
53593 if (!err)
53594 sb->s_bdi = &fsc->backing_dev_info;
53595 return err;
53596diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53597index f3ac415..3d2420c 100644
53598--- a/fs/cifs/cifs_debug.c
53599+++ b/fs/cifs/cifs_debug.c
53600@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53601
53602 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53603 #ifdef CONFIG_CIFS_STATS2
53604- atomic_set(&totBufAllocCount, 0);
53605- atomic_set(&totSmBufAllocCount, 0);
53606+ atomic_set_unchecked(&totBufAllocCount, 0);
53607+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53608 #endif /* CONFIG_CIFS_STATS2 */
53609 spin_lock(&cifs_tcp_ses_lock);
53610 list_for_each(tmp1, &cifs_tcp_ses_list) {
53611@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53612 tcon = list_entry(tmp3,
53613 struct cifs_tcon,
53614 tcon_list);
53615- atomic_set(&tcon->num_smbs_sent, 0);
53616+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53617 if (server->ops->clear_stats)
53618 server->ops->clear_stats(tcon);
53619 }
53620@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53621 smBufAllocCount.counter, cifs_min_small);
53622 #ifdef CONFIG_CIFS_STATS2
53623 seq_printf(m, "Total Large %d Small %d Allocations\n",
53624- atomic_read(&totBufAllocCount),
53625- atomic_read(&totSmBufAllocCount));
53626+ atomic_read_unchecked(&totBufAllocCount),
53627+ atomic_read_unchecked(&totSmBufAllocCount));
53628 #endif /* CONFIG_CIFS_STATS2 */
53629
53630 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53631@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53632 if (tcon->need_reconnect)
53633 seq_puts(m, "\tDISCONNECTED ");
53634 seq_printf(m, "\nSMBs: %d",
53635- atomic_read(&tcon->num_smbs_sent));
53636+ atomic_read_unchecked(&tcon->num_smbs_sent));
53637 if (server->ops->print_stats)
53638 server->ops->print_stats(m, tcon);
53639 }
53640diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53641index 85ea98d..1eee040 100644
53642--- a/fs/cifs/cifsfs.c
53643+++ b/fs/cifs/cifsfs.c
53644@@ -120,14 +120,16 @@ cifs_read_super(struct super_block *sb)
53645 {
53646 struct inode *inode;
53647 struct cifs_sb_info *cifs_sb;
53648+ struct cifs_tcon *tcon;
53649 int rc = 0;
53650
53651 cifs_sb = CIFS_SB(sb);
53652+ tcon = cifs_sb_master_tcon(cifs_sb);
53653
53654 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
53655 sb->s_flags |= MS_POSIXACL;
53656
53657- if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
53658+ if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
53659 sb->s_maxbytes = MAX_LFS_FILESIZE;
53660 else
53661 sb->s_maxbytes = MAX_NON_LFS;
53662@@ -147,7 +149,7 @@ cifs_read_super(struct super_block *sb)
53663 goto out_no_root;
53664 }
53665
53666- if (cifs_sb_master_tcon(cifs_sb)->nocase)
53667+ if (tcon->nocase)
53668 sb->s_d_op = &cifs_ci_dentry_ops;
53669 else
53670 sb->s_d_op = &cifs_dentry_ops;
53671@@ -1037,7 +1039,7 @@ cifs_init_request_bufs(void)
53672 */
53673 cifs_req_cachep = kmem_cache_create("cifs_request",
53674 CIFSMaxBufSize + max_hdr_size, 0,
53675- SLAB_HWCACHE_ALIGN, NULL);
53676+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53677 if (cifs_req_cachep == NULL)
53678 return -ENOMEM;
53679
53680@@ -1064,7 +1066,7 @@ cifs_init_request_bufs(void)
53681 efficient to alloc 1 per page off the slab compared to 17K (5page)
53682 alloc of large cifs buffers even when page debugging is on */
53683 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53684- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53685+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53686 NULL);
53687 if (cifs_sm_req_cachep == NULL) {
53688 mempool_destroy(cifs_req_poolp);
53689@@ -1149,8 +1151,8 @@ init_cifs(void)
53690 atomic_set(&bufAllocCount, 0);
53691 atomic_set(&smBufAllocCount, 0);
53692 #ifdef CONFIG_CIFS_STATS2
53693- atomic_set(&totBufAllocCount, 0);
53694- atomic_set(&totSmBufAllocCount, 0);
53695+ atomic_set_unchecked(&totBufAllocCount, 0);
53696+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53697 #endif /* CONFIG_CIFS_STATS2 */
53698
53699 atomic_set(&midCount, 0);
53700diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53701index 52ca861..47f309c 100644
53702--- a/fs/cifs/cifsglob.h
53703+++ b/fs/cifs/cifsglob.h
53704@@ -756,35 +756,35 @@ struct cifs_tcon {
53705 __u16 Flags; /* optional support bits */
53706 enum statusEnum tidStatus;
53707 #ifdef CONFIG_CIFS_STATS
53708- atomic_t num_smbs_sent;
53709+ atomic_unchecked_t num_smbs_sent;
53710 union {
53711 struct {
53712- atomic_t num_writes;
53713- atomic_t num_reads;
53714- atomic_t num_flushes;
53715- atomic_t num_oplock_brks;
53716- atomic_t num_opens;
53717- atomic_t num_closes;
53718- atomic_t num_deletes;
53719- atomic_t num_mkdirs;
53720- atomic_t num_posixopens;
53721- atomic_t num_posixmkdirs;
53722- atomic_t num_rmdirs;
53723- atomic_t num_renames;
53724- atomic_t num_t2renames;
53725- atomic_t num_ffirst;
53726- atomic_t num_fnext;
53727- atomic_t num_fclose;
53728- atomic_t num_hardlinks;
53729- atomic_t num_symlinks;
53730- atomic_t num_locks;
53731- atomic_t num_acl_get;
53732- atomic_t num_acl_set;
53733+ atomic_unchecked_t num_writes;
53734+ atomic_unchecked_t num_reads;
53735+ atomic_unchecked_t num_flushes;
53736+ atomic_unchecked_t num_oplock_brks;
53737+ atomic_unchecked_t num_opens;
53738+ atomic_unchecked_t num_closes;
53739+ atomic_unchecked_t num_deletes;
53740+ atomic_unchecked_t num_mkdirs;
53741+ atomic_unchecked_t num_posixopens;
53742+ atomic_unchecked_t num_posixmkdirs;
53743+ atomic_unchecked_t num_rmdirs;
53744+ atomic_unchecked_t num_renames;
53745+ atomic_unchecked_t num_t2renames;
53746+ atomic_unchecked_t num_ffirst;
53747+ atomic_unchecked_t num_fnext;
53748+ atomic_unchecked_t num_fclose;
53749+ atomic_unchecked_t num_hardlinks;
53750+ atomic_unchecked_t num_symlinks;
53751+ atomic_unchecked_t num_locks;
53752+ atomic_unchecked_t num_acl_get;
53753+ atomic_unchecked_t num_acl_set;
53754 } cifs_stats;
53755 #ifdef CONFIG_CIFS_SMB2
53756 struct {
53757- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53758- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53759+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53760+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53761 } smb2_stats;
53762 #endif /* CONFIG_CIFS_SMB2 */
53763 } stats;
53764@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53765 }
53766
53767 #ifdef CONFIG_CIFS_STATS
53768-#define cifs_stats_inc atomic_inc
53769+#define cifs_stats_inc atomic_inc_unchecked
53770
53771 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53772 unsigned int bytes)
53773@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53774 /* Various Debug counters */
53775 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53776 #ifdef CONFIG_CIFS_STATS2
53777-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53778-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53779+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53780+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53781 #endif
53782 GLOBAL_EXTERN atomic_t smBufAllocCount;
53783 GLOBAL_EXTERN atomic_t midCount;
53784diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53785index 562044f..4af6a17 100644
53786--- a/fs/cifs/link.c
53787+++ b/fs/cifs/link.c
53788@@ -638,7 +638,7 @@ symlink_exit:
53789
53790 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53791 {
53792- char *p = nd_get_link(nd);
53793+ const char *p = nd_get_link(nd);
53794 if (!IS_ERR(p))
53795 kfree(p);
53796 }
53797diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53798index f7d4b22..1254377 100644
53799--- a/fs/cifs/misc.c
53800+++ b/fs/cifs/misc.c
53801@@ -169,7 +169,7 @@ cifs_buf_get(void)
53802 memset(ret_buf, 0, buf_size + 3);
53803 atomic_inc(&bufAllocCount);
53804 #ifdef CONFIG_CIFS_STATS2
53805- atomic_inc(&totBufAllocCount);
53806+ atomic_inc_unchecked(&totBufAllocCount);
53807 #endif /* CONFIG_CIFS_STATS2 */
53808 }
53809
53810@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53811 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53812 atomic_inc(&smBufAllocCount);
53813 #ifdef CONFIG_CIFS_STATS2
53814- atomic_inc(&totSmBufAllocCount);
53815+ atomic_inc_unchecked(&totSmBufAllocCount);
53816 #endif /* CONFIG_CIFS_STATS2 */
53817
53818 }
53819diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
53820index af847e1..651a527 100644
53821--- a/fs/cifs/netmisc.c
53822+++ b/fs/cifs/netmisc.c
53823@@ -780,7 +780,9 @@ static const struct {
53824 ERRDOS, ERRnoaccess, 0xc0000290}, {
53825 ERRDOS, ERRbadfunc, 0xc000029c}, {
53826 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
53827- ERRDOS, ERRinvlevel, 0x007c0001}, };
53828+ ERRDOS, ERRinvlevel, 0x007c0001}, {
53829+ 0, 0, 0 }
53830+};
53831
53832 /*****************************************************************************
53833 Print an error message from the status code
53834diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53835index 6094397..51e576f 100644
53836--- a/fs/cifs/smb1ops.c
53837+++ b/fs/cifs/smb1ops.c
53838@@ -590,27 +590,27 @@ static void
53839 cifs_clear_stats(struct cifs_tcon *tcon)
53840 {
53841 #ifdef CONFIG_CIFS_STATS
53842- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53843- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53844- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53845- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53846- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53847- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53848- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53849- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53850- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53851- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53852- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53853- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53854- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53855- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53856- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53857- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53858- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53859- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53860- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53861- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53862- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53863+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53864+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53865+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53866+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53867+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53868+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53869+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53870+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
53871+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
53872+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
53873+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
53874+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
53875+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
53876+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
53877+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
53878+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
53879+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
53880+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
53881+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
53882+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
53883+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
53884 #endif
53885 }
53886
53887@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53888 {
53889 #ifdef CONFIG_CIFS_STATS
53890 seq_printf(m, " Oplocks breaks: %d",
53891- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
53892+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
53893 seq_printf(m, "\nReads: %d Bytes: %llu",
53894- atomic_read(&tcon->stats.cifs_stats.num_reads),
53895+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
53896 (long long)(tcon->bytes_read));
53897 seq_printf(m, "\nWrites: %d Bytes: %llu",
53898- atomic_read(&tcon->stats.cifs_stats.num_writes),
53899+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
53900 (long long)(tcon->bytes_written));
53901 seq_printf(m, "\nFlushes: %d",
53902- atomic_read(&tcon->stats.cifs_stats.num_flushes));
53903+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
53904 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
53905- atomic_read(&tcon->stats.cifs_stats.num_locks),
53906- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
53907- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
53908+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
53909+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
53910+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
53911 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
53912- atomic_read(&tcon->stats.cifs_stats.num_opens),
53913- atomic_read(&tcon->stats.cifs_stats.num_closes),
53914- atomic_read(&tcon->stats.cifs_stats.num_deletes));
53915+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
53916+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
53917+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
53918 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
53919- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
53920- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
53921+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
53922+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
53923 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
53924- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
53925- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
53926+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
53927+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
53928 seq_printf(m, "\nRenames: %d T2 Renames %d",
53929- atomic_read(&tcon->stats.cifs_stats.num_renames),
53930- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
53931+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
53932+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
53933 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
53934- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
53935- atomic_read(&tcon->stats.cifs_stats.num_fnext),
53936- atomic_read(&tcon->stats.cifs_stats.num_fclose));
53937+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
53938+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
53939+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
53940 #endif
53941 }
53942
53943diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
53944index f259e6c..ca948ff 100644
53945--- a/fs/cifs/smb2ops.c
53946+++ b/fs/cifs/smb2ops.c
53947@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
53948 #ifdef CONFIG_CIFS_STATS
53949 int i;
53950 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
53951- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53952- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53953+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53954+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53955 }
53956 #endif
53957 }
53958@@ -310,65 +310,65 @@ static void
53959 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53960 {
53961 #ifdef CONFIG_CIFS_STATS
53962- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53963- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53964+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53965+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53966 seq_printf(m, "\nNegotiates: %d sent %d failed",
53967- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
53968- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
53969+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
53970+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
53971 seq_printf(m, "\nSessionSetups: %d sent %d failed",
53972- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
53973- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
53974+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
53975+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
53976 seq_printf(m, "\nLogoffs: %d sent %d failed",
53977- atomic_read(&sent[SMB2_LOGOFF_HE]),
53978- atomic_read(&failed[SMB2_LOGOFF_HE]));
53979+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
53980+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
53981 seq_printf(m, "\nTreeConnects: %d sent %d failed",
53982- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
53983- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
53984+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
53985+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
53986 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
53987- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
53988- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
53989+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
53990+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
53991 seq_printf(m, "\nCreates: %d sent %d failed",
53992- atomic_read(&sent[SMB2_CREATE_HE]),
53993- atomic_read(&failed[SMB2_CREATE_HE]));
53994+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
53995+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
53996 seq_printf(m, "\nCloses: %d sent %d failed",
53997- atomic_read(&sent[SMB2_CLOSE_HE]),
53998- atomic_read(&failed[SMB2_CLOSE_HE]));
53999+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54000+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54001 seq_printf(m, "\nFlushes: %d sent %d failed",
54002- atomic_read(&sent[SMB2_FLUSH_HE]),
54003- atomic_read(&failed[SMB2_FLUSH_HE]));
54004+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54005+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54006 seq_printf(m, "\nReads: %d sent %d failed",
54007- atomic_read(&sent[SMB2_READ_HE]),
54008- atomic_read(&failed[SMB2_READ_HE]));
54009+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54010+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54011 seq_printf(m, "\nWrites: %d sent %d failed",
54012- atomic_read(&sent[SMB2_WRITE_HE]),
54013- atomic_read(&failed[SMB2_WRITE_HE]));
54014+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54015+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54016 seq_printf(m, "\nLocks: %d sent %d failed",
54017- atomic_read(&sent[SMB2_LOCK_HE]),
54018- atomic_read(&failed[SMB2_LOCK_HE]));
54019+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54020+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54021 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54022- atomic_read(&sent[SMB2_IOCTL_HE]),
54023- atomic_read(&failed[SMB2_IOCTL_HE]));
54024+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54025+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54026 seq_printf(m, "\nCancels: %d sent %d failed",
54027- atomic_read(&sent[SMB2_CANCEL_HE]),
54028- atomic_read(&failed[SMB2_CANCEL_HE]));
54029+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54030+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54031 seq_printf(m, "\nEchos: %d sent %d failed",
54032- atomic_read(&sent[SMB2_ECHO_HE]),
54033- atomic_read(&failed[SMB2_ECHO_HE]));
54034+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54035+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54036 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54037- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54038- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54039+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54040+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54041 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54042- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54043- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54044+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54045+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54046 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54047- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54048- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54049+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54050+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54051 seq_printf(m, "\nSetInfos: %d sent %d failed",
54052- atomic_read(&sent[SMB2_SET_INFO_HE]),
54053- atomic_read(&failed[SMB2_SET_INFO_HE]));
54054+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54055+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54056 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54057- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54058- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54059+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54060+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54061 #endif
54062 }
54063
54064diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54065index abc9c28..3fdae28 100644
54066--- a/fs/cifs/smb2pdu.c
54067+++ b/fs/cifs/smb2pdu.c
54068@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54069 default:
54070 cifs_dbg(VFS, "info level %u isn't supported\n",
54071 srch_inf->info_level);
54072- rc = -EINVAL;
54073- goto qdir_exit;
54074+ return -EINVAL;
54075 }
54076
54077 req->FileIndex = cpu_to_le32(index);
54078diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54079index 1da168c..8bc7ff6 100644
54080--- a/fs/coda/cache.c
54081+++ b/fs/coda/cache.c
54082@@ -24,7 +24,7 @@
54083 #include "coda_linux.h"
54084 #include "coda_cache.h"
54085
54086-static atomic_t permission_epoch = ATOMIC_INIT(0);
54087+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54088
54089 /* replace or extend an acl cache hit */
54090 void coda_cache_enter(struct inode *inode, int mask)
54091@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54092 struct coda_inode_info *cii = ITOC(inode);
54093
54094 spin_lock(&cii->c_lock);
54095- cii->c_cached_epoch = atomic_read(&permission_epoch);
54096+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54097 if (!uid_eq(cii->c_uid, current_fsuid())) {
54098 cii->c_uid = current_fsuid();
54099 cii->c_cached_perm = mask;
54100@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54101 {
54102 struct coda_inode_info *cii = ITOC(inode);
54103 spin_lock(&cii->c_lock);
54104- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54105+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54106 spin_unlock(&cii->c_lock);
54107 }
54108
54109 /* remove all acl caches */
54110 void coda_cache_clear_all(struct super_block *sb)
54111 {
54112- atomic_inc(&permission_epoch);
54113+ atomic_inc_unchecked(&permission_epoch);
54114 }
54115
54116
54117@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54118 spin_lock(&cii->c_lock);
54119 hit = (mask & cii->c_cached_perm) == mask &&
54120 uid_eq(cii->c_uid, current_fsuid()) &&
54121- cii->c_cached_epoch == atomic_read(&permission_epoch);
54122+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54123 spin_unlock(&cii->c_lock);
54124
54125 return hit;
54126diff --git a/fs/compat.c b/fs/compat.c
54127index 6af20de..fec3fbb 100644
54128--- a/fs/compat.c
54129+++ b/fs/compat.c
54130@@ -54,7 +54,7 @@
54131 #include <asm/ioctls.h>
54132 #include "internal.h"
54133
54134-int compat_log = 1;
54135+int compat_log = 0;
54136
54137 int compat_printk(const char *fmt, ...)
54138 {
54139@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54140
54141 set_fs(KERNEL_DS);
54142 /* The __user pointer cast is valid because of the set_fs() */
54143- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54144+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54145 set_fs(oldfs);
54146 /* truncating is ok because it's a user address */
54147 if (!ret)
54148@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54149 goto out;
54150
54151 ret = -EINVAL;
54152- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54153+ if (nr_segs > UIO_MAXIOV)
54154 goto out;
54155 if (nr_segs > fast_segs) {
54156 ret = -ENOMEM;
54157@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54158 struct compat_readdir_callback {
54159 struct dir_context ctx;
54160 struct compat_old_linux_dirent __user *dirent;
54161+ struct file * file;
54162 int result;
54163 };
54164
54165@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54166 buf->result = -EOVERFLOW;
54167 return -EOVERFLOW;
54168 }
54169+
54170+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54171+ return 0;
54172+
54173 buf->result++;
54174 dirent = buf->dirent;
54175 if (!access_ok(VERIFY_WRITE, dirent,
54176@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54177 if (!f.file)
54178 return -EBADF;
54179
54180+ buf.file = f.file;
54181 error = iterate_dir(f.file, &buf.ctx);
54182 if (buf.result)
54183 error = buf.result;
54184@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54185 struct dir_context ctx;
54186 struct compat_linux_dirent __user *current_dir;
54187 struct compat_linux_dirent __user *previous;
54188+ struct file * file;
54189 int count;
54190 int error;
54191 };
54192@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54193 buf->error = -EOVERFLOW;
54194 return -EOVERFLOW;
54195 }
54196+
54197+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54198+ return 0;
54199+
54200 dirent = buf->previous;
54201 if (dirent) {
54202 if (__put_user(offset, &dirent->d_off))
54203@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54204 if (!f.file)
54205 return -EBADF;
54206
54207+ buf.file = f.file;
54208 error = iterate_dir(f.file, &buf.ctx);
54209 if (error >= 0)
54210 error = buf.error;
54211@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54212 struct dir_context ctx;
54213 struct linux_dirent64 __user *current_dir;
54214 struct linux_dirent64 __user *previous;
54215+ struct file * file;
54216 int count;
54217 int error;
54218 };
54219@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54220 buf->error = -EINVAL; /* only used if we fail.. */
54221 if (reclen > buf->count)
54222 return -EINVAL;
54223+
54224+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54225+ return 0;
54226+
54227 dirent = buf->previous;
54228
54229 if (dirent) {
54230@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54231 if (!f.file)
54232 return -EBADF;
54233
54234+ buf.file = f.file;
54235 error = iterate_dir(f.file, &buf.ctx);
54236 if (error >= 0)
54237 error = buf.error;
54238diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54239index a81147e..20bf2b5 100644
54240--- a/fs/compat_binfmt_elf.c
54241+++ b/fs/compat_binfmt_elf.c
54242@@ -30,11 +30,13 @@
54243 #undef elf_phdr
54244 #undef elf_shdr
54245 #undef elf_note
54246+#undef elf_dyn
54247 #undef elf_addr_t
54248 #define elfhdr elf32_hdr
54249 #define elf_phdr elf32_phdr
54250 #define elf_shdr elf32_shdr
54251 #define elf_note elf32_note
54252+#define elf_dyn Elf32_Dyn
54253 #define elf_addr_t Elf32_Addr
54254
54255 /*
54256diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54257index 5d19acf..9ab093b 100644
54258--- a/fs/compat_ioctl.c
54259+++ b/fs/compat_ioctl.c
54260@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54261 return -EFAULT;
54262 if (__get_user(udata, &ss32->iomem_base))
54263 return -EFAULT;
54264- ss.iomem_base = compat_ptr(udata);
54265+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54266 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54267 __get_user(ss.port_high, &ss32->port_high))
54268 return -EFAULT;
54269@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54270 for (i = 0; i < nmsgs; i++) {
54271 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54272 return -EFAULT;
54273- if (get_user(datap, &umsgs[i].buf) ||
54274- put_user(compat_ptr(datap), &tmsgs[i].buf))
54275+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54276+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54277 return -EFAULT;
54278 }
54279 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54280@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54281 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54282 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54283 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54284- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54285+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54286 return -EFAULT;
54287
54288 return ioctl_preallocate(file, p);
54289@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54290 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54291 {
54292 unsigned int a, b;
54293- a = *(unsigned int *)p;
54294- b = *(unsigned int *)q;
54295+ a = *(const unsigned int *)p;
54296+ b = *(const unsigned int *)q;
54297 if (a > b)
54298 return 1;
54299 if (a < b)
54300diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54301index 277bd1b..f312c9e 100644
54302--- a/fs/configfs/dir.c
54303+++ b/fs/configfs/dir.c
54304@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54305 }
54306 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54307 struct configfs_dirent *next;
54308- const char *name;
54309+ const unsigned char * name;
54310+ char d_name[sizeof(next->s_dentry->d_iname)];
54311 int len;
54312 struct inode *inode = NULL;
54313
54314@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54315 continue;
54316
54317 name = configfs_get_name(next);
54318- len = strlen(name);
54319+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54320+ len = next->s_dentry->d_name.len;
54321+ memcpy(d_name, name, len);
54322+ name = d_name;
54323+ } else
54324+ len = strlen(name);
54325
54326 /*
54327 * We'll have a dentry and an inode for
54328diff --git a/fs/coredump.c b/fs/coredump.c
54329index 72f816d..1ba8eff 100644
54330--- a/fs/coredump.c
54331+++ b/fs/coredump.c
54332@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54333 struct pipe_inode_info *pipe = file->private_data;
54334
54335 pipe_lock(pipe);
54336- pipe->readers++;
54337- pipe->writers--;
54338+ atomic_inc(&pipe->readers);
54339+ atomic_dec(&pipe->writers);
54340 wake_up_interruptible_sync(&pipe->wait);
54341 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54342 pipe_unlock(pipe);
54343@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54344 * We actually want wait_event_freezable() but then we need
54345 * to clear TIF_SIGPENDING and improve dump_interrupted().
54346 */
54347- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54348+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54349
54350 pipe_lock(pipe);
54351- pipe->readers--;
54352- pipe->writers++;
54353+ atomic_dec(&pipe->readers);
54354+ atomic_inc(&pipe->writers);
54355 pipe_unlock(pipe);
54356 }
54357
54358@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54359 struct files_struct *displaced;
54360 bool need_nonrelative = false;
54361 bool core_dumped = false;
54362- static atomic_t core_dump_count = ATOMIC_INIT(0);
54363+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54364+ long signr = siginfo->si_signo;
54365 struct coredump_params cprm = {
54366 .siginfo = siginfo,
54367 .regs = signal_pt_regs(),
54368@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54369 .mm_flags = mm->flags,
54370 };
54371
54372- audit_core_dumps(siginfo->si_signo);
54373+ audit_core_dumps(signr);
54374+
54375+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54376+ gr_handle_brute_attach(cprm.mm_flags);
54377
54378 binfmt = mm->binfmt;
54379 if (!binfmt || !binfmt->core_dump)
54380@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54381 need_nonrelative = true;
54382 }
54383
54384- retval = coredump_wait(siginfo->si_signo, &core_state);
54385+ retval = coredump_wait(signr, &core_state);
54386 if (retval < 0)
54387 goto fail_creds;
54388
54389@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54390 }
54391 cprm.limit = RLIM_INFINITY;
54392
54393- dump_count = atomic_inc_return(&core_dump_count);
54394+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54395 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54396 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54397 task_tgid_vnr(current), current->comm);
54398@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54399 } else {
54400 struct inode *inode;
54401
54402+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54403+
54404 if (cprm.limit < binfmt->min_coredump)
54405 goto fail_unlock;
54406
54407@@ -664,7 +670,7 @@ close_fail:
54408 filp_close(cprm.file, NULL);
54409 fail_dropcount:
54410 if (ispipe)
54411- atomic_dec(&core_dump_count);
54412+ atomic_dec_unchecked(&core_dump_count);
54413 fail_unlock:
54414 kfree(cn.corename);
54415 coredump_finish(mm, core_dumped);
54416@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54417 {
54418 return !dump_interrupted() &&
54419 access_ok(VERIFY_READ, addr, nr) &&
54420- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54421+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54422 }
54423 EXPORT_SYMBOL(dump_write);
54424
54425diff --git a/fs/dcache.c b/fs/dcache.c
54426index b949af8..5978926 100644
54427--- a/fs/dcache.c
54428+++ b/fs/dcache.c
54429@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54430 mempages -= reserve;
54431
54432 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54433- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54434+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54435+ SLAB_NO_SANITIZE, NULL);
54436
54437 dcache_init();
54438 inode_init();
54439diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54440index c7c83ff..bda9461 100644
54441--- a/fs/debugfs/inode.c
54442+++ b/fs/debugfs/inode.c
54443@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54444 */
54445 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54446 {
54447+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54448+ return __create_file(name, S_IFDIR | S_IRWXU,
54449+#else
54450 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54451+#endif
54452 parent, NULL, NULL);
54453 }
54454 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54455diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54456index 67e9b63..a9adb68 100644
54457--- a/fs/ecryptfs/inode.c
54458+++ b/fs/ecryptfs/inode.c
54459@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54460 old_fs = get_fs();
54461 set_fs(get_ds());
54462 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54463- (char __user *)lower_buf,
54464+ (char __force_user *)lower_buf,
54465 PATH_MAX);
54466 set_fs(old_fs);
54467 if (rc < 0)
54468@@ -706,7 +706,7 @@ out:
54469 static void
54470 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54471 {
54472- char *buf = nd_get_link(nd);
54473+ const char *buf = nd_get_link(nd);
54474 if (!IS_ERR(buf)) {
54475 /* Free the char* */
54476 kfree(buf);
54477diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54478index e4141f2..d8263e8 100644
54479--- a/fs/ecryptfs/miscdev.c
54480+++ b/fs/ecryptfs/miscdev.c
54481@@ -304,7 +304,7 @@ check_list:
54482 goto out_unlock_msg_ctx;
54483 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54484 if (msg_ctx->msg) {
54485- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54486+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54487 goto out_unlock_msg_ctx;
54488 i += packet_length_size;
54489 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54490diff --git a/fs/exec.c b/fs/exec.c
54491index fd774c7..1c6a7bf 100644
54492--- a/fs/exec.c
54493+++ b/fs/exec.c
54494@@ -55,8 +55,20 @@
54495 #include <linux/pipe_fs_i.h>
54496 #include <linux/oom.h>
54497 #include <linux/compat.h>
54498+#include <linux/random.h>
54499+#include <linux/seq_file.h>
54500+#include <linux/coredump.h>
54501+#include <linux/mman.h>
54502+
54503+#ifdef CONFIG_PAX_REFCOUNT
54504+#include <linux/kallsyms.h>
54505+#include <linux/kdebug.h>
54506+#endif
54507+
54508+#include <trace/events/fs.h>
54509
54510 #include <asm/uaccess.h>
54511+#include <asm/sections.h>
54512 #include <asm/mmu_context.h>
54513 #include <asm/tlb.h>
54514
54515@@ -66,17 +78,32 @@
54516
54517 #include <trace/events/sched.h>
54518
54519+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54520+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54521+{
54522+ 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");
54523+}
54524+#endif
54525+
54526+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54527+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54528+EXPORT_SYMBOL(pax_set_initial_flags_func);
54529+#endif
54530+
54531 int suid_dumpable = 0;
54532
54533 static LIST_HEAD(formats);
54534 static DEFINE_RWLOCK(binfmt_lock);
54535
54536+extern int gr_process_kernel_exec_ban(void);
54537+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54538+
54539 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54540 {
54541 BUG_ON(!fmt);
54542 write_lock(&binfmt_lock);
54543- insert ? list_add(&fmt->lh, &formats) :
54544- list_add_tail(&fmt->lh, &formats);
54545+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54546+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54547 write_unlock(&binfmt_lock);
54548 }
54549
54550@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54551 void unregister_binfmt(struct linux_binfmt * fmt)
54552 {
54553 write_lock(&binfmt_lock);
54554- list_del(&fmt->lh);
54555+ pax_list_del((struct list_head *)&fmt->lh);
54556 write_unlock(&binfmt_lock);
54557 }
54558
54559@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54560 int write)
54561 {
54562 struct page *page;
54563- int ret;
54564
54565-#ifdef CONFIG_STACK_GROWSUP
54566- if (write) {
54567- ret = expand_downwards(bprm->vma, pos);
54568- if (ret < 0)
54569- return NULL;
54570- }
54571-#endif
54572- ret = get_user_pages(current, bprm->mm, pos,
54573- 1, write, 1, &page, NULL);
54574- if (ret <= 0)
54575+ if (0 > expand_downwards(bprm->vma, pos))
54576+ return NULL;
54577+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54578 return NULL;
54579
54580 if (write) {
54581@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54582 if (size <= ARG_MAX)
54583 return page;
54584
54585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54586+ // only allow 512KB for argv+env on suid/sgid binaries
54587+ // to prevent easy ASLR exhaustion
54588+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54589+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54590+ (size > (512 * 1024))) {
54591+ put_page(page);
54592+ return NULL;
54593+ }
54594+#endif
54595+
54596 /*
54597 * Limit to 1/4-th the stack size for the argv+env strings.
54598 * This ensures that:
54599@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54600 vma->vm_end = STACK_TOP_MAX;
54601 vma->vm_start = vma->vm_end - PAGE_SIZE;
54602 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54603+
54604+#ifdef CONFIG_PAX_SEGMEXEC
54605+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54606+#endif
54607+
54608 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54609 INIT_LIST_HEAD(&vma->anon_vma_chain);
54610
54611@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54612 mm->stack_vm = mm->total_vm = 1;
54613 up_write(&mm->mmap_sem);
54614 bprm->p = vma->vm_end - sizeof(void *);
54615+
54616+#ifdef CONFIG_PAX_RANDUSTACK
54617+ if (randomize_va_space)
54618+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54619+#endif
54620+
54621 return 0;
54622 err:
54623 up_write(&mm->mmap_sem);
54624@@ -397,7 +438,7 @@ struct user_arg_ptr {
54625 } ptr;
54626 };
54627
54628-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54629+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54630 {
54631 const char __user *native;
54632
54633@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54634 compat_uptr_t compat;
54635
54636 if (get_user(compat, argv.ptr.compat + nr))
54637- return ERR_PTR(-EFAULT);
54638+ return (const char __force_user *)ERR_PTR(-EFAULT);
54639
54640 return compat_ptr(compat);
54641 }
54642 #endif
54643
54644 if (get_user(native, argv.ptr.native + nr))
54645- return ERR_PTR(-EFAULT);
54646+ return (const char __force_user *)ERR_PTR(-EFAULT);
54647
54648 return native;
54649 }
54650@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54651 if (!p)
54652 break;
54653
54654- if (IS_ERR(p))
54655+ if (IS_ERR((const char __force_kernel *)p))
54656 return -EFAULT;
54657
54658 if (i >= max)
54659@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54660
54661 ret = -EFAULT;
54662 str = get_user_arg_ptr(argv, argc);
54663- if (IS_ERR(str))
54664+ if (IS_ERR((const char __force_kernel *)str))
54665 goto out;
54666
54667 len = strnlen_user(str, MAX_ARG_STRLEN);
54668@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54669 int r;
54670 mm_segment_t oldfs = get_fs();
54671 struct user_arg_ptr argv = {
54672- .ptr.native = (const char __user *const __user *)__argv,
54673+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54674 };
54675
54676 set_fs(KERNEL_DS);
54677@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54678 unsigned long new_end = old_end - shift;
54679 struct mmu_gather tlb;
54680
54681- BUG_ON(new_start > new_end);
54682+ if (new_start >= new_end || new_start < mmap_min_addr)
54683+ return -ENOMEM;
54684
54685 /*
54686 * ensure there are no vmas between where we want to go
54687@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54688 if (vma != find_vma(mm, new_start))
54689 return -EFAULT;
54690
54691+#ifdef CONFIG_PAX_SEGMEXEC
54692+ BUG_ON(pax_find_mirror_vma(vma));
54693+#endif
54694+
54695 /*
54696 * cover the whole range: [new_start, old_end)
54697 */
54698@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54699 stack_top = arch_align_stack(stack_top);
54700 stack_top = PAGE_ALIGN(stack_top);
54701
54702- if (unlikely(stack_top < mmap_min_addr) ||
54703- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54704- return -ENOMEM;
54705-
54706 stack_shift = vma->vm_end - stack_top;
54707
54708 bprm->p -= stack_shift;
54709@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54710 bprm->exec -= stack_shift;
54711
54712 down_write(&mm->mmap_sem);
54713+
54714+ /* Move stack pages down in memory. */
54715+ if (stack_shift) {
54716+ ret = shift_arg_pages(vma, stack_shift);
54717+ if (ret)
54718+ goto out_unlock;
54719+ }
54720+
54721 vm_flags = VM_STACK_FLAGS;
54722
54723+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54724+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54725+ vm_flags &= ~VM_EXEC;
54726+
54727+#ifdef CONFIG_PAX_MPROTECT
54728+ if (mm->pax_flags & MF_PAX_MPROTECT)
54729+ vm_flags &= ~VM_MAYEXEC;
54730+#endif
54731+
54732+ }
54733+#endif
54734+
54735 /*
54736 * Adjust stack execute permissions; explicitly enable for
54737 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54738@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54739 goto out_unlock;
54740 BUG_ON(prev != vma);
54741
54742- /* Move stack pages down in memory. */
54743- if (stack_shift) {
54744- ret = shift_arg_pages(vma, stack_shift);
54745- if (ret)
54746- goto out_unlock;
54747- }
54748-
54749 /* mprotect_fixup is overkill to remove the temporary stack flags */
54750 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54751
54752@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54753 #endif
54754 current->mm->start_stack = bprm->p;
54755 ret = expand_stack(vma, stack_base);
54756+
54757+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54758+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54759+ unsigned long size;
54760+ vm_flags_t vm_flags;
54761+
54762+ size = STACK_TOP - vma->vm_end;
54763+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54764+
54765+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54766+
54767+#ifdef CONFIG_X86
54768+ if (!ret) {
54769+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54770+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54771+ }
54772+#endif
54773+
54774+ }
54775+#endif
54776+
54777 if (ret)
54778 ret = -EFAULT;
54779
54780@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54781
54782 fsnotify_open(file);
54783
54784+ trace_open_exec(name);
54785+
54786 err = deny_write_access(file);
54787 if (err)
54788 goto exit;
54789@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54790 old_fs = get_fs();
54791 set_fs(get_ds());
54792 /* The cast to a user pointer is valid due to the set_fs() */
54793- result = vfs_read(file, (void __user *)addr, count, &pos);
54794+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54795 set_fs(old_fs);
54796 return result;
54797 }
54798@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54799 }
54800 rcu_read_unlock();
54801
54802- if (p->fs->users > n_fs) {
54803+ if (atomic_read(&p->fs->users) > n_fs) {
54804 bprm->unsafe |= LSM_UNSAFE_SHARE;
54805 } else {
54806 res = -EAGAIN;
54807@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54808
54809 EXPORT_SYMBOL(search_binary_handler);
54810
54811+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54812+static DEFINE_PER_CPU(u64, exec_counter);
54813+static int __init init_exec_counters(void)
54814+{
54815+ unsigned int cpu;
54816+
54817+ for_each_possible_cpu(cpu) {
54818+ per_cpu(exec_counter, cpu) = (u64)cpu;
54819+ }
54820+
54821+ return 0;
54822+}
54823+early_initcall(init_exec_counters);
54824+static inline void increment_exec_counter(void)
54825+{
54826+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54827+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54828+}
54829+#else
54830+static inline void increment_exec_counter(void) {}
54831+#endif
54832+
54833+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54834+ struct user_arg_ptr argv);
54835+
54836 /*
54837 * sys_execve() executes a new program.
54838 */
54839@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54840 struct user_arg_ptr argv,
54841 struct user_arg_ptr envp)
54842 {
54843+#ifdef CONFIG_GRKERNSEC
54844+ struct file *old_exec_file;
54845+ struct acl_subject_label *old_acl;
54846+ struct rlimit old_rlim[RLIM_NLIMITS];
54847+#endif
54848 struct linux_binprm *bprm;
54849 struct file *file;
54850 struct files_struct *displaced;
54851 bool clear_in_exec;
54852 int retval;
54853
54854+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54855+
54856 /*
54857 * We move the actual failure in case of RLIMIT_NPROC excess from
54858 * set*uid() to execve() because too many poorly written programs
54859@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54860 if (IS_ERR(file))
54861 goto out_unmark;
54862
54863+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54864+ retval = -EPERM;
54865+ goto out_file;
54866+ }
54867+
54868 sched_exec();
54869
54870 bprm->file = file;
54871 bprm->filename = filename;
54872 bprm->interp = filename;
54873
54874+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
54875+ retval = -EACCES;
54876+ goto out_file;
54877+ }
54878+
54879 retval = bprm_mm_init(bprm);
54880 if (retval)
54881 goto out_file;
54882@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
54883 if (retval < 0)
54884 goto out;
54885
54886+#ifdef CONFIG_GRKERNSEC
54887+ old_acl = current->acl;
54888+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
54889+ old_exec_file = current->exec_file;
54890+ get_file(file);
54891+ current->exec_file = file;
54892+#endif
54893+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54894+ /* limit suid stack to 8MB
54895+ * we saved the old limits above and will restore them if this exec fails
54896+ */
54897+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
54898+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
54899+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
54900+#endif
54901+
54902+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
54903+ retval = -EPERM;
54904+ goto out_fail;
54905+ }
54906+
54907+ if (!gr_tpe_allow(file)) {
54908+ retval = -EACCES;
54909+ goto out_fail;
54910+ }
54911+
54912+ if (gr_check_crash_exec(file)) {
54913+ retval = -EACCES;
54914+ goto out_fail;
54915+ }
54916+
54917+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
54918+ bprm->unsafe);
54919+ if (retval < 0)
54920+ goto out_fail;
54921+
54922 retval = copy_strings_kernel(1, &bprm->filename, bprm);
54923 if (retval < 0)
54924- goto out;
54925+ goto out_fail;
54926
54927 bprm->exec = bprm->p;
54928 retval = copy_strings(bprm->envc, envp, bprm);
54929 if (retval < 0)
54930- goto out;
54931+ goto out_fail;
54932
54933 retval = copy_strings(bprm->argc, argv, bprm);
54934 if (retval < 0)
54935- goto out;
54936+ goto out_fail;
54937+
54938+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
54939+
54940+ gr_handle_exec_args(bprm, argv);
54941
54942 retval = search_binary_handler(bprm);
54943 if (retval < 0)
54944- goto out;
54945+ goto out_fail;
54946+#ifdef CONFIG_GRKERNSEC
54947+ if (old_exec_file)
54948+ fput(old_exec_file);
54949+#endif
54950
54951 /* execve succeeded */
54952+
54953+ increment_exec_counter();
54954 current->fs->in_exec = 0;
54955 current->in_execve = 0;
54956 acct_update_integrals(current);
54957@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
54958 put_files_struct(displaced);
54959 return retval;
54960
54961+out_fail:
54962+#ifdef CONFIG_GRKERNSEC
54963+ current->acl = old_acl;
54964+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
54965+ fput(current->exec_file);
54966+ current->exec_file = old_exec_file;
54967+#endif
54968+
54969 out:
54970 if (bprm->mm) {
54971 acct_arg_size(bprm, 0);
54972@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
54973 return error;
54974 }
54975 #endif
54976+
54977+int pax_check_flags(unsigned long *flags)
54978+{
54979+ int retval = 0;
54980+
54981+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
54982+ if (*flags & MF_PAX_SEGMEXEC)
54983+ {
54984+ *flags &= ~MF_PAX_SEGMEXEC;
54985+ retval = -EINVAL;
54986+ }
54987+#endif
54988+
54989+ if ((*flags & MF_PAX_PAGEEXEC)
54990+
54991+#ifdef CONFIG_PAX_PAGEEXEC
54992+ && (*flags & MF_PAX_SEGMEXEC)
54993+#endif
54994+
54995+ )
54996+ {
54997+ *flags &= ~MF_PAX_PAGEEXEC;
54998+ retval = -EINVAL;
54999+ }
55000+
55001+ if ((*flags & MF_PAX_MPROTECT)
55002+
55003+#ifdef CONFIG_PAX_MPROTECT
55004+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55005+#endif
55006+
55007+ )
55008+ {
55009+ *flags &= ~MF_PAX_MPROTECT;
55010+ retval = -EINVAL;
55011+ }
55012+
55013+ if ((*flags & MF_PAX_EMUTRAMP)
55014+
55015+#ifdef CONFIG_PAX_EMUTRAMP
55016+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55017+#endif
55018+
55019+ )
55020+ {
55021+ *flags &= ~MF_PAX_EMUTRAMP;
55022+ retval = -EINVAL;
55023+ }
55024+
55025+ return retval;
55026+}
55027+
55028+EXPORT_SYMBOL(pax_check_flags);
55029+
55030+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55031+char *pax_get_path(const struct path *path, char *buf, int buflen)
55032+{
55033+ char *pathname = d_path(path, buf, buflen);
55034+
55035+ if (IS_ERR(pathname))
55036+ goto toolong;
55037+
55038+ pathname = mangle_path(buf, pathname, "\t\n\\");
55039+ if (!pathname)
55040+ goto toolong;
55041+
55042+ *pathname = 0;
55043+ return buf;
55044+
55045+toolong:
55046+ return "<path too long>";
55047+}
55048+EXPORT_SYMBOL(pax_get_path);
55049+
55050+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55051+{
55052+ struct task_struct *tsk = current;
55053+ struct mm_struct *mm = current->mm;
55054+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55055+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55056+ char *path_exec = NULL;
55057+ char *path_fault = NULL;
55058+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55059+ siginfo_t info = { };
55060+
55061+ if (buffer_exec && buffer_fault) {
55062+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55063+
55064+ down_read(&mm->mmap_sem);
55065+ vma = mm->mmap;
55066+ while (vma && (!vma_exec || !vma_fault)) {
55067+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55068+ vma_exec = vma;
55069+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55070+ vma_fault = vma;
55071+ vma = vma->vm_next;
55072+ }
55073+ if (vma_exec)
55074+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55075+ if (vma_fault) {
55076+ start = vma_fault->vm_start;
55077+ end = vma_fault->vm_end;
55078+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55079+ if (vma_fault->vm_file)
55080+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55081+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55082+ path_fault = "<heap>";
55083+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55084+ path_fault = "<stack>";
55085+ else
55086+ path_fault = "<anonymous mapping>";
55087+ }
55088+ up_read(&mm->mmap_sem);
55089+ }
55090+ if (tsk->signal->curr_ip)
55091+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55092+ else
55093+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55094+ 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),
55095+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55096+ free_page((unsigned long)buffer_exec);
55097+ free_page((unsigned long)buffer_fault);
55098+ pax_report_insns(regs, pc, sp);
55099+ info.si_signo = SIGKILL;
55100+ info.si_errno = 0;
55101+ info.si_code = SI_KERNEL;
55102+ info.si_pid = 0;
55103+ info.si_uid = 0;
55104+ do_coredump(&info);
55105+}
55106+#endif
55107+
55108+#ifdef CONFIG_PAX_REFCOUNT
55109+void pax_report_refcount_overflow(struct pt_regs *regs)
55110+{
55111+ if (current->signal->curr_ip)
55112+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55113+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55114+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55115+ else
55116+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55117+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55118+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55119+ preempt_disable();
55120+ show_regs(regs);
55121+ preempt_enable();
55122+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55123+}
55124+#endif
55125+
55126+#ifdef CONFIG_PAX_USERCOPY
55127+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55128+static noinline int check_stack_object(const void *obj, unsigned long len)
55129+{
55130+ const void * const stack = task_stack_page(current);
55131+ const void * const stackend = stack + THREAD_SIZE;
55132+
55133+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55134+ const void *frame = NULL;
55135+ const void *oldframe;
55136+#endif
55137+
55138+ if (obj + len < obj)
55139+ return -1;
55140+
55141+ if (obj + len <= stack || stackend <= obj)
55142+ return 0;
55143+
55144+ if (obj < stack || stackend < obj + len)
55145+ return -1;
55146+
55147+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55148+ oldframe = __builtin_frame_address(1);
55149+ if (oldframe)
55150+ frame = __builtin_frame_address(2);
55151+ /*
55152+ low ----------------------------------------------> high
55153+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55154+ ^----------------^
55155+ allow copies only within here
55156+ */
55157+ while (stack <= frame && frame < stackend) {
55158+ /* if obj + len extends past the last frame, this
55159+ check won't pass and the next frame will be 0,
55160+ causing us to bail out and correctly report
55161+ the copy as invalid
55162+ */
55163+ if (obj + len <= frame)
55164+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55165+ oldframe = frame;
55166+ frame = *(const void * const *)frame;
55167+ }
55168+ return -1;
55169+#else
55170+ return 1;
55171+#endif
55172+}
55173+
55174+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55175+{
55176+ if (current->signal->curr_ip)
55177+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55178+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55179+ else
55180+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55181+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55182+ dump_stack();
55183+ gr_handle_kernel_exploit();
55184+ do_group_exit(SIGKILL);
55185+}
55186+#endif
55187+
55188+#ifdef CONFIG_PAX_USERCOPY
55189+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55190+{
55191+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55192+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55193+#ifdef CONFIG_MODULES
55194+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55195+#else
55196+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55197+#endif
55198+
55199+#else
55200+ unsigned long textlow = (unsigned long)_stext;
55201+ unsigned long texthigh = (unsigned long)_etext;
55202+#endif
55203+
55204+ if (high <= textlow || low > texthigh)
55205+ return false;
55206+ else
55207+ return true;
55208+}
55209+#endif
55210+
55211+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55212+{
55213+
55214+#ifdef CONFIG_PAX_USERCOPY
55215+ const char *type;
55216+
55217+ if (!n)
55218+ return;
55219+
55220+ type = check_heap_object(ptr, n);
55221+ if (!type) {
55222+ int ret = check_stack_object(ptr, n);
55223+ if (ret == 1 || ret == 2)
55224+ return;
55225+ if (ret == 0) {
55226+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55227+ type = "<kernel text>";
55228+ else
55229+ return;
55230+ } else
55231+ type = "<process stack>";
55232+ }
55233+
55234+ pax_report_usercopy(ptr, n, to_user, type);
55235+#endif
55236+
55237+}
55238+EXPORT_SYMBOL(__check_object_size);
55239+
55240+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55241+void pax_track_stack(void)
55242+{
55243+ unsigned long sp = (unsigned long)&sp;
55244+ if (sp < current_thread_info()->lowest_stack &&
55245+ sp > (unsigned long)task_stack_page(current))
55246+ current_thread_info()->lowest_stack = sp;
55247+}
55248+EXPORT_SYMBOL(pax_track_stack);
55249+#endif
55250+
55251+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55252+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55253+{
55254+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55255+ dump_stack();
55256+ do_group_exit(SIGKILL);
55257+}
55258+EXPORT_SYMBOL(report_size_overflow);
55259+#endif
55260diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55261index 9f9992b..8b59411 100644
55262--- a/fs/ext2/balloc.c
55263+++ b/fs/ext2/balloc.c
55264@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55265
55266 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55267 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55268- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55269+ if (free_blocks < root_blocks + 1 &&
55270 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55271 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55272- !in_group_p (sbi->s_resgid))) {
55273+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55274 return 0;
55275 }
55276 return 1;
55277diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55278index 22548f5..41521d8 100644
55279--- a/fs/ext3/balloc.c
55280+++ b/fs/ext3/balloc.c
55281@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55282
55283 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55284 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55285- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55286+ if (free_blocks < root_blocks + 1 &&
55287 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55288 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55289- !in_group_p (sbi->s_resgid))) {
55290+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55291 return 0;
55292 }
55293 return 1;
55294diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
55295index 1194b1f..f8cde46 100644
55296--- a/fs/ext3/namei.c
55297+++ b/fs/ext3/namei.c
55298@@ -1783,7 +1783,7 @@ retry:
55299 d_tmpfile(dentry, inode);
55300 err = ext3_orphan_add(handle, inode);
55301 if (err)
55302- goto err_drop_inode;
55303+ goto err_unlock_inode;
55304 mark_inode_dirty(inode);
55305 unlock_new_inode(inode);
55306 }
55307@@ -1791,10 +1791,9 @@ retry:
55308 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
55309 goto retry;
55310 return err;
55311-err_drop_inode:
55312+err_unlock_inode:
55313 ext3_journal_stop(handle);
55314 unlock_new_inode(inode);
55315- iput(inode);
55316 return err;
55317 }
55318
55319diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55320index ddd715e..c772f88 100644
55321--- a/fs/ext4/balloc.c
55322+++ b/fs/ext4/balloc.c
55323@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55324 /* Hm, nope. Are (enough) root reserved clusters available? */
55325 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55326 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55327- capable(CAP_SYS_RESOURCE) ||
55328- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55329+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55330+ capable_nolog(CAP_SYS_RESOURCE)) {
55331
55332 if (free_clusters >= (nclusters + dirty_clusters +
55333 resv_clusters))
55334diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55335index 0ab26fb..b6ecb39 100644
55336--- a/fs/ext4/ext4.h
55337+++ b/fs/ext4/ext4.h
55338@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55339 unsigned long s_mb_last_start;
55340
55341 /* stats for buddy allocator */
55342- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55343- atomic_t s_bal_success; /* we found long enough chunks */
55344- atomic_t s_bal_allocated; /* in blocks */
55345- atomic_t s_bal_ex_scanned; /* total extents scanned */
55346- atomic_t s_bal_goals; /* goal hits */
55347- atomic_t s_bal_breaks; /* too long searches */
55348- atomic_t s_bal_2orders; /* 2^order hits */
55349+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55350+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55351+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55352+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55353+ atomic_unchecked_t s_bal_goals; /* goal hits */
55354+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55355+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55356 spinlock_t s_bal_lock;
55357 unsigned long s_mb_buddies_generated;
55358 unsigned long long s_mb_generation_time;
55359- atomic_t s_mb_lost_chunks;
55360- atomic_t s_mb_preallocated;
55361- atomic_t s_mb_discarded;
55362+ atomic_unchecked_t s_mb_lost_chunks;
55363+ atomic_unchecked_t s_mb_preallocated;
55364+ atomic_unchecked_t s_mb_discarded;
55365 atomic_t s_lock_busy;
55366
55367 /* locality groups */
55368diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55369index 4bbbf13b..dcceaeb 100644
55370--- a/fs/ext4/mballoc.c
55371+++ b/fs/ext4/mballoc.c
55372@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55373 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55374
55375 if (EXT4_SB(sb)->s_mb_stats)
55376- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55377+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55378
55379 break;
55380 }
55381@@ -2171,7 +2171,7 @@ repeat:
55382 ac->ac_status = AC_STATUS_CONTINUE;
55383 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55384 cr = 3;
55385- atomic_inc(&sbi->s_mb_lost_chunks);
55386+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55387 goto repeat;
55388 }
55389 }
55390@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55391 if (sbi->s_mb_stats) {
55392 ext4_msg(sb, KERN_INFO,
55393 "mballoc: %u blocks %u reqs (%u success)",
55394- atomic_read(&sbi->s_bal_allocated),
55395- atomic_read(&sbi->s_bal_reqs),
55396- atomic_read(&sbi->s_bal_success));
55397+ atomic_read_unchecked(&sbi->s_bal_allocated),
55398+ atomic_read_unchecked(&sbi->s_bal_reqs),
55399+ atomic_read_unchecked(&sbi->s_bal_success));
55400 ext4_msg(sb, KERN_INFO,
55401 "mballoc: %u extents scanned, %u goal hits, "
55402 "%u 2^N hits, %u breaks, %u lost",
55403- atomic_read(&sbi->s_bal_ex_scanned),
55404- atomic_read(&sbi->s_bal_goals),
55405- atomic_read(&sbi->s_bal_2orders),
55406- atomic_read(&sbi->s_bal_breaks),
55407- atomic_read(&sbi->s_mb_lost_chunks));
55408+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55409+ atomic_read_unchecked(&sbi->s_bal_goals),
55410+ atomic_read_unchecked(&sbi->s_bal_2orders),
55411+ atomic_read_unchecked(&sbi->s_bal_breaks),
55412+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55413 ext4_msg(sb, KERN_INFO,
55414 "mballoc: %lu generated and it took %Lu",
55415 sbi->s_mb_buddies_generated,
55416 sbi->s_mb_generation_time);
55417 ext4_msg(sb, KERN_INFO,
55418 "mballoc: %u preallocated, %u discarded",
55419- atomic_read(&sbi->s_mb_preallocated),
55420- atomic_read(&sbi->s_mb_discarded));
55421+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55422+ atomic_read_unchecked(&sbi->s_mb_discarded));
55423 }
55424
55425 free_percpu(sbi->s_locality_groups);
55426@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55427 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55428
55429 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55430- atomic_inc(&sbi->s_bal_reqs);
55431- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55432+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55433+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55434 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55435- atomic_inc(&sbi->s_bal_success);
55436- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55437+ atomic_inc_unchecked(&sbi->s_bal_success);
55438+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55439 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55440 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55441- atomic_inc(&sbi->s_bal_goals);
55442+ atomic_inc_unchecked(&sbi->s_bal_goals);
55443 if (ac->ac_found > sbi->s_mb_max_to_scan)
55444- atomic_inc(&sbi->s_bal_breaks);
55445+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55446 }
55447
55448 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55449@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55450 trace_ext4_mb_new_inode_pa(ac, pa);
55451
55452 ext4_mb_use_inode_pa(ac, pa);
55453- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55454+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55455
55456 ei = EXT4_I(ac->ac_inode);
55457 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55458@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55459 trace_ext4_mb_new_group_pa(ac, pa);
55460
55461 ext4_mb_use_group_pa(ac, pa);
55462- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55463+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55464
55465 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55466 lg = ac->ac_lg;
55467@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55468 * from the bitmap and continue.
55469 */
55470 }
55471- atomic_add(free, &sbi->s_mb_discarded);
55472+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55473
55474 return err;
55475 }
55476@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55477 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55478 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55479 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55480- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55481+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55482 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55483
55484 return 0;
55485diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55486index 214461e..3614c89 100644
55487--- a/fs/ext4/mmp.c
55488+++ b/fs/ext4/mmp.c
55489@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55490 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55491 const char *function, unsigned int line, const char *msg)
55492 {
55493- __ext4_warning(sb, function, line, msg);
55494+ __ext4_warning(sb, function, line, "%s", msg);
55495 __ext4_warning(sb, function, line,
55496 "MMP failure info: last update time: %llu, last update "
55497 "node: %s, last update device: %s\n",
55498diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
55499index 35f55a0..b53cbc6 100644
55500--- a/fs/ext4/namei.c
55501+++ b/fs/ext4/namei.c
55502@@ -2319,7 +2319,7 @@ retry:
55503 d_tmpfile(dentry, inode);
55504 err = ext4_orphan_add(handle, inode);
55505 if (err)
55506- goto err_drop_inode;
55507+ goto err_unlock_inode;
55508 mark_inode_dirty(inode);
55509 unlock_new_inode(inode);
55510 }
55511@@ -2328,10 +2328,9 @@ retry:
55512 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
55513 goto retry;
55514 return err;
55515-err_drop_inode:
55516+err_unlock_inode:
55517 ext4_journal_stop(handle);
55518 unlock_new_inode(inode);
55519- iput(inode);
55520 return err;
55521 }
55522
55523diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55524index b59373b..f41c2b5 100644
55525--- a/fs/ext4/super.c
55526+++ b/fs/ext4/super.c
55527@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55528 }
55529
55530 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55531-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55532+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55533 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55534
55535 #ifdef CONFIG_QUOTA
55536@@ -2394,7 +2394,7 @@ struct ext4_attr {
55537 int offset;
55538 int deprecated_val;
55539 } u;
55540-};
55541+} __do_const;
55542
55543 static int parse_strtoull(const char *buf,
55544 unsigned long long max, unsigned long long *value)
55545diff --git a/fs/fcntl.c b/fs/fcntl.c
55546index 65343c3..9969dcf 100644
55547--- a/fs/fcntl.c
55548+++ b/fs/fcntl.c
55549@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55550 if (err)
55551 return err;
55552
55553+ if (gr_handle_chroot_fowner(pid, type))
55554+ return -ENOENT;
55555+ if (gr_check_protected_task_fowner(pid, type))
55556+ return -EACCES;
55557+
55558 f_modown(filp, pid, type, force);
55559 return 0;
55560 }
55561diff --git a/fs/fhandle.c b/fs/fhandle.c
55562index 999ff5c..41f4109 100644
55563--- a/fs/fhandle.c
55564+++ b/fs/fhandle.c
55565@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55566 } else
55567 retval = 0;
55568 /* copy the mount id */
55569- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55570- sizeof(*mnt_id)) ||
55571+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55572 copy_to_user(ufh, handle,
55573 sizeof(struct file_handle) + handle_bytes))
55574 retval = -EFAULT;
55575diff --git a/fs/file.c b/fs/file.c
55576index 4a78f98..9447397 100644
55577--- a/fs/file.c
55578+++ b/fs/file.c
55579@@ -16,6 +16,7 @@
55580 #include <linux/slab.h>
55581 #include <linux/vmalloc.h>
55582 #include <linux/file.h>
55583+#include <linux/security.h>
55584 #include <linux/fdtable.h>
55585 #include <linux/bitops.h>
55586 #include <linux/interrupt.h>
55587@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55588 if (!file)
55589 return __close_fd(files, fd);
55590
55591+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55592 if (fd >= rlimit(RLIMIT_NOFILE))
55593 return -EBADF;
55594
55595@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55596 if (unlikely(oldfd == newfd))
55597 return -EINVAL;
55598
55599+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55600 if (newfd >= rlimit(RLIMIT_NOFILE))
55601 return -EBADF;
55602
55603@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55604 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55605 {
55606 int err;
55607+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55608 if (from >= rlimit(RLIMIT_NOFILE))
55609 return -EINVAL;
55610 err = alloc_fd(from, flags);
55611diff --git a/fs/filesystems.c b/fs/filesystems.c
55612index 92567d9..fcd8cbf 100644
55613--- a/fs/filesystems.c
55614+++ b/fs/filesystems.c
55615@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55616 int len = dot ? dot - name : strlen(name);
55617
55618 fs = __get_fs_type(name, len);
55619+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55620+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55621+#else
55622 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55623+#endif
55624 fs = __get_fs_type(name, len);
55625
55626 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55627diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55628index d8ac61d..79a36f0 100644
55629--- a/fs/fs_struct.c
55630+++ b/fs/fs_struct.c
55631@@ -4,6 +4,7 @@
55632 #include <linux/path.h>
55633 #include <linux/slab.h>
55634 #include <linux/fs_struct.h>
55635+#include <linux/grsecurity.h>
55636 #include "internal.h"
55637
55638 /*
55639@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55640 write_seqcount_begin(&fs->seq);
55641 old_root = fs->root;
55642 fs->root = *path;
55643+ gr_set_chroot_entries(current, path);
55644 write_seqcount_end(&fs->seq);
55645 spin_unlock(&fs->lock);
55646 if (old_root.dentry)
55647@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55648 int hits = 0;
55649 spin_lock(&fs->lock);
55650 write_seqcount_begin(&fs->seq);
55651+ /* this root replacement is only done by pivot_root,
55652+ leave grsec's chroot tagging alone for this task
55653+ so that a pivoted root isn't treated as a chroot
55654+ */
55655 hits += replace_path(&fs->root, old_root, new_root);
55656 hits += replace_path(&fs->pwd, old_root, new_root);
55657 write_seqcount_end(&fs->seq);
55658@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55659 task_lock(tsk);
55660 spin_lock(&fs->lock);
55661 tsk->fs = NULL;
55662- kill = !--fs->users;
55663+ gr_clear_chroot_entries(tsk);
55664+ kill = !atomic_dec_return(&fs->users);
55665 spin_unlock(&fs->lock);
55666 task_unlock(tsk);
55667 if (kill)
55668@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55669 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55670 /* We don't need to lock fs - think why ;-) */
55671 if (fs) {
55672- fs->users = 1;
55673+ atomic_set(&fs->users, 1);
55674 fs->in_exec = 0;
55675 spin_lock_init(&fs->lock);
55676 seqcount_init(&fs->seq);
55677@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55678 spin_lock(&old->lock);
55679 fs->root = old->root;
55680 path_get(&fs->root);
55681+ /* instead of calling gr_set_chroot_entries here,
55682+ we call it from every caller of this function
55683+ */
55684 fs->pwd = old->pwd;
55685 path_get(&fs->pwd);
55686 spin_unlock(&old->lock);
55687@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55688
55689 task_lock(current);
55690 spin_lock(&fs->lock);
55691- kill = !--fs->users;
55692+ kill = !atomic_dec_return(&fs->users);
55693 current->fs = new_fs;
55694+ gr_set_chroot_entries(current, &new_fs->root);
55695 spin_unlock(&fs->lock);
55696 task_unlock(current);
55697
55698@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55699
55700 int current_umask(void)
55701 {
55702- return current->fs->umask;
55703+ return current->fs->umask | gr_acl_umask();
55704 }
55705 EXPORT_SYMBOL(current_umask);
55706
55707 /* to be mentioned only in INIT_TASK */
55708 struct fs_struct init_fs = {
55709- .users = 1,
55710+ .users = ATOMIC_INIT(1),
55711 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55712 .seq = SEQCNT_ZERO,
55713 .umask = 0022,
55714diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55715index 0e91a3c..6c6d2e0 100644
55716--- a/fs/fscache/cookie.c
55717+++ b/fs/fscache/cookie.c
55718@@ -19,7 +19,7 @@
55719
55720 struct kmem_cache *fscache_cookie_jar;
55721
55722-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55723+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55724
55725 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55726 static int fscache_alloc_object(struct fscache_cache *cache,
55727@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55728 parent ? (char *) parent->def->name : "<no-parent>",
55729 def->name, netfs_data);
55730
55731- fscache_stat(&fscache_n_acquires);
55732+ fscache_stat_unchecked(&fscache_n_acquires);
55733
55734 /* if there's no parent cookie, then we don't create one here either */
55735 if (!parent) {
55736- fscache_stat(&fscache_n_acquires_null);
55737+ fscache_stat_unchecked(&fscache_n_acquires_null);
55738 _leave(" [no parent]");
55739 return NULL;
55740 }
55741@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55742 /* allocate and initialise a cookie */
55743 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55744 if (!cookie) {
55745- fscache_stat(&fscache_n_acquires_oom);
55746+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55747 _leave(" [ENOMEM]");
55748 return NULL;
55749 }
55750@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55751
55752 switch (cookie->def->type) {
55753 case FSCACHE_COOKIE_TYPE_INDEX:
55754- fscache_stat(&fscache_n_cookie_index);
55755+ fscache_stat_unchecked(&fscache_n_cookie_index);
55756 break;
55757 case FSCACHE_COOKIE_TYPE_DATAFILE:
55758- fscache_stat(&fscache_n_cookie_data);
55759+ fscache_stat_unchecked(&fscache_n_cookie_data);
55760 break;
55761 default:
55762- fscache_stat(&fscache_n_cookie_special);
55763+ fscache_stat_unchecked(&fscache_n_cookie_special);
55764 break;
55765 }
55766
55767@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55768 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55769 atomic_dec(&parent->n_children);
55770 __fscache_cookie_put(cookie);
55771- fscache_stat(&fscache_n_acquires_nobufs);
55772+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55773 _leave(" = NULL");
55774 return NULL;
55775 }
55776 }
55777
55778- fscache_stat(&fscache_n_acquires_ok);
55779+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55780 _leave(" = %p", cookie);
55781 return cookie;
55782 }
55783@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55784 cache = fscache_select_cache_for_object(cookie->parent);
55785 if (!cache) {
55786 up_read(&fscache_addremove_sem);
55787- fscache_stat(&fscache_n_acquires_no_cache);
55788+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55789 _leave(" = -ENOMEDIUM [no cache]");
55790 return -ENOMEDIUM;
55791 }
55792@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55793 object = cache->ops->alloc_object(cache, cookie);
55794 fscache_stat_d(&fscache_n_cop_alloc_object);
55795 if (IS_ERR(object)) {
55796- fscache_stat(&fscache_n_object_no_alloc);
55797+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55798 ret = PTR_ERR(object);
55799 goto error;
55800 }
55801
55802- fscache_stat(&fscache_n_object_alloc);
55803+ fscache_stat_unchecked(&fscache_n_object_alloc);
55804
55805- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55806+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55807
55808 _debug("ALLOC OBJ%x: %s {%lx}",
55809 object->debug_id, cookie->def->name, object->events);
55810@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55811
55812 _enter("{%s}", cookie->def->name);
55813
55814- fscache_stat(&fscache_n_invalidates);
55815+ fscache_stat_unchecked(&fscache_n_invalidates);
55816
55817 /* Only permit invalidation of data files. Invalidating an index will
55818 * require the caller to release all its attachments to the tree rooted
55819@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55820 {
55821 struct fscache_object *object;
55822
55823- fscache_stat(&fscache_n_updates);
55824+ fscache_stat_unchecked(&fscache_n_updates);
55825
55826 if (!cookie) {
55827- fscache_stat(&fscache_n_updates_null);
55828+ fscache_stat_unchecked(&fscache_n_updates_null);
55829 _leave(" [no cookie]");
55830 return;
55831 }
55832@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55833 {
55834 struct fscache_object *object;
55835
55836- fscache_stat(&fscache_n_relinquishes);
55837+ fscache_stat_unchecked(&fscache_n_relinquishes);
55838 if (retire)
55839- fscache_stat(&fscache_n_relinquishes_retire);
55840+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55841
55842 if (!cookie) {
55843- fscache_stat(&fscache_n_relinquishes_null);
55844+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55845 _leave(" [no cookie]");
55846 return;
55847 }
55848diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55849index 12d505b..86473a3 100644
55850--- a/fs/fscache/internal.h
55851+++ b/fs/fscache/internal.h
55852@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55853 * stats.c
55854 */
55855 #ifdef CONFIG_FSCACHE_STATS
55856-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55857-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55858+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55859+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55860
55861-extern atomic_t fscache_n_op_pend;
55862-extern atomic_t fscache_n_op_run;
55863-extern atomic_t fscache_n_op_enqueue;
55864-extern atomic_t fscache_n_op_deferred_release;
55865-extern atomic_t fscache_n_op_release;
55866-extern atomic_t fscache_n_op_gc;
55867-extern atomic_t fscache_n_op_cancelled;
55868-extern atomic_t fscache_n_op_rejected;
55869+extern atomic_unchecked_t fscache_n_op_pend;
55870+extern atomic_unchecked_t fscache_n_op_run;
55871+extern atomic_unchecked_t fscache_n_op_enqueue;
55872+extern atomic_unchecked_t fscache_n_op_deferred_release;
55873+extern atomic_unchecked_t fscache_n_op_release;
55874+extern atomic_unchecked_t fscache_n_op_gc;
55875+extern atomic_unchecked_t fscache_n_op_cancelled;
55876+extern atomic_unchecked_t fscache_n_op_rejected;
55877
55878-extern atomic_t fscache_n_attr_changed;
55879-extern atomic_t fscache_n_attr_changed_ok;
55880-extern atomic_t fscache_n_attr_changed_nobufs;
55881-extern atomic_t fscache_n_attr_changed_nomem;
55882-extern atomic_t fscache_n_attr_changed_calls;
55883+extern atomic_unchecked_t fscache_n_attr_changed;
55884+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55885+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55886+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55887+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55888
55889-extern atomic_t fscache_n_allocs;
55890-extern atomic_t fscache_n_allocs_ok;
55891-extern atomic_t fscache_n_allocs_wait;
55892-extern atomic_t fscache_n_allocs_nobufs;
55893-extern atomic_t fscache_n_allocs_intr;
55894-extern atomic_t fscache_n_allocs_object_dead;
55895-extern atomic_t fscache_n_alloc_ops;
55896-extern atomic_t fscache_n_alloc_op_waits;
55897+extern atomic_unchecked_t fscache_n_allocs;
55898+extern atomic_unchecked_t fscache_n_allocs_ok;
55899+extern atomic_unchecked_t fscache_n_allocs_wait;
55900+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55901+extern atomic_unchecked_t fscache_n_allocs_intr;
55902+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55903+extern atomic_unchecked_t fscache_n_alloc_ops;
55904+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55905
55906-extern atomic_t fscache_n_retrievals;
55907-extern atomic_t fscache_n_retrievals_ok;
55908-extern atomic_t fscache_n_retrievals_wait;
55909-extern atomic_t fscache_n_retrievals_nodata;
55910-extern atomic_t fscache_n_retrievals_nobufs;
55911-extern atomic_t fscache_n_retrievals_intr;
55912-extern atomic_t fscache_n_retrievals_nomem;
55913-extern atomic_t fscache_n_retrievals_object_dead;
55914-extern atomic_t fscache_n_retrieval_ops;
55915-extern atomic_t fscache_n_retrieval_op_waits;
55916+extern atomic_unchecked_t fscache_n_retrievals;
55917+extern atomic_unchecked_t fscache_n_retrievals_ok;
55918+extern atomic_unchecked_t fscache_n_retrievals_wait;
55919+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55920+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
55921+extern atomic_unchecked_t fscache_n_retrievals_intr;
55922+extern atomic_unchecked_t fscache_n_retrievals_nomem;
55923+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
55924+extern atomic_unchecked_t fscache_n_retrieval_ops;
55925+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
55926
55927-extern atomic_t fscache_n_stores;
55928-extern atomic_t fscache_n_stores_ok;
55929-extern atomic_t fscache_n_stores_again;
55930-extern atomic_t fscache_n_stores_nobufs;
55931-extern atomic_t fscache_n_stores_oom;
55932-extern atomic_t fscache_n_store_ops;
55933-extern atomic_t fscache_n_store_calls;
55934-extern atomic_t fscache_n_store_pages;
55935-extern atomic_t fscache_n_store_radix_deletes;
55936-extern atomic_t fscache_n_store_pages_over_limit;
55937+extern atomic_unchecked_t fscache_n_stores;
55938+extern atomic_unchecked_t fscache_n_stores_ok;
55939+extern atomic_unchecked_t fscache_n_stores_again;
55940+extern atomic_unchecked_t fscache_n_stores_nobufs;
55941+extern atomic_unchecked_t fscache_n_stores_oom;
55942+extern atomic_unchecked_t fscache_n_store_ops;
55943+extern atomic_unchecked_t fscache_n_store_calls;
55944+extern atomic_unchecked_t fscache_n_store_pages;
55945+extern atomic_unchecked_t fscache_n_store_radix_deletes;
55946+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
55947
55948-extern atomic_t fscache_n_store_vmscan_not_storing;
55949-extern atomic_t fscache_n_store_vmscan_gone;
55950-extern atomic_t fscache_n_store_vmscan_busy;
55951-extern atomic_t fscache_n_store_vmscan_cancelled;
55952-extern atomic_t fscache_n_store_vmscan_wait;
55953+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
55954+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
55955+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
55956+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
55957+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
55958
55959-extern atomic_t fscache_n_marks;
55960-extern atomic_t fscache_n_uncaches;
55961+extern atomic_unchecked_t fscache_n_marks;
55962+extern atomic_unchecked_t fscache_n_uncaches;
55963
55964-extern atomic_t fscache_n_acquires;
55965-extern atomic_t fscache_n_acquires_null;
55966-extern atomic_t fscache_n_acquires_no_cache;
55967-extern atomic_t fscache_n_acquires_ok;
55968-extern atomic_t fscache_n_acquires_nobufs;
55969-extern atomic_t fscache_n_acquires_oom;
55970+extern atomic_unchecked_t fscache_n_acquires;
55971+extern atomic_unchecked_t fscache_n_acquires_null;
55972+extern atomic_unchecked_t fscache_n_acquires_no_cache;
55973+extern atomic_unchecked_t fscache_n_acquires_ok;
55974+extern atomic_unchecked_t fscache_n_acquires_nobufs;
55975+extern atomic_unchecked_t fscache_n_acquires_oom;
55976
55977-extern atomic_t fscache_n_invalidates;
55978-extern atomic_t fscache_n_invalidates_run;
55979+extern atomic_unchecked_t fscache_n_invalidates;
55980+extern atomic_unchecked_t fscache_n_invalidates_run;
55981
55982-extern atomic_t fscache_n_updates;
55983-extern atomic_t fscache_n_updates_null;
55984-extern atomic_t fscache_n_updates_run;
55985+extern atomic_unchecked_t fscache_n_updates;
55986+extern atomic_unchecked_t fscache_n_updates_null;
55987+extern atomic_unchecked_t fscache_n_updates_run;
55988
55989-extern atomic_t fscache_n_relinquishes;
55990-extern atomic_t fscache_n_relinquishes_null;
55991-extern atomic_t fscache_n_relinquishes_waitcrt;
55992-extern atomic_t fscache_n_relinquishes_retire;
55993+extern atomic_unchecked_t fscache_n_relinquishes;
55994+extern atomic_unchecked_t fscache_n_relinquishes_null;
55995+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
55996+extern atomic_unchecked_t fscache_n_relinquishes_retire;
55997
55998-extern atomic_t fscache_n_cookie_index;
55999-extern atomic_t fscache_n_cookie_data;
56000-extern atomic_t fscache_n_cookie_special;
56001+extern atomic_unchecked_t fscache_n_cookie_index;
56002+extern atomic_unchecked_t fscache_n_cookie_data;
56003+extern atomic_unchecked_t fscache_n_cookie_special;
56004
56005-extern atomic_t fscache_n_object_alloc;
56006-extern atomic_t fscache_n_object_no_alloc;
56007-extern atomic_t fscache_n_object_lookups;
56008-extern atomic_t fscache_n_object_lookups_negative;
56009-extern atomic_t fscache_n_object_lookups_positive;
56010-extern atomic_t fscache_n_object_lookups_timed_out;
56011-extern atomic_t fscache_n_object_created;
56012-extern atomic_t fscache_n_object_avail;
56013-extern atomic_t fscache_n_object_dead;
56014+extern atomic_unchecked_t fscache_n_object_alloc;
56015+extern atomic_unchecked_t fscache_n_object_no_alloc;
56016+extern atomic_unchecked_t fscache_n_object_lookups;
56017+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56018+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56019+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56020+extern atomic_unchecked_t fscache_n_object_created;
56021+extern atomic_unchecked_t fscache_n_object_avail;
56022+extern atomic_unchecked_t fscache_n_object_dead;
56023
56024-extern atomic_t fscache_n_checkaux_none;
56025-extern atomic_t fscache_n_checkaux_okay;
56026-extern atomic_t fscache_n_checkaux_update;
56027-extern atomic_t fscache_n_checkaux_obsolete;
56028+extern atomic_unchecked_t fscache_n_checkaux_none;
56029+extern atomic_unchecked_t fscache_n_checkaux_okay;
56030+extern atomic_unchecked_t fscache_n_checkaux_update;
56031+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56032
56033 extern atomic_t fscache_n_cop_alloc_object;
56034 extern atomic_t fscache_n_cop_lookup_object;
56035@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56036 atomic_inc(stat);
56037 }
56038
56039+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56040+{
56041+ atomic_inc_unchecked(stat);
56042+}
56043+
56044 static inline void fscache_stat_d(atomic_t *stat)
56045 {
56046 atomic_dec(stat);
56047@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56048
56049 #define __fscache_stat(stat) (NULL)
56050 #define fscache_stat(stat) do {} while (0)
56051+#define fscache_stat_unchecked(stat) do {} while (0)
56052 #define fscache_stat_d(stat) do {} while (0)
56053 #endif
56054
56055diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56056index 86d75a6..5f3d7a0 100644
56057--- a/fs/fscache/object.c
56058+++ b/fs/fscache/object.c
56059@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56060 _debug("LOOKUP \"%s\" in \"%s\"",
56061 cookie->def->name, object->cache->tag->name);
56062
56063- fscache_stat(&fscache_n_object_lookups);
56064+ fscache_stat_unchecked(&fscache_n_object_lookups);
56065 fscache_stat(&fscache_n_cop_lookup_object);
56066 ret = object->cache->ops->lookup_object(object);
56067 fscache_stat_d(&fscache_n_cop_lookup_object);
56068@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56069 if (ret == -ETIMEDOUT) {
56070 /* probably stuck behind another object, so move this one to
56071 * the back of the queue */
56072- fscache_stat(&fscache_n_object_lookups_timed_out);
56073+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56074 _leave(" [timeout]");
56075 return NO_TRANSIT;
56076 }
56077@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56078 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56079
56080 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56081- fscache_stat(&fscache_n_object_lookups_negative);
56082+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56083
56084 /* Allow write requests to begin stacking up and read requests to begin
56085 * returning ENODATA.
56086@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56087 /* if we were still looking up, then we must have a positive lookup
56088 * result, in which case there may be data available */
56089 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56090- fscache_stat(&fscache_n_object_lookups_positive);
56091+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56092
56093 /* We do (presumably) have data */
56094 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56095@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56096 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56097 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56098 } else {
56099- fscache_stat(&fscache_n_object_created);
56100+ fscache_stat_unchecked(&fscache_n_object_created);
56101 }
56102
56103 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56104@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56105 fscache_stat_d(&fscache_n_cop_lookup_complete);
56106
56107 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56108- fscache_stat(&fscache_n_object_avail);
56109+ fscache_stat_unchecked(&fscache_n_object_avail);
56110
56111 _leave("");
56112 return transit_to(JUMPSTART_DEPS);
56113@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56114
56115 /* this just shifts the object release to the work processor */
56116 fscache_put_object(object);
56117- fscache_stat(&fscache_n_object_dead);
56118+ fscache_stat_unchecked(&fscache_n_object_dead);
56119
56120 _leave("");
56121 return transit_to(OBJECT_DEAD);
56122@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56123 enum fscache_checkaux result;
56124
56125 if (!object->cookie->def->check_aux) {
56126- fscache_stat(&fscache_n_checkaux_none);
56127+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56128 return FSCACHE_CHECKAUX_OKAY;
56129 }
56130
56131@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56132 switch (result) {
56133 /* entry okay as is */
56134 case FSCACHE_CHECKAUX_OKAY:
56135- fscache_stat(&fscache_n_checkaux_okay);
56136+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56137 break;
56138
56139 /* entry requires update */
56140 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56141- fscache_stat(&fscache_n_checkaux_update);
56142+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56143 break;
56144
56145 /* entry requires deletion */
56146 case FSCACHE_CHECKAUX_OBSOLETE:
56147- fscache_stat(&fscache_n_checkaux_obsolete);
56148+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56149 break;
56150
56151 default:
56152@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56153 {
56154 const struct fscache_state *s;
56155
56156- fscache_stat(&fscache_n_invalidates_run);
56157+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56158 fscache_stat(&fscache_n_cop_invalidate_object);
56159 s = _fscache_invalidate_object(object, event);
56160 fscache_stat_d(&fscache_n_cop_invalidate_object);
56161@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56162 {
56163 _enter("{OBJ%x},%d", object->debug_id, event);
56164
56165- fscache_stat(&fscache_n_updates_run);
56166+ fscache_stat_unchecked(&fscache_n_updates_run);
56167 fscache_stat(&fscache_n_cop_update_object);
56168 object->cache->ops->update_object(object);
56169 fscache_stat_d(&fscache_n_cop_update_object);
56170diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56171index 318071a..379938b 100644
56172--- a/fs/fscache/operation.c
56173+++ b/fs/fscache/operation.c
56174@@ -17,7 +17,7 @@
56175 #include <linux/slab.h>
56176 #include "internal.h"
56177
56178-atomic_t fscache_op_debug_id;
56179+atomic_unchecked_t fscache_op_debug_id;
56180 EXPORT_SYMBOL(fscache_op_debug_id);
56181
56182 /**
56183@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56184 ASSERTCMP(atomic_read(&op->usage), >, 0);
56185 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56186
56187- fscache_stat(&fscache_n_op_enqueue);
56188+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56189 switch (op->flags & FSCACHE_OP_TYPE) {
56190 case FSCACHE_OP_ASYNC:
56191 _debug("queue async");
56192@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56193 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56194 if (op->processor)
56195 fscache_enqueue_operation(op);
56196- fscache_stat(&fscache_n_op_run);
56197+ fscache_stat_unchecked(&fscache_n_op_run);
56198 }
56199
56200 /*
56201@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56202 if (object->n_in_progress > 0) {
56203 atomic_inc(&op->usage);
56204 list_add_tail(&op->pend_link, &object->pending_ops);
56205- fscache_stat(&fscache_n_op_pend);
56206+ fscache_stat_unchecked(&fscache_n_op_pend);
56207 } else if (!list_empty(&object->pending_ops)) {
56208 atomic_inc(&op->usage);
56209 list_add_tail(&op->pend_link, &object->pending_ops);
56210- fscache_stat(&fscache_n_op_pend);
56211+ fscache_stat_unchecked(&fscache_n_op_pend);
56212 fscache_start_operations(object);
56213 } else {
56214 ASSERTCMP(object->n_in_progress, ==, 0);
56215@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56216 object->n_exclusive++; /* reads and writes must wait */
56217 atomic_inc(&op->usage);
56218 list_add_tail(&op->pend_link, &object->pending_ops);
56219- fscache_stat(&fscache_n_op_pend);
56220+ fscache_stat_unchecked(&fscache_n_op_pend);
56221 ret = 0;
56222 } else {
56223 /* If we're in any other state, there must have been an I/O
56224@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56225 if (object->n_exclusive > 0) {
56226 atomic_inc(&op->usage);
56227 list_add_tail(&op->pend_link, &object->pending_ops);
56228- fscache_stat(&fscache_n_op_pend);
56229+ fscache_stat_unchecked(&fscache_n_op_pend);
56230 } else if (!list_empty(&object->pending_ops)) {
56231 atomic_inc(&op->usage);
56232 list_add_tail(&op->pend_link, &object->pending_ops);
56233- fscache_stat(&fscache_n_op_pend);
56234+ fscache_stat_unchecked(&fscache_n_op_pend);
56235 fscache_start_operations(object);
56236 } else {
56237 ASSERTCMP(object->n_exclusive, ==, 0);
56238@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56239 object->n_ops++;
56240 atomic_inc(&op->usage);
56241 list_add_tail(&op->pend_link, &object->pending_ops);
56242- fscache_stat(&fscache_n_op_pend);
56243+ fscache_stat_unchecked(&fscache_n_op_pend);
56244 ret = 0;
56245 } else if (fscache_object_is_dying(object)) {
56246- fscache_stat(&fscache_n_op_rejected);
56247+ fscache_stat_unchecked(&fscache_n_op_rejected);
56248 op->state = FSCACHE_OP_ST_CANCELLED;
56249 ret = -ENOBUFS;
56250 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56251@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56252 ret = -EBUSY;
56253 if (op->state == FSCACHE_OP_ST_PENDING) {
56254 ASSERT(!list_empty(&op->pend_link));
56255- fscache_stat(&fscache_n_op_cancelled);
56256+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56257 list_del_init(&op->pend_link);
56258 if (do_cancel)
56259 do_cancel(op);
56260@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56261 while (!list_empty(&object->pending_ops)) {
56262 op = list_entry(object->pending_ops.next,
56263 struct fscache_operation, pend_link);
56264- fscache_stat(&fscache_n_op_cancelled);
56265+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56266 list_del_init(&op->pend_link);
56267
56268 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56269@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56270 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56271 op->state = FSCACHE_OP_ST_DEAD;
56272
56273- fscache_stat(&fscache_n_op_release);
56274+ fscache_stat_unchecked(&fscache_n_op_release);
56275
56276 if (op->release) {
56277 op->release(op);
56278@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56279 * lock, and defer it otherwise */
56280 if (!spin_trylock(&object->lock)) {
56281 _debug("defer put");
56282- fscache_stat(&fscache_n_op_deferred_release);
56283+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56284
56285 cache = object->cache;
56286 spin_lock(&cache->op_gc_list_lock);
56287@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56288
56289 _debug("GC DEFERRED REL OBJ%x OP%x",
56290 object->debug_id, op->debug_id);
56291- fscache_stat(&fscache_n_op_gc);
56292+ fscache_stat_unchecked(&fscache_n_op_gc);
56293
56294 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56295 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56296diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56297index d479ab3..727a7f2 100644
56298--- a/fs/fscache/page.c
56299+++ b/fs/fscache/page.c
56300@@ -61,7 +61,7 @@ try_again:
56301 val = radix_tree_lookup(&cookie->stores, page->index);
56302 if (!val) {
56303 rcu_read_unlock();
56304- fscache_stat(&fscache_n_store_vmscan_not_storing);
56305+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56306 __fscache_uncache_page(cookie, page);
56307 return true;
56308 }
56309@@ -91,11 +91,11 @@ try_again:
56310 spin_unlock(&cookie->stores_lock);
56311
56312 if (xpage) {
56313- fscache_stat(&fscache_n_store_vmscan_cancelled);
56314- fscache_stat(&fscache_n_store_radix_deletes);
56315+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56316+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56317 ASSERTCMP(xpage, ==, page);
56318 } else {
56319- fscache_stat(&fscache_n_store_vmscan_gone);
56320+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56321 }
56322
56323 wake_up_bit(&cookie->flags, 0);
56324@@ -110,11 +110,11 @@ page_busy:
56325 * sleeping on memory allocation, so we may need to impose a timeout
56326 * too. */
56327 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56328- fscache_stat(&fscache_n_store_vmscan_busy);
56329+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56330 return false;
56331 }
56332
56333- fscache_stat(&fscache_n_store_vmscan_wait);
56334+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56335 __fscache_wait_on_page_write(cookie, page);
56336 gfp &= ~__GFP_WAIT;
56337 goto try_again;
56338@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56339 FSCACHE_COOKIE_STORING_TAG);
56340 if (!radix_tree_tag_get(&cookie->stores, page->index,
56341 FSCACHE_COOKIE_PENDING_TAG)) {
56342- fscache_stat(&fscache_n_store_radix_deletes);
56343+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56344 xpage = radix_tree_delete(&cookie->stores, page->index);
56345 }
56346 spin_unlock(&cookie->stores_lock);
56347@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56348
56349 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56350
56351- fscache_stat(&fscache_n_attr_changed_calls);
56352+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56353
56354 if (fscache_object_is_active(object) &&
56355 fscache_use_cookie(object)) {
56356@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56357
56358 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56359
56360- fscache_stat(&fscache_n_attr_changed);
56361+ fscache_stat_unchecked(&fscache_n_attr_changed);
56362
56363 op = kzalloc(sizeof(*op), GFP_KERNEL);
56364 if (!op) {
56365- fscache_stat(&fscache_n_attr_changed_nomem);
56366+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56367 _leave(" = -ENOMEM");
56368 return -ENOMEM;
56369 }
56370@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56371 if (fscache_submit_exclusive_op(object, op) < 0)
56372 goto nobufs;
56373 spin_unlock(&cookie->lock);
56374- fscache_stat(&fscache_n_attr_changed_ok);
56375+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56376 fscache_put_operation(op);
56377 _leave(" = 0");
56378 return 0;
56379@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56380 nobufs:
56381 spin_unlock(&cookie->lock);
56382 kfree(op);
56383- fscache_stat(&fscache_n_attr_changed_nobufs);
56384+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56385 _leave(" = %d", -ENOBUFS);
56386 return -ENOBUFS;
56387 }
56388@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56389 /* allocate a retrieval operation and attempt to submit it */
56390 op = kzalloc(sizeof(*op), GFP_NOIO);
56391 if (!op) {
56392- fscache_stat(&fscache_n_retrievals_nomem);
56393+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56394 return NULL;
56395 }
56396
56397@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56398 return 0;
56399 }
56400
56401- fscache_stat(&fscache_n_retrievals_wait);
56402+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56403
56404 jif = jiffies;
56405 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56406 fscache_wait_bit_interruptible,
56407 TASK_INTERRUPTIBLE) != 0) {
56408- fscache_stat(&fscache_n_retrievals_intr);
56409+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56410 _leave(" = -ERESTARTSYS");
56411 return -ERESTARTSYS;
56412 }
56413@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56414 */
56415 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56416 struct fscache_retrieval *op,
56417- atomic_t *stat_op_waits,
56418- atomic_t *stat_object_dead)
56419+ atomic_unchecked_t *stat_op_waits,
56420+ atomic_unchecked_t *stat_object_dead)
56421 {
56422 int ret;
56423
56424@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56425 goto check_if_dead;
56426
56427 _debug(">>> WT");
56428- fscache_stat(stat_op_waits);
56429+ fscache_stat_unchecked(stat_op_waits);
56430 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56431 fscache_wait_bit_interruptible,
56432 TASK_INTERRUPTIBLE) != 0) {
56433@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56434
56435 check_if_dead:
56436 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56437- fscache_stat(stat_object_dead);
56438+ fscache_stat_unchecked(stat_object_dead);
56439 _leave(" = -ENOBUFS [cancelled]");
56440 return -ENOBUFS;
56441 }
56442 if (unlikely(fscache_object_is_dead(object))) {
56443 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56444 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56445- fscache_stat(stat_object_dead);
56446+ fscache_stat_unchecked(stat_object_dead);
56447 return -ENOBUFS;
56448 }
56449 return 0;
56450@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56451
56452 _enter("%p,%p,,,", cookie, page);
56453
56454- fscache_stat(&fscache_n_retrievals);
56455+ fscache_stat_unchecked(&fscache_n_retrievals);
56456
56457 if (hlist_empty(&cookie->backing_objects))
56458 goto nobufs;
56459@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56460 goto nobufs_unlock_dec;
56461 spin_unlock(&cookie->lock);
56462
56463- fscache_stat(&fscache_n_retrieval_ops);
56464+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56465
56466 /* pin the netfs read context in case we need to do the actual netfs
56467 * read because we've encountered a cache read failure */
56468@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56469
56470 error:
56471 if (ret == -ENOMEM)
56472- fscache_stat(&fscache_n_retrievals_nomem);
56473+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56474 else if (ret == -ERESTARTSYS)
56475- fscache_stat(&fscache_n_retrievals_intr);
56476+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56477 else if (ret == -ENODATA)
56478- fscache_stat(&fscache_n_retrievals_nodata);
56479+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56480 else if (ret < 0)
56481- fscache_stat(&fscache_n_retrievals_nobufs);
56482+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56483 else
56484- fscache_stat(&fscache_n_retrievals_ok);
56485+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56486
56487 fscache_put_retrieval(op);
56488 _leave(" = %d", ret);
56489@@ -475,7 +475,7 @@ nobufs_unlock:
56490 atomic_dec(&cookie->n_active);
56491 kfree(op);
56492 nobufs:
56493- fscache_stat(&fscache_n_retrievals_nobufs);
56494+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56495 _leave(" = -ENOBUFS");
56496 return -ENOBUFS;
56497 }
56498@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56499
56500 _enter("%p,,%d,,,", cookie, *nr_pages);
56501
56502- fscache_stat(&fscache_n_retrievals);
56503+ fscache_stat_unchecked(&fscache_n_retrievals);
56504
56505 if (hlist_empty(&cookie->backing_objects))
56506 goto nobufs;
56507@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56508 goto nobufs_unlock_dec;
56509 spin_unlock(&cookie->lock);
56510
56511- fscache_stat(&fscache_n_retrieval_ops);
56512+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56513
56514 /* pin the netfs read context in case we need to do the actual netfs
56515 * read because we've encountered a cache read failure */
56516@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56517
56518 error:
56519 if (ret == -ENOMEM)
56520- fscache_stat(&fscache_n_retrievals_nomem);
56521+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56522 else if (ret == -ERESTARTSYS)
56523- fscache_stat(&fscache_n_retrievals_intr);
56524+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56525 else if (ret == -ENODATA)
56526- fscache_stat(&fscache_n_retrievals_nodata);
56527+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56528 else if (ret < 0)
56529- fscache_stat(&fscache_n_retrievals_nobufs);
56530+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56531 else
56532- fscache_stat(&fscache_n_retrievals_ok);
56533+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56534
56535 fscache_put_retrieval(op);
56536 _leave(" = %d", ret);
56537@@ -600,7 +600,7 @@ nobufs_unlock:
56538 atomic_dec(&cookie->n_active);
56539 kfree(op);
56540 nobufs:
56541- fscache_stat(&fscache_n_retrievals_nobufs);
56542+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56543 _leave(" = -ENOBUFS");
56544 return -ENOBUFS;
56545 }
56546@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56547
56548 _enter("%p,%p,,,", cookie, page);
56549
56550- fscache_stat(&fscache_n_allocs);
56551+ fscache_stat_unchecked(&fscache_n_allocs);
56552
56553 if (hlist_empty(&cookie->backing_objects))
56554 goto nobufs;
56555@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56556 goto nobufs_unlock;
56557 spin_unlock(&cookie->lock);
56558
56559- fscache_stat(&fscache_n_alloc_ops);
56560+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56561
56562 ret = fscache_wait_for_retrieval_activation(
56563 object, op,
56564@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56565
56566 error:
56567 if (ret == -ERESTARTSYS)
56568- fscache_stat(&fscache_n_allocs_intr);
56569+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56570 else if (ret < 0)
56571- fscache_stat(&fscache_n_allocs_nobufs);
56572+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56573 else
56574- fscache_stat(&fscache_n_allocs_ok);
56575+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56576
56577 fscache_put_retrieval(op);
56578 _leave(" = %d", ret);
56579@@ -687,7 +687,7 @@ nobufs_unlock:
56580 atomic_dec(&cookie->n_active);
56581 kfree(op);
56582 nobufs:
56583- fscache_stat(&fscache_n_allocs_nobufs);
56584+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56585 _leave(" = -ENOBUFS");
56586 return -ENOBUFS;
56587 }
56588@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56589
56590 spin_lock(&cookie->stores_lock);
56591
56592- fscache_stat(&fscache_n_store_calls);
56593+ fscache_stat_unchecked(&fscache_n_store_calls);
56594
56595 /* find a page to store */
56596 page = NULL;
56597@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56598 page = results[0];
56599 _debug("gang %d [%lx]", n, page->index);
56600 if (page->index > op->store_limit) {
56601- fscache_stat(&fscache_n_store_pages_over_limit);
56602+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56603 goto superseded;
56604 }
56605
56606@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56607 spin_unlock(&cookie->stores_lock);
56608 spin_unlock(&object->lock);
56609
56610- fscache_stat(&fscache_n_store_pages);
56611+ fscache_stat_unchecked(&fscache_n_store_pages);
56612 fscache_stat(&fscache_n_cop_write_page);
56613 ret = object->cache->ops->write_page(op, page);
56614 fscache_stat_d(&fscache_n_cop_write_page);
56615@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56616 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56617 ASSERT(PageFsCache(page));
56618
56619- fscache_stat(&fscache_n_stores);
56620+ fscache_stat_unchecked(&fscache_n_stores);
56621
56622 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56623 _leave(" = -ENOBUFS [invalidating]");
56624@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56625 spin_unlock(&cookie->stores_lock);
56626 spin_unlock(&object->lock);
56627
56628- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56629+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56630 op->store_limit = object->store_limit;
56631
56632 atomic_inc(&cookie->n_active);
56633@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56634
56635 spin_unlock(&cookie->lock);
56636 radix_tree_preload_end();
56637- fscache_stat(&fscache_n_store_ops);
56638- fscache_stat(&fscache_n_stores_ok);
56639+ fscache_stat_unchecked(&fscache_n_store_ops);
56640+ fscache_stat_unchecked(&fscache_n_stores_ok);
56641
56642 /* the work queue now carries its own ref on the object */
56643 fscache_put_operation(&op->op);
56644@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56645 return 0;
56646
56647 already_queued:
56648- fscache_stat(&fscache_n_stores_again);
56649+ fscache_stat_unchecked(&fscache_n_stores_again);
56650 already_pending:
56651 spin_unlock(&cookie->stores_lock);
56652 spin_unlock(&object->lock);
56653 spin_unlock(&cookie->lock);
56654 radix_tree_preload_end();
56655 kfree(op);
56656- fscache_stat(&fscache_n_stores_ok);
56657+ fscache_stat_unchecked(&fscache_n_stores_ok);
56658 _leave(" = 0");
56659 return 0;
56660
56661@@ -976,14 +976,14 @@ nobufs:
56662 spin_unlock(&cookie->lock);
56663 radix_tree_preload_end();
56664 kfree(op);
56665- fscache_stat(&fscache_n_stores_nobufs);
56666+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56667 _leave(" = -ENOBUFS");
56668 return -ENOBUFS;
56669
56670 nomem_free:
56671 kfree(op);
56672 nomem:
56673- fscache_stat(&fscache_n_stores_oom);
56674+ fscache_stat_unchecked(&fscache_n_stores_oom);
56675 _leave(" = -ENOMEM");
56676 return -ENOMEM;
56677 }
56678@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56679 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56680 ASSERTCMP(page, !=, NULL);
56681
56682- fscache_stat(&fscache_n_uncaches);
56683+ fscache_stat_unchecked(&fscache_n_uncaches);
56684
56685 /* cache withdrawal may beat us to it */
56686 if (!PageFsCache(page))
56687@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56688 struct fscache_cookie *cookie = op->op.object->cookie;
56689
56690 #ifdef CONFIG_FSCACHE_STATS
56691- atomic_inc(&fscache_n_marks);
56692+ atomic_inc_unchecked(&fscache_n_marks);
56693 #endif
56694
56695 _debug("- mark %p{%lx}", page, page->index);
56696diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56697index 40d13c7..ddf52b9 100644
56698--- a/fs/fscache/stats.c
56699+++ b/fs/fscache/stats.c
56700@@ -18,99 +18,99 @@
56701 /*
56702 * operation counters
56703 */
56704-atomic_t fscache_n_op_pend;
56705-atomic_t fscache_n_op_run;
56706-atomic_t fscache_n_op_enqueue;
56707-atomic_t fscache_n_op_requeue;
56708-atomic_t fscache_n_op_deferred_release;
56709-atomic_t fscache_n_op_release;
56710-atomic_t fscache_n_op_gc;
56711-atomic_t fscache_n_op_cancelled;
56712-atomic_t fscache_n_op_rejected;
56713+atomic_unchecked_t fscache_n_op_pend;
56714+atomic_unchecked_t fscache_n_op_run;
56715+atomic_unchecked_t fscache_n_op_enqueue;
56716+atomic_unchecked_t fscache_n_op_requeue;
56717+atomic_unchecked_t fscache_n_op_deferred_release;
56718+atomic_unchecked_t fscache_n_op_release;
56719+atomic_unchecked_t fscache_n_op_gc;
56720+atomic_unchecked_t fscache_n_op_cancelled;
56721+atomic_unchecked_t fscache_n_op_rejected;
56722
56723-atomic_t fscache_n_attr_changed;
56724-atomic_t fscache_n_attr_changed_ok;
56725-atomic_t fscache_n_attr_changed_nobufs;
56726-atomic_t fscache_n_attr_changed_nomem;
56727-atomic_t fscache_n_attr_changed_calls;
56728+atomic_unchecked_t fscache_n_attr_changed;
56729+atomic_unchecked_t fscache_n_attr_changed_ok;
56730+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56731+atomic_unchecked_t fscache_n_attr_changed_nomem;
56732+atomic_unchecked_t fscache_n_attr_changed_calls;
56733
56734-atomic_t fscache_n_allocs;
56735-atomic_t fscache_n_allocs_ok;
56736-atomic_t fscache_n_allocs_wait;
56737-atomic_t fscache_n_allocs_nobufs;
56738-atomic_t fscache_n_allocs_intr;
56739-atomic_t fscache_n_allocs_object_dead;
56740-atomic_t fscache_n_alloc_ops;
56741-atomic_t fscache_n_alloc_op_waits;
56742+atomic_unchecked_t fscache_n_allocs;
56743+atomic_unchecked_t fscache_n_allocs_ok;
56744+atomic_unchecked_t fscache_n_allocs_wait;
56745+atomic_unchecked_t fscache_n_allocs_nobufs;
56746+atomic_unchecked_t fscache_n_allocs_intr;
56747+atomic_unchecked_t fscache_n_allocs_object_dead;
56748+atomic_unchecked_t fscache_n_alloc_ops;
56749+atomic_unchecked_t fscache_n_alloc_op_waits;
56750
56751-atomic_t fscache_n_retrievals;
56752-atomic_t fscache_n_retrievals_ok;
56753-atomic_t fscache_n_retrievals_wait;
56754-atomic_t fscache_n_retrievals_nodata;
56755-atomic_t fscache_n_retrievals_nobufs;
56756-atomic_t fscache_n_retrievals_intr;
56757-atomic_t fscache_n_retrievals_nomem;
56758-atomic_t fscache_n_retrievals_object_dead;
56759-atomic_t fscache_n_retrieval_ops;
56760-atomic_t fscache_n_retrieval_op_waits;
56761+atomic_unchecked_t fscache_n_retrievals;
56762+atomic_unchecked_t fscache_n_retrievals_ok;
56763+atomic_unchecked_t fscache_n_retrievals_wait;
56764+atomic_unchecked_t fscache_n_retrievals_nodata;
56765+atomic_unchecked_t fscache_n_retrievals_nobufs;
56766+atomic_unchecked_t fscache_n_retrievals_intr;
56767+atomic_unchecked_t fscache_n_retrievals_nomem;
56768+atomic_unchecked_t fscache_n_retrievals_object_dead;
56769+atomic_unchecked_t fscache_n_retrieval_ops;
56770+atomic_unchecked_t fscache_n_retrieval_op_waits;
56771
56772-atomic_t fscache_n_stores;
56773-atomic_t fscache_n_stores_ok;
56774-atomic_t fscache_n_stores_again;
56775-atomic_t fscache_n_stores_nobufs;
56776-atomic_t fscache_n_stores_oom;
56777-atomic_t fscache_n_store_ops;
56778-atomic_t fscache_n_store_calls;
56779-atomic_t fscache_n_store_pages;
56780-atomic_t fscache_n_store_radix_deletes;
56781-atomic_t fscache_n_store_pages_over_limit;
56782+atomic_unchecked_t fscache_n_stores;
56783+atomic_unchecked_t fscache_n_stores_ok;
56784+atomic_unchecked_t fscache_n_stores_again;
56785+atomic_unchecked_t fscache_n_stores_nobufs;
56786+atomic_unchecked_t fscache_n_stores_oom;
56787+atomic_unchecked_t fscache_n_store_ops;
56788+atomic_unchecked_t fscache_n_store_calls;
56789+atomic_unchecked_t fscache_n_store_pages;
56790+atomic_unchecked_t fscache_n_store_radix_deletes;
56791+atomic_unchecked_t fscache_n_store_pages_over_limit;
56792
56793-atomic_t fscache_n_store_vmscan_not_storing;
56794-atomic_t fscache_n_store_vmscan_gone;
56795-atomic_t fscache_n_store_vmscan_busy;
56796-atomic_t fscache_n_store_vmscan_cancelled;
56797-atomic_t fscache_n_store_vmscan_wait;
56798+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56799+atomic_unchecked_t fscache_n_store_vmscan_gone;
56800+atomic_unchecked_t fscache_n_store_vmscan_busy;
56801+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56802+atomic_unchecked_t fscache_n_store_vmscan_wait;
56803
56804-atomic_t fscache_n_marks;
56805-atomic_t fscache_n_uncaches;
56806+atomic_unchecked_t fscache_n_marks;
56807+atomic_unchecked_t fscache_n_uncaches;
56808
56809-atomic_t fscache_n_acquires;
56810-atomic_t fscache_n_acquires_null;
56811-atomic_t fscache_n_acquires_no_cache;
56812-atomic_t fscache_n_acquires_ok;
56813-atomic_t fscache_n_acquires_nobufs;
56814-atomic_t fscache_n_acquires_oom;
56815+atomic_unchecked_t fscache_n_acquires;
56816+atomic_unchecked_t fscache_n_acquires_null;
56817+atomic_unchecked_t fscache_n_acquires_no_cache;
56818+atomic_unchecked_t fscache_n_acquires_ok;
56819+atomic_unchecked_t fscache_n_acquires_nobufs;
56820+atomic_unchecked_t fscache_n_acquires_oom;
56821
56822-atomic_t fscache_n_invalidates;
56823-atomic_t fscache_n_invalidates_run;
56824+atomic_unchecked_t fscache_n_invalidates;
56825+atomic_unchecked_t fscache_n_invalidates_run;
56826
56827-atomic_t fscache_n_updates;
56828-atomic_t fscache_n_updates_null;
56829-atomic_t fscache_n_updates_run;
56830+atomic_unchecked_t fscache_n_updates;
56831+atomic_unchecked_t fscache_n_updates_null;
56832+atomic_unchecked_t fscache_n_updates_run;
56833
56834-atomic_t fscache_n_relinquishes;
56835-atomic_t fscache_n_relinquishes_null;
56836-atomic_t fscache_n_relinquishes_waitcrt;
56837-atomic_t fscache_n_relinquishes_retire;
56838+atomic_unchecked_t fscache_n_relinquishes;
56839+atomic_unchecked_t fscache_n_relinquishes_null;
56840+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56841+atomic_unchecked_t fscache_n_relinquishes_retire;
56842
56843-atomic_t fscache_n_cookie_index;
56844-atomic_t fscache_n_cookie_data;
56845-atomic_t fscache_n_cookie_special;
56846+atomic_unchecked_t fscache_n_cookie_index;
56847+atomic_unchecked_t fscache_n_cookie_data;
56848+atomic_unchecked_t fscache_n_cookie_special;
56849
56850-atomic_t fscache_n_object_alloc;
56851-atomic_t fscache_n_object_no_alloc;
56852-atomic_t fscache_n_object_lookups;
56853-atomic_t fscache_n_object_lookups_negative;
56854-atomic_t fscache_n_object_lookups_positive;
56855-atomic_t fscache_n_object_lookups_timed_out;
56856-atomic_t fscache_n_object_created;
56857-atomic_t fscache_n_object_avail;
56858-atomic_t fscache_n_object_dead;
56859+atomic_unchecked_t fscache_n_object_alloc;
56860+atomic_unchecked_t fscache_n_object_no_alloc;
56861+atomic_unchecked_t fscache_n_object_lookups;
56862+atomic_unchecked_t fscache_n_object_lookups_negative;
56863+atomic_unchecked_t fscache_n_object_lookups_positive;
56864+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56865+atomic_unchecked_t fscache_n_object_created;
56866+atomic_unchecked_t fscache_n_object_avail;
56867+atomic_unchecked_t fscache_n_object_dead;
56868
56869-atomic_t fscache_n_checkaux_none;
56870-atomic_t fscache_n_checkaux_okay;
56871-atomic_t fscache_n_checkaux_update;
56872-atomic_t fscache_n_checkaux_obsolete;
56873+atomic_unchecked_t fscache_n_checkaux_none;
56874+atomic_unchecked_t fscache_n_checkaux_okay;
56875+atomic_unchecked_t fscache_n_checkaux_update;
56876+atomic_unchecked_t fscache_n_checkaux_obsolete;
56877
56878 atomic_t fscache_n_cop_alloc_object;
56879 atomic_t fscache_n_cop_lookup_object;
56880@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56881 seq_puts(m, "FS-Cache statistics\n");
56882
56883 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56884- atomic_read(&fscache_n_cookie_index),
56885- atomic_read(&fscache_n_cookie_data),
56886- atomic_read(&fscache_n_cookie_special));
56887+ atomic_read_unchecked(&fscache_n_cookie_index),
56888+ atomic_read_unchecked(&fscache_n_cookie_data),
56889+ atomic_read_unchecked(&fscache_n_cookie_special));
56890
56891 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56892- atomic_read(&fscache_n_object_alloc),
56893- atomic_read(&fscache_n_object_no_alloc),
56894- atomic_read(&fscache_n_object_avail),
56895- atomic_read(&fscache_n_object_dead));
56896+ atomic_read_unchecked(&fscache_n_object_alloc),
56897+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56898+ atomic_read_unchecked(&fscache_n_object_avail),
56899+ atomic_read_unchecked(&fscache_n_object_dead));
56900 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56901- atomic_read(&fscache_n_checkaux_none),
56902- atomic_read(&fscache_n_checkaux_okay),
56903- atomic_read(&fscache_n_checkaux_update),
56904- atomic_read(&fscache_n_checkaux_obsolete));
56905+ atomic_read_unchecked(&fscache_n_checkaux_none),
56906+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56907+ atomic_read_unchecked(&fscache_n_checkaux_update),
56908+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56909
56910 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56911- atomic_read(&fscache_n_marks),
56912- atomic_read(&fscache_n_uncaches));
56913+ atomic_read_unchecked(&fscache_n_marks),
56914+ atomic_read_unchecked(&fscache_n_uncaches));
56915
56916 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56917 " oom=%u\n",
56918- atomic_read(&fscache_n_acquires),
56919- atomic_read(&fscache_n_acquires_null),
56920- atomic_read(&fscache_n_acquires_no_cache),
56921- atomic_read(&fscache_n_acquires_ok),
56922- atomic_read(&fscache_n_acquires_nobufs),
56923- atomic_read(&fscache_n_acquires_oom));
56924+ atomic_read_unchecked(&fscache_n_acquires),
56925+ atomic_read_unchecked(&fscache_n_acquires_null),
56926+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
56927+ atomic_read_unchecked(&fscache_n_acquires_ok),
56928+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
56929+ atomic_read_unchecked(&fscache_n_acquires_oom));
56930
56931 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
56932- atomic_read(&fscache_n_object_lookups),
56933- atomic_read(&fscache_n_object_lookups_negative),
56934- atomic_read(&fscache_n_object_lookups_positive),
56935- atomic_read(&fscache_n_object_created),
56936- atomic_read(&fscache_n_object_lookups_timed_out));
56937+ atomic_read_unchecked(&fscache_n_object_lookups),
56938+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
56939+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
56940+ atomic_read_unchecked(&fscache_n_object_created),
56941+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
56942
56943 seq_printf(m, "Invals : n=%u run=%u\n",
56944- atomic_read(&fscache_n_invalidates),
56945- atomic_read(&fscache_n_invalidates_run));
56946+ atomic_read_unchecked(&fscache_n_invalidates),
56947+ atomic_read_unchecked(&fscache_n_invalidates_run));
56948
56949 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
56950- atomic_read(&fscache_n_updates),
56951- atomic_read(&fscache_n_updates_null),
56952- atomic_read(&fscache_n_updates_run));
56953+ atomic_read_unchecked(&fscache_n_updates),
56954+ atomic_read_unchecked(&fscache_n_updates_null),
56955+ atomic_read_unchecked(&fscache_n_updates_run));
56956
56957 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
56958- atomic_read(&fscache_n_relinquishes),
56959- atomic_read(&fscache_n_relinquishes_null),
56960- atomic_read(&fscache_n_relinquishes_waitcrt),
56961- atomic_read(&fscache_n_relinquishes_retire));
56962+ atomic_read_unchecked(&fscache_n_relinquishes),
56963+ atomic_read_unchecked(&fscache_n_relinquishes_null),
56964+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
56965+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
56966
56967 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
56968- atomic_read(&fscache_n_attr_changed),
56969- atomic_read(&fscache_n_attr_changed_ok),
56970- atomic_read(&fscache_n_attr_changed_nobufs),
56971- atomic_read(&fscache_n_attr_changed_nomem),
56972- atomic_read(&fscache_n_attr_changed_calls));
56973+ atomic_read_unchecked(&fscache_n_attr_changed),
56974+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
56975+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
56976+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
56977+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
56978
56979 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
56980- atomic_read(&fscache_n_allocs),
56981- atomic_read(&fscache_n_allocs_ok),
56982- atomic_read(&fscache_n_allocs_wait),
56983- atomic_read(&fscache_n_allocs_nobufs),
56984- atomic_read(&fscache_n_allocs_intr));
56985+ atomic_read_unchecked(&fscache_n_allocs),
56986+ atomic_read_unchecked(&fscache_n_allocs_ok),
56987+ atomic_read_unchecked(&fscache_n_allocs_wait),
56988+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
56989+ atomic_read_unchecked(&fscache_n_allocs_intr));
56990 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
56991- atomic_read(&fscache_n_alloc_ops),
56992- atomic_read(&fscache_n_alloc_op_waits),
56993- atomic_read(&fscache_n_allocs_object_dead));
56994+ atomic_read_unchecked(&fscache_n_alloc_ops),
56995+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
56996+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
56997
56998 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
56999 " int=%u oom=%u\n",
57000- atomic_read(&fscache_n_retrievals),
57001- atomic_read(&fscache_n_retrievals_ok),
57002- atomic_read(&fscache_n_retrievals_wait),
57003- atomic_read(&fscache_n_retrievals_nodata),
57004- atomic_read(&fscache_n_retrievals_nobufs),
57005- atomic_read(&fscache_n_retrievals_intr),
57006- atomic_read(&fscache_n_retrievals_nomem));
57007+ atomic_read_unchecked(&fscache_n_retrievals),
57008+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57009+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57010+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57011+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57012+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57013+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57014 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57015- atomic_read(&fscache_n_retrieval_ops),
57016- atomic_read(&fscache_n_retrieval_op_waits),
57017- atomic_read(&fscache_n_retrievals_object_dead));
57018+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57019+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57020+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57021
57022 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57023- atomic_read(&fscache_n_stores),
57024- atomic_read(&fscache_n_stores_ok),
57025- atomic_read(&fscache_n_stores_again),
57026- atomic_read(&fscache_n_stores_nobufs),
57027- atomic_read(&fscache_n_stores_oom));
57028+ atomic_read_unchecked(&fscache_n_stores),
57029+ atomic_read_unchecked(&fscache_n_stores_ok),
57030+ atomic_read_unchecked(&fscache_n_stores_again),
57031+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57032+ atomic_read_unchecked(&fscache_n_stores_oom));
57033 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57034- atomic_read(&fscache_n_store_ops),
57035- atomic_read(&fscache_n_store_calls),
57036- atomic_read(&fscache_n_store_pages),
57037- atomic_read(&fscache_n_store_radix_deletes),
57038- atomic_read(&fscache_n_store_pages_over_limit));
57039+ atomic_read_unchecked(&fscache_n_store_ops),
57040+ atomic_read_unchecked(&fscache_n_store_calls),
57041+ atomic_read_unchecked(&fscache_n_store_pages),
57042+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57043+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57044
57045 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57046- atomic_read(&fscache_n_store_vmscan_not_storing),
57047- atomic_read(&fscache_n_store_vmscan_gone),
57048- atomic_read(&fscache_n_store_vmscan_busy),
57049- atomic_read(&fscache_n_store_vmscan_cancelled),
57050- atomic_read(&fscache_n_store_vmscan_wait));
57051+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57052+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57053+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57054+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57055+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57056
57057 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57058- atomic_read(&fscache_n_op_pend),
57059- atomic_read(&fscache_n_op_run),
57060- atomic_read(&fscache_n_op_enqueue),
57061- atomic_read(&fscache_n_op_cancelled),
57062- atomic_read(&fscache_n_op_rejected));
57063+ atomic_read_unchecked(&fscache_n_op_pend),
57064+ atomic_read_unchecked(&fscache_n_op_run),
57065+ atomic_read_unchecked(&fscache_n_op_enqueue),
57066+ atomic_read_unchecked(&fscache_n_op_cancelled),
57067+ atomic_read_unchecked(&fscache_n_op_rejected));
57068 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57069- atomic_read(&fscache_n_op_deferred_release),
57070- atomic_read(&fscache_n_op_release),
57071- atomic_read(&fscache_n_op_gc));
57072+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57073+ atomic_read_unchecked(&fscache_n_op_release),
57074+ atomic_read_unchecked(&fscache_n_op_gc));
57075
57076 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57077 atomic_read(&fscache_n_cop_alloc_object),
57078diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57079index aef34b1..59bfd7b 100644
57080--- a/fs/fuse/cuse.c
57081+++ b/fs/fuse/cuse.c
57082@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57083 INIT_LIST_HEAD(&cuse_conntbl[i]);
57084
57085 /* inherit and extend fuse_dev_operations */
57086- cuse_channel_fops = fuse_dev_operations;
57087- cuse_channel_fops.owner = THIS_MODULE;
57088- cuse_channel_fops.open = cuse_channel_open;
57089- cuse_channel_fops.release = cuse_channel_release;
57090+ pax_open_kernel();
57091+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57092+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57093+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57094+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57095+ pax_close_kernel();
57096
57097 cuse_class = class_create(THIS_MODULE, "cuse");
57098 if (IS_ERR(cuse_class))
57099diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57100index 1d55f94..088da65 100644
57101--- a/fs/fuse/dev.c
57102+++ b/fs/fuse/dev.c
57103@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57104 ret = 0;
57105 pipe_lock(pipe);
57106
57107- if (!pipe->readers) {
57108+ if (!atomic_read(&pipe->readers)) {
57109 send_sig(SIGPIPE, current, 0);
57110 if (!ret)
57111 ret = -EPIPE;
57112@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57113 page_nr++;
57114 ret += buf->len;
57115
57116- if (pipe->files)
57117+ if (atomic_read(&pipe->files))
57118 do_wakeup = 1;
57119 }
57120
57121diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57122index 8fec28f..cd40dba 100644
57123--- a/fs/fuse/dir.c
57124+++ b/fs/fuse/dir.c
57125@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
57126 return link;
57127 }
57128
57129-static void free_link(char *link)
57130+static void free_link(const char *link)
57131 {
57132 if (!IS_ERR(link))
57133 free_page((unsigned long) link);
57134diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57135index 64915ee..6bed500 100644
57136--- a/fs/gfs2/inode.c
57137+++ b/fs/gfs2/inode.c
57138@@ -1506,7 +1506,7 @@ out:
57139
57140 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57141 {
57142- char *s = nd_get_link(nd);
57143+ const char *s = nd_get_link(nd);
57144 if (!IS_ERR(s))
57145 kfree(s);
57146 }
57147diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57148index d19b30a..ef89c36 100644
57149--- a/fs/hugetlbfs/inode.c
57150+++ b/fs/hugetlbfs/inode.c
57151@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57152 struct mm_struct *mm = current->mm;
57153 struct vm_area_struct *vma;
57154 struct hstate *h = hstate_file(file);
57155+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57156 struct vm_unmapped_area_info info;
57157
57158 if (len & ~huge_page_mask(h))
57159@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57160 return addr;
57161 }
57162
57163+#ifdef CONFIG_PAX_RANDMMAP
57164+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57165+#endif
57166+
57167 if (addr) {
57168 addr = ALIGN(addr, huge_page_size(h));
57169 vma = find_vma(mm, addr);
57170- if (TASK_SIZE - len >= addr &&
57171- (!vma || addr + len <= vma->vm_start))
57172+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57173 return addr;
57174 }
57175
57176 info.flags = 0;
57177 info.length = len;
57178 info.low_limit = TASK_UNMAPPED_BASE;
57179+
57180+#ifdef CONFIG_PAX_RANDMMAP
57181+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57182+ info.low_limit += mm->delta_mmap;
57183+#endif
57184+
57185 info.high_limit = TASK_SIZE;
57186 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57187 info.align_offset = 0;
57188@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57189 };
57190 MODULE_ALIAS_FS("hugetlbfs");
57191
57192-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57193+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57194
57195 static int can_do_hugetlb_shm(void)
57196 {
57197diff --git a/fs/inode.c b/fs/inode.c
57198index d6dfb09..602e77e 100644
57199--- a/fs/inode.c
57200+++ b/fs/inode.c
57201@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57202
57203 #ifdef CONFIG_SMP
57204 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57205- static atomic_t shared_last_ino;
57206- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57207+ static atomic_unchecked_t shared_last_ino;
57208+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57209
57210 res = next - LAST_INO_BATCH;
57211 }
57212diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57213index 4a6cf28..d3a29d3 100644
57214--- a/fs/jffs2/erase.c
57215+++ b/fs/jffs2/erase.c
57216@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57217 struct jffs2_unknown_node marker = {
57218 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57219 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57220- .totlen = cpu_to_je32(c->cleanmarker_size)
57221+ .totlen = cpu_to_je32(c->cleanmarker_size),
57222+ .hdr_crc = cpu_to_je32(0)
57223 };
57224
57225 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57226diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57227index a6597d6..41b30ec 100644
57228--- a/fs/jffs2/wbuf.c
57229+++ b/fs/jffs2/wbuf.c
57230@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57231 {
57232 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57233 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57234- .totlen = constant_cpu_to_je32(8)
57235+ .totlen = constant_cpu_to_je32(8),
57236+ .hdr_crc = constant_cpu_to_je32(0)
57237 };
57238
57239 /*
57240diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57241index 6669aa2..36b033d 100644
57242--- a/fs/jfs/super.c
57243+++ b/fs/jfs/super.c
57244@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57245
57246 jfs_inode_cachep =
57247 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57248- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57249+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57250 init_once);
57251 if (jfs_inode_cachep == NULL)
57252 return -ENOMEM;
57253diff --git a/fs/libfs.c b/fs/libfs.c
57254index 3a3a9b5..3a9b074 100644
57255--- a/fs/libfs.c
57256+++ b/fs/libfs.c
57257@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57258
57259 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57260 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57261+ char d_name[sizeof(next->d_iname)];
57262+ const unsigned char *name;
57263+
57264 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57265 if (!simple_positive(next)) {
57266 spin_unlock(&next->d_lock);
57267@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57268
57269 spin_unlock(&next->d_lock);
57270 spin_unlock(&dentry->d_lock);
57271- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57272+ name = next->d_name.name;
57273+ if (name == next->d_iname) {
57274+ memcpy(d_name, name, next->d_name.len);
57275+ name = d_name;
57276+ }
57277+ if (!dir_emit(ctx, name, next->d_name.len,
57278 next->d_inode->i_ino, dt_type(next->d_inode)))
57279 return 0;
57280 spin_lock(&dentry->d_lock);
57281diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57282index acd3947..1f896e2 100644
57283--- a/fs/lockd/clntproc.c
57284+++ b/fs/lockd/clntproc.c
57285@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57286 /*
57287 * Cookie counter for NLM requests
57288 */
57289-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57290+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57291
57292 void nlmclnt_next_cookie(struct nlm_cookie *c)
57293 {
57294- u32 cookie = atomic_inc_return(&nlm_cookie);
57295+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57296
57297 memcpy(c->data, &cookie, 4);
57298 c->len=4;
57299diff --git a/fs/locks.c b/fs/locks.c
57300index b27a300..4156d0b 100644
57301--- a/fs/locks.c
57302+++ b/fs/locks.c
57303@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57304 return;
57305
57306 if (filp->f_op && filp->f_op->flock) {
57307- struct file_lock fl = {
57308+ struct file_lock flock = {
57309 .fl_pid = current->tgid,
57310 .fl_file = filp,
57311 .fl_flags = FL_FLOCK,
57312 .fl_type = F_UNLCK,
57313 .fl_end = OFFSET_MAX,
57314 };
57315- filp->f_op->flock(filp, F_SETLKW, &fl);
57316- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57317- fl.fl_ops->fl_release_private(&fl);
57318+ filp->f_op->flock(filp, F_SETLKW, &flock);
57319+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57320+ flock.fl_ops->fl_release_private(&flock);
57321 }
57322
57323 spin_lock(&inode->i_lock);
57324diff --git a/fs/namei.c b/fs/namei.c
57325index 7720fbd..7934bb2 100644
57326--- a/fs/namei.c
57327+++ b/fs/namei.c
57328@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57329 if (ret != -EACCES)
57330 return ret;
57331
57332+#ifdef CONFIG_GRKERNSEC
57333+ /* we'll block if we have to log due to a denied capability use */
57334+ if (mask & MAY_NOT_BLOCK)
57335+ return -ECHILD;
57336+#endif
57337+
57338 if (S_ISDIR(inode->i_mode)) {
57339 /* DACs are overridable for directories */
57340- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57341- return 0;
57342 if (!(mask & MAY_WRITE))
57343- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57344+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57345+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57346 return 0;
57347+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57348+ return 0;
57349 return -EACCES;
57350 }
57351 /*
57352+ * Searching includes executable on directories, else just read.
57353+ */
57354+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57355+ if (mask == MAY_READ)
57356+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57357+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57358+ return 0;
57359+
57360+ /*
57361 * Read/write DACs are always overridable.
57362 * Executable DACs are overridable when there is
57363 * at least one exec bit set.
57364@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57365 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57366 return 0;
57367
57368- /*
57369- * Searching includes executable on directories, else just read.
57370- */
57371- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57372- if (mask == MAY_READ)
57373- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57374- return 0;
57375-
57376 return -EACCES;
57377 }
57378
57379@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57380 {
57381 struct dentry *dentry = link->dentry;
57382 int error;
57383- char *s;
57384+ const char *s;
57385
57386 BUG_ON(nd->flags & LOOKUP_RCU);
57387
57388@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57389 if (error)
57390 goto out_put_nd_path;
57391
57392+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57393+ dentry->d_inode, dentry, nd->path.mnt)) {
57394+ error = -EACCES;
57395+ goto out_put_nd_path;
57396+ }
57397+
57398 nd->last_type = LAST_BIND;
57399 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57400 error = PTR_ERR(*p);
57401@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57402 if (res)
57403 break;
57404 res = walk_component(nd, path, LOOKUP_FOLLOW);
57405+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57406+ res = -EACCES;
57407 put_link(nd, &link, cookie);
57408 } while (res > 0);
57409
57410@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57411 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57412 {
57413 unsigned long a, b, adata, bdata, mask, hash, len;
57414- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57415+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57416
57417 hash = a = 0;
57418 len = -sizeof(unsigned long);
57419@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57420 if (err)
57421 break;
57422 err = lookup_last(nd, &path);
57423+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57424+ err = -EACCES;
57425 put_link(nd, &link, cookie);
57426 }
57427 }
57428@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57429 if (!err)
57430 err = complete_walk(nd);
57431
57432+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57433+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57434+ path_put(&nd->path);
57435+ err = -ENOENT;
57436+ }
57437+ }
57438+
57439 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57440 if (!can_lookup(nd->inode)) {
57441 path_put(&nd->path);
57442@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57443 retval = path_lookupat(dfd, name->name,
57444 flags | LOOKUP_REVAL, nd);
57445
57446- if (likely(!retval))
57447+ if (likely(!retval)) {
57448 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57449+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57450+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57451+ path_put(&nd->path);
57452+ return -ENOENT;
57453+ }
57454+ }
57455+ }
57456 return retval;
57457 }
57458
57459@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57460 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57461 return -EPERM;
57462
57463+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57464+ return -EPERM;
57465+ if (gr_handle_rawio(inode))
57466+ return -EPERM;
57467+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57468+ return -EACCES;
57469+
57470 return 0;
57471 }
57472
57473@@ -2601,7 +2640,7 @@ looked_up:
57474 * cleared otherwise prior to returning.
57475 */
57476 static int lookup_open(struct nameidata *nd, struct path *path,
57477- struct file *file,
57478+ struct path *link, struct file *file,
57479 const struct open_flags *op,
57480 bool got_write, int *opened)
57481 {
57482@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57483 /* Negative dentry, just create the file */
57484 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57485 umode_t mode = op->mode;
57486+
57487+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57488+ error = -EACCES;
57489+ goto out_dput;
57490+ }
57491+
57492+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57493+ error = -EACCES;
57494+ goto out_dput;
57495+ }
57496+
57497 if (!IS_POSIXACL(dir->d_inode))
57498 mode &= ~current_umask();
57499 /*
57500@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57501 nd->flags & LOOKUP_EXCL);
57502 if (error)
57503 goto out_dput;
57504+ else
57505+ gr_handle_create(dentry, nd->path.mnt);
57506 }
57507 out_no_open:
57508 path->dentry = dentry;
57509@@ -2671,7 +2723,7 @@ out_dput:
57510 /*
57511 * Handle the last step of open()
57512 */
57513-static int do_last(struct nameidata *nd, struct path *path,
57514+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57515 struct file *file, const struct open_flags *op,
57516 int *opened, struct filename *name)
57517 {
57518@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57519 if (error)
57520 return error;
57521
57522+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57523+ error = -ENOENT;
57524+ goto out;
57525+ }
57526+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57527+ error = -EACCES;
57528+ goto out;
57529+ }
57530+
57531 audit_inode(name, dir, LOOKUP_PARENT);
57532 error = -EISDIR;
57533 /* trailing slashes? */
57534@@ -2740,7 +2801,7 @@ retry_lookup:
57535 */
57536 }
57537 mutex_lock(&dir->d_inode->i_mutex);
57538- error = lookup_open(nd, path, file, op, got_write, opened);
57539+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57540 mutex_unlock(&dir->d_inode->i_mutex);
57541
57542 if (error <= 0) {
57543@@ -2764,11 +2825,28 @@ retry_lookup:
57544 goto finish_open_created;
57545 }
57546
57547+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57548+ error = -ENOENT;
57549+ goto exit_dput;
57550+ }
57551+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57552+ error = -EACCES;
57553+ goto exit_dput;
57554+ }
57555+
57556 /*
57557 * create/update audit record if it already exists.
57558 */
57559- if (path->dentry->d_inode)
57560+ if (path->dentry->d_inode) {
57561+ /* only check if O_CREAT is specified, all other checks need to go
57562+ into may_open */
57563+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57564+ error = -EACCES;
57565+ goto exit_dput;
57566+ }
57567+
57568 audit_inode(name, path->dentry, 0);
57569+ }
57570
57571 /*
57572 * If atomic_open() acquired write access it is dropped now due to
57573@@ -2809,6 +2887,11 @@ finish_lookup:
57574 }
57575 }
57576 BUG_ON(inode != path->dentry->d_inode);
57577+ /* if we're resolving a symlink to another symlink */
57578+ if (link && gr_handle_symlink_owner(link, inode)) {
57579+ error = -EACCES;
57580+ goto out;
57581+ }
57582 return 1;
57583 }
57584
57585@@ -2818,7 +2901,6 @@ finish_lookup:
57586 save_parent.dentry = nd->path.dentry;
57587 save_parent.mnt = mntget(path->mnt);
57588 nd->path.dentry = path->dentry;
57589-
57590 }
57591 nd->inode = inode;
57592 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57593@@ -2828,7 +2910,18 @@ finish_open:
57594 path_put(&save_parent);
57595 return error;
57596 }
57597+
57598+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57599+ error = -ENOENT;
57600+ goto out;
57601+ }
57602+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57603+ error = -EACCES;
57604+ goto out;
57605+ }
57606+
57607 audit_inode(name, nd->path.dentry, 0);
57608+
57609 error = -EISDIR;
57610 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57611 goto out;
57612@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57613 if (unlikely(error))
57614 goto out;
57615
57616- error = do_last(nd, &path, file, op, &opened, pathname);
57617+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57618 while (unlikely(error > 0)) { /* trailing symlink */
57619 struct path link = path;
57620 void *cookie;
57621@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57622 error = follow_link(&link, nd, &cookie);
57623 if (unlikely(error))
57624 break;
57625- error = do_last(nd, &path, file, op, &opened, pathname);
57626+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57627 put_link(nd, &link, cookie);
57628 }
57629 out:
57630@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57631 goto unlock;
57632
57633 error = -EEXIST;
57634- if (dentry->d_inode)
57635+ if (dentry->d_inode) {
57636+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57637+ error = -ENOENT;
57638+ }
57639 goto fail;
57640+ }
57641 /*
57642 * Special case - lookup gave negative, but... we had foo/bar/
57643 * From the vfs_mknod() POV we just have a negative dentry -
57644@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57645 }
57646 EXPORT_SYMBOL(user_path_create);
57647
57648+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57649+{
57650+ struct filename *tmp = getname(pathname);
57651+ struct dentry *res;
57652+ if (IS_ERR(tmp))
57653+ return ERR_CAST(tmp);
57654+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57655+ if (IS_ERR(res))
57656+ putname(tmp);
57657+ else
57658+ *to = tmp;
57659+ return res;
57660+}
57661+
57662 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57663 {
57664 int error = may_create(dir, dentry);
57665@@ -3224,6 +3335,17 @@ retry:
57666
57667 if (!IS_POSIXACL(path.dentry->d_inode))
57668 mode &= ~current_umask();
57669+
57670+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57671+ error = -EPERM;
57672+ goto out;
57673+ }
57674+
57675+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57676+ error = -EACCES;
57677+ goto out;
57678+ }
57679+
57680 error = security_path_mknod(&path, dentry, mode, dev);
57681 if (error)
57682 goto out;
57683@@ -3240,6 +3362,8 @@ retry:
57684 break;
57685 }
57686 out:
57687+ if (!error)
57688+ gr_handle_create(dentry, path.mnt);
57689 done_path_create(&path, dentry);
57690 if (retry_estale(error, lookup_flags)) {
57691 lookup_flags |= LOOKUP_REVAL;
57692@@ -3292,9 +3416,16 @@ retry:
57693
57694 if (!IS_POSIXACL(path.dentry->d_inode))
57695 mode &= ~current_umask();
57696+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57697+ error = -EACCES;
57698+ goto out;
57699+ }
57700 error = security_path_mkdir(&path, dentry, mode);
57701 if (!error)
57702 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57703+ if (!error)
57704+ gr_handle_create(dentry, path.mnt);
57705+out:
57706 done_path_create(&path, dentry);
57707 if (retry_estale(error, lookup_flags)) {
57708 lookup_flags |= LOOKUP_REVAL;
57709@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57710 struct filename *name;
57711 struct dentry *dentry;
57712 struct nameidata nd;
57713+ ino_t saved_ino = 0;
57714+ dev_t saved_dev = 0;
57715 unsigned int lookup_flags = 0;
57716 retry:
57717 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57718@@ -3407,10 +3540,21 @@ retry:
57719 error = -ENOENT;
57720 goto exit3;
57721 }
57722+
57723+ saved_ino = dentry->d_inode->i_ino;
57724+ saved_dev = gr_get_dev_from_dentry(dentry);
57725+
57726+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57727+ error = -EACCES;
57728+ goto exit3;
57729+ }
57730+
57731 error = security_path_rmdir(&nd.path, dentry);
57732 if (error)
57733 goto exit3;
57734 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57735+ if (!error && (saved_dev || saved_ino))
57736+ gr_handle_delete(saved_ino, saved_dev);
57737 exit3:
57738 dput(dentry);
57739 exit2:
57740@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57741 struct dentry *dentry;
57742 struct nameidata nd;
57743 struct inode *inode = NULL;
57744+ ino_t saved_ino = 0;
57745+ dev_t saved_dev = 0;
57746 unsigned int lookup_flags = 0;
57747 retry:
57748 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57749@@ -3502,10 +3648,22 @@ retry:
57750 if (!inode)
57751 goto slashes;
57752 ihold(inode);
57753+
57754+ if (inode->i_nlink <= 1) {
57755+ saved_ino = inode->i_ino;
57756+ saved_dev = gr_get_dev_from_dentry(dentry);
57757+ }
57758+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57759+ error = -EACCES;
57760+ goto exit2;
57761+ }
57762+
57763 error = security_path_unlink(&nd.path, dentry);
57764 if (error)
57765 goto exit2;
57766 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57767+ if (!error && (saved_ino || saved_dev))
57768+ gr_handle_delete(saved_ino, saved_dev);
57769 exit2:
57770 dput(dentry);
57771 }
57772@@ -3583,9 +3741,17 @@ retry:
57773 if (IS_ERR(dentry))
57774 goto out_putname;
57775
57776+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57777+ error = -EACCES;
57778+ goto out;
57779+ }
57780+
57781 error = security_path_symlink(&path, dentry, from->name);
57782 if (!error)
57783 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57784+ if (!error)
57785+ gr_handle_create(dentry, path.mnt);
57786+out:
57787 done_path_create(&path, dentry);
57788 if (retry_estale(error, lookup_flags)) {
57789 lookup_flags |= LOOKUP_REVAL;
57790@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57791 {
57792 struct dentry *new_dentry;
57793 struct path old_path, new_path;
57794+ struct filename *to = NULL;
57795 int how = 0;
57796 int error;
57797
57798@@ -3688,7 +3855,7 @@ retry:
57799 if (error)
57800 return error;
57801
57802- new_dentry = user_path_create(newdfd, newname, &new_path,
57803+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57804 (how & LOOKUP_REVAL));
57805 error = PTR_ERR(new_dentry);
57806 if (IS_ERR(new_dentry))
57807@@ -3700,11 +3867,28 @@ retry:
57808 error = may_linkat(&old_path);
57809 if (unlikely(error))
57810 goto out_dput;
57811+
57812+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57813+ old_path.dentry->d_inode,
57814+ old_path.dentry->d_inode->i_mode, to)) {
57815+ error = -EACCES;
57816+ goto out_dput;
57817+ }
57818+
57819+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57820+ old_path.dentry, old_path.mnt, to)) {
57821+ error = -EACCES;
57822+ goto out_dput;
57823+ }
57824+
57825 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57826 if (error)
57827 goto out_dput;
57828 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57829+ if (!error)
57830+ gr_handle_create(new_dentry, new_path.mnt);
57831 out_dput:
57832+ putname(to);
57833 done_path_create(&new_path, new_dentry);
57834 if (retry_estale(error, how)) {
57835 how |= LOOKUP_REVAL;
57836@@ -3950,12 +4134,21 @@ retry:
57837 if (new_dentry == trap)
57838 goto exit5;
57839
57840+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57841+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57842+ to);
57843+ if (error)
57844+ goto exit5;
57845+
57846 error = security_path_rename(&oldnd.path, old_dentry,
57847 &newnd.path, new_dentry);
57848 if (error)
57849 goto exit5;
57850 error = vfs_rename(old_dir->d_inode, old_dentry,
57851 new_dir->d_inode, new_dentry);
57852+ if (!error)
57853+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57854+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57855 exit5:
57856 dput(new_dentry);
57857 exit4:
57858@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57859
57860 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57861 {
57862+ char tmpbuf[64];
57863+ const char *newlink;
57864 int len;
57865
57866 len = PTR_ERR(link);
57867@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57868 len = strlen(link);
57869 if (len > (unsigned) buflen)
57870 len = buflen;
57871- if (copy_to_user(buffer, link, len))
57872+
57873+ if (len < sizeof(tmpbuf)) {
57874+ memcpy(tmpbuf, link, len);
57875+ newlink = tmpbuf;
57876+ } else
57877+ newlink = link;
57878+
57879+ if (copy_to_user(buffer, newlink, len))
57880 len = -EFAULT;
57881 out:
57882 return len;
57883diff --git a/fs/namespace.c b/fs/namespace.c
57884index a45ba4f..b4c7d07 100644
57885--- a/fs/namespace.c
57886+++ b/fs/namespace.c
57887@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57888 if (!(sb->s_flags & MS_RDONLY))
57889 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57890 up_write(&sb->s_umount);
57891+
57892+ gr_log_remount(mnt->mnt_devname, retval);
57893+
57894 return retval;
57895 }
57896
57897@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57898 }
57899 br_write_unlock(&vfsmount_lock);
57900 namespace_unlock();
57901+
57902+ gr_log_unmount(mnt->mnt_devname, retval);
57903+
57904 return retval;
57905 }
57906
57907@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57908 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57909 */
57910
57911-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57912+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57913 {
57914 struct path path;
57915 struct mount *mnt;
57916@@ -1342,7 +1348,7 @@ out:
57917 /*
57918 * The 2.0 compatible umount. No flags.
57919 */
57920-SYSCALL_DEFINE1(oldumount, char __user *, name)
57921+SYSCALL_DEFINE1(oldumount, const char __user *, name)
57922 {
57923 return sys_umount(name, 0);
57924 }
57925@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
57926 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
57927 MS_STRICTATIME);
57928
57929+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
57930+ retval = -EPERM;
57931+ goto dput_out;
57932+ }
57933+
57934+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
57935+ retval = -EPERM;
57936+ goto dput_out;
57937+ }
57938+
57939 if (flags & MS_REMOUNT)
57940 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
57941 data_page);
57942@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
57943 dev_name, data_page);
57944 dput_out:
57945 path_put(&path);
57946+
57947+ gr_log_mount(dev_name, dir_name, retval);
57948+
57949 return retval;
57950 }
57951
57952@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
57953 * number incrementing at 10Ghz will take 12,427 years to wrap which
57954 * is effectively never, so we can ignore the possibility.
57955 */
57956-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
57957+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
57958
57959 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57960 {
57961@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57962 kfree(new_ns);
57963 return ERR_PTR(ret);
57964 }
57965- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
57966+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
57967 atomic_set(&new_ns->count, 1);
57968 new_ns->root = NULL;
57969 INIT_LIST_HEAD(&new_ns->list);
57970@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57971 * Allocate a new namespace structure and populate it with contents
57972 * copied from the namespace of the passed in task structure.
57973 */
57974-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57975+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57976 struct user_namespace *user_ns, struct fs_struct *fs)
57977 {
57978 struct mnt_namespace *new_ns;
57979@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
57980 }
57981 EXPORT_SYMBOL(mount_subtree);
57982
57983-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
57984- char __user *, type, unsigned long, flags, void __user *, data)
57985+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
57986+ const char __user *, type, unsigned long, flags, void __user *, data)
57987 {
57988 int ret;
57989 char *kernel_type;
57990@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
57991 if (error)
57992 goto out2;
57993
57994+ if (gr_handle_chroot_pivot()) {
57995+ error = -EPERM;
57996+ goto out2;
57997+ }
57998+
57999 get_fs_root(current->fs, &root);
58000 old_mp = lock_mount(&old);
58001 error = PTR_ERR(old_mp);
58002@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58003 !nsown_capable(CAP_SYS_ADMIN))
58004 return -EPERM;
58005
58006- if (fs->users != 1)
58007+ if (atomic_read(&fs->users) != 1)
58008 return -EINVAL;
58009
58010 get_mnt_ns(mnt_ns);
58011diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58012index f4ccfe6..a5cf064 100644
58013--- a/fs/nfs/callback_xdr.c
58014+++ b/fs/nfs/callback_xdr.c
58015@@ -51,7 +51,7 @@ struct callback_op {
58016 callback_decode_arg_t decode_args;
58017 callback_encode_res_t encode_res;
58018 long res_maxsize;
58019-};
58020+} __do_const;
58021
58022 static struct callback_op callback_ops[];
58023
58024diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58025index 941246f..17d8724 100644
58026--- a/fs/nfs/inode.c
58027+++ b/fs/nfs/inode.c
58028@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58029 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58030 }
58031
58032-static atomic_long_t nfs_attr_generation_counter;
58033+static atomic_long_unchecked_t nfs_attr_generation_counter;
58034
58035 static unsigned long nfs_read_attr_generation_counter(void)
58036 {
58037- return atomic_long_read(&nfs_attr_generation_counter);
58038+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58039 }
58040
58041 unsigned long nfs_inc_attr_generation_counter(void)
58042 {
58043- return atomic_long_inc_return(&nfs_attr_generation_counter);
58044+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58045 }
58046
58047 void nfs_fattr_init(struct nfs_fattr *fattr)
58048diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58049index 419572f..5414a23 100644
58050--- a/fs/nfsd/nfs4proc.c
58051+++ b/fs/nfsd/nfs4proc.c
58052@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58053 nfsd4op_rsize op_rsize_bop;
58054 stateid_getter op_get_currentstateid;
58055 stateid_setter op_set_currentstateid;
58056-};
58057+} __do_const;
58058
58059 static struct nfsd4_operation nfsd4_ops[];
58060
58061diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58062index c2a4701..fd80e29 100644
58063--- a/fs/nfsd/nfs4xdr.c
58064+++ b/fs/nfsd/nfs4xdr.c
58065@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58066
58067 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58068
58069-static nfsd4_dec nfsd4_dec_ops[] = {
58070+static const nfsd4_dec nfsd4_dec_ops[] = {
58071 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58072 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58073 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58074@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58075 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58076 };
58077
58078-static nfsd4_dec nfsd41_dec_ops[] = {
58079+static const nfsd4_dec nfsd41_dec_ops[] = {
58080 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58081 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58082 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58083@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58084 };
58085
58086 struct nfsd4_minorversion_ops {
58087- nfsd4_dec *decoders;
58088+ const nfsd4_dec *decoders;
58089 int nops;
58090 };
58091
58092diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58093index e76244e..9fe8f2f1 100644
58094--- a/fs/nfsd/nfscache.c
58095+++ b/fs/nfsd/nfscache.c
58096@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58097 {
58098 struct svc_cacherep *rp = rqstp->rq_cacherep;
58099 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58100- int len;
58101+ long len;
58102 size_t bufsize = 0;
58103
58104 if (!rp)
58105 return;
58106
58107- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58108- len >>= 2;
58109+ if (statp) {
58110+ len = (char*)statp - (char*)resv->iov_base;
58111+ len = resv->iov_len - len;
58112+ len >>= 2;
58113+ }
58114
58115 /* Don't cache excessive amounts of data and XDR failures */
58116 if (!statp || len > (256 >> 2)) {
58117diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58118index c827acb..b253b77 100644
58119--- a/fs/nfsd/vfs.c
58120+++ b/fs/nfsd/vfs.c
58121@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58122 } else {
58123 oldfs = get_fs();
58124 set_fs(KERNEL_DS);
58125- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58126+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58127 set_fs(oldfs);
58128 }
58129
58130@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58131
58132 /* Write the data. */
58133 oldfs = get_fs(); set_fs(KERNEL_DS);
58134- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58135+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58136 set_fs(oldfs);
58137 if (host_err < 0)
58138 goto out_nfserr;
58139@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58140 */
58141
58142 oldfs = get_fs(); set_fs(KERNEL_DS);
58143- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58144+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58145 set_fs(oldfs);
58146
58147 if (host_err < 0)
58148diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58149index fea6bd5..8ee9d81 100644
58150--- a/fs/nls/nls_base.c
58151+++ b/fs/nls/nls_base.c
58152@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58153
58154 int register_nls(struct nls_table * nls)
58155 {
58156- struct nls_table ** tmp = &tables;
58157+ struct nls_table *tmp = tables;
58158
58159 if (nls->next)
58160 return -EBUSY;
58161
58162 spin_lock(&nls_lock);
58163- while (*tmp) {
58164- if (nls == *tmp) {
58165+ while (tmp) {
58166+ if (nls == tmp) {
58167 spin_unlock(&nls_lock);
58168 return -EBUSY;
58169 }
58170- tmp = &(*tmp)->next;
58171+ tmp = tmp->next;
58172 }
58173- nls->next = tables;
58174+ pax_open_kernel();
58175+ *(struct nls_table **)&nls->next = tables;
58176+ pax_close_kernel();
58177 tables = nls;
58178 spin_unlock(&nls_lock);
58179 return 0;
58180@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58181
58182 int unregister_nls(struct nls_table * nls)
58183 {
58184- struct nls_table ** tmp = &tables;
58185+ struct nls_table * const * tmp = &tables;
58186
58187 spin_lock(&nls_lock);
58188 while (*tmp) {
58189 if (nls == *tmp) {
58190- *tmp = nls->next;
58191+ pax_open_kernel();
58192+ *(struct nls_table **)tmp = nls->next;
58193+ pax_close_kernel();
58194 spin_unlock(&nls_lock);
58195 return 0;
58196 }
58197diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58198index 7424929..35f6be5 100644
58199--- a/fs/nls/nls_euc-jp.c
58200+++ b/fs/nls/nls_euc-jp.c
58201@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58202 p_nls = load_nls("cp932");
58203
58204 if (p_nls) {
58205- table.charset2upper = p_nls->charset2upper;
58206- table.charset2lower = p_nls->charset2lower;
58207+ pax_open_kernel();
58208+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58209+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58210+ pax_close_kernel();
58211 return register_nls(&table);
58212 }
58213
58214diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58215index e7bc1d7..06bd4bb 100644
58216--- a/fs/nls/nls_koi8-ru.c
58217+++ b/fs/nls/nls_koi8-ru.c
58218@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58219 p_nls = load_nls("koi8-u");
58220
58221 if (p_nls) {
58222- table.charset2upper = p_nls->charset2upper;
58223- table.charset2lower = p_nls->charset2lower;
58224+ pax_open_kernel();
58225+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58226+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58227+ pax_close_kernel();
58228 return register_nls(&table);
58229 }
58230
58231diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58232index e44cb64..4807084 100644
58233--- a/fs/notify/fanotify/fanotify_user.c
58234+++ b/fs/notify/fanotify/fanotify_user.c
58235@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58236
58237 fd = fanotify_event_metadata.fd;
58238 ret = -EFAULT;
58239- if (copy_to_user(buf, &fanotify_event_metadata,
58240- fanotify_event_metadata.event_len))
58241+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58242+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58243 goto out_close_fd;
58244
58245 ret = prepare_for_access_response(group, event, fd);
58246diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58247index 7b51b05..5ea5ef6 100644
58248--- a/fs/notify/notification.c
58249+++ b/fs/notify/notification.c
58250@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58251 * get set to 0 so it will never get 'freed'
58252 */
58253 static struct fsnotify_event *q_overflow_event;
58254-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58255+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58256
58257 /**
58258 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58259@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58260 */
58261 u32 fsnotify_get_cookie(void)
58262 {
58263- return atomic_inc_return(&fsnotify_sync_cookie);
58264+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58265 }
58266 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58267
58268diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58269index 9e38daf..5727cae 100644
58270--- a/fs/ntfs/dir.c
58271+++ b/fs/ntfs/dir.c
58272@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58273 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58274 ~(s64)(ndir->itype.index.block_size - 1)));
58275 /* Bounds checks. */
58276- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58277+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58278 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58279 "inode 0x%lx or driver bug.", vdir->i_ino);
58280 goto err_out;
58281diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58282index c5670b8..d590213 100644
58283--- a/fs/ntfs/file.c
58284+++ b/fs/ntfs/file.c
58285@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58286 char *addr;
58287 size_t total = 0;
58288 unsigned len;
58289- int left;
58290+ unsigned left;
58291
58292 do {
58293 len = PAGE_CACHE_SIZE - ofs;
58294diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58295index 82650d5..db37dcf 100644
58296--- a/fs/ntfs/super.c
58297+++ b/fs/ntfs/super.c
58298@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58299 if (!silent)
58300 ntfs_error(sb, "Primary boot sector is invalid.");
58301 } else if (!silent)
58302- ntfs_error(sb, read_err_str, "primary");
58303+ ntfs_error(sb, read_err_str, "%s", "primary");
58304 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58305 if (bh_primary)
58306 brelse(bh_primary);
58307@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58308 goto hotfix_primary_boot_sector;
58309 brelse(bh_backup);
58310 } else if (!silent)
58311- ntfs_error(sb, read_err_str, "backup");
58312+ ntfs_error(sb, read_err_str, "%s", "backup");
58313 /* Try to read NT3.51- backup boot sector. */
58314 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58315 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58316@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58317 "sector.");
58318 brelse(bh_backup);
58319 } else if (!silent)
58320- ntfs_error(sb, read_err_str, "backup");
58321+ ntfs_error(sb, read_err_str, "%s", "backup");
58322 /* We failed. Cleanup and return. */
58323 if (bh_primary)
58324 brelse(bh_primary);
58325diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58326index aebeacd..0dcdd26 100644
58327--- a/fs/ocfs2/localalloc.c
58328+++ b/fs/ocfs2/localalloc.c
58329@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58330 goto bail;
58331 }
58332
58333- atomic_inc(&osb->alloc_stats.moves);
58334+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58335
58336 bail:
58337 if (handle)
58338diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58339index 3a90347..c40bef8 100644
58340--- a/fs/ocfs2/ocfs2.h
58341+++ b/fs/ocfs2/ocfs2.h
58342@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58343
58344 struct ocfs2_alloc_stats
58345 {
58346- atomic_t moves;
58347- atomic_t local_data;
58348- atomic_t bitmap_data;
58349- atomic_t bg_allocs;
58350- atomic_t bg_extends;
58351+ atomic_unchecked_t moves;
58352+ atomic_unchecked_t local_data;
58353+ atomic_unchecked_t bitmap_data;
58354+ atomic_unchecked_t bg_allocs;
58355+ atomic_unchecked_t bg_extends;
58356 };
58357
58358 enum ocfs2_local_alloc_state
58359diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58360index 5397c07..54afc55 100644
58361--- a/fs/ocfs2/suballoc.c
58362+++ b/fs/ocfs2/suballoc.c
58363@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58364 mlog_errno(status);
58365 goto bail;
58366 }
58367- atomic_inc(&osb->alloc_stats.bg_extends);
58368+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58369
58370 /* You should never ask for this much metadata */
58371 BUG_ON(bits_wanted >
58372@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58373 mlog_errno(status);
58374 goto bail;
58375 }
58376- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58377+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58378
58379 *suballoc_loc = res.sr_bg_blkno;
58380 *suballoc_bit_start = res.sr_bit_offset;
58381@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58382 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58383 res->sr_bits);
58384
58385- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58386+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58387
58388 BUG_ON(res->sr_bits != 1);
58389
58390@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58391 mlog_errno(status);
58392 goto bail;
58393 }
58394- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58395+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58396
58397 BUG_ON(res.sr_bits != 1);
58398
58399@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58400 cluster_start,
58401 num_clusters);
58402 if (!status)
58403- atomic_inc(&osb->alloc_stats.local_data);
58404+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58405 } else {
58406 if (min_clusters > (osb->bitmap_cpg - 1)) {
58407 /* The only paths asking for contiguousness
58408@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58409 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58410 res.sr_bg_blkno,
58411 res.sr_bit_offset);
58412- atomic_inc(&osb->alloc_stats.bitmap_data);
58413+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58414 *num_clusters = res.sr_bits;
58415 }
58416 }
58417diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58418index 121da2d..a0232bc 100644
58419--- a/fs/ocfs2/super.c
58420+++ b/fs/ocfs2/super.c
58421@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58422 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58423 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58424 "Stats",
58425- atomic_read(&osb->alloc_stats.bitmap_data),
58426- atomic_read(&osb->alloc_stats.local_data),
58427- atomic_read(&osb->alloc_stats.bg_allocs),
58428- atomic_read(&osb->alloc_stats.moves),
58429- atomic_read(&osb->alloc_stats.bg_extends));
58430+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58431+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58432+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58433+ atomic_read_unchecked(&osb->alloc_stats.moves),
58434+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58435
58436 out += snprintf(buf + out, len - out,
58437 "%10s => State: %u Descriptor: %llu Size: %u bits "
58438@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58439 spin_lock_init(&osb->osb_xattr_lock);
58440 ocfs2_init_steal_slots(osb);
58441
58442- atomic_set(&osb->alloc_stats.moves, 0);
58443- atomic_set(&osb->alloc_stats.local_data, 0);
58444- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58445- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58446- atomic_set(&osb->alloc_stats.bg_extends, 0);
58447+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58448+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58449+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58450+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58451+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58452
58453 /* Copy the blockcheck stats from the superblock probe */
58454 osb->osb_ecc_stats = *stats;
58455diff --git a/fs/open.c b/fs/open.c
58456index 7931f76..7b03f3b 100644
58457--- a/fs/open.c
58458+++ b/fs/open.c
58459@@ -32,6 +32,8 @@
58460 #include <linux/dnotify.h>
58461 #include <linux/compat.h>
58462
58463+#define CREATE_TRACE_POINTS
58464+#include <trace/events/fs.h>
58465 #include "internal.h"
58466
58467 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58468@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58469 error = locks_verify_truncate(inode, NULL, length);
58470 if (!error)
58471 error = security_path_truncate(path);
58472+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58473+ error = -EACCES;
58474 if (!error)
58475 error = do_truncate(path->dentry, length, 0, NULL);
58476
58477@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58478 error = locks_verify_truncate(inode, f.file, length);
58479 if (!error)
58480 error = security_path_truncate(&f.file->f_path);
58481+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58482+ error = -EACCES;
58483 if (!error)
58484 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58485 sb_end_write(inode->i_sb);
58486@@ -360,6 +366,9 @@ retry:
58487 if (__mnt_is_readonly(path.mnt))
58488 res = -EROFS;
58489
58490+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58491+ res = -EACCES;
58492+
58493 out_path_release:
58494 path_put(&path);
58495 if (retry_estale(res, lookup_flags)) {
58496@@ -391,6 +400,8 @@ retry:
58497 if (error)
58498 goto dput_and_out;
58499
58500+ gr_log_chdir(path.dentry, path.mnt);
58501+
58502 set_fs_pwd(current->fs, &path);
58503
58504 dput_and_out:
58505@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58506 goto out_putf;
58507
58508 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58509+
58510+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58511+ error = -EPERM;
58512+
58513+ if (!error)
58514+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58515+
58516 if (!error)
58517 set_fs_pwd(current->fs, &f.file->f_path);
58518 out_putf:
58519@@ -449,7 +467,13 @@ retry:
58520 if (error)
58521 goto dput_and_out;
58522
58523+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58524+ goto dput_and_out;
58525+
58526 set_fs_root(current->fs, &path);
58527+
58528+ gr_handle_chroot_chdir(&path);
58529+
58530 error = 0;
58531 dput_and_out:
58532 path_put(&path);
58533@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58534 if (error)
58535 return error;
58536 mutex_lock(&inode->i_mutex);
58537+
58538+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58539+ error = -EACCES;
58540+ goto out_unlock;
58541+ }
58542+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58543+ error = -EACCES;
58544+ goto out_unlock;
58545+ }
58546+
58547 error = security_path_chmod(path, mode);
58548 if (error)
58549 goto out_unlock;
58550@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58551 uid = make_kuid(current_user_ns(), user);
58552 gid = make_kgid(current_user_ns(), group);
58553
58554+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58555+ return -EACCES;
58556+
58557 newattrs.ia_valid = ATTR_CTIME;
58558 if (user != (uid_t) -1) {
58559 if (!uid_valid(uid))
58560@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58561 } else {
58562 fsnotify_open(f);
58563 fd_install(fd, f);
58564+ trace_do_sys_open(tmp->name, flags, mode);
58565 }
58566 }
58567 putname(tmp);
58568diff --git a/fs/pipe.c b/fs/pipe.c
58569index d2c45e1..009fe1c 100644
58570--- a/fs/pipe.c
58571+++ b/fs/pipe.c
58572@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58573
58574 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58575 {
58576- if (pipe->files)
58577+ if (atomic_read(&pipe->files))
58578 mutex_lock_nested(&pipe->mutex, subclass);
58579 }
58580
58581@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58582
58583 void pipe_unlock(struct pipe_inode_info *pipe)
58584 {
58585- if (pipe->files)
58586+ if (atomic_read(&pipe->files))
58587 mutex_unlock(&pipe->mutex);
58588 }
58589 EXPORT_SYMBOL(pipe_unlock);
58590@@ -449,9 +449,9 @@ redo:
58591 }
58592 if (bufs) /* More to do? */
58593 continue;
58594- if (!pipe->writers)
58595+ if (!atomic_read(&pipe->writers))
58596 break;
58597- if (!pipe->waiting_writers) {
58598+ if (!atomic_read(&pipe->waiting_writers)) {
58599 /* syscall merging: Usually we must not sleep
58600 * if O_NONBLOCK is set, or if we got some data.
58601 * But if a writer sleeps in kernel space, then
58602@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58603 ret = 0;
58604 __pipe_lock(pipe);
58605
58606- if (!pipe->readers) {
58607+ if (!atomic_read(&pipe->readers)) {
58608 send_sig(SIGPIPE, current, 0);
58609 ret = -EPIPE;
58610 goto out;
58611@@ -562,7 +562,7 @@ redo1:
58612 for (;;) {
58613 int bufs;
58614
58615- if (!pipe->readers) {
58616+ if (!atomic_read(&pipe->readers)) {
58617 send_sig(SIGPIPE, current, 0);
58618 if (!ret)
58619 ret = -EPIPE;
58620@@ -653,9 +653,9 @@ redo2:
58621 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58622 do_wakeup = 0;
58623 }
58624- pipe->waiting_writers++;
58625+ atomic_inc(&pipe->waiting_writers);
58626 pipe_wait(pipe);
58627- pipe->waiting_writers--;
58628+ atomic_dec(&pipe->waiting_writers);
58629 }
58630 out:
58631 __pipe_unlock(pipe);
58632@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58633 mask = 0;
58634 if (filp->f_mode & FMODE_READ) {
58635 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58636- if (!pipe->writers && filp->f_version != pipe->w_counter)
58637+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58638 mask |= POLLHUP;
58639 }
58640
58641@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58642 * Most Unices do not set POLLERR for FIFOs but on Linux they
58643 * behave exactly like pipes for poll().
58644 */
58645- if (!pipe->readers)
58646+ if (!atomic_read(&pipe->readers))
58647 mask |= POLLERR;
58648 }
58649
58650@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58651
58652 __pipe_lock(pipe);
58653 if (file->f_mode & FMODE_READ)
58654- pipe->readers--;
58655+ atomic_dec(&pipe->readers);
58656 if (file->f_mode & FMODE_WRITE)
58657- pipe->writers--;
58658+ atomic_dec(&pipe->writers);
58659
58660- if (pipe->readers || pipe->writers) {
58661+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58662 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58663 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58664 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58665 }
58666 spin_lock(&inode->i_lock);
58667- if (!--pipe->files) {
58668+ if (atomic_dec_and_test(&pipe->files)) {
58669 inode->i_pipe = NULL;
58670 kill = 1;
58671 }
58672@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58673 kfree(pipe);
58674 }
58675
58676-static struct vfsmount *pipe_mnt __read_mostly;
58677+struct vfsmount *pipe_mnt __read_mostly;
58678
58679 /*
58680 * pipefs_dname() is called from d_path().
58681@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58682 goto fail_iput;
58683
58684 inode->i_pipe = pipe;
58685- pipe->files = 2;
58686- pipe->readers = pipe->writers = 1;
58687+ atomic_set(&pipe->files, 2);
58688+ atomic_set(&pipe->readers, 1);
58689+ atomic_set(&pipe->writers, 1);
58690 inode->i_fop = &pipefifo_fops;
58691
58692 /*
58693@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58694 spin_lock(&inode->i_lock);
58695 if (inode->i_pipe) {
58696 pipe = inode->i_pipe;
58697- pipe->files++;
58698+ atomic_inc(&pipe->files);
58699 spin_unlock(&inode->i_lock);
58700 } else {
58701 spin_unlock(&inode->i_lock);
58702 pipe = alloc_pipe_info();
58703 if (!pipe)
58704 return -ENOMEM;
58705- pipe->files = 1;
58706+ atomic_set(&pipe->files, 1);
58707 spin_lock(&inode->i_lock);
58708 if (unlikely(inode->i_pipe)) {
58709- inode->i_pipe->files++;
58710+ atomic_inc(&inode->i_pipe->files);
58711 spin_unlock(&inode->i_lock);
58712 free_pipe_info(pipe);
58713 pipe = inode->i_pipe;
58714@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58715 * opened, even when there is no process writing the FIFO.
58716 */
58717 pipe->r_counter++;
58718- if (pipe->readers++ == 0)
58719+ if (atomic_inc_return(&pipe->readers) == 1)
58720 wake_up_partner(pipe);
58721
58722- if (!is_pipe && !pipe->writers) {
58723+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58724 if ((filp->f_flags & O_NONBLOCK)) {
58725 /* suppress POLLHUP until we have
58726 * seen a writer */
58727@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58728 * errno=ENXIO when there is no process reading the FIFO.
58729 */
58730 ret = -ENXIO;
58731- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58732+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58733 goto err;
58734
58735 pipe->w_counter++;
58736- if (!pipe->writers++)
58737+ if (atomic_inc_return(&pipe->writers) == 1)
58738 wake_up_partner(pipe);
58739
58740- if (!is_pipe && !pipe->readers) {
58741+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58742 if (wait_for_partner(pipe, &pipe->r_counter))
58743 goto err_wr;
58744 }
58745@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58746 * the process can at least talk to itself.
58747 */
58748
58749- pipe->readers++;
58750- pipe->writers++;
58751+ atomic_inc(&pipe->readers);
58752+ atomic_inc(&pipe->writers);
58753 pipe->r_counter++;
58754 pipe->w_counter++;
58755- if (pipe->readers == 1 || pipe->writers == 1)
58756+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58757 wake_up_partner(pipe);
58758 break;
58759
58760@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58761 return 0;
58762
58763 err_rd:
58764- if (!--pipe->readers)
58765+ if (atomic_dec_and_test(&pipe->readers))
58766 wake_up_interruptible(&pipe->wait);
58767 ret = -ERESTARTSYS;
58768 goto err;
58769
58770 err_wr:
58771- if (!--pipe->writers)
58772+ if (atomic_dec_and_test(&pipe->writers))
58773 wake_up_interruptible(&pipe->wait);
58774 ret = -ERESTARTSYS;
58775 goto err;
58776
58777 err:
58778 spin_lock(&inode->i_lock);
58779- if (!--pipe->files) {
58780+ if (atomic_dec_and_test(&pipe->files)) {
58781 inode->i_pipe = NULL;
58782 kill = 1;
58783 }
58784diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58785index 15af622..0e9f4467 100644
58786--- a/fs/proc/Kconfig
58787+++ b/fs/proc/Kconfig
58788@@ -30,12 +30,12 @@ config PROC_FS
58789
58790 config PROC_KCORE
58791 bool "/proc/kcore support" if !ARM
58792- depends on PROC_FS && MMU
58793+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58794
58795 config PROC_VMCORE
58796 bool "/proc/vmcore support"
58797- depends on PROC_FS && CRASH_DUMP
58798- default y
58799+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58800+ default n
58801 help
58802 Exports the dump image of crashed kernel in ELF format.
58803
58804@@ -59,8 +59,8 @@ config PROC_SYSCTL
58805 limited in memory.
58806
58807 config PROC_PAGE_MONITOR
58808- default y
58809- depends on PROC_FS && MMU
58810+ default n
58811+ depends on PROC_FS && MMU && !GRKERNSEC
58812 bool "Enable /proc page monitoring" if EXPERT
58813 help
58814 Various /proc files exist to monitor process memory utilization:
58815diff --git a/fs/proc/array.c b/fs/proc/array.c
58816index cbd0f1b..adec3f0 100644
58817--- a/fs/proc/array.c
58818+++ b/fs/proc/array.c
58819@@ -60,6 +60,7 @@
58820 #include <linux/tty.h>
58821 #include <linux/string.h>
58822 #include <linux/mman.h>
58823+#include <linux/grsecurity.h>
58824 #include <linux/proc_fs.h>
58825 #include <linux/ioport.h>
58826 #include <linux/uaccess.h>
58827@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58828 seq_putc(m, '\n');
58829 }
58830
58831+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58832+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58833+{
58834+ if (p->mm)
58835+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58836+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58837+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58838+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58839+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58840+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58841+ else
58842+ seq_printf(m, "PaX:\t-----\n");
58843+}
58844+#endif
58845+
58846 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58847 struct pid *pid, struct task_struct *task)
58848 {
58849@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58850 task_cpus_allowed(m, task);
58851 cpuset_task_status_allowed(m, task);
58852 task_context_switch_counts(m, task);
58853+
58854+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58855+ task_pax(m, task);
58856+#endif
58857+
58858+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58859+ task_grsec_rbac(m, task);
58860+#endif
58861+
58862 return 0;
58863 }
58864
58865+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58866+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58867+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58868+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58869+#endif
58870+
58871 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58872 struct pid *pid, struct task_struct *task, int whole)
58873 {
58874@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58875 char tcomm[sizeof(task->comm)];
58876 unsigned long flags;
58877
58878+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58879+ if (current->exec_id != m->exec_id) {
58880+ gr_log_badprocpid("stat");
58881+ return 0;
58882+ }
58883+#endif
58884+
58885 state = *get_task_state(task);
58886 vsize = eip = esp = 0;
58887 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58888@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58889 gtime = task_gtime(task);
58890 }
58891
58892+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58893+ if (PAX_RAND_FLAGS(mm)) {
58894+ eip = 0;
58895+ esp = 0;
58896+ wchan = 0;
58897+ }
58898+#endif
58899+#ifdef CONFIG_GRKERNSEC_HIDESYM
58900+ wchan = 0;
58901+ eip =0;
58902+ esp =0;
58903+#endif
58904+
58905 /* scale priority and nice values from timeslices to -20..20 */
58906 /* to make it look like a "normal" Unix priority/nice value */
58907 priority = task_prio(task);
58908@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58909 seq_put_decimal_ull(m, ' ', vsize);
58910 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58911 seq_put_decimal_ull(m, ' ', rsslim);
58912+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58913+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
58914+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
58915+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
58916+#else
58917 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
58918 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
58919 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
58920+#endif
58921 seq_put_decimal_ull(m, ' ', esp);
58922 seq_put_decimal_ull(m, ' ', eip);
58923 /* The signal information here is obsolete.
58924@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58925 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
58926 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
58927
58928- if (mm && permitted) {
58929+ if (mm && permitted
58930+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58931+ && !PAX_RAND_FLAGS(mm)
58932+#endif
58933+ ) {
58934 seq_put_decimal_ull(m, ' ', mm->start_data);
58935 seq_put_decimal_ull(m, ' ', mm->end_data);
58936 seq_put_decimal_ull(m, ' ', mm->start_brk);
58937@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58938 struct pid *pid, struct task_struct *task)
58939 {
58940 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
58941- struct mm_struct *mm = get_task_mm(task);
58942+ struct mm_struct *mm;
58943
58944+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58945+ if (current->exec_id != m->exec_id) {
58946+ gr_log_badprocpid("statm");
58947+ return 0;
58948+ }
58949+#endif
58950+ mm = get_task_mm(task);
58951 if (mm) {
58952 size = task_statm(mm, &shared, &text, &data, &resident);
58953 mmput(mm);
58954@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58955 return 0;
58956 }
58957
58958+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
58959+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
58960+{
58961+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
58962+}
58963+#endif
58964+
58965 #ifdef CONFIG_CHECKPOINT_RESTORE
58966 static struct pid *
58967 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
58968diff --git a/fs/proc/base.c b/fs/proc/base.c
58969index 1485e38..8ad4236 100644
58970--- a/fs/proc/base.c
58971+++ b/fs/proc/base.c
58972@@ -113,6 +113,14 @@ struct pid_entry {
58973 union proc_op op;
58974 };
58975
58976+struct getdents_callback {
58977+ struct linux_dirent __user * current_dir;
58978+ struct linux_dirent __user * previous;
58979+ struct file * file;
58980+ int count;
58981+ int error;
58982+};
58983+
58984 #define NOD(NAME, MODE, IOP, FOP, OP) { \
58985 .name = (NAME), \
58986 .len = sizeof(NAME) - 1, \
58987@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
58988 if (!mm->arg_end)
58989 goto out_mm; /* Shh! No looking before we're done */
58990
58991+ if (gr_acl_handle_procpidmem(task))
58992+ goto out_mm;
58993+
58994 len = mm->arg_end - mm->arg_start;
58995
58996 if (len > PAGE_SIZE)
58997@@ -237,12 +248,28 @@ out:
58998 return res;
58999 }
59000
59001+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59002+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59003+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59004+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59005+#endif
59006+
59007 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59008 {
59009 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59010 int res = PTR_ERR(mm);
59011 if (mm && !IS_ERR(mm)) {
59012 unsigned int nwords = 0;
59013+
59014+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59015+ /* allow if we're currently ptracing this task */
59016+ if (PAX_RAND_FLAGS(mm) &&
59017+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59018+ mmput(mm);
59019+ return 0;
59020+ }
59021+#endif
59022+
59023 do {
59024 nwords += 2;
59025 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59026@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59027 }
59028
59029
59030-#ifdef CONFIG_KALLSYMS
59031+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59032 /*
59033 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59034 * Returns the resolved symbol. If that fails, simply return the address.
59035@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59036 mutex_unlock(&task->signal->cred_guard_mutex);
59037 }
59038
59039-#ifdef CONFIG_STACKTRACE
59040+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59041
59042 #define MAX_STACK_TRACE_DEPTH 64
59043
59044@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59045 return count;
59046 }
59047
59048-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59049+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59050 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59051 {
59052 long nr;
59053@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59054 /************************************************************************/
59055
59056 /* permission checks */
59057-static int proc_fd_access_allowed(struct inode *inode)
59058+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59059 {
59060 struct task_struct *task;
59061 int allowed = 0;
59062@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59063 */
59064 task = get_proc_task(inode);
59065 if (task) {
59066- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59067+ if (log)
59068+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59069+ else
59070+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59071 put_task_struct(task);
59072 }
59073 return allowed;
59074@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59075 struct task_struct *task,
59076 int hide_pid_min)
59077 {
59078+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59079+ return false;
59080+
59081+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59082+ rcu_read_lock();
59083+ {
59084+ const struct cred *tmpcred = current_cred();
59085+ const struct cred *cred = __task_cred(task);
59086+
59087+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59088+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59089+ || in_group_p(grsec_proc_gid)
59090+#endif
59091+ ) {
59092+ rcu_read_unlock();
59093+ return true;
59094+ }
59095+ }
59096+ rcu_read_unlock();
59097+
59098+ if (!pid->hide_pid)
59099+ return false;
59100+#endif
59101+
59102 if (pid->hide_pid < hide_pid_min)
59103 return true;
59104 if (in_group_p(pid->pid_gid))
59105 return true;
59106+
59107 return ptrace_may_access(task, PTRACE_MODE_READ);
59108 }
59109
59110@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59111 put_task_struct(task);
59112
59113 if (!has_perms) {
59114+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59115+ {
59116+#else
59117 if (pid->hide_pid == 2) {
59118+#endif
59119 /*
59120 * Let's make getdents(), stat(), and open()
59121 * consistent with each other. If a process
59122@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59123 if (!task)
59124 return -ESRCH;
59125
59126+ if (gr_acl_handle_procpidmem(task)) {
59127+ put_task_struct(task);
59128+ return -EPERM;
59129+ }
59130+
59131 mm = mm_access(task, mode);
59132 put_task_struct(task);
59133
59134@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59135
59136 file->private_data = mm;
59137
59138+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59139+ file->f_version = current->exec_id;
59140+#endif
59141+
59142 return 0;
59143 }
59144
59145@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59146 ssize_t copied;
59147 char *page;
59148
59149+#ifdef CONFIG_GRKERNSEC
59150+ if (write)
59151+ return -EPERM;
59152+#endif
59153+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59154+ if (file->f_version != current->exec_id) {
59155+ gr_log_badprocpid("mem");
59156+ return 0;
59157+ }
59158+#endif
59159+
59160 if (!mm)
59161 return 0;
59162
59163@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59164 goto free;
59165
59166 while (count > 0) {
59167- int this_len = min_t(int, count, PAGE_SIZE);
59168+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59169
59170 if (write && copy_from_user(page, buf, this_len)) {
59171 copied = -EFAULT;
59172@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59173 if (!mm)
59174 return 0;
59175
59176+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59177+ if (file->f_version != current->exec_id) {
59178+ gr_log_badprocpid("environ");
59179+ return 0;
59180+ }
59181+#endif
59182+
59183 page = (char *)__get_free_page(GFP_TEMPORARY);
59184 if (!page)
59185 return -ENOMEM;
59186@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59187 goto free;
59188 while (count > 0) {
59189 size_t this_len, max_len;
59190- int retval;
59191+ ssize_t retval;
59192
59193 if (src >= (mm->env_end - mm->env_start))
59194 break;
59195@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59196 int error = -EACCES;
59197
59198 /* Are we allowed to snoop on the tasks file descriptors? */
59199- if (!proc_fd_access_allowed(inode))
59200+ if (!proc_fd_access_allowed(inode, 0))
59201 goto out;
59202
59203 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59204@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59205 struct path path;
59206
59207 /* Are we allowed to snoop on the tasks file descriptors? */
59208- if (!proc_fd_access_allowed(inode))
59209- goto out;
59210+ /* logging this is needed for learning on chromium to work properly,
59211+ but we don't want to flood the logs from 'ps' which does a readlink
59212+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59213+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59214+ */
59215+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59216+ if (!proc_fd_access_allowed(inode,0))
59217+ goto out;
59218+ } else {
59219+ if (!proc_fd_access_allowed(inode,1))
59220+ goto out;
59221+ }
59222
59223 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59224 if (error)
59225@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59226 rcu_read_lock();
59227 cred = __task_cred(task);
59228 inode->i_uid = cred->euid;
59229+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59230+ inode->i_gid = grsec_proc_gid;
59231+#else
59232 inode->i_gid = cred->egid;
59233+#endif
59234 rcu_read_unlock();
59235 }
59236 security_task_to_inode(task, inode);
59237@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59238 return -ENOENT;
59239 }
59240 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59241+#ifdef CONFIG_GRKERNSEC_PROC_USER
59242+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59243+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59244+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59245+#endif
59246 task_dumpable(task)) {
59247 cred = __task_cred(task);
59248 stat->uid = cred->euid;
59249+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59250+ stat->gid = grsec_proc_gid;
59251+#else
59252 stat->gid = cred->egid;
59253+#endif
59254 }
59255 }
59256 rcu_read_unlock();
59257@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59258
59259 if (task) {
59260 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59261+#ifdef CONFIG_GRKERNSEC_PROC_USER
59262+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59263+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59264+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59265+#endif
59266 task_dumpable(task)) {
59267 rcu_read_lock();
59268 cred = __task_cred(task);
59269 inode->i_uid = cred->euid;
59270+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59271+ inode->i_gid = grsec_proc_gid;
59272+#else
59273 inode->i_gid = cred->egid;
59274+#endif
59275 rcu_read_unlock();
59276 } else {
59277 inode->i_uid = GLOBAL_ROOT_UID;
59278@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59279 if (!task)
59280 goto out_no_task;
59281
59282+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59283+ goto out;
59284+
59285 /*
59286 * Yes, it does not scale. And it should not. Don't add
59287 * new entries into /proc/<tgid>/ without very good reasons.
59288@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59289 if (!task)
59290 return -ENOENT;
59291
59292+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59293+ goto out;
59294+
59295 if (!dir_emit_dots(file, ctx))
59296 goto out;
59297
59298@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59299 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59300 #endif
59301 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59302-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59303+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59304 INF("syscall", S_IRUGO, proc_pid_syscall),
59305 #endif
59306 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59307@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59308 #ifdef CONFIG_SECURITY
59309 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59310 #endif
59311-#ifdef CONFIG_KALLSYMS
59312+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59313 INF("wchan", S_IRUGO, proc_pid_wchan),
59314 #endif
59315-#ifdef CONFIG_STACKTRACE
59316+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59317 ONE("stack", S_IRUGO, proc_pid_stack),
59318 #endif
59319 #ifdef CONFIG_SCHEDSTATS
59320@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59321 #ifdef CONFIG_HARDWALL
59322 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59323 #endif
59324+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59325+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59326+#endif
59327 #ifdef CONFIG_USER_NS
59328 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59329 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59330@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59331 if (!inode)
59332 goto out;
59333
59334+#ifdef CONFIG_GRKERNSEC_PROC_USER
59335+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59336+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59337+ inode->i_gid = grsec_proc_gid;
59338+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59339+#else
59340 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59341+#endif
59342 inode->i_op = &proc_tgid_base_inode_operations;
59343 inode->i_fop = &proc_tgid_base_operations;
59344 inode->i_flags|=S_IMMUTABLE;
59345@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59346 if (!task)
59347 goto out;
59348
59349+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59350+ goto out_put_task;
59351+
59352 result = proc_pid_instantiate(dir, dentry, task, NULL);
59353+out_put_task:
59354 put_task_struct(task);
59355 out:
59356 return ERR_PTR(result);
59357@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59358 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59359 #endif
59360 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59361-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59362+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59363 INF("syscall", S_IRUGO, proc_pid_syscall),
59364 #endif
59365 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59366@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59367 #ifdef CONFIG_SECURITY
59368 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59369 #endif
59370-#ifdef CONFIG_KALLSYMS
59371+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59372 INF("wchan", S_IRUGO, proc_pid_wchan),
59373 #endif
59374-#ifdef CONFIG_STACKTRACE
59375+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59376 ONE("stack", S_IRUGO, proc_pid_stack),
59377 #endif
59378 #ifdef CONFIG_SCHEDSTATS
59379diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59380index 82676e3..5f8518a 100644
59381--- a/fs/proc/cmdline.c
59382+++ b/fs/proc/cmdline.c
59383@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59384
59385 static int __init proc_cmdline_init(void)
59386 {
59387+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59388+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59389+#else
59390 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59391+#endif
59392 return 0;
59393 }
59394 module_init(proc_cmdline_init);
59395diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59396index b143471..bb105e5 100644
59397--- a/fs/proc/devices.c
59398+++ b/fs/proc/devices.c
59399@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59400
59401 static int __init proc_devices_init(void)
59402 {
59403+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59404+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59405+#else
59406 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59407+#endif
59408 return 0;
59409 }
59410 module_init(proc_devices_init);
59411diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59412index 0ff80f9..a1d7500 100644
59413--- a/fs/proc/fd.c
59414+++ b/fs/proc/fd.c
59415@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59416 if (!task)
59417 return -ENOENT;
59418
59419- files = get_files_struct(task);
59420+ if (!gr_acl_handle_procpidmem(task))
59421+ files = get_files_struct(task);
59422 put_task_struct(task);
59423
59424 if (files) {
59425@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59426 */
59427 int proc_fd_permission(struct inode *inode, int mask)
59428 {
59429+ struct task_struct *task;
59430 int rv = generic_permission(inode, mask);
59431- if (rv == 0)
59432- return 0;
59433+
59434 if (task_pid(current) == proc_pid(inode))
59435 rv = 0;
59436+
59437+ task = get_proc_task(inode);
59438+ if (task == NULL)
59439+ return rv;
59440+
59441+ if (gr_acl_handle_procpidmem(task))
59442+ rv = -EACCES;
59443+
59444+ put_task_struct(task);
59445+
59446 return rv;
59447 }
59448
59449diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59450index 073aea6..0630370 100644
59451--- a/fs/proc/inode.c
59452+++ b/fs/proc/inode.c
59453@@ -23,11 +23,17 @@
59454 #include <linux/slab.h>
59455 #include <linux/mount.h>
59456 #include <linux/magic.h>
59457+#include <linux/grsecurity.h>
59458
59459 #include <asm/uaccess.h>
59460
59461 #include "internal.h"
59462
59463+#ifdef CONFIG_PROC_SYSCTL
59464+extern const struct inode_operations proc_sys_inode_operations;
59465+extern const struct inode_operations proc_sys_dir_operations;
59466+#endif
59467+
59468 static void proc_evict_inode(struct inode *inode)
59469 {
59470 struct proc_dir_entry *de;
59471@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59472 ns = PROC_I(inode)->ns.ns;
59473 if (ns_ops && ns)
59474 ns_ops->put(ns);
59475+
59476+#ifdef CONFIG_PROC_SYSCTL
59477+ if (inode->i_op == &proc_sys_inode_operations ||
59478+ inode->i_op == &proc_sys_dir_operations)
59479+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59480+#endif
59481+
59482 }
59483
59484 static struct kmem_cache * proc_inode_cachep;
59485@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59486 if (de->mode) {
59487 inode->i_mode = de->mode;
59488 inode->i_uid = de->uid;
59489+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59490+ inode->i_gid = grsec_proc_gid;
59491+#else
59492 inode->i_gid = de->gid;
59493+#endif
59494 }
59495 if (de->size)
59496 inode->i_size = de->size;
59497diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59498index 651d09a..60c73ae 100644
59499--- a/fs/proc/internal.h
59500+++ b/fs/proc/internal.h
59501@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59502 struct pid *, struct task_struct *);
59503 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59504 struct pid *, struct task_struct *);
59505+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59506+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59507+#endif
59508
59509 /*
59510 * base.c
59511diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59512index 06ea155..9a798c7 100644
59513--- a/fs/proc/kcore.c
59514+++ b/fs/proc/kcore.c
59515@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59516 * the addresses in the elf_phdr on our list.
59517 */
59518 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59519- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59520+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59521+ if (tsz > buflen)
59522 tsz = buflen;
59523-
59524+
59525 while (buflen) {
59526 struct kcore_list *m;
59527
59528@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59529 kfree(elf_buf);
59530 } else {
59531 if (kern_addr_valid(start)) {
59532- unsigned long n;
59533+ char *elf_buf;
59534+ mm_segment_t oldfs;
59535
59536- n = copy_to_user(buffer, (char *)start, tsz);
59537- /*
59538- * We cannot distinguish between fault on source
59539- * and fault on destination. When this happens
59540- * we clear too and hope it will trigger the
59541- * EFAULT again.
59542- */
59543- if (n) {
59544- if (clear_user(buffer + tsz - n,
59545- n))
59546+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59547+ if (!elf_buf)
59548+ return -ENOMEM;
59549+ oldfs = get_fs();
59550+ set_fs(KERNEL_DS);
59551+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59552+ set_fs(oldfs);
59553+ if (copy_to_user(buffer, elf_buf, tsz)) {
59554+ kfree(elf_buf);
59555 return -EFAULT;
59556+ }
59557 }
59558+ set_fs(oldfs);
59559+ kfree(elf_buf);
59560 } else {
59561 if (clear_user(buffer, tsz))
59562 return -EFAULT;
59563@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59564
59565 static int open_kcore(struct inode *inode, struct file *filp)
59566 {
59567+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59568+ return -EPERM;
59569+#endif
59570 if (!capable(CAP_SYS_RAWIO))
59571 return -EPERM;
59572 if (kcore_need_update)
59573diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59574index 5aa847a..f77c8d4 100644
59575--- a/fs/proc/meminfo.c
59576+++ b/fs/proc/meminfo.c
59577@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59578 vmi.used >> 10,
59579 vmi.largest_chunk >> 10
59580 #ifdef CONFIG_MEMORY_FAILURE
59581- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59582+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59583 #endif
59584 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59585 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59586diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59587index ccfd99b..1b7e255 100644
59588--- a/fs/proc/nommu.c
59589+++ b/fs/proc/nommu.c
59590@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59591 if (len < 1)
59592 len = 1;
59593 seq_printf(m, "%*c", len, ' ');
59594- seq_path(m, &file->f_path, "");
59595+ seq_path(m, &file->f_path, "\n\\");
59596 }
59597
59598 seq_putc(m, '\n');
59599diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59600index 4677bb7..408e936 100644
59601--- a/fs/proc/proc_net.c
59602+++ b/fs/proc/proc_net.c
59603@@ -23,6 +23,7 @@
59604 #include <linux/nsproxy.h>
59605 #include <net/net_namespace.h>
59606 #include <linux/seq_file.h>
59607+#include <linux/grsecurity.h>
59608
59609 #include "internal.h"
59610
59611@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59612 struct task_struct *task;
59613 struct nsproxy *ns;
59614 struct net *net = NULL;
59615+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59616+ const struct cred *cred = current_cred();
59617+#endif
59618+
59619+#ifdef CONFIG_GRKERNSEC_PROC_USER
59620+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59621+ return net;
59622+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59623+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59624+ return net;
59625+#endif
59626
59627 rcu_read_lock();
59628 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59629diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59630index 7129046..f2779c6 100644
59631--- a/fs/proc/proc_sysctl.c
59632+++ b/fs/proc/proc_sysctl.c
59633@@ -13,11 +13,15 @@
59634 #include <linux/module.h>
59635 #include "internal.h"
59636
59637+extern int gr_handle_chroot_sysctl(const int op);
59638+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59639+ const int op);
59640+
59641 static const struct dentry_operations proc_sys_dentry_operations;
59642 static const struct file_operations proc_sys_file_operations;
59643-static const struct inode_operations proc_sys_inode_operations;
59644+const struct inode_operations proc_sys_inode_operations;
59645 static const struct file_operations proc_sys_dir_file_operations;
59646-static const struct inode_operations proc_sys_dir_operations;
59647+const struct inode_operations proc_sys_dir_operations;
59648
59649 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59650 {
59651@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59652
59653 err = NULL;
59654 d_set_d_op(dentry, &proc_sys_dentry_operations);
59655+
59656+ gr_handle_proc_create(dentry, inode);
59657+
59658 d_add(dentry, inode);
59659
59660 out:
59661@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59662 struct inode *inode = file_inode(filp);
59663 struct ctl_table_header *head = grab_header(inode);
59664 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59665+ int op = write ? MAY_WRITE : MAY_READ;
59666 ssize_t error;
59667 size_t res;
59668
59669@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59670 * and won't be until we finish.
59671 */
59672 error = -EPERM;
59673- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59674+ if (sysctl_perm(head, table, op))
59675 goto out;
59676
59677 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59678@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59679 if (!table->proc_handler)
59680 goto out;
59681
59682+#ifdef CONFIG_GRKERNSEC
59683+ error = -EPERM;
59684+ if (gr_handle_chroot_sysctl(op))
59685+ goto out;
59686+ dget(filp->f_path.dentry);
59687+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59688+ dput(filp->f_path.dentry);
59689+ goto out;
59690+ }
59691+ dput(filp->f_path.dentry);
59692+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59693+ goto out;
59694+ if (write && !capable(CAP_SYS_ADMIN))
59695+ goto out;
59696+#endif
59697+
59698 /* careful: calling conventions are nasty here */
59699 res = count;
59700 error = table->proc_handler(table, write, buf, &res, ppos);
59701@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59702 return false;
59703 } else {
59704 d_set_d_op(child, &proc_sys_dentry_operations);
59705+
59706+ gr_handle_proc_create(child, inode);
59707+
59708 d_add(child, inode);
59709 }
59710 } else {
59711@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59712 if ((*pos)++ < ctx->pos)
59713 return true;
59714
59715+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59716+ return 0;
59717+
59718 if (unlikely(S_ISLNK(table->mode)))
59719 res = proc_sys_link_fill_cache(file, ctx, head, table);
59720 else
59721@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59722 if (IS_ERR(head))
59723 return PTR_ERR(head);
59724
59725+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59726+ return -ENOENT;
59727+
59728 generic_fillattr(inode, stat);
59729 if (table)
59730 stat->mode = (stat->mode & S_IFMT) | table->mode;
59731@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59732 .llseek = generic_file_llseek,
59733 };
59734
59735-static const struct inode_operations proc_sys_inode_operations = {
59736+const struct inode_operations proc_sys_inode_operations = {
59737 .permission = proc_sys_permission,
59738 .setattr = proc_sys_setattr,
59739 .getattr = proc_sys_getattr,
59740 };
59741
59742-static const struct inode_operations proc_sys_dir_operations = {
59743+const struct inode_operations proc_sys_dir_operations = {
59744 .lookup = proc_sys_lookup,
59745 .permission = proc_sys_permission,
59746 .setattr = proc_sys_setattr,
59747@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59748 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59749 const char *name, int namelen)
59750 {
59751- struct ctl_table *table;
59752+ ctl_table_no_const *table;
59753 struct ctl_dir *new;
59754 struct ctl_node *node;
59755 char *new_name;
59756@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59757 return NULL;
59758
59759 node = (struct ctl_node *)(new + 1);
59760- table = (struct ctl_table *)(node + 1);
59761+ table = (ctl_table_no_const *)(node + 1);
59762 new_name = (char *)(table + 2);
59763 memcpy(new_name, name, namelen);
59764 new_name[namelen] = '\0';
59765@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59766 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59767 struct ctl_table_root *link_root)
59768 {
59769- struct ctl_table *link_table, *entry, *link;
59770+ ctl_table_no_const *link_table, *link;
59771+ struct ctl_table *entry;
59772 struct ctl_table_header *links;
59773 struct ctl_node *node;
59774 char *link_name;
59775@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59776 return NULL;
59777
59778 node = (struct ctl_node *)(links + 1);
59779- link_table = (struct ctl_table *)(node + nr_entries);
59780+ link_table = (ctl_table_no_const *)(node + nr_entries);
59781 link_name = (char *)&link_table[nr_entries + 1];
59782
59783 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59784@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59785 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59786 struct ctl_table *table)
59787 {
59788- struct ctl_table *ctl_table_arg = NULL;
59789- struct ctl_table *entry, *files;
59790+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59791+ struct ctl_table *entry;
59792 int nr_files = 0;
59793 int nr_dirs = 0;
59794 int err = -ENOMEM;
59795@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59796 nr_files++;
59797 }
59798
59799- files = table;
59800 /* If there are mixed files and directories we need a new table */
59801 if (nr_dirs && nr_files) {
59802- struct ctl_table *new;
59803+ ctl_table_no_const *new;
59804 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59805 GFP_KERNEL);
59806 if (!files)
59807@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59808 /* Register everything except a directory full of subdirectories */
59809 if (nr_files || !nr_dirs) {
59810 struct ctl_table_header *header;
59811- header = __register_sysctl_table(set, path, files);
59812+ header = __register_sysctl_table(set, path, files ? files : table);
59813 if (!header) {
59814 kfree(ctl_table_arg);
59815 goto out;
59816diff --git a/fs/proc/root.c b/fs/proc/root.c
59817index 0e0e83c..005ba6a 100644
59818--- a/fs/proc/root.c
59819+++ b/fs/proc/root.c
59820@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59821 #ifdef CONFIG_PROC_DEVICETREE
59822 proc_device_tree_init();
59823 #endif
59824+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59825+#ifdef CONFIG_GRKERNSEC_PROC_USER
59826+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59827+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59828+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59829+#endif
59830+#else
59831 proc_mkdir("bus", NULL);
59832+#endif
59833 proc_sys_init();
59834 }
59835
59836diff --git a/fs/proc/self.c b/fs/proc/self.c
59837index 6b6a993..807cccc 100644
59838--- a/fs/proc/self.c
59839+++ b/fs/proc/self.c
59840@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59841 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59842 void *cookie)
59843 {
59844- char *s = nd_get_link(nd);
59845+ const char *s = nd_get_link(nd);
59846 if (!IS_ERR(s))
59847 kfree(s);
59848 }
59849diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59850index 107d026..c715aeb 100644
59851--- a/fs/proc/task_mmu.c
59852+++ b/fs/proc/task_mmu.c
59853@@ -12,12 +12,19 @@
59854 #include <linux/swap.h>
59855 #include <linux/swapops.h>
59856 #include <linux/mmu_notifier.h>
59857+#include <linux/grsecurity.h>
59858
59859 #include <asm/elf.h>
59860 #include <asm/uaccess.h>
59861 #include <asm/tlbflush.h>
59862 #include "internal.h"
59863
59864+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59865+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59866+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59867+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59868+#endif
59869+
59870 void task_mem(struct seq_file *m, struct mm_struct *mm)
59871 {
59872 unsigned long data, text, lib, swap;
59873@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59874 "VmExe:\t%8lu kB\n"
59875 "VmLib:\t%8lu kB\n"
59876 "VmPTE:\t%8lu kB\n"
59877- "VmSwap:\t%8lu kB\n",
59878- hiwater_vm << (PAGE_SHIFT-10),
59879+ "VmSwap:\t%8lu kB\n"
59880+
59881+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59882+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59883+#endif
59884+
59885+ ,hiwater_vm << (PAGE_SHIFT-10),
59886 total_vm << (PAGE_SHIFT-10),
59887 mm->locked_vm << (PAGE_SHIFT-10),
59888 mm->pinned_vm << (PAGE_SHIFT-10),
59889@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59890 data << (PAGE_SHIFT-10),
59891 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59892 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59893- swap << (PAGE_SHIFT-10));
59894+ swap << (PAGE_SHIFT-10)
59895+
59896+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59897+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59898+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59899+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59900+#else
59901+ , mm->context.user_cs_base
59902+ , mm->context.user_cs_limit
59903+#endif
59904+#endif
59905+
59906+ );
59907 }
59908
59909 unsigned long task_vsize(struct mm_struct *mm)
59910@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59911 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59912 }
59913
59914- /* We don't show the stack guard page in /proc/maps */
59915+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59916+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59917+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59918+#else
59919 start = vma->vm_start;
59920- if (stack_guard_page_start(vma, start))
59921- start += PAGE_SIZE;
59922 end = vma->vm_end;
59923- if (stack_guard_page_end(vma, end))
59924- end -= PAGE_SIZE;
59925+#endif
59926
59927 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59928 start,
59929@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59930 flags & VM_WRITE ? 'w' : '-',
59931 flags & VM_EXEC ? 'x' : '-',
59932 flags & VM_MAYSHARE ? 's' : 'p',
59933+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59934+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59935+#else
59936 pgoff,
59937+#endif
59938 MAJOR(dev), MINOR(dev), ino, &len);
59939
59940 /*
59941@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59942 */
59943 if (file) {
59944 pad_len_spaces(m, len);
59945- seq_path(m, &file->f_path, "\n");
59946+ seq_path(m, &file->f_path, "\n\\");
59947 goto done;
59948 }
59949
59950@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59951 * Thread stack in /proc/PID/task/TID/maps or
59952 * the main process stack.
59953 */
59954- if (!is_pid || (vma->vm_start <= mm->start_stack &&
59955- vma->vm_end >= mm->start_stack)) {
59956+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
59957+ (vma->vm_start <= mm->start_stack &&
59958+ vma->vm_end >= mm->start_stack)) {
59959 name = "[stack]";
59960 } else {
59961 /* Thread stack in /proc/PID/maps */
59962@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
59963 struct proc_maps_private *priv = m->private;
59964 struct task_struct *task = priv->task;
59965
59966+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59967+ if (current->exec_id != m->exec_id) {
59968+ gr_log_badprocpid("maps");
59969+ return 0;
59970+ }
59971+#endif
59972+
59973 show_map_vma(m, vma, is_pid);
59974
59975 if (m->count < m->size) /* vma is copied successfully */
59976@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59977 .private = &mss,
59978 };
59979
59980+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59981+ if (current->exec_id != m->exec_id) {
59982+ gr_log_badprocpid("smaps");
59983+ return 0;
59984+ }
59985+#endif
59986 memset(&mss, 0, sizeof mss);
59987- mss.vma = vma;
59988- /* mmap_sem is held in m_start */
59989- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59990- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59991-
59992+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59993+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
59994+#endif
59995+ mss.vma = vma;
59996+ /* mmap_sem is held in m_start */
59997+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59998+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59999+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60000+ }
60001+#endif
60002 show_map_vma(m, vma, is_pid);
60003
60004 seq_printf(m,
60005@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60006 "KernelPageSize: %8lu kB\n"
60007 "MMUPageSize: %8lu kB\n"
60008 "Locked: %8lu kB\n",
60009+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60010+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60011+#else
60012 (vma->vm_end - vma->vm_start) >> 10,
60013+#endif
60014 mss.resident >> 10,
60015 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60016 mss.shared_clean >> 10,
60017@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60018 int n;
60019 char buffer[50];
60020
60021+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60022+ if (current->exec_id != m->exec_id) {
60023+ gr_log_badprocpid("numa_maps");
60024+ return 0;
60025+ }
60026+#endif
60027+
60028 if (!mm)
60029 return 0;
60030
60031@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60032 mpol_to_str(buffer, sizeof(buffer), pol);
60033 mpol_cond_put(pol);
60034
60035+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60036+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60037+#else
60038 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60039+#endif
60040
60041 if (file) {
60042 seq_printf(m, " file=");
60043- seq_path(m, &file->f_path, "\n\t= ");
60044+ seq_path(m, &file->f_path, "\n\t\\= ");
60045 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60046 seq_printf(m, " heap");
60047 } else {
60048diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60049index 56123a6..5a2f6ec 100644
60050--- a/fs/proc/task_nommu.c
60051+++ b/fs/proc/task_nommu.c
60052@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60053 else
60054 bytes += kobjsize(mm);
60055
60056- if (current->fs && current->fs->users > 1)
60057+ if (current->fs && atomic_read(&current->fs->users) > 1)
60058 sbytes += kobjsize(current->fs);
60059 else
60060 bytes += kobjsize(current->fs);
60061@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60062
60063 if (file) {
60064 pad_len_spaces(m, len);
60065- seq_path(m, &file->f_path, "");
60066+ seq_path(m, &file->f_path, "\n\\");
60067 } else if (mm) {
60068 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60069
60070diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60071index a1a16eb..6be46ed 100644
60072--- a/fs/proc/vmcore.c
60073+++ b/fs/proc/vmcore.c
60074@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60075 nr_bytes = count;
60076
60077 /* If pfn is not ram, return zeros for sparse dump files */
60078- if (pfn_is_ram(pfn) == 0)
60079- memset(buf, 0, nr_bytes);
60080- else {
60081+ if (pfn_is_ram(pfn) == 0) {
60082+ if (userbuf) {
60083+ if (clear_user((char __force_user *)buf, nr_bytes))
60084+ return -EFAULT;
60085+ } else
60086+ memset(buf, 0, nr_bytes);
60087+ } else {
60088 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60089 offset, userbuf);
60090 if (tmp < 0)
60091@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60092 if (*fpos < m->offset + m->size) {
60093 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60094 start = m->paddr + *fpos - m->offset;
60095- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60096+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60097 if (tmp < 0)
60098 return tmp;
60099 buflen -= tsz;
60100diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60101index b00fcc9..e0c6381 100644
60102--- a/fs/qnx6/qnx6.h
60103+++ b/fs/qnx6/qnx6.h
60104@@ -74,7 +74,7 @@ enum {
60105 BYTESEX_BE,
60106 };
60107
60108-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60109+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60110 {
60111 if (sbi->s_bytesex == BYTESEX_LE)
60112 return le64_to_cpu((__force __le64)n);
60113@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60114 return (__force __fs64)cpu_to_be64(n);
60115 }
60116
60117-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60118+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60119 {
60120 if (sbi->s_bytesex == BYTESEX_LE)
60121 return le32_to_cpu((__force __le32)n);
60122diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60123index 16e8abb..2dcf914 100644
60124--- a/fs/quota/netlink.c
60125+++ b/fs/quota/netlink.c
60126@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60127 void quota_send_warning(struct kqid qid, dev_t dev,
60128 const char warntype)
60129 {
60130- static atomic_t seq;
60131+ static atomic_unchecked_t seq;
60132 struct sk_buff *skb;
60133 void *msg_head;
60134 int ret;
60135@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60136 "VFS: Not enough memory to send quota warning.\n");
60137 return;
60138 }
60139- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60140+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60141 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60142 if (!msg_head) {
60143 printk(KERN_ERR
60144diff --git a/fs/read_write.c b/fs/read_write.c
60145index 122a384..0b7ecf2 100644
60146--- a/fs/read_write.c
60147+++ b/fs/read_write.c
60148@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60149
60150 old_fs = get_fs();
60151 set_fs(get_ds());
60152- p = (__force const char __user *)buf;
60153+ p = (const char __force_user *)buf;
60154 if (count > MAX_RW_COUNT)
60155 count = MAX_RW_COUNT;
60156 if (file->f_op->write)
60157diff --git a/fs/readdir.c b/fs/readdir.c
60158index 93d71e5..6a14be8 100644
60159--- a/fs/readdir.c
60160+++ b/fs/readdir.c
60161@@ -17,6 +17,7 @@
60162 #include <linux/security.h>
60163 #include <linux/syscalls.h>
60164 #include <linux/unistd.h>
60165+#include <linux/namei.h>
60166
60167 #include <asm/uaccess.h>
60168
60169@@ -69,6 +70,7 @@ struct old_linux_dirent {
60170 struct readdir_callback {
60171 struct dir_context ctx;
60172 struct old_linux_dirent __user * dirent;
60173+ struct file * file;
60174 int result;
60175 };
60176
60177@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60178 buf->result = -EOVERFLOW;
60179 return -EOVERFLOW;
60180 }
60181+
60182+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60183+ return 0;
60184+
60185 buf->result++;
60186 dirent = buf->dirent;
60187 if (!access_ok(VERIFY_WRITE, dirent,
60188@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60189 if (!f.file)
60190 return -EBADF;
60191
60192+ buf.file = f.file;
60193 error = iterate_dir(f.file, &buf.ctx);
60194 if (buf.result)
60195 error = buf.result;
60196@@ -142,6 +149,7 @@ struct getdents_callback {
60197 struct dir_context ctx;
60198 struct linux_dirent __user * current_dir;
60199 struct linux_dirent __user * previous;
60200+ struct file * file;
60201 int count;
60202 int error;
60203 };
60204@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60205 buf->error = -EOVERFLOW;
60206 return -EOVERFLOW;
60207 }
60208+
60209+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60210+ return 0;
60211+
60212 dirent = buf->previous;
60213 if (dirent) {
60214 if (__put_user(offset, &dirent->d_off))
60215@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60216 if (!f.file)
60217 return -EBADF;
60218
60219+ buf.file = f.file;
60220 error = iterate_dir(f.file, &buf.ctx);
60221 if (error >= 0)
60222 error = buf.error;
60223@@ -226,6 +239,7 @@ struct getdents_callback64 {
60224 struct dir_context ctx;
60225 struct linux_dirent64 __user * current_dir;
60226 struct linux_dirent64 __user * previous;
60227+ struct file *file;
60228 int count;
60229 int error;
60230 };
60231@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60232 buf->error = -EINVAL; /* only used if we fail.. */
60233 if (reclen > buf->count)
60234 return -EINVAL;
60235+
60236+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60237+ return 0;
60238+
60239 dirent = buf->previous;
60240 if (dirent) {
60241 if (__put_user(offset, &dirent->d_off))
60242@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60243 if (!f.file)
60244 return -EBADF;
60245
60246+ buf.file = f.file;
60247 error = iterate_dir(f.file, &buf.ctx);
60248 if (error >= 0)
60249 error = buf.error;
60250diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60251index 2b7882b..1c5ef48 100644
60252--- a/fs/reiserfs/do_balan.c
60253+++ b/fs/reiserfs/do_balan.c
60254@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60255 return;
60256 }
60257
60258- atomic_inc(&(fs_generation(tb->tb_sb)));
60259+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60260 do_balance_starts(tb);
60261
60262 /* balance leaf returns 0 except if combining L R and S into
60263diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60264index a958444..42b2323 100644
60265--- a/fs/reiserfs/procfs.c
60266+++ b/fs/reiserfs/procfs.c
60267@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60268 "SMALL_TAILS " : "NO_TAILS ",
60269 replay_only(sb) ? "REPLAY_ONLY " : "",
60270 convert_reiserfs(sb) ? "CONV " : "",
60271- atomic_read(&r->s_generation_counter),
60272+ atomic_read_unchecked(&r->s_generation_counter),
60273 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60274 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60275 SF(s_good_search_by_key_reada), SF(s_bmaps),
60276diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60277index 3df5ce6..8c0f4b0 100644
60278--- a/fs/reiserfs/reiserfs.h
60279+++ b/fs/reiserfs/reiserfs.h
60280@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60281 /* Comment? -Hans */
60282 wait_queue_head_t s_wait;
60283 /* To be obsoleted soon by per buffer seals.. -Hans */
60284- atomic_t s_generation_counter; // increased by one every time the
60285+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60286 // tree gets re-balanced
60287 unsigned long s_properties; /* File system properties. Currently holds
60288 on-disk FS format */
60289@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60290 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60291
60292 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60293-#define get_generation(s) atomic_read (&fs_generation(s))
60294+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60295 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60296 #define __fs_changed(gen,s) (gen != get_generation (s))
60297 #define fs_changed(gen,s) \
60298diff --git a/fs/select.c b/fs/select.c
60299index 35d4adc7..d6c60db 100644
60300--- a/fs/select.c
60301+++ b/fs/select.c
60302@@ -20,6 +20,7 @@
60303 #include <linux/export.h>
60304 #include <linux/slab.h>
60305 #include <linux/poll.h>
60306+#include <linux/security.h>
60307 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60308 #include <linux/file.h>
60309 #include <linux/fdtable.h>
60310@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60311 struct poll_list *walk = head;
60312 unsigned long todo = nfds;
60313
60314+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60315 if (nfds > rlimit(RLIMIT_NOFILE))
60316 return -EINVAL;
60317
60318diff --git a/fs/seq_file.c b/fs/seq_file.c
60319index 3135c25..d0395dd 100644
60320--- a/fs/seq_file.c
60321+++ b/fs/seq_file.c
60322@@ -10,6 +10,7 @@
60323 #include <linux/seq_file.h>
60324 #include <linux/slab.h>
60325 #include <linux/cred.h>
60326+#include <linux/sched.h>
60327
60328 #include <asm/uaccess.h>
60329 #include <asm/page.h>
60330@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60331 #ifdef CONFIG_USER_NS
60332 p->user_ns = file->f_cred->user_ns;
60333 #endif
60334+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60335+ p->exec_id = current->exec_id;
60336+#endif
60337
60338 /*
60339 * Wrappers around seq_open(e.g. swaps_open) need to be
60340@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60341 return 0;
60342 }
60343 if (!m->buf) {
60344- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60345+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60346 if (!m->buf)
60347 return -ENOMEM;
60348 }
60349@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60350 Eoverflow:
60351 m->op->stop(m, p);
60352 kfree(m->buf);
60353- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60354+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60355 return !m->buf ? -ENOMEM : -EAGAIN;
60356 }
60357
60358@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60359
60360 /* grab buffer if we didn't have one */
60361 if (!m->buf) {
60362- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60363+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60364 if (!m->buf)
60365 goto Enomem;
60366 }
60367@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60368 goto Fill;
60369 m->op->stop(m, p);
60370 kfree(m->buf);
60371- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60372+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60373 if (!m->buf)
60374 goto Enomem;
60375 m->count = 0;
60376@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60377 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60378 void *data)
60379 {
60380- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60381+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60382 int res = -ENOMEM;
60383
60384 if (op) {
60385diff --git a/fs/splice.c b/fs/splice.c
60386index 3b7ee65..87fc2e4 100644
60387--- a/fs/splice.c
60388+++ b/fs/splice.c
60389@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60390 pipe_lock(pipe);
60391
60392 for (;;) {
60393- if (!pipe->readers) {
60394+ if (!atomic_read(&pipe->readers)) {
60395 send_sig(SIGPIPE, current, 0);
60396 if (!ret)
60397 ret = -EPIPE;
60398@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60399 page_nr++;
60400 ret += buf->len;
60401
60402- if (pipe->files)
60403+ if (atomic_read(&pipe->files))
60404 do_wakeup = 1;
60405
60406 if (!--spd->nr_pages)
60407@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60408 do_wakeup = 0;
60409 }
60410
60411- pipe->waiting_writers++;
60412+ atomic_inc(&pipe->waiting_writers);
60413 pipe_wait(pipe);
60414- pipe->waiting_writers--;
60415+ atomic_dec(&pipe->waiting_writers);
60416 }
60417
60418 pipe_unlock(pipe);
60419@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60420 old_fs = get_fs();
60421 set_fs(get_ds());
60422 /* The cast to a user pointer is valid due to the set_fs() */
60423- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60424+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60425 set_fs(old_fs);
60426
60427 return res;
60428@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60429 old_fs = get_fs();
60430 set_fs(get_ds());
60431 /* The cast to a user pointer is valid due to the set_fs() */
60432- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60433+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60434 set_fs(old_fs);
60435
60436 return res;
60437@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60438 goto err;
60439
60440 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60441- vec[i].iov_base = (void __user *) page_address(page);
60442+ vec[i].iov_base = (void __force_user *) page_address(page);
60443 vec[i].iov_len = this_len;
60444 spd.pages[i] = page;
60445 spd.nr_pages++;
60446@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60447 ops->release(pipe, buf);
60448 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60449 pipe->nrbufs--;
60450- if (pipe->files)
60451+ if (atomic_read(&pipe->files))
60452 sd->need_wakeup = true;
60453 }
60454
60455@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60456 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60457 {
60458 while (!pipe->nrbufs) {
60459- if (!pipe->writers)
60460+ if (!atomic_read(&pipe->writers))
60461 return 0;
60462
60463- if (!pipe->waiting_writers && sd->num_spliced)
60464+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60465 return 0;
60466
60467 if (sd->flags & SPLICE_F_NONBLOCK)
60468@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60469 * out of the pipe right after the splice_to_pipe(). So set
60470 * PIPE_READERS appropriately.
60471 */
60472- pipe->readers = 1;
60473+ atomic_set(&pipe->readers, 1);
60474
60475 current->splice_pipe = pipe;
60476 }
60477@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60478
60479 partial[buffers].offset = off;
60480 partial[buffers].len = plen;
60481+ partial[buffers].private = 0;
60482
60483 off = 0;
60484 len -= plen;
60485@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60486 ret = -ERESTARTSYS;
60487 break;
60488 }
60489- if (!pipe->writers)
60490+ if (!atomic_read(&pipe->writers))
60491 break;
60492- if (!pipe->waiting_writers) {
60493+ if (!atomic_read(&pipe->waiting_writers)) {
60494 if (flags & SPLICE_F_NONBLOCK) {
60495 ret = -EAGAIN;
60496 break;
60497@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60498 pipe_lock(pipe);
60499
60500 while (pipe->nrbufs >= pipe->buffers) {
60501- if (!pipe->readers) {
60502+ if (!atomic_read(&pipe->readers)) {
60503 send_sig(SIGPIPE, current, 0);
60504 ret = -EPIPE;
60505 break;
60506@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60507 ret = -ERESTARTSYS;
60508 break;
60509 }
60510- pipe->waiting_writers++;
60511+ atomic_inc(&pipe->waiting_writers);
60512 pipe_wait(pipe);
60513- pipe->waiting_writers--;
60514+ atomic_dec(&pipe->waiting_writers);
60515 }
60516
60517 pipe_unlock(pipe);
60518@@ -1862,14 +1863,14 @@ retry:
60519 pipe_double_lock(ipipe, opipe);
60520
60521 do {
60522- if (!opipe->readers) {
60523+ if (!atomic_read(&opipe->readers)) {
60524 send_sig(SIGPIPE, current, 0);
60525 if (!ret)
60526 ret = -EPIPE;
60527 break;
60528 }
60529
60530- if (!ipipe->nrbufs && !ipipe->writers)
60531+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60532 break;
60533
60534 /*
60535@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60536 pipe_double_lock(ipipe, opipe);
60537
60538 do {
60539- if (!opipe->readers) {
60540+ if (!atomic_read(&opipe->readers)) {
60541 send_sig(SIGPIPE, current, 0);
60542 if (!ret)
60543 ret = -EPIPE;
60544@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60545 * return EAGAIN if we have the potential of some data in the
60546 * future, otherwise just return 0
60547 */
60548- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60549+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60550 ret = -EAGAIN;
60551
60552 pipe_unlock(ipipe);
60553diff --git a/fs/stat.c b/fs/stat.c
60554index 04ce1ac..a13dd1e 100644
60555--- a/fs/stat.c
60556+++ b/fs/stat.c
60557@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60558 stat->gid = inode->i_gid;
60559 stat->rdev = inode->i_rdev;
60560 stat->size = i_size_read(inode);
60561- stat->atime = inode->i_atime;
60562- stat->mtime = inode->i_mtime;
60563+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60564+ stat->atime = inode->i_ctime;
60565+ stat->mtime = inode->i_ctime;
60566+ } else {
60567+ stat->atime = inode->i_atime;
60568+ stat->mtime = inode->i_mtime;
60569+ }
60570 stat->ctime = inode->i_ctime;
60571 stat->blksize = (1 << inode->i_blkbits);
60572 stat->blocks = inode->i_blocks;
60573@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60574 if (retval)
60575 return retval;
60576
60577- if (inode->i_op->getattr)
60578- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60579+ if (inode->i_op->getattr) {
60580+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60581+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60582+ stat->atime = stat->ctime;
60583+ stat->mtime = stat->ctime;
60584+ }
60585+ return retval;
60586+ }
60587
60588 generic_fillattr(inode, stat);
60589 return 0;
60590diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60591index 15c68f9..36a8b3e 100644
60592--- a/fs/sysfs/bin.c
60593+++ b/fs/sysfs/bin.c
60594@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60595 return ret;
60596 }
60597
60598-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60599- void *buf, int len, int write)
60600+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60601+ void *buf, size_t len, int write)
60602 {
60603 struct file *file = vma->vm_file;
60604 struct bin_buffer *bb = file->private_data;
60605 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60606- int ret;
60607+ ssize_t ret;
60608
60609 if (!bb->vm_ops)
60610 return -EINVAL;
60611diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60612index e068e74..92edeb8 100644
60613--- a/fs/sysfs/dir.c
60614+++ b/fs/sysfs/dir.c
60615@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60616 *
60617 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60618 */
60619-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60620+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60621 {
60622 unsigned long hash = init_name_hash();
60623 unsigned int len = strlen(name);
60624@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60625 struct sysfs_dirent *sd;
60626 int rc;
60627
60628+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60629+ const char *parent_name = parent_sd->s_name;
60630+
60631+ mode = S_IFDIR | S_IRWXU;
60632+
60633+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60634+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60635+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60636+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60637+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60638+#endif
60639+
60640 /* allocate */
60641 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60642 if (!sd)
60643diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60644index d2bb7ed..fe8c331 100644
60645--- a/fs/sysfs/file.c
60646+++ b/fs/sysfs/file.c
60647@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60648
60649 struct sysfs_open_dirent {
60650 atomic_t refcnt;
60651- atomic_t event;
60652+ atomic_unchecked_t event;
60653 wait_queue_head_t poll;
60654 struct list_head buffers; /* goes through sysfs_buffer.list */
60655 };
60656@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60657 if (!sysfs_get_active(attr_sd))
60658 return -ENODEV;
60659
60660- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60661+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60662 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60663
60664 sysfs_put_active(attr_sd);
60665@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60666 return -ENOMEM;
60667
60668 atomic_set(&new_od->refcnt, 0);
60669- atomic_set(&new_od->event, 1);
60670+ atomic_set_unchecked(&new_od->event, 1);
60671 init_waitqueue_head(&new_od->poll);
60672 INIT_LIST_HEAD(&new_od->buffers);
60673 goto retry;
60674@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60675
60676 sysfs_put_active(attr_sd);
60677
60678- if (buffer->event != atomic_read(&od->event))
60679+ if (buffer->event != atomic_read_unchecked(&od->event))
60680 goto trigger;
60681
60682 return DEFAULT_POLLMASK;
60683@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60684 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60685 od = sd->s_attr.open;
60686 if (od) {
60687- atomic_inc(&od->event);
60688+ atomic_inc_unchecked(&od->event);
60689 wake_up_interruptible(&od->poll);
60690 }
60691 }
60692diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60693index 8c940df..25b733e 100644
60694--- a/fs/sysfs/symlink.c
60695+++ b/fs/sysfs/symlink.c
60696@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60697
60698 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60699 {
60700- char *page = nd_get_link(nd);
60701+ const char *page = nd_get_link(nd);
60702 if (!IS_ERR(page))
60703 free_page((unsigned long)page);
60704 }
60705diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60706index 69d4889..a810bd4 100644
60707--- a/fs/sysv/sysv.h
60708+++ b/fs/sysv/sysv.h
60709@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60710 #endif
60711 }
60712
60713-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60714+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60715 {
60716 if (sbi->s_bytesex == BYTESEX_PDP)
60717 return PDP_swab((__force __u32)n);
60718diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60719index e18b988..f1d4ad0f 100644
60720--- a/fs/ubifs/io.c
60721+++ b/fs/ubifs/io.c
60722@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60723 return err;
60724 }
60725
60726-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60727+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60728 {
60729 int err;
60730
60731diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60732index c175b4d..8f36a16 100644
60733--- a/fs/udf/misc.c
60734+++ b/fs/udf/misc.c
60735@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60736
60737 u8 udf_tag_checksum(const struct tag *t)
60738 {
60739- u8 *data = (u8 *)t;
60740+ const u8 *data = (const u8 *)t;
60741 u8 checksum = 0;
60742 int i;
60743 for (i = 0; i < sizeof(struct tag); ++i)
60744diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60745index 8d974c4..b82f6ec 100644
60746--- a/fs/ufs/swab.h
60747+++ b/fs/ufs/swab.h
60748@@ -22,7 +22,7 @@ enum {
60749 BYTESEX_BE
60750 };
60751
60752-static inline u64
60753+static inline u64 __intentional_overflow(-1)
60754 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60755 {
60756 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60757@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60758 return (__force __fs64)cpu_to_be64(n);
60759 }
60760
60761-static inline u32
60762+static inline u32 __intentional_overflow(-1)
60763 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60764 {
60765 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60766diff --git a/fs/utimes.c b/fs/utimes.c
60767index f4fb7ec..3fe03c0 100644
60768--- a/fs/utimes.c
60769+++ b/fs/utimes.c
60770@@ -1,6 +1,7 @@
60771 #include <linux/compiler.h>
60772 #include <linux/file.h>
60773 #include <linux/fs.h>
60774+#include <linux/security.h>
60775 #include <linux/linkage.h>
60776 #include <linux/mount.h>
60777 #include <linux/namei.h>
60778@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60779 goto mnt_drop_write_and_out;
60780 }
60781 }
60782+
60783+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60784+ error = -EACCES;
60785+ goto mnt_drop_write_and_out;
60786+ }
60787+
60788 mutex_lock(&inode->i_mutex);
60789 error = notify_change(path->dentry, &newattrs);
60790 mutex_unlock(&inode->i_mutex);
60791diff --git a/fs/xattr.c b/fs/xattr.c
60792index 3377dff..4d074d9 100644
60793--- a/fs/xattr.c
60794+++ b/fs/xattr.c
60795@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60796 return rc;
60797 }
60798
60799+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60800+ssize_t
60801+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60802+{
60803+ struct inode *inode = dentry->d_inode;
60804+ ssize_t error;
60805+
60806+ error = inode_permission(inode, MAY_EXEC);
60807+ if (error)
60808+ return error;
60809+
60810+ if (inode->i_op->getxattr)
60811+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60812+ else
60813+ error = -EOPNOTSUPP;
60814+
60815+ return error;
60816+}
60817+EXPORT_SYMBOL(pax_getxattr);
60818+#endif
60819+
60820 ssize_t
60821 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60822 {
60823@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60824 * Extended attribute SET operations
60825 */
60826 static long
60827-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60828+setxattr(struct path *path, const char __user *name, const void __user *value,
60829 size_t size, int flags)
60830 {
60831 int error;
60832@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60833 posix_acl_fix_xattr_from_user(kvalue, size);
60834 }
60835
60836- error = vfs_setxattr(d, kname, kvalue, size, flags);
60837+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60838+ error = -EACCES;
60839+ goto out;
60840+ }
60841+
60842+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60843 out:
60844 if (vvalue)
60845 vfree(vvalue);
60846@@ -377,7 +403,7 @@ retry:
60847 return error;
60848 error = mnt_want_write(path.mnt);
60849 if (!error) {
60850- error = setxattr(path.dentry, name, value, size, flags);
60851+ error = setxattr(&path, name, value, size, flags);
60852 mnt_drop_write(path.mnt);
60853 }
60854 path_put(&path);
60855@@ -401,7 +427,7 @@ retry:
60856 return error;
60857 error = mnt_want_write(path.mnt);
60858 if (!error) {
60859- error = setxattr(path.dentry, name, value, size, flags);
60860+ error = setxattr(&path, name, value, size, flags);
60861 mnt_drop_write(path.mnt);
60862 }
60863 path_put(&path);
60864@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60865 const void __user *,value, size_t, size, int, flags)
60866 {
60867 struct fd f = fdget(fd);
60868- struct dentry *dentry;
60869 int error = -EBADF;
60870
60871 if (!f.file)
60872 return error;
60873- dentry = f.file->f_path.dentry;
60874- audit_inode(NULL, dentry, 0);
60875+ audit_inode(NULL, f.file->f_path.dentry, 0);
60876 error = mnt_want_write_file(f.file);
60877 if (!error) {
60878- error = setxattr(dentry, name, value, size, flags);
60879+ error = setxattr(&f.file->f_path, name, value, size, flags);
60880 mnt_drop_write_file(f.file);
60881 }
60882 fdput(f);
60883diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60884index 9fbea87..6b19972 100644
60885--- a/fs/xattr_acl.c
60886+++ b/fs/xattr_acl.c
60887@@ -76,8 +76,8 @@ struct posix_acl *
60888 posix_acl_from_xattr(struct user_namespace *user_ns,
60889 const void *value, size_t size)
60890 {
60891- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60892- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60893+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60894+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60895 int count;
60896 struct posix_acl *acl;
60897 struct posix_acl_entry *acl_e;
60898diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60899index 05c698c..6b918af 100644
60900--- a/fs/xfs/xfs_bmap.c
60901+++ b/fs/xfs/xfs_bmap.c
60902@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60903
60904 #else
60905 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60906-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60907+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60908 #endif /* DEBUG */
60909
60910 /*
60911diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60912index 97676a3..399a75d 100644
60913--- a/fs/xfs/xfs_dir2_sf.c
60914+++ b/fs/xfs/xfs_dir2_sf.c
60915@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60916
60917 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60918 ctx->pos = off & 0x7fffffff;
60919- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60920+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60921+ char name[sfep->namelen];
60922+ memcpy(name, sfep->name, sfep->namelen);
60923+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60924+ return 0;
60925+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60926 ino, DT_UNKNOWN))
60927 return 0;
60928 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60929diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60930index 6e2bca5..6ce80d3 100644
60931--- a/fs/xfs/xfs_ioctl.c
60932+++ b/fs/xfs/xfs_ioctl.c
60933@@ -127,7 +127,7 @@ xfs_find_handle(
60934 }
60935
60936 error = -EFAULT;
60937- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60938+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60939 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60940 goto out_put;
60941
60942diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60943index 96dda62..d6c6a52 100644
60944--- a/fs/xfs/xfs_iops.c
60945+++ b/fs/xfs/xfs_iops.c
60946@@ -395,7 +395,7 @@ xfs_vn_put_link(
60947 struct nameidata *nd,
60948 void *p)
60949 {
60950- char *s = nd_get_link(nd);
60951+ const char *s = nd_get_link(nd);
60952
60953 if (!IS_ERR(s))
60954 kfree(s);
60955diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
60956new file mode 100644
60957index 0000000..0fd7c82
60958--- /dev/null
60959+++ b/grsecurity/Kconfig
60960@@ -0,0 +1,1080 @@
60961+#
60962+# grecurity configuration
60963+#
60964+menu "Memory Protections"
60965+depends on GRKERNSEC
60966+
60967+config GRKERNSEC_KMEM
60968+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
60969+ default y if GRKERNSEC_CONFIG_AUTO
60970+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60971+ help
60972+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60973+ be written to or read from to modify or leak the contents of the running
60974+ kernel. /dev/port will also not be allowed to be opened and support
60975+ for /dev/cpu/*/msr will be removed. If you have module
60976+ support disabled, enabling this will close up five ways that are
60977+ currently used to insert malicious code into the running kernel.
60978+
60979+ Even with all these features enabled, we still highly recommend that
60980+ you use the RBAC system, as it is still possible for an attacker to
60981+ modify the running kernel through privileged I/O granted by ioperm/iopl.
60982+
60983+ If you are not using XFree86, you may be able to stop this additional
60984+ case by enabling the 'Disable privileged I/O' option. Though nothing
60985+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60986+ but only to video memory, which is the only writing we allow in this
60987+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60988+ not be allowed to mprotect it with PROT_WRITE later.
60989+ Enabling this feature will prevent the "cpupower" and "powertop" tools
60990+ from working.
60991+
60992+ It is highly recommended that you say Y here if you meet all the
60993+ conditions above.
60994+
60995+config GRKERNSEC_VM86
60996+ bool "Restrict VM86 mode"
60997+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60998+ depends on X86_32
60999+
61000+ help
61001+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61002+ make use of a special execution mode on 32bit x86 processors called
61003+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61004+ video cards and will still work with this option enabled. The purpose
61005+ of the option is to prevent exploitation of emulation errors in
61006+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61007+ Nearly all users should be able to enable this option.
61008+
61009+config GRKERNSEC_IO
61010+ bool "Disable privileged I/O"
61011+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61012+ depends on X86
61013+ select RTC_CLASS
61014+ select RTC_INTF_DEV
61015+ select RTC_DRV_CMOS
61016+
61017+ help
61018+ If you say Y here, all ioperm and iopl calls will return an error.
61019+ Ioperm and iopl can be used to modify the running kernel.
61020+ Unfortunately, some programs need this access to operate properly,
61021+ the most notable of which are XFree86 and hwclock. hwclock can be
61022+ remedied by having RTC support in the kernel, so real-time
61023+ clock support is enabled if this option is enabled, to ensure
61024+ that hwclock operates correctly. XFree86 still will not
61025+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61026+ IF YOU USE XFree86. If you use XFree86 and you still want to
61027+ protect your kernel against modification, use the RBAC system.
61028+
61029+config GRKERNSEC_JIT_HARDEN
61030+ bool "Harden BPF JIT against spray attacks"
61031+ default y if GRKERNSEC_CONFIG_AUTO
61032+ depends on BPF_JIT
61033+ help
61034+ If you say Y here, the native code generated by the kernel's Berkeley
61035+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61036+ attacks that attempt to fit attacker-beneficial instructions in
61037+ 32bit immediate fields of JIT-generated native instructions. The
61038+ attacker will generally aim to cause an unintended instruction sequence
61039+ of JIT-generated native code to execute by jumping into the middle of
61040+ a generated instruction. This feature effectively randomizes the 32bit
61041+ immediate constants present in the generated code to thwart such attacks.
61042+
61043+ If you're using KERNEXEC, it's recommended that you enable this option
61044+ to supplement the hardening of the kernel.
61045+
61046+config GRKERNSEC_PERF_HARDEN
61047+ bool "Disable unprivileged PERF_EVENTS usage by default"
61048+ default y if GRKERNSEC_CONFIG_AUTO
61049+ depends on PERF_EVENTS
61050+ help
61051+ If you say Y here, the range of acceptable values for the
61052+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61053+ default to a new value: 3. When the sysctl is set to this value, no
61054+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61055+
61056+ Though PERF_EVENTS can be used legitimately for performance monitoring
61057+ and low-level application profiling, it is forced on regardless of
61058+ configuration, has been at fault for several vulnerabilities, and
61059+ creates new opportunities for side channels and other information leaks.
61060+
61061+ This feature puts PERF_EVENTS into a secure default state and permits
61062+ the administrator to change out of it temporarily if unprivileged
61063+ application profiling is needed.
61064+
61065+config GRKERNSEC_RAND_THREADSTACK
61066+ bool "Insert random gaps between thread stacks"
61067+ default y if GRKERNSEC_CONFIG_AUTO
61068+ depends on PAX_RANDMMAP && !PPC
61069+ help
61070+ If you say Y here, a random-sized gap will be enforced between allocated
61071+ thread stacks. Glibc's NPTL and other threading libraries that
61072+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61073+ The implementation currently provides 8 bits of entropy for the gap.
61074+
61075+ Many distributions do not compile threaded remote services with the
61076+ -fstack-check argument to GCC, causing the variable-sized stack-based
61077+ allocator, alloca(), to not probe the stack on allocation. This
61078+ permits an unbounded alloca() to skip over any guard page and potentially
61079+ modify another thread's stack reliably. An enforced random gap
61080+ reduces the reliability of such an attack and increases the chance
61081+ that such a read/write to another thread's stack instead lands in
61082+ an unmapped area, causing a crash and triggering grsecurity's
61083+ anti-bruteforcing logic.
61084+
61085+config GRKERNSEC_PROC_MEMMAP
61086+ bool "Harden ASLR against information leaks and entropy reduction"
61087+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61088+ depends on PAX_NOEXEC || PAX_ASLR
61089+ help
61090+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61091+ give no information about the addresses of its mappings if
61092+ PaX features that rely on random addresses are enabled on the task.
61093+ In addition to sanitizing this information and disabling other
61094+ dangerous sources of information, this option causes reads of sensitive
61095+ /proc/<pid> entries where the file descriptor was opened in a different
61096+ task than the one performing the read. Such attempts are logged.
61097+ This option also limits argv/env strings for suid/sgid binaries
61098+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61099+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61100+ binaries to prevent alternative mmap layouts from being abused.
61101+
61102+ If you use PaX it is essential that you say Y here as it closes up
61103+ several holes that make full ASLR useless locally.
61104+
61105+config GRKERNSEC_BRUTE
61106+ bool "Deter exploit bruteforcing"
61107+ default y if GRKERNSEC_CONFIG_AUTO
61108+ help
61109+ If you say Y here, attempts to bruteforce exploits against forking
61110+ daemons such as apache or sshd, as well as against suid/sgid binaries
61111+ will be deterred. When a child of a forking daemon is killed by PaX
61112+ or crashes due to an illegal instruction or other suspicious signal,
61113+ the parent process will be delayed 30 seconds upon every subsequent
61114+ fork until the administrator is able to assess the situation and
61115+ restart the daemon.
61116+ In the suid/sgid case, the attempt is logged, the user has all their
61117+ existing instances of the suid/sgid binary terminated and will
61118+ be unable to execute any suid/sgid binaries for 15 minutes.
61119+
61120+ It is recommended that you also enable signal logging in the auditing
61121+ section so that logs are generated when a process triggers a suspicious
61122+ signal.
61123+ If the sysctl option is enabled, a sysctl option with name
61124+ "deter_bruteforce" is created.
61125+
61126+
61127+config GRKERNSEC_MODHARDEN
61128+ bool "Harden module auto-loading"
61129+ default y if GRKERNSEC_CONFIG_AUTO
61130+ depends on MODULES
61131+ help
61132+ If you say Y here, module auto-loading in response to use of some
61133+ feature implemented by an unloaded module will be restricted to
61134+ root users. Enabling this option helps defend against attacks
61135+ by unprivileged users who abuse the auto-loading behavior to
61136+ cause a vulnerable module to load that is then exploited.
61137+
61138+ If this option prevents a legitimate use of auto-loading for a
61139+ non-root user, the administrator can execute modprobe manually
61140+ with the exact name of the module mentioned in the alert log.
61141+ Alternatively, the administrator can add the module to the list
61142+ of modules loaded at boot by modifying init scripts.
61143+
61144+ Modification of init scripts will most likely be needed on
61145+ Ubuntu servers with encrypted home directory support enabled,
61146+ as the first non-root user logging in will cause the ecb(aes),
61147+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61148+
61149+config GRKERNSEC_HIDESYM
61150+ bool "Hide kernel symbols"
61151+ default y if GRKERNSEC_CONFIG_AUTO
61152+ select PAX_USERCOPY_SLABS
61153+ help
61154+ If you say Y here, getting information on loaded modules, and
61155+ displaying all kernel symbols through a syscall will be restricted
61156+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61157+ /proc/kallsyms will be restricted to the root user. The RBAC
61158+ system can hide that entry even from root.
61159+
61160+ This option also prevents leaking of kernel addresses through
61161+ several /proc entries.
61162+
61163+ Note that this option is only effective provided the following
61164+ conditions are met:
61165+ 1) The kernel using grsecurity is not precompiled by some distribution
61166+ 2) You have also enabled GRKERNSEC_DMESG
61167+ 3) You are using the RBAC system and hiding other files such as your
61168+ kernel image and System.map. Alternatively, enabling this option
61169+ causes the permissions on /boot, /lib/modules, and the kernel
61170+ source directory to change at compile time to prevent
61171+ reading by non-root users.
61172+ If the above conditions are met, this option will aid in providing a
61173+ useful protection against local kernel exploitation of overflows
61174+ and arbitrary read/write vulnerabilities.
61175+
61176+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61177+ in addition to this feature.
61178+
61179+config GRKERNSEC_KERN_LOCKOUT
61180+ bool "Active kernel exploit response"
61181+ default y if GRKERNSEC_CONFIG_AUTO
61182+ depends on X86 || ARM || PPC || SPARC
61183+ help
61184+ If you say Y here, when a PaX alert is triggered due to suspicious
61185+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61186+ or an OOPS occurs due to bad memory accesses, instead of just
61187+ terminating the offending process (and potentially allowing
61188+ a subsequent exploit from the same user), we will take one of two
61189+ actions:
61190+ If the user was root, we will panic the system
61191+ If the user was non-root, we will log the attempt, terminate
61192+ all processes owned by the user, then prevent them from creating
61193+ any new processes until the system is restarted
61194+ This deters repeated kernel exploitation/bruteforcing attempts
61195+ and is useful for later forensics.
61196+
61197+endmenu
61198+menu "Role Based Access Control Options"
61199+depends on GRKERNSEC
61200+
61201+config GRKERNSEC_RBAC_DEBUG
61202+ bool
61203+
61204+config GRKERNSEC_NO_RBAC
61205+ bool "Disable RBAC system"
61206+ help
61207+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61208+ preventing the RBAC system from being enabled. You should only say Y
61209+ here if you have no intention of using the RBAC system, so as to prevent
61210+ an attacker with root access from misusing the RBAC system to hide files
61211+ and processes when loadable module support and /dev/[k]mem have been
61212+ locked down.
61213+
61214+config GRKERNSEC_ACL_HIDEKERN
61215+ bool "Hide kernel processes"
61216+ help
61217+ If you say Y here, all kernel threads will be hidden to all
61218+ processes but those whose subject has the "view hidden processes"
61219+ flag.
61220+
61221+config GRKERNSEC_ACL_MAXTRIES
61222+ int "Maximum tries before password lockout"
61223+ default 3
61224+ help
61225+ This option enforces the maximum number of times a user can attempt
61226+ to authorize themselves with the grsecurity RBAC system before being
61227+ denied the ability to attempt authorization again for a specified time.
61228+ The lower the number, the harder it will be to brute-force a password.
61229+
61230+config GRKERNSEC_ACL_TIMEOUT
61231+ int "Time to wait after max password tries, in seconds"
61232+ default 30
61233+ help
61234+ This option specifies the time the user must wait after attempting to
61235+ authorize to the RBAC system with the maximum number of invalid
61236+ passwords. The higher the number, the harder it will be to brute-force
61237+ a password.
61238+
61239+endmenu
61240+menu "Filesystem Protections"
61241+depends on GRKERNSEC
61242+
61243+config GRKERNSEC_PROC
61244+ bool "Proc restrictions"
61245+ default y if GRKERNSEC_CONFIG_AUTO
61246+ help
61247+ If you say Y here, the permissions of the /proc filesystem
61248+ will be altered to enhance system security and privacy. You MUST
61249+ choose either a user only restriction or a user and group restriction.
61250+ Depending upon the option you choose, you can either restrict users to
61251+ see only the processes they themselves run, or choose a group that can
61252+ view all processes and files normally restricted to root if you choose
61253+ the "restrict to user only" option. NOTE: If you're running identd or
61254+ ntpd as a non-root user, you will have to run it as the group you
61255+ specify here.
61256+
61257+config GRKERNSEC_PROC_USER
61258+ bool "Restrict /proc to user only"
61259+ depends on GRKERNSEC_PROC
61260+ help
61261+ If you say Y here, non-root users will only be able to view their own
61262+ processes, and restricts them from viewing network-related information,
61263+ and viewing kernel symbol and module information.
61264+
61265+config GRKERNSEC_PROC_USERGROUP
61266+ bool "Allow special group"
61267+ default y if GRKERNSEC_CONFIG_AUTO
61268+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61269+ help
61270+ If you say Y here, you will be able to select a group that will be
61271+ able to view all processes and network-related information. If you've
61272+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61273+ remain hidden. This option is useful if you want to run identd as
61274+ a non-root user. The group you select may also be chosen at boot time
61275+ via "grsec_proc_gid=" on the kernel commandline.
61276+
61277+config GRKERNSEC_PROC_GID
61278+ int "GID for special group"
61279+ depends on GRKERNSEC_PROC_USERGROUP
61280+ default 1001
61281+
61282+config GRKERNSEC_PROC_ADD
61283+ bool "Additional restrictions"
61284+ default y if GRKERNSEC_CONFIG_AUTO
61285+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61286+ help
61287+ If you say Y here, additional restrictions will be placed on
61288+ /proc that keep normal users from viewing device information and
61289+ slabinfo information that could be useful for exploits.
61290+
61291+config GRKERNSEC_LINK
61292+ bool "Linking restrictions"
61293+ default y if GRKERNSEC_CONFIG_AUTO
61294+ help
61295+ If you say Y here, /tmp race exploits will be prevented, since users
61296+ will no longer be able to follow symlinks owned by other users in
61297+ world-writable +t directories (e.g. /tmp), unless the owner of the
61298+ symlink is the owner of the directory. users will also not be
61299+ able to hardlink to files they do not own. If the sysctl option is
61300+ enabled, a sysctl option with name "linking_restrictions" is created.
61301+
61302+config GRKERNSEC_SYMLINKOWN
61303+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61304+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61305+ help
61306+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61307+ that prevents it from being used as a security feature. As Apache
61308+ verifies the symlink by performing a stat() against the target of
61309+ the symlink before it is followed, an attacker can setup a symlink
61310+ to point to a same-owned file, then replace the symlink with one
61311+ that targets another user's file just after Apache "validates" the
61312+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61313+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61314+ will be in place for the group you specify. If the sysctl option
61315+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61316+ created.
61317+
61318+config GRKERNSEC_SYMLINKOWN_GID
61319+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61320+ depends on GRKERNSEC_SYMLINKOWN
61321+ default 1006
61322+ help
61323+ Setting this GID determines what group kernel-enforced
61324+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61325+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61326+
61327+config GRKERNSEC_FIFO
61328+ bool "FIFO restrictions"
61329+ default y if GRKERNSEC_CONFIG_AUTO
61330+ help
61331+ If you say Y here, users will not be able to write to FIFOs they don't
61332+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61333+ the FIFO is the same owner of the directory it's held in. If the sysctl
61334+ option is enabled, a sysctl option with name "fifo_restrictions" is
61335+ created.
61336+
61337+config GRKERNSEC_SYSFS_RESTRICT
61338+ bool "Sysfs/debugfs restriction"
61339+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61340+ depends on SYSFS
61341+ help
61342+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61343+ any filesystem normally mounted under it (e.g. debugfs) will be
61344+ mostly accessible only by root. These filesystems generally provide access
61345+ to hardware and debug information that isn't appropriate for unprivileged
61346+ users of the system. Sysfs and debugfs have also become a large source
61347+ of new vulnerabilities, ranging from infoleaks to local compromise.
61348+ There has been very little oversight with an eye toward security involved
61349+ in adding new exporters of information to these filesystems, so their
61350+ use is discouraged.
61351+ For reasons of compatibility, a few directories have been whitelisted
61352+ for access by non-root users:
61353+ /sys/fs/selinux
61354+ /sys/fs/fuse
61355+ /sys/devices/system/cpu
61356+
61357+config GRKERNSEC_ROFS
61358+ bool "Runtime read-only mount protection"
61359+ depends on SYSCTL
61360+ help
61361+ If you say Y here, a sysctl option with name "romount_protect" will
61362+ be created. By setting this option to 1 at runtime, filesystems
61363+ will be protected in the following ways:
61364+ * No new writable mounts will be allowed
61365+ * Existing read-only mounts won't be able to be remounted read/write
61366+ * Write operations will be denied on all block devices
61367+ This option acts independently of grsec_lock: once it is set to 1,
61368+ it cannot be turned off. Therefore, please be mindful of the resulting
61369+ behavior if this option is enabled in an init script on a read-only
61370+ filesystem. This feature is mainly intended for secure embedded systems.
61371+
61372+config GRKERNSEC_DEVICE_SIDECHANNEL
61373+ bool "Eliminate stat/notify-based device sidechannels"
61374+ default y if GRKERNSEC_CONFIG_AUTO
61375+ help
61376+ If you say Y here, timing analyses on block or character
61377+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61378+ will be thwarted for unprivileged users. If a process without
61379+ CAP_MKNOD stats such a device, the last access and last modify times
61380+ will match the device's create time. No access or modify events
61381+ will be triggered through inotify/dnotify/fanotify for such devices.
61382+ This feature will prevent attacks that may at a minimum
61383+ allow an attacker to determine the administrator's password length.
61384+
61385+config GRKERNSEC_CHROOT
61386+ bool "Chroot jail restrictions"
61387+ default y if GRKERNSEC_CONFIG_AUTO
61388+ help
61389+ If you say Y here, you will be able to choose several options that will
61390+ make breaking out of a chrooted jail much more difficult. If you
61391+ encounter no software incompatibilities with the following options, it
61392+ is recommended that you enable each one.
61393+
61394+config GRKERNSEC_CHROOT_MOUNT
61395+ bool "Deny mounts"
61396+ default y if GRKERNSEC_CONFIG_AUTO
61397+ depends on GRKERNSEC_CHROOT
61398+ help
61399+ If you say Y here, processes inside a chroot will not be able to
61400+ mount or remount filesystems. If the sysctl option is enabled, a
61401+ sysctl option with name "chroot_deny_mount" is created.
61402+
61403+config GRKERNSEC_CHROOT_DOUBLE
61404+ bool "Deny double-chroots"
61405+ default y if GRKERNSEC_CONFIG_AUTO
61406+ depends on GRKERNSEC_CHROOT
61407+ help
61408+ If you say Y here, processes inside a chroot will not be able to chroot
61409+ again outside the chroot. This is a widely used method of breaking
61410+ out of a chroot jail and should not be allowed. If the sysctl
61411+ option is enabled, a sysctl option with name
61412+ "chroot_deny_chroot" is created.
61413+
61414+config GRKERNSEC_CHROOT_PIVOT
61415+ bool "Deny pivot_root in chroot"
61416+ default y if GRKERNSEC_CONFIG_AUTO
61417+ depends on GRKERNSEC_CHROOT
61418+ help
61419+ If you say Y here, processes inside a chroot will not be able to use
61420+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61421+ works similar to chroot in that it changes the root filesystem. This
61422+ function could be misused in a chrooted process to attempt to break out
61423+ of the chroot, and therefore should not be allowed. If the sysctl
61424+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61425+ created.
61426+
61427+config GRKERNSEC_CHROOT_CHDIR
61428+ bool "Enforce chdir(\"/\") on all chroots"
61429+ default y if GRKERNSEC_CONFIG_AUTO
61430+ depends on GRKERNSEC_CHROOT
61431+ help
61432+ If you say Y here, the current working directory of all newly-chrooted
61433+ applications will be set to the the root directory of the chroot.
61434+ The man page on chroot(2) states:
61435+ Note that this call does not change the current working
61436+ directory, so that `.' can be outside the tree rooted at
61437+ `/'. In particular, the super-user can escape from a
61438+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61439+
61440+ It is recommended that you say Y here, since it's not known to break
61441+ any software. If the sysctl option is enabled, a sysctl option with
61442+ name "chroot_enforce_chdir" is created.
61443+
61444+config GRKERNSEC_CHROOT_CHMOD
61445+ bool "Deny (f)chmod +s"
61446+ default y if GRKERNSEC_CONFIG_AUTO
61447+ depends on GRKERNSEC_CHROOT
61448+ help
61449+ If you say Y here, processes inside a chroot will not be able to chmod
61450+ or fchmod files to make them have suid or sgid bits. This protects
61451+ against another published method of breaking a chroot. If the sysctl
61452+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61453+ created.
61454+
61455+config GRKERNSEC_CHROOT_FCHDIR
61456+ bool "Deny fchdir out of chroot"
61457+ default y if GRKERNSEC_CONFIG_AUTO
61458+ depends on GRKERNSEC_CHROOT
61459+ help
61460+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61461+ to a file descriptor of the chrooting process that points to a directory
61462+ outside the filesystem will be stopped. If the sysctl option
61463+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61464+
61465+config GRKERNSEC_CHROOT_MKNOD
61466+ bool "Deny mknod"
61467+ default y if GRKERNSEC_CONFIG_AUTO
61468+ depends on GRKERNSEC_CHROOT
61469+ help
61470+ If you say Y here, processes inside a chroot will not be allowed to
61471+ mknod. The problem with using mknod inside a chroot is that it
61472+ would allow an attacker to create a device entry that is the same
61473+ as one on the physical root of your system, which could range from
61474+ anything from the console device to a device for your harddrive (which
61475+ they could then use to wipe the drive or steal data). It is recommended
61476+ that you say Y here, unless you run into software incompatibilities.
61477+ If the sysctl option is enabled, a sysctl option with name
61478+ "chroot_deny_mknod" is created.
61479+
61480+config GRKERNSEC_CHROOT_SHMAT
61481+ bool "Deny shmat() out of chroot"
61482+ default y if GRKERNSEC_CONFIG_AUTO
61483+ depends on GRKERNSEC_CHROOT
61484+ help
61485+ If you say Y here, processes inside a chroot will not be able to attach
61486+ to shared memory segments that were created outside of the chroot jail.
61487+ It is recommended that you say Y here. If the sysctl option is enabled,
61488+ a sysctl option with name "chroot_deny_shmat" is created.
61489+
61490+config GRKERNSEC_CHROOT_UNIX
61491+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61492+ default y if GRKERNSEC_CONFIG_AUTO
61493+ depends on GRKERNSEC_CHROOT
61494+ help
61495+ If you say Y here, processes inside a chroot will not be able to
61496+ connect to abstract (meaning not belonging to a filesystem) Unix
61497+ domain sockets that were bound outside of a chroot. It is recommended
61498+ that you say Y here. If the sysctl option is enabled, a sysctl option
61499+ with name "chroot_deny_unix" is created.
61500+
61501+config GRKERNSEC_CHROOT_FINDTASK
61502+ bool "Protect outside processes"
61503+ default y if GRKERNSEC_CONFIG_AUTO
61504+ depends on GRKERNSEC_CHROOT
61505+ help
61506+ If you say Y here, processes inside a chroot will not be able to
61507+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61508+ getsid, or view any process outside of the chroot. If the sysctl
61509+ option is enabled, a sysctl option with name "chroot_findtask" is
61510+ created.
61511+
61512+config GRKERNSEC_CHROOT_NICE
61513+ bool "Restrict priority changes"
61514+ default y if GRKERNSEC_CONFIG_AUTO
61515+ depends on GRKERNSEC_CHROOT
61516+ help
61517+ If you say Y here, processes inside a chroot will not be able to raise
61518+ the priority of processes in the chroot, or alter the priority of
61519+ processes outside the chroot. This provides more security than simply
61520+ removing CAP_SYS_NICE from the process' capability set. If the
61521+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61522+ is created.
61523+
61524+config GRKERNSEC_CHROOT_SYSCTL
61525+ bool "Deny sysctl writes"
61526+ default y if GRKERNSEC_CONFIG_AUTO
61527+ depends on GRKERNSEC_CHROOT
61528+ help
61529+ If you say Y here, an attacker in a chroot will not be able to
61530+ write to sysctl entries, either by sysctl(2) or through a /proc
61531+ interface. It is strongly recommended that you say Y here. If the
61532+ sysctl option is enabled, a sysctl option with name
61533+ "chroot_deny_sysctl" is created.
61534+
61535+config GRKERNSEC_CHROOT_CAPS
61536+ bool "Capability restrictions"
61537+ default y if GRKERNSEC_CONFIG_AUTO
61538+ depends on GRKERNSEC_CHROOT
61539+ help
61540+ If you say Y here, the capabilities on all processes within a
61541+ chroot jail will be lowered to stop module insertion, raw i/o,
61542+ system and net admin tasks, rebooting the system, modifying immutable
61543+ files, modifying IPC owned by another, and changing the system time.
61544+ This is left an option because it can break some apps. Disable this
61545+ if your chrooted apps are having problems performing those kinds of
61546+ tasks. If the sysctl option is enabled, a sysctl option with
61547+ name "chroot_caps" is created.
61548+
61549+config GRKERNSEC_CHROOT_INITRD
61550+ bool "Exempt initrd tasks from restrictions"
61551+ default y if GRKERNSEC_CONFIG_AUTO
61552+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61553+ help
61554+ If you say Y here, tasks started prior to init will be exempted from
61555+ grsecurity's chroot restrictions. This option is mainly meant to
61556+ resolve Plymouth's performing privileged operations unnecessarily
61557+ in a chroot.
61558+
61559+endmenu
61560+menu "Kernel Auditing"
61561+depends on GRKERNSEC
61562+
61563+config GRKERNSEC_AUDIT_GROUP
61564+ bool "Single group for auditing"
61565+ help
61566+ If you say Y here, the exec and chdir logging features will only operate
61567+ on a group you specify. This option is recommended if you only want to
61568+ watch certain users instead of having a large amount of logs from the
61569+ entire system. If the sysctl option is enabled, a sysctl option with
61570+ name "audit_group" is created.
61571+
61572+config GRKERNSEC_AUDIT_GID
61573+ int "GID for auditing"
61574+ depends on GRKERNSEC_AUDIT_GROUP
61575+ default 1007
61576+
61577+config GRKERNSEC_EXECLOG
61578+ bool "Exec logging"
61579+ help
61580+ If you say Y here, all execve() calls will be logged (since the
61581+ other exec*() calls are frontends to execve(), all execution
61582+ will be logged). Useful for shell-servers that like to keep track
61583+ of their users. If the sysctl option is enabled, a sysctl option with
61584+ name "exec_logging" is created.
61585+ WARNING: This option when enabled will produce a LOT of logs, especially
61586+ on an active system.
61587+
61588+config GRKERNSEC_RESLOG
61589+ bool "Resource logging"
61590+ default y if GRKERNSEC_CONFIG_AUTO
61591+ help
61592+ If you say Y here, all attempts to overstep resource limits will
61593+ be logged with the resource name, the requested size, and the current
61594+ limit. It is highly recommended that you say Y here. If the sysctl
61595+ option is enabled, a sysctl option with name "resource_logging" is
61596+ created. If the RBAC system is enabled, the sysctl value is ignored.
61597+
61598+config GRKERNSEC_CHROOT_EXECLOG
61599+ bool "Log execs within chroot"
61600+ help
61601+ If you say Y here, all executions inside a chroot jail will be logged
61602+ to syslog. This can cause a large amount of logs if certain
61603+ applications (eg. djb's daemontools) are installed on the system, and
61604+ is therefore left as an option. If the sysctl option is enabled, a
61605+ sysctl option with name "chroot_execlog" is created.
61606+
61607+config GRKERNSEC_AUDIT_PTRACE
61608+ bool "Ptrace logging"
61609+ help
61610+ If you say Y here, all attempts to attach to a process via ptrace
61611+ will be logged. If the sysctl option is enabled, a sysctl option
61612+ with name "audit_ptrace" is created.
61613+
61614+config GRKERNSEC_AUDIT_CHDIR
61615+ bool "Chdir logging"
61616+ help
61617+ If you say Y here, all chdir() calls will be logged. If the sysctl
61618+ option is enabled, a sysctl option with name "audit_chdir" is created.
61619+
61620+config GRKERNSEC_AUDIT_MOUNT
61621+ bool "(Un)Mount logging"
61622+ help
61623+ If you say Y here, all mounts and unmounts will be logged. If the
61624+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61625+ created.
61626+
61627+config GRKERNSEC_SIGNAL
61628+ bool "Signal logging"
61629+ default y if GRKERNSEC_CONFIG_AUTO
61630+ help
61631+ If you say Y here, certain important signals will be logged, such as
61632+ SIGSEGV, which will as a result inform you of when a error in a program
61633+ occurred, which in some cases could mean a possible exploit attempt.
61634+ If the sysctl option is enabled, a sysctl option with name
61635+ "signal_logging" is created.
61636+
61637+config GRKERNSEC_FORKFAIL
61638+ bool "Fork failure logging"
61639+ help
61640+ If you say Y here, all failed fork() attempts will be logged.
61641+ This could suggest a fork bomb, or someone attempting to overstep
61642+ their process limit. If the sysctl option is enabled, a sysctl option
61643+ with name "forkfail_logging" is created.
61644+
61645+config GRKERNSEC_TIME
61646+ bool "Time change logging"
61647+ default y if GRKERNSEC_CONFIG_AUTO
61648+ help
61649+ If you say Y here, any changes of the system clock will be logged.
61650+ If the sysctl option is enabled, a sysctl option with name
61651+ "timechange_logging" is created.
61652+
61653+config GRKERNSEC_PROC_IPADDR
61654+ bool "/proc/<pid>/ipaddr support"
61655+ default y if GRKERNSEC_CONFIG_AUTO
61656+ help
61657+ If you say Y here, a new entry will be added to each /proc/<pid>
61658+ directory that contains the IP address of the person using the task.
61659+ The IP is carried across local TCP and AF_UNIX stream sockets.
61660+ This information can be useful for IDS/IPSes to perform remote response
61661+ to a local attack. The entry is readable by only the owner of the
61662+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61663+ the RBAC system), and thus does not create privacy concerns.
61664+
61665+config GRKERNSEC_RWXMAP_LOG
61666+ bool 'Denied RWX mmap/mprotect logging'
61667+ default y if GRKERNSEC_CONFIG_AUTO
61668+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61669+ help
61670+ If you say Y here, calls to mmap() and mprotect() with explicit
61671+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61672+ denied by the PAX_MPROTECT feature. This feature will also
61673+ log other problematic scenarios that can occur when PAX_MPROTECT
61674+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61675+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61676+ is created.
61677+
61678+endmenu
61679+
61680+menu "Executable Protections"
61681+depends on GRKERNSEC
61682+
61683+config GRKERNSEC_DMESG
61684+ bool "Dmesg(8) restriction"
61685+ default y if GRKERNSEC_CONFIG_AUTO
61686+ help
61687+ If you say Y here, non-root users will not be able to use dmesg(8)
61688+ to view the contents of the kernel's circular log buffer.
61689+ The kernel's log buffer often contains kernel addresses and other
61690+ identifying information useful to an attacker in fingerprinting a
61691+ system for a targeted exploit.
61692+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61693+ created.
61694+
61695+config GRKERNSEC_HARDEN_PTRACE
61696+ bool "Deter ptrace-based process snooping"
61697+ default y if GRKERNSEC_CONFIG_AUTO
61698+ help
61699+ If you say Y here, TTY sniffers and other malicious monitoring
61700+ programs implemented through ptrace will be defeated. If you
61701+ have been using the RBAC system, this option has already been
61702+ enabled for several years for all users, with the ability to make
61703+ fine-grained exceptions.
61704+
61705+ This option only affects the ability of non-root users to ptrace
61706+ processes that are not a descendent of the ptracing process.
61707+ This means that strace ./binary and gdb ./binary will still work,
61708+ but attaching to arbitrary processes will not. If the sysctl
61709+ option is enabled, a sysctl option with name "harden_ptrace" is
61710+ created.
61711+
61712+config GRKERNSEC_PTRACE_READEXEC
61713+ bool "Require read access to ptrace sensitive binaries"
61714+ default y if GRKERNSEC_CONFIG_AUTO
61715+ help
61716+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61717+ binaries. This option is useful in environments that
61718+ remove the read bits (e.g. file mode 4711) from suid binaries to
61719+ prevent infoleaking of their contents. This option adds
61720+ consistency to the use of that file mode, as the binary could normally
61721+ be read out when run without privileges while ptracing.
61722+
61723+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61724+ is created.
61725+
61726+config GRKERNSEC_SETXID
61727+ bool "Enforce consistent multithreaded privileges"
61728+ default y if GRKERNSEC_CONFIG_AUTO
61729+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61730+ help
61731+ If you say Y here, a change from a root uid to a non-root uid
61732+ in a multithreaded application will cause the resulting uids,
61733+ gids, supplementary groups, and capabilities in that thread
61734+ to be propagated to the other threads of the process. In most
61735+ cases this is unnecessary, as glibc will emulate this behavior
61736+ on behalf of the application. Other libcs do not act in the
61737+ same way, allowing the other threads of the process to continue
61738+ running with root privileges. If the sysctl option is enabled,
61739+ a sysctl option with name "consistent_setxid" is created.
61740+
61741+config GRKERNSEC_TPE
61742+ bool "Trusted Path Execution (TPE)"
61743+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61744+ help
61745+ If you say Y here, you will be able to choose a gid to add to the
61746+ supplementary groups of users you want to mark as "untrusted."
61747+ These users will not be able to execute any files that are not in
61748+ root-owned directories writable only by root. If the sysctl option
61749+ is enabled, a sysctl option with name "tpe" is created.
61750+
61751+config GRKERNSEC_TPE_ALL
61752+ bool "Partially restrict all non-root users"
61753+ depends on GRKERNSEC_TPE
61754+ help
61755+ If you say Y here, all non-root users will be covered under
61756+ a weaker TPE restriction. This is separate from, and in addition to,
61757+ the main TPE options that you have selected elsewhere. Thus, if a
61758+ "trusted" GID is chosen, this restriction applies to even that GID.
61759+ Under this restriction, all non-root users will only be allowed to
61760+ execute files in directories they own that are not group or
61761+ world-writable, or in directories owned by root and writable only by
61762+ root. If the sysctl option is enabled, a sysctl option with name
61763+ "tpe_restrict_all" is created.
61764+
61765+config GRKERNSEC_TPE_INVERT
61766+ bool "Invert GID option"
61767+ depends on GRKERNSEC_TPE
61768+ help
61769+ If you say Y here, the group you specify in the TPE configuration will
61770+ decide what group TPE restrictions will be *disabled* for. This
61771+ option is useful if you want TPE restrictions to be applied to most
61772+ users on the system. If the sysctl option is enabled, a sysctl option
61773+ with name "tpe_invert" is created. Unlike other sysctl options, this
61774+ entry will default to on for backward-compatibility.
61775+
61776+config GRKERNSEC_TPE_GID
61777+ int
61778+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61779+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61780+
61781+config GRKERNSEC_TPE_UNTRUSTED_GID
61782+ int "GID for TPE-untrusted users"
61783+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61784+ default 1005
61785+ help
61786+ Setting this GID determines what group TPE restrictions will be
61787+ *enabled* for. If the sysctl option is enabled, a sysctl option
61788+ with name "tpe_gid" is created.
61789+
61790+config GRKERNSEC_TPE_TRUSTED_GID
61791+ int "GID for TPE-trusted users"
61792+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61793+ default 1005
61794+ help
61795+ Setting this GID determines what group TPE restrictions will be
61796+ *disabled* for. If the sysctl option is enabled, a sysctl option
61797+ with name "tpe_gid" is created.
61798+
61799+endmenu
61800+menu "Network Protections"
61801+depends on GRKERNSEC
61802+
61803+config GRKERNSEC_RANDNET
61804+ bool "Larger entropy pools"
61805+ default y if GRKERNSEC_CONFIG_AUTO
61806+ help
61807+ If you say Y here, the entropy pools used for many features of Linux
61808+ and grsecurity will be doubled in size. Since several grsecurity
61809+ features use additional randomness, it is recommended that you say Y
61810+ here. Saying Y here has a similar effect as modifying
61811+ /proc/sys/kernel/random/poolsize.
61812+
61813+config GRKERNSEC_BLACKHOLE
61814+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61815+ default y if GRKERNSEC_CONFIG_AUTO
61816+ depends on NET
61817+ help
61818+ If you say Y here, neither TCP resets nor ICMP
61819+ destination-unreachable packets will be sent in response to packets
61820+ sent to ports for which no associated listening process exists.
61821+ This feature supports both IPV4 and IPV6 and exempts the
61822+ loopback interface from blackholing. Enabling this feature
61823+ makes a host more resilient to DoS attacks and reduces network
61824+ visibility against scanners.
61825+
61826+ The blackhole feature as-implemented is equivalent to the FreeBSD
61827+ blackhole feature, as it prevents RST responses to all packets, not
61828+ just SYNs. Under most application behavior this causes no
61829+ problems, but applications (like haproxy) may not close certain
61830+ connections in a way that cleanly terminates them on the remote
61831+ end, leaving the remote host in LAST_ACK state. Because of this
61832+ side-effect and to prevent intentional LAST_ACK DoSes, this
61833+ feature also adds automatic mitigation against such attacks.
61834+ The mitigation drastically reduces the amount of time a socket
61835+ can spend in LAST_ACK state. If you're using haproxy and not
61836+ all servers it connects to have this option enabled, consider
61837+ disabling this feature on the haproxy host.
61838+
61839+ If the sysctl option is enabled, two sysctl options with names
61840+ "ip_blackhole" and "lastack_retries" will be created.
61841+ While "ip_blackhole" takes the standard zero/non-zero on/off
61842+ toggle, "lastack_retries" uses the same kinds of values as
61843+ "tcp_retries1" and "tcp_retries2". The default value of 4
61844+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61845+ state.
61846+
61847+config GRKERNSEC_NO_SIMULT_CONNECT
61848+ bool "Disable TCP Simultaneous Connect"
61849+ default y if GRKERNSEC_CONFIG_AUTO
61850+ depends on NET
61851+ help
61852+ If you say Y here, a feature by Willy Tarreau will be enabled that
61853+ removes a weakness in Linux's strict implementation of TCP that
61854+ allows two clients to connect to each other without either entering
61855+ a listening state. The weakness allows an attacker to easily prevent
61856+ a client from connecting to a known server provided the source port
61857+ for the connection is guessed correctly.
61858+
61859+ As the weakness could be used to prevent an antivirus or IPS from
61860+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61861+ it should be eliminated by enabling this option. Though Linux is
61862+ one of few operating systems supporting simultaneous connect, it
61863+ has no legitimate use in practice and is rarely supported by firewalls.
61864+
61865+config GRKERNSEC_SOCKET
61866+ bool "Socket restrictions"
61867+ depends on NET
61868+ help
61869+ If you say Y here, you will be able to choose from several options.
61870+ If you assign a GID on your system and add it to the supplementary
61871+ groups of users you want to restrict socket access to, this patch
61872+ will perform up to three things, based on the option(s) you choose.
61873+
61874+config GRKERNSEC_SOCKET_ALL
61875+ bool "Deny any sockets to group"
61876+ depends on GRKERNSEC_SOCKET
61877+ help
61878+ If you say Y here, you will be able to choose a GID of whose users will
61879+ be unable to connect to other hosts from your machine or run server
61880+ applications from your machine. If the sysctl option is enabled, a
61881+ sysctl option with name "socket_all" is created.
61882+
61883+config GRKERNSEC_SOCKET_ALL_GID
61884+ int "GID to deny all sockets for"
61885+ depends on GRKERNSEC_SOCKET_ALL
61886+ default 1004
61887+ help
61888+ Here you can choose the GID to disable socket access for. Remember to
61889+ add the users you want socket access disabled for to the GID
61890+ specified here. If the sysctl option is enabled, a sysctl option
61891+ with name "socket_all_gid" is created.
61892+
61893+config GRKERNSEC_SOCKET_CLIENT
61894+ bool "Deny client sockets to group"
61895+ depends on GRKERNSEC_SOCKET
61896+ help
61897+ If you say Y here, you will be able to choose a GID of whose users will
61898+ be unable to connect to other hosts from your machine, but will be
61899+ able to run servers. If this option is enabled, all users in the group
61900+ you specify will have to use passive mode when initiating ftp transfers
61901+ from the shell on your machine. If the sysctl option is enabled, a
61902+ sysctl option with name "socket_client" is created.
61903+
61904+config GRKERNSEC_SOCKET_CLIENT_GID
61905+ int "GID to deny client sockets for"
61906+ depends on GRKERNSEC_SOCKET_CLIENT
61907+ default 1003
61908+ help
61909+ Here you can choose the GID to disable client socket access for.
61910+ Remember to add the users you want client socket access disabled for to
61911+ the GID specified here. If the sysctl option is enabled, a sysctl
61912+ option with name "socket_client_gid" is created.
61913+
61914+config GRKERNSEC_SOCKET_SERVER
61915+ bool "Deny server sockets to group"
61916+ depends on GRKERNSEC_SOCKET
61917+ help
61918+ If you say Y here, you will be able to choose a GID of whose users will
61919+ be unable to run server applications from your machine. If the sysctl
61920+ option is enabled, a sysctl option with name "socket_server" is created.
61921+
61922+config GRKERNSEC_SOCKET_SERVER_GID
61923+ int "GID to deny server sockets for"
61924+ depends on GRKERNSEC_SOCKET_SERVER
61925+ default 1002
61926+ help
61927+ Here you can choose the GID to disable server socket access for.
61928+ Remember to add the users you want server socket access disabled for to
61929+ the GID specified here. If the sysctl option is enabled, a sysctl
61930+ option with name "socket_server_gid" is created.
61931+
61932+endmenu
61933+
61934+menu "Physical Protections"
61935+depends on GRKERNSEC
61936+
61937+config GRKERNSEC_DENYUSB
61938+ bool "Deny new USB connections after toggle"
61939+ default y if GRKERNSEC_CONFIG_AUTO
61940+ depends on SYSCTL && USB_SUPPORT
61941+ help
61942+ If you say Y here, a new sysctl option with name "deny_new_usb"
61943+ will be created. Setting its value to 1 will prevent any new
61944+ USB devices from being recognized by the OS. Any attempted USB
61945+ device insertion will be logged. This option is intended to be
61946+ used against custom USB devices designed to exploit vulnerabilities
61947+ in various USB device drivers.
61948+
61949+ For greatest effectiveness, this sysctl should be set after any
61950+ relevant init scripts. This option is safe to enable in distros
61951+ as each user can choose whether or not to toggle the sysctl.
61952+
61953+config GRKERNSEC_DENYUSB_FORCE
61954+ bool "Reject all USB devices not connected at boot"
61955+ select USB
61956+ depends on GRKERNSEC_DENYUSB
61957+ help
61958+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
61959+ that doesn't involve a sysctl entry. This option should only be
61960+ enabled if you're sure you want to deny all new USB connections
61961+ at runtime and don't want to modify init scripts. This should not
61962+ be enabled by distros. It forces the core USB code to be built
61963+ into the kernel image so that all devices connected at boot time
61964+ can be recognized and new USB device connections can be prevented
61965+ prior to init running.
61966+
61967+endmenu
61968+
61969+menu "Sysctl Support"
61970+depends on GRKERNSEC && SYSCTL
61971+
61972+config GRKERNSEC_SYSCTL
61973+ bool "Sysctl support"
61974+ default y if GRKERNSEC_CONFIG_AUTO
61975+ help
61976+ If you say Y here, you will be able to change the options that
61977+ grsecurity runs with at bootup, without having to recompile your
61978+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
61979+ to enable (1) or disable (0) various features. All the sysctl entries
61980+ are mutable until the "grsec_lock" entry is set to a non-zero value.
61981+ All features enabled in the kernel configuration are disabled at boot
61982+ if you do not say Y to the "Turn on features by default" option.
61983+ All options should be set at startup, and the grsec_lock entry should
61984+ be set to a non-zero value after all the options are set.
61985+ *THIS IS EXTREMELY IMPORTANT*
61986+
61987+config GRKERNSEC_SYSCTL_DISTRO
61988+ bool "Extra sysctl support for distro makers (READ HELP)"
61989+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
61990+ help
61991+ If you say Y here, additional sysctl options will be created
61992+ for features that affect processes running as root. Therefore,
61993+ it is critical when using this option that the grsec_lock entry be
61994+ enabled after boot. Only distros with prebuilt kernel packages
61995+ with this option enabled that can ensure grsec_lock is enabled
61996+ after boot should use this option.
61997+ *Failure to set grsec_lock after boot makes all grsec features
61998+ this option covers useless*
61999+
62000+ Currently this option creates the following sysctl entries:
62001+ "Disable Privileged I/O": "disable_priv_io"
62002+
62003+config GRKERNSEC_SYSCTL_ON
62004+ bool "Turn on features by default"
62005+ default y if GRKERNSEC_CONFIG_AUTO
62006+ depends on GRKERNSEC_SYSCTL
62007+ help
62008+ If you say Y here, instead of having all features enabled in the
62009+ kernel configuration disabled at boot time, the features will be
62010+ enabled at boot time. It is recommended you say Y here unless
62011+ there is some reason you would want all sysctl-tunable features to
62012+ be disabled by default. As mentioned elsewhere, it is important
62013+ to enable the grsec_lock entry once you have finished modifying
62014+ the sysctl entries.
62015+
62016+endmenu
62017+menu "Logging Options"
62018+depends on GRKERNSEC
62019+
62020+config GRKERNSEC_FLOODTIME
62021+ int "Seconds in between log messages (minimum)"
62022+ default 10
62023+ help
62024+ This option allows you to enforce the number of seconds between
62025+ grsecurity log messages. The default should be suitable for most
62026+ people, however, if you choose to change it, choose a value small enough
62027+ to allow informative logs to be produced, but large enough to
62028+ prevent flooding.
62029+
62030+config GRKERNSEC_FLOODBURST
62031+ int "Number of messages in a burst (maximum)"
62032+ default 6
62033+ help
62034+ This option allows you to choose the maximum number of messages allowed
62035+ within the flood time interval you chose in a separate option. The
62036+ default should be suitable for most people, however if you find that
62037+ many of your logs are being interpreted as flooding, you may want to
62038+ raise this value.
62039+
62040+endmenu
62041diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62042new file mode 100644
62043index 0000000..b0b77d5
62044--- /dev/null
62045+++ b/grsecurity/Makefile
62046@@ -0,0 +1,43 @@
62047+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62048+# during 2001-2009 it has been completely redesigned by Brad Spengler
62049+# into an RBAC system
62050+#
62051+# All code in this directory and various hooks inserted throughout the kernel
62052+# are copyright Brad Spengler - Open Source Security, Inc., and released
62053+# under the GPL v2 or higher
62054+
62055+KBUILD_CFLAGS += -Werror
62056+
62057+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62058+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62059+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62060+ grsec_usb.o
62061+
62062+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62063+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62064+ gracl_learn.o grsec_log.o
62065+ifdef CONFIG_COMPAT
62066+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62067+endif
62068+
62069+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62070+
62071+ifdef CONFIG_NET
62072+obj-y += grsec_sock.o
62073+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62074+endif
62075+
62076+ifndef CONFIG_GRKERNSEC
62077+obj-y += grsec_disabled.o
62078+endif
62079+
62080+ifdef CONFIG_GRKERNSEC_HIDESYM
62081+extra-y := grsec_hidesym.o
62082+$(obj)/grsec_hidesym.o:
62083+ @-chmod -f 500 /boot
62084+ @-chmod -f 500 /lib/modules
62085+ @-chmod -f 500 /lib64/modules
62086+ @-chmod -f 500 /lib32/modules
62087+ @-chmod -f 700 .
62088+ @echo ' grsec: protected kernel image paths'
62089+endif
62090diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62091new file mode 100644
62092index 0000000..c0793fd
62093--- /dev/null
62094+++ b/grsecurity/gracl.c
62095@@ -0,0 +1,4178 @@
62096+#include <linux/kernel.h>
62097+#include <linux/module.h>
62098+#include <linux/sched.h>
62099+#include <linux/mm.h>
62100+#include <linux/file.h>
62101+#include <linux/fs.h>
62102+#include <linux/namei.h>
62103+#include <linux/mount.h>
62104+#include <linux/tty.h>
62105+#include <linux/proc_fs.h>
62106+#include <linux/lglock.h>
62107+#include <linux/slab.h>
62108+#include <linux/vmalloc.h>
62109+#include <linux/types.h>
62110+#include <linux/sysctl.h>
62111+#include <linux/netdevice.h>
62112+#include <linux/ptrace.h>
62113+#include <linux/gracl.h>
62114+#include <linux/gralloc.h>
62115+#include <linux/security.h>
62116+#include <linux/grinternal.h>
62117+#include <linux/pid_namespace.h>
62118+#include <linux/stop_machine.h>
62119+#include <linux/fdtable.h>
62120+#include <linux/percpu.h>
62121+#include <linux/lglock.h>
62122+#include <linux/hugetlb.h>
62123+#include <linux/posix-timers.h>
62124+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62125+#include <linux/magic.h>
62126+#include <linux/pagemap.h>
62127+#include "../fs/btrfs/async-thread.h"
62128+#include "../fs/btrfs/ctree.h"
62129+#include "../fs/btrfs/btrfs_inode.h"
62130+#endif
62131+#include "../fs/mount.h"
62132+
62133+#include <asm/uaccess.h>
62134+#include <asm/errno.h>
62135+#include <asm/mman.h>
62136+
62137+extern struct lglock vfsmount_lock;
62138+
62139+static struct acl_role_db acl_role_set;
62140+static struct name_db name_set;
62141+static struct inodev_db inodev_set;
62142+
62143+/* for keeping track of userspace pointers used for subjects, so we
62144+ can share references in the kernel as well
62145+*/
62146+
62147+static struct path real_root;
62148+
62149+static struct acl_subj_map_db subj_map_set;
62150+
62151+static struct acl_role_label *default_role;
62152+
62153+static struct acl_role_label *role_list;
62154+
62155+static u16 acl_sp_role_value;
62156+
62157+extern char *gr_shared_page[4];
62158+static DEFINE_MUTEX(gr_dev_mutex);
62159+DEFINE_RWLOCK(gr_inode_lock);
62160+
62161+struct gr_arg *gr_usermode;
62162+
62163+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62164+
62165+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62166+extern void gr_clear_learn_entries(void);
62167+
62168+unsigned char *gr_system_salt;
62169+unsigned char *gr_system_sum;
62170+
62171+static struct sprole_pw **acl_special_roles = NULL;
62172+static __u16 num_sprole_pws = 0;
62173+
62174+static struct acl_role_label *kernel_role = NULL;
62175+
62176+static unsigned int gr_auth_attempts = 0;
62177+static unsigned long gr_auth_expires = 0UL;
62178+
62179+#ifdef CONFIG_NET
62180+extern struct vfsmount *sock_mnt;
62181+#endif
62182+
62183+extern struct vfsmount *pipe_mnt;
62184+extern struct vfsmount *shm_mnt;
62185+
62186+#ifdef CONFIG_HUGETLBFS
62187+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62188+#endif
62189+
62190+static struct acl_object_label *fakefs_obj_rw;
62191+static struct acl_object_label *fakefs_obj_rwx;
62192+
62193+extern int gr_init_uidset(void);
62194+extern void gr_free_uidset(void);
62195+extern void gr_remove_uid(uid_t uid);
62196+extern int gr_find_uid(uid_t uid);
62197+
62198+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62199+{
62200+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62201+ return -EFAULT;
62202+
62203+ return 0;
62204+}
62205+
62206+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62207+{
62208+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62209+ return -EFAULT;
62210+
62211+ return 0;
62212+}
62213+
62214+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62215+{
62216+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62217+ return -EFAULT;
62218+
62219+ return 0;
62220+}
62221+
62222+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62223+{
62224+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62225+ return -EFAULT;
62226+
62227+ return 0;
62228+}
62229+
62230+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62231+{
62232+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62233+ return -EFAULT;
62234+
62235+ return 0;
62236+}
62237+
62238+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62239+{
62240+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62241+ return -EFAULT;
62242+
62243+ return 0;
62244+}
62245+
62246+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62247+{
62248+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62249+ return -EFAULT;
62250+
62251+ return 0;
62252+}
62253+
62254+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62255+{
62256+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62257+ return -EFAULT;
62258+
62259+ return 0;
62260+}
62261+
62262+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62263+{
62264+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62265+ return -EFAULT;
62266+
62267+ return 0;
62268+}
62269+
62270+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62271+{
62272+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62273+ return -EFAULT;
62274+
62275+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62276+ return -EINVAL;
62277+
62278+ return 0;
62279+}
62280+
62281+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62282+{
62283+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62284+ return -EFAULT;
62285+
62286+ return 0;
62287+}
62288+
62289+static size_t get_gr_arg_wrapper_size_normal(void)
62290+{
62291+ return sizeof(struct gr_arg_wrapper);
62292+}
62293+
62294+#ifdef CONFIG_COMPAT
62295+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62296+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62297+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62298+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62299+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62300+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62301+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62302+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62303+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62304+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62305+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62306+extern size_t get_gr_arg_wrapper_size_compat(void);
62307+
62308+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62309+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62310+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62311+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62312+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62313+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62314+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62315+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62316+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62317+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62318+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62319+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62320+
62321+#else
62322+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62323+#define copy_gr_arg copy_gr_arg_normal
62324+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62325+#define copy_acl_object_label copy_acl_object_label_normal
62326+#define copy_acl_subject_label copy_acl_subject_label_normal
62327+#define copy_acl_role_label copy_acl_role_label_normal
62328+#define copy_acl_ip_label copy_acl_ip_label_normal
62329+#define copy_pointer_from_array copy_pointer_from_array_normal
62330+#define copy_sprole_pw copy_sprole_pw_normal
62331+#define copy_role_transition copy_role_transition_normal
62332+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62333+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62334+#endif
62335+
62336+__inline__ int
62337+gr_acl_is_enabled(void)
62338+{
62339+ return (gr_status & GR_READY);
62340+}
62341+
62342+static inline dev_t __get_dev(const struct dentry *dentry)
62343+{
62344+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62345+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62346+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62347+ else
62348+#endif
62349+ return dentry->d_sb->s_dev;
62350+}
62351+
62352+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62353+{
62354+ return __get_dev(dentry);
62355+}
62356+
62357+static char gr_task_roletype_to_char(struct task_struct *task)
62358+{
62359+ switch (task->role->roletype &
62360+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62361+ GR_ROLE_SPECIAL)) {
62362+ case GR_ROLE_DEFAULT:
62363+ return 'D';
62364+ case GR_ROLE_USER:
62365+ return 'U';
62366+ case GR_ROLE_GROUP:
62367+ return 'G';
62368+ case GR_ROLE_SPECIAL:
62369+ return 'S';
62370+ }
62371+
62372+ return 'X';
62373+}
62374+
62375+char gr_roletype_to_char(void)
62376+{
62377+ return gr_task_roletype_to_char(current);
62378+}
62379+
62380+__inline__ int
62381+gr_acl_tpe_check(void)
62382+{
62383+ if (unlikely(!(gr_status & GR_READY)))
62384+ return 0;
62385+ if (current->role->roletype & GR_ROLE_TPE)
62386+ return 1;
62387+ else
62388+ return 0;
62389+}
62390+
62391+int
62392+gr_handle_rawio(const struct inode *inode)
62393+{
62394+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62395+ if (inode && S_ISBLK(inode->i_mode) &&
62396+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62397+ !capable(CAP_SYS_RAWIO))
62398+ return 1;
62399+#endif
62400+ return 0;
62401+}
62402+
62403+static int
62404+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62405+{
62406+ if (likely(lena != lenb))
62407+ return 0;
62408+
62409+ return !memcmp(a, b, lena);
62410+}
62411+
62412+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62413+{
62414+ *buflen -= namelen;
62415+ if (*buflen < 0)
62416+ return -ENAMETOOLONG;
62417+ *buffer -= namelen;
62418+ memcpy(*buffer, str, namelen);
62419+ return 0;
62420+}
62421+
62422+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62423+{
62424+ return prepend(buffer, buflen, name->name, name->len);
62425+}
62426+
62427+static int prepend_path(const struct path *path, struct path *root,
62428+ char **buffer, int *buflen)
62429+{
62430+ struct dentry *dentry = path->dentry;
62431+ struct vfsmount *vfsmnt = path->mnt;
62432+ struct mount *mnt = real_mount(vfsmnt);
62433+ bool slash = false;
62434+ int error = 0;
62435+
62436+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62437+ struct dentry * parent;
62438+
62439+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62440+ /* Global root? */
62441+ if (!mnt_has_parent(mnt)) {
62442+ goto out;
62443+ }
62444+ dentry = mnt->mnt_mountpoint;
62445+ mnt = mnt->mnt_parent;
62446+ vfsmnt = &mnt->mnt;
62447+ continue;
62448+ }
62449+ parent = dentry->d_parent;
62450+ prefetch(parent);
62451+ spin_lock(&dentry->d_lock);
62452+ error = prepend_name(buffer, buflen, &dentry->d_name);
62453+ spin_unlock(&dentry->d_lock);
62454+ if (!error)
62455+ error = prepend(buffer, buflen, "/", 1);
62456+ if (error)
62457+ break;
62458+
62459+ slash = true;
62460+ dentry = parent;
62461+ }
62462+
62463+out:
62464+ if (!error && !slash)
62465+ error = prepend(buffer, buflen, "/", 1);
62466+
62467+ return error;
62468+}
62469+
62470+/* this must be called with vfsmount_lock and rename_lock held */
62471+
62472+static char *__our_d_path(const struct path *path, struct path *root,
62473+ char *buf, int buflen)
62474+{
62475+ char *res = buf + buflen;
62476+ int error;
62477+
62478+ prepend(&res, &buflen, "\0", 1);
62479+ error = prepend_path(path, root, &res, &buflen);
62480+ if (error)
62481+ return ERR_PTR(error);
62482+
62483+ return res;
62484+}
62485+
62486+static char *
62487+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62488+{
62489+ char *retval;
62490+
62491+ retval = __our_d_path(path, root, buf, buflen);
62492+ if (unlikely(IS_ERR(retval)))
62493+ retval = strcpy(buf, "<path too long>");
62494+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62495+ retval[1] = '\0';
62496+
62497+ return retval;
62498+}
62499+
62500+static char *
62501+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62502+ char *buf, int buflen)
62503+{
62504+ struct path path;
62505+ char *res;
62506+
62507+ path.dentry = (struct dentry *)dentry;
62508+ path.mnt = (struct vfsmount *)vfsmnt;
62509+
62510+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62511+ by the RBAC system */
62512+ res = gen_full_path(&path, &real_root, buf, buflen);
62513+
62514+ return res;
62515+}
62516+
62517+static char *
62518+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62519+ char *buf, int buflen)
62520+{
62521+ char *res;
62522+ struct path path;
62523+ struct path root;
62524+ struct task_struct *reaper = init_pid_ns.child_reaper;
62525+
62526+ path.dentry = (struct dentry *)dentry;
62527+ path.mnt = (struct vfsmount *)vfsmnt;
62528+
62529+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62530+ get_fs_root(reaper->fs, &root);
62531+
62532+ br_read_lock(&vfsmount_lock);
62533+ write_seqlock(&rename_lock);
62534+ res = gen_full_path(&path, &root, buf, buflen);
62535+ write_sequnlock(&rename_lock);
62536+ br_read_unlock(&vfsmount_lock);
62537+
62538+ path_put(&root);
62539+ return res;
62540+}
62541+
62542+static char *
62543+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62544+{
62545+ char *ret;
62546+ br_read_lock(&vfsmount_lock);
62547+ write_seqlock(&rename_lock);
62548+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62549+ PAGE_SIZE);
62550+ write_sequnlock(&rename_lock);
62551+ br_read_unlock(&vfsmount_lock);
62552+ return ret;
62553+}
62554+
62555+static char *
62556+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62557+{
62558+ char *ret;
62559+ char *buf;
62560+ int buflen;
62561+
62562+ br_read_lock(&vfsmount_lock);
62563+ write_seqlock(&rename_lock);
62564+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62565+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62566+ buflen = (int)(ret - buf);
62567+ if (buflen >= 5)
62568+ prepend(&ret, &buflen, "/proc", 5);
62569+ else
62570+ ret = strcpy(buf, "<path too long>");
62571+ write_sequnlock(&rename_lock);
62572+ br_read_unlock(&vfsmount_lock);
62573+ return ret;
62574+}
62575+
62576+char *
62577+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62578+{
62579+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62580+ PAGE_SIZE);
62581+}
62582+
62583+char *
62584+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62585+{
62586+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62587+ PAGE_SIZE);
62588+}
62589+
62590+char *
62591+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62592+{
62593+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62594+ PAGE_SIZE);
62595+}
62596+
62597+char *
62598+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62599+{
62600+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62601+ PAGE_SIZE);
62602+}
62603+
62604+char *
62605+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62606+{
62607+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62608+ PAGE_SIZE);
62609+}
62610+
62611+__inline__ __u32
62612+to_gr_audit(const __u32 reqmode)
62613+{
62614+ /* masks off auditable permission flags, then shifts them to create
62615+ auditing flags, and adds the special case of append auditing if
62616+ we're requesting write */
62617+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62618+}
62619+
62620+struct acl_subject_label *
62621+lookup_subject_map(const struct acl_subject_label *userp)
62622+{
62623+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62624+ struct subject_map *match;
62625+
62626+ match = subj_map_set.s_hash[index];
62627+
62628+ while (match && match->user != userp)
62629+ match = match->next;
62630+
62631+ if (match != NULL)
62632+ return match->kernel;
62633+ else
62634+ return NULL;
62635+}
62636+
62637+static void
62638+insert_subj_map_entry(struct subject_map *subjmap)
62639+{
62640+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62641+ struct subject_map **curr;
62642+
62643+ subjmap->prev = NULL;
62644+
62645+ curr = &subj_map_set.s_hash[index];
62646+ if (*curr != NULL)
62647+ (*curr)->prev = subjmap;
62648+
62649+ subjmap->next = *curr;
62650+ *curr = subjmap;
62651+
62652+ return;
62653+}
62654+
62655+static struct acl_role_label *
62656+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62657+ const gid_t gid)
62658+{
62659+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62660+ struct acl_role_label *match;
62661+ struct role_allowed_ip *ipp;
62662+ unsigned int x;
62663+ u32 curr_ip = task->signal->curr_ip;
62664+
62665+ task->signal->saved_ip = curr_ip;
62666+
62667+ match = acl_role_set.r_hash[index];
62668+
62669+ while (match) {
62670+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62671+ for (x = 0; x < match->domain_child_num; x++) {
62672+ if (match->domain_children[x] == uid)
62673+ goto found;
62674+ }
62675+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62676+ break;
62677+ match = match->next;
62678+ }
62679+found:
62680+ if (match == NULL) {
62681+ try_group:
62682+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62683+ match = acl_role_set.r_hash[index];
62684+
62685+ while (match) {
62686+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62687+ for (x = 0; x < match->domain_child_num; x++) {
62688+ if (match->domain_children[x] == gid)
62689+ goto found2;
62690+ }
62691+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62692+ break;
62693+ match = match->next;
62694+ }
62695+found2:
62696+ if (match == NULL)
62697+ match = default_role;
62698+ if (match->allowed_ips == NULL)
62699+ return match;
62700+ else {
62701+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62702+ if (likely
62703+ ((ntohl(curr_ip) & ipp->netmask) ==
62704+ (ntohl(ipp->addr) & ipp->netmask)))
62705+ return match;
62706+ }
62707+ match = default_role;
62708+ }
62709+ } else if (match->allowed_ips == NULL) {
62710+ return match;
62711+ } else {
62712+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62713+ if (likely
62714+ ((ntohl(curr_ip) & ipp->netmask) ==
62715+ (ntohl(ipp->addr) & ipp->netmask)))
62716+ return match;
62717+ }
62718+ goto try_group;
62719+ }
62720+
62721+ return match;
62722+}
62723+
62724+struct acl_subject_label *
62725+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62726+ const struct acl_role_label *role)
62727+{
62728+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62729+ struct acl_subject_label *match;
62730+
62731+ match = role->subj_hash[index];
62732+
62733+ while (match && (match->inode != ino || match->device != dev ||
62734+ (match->mode & GR_DELETED))) {
62735+ match = match->next;
62736+ }
62737+
62738+ if (match && !(match->mode & GR_DELETED))
62739+ return match;
62740+ else
62741+ return NULL;
62742+}
62743+
62744+struct acl_subject_label *
62745+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62746+ const struct acl_role_label *role)
62747+{
62748+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62749+ struct acl_subject_label *match;
62750+
62751+ match = role->subj_hash[index];
62752+
62753+ while (match && (match->inode != ino || match->device != dev ||
62754+ !(match->mode & GR_DELETED))) {
62755+ match = match->next;
62756+ }
62757+
62758+ if (match && (match->mode & GR_DELETED))
62759+ return match;
62760+ else
62761+ return NULL;
62762+}
62763+
62764+static struct acl_object_label *
62765+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62766+ const struct acl_subject_label *subj)
62767+{
62768+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62769+ struct acl_object_label *match;
62770+
62771+ match = subj->obj_hash[index];
62772+
62773+ while (match && (match->inode != ino || match->device != dev ||
62774+ (match->mode & GR_DELETED))) {
62775+ match = match->next;
62776+ }
62777+
62778+ if (match && !(match->mode & GR_DELETED))
62779+ return match;
62780+ else
62781+ return NULL;
62782+}
62783+
62784+static struct acl_object_label *
62785+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62786+ const struct acl_subject_label *subj)
62787+{
62788+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62789+ struct acl_object_label *match;
62790+
62791+ match = subj->obj_hash[index];
62792+
62793+ while (match && (match->inode != ino || match->device != dev ||
62794+ !(match->mode & GR_DELETED))) {
62795+ match = match->next;
62796+ }
62797+
62798+ if (match && (match->mode & GR_DELETED))
62799+ return match;
62800+
62801+ match = subj->obj_hash[index];
62802+
62803+ while (match && (match->inode != ino || match->device != dev ||
62804+ (match->mode & GR_DELETED))) {
62805+ match = match->next;
62806+ }
62807+
62808+ if (match && !(match->mode & GR_DELETED))
62809+ return match;
62810+ else
62811+ return NULL;
62812+}
62813+
62814+static struct name_entry *
62815+lookup_name_entry(const char *name)
62816+{
62817+ unsigned int len = strlen(name);
62818+ unsigned int key = full_name_hash(name, len);
62819+ unsigned int index = key % name_set.n_size;
62820+ struct name_entry *match;
62821+
62822+ match = name_set.n_hash[index];
62823+
62824+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62825+ match = match->next;
62826+
62827+ return match;
62828+}
62829+
62830+static struct name_entry *
62831+lookup_name_entry_create(const char *name)
62832+{
62833+ unsigned int len = strlen(name);
62834+ unsigned int key = full_name_hash(name, len);
62835+ unsigned int index = key % name_set.n_size;
62836+ struct name_entry *match;
62837+
62838+ match = name_set.n_hash[index];
62839+
62840+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62841+ !match->deleted))
62842+ match = match->next;
62843+
62844+ if (match && match->deleted)
62845+ return match;
62846+
62847+ match = name_set.n_hash[index];
62848+
62849+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62850+ match->deleted))
62851+ match = match->next;
62852+
62853+ if (match && !match->deleted)
62854+ return match;
62855+ else
62856+ return NULL;
62857+}
62858+
62859+static struct inodev_entry *
62860+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62861+{
62862+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62863+ struct inodev_entry *match;
62864+
62865+ match = inodev_set.i_hash[index];
62866+
62867+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62868+ match = match->next;
62869+
62870+ return match;
62871+}
62872+
62873+static void
62874+insert_inodev_entry(struct inodev_entry *entry)
62875+{
62876+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62877+ inodev_set.i_size);
62878+ struct inodev_entry **curr;
62879+
62880+ entry->prev = NULL;
62881+
62882+ curr = &inodev_set.i_hash[index];
62883+ if (*curr != NULL)
62884+ (*curr)->prev = entry;
62885+
62886+ entry->next = *curr;
62887+ *curr = entry;
62888+
62889+ return;
62890+}
62891+
62892+static void
62893+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62894+{
62895+ unsigned int index =
62896+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62897+ struct acl_role_label **curr;
62898+ struct acl_role_label *tmp, *tmp2;
62899+
62900+ curr = &acl_role_set.r_hash[index];
62901+
62902+ /* simple case, slot is empty, just set it to our role */
62903+ if (*curr == NULL) {
62904+ *curr = role;
62905+ } else {
62906+ /* example:
62907+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62908+ 2 -> 3
62909+ */
62910+ /* first check to see if we can already be reached via this slot */
62911+ tmp = *curr;
62912+ while (tmp && tmp != role)
62913+ tmp = tmp->next;
62914+ if (tmp == role) {
62915+ /* we don't need to add ourselves to this slot's chain */
62916+ return;
62917+ }
62918+ /* we need to add ourselves to this chain, two cases */
62919+ if (role->next == NULL) {
62920+ /* simple case, append the current chain to our role */
62921+ role->next = *curr;
62922+ *curr = role;
62923+ } else {
62924+ /* 1 -> 2 -> 3 -> 4
62925+ 2 -> 3 -> 4
62926+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62927+ */
62928+ /* trickier case: walk our role's chain until we find
62929+ the role for the start of the current slot's chain */
62930+ tmp = role;
62931+ tmp2 = *curr;
62932+ while (tmp->next && tmp->next != tmp2)
62933+ tmp = tmp->next;
62934+ if (tmp->next == tmp2) {
62935+ /* from example above, we found 3, so just
62936+ replace this slot's chain with ours */
62937+ *curr = role;
62938+ } else {
62939+ /* we didn't find a subset of our role's chain
62940+ in the current slot's chain, so append their
62941+ chain to ours, and set us as the first role in
62942+ the slot's chain
62943+
62944+ we could fold this case with the case above,
62945+ but making it explicit for clarity
62946+ */
62947+ tmp->next = tmp2;
62948+ *curr = role;
62949+ }
62950+ }
62951+ }
62952+
62953+ return;
62954+}
62955+
62956+static void
62957+insert_acl_role_label(struct acl_role_label *role)
62958+{
62959+ int i;
62960+
62961+ if (role_list == NULL) {
62962+ role_list = role;
62963+ role->prev = NULL;
62964+ } else {
62965+ role->prev = role_list;
62966+ role_list = role;
62967+ }
62968+
62969+ /* used for hash chains */
62970+ role->next = NULL;
62971+
62972+ if (role->roletype & GR_ROLE_DOMAIN) {
62973+ for (i = 0; i < role->domain_child_num; i++)
62974+ __insert_acl_role_label(role, role->domain_children[i]);
62975+ } else
62976+ __insert_acl_role_label(role, role->uidgid);
62977+}
62978+
62979+static int
62980+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
62981+{
62982+ struct name_entry **curr, *nentry;
62983+ struct inodev_entry *ientry;
62984+ unsigned int len = strlen(name);
62985+ unsigned int key = full_name_hash(name, len);
62986+ unsigned int index = key % name_set.n_size;
62987+
62988+ curr = &name_set.n_hash[index];
62989+
62990+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
62991+ curr = &((*curr)->next);
62992+
62993+ if (*curr != NULL)
62994+ return 1;
62995+
62996+ nentry = acl_alloc(sizeof (struct name_entry));
62997+ if (nentry == NULL)
62998+ return 0;
62999+ ientry = acl_alloc(sizeof (struct inodev_entry));
63000+ if (ientry == NULL)
63001+ return 0;
63002+ ientry->nentry = nentry;
63003+
63004+ nentry->key = key;
63005+ nentry->name = name;
63006+ nentry->inode = inode;
63007+ nentry->device = device;
63008+ nentry->len = len;
63009+ nentry->deleted = deleted;
63010+
63011+ nentry->prev = NULL;
63012+ curr = &name_set.n_hash[index];
63013+ if (*curr != NULL)
63014+ (*curr)->prev = nentry;
63015+ nentry->next = *curr;
63016+ *curr = nentry;
63017+
63018+ /* insert us into the table searchable by inode/dev */
63019+ insert_inodev_entry(ientry);
63020+
63021+ return 1;
63022+}
63023+
63024+static void
63025+insert_acl_obj_label(struct acl_object_label *obj,
63026+ struct acl_subject_label *subj)
63027+{
63028+ unsigned int index =
63029+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63030+ struct acl_object_label **curr;
63031+
63032+
63033+ obj->prev = NULL;
63034+
63035+ curr = &subj->obj_hash[index];
63036+ if (*curr != NULL)
63037+ (*curr)->prev = obj;
63038+
63039+ obj->next = *curr;
63040+ *curr = obj;
63041+
63042+ return;
63043+}
63044+
63045+static void
63046+insert_acl_subj_label(struct acl_subject_label *obj,
63047+ struct acl_role_label *role)
63048+{
63049+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63050+ struct acl_subject_label **curr;
63051+
63052+ obj->prev = NULL;
63053+
63054+ curr = &role->subj_hash[index];
63055+ if (*curr != NULL)
63056+ (*curr)->prev = obj;
63057+
63058+ obj->next = *curr;
63059+ *curr = obj;
63060+
63061+ return;
63062+}
63063+
63064+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63065+
63066+static void *
63067+create_table(__u32 * len, int elementsize)
63068+{
63069+ unsigned int table_sizes[] = {
63070+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63071+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63072+ 4194301, 8388593, 16777213, 33554393, 67108859
63073+ };
63074+ void *newtable = NULL;
63075+ unsigned int pwr = 0;
63076+
63077+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63078+ table_sizes[pwr] <= *len)
63079+ pwr++;
63080+
63081+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63082+ return newtable;
63083+
63084+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63085+ newtable =
63086+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63087+ else
63088+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63089+
63090+ *len = table_sizes[pwr];
63091+
63092+ return newtable;
63093+}
63094+
63095+static int
63096+init_variables(const struct gr_arg *arg)
63097+{
63098+ struct task_struct *reaper = init_pid_ns.child_reaper;
63099+ unsigned int stacksize;
63100+
63101+ subj_map_set.s_size = arg->role_db.num_subjects;
63102+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63103+ name_set.n_size = arg->role_db.num_objects;
63104+ inodev_set.i_size = arg->role_db.num_objects;
63105+
63106+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63107+ !name_set.n_size || !inodev_set.i_size)
63108+ return 1;
63109+
63110+ if (!gr_init_uidset())
63111+ return 1;
63112+
63113+ /* set up the stack that holds allocation info */
63114+
63115+ stacksize = arg->role_db.num_pointers + 5;
63116+
63117+ if (!acl_alloc_stack_init(stacksize))
63118+ return 1;
63119+
63120+ /* grab reference for the real root dentry and vfsmount */
63121+ get_fs_root(reaper->fs, &real_root);
63122+
63123+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63124+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63125+#endif
63126+
63127+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63128+ if (fakefs_obj_rw == NULL)
63129+ return 1;
63130+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63131+
63132+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63133+ if (fakefs_obj_rwx == NULL)
63134+ return 1;
63135+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63136+
63137+ subj_map_set.s_hash =
63138+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63139+ acl_role_set.r_hash =
63140+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63141+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63142+ inodev_set.i_hash =
63143+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63144+
63145+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63146+ !name_set.n_hash || !inodev_set.i_hash)
63147+ return 1;
63148+
63149+ memset(subj_map_set.s_hash, 0,
63150+ sizeof(struct subject_map *) * subj_map_set.s_size);
63151+ memset(acl_role_set.r_hash, 0,
63152+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63153+ memset(name_set.n_hash, 0,
63154+ sizeof (struct name_entry *) * name_set.n_size);
63155+ memset(inodev_set.i_hash, 0,
63156+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63157+
63158+ return 0;
63159+}
63160+
63161+/* free information not needed after startup
63162+ currently contains user->kernel pointer mappings for subjects
63163+*/
63164+
63165+static void
63166+free_init_variables(void)
63167+{
63168+ __u32 i;
63169+
63170+ if (subj_map_set.s_hash) {
63171+ for (i = 0; i < subj_map_set.s_size; i++) {
63172+ if (subj_map_set.s_hash[i]) {
63173+ kfree(subj_map_set.s_hash[i]);
63174+ subj_map_set.s_hash[i] = NULL;
63175+ }
63176+ }
63177+
63178+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63179+ PAGE_SIZE)
63180+ kfree(subj_map_set.s_hash);
63181+ else
63182+ vfree(subj_map_set.s_hash);
63183+ }
63184+
63185+ return;
63186+}
63187+
63188+static void
63189+free_variables(void)
63190+{
63191+ struct acl_subject_label *s;
63192+ struct acl_role_label *r;
63193+ struct task_struct *task, *task2;
63194+ unsigned int x;
63195+
63196+ gr_clear_learn_entries();
63197+
63198+ read_lock(&tasklist_lock);
63199+ do_each_thread(task2, task) {
63200+ task->acl_sp_role = 0;
63201+ task->acl_role_id = 0;
63202+ task->acl = NULL;
63203+ task->role = NULL;
63204+ } while_each_thread(task2, task);
63205+ read_unlock(&tasklist_lock);
63206+
63207+ /* release the reference to the real root dentry and vfsmount */
63208+ path_put(&real_root);
63209+ memset(&real_root, 0, sizeof(real_root));
63210+
63211+ /* free all object hash tables */
63212+
63213+ FOR_EACH_ROLE_START(r)
63214+ if (r->subj_hash == NULL)
63215+ goto next_role;
63216+ FOR_EACH_SUBJECT_START(r, s, x)
63217+ if (s->obj_hash == NULL)
63218+ break;
63219+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63220+ kfree(s->obj_hash);
63221+ else
63222+ vfree(s->obj_hash);
63223+ FOR_EACH_SUBJECT_END(s, x)
63224+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63225+ if (s->obj_hash == NULL)
63226+ break;
63227+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63228+ kfree(s->obj_hash);
63229+ else
63230+ vfree(s->obj_hash);
63231+ FOR_EACH_NESTED_SUBJECT_END(s)
63232+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63233+ kfree(r->subj_hash);
63234+ else
63235+ vfree(r->subj_hash);
63236+ r->subj_hash = NULL;
63237+next_role:
63238+ FOR_EACH_ROLE_END(r)
63239+
63240+ acl_free_all();
63241+
63242+ if (acl_role_set.r_hash) {
63243+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63244+ PAGE_SIZE)
63245+ kfree(acl_role_set.r_hash);
63246+ else
63247+ vfree(acl_role_set.r_hash);
63248+ }
63249+ if (name_set.n_hash) {
63250+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63251+ PAGE_SIZE)
63252+ kfree(name_set.n_hash);
63253+ else
63254+ vfree(name_set.n_hash);
63255+ }
63256+
63257+ if (inodev_set.i_hash) {
63258+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63259+ PAGE_SIZE)
63260+ kfree(inodev_set.i_hash);
63261+ else
63262+ vfree(inodev_set.i_hash);
63263+ }
63264+
63265+ gr_free_uidset();
63266+
63267+ memset(&name_set, 0, sizeof (struct name_db));
63268+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63269+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63270+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63271+
63272+ default_role = NULL;
63273+ kernel_role = NULL;
63274+ role_list = NULL;
63275+
63276+ return;
63277+}
63278+
63279+static struct acl_subject_label *
63280+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63281+
63282+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63283+{
63284+ unsigned int len = strnlen_user(*name, maxlen);
63285+ char *tmp;
63286+
63287+ if (!len || len >= maxlen)
63288+ return -EINVAL;
63289+
63290+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63291+ return -ENOMEM;
63292+
63293+ if (copy_from_user(tmp, *name, len))
63294+ return -EFAULT;
63295+
63296+ tmp[len-1] = '\0';
63297+ *name = tmp;
63298+
63299+ return 0;
63300+}
63301+
63302+static int
63303+copy_user_glob(struct acl_object_label *obj)
63304+{
63305+ struct acl_object_label *g_tmp, **guser;
63306+ int error;
63307+
63308+ if (obj->globbed == NULL)
63309+ return 0;
63310+
63311+ guser = &obj->globbed;
63312+ while (*guser) {
63313+ g_tmp = (struct acl_object_label *)
63314+ acl_alloc(sizeof (struct acl_object_label));
63315+ if (g_tmp == NULL)
63316+ return -ENOMEM;
63317+
63318+ if (copy_acl_object_label(g_tmp, *guser))
63319+ return -EFAULT;
63320+
63321+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63322+ if (error)
63323+ return error;
63324+
63325+ *guser = g_tmp;
63326+ guser = &(g_tmp->next);
63327+ }
63328+
63329+ return 0;
63330+}
63331+
63332+static int
63333+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63334+ struct acl_role_label *role)
63335+{
63336+ struct acl_object_label *o_tmp;
63337+ int ret;
63338+
63339+ while (userp) {
63340+ if ((o_tmp = (struct acl_object_label *)
63341+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63342+ return -ENOMEM;
63343+
63344+ if (copy_acl_object_label(o_tmp, userp))
63345+ return -EFAULT;
63346+
63347+ userp = o_tmp->prev;
63348+
63349+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63350+ if (ret)
63351+ return ret;
63352+
63353+ insert_acl_obj_label(o_tmp, subj);
63354+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63355+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63356+ return -ENOMEM;
63357+
63358+ ret = copy_user_glob(o_tmp);
63359+ if (ret)
63360+ return ret;
63361+
63362+ if (o_tmp->nested) {
63363+ int already_copied;
63364+
63365+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63366+ if (IS_ERR(o_tmp->nested))
63367+ return PTR_ERR(o_tmp->nested);
63368+
63369+ /* insert into nested subject list if we haven't copied this one yet
63370+ to prevent duplicate entries */
63371+ if (!already_copied) {
63372+ o_tmp->nested->next = role->hash->first;
63373+ role->hash->first = o_tmp->nested;
63374+ }
63375+ }
63376+ }
63377+
63378+ return 0;
63379+}
63380+
63381+static __u32
63382+count_user_subjs(struct acl_subject_label *userp)
63383+{
63384+ struct acl_subject_label s_tmp;
63385+ __u32 num = 0;
63386+
63387+ while (userp) {
63388+ if (copy_acl_subject_label(&s_tmp, userp))
63389+ break;
63390+
63391+ userp = s_tmp.prev;
63392+ }
63393+
63394+ return num;
63395+}
63396+
63397+static int
63398+copy_user_allowedips(struct acl_role_label *rolep)
63399+{
63400+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63401+
63402+ ruserip = rolep->allowed_ips;
63403+
63404+ while (ruserip) {
63405+ rlast = rtmp;
63406+
63407+ if ((rtmp = (struct role_allowed_ip *)
63408+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63409+ return -ENOMEM;
63410+
63411+ if (copy_role_allowed_ip(rtmp, ruserip))
63412+ return -EFAULT;
63413+
63414+ ruserip = rtmp->prev;
63415+
63416+ if (!rlast) {
63417+ rtmp->prev = NULL;
63418+ rolep->allowed_ips = rtmp;
63419+ } else {
63420+ rlast->next = rtmp;
63421+ rtmp->prev = rlast;
63422+ }
63423+
63424+ if (!ruserip)
63425+ rtmp->next = NULL;
63426+ }
63427+
63428+ return 0;
63429+}
63430+
63431+static int
63432+copy_user_transitions(struct acl_role_label *rolep)
63433+{
63434+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63435+ int error;
63436+
63437+ rusertp = rolep->transitions;
63438+
63439+ while (rusertp) {
63440+ rlast = rtmp;
63441+
63442+ if ((rtmp = (struct role_transition *)
63443+ acl_alloc(sizeof (struct role_transition))) == NULL)
63444+ return -ENOMEM;
63445+
63446+ if (copy_role_transition(rtmp, rusertp))
63447+ return -EFAULT;
63448+
63449+ rusertp = rtmp->prev;
63450+
63451+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63452+ if (error)
63453+ return error;
63454+
63455+ if (!rlast) {
63456+ rtmp->prev = NULL;
63457+ rolep->transitions = rtmp;
63458+ } else {
63459+ rlast->next = rtmp;
63460+ rtmp->prev = rlast;
63461+ }
63462+
63463+ if (!rusertp)
63464+ rtmp->next = NULL;
63465+ }
63466+
63467+ return 0;
63468+}
63469+
63470+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63471+{
63472+ struct acl_object_label o_tmp;
63473+ __u32 num = 0;
63474+
63475+ while (userp) {
63476+ if (copy_acl_object_label(&o_tmp, userp))
63477+ break;
63478+
63479+ userp = o_tmp.prev;
63480+ num++;
63481+ }
63482+
63483+ return num;
63484+}
63485+
63486+static struct acl_subject_label *
63487+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63488+{
63489+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63490+ __u32 num_objs;
63491+ struct acl_ip_label **i_tmp, *i_utmp2;
63492+ struct gr_hash_struct ghash;
63493+ struct subject_map *subjmap;
63494+ unsigned int i_num;
63495+ int err;
63496+
63497+ if (already_copied != NULL)
63498+ *already_copied = 0;
63499+
63500+ s_tmp = lookup_subject_map(userp);
63501+
63502+ /* we've already copied this subject into the kernel, just return
63503+ the reference to it, and don't copy it over again
63504+ */
63505+ if (s_tmp) {
63506+ if (already_copied != NULL)
63507+ *already_copied = 1;
63508+ return(s_tmp);
63509+ }
63510+
63511+ if ((s_tmp = (struct acl_subject_label *)
63512+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63513+ return ERR_PTR(-ENOMEM);
63514+
63515+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63516+ if (subjmap == NULL)
63517+ return ERR_PTR(-ENOMEM);
63518+
63519+ subjmap->user = userp;
63520+ subjmap->kernel = s_tmp;
63521+ insert_subj_map_entry(subjmap);
63522+
63523+ if (copy_acl_subject_label(s_tmp, userp))
63524+ return ERR_PTR(-EFAULT);
63525+
63526+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63527+ if (err)
63528+ return ERR_PTR(err);
63529+
63530+ if (!strcmp(s_tmp->filename, "/"))
63531+ role->root_label = s_tmp;
63532+
63533+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63534+ return ERR_PTR(-EFAULT);
63535+
63536+ /* copy user and group transition tables */
63537+
63538+ if (s_tmp->user_trans_num) {
63539+ uid_t *uidlist;
63540+
63541+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63542+ if (uidlist == NULL)
63543+ return ERR_PTR(-ENOMEM);
63544+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63545+ return ERR_PTR(-EFAULT);
63546+
63547+ s_tmp->user_transitions = uidlist;
63548+ }
63549+
63550+ if (s_tmp->group_trans_num) {
63551+ gid_t *gidlist;
63552+
63553+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63554+ if (gidlist == NULL)
63555+ return ERR_PTR(-ENOMEM);
63556+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63557+ return ERR_PTR(-EFAULT);
63558+
63559+ s_tmp->group_transitions = gidlist;
63560+ }
63561+
63562+ /* set up object hash table */
63563+ num_objs = count_user_objs(ghash.first);
63564+
63565+ s_tmp->obj_hash_size = num_objs;
63566+ s_tmp->obj_hash =
63567+ (struct acl_object_label **)
63568+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63569+
63570+ if (!s_tmp->obj_hash)
63571+ return ERR_PTR(-ENOMEM);
63572+
63573+ memset(s_tmp->obj_hash, 0,
63574+ s_tmp->obj_hash_size *
63575+ sizeof (struct acl_object_label *));
63576+
63577+ /* add in objects */
63578+ err = copy_user_objs(ghash.first, s_tmp, role);
63579+
63580+ if (err)
63581+ return ERR_PTR(err);
63582+
63583+ /* set pointer for parent subject */
63584+ if (s_tmp->parent_subject) {
63585+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63586+
63587+ if (IS_ERR(s_tmp2))
63588+ return s_tmp2;
63589+
63590+ s_tmp->parent_subject = s_tmp2;
63591+ }
63592+
63593+ /* add in ip acls */
63594+
63595+ if (!s_tmp->ip_num) {
63596+ s_tmp->ips = NULL;
63597+ goto insert;
63598+ }
63599+
63600+ i_tmp =
63601+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63602+ sizeof (struct acl_ip_label *));
63603+
63604+ if (!i_tmp)
63605+ return ERR_PTR(-ENOMEM);
63606+
63607+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63608+ *(i_tmp + i_num) =
63609+ (struct acl_ip_label *)
63610+ acl_alloc(sizeof (struct acl_ip_label));
63611+ if (!*(i_tmp + i_num))
63612+ return ERR_PTR(-ENOMEM);
63613+
63614+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63615+ return ERR_PTR(-EFAULT);
63616+
63617+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63618+ return ERR_PTR(-EFAULT);
63619+
63620+ if ((*(i_tmp + i_num))->iface == NULL)
63621+ continue;
63622+
63623+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63624+ if (err)
63625+ return ERR_PTR(err);
63626+ }
63627+
63628+ s_tmp->ips = i_tmp;
63629+
63630+insert:
63631+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63632+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63633+ return ERR_PTR(-ENOMEM);
63634+
63635+ return s_tmp;
63636+}
63637+
63638+static int
63639+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63640+{
63641+ struct acl_subject_label s_pre;
63642+ struct acl_subject_label * ret;
63643+ int err;
63644+
63645+ while (userp) {
63646+ if (copy_acl_subject_label(&s_pre, userp))
63647+ return -EFAULT;
63648+
63649+ ret = do_copy_user_subj(userp, role, NULL);
63650+
63651+ err = PTR_ERR(ret);
63652+ if (IS_ERR(ret))
63653+ return err;
63654+
63655+ insert_acl_subj_label(ret, role);
63656+
63657+ userp = s_pre.prev;
63658+ }
63659+
63660+ return 0;
63661+}
63662+
63663+static int
63664+copy_user_acl(struct gr_arg *arg)
63665+{
63666+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63667+ struct acl_subject_label *subj_list;
63668+ struct sprole_pw *sptmp;
63669+ struct gr_hash_struct *ghash;
63670+ uid_t *domainlist;
63671+ unsigned int r_num;
63672+ int err = 0;
63673+ __u16 i;
63674+ __u32 num_subjs;
63675+
63676+ /* we need a default and kernel role */
63677+ if (arg->role_db.num_roles < 2)
63678+ return -EINVAL;
63679+
63680+ /* copy special role authentication info from userspace */
63681+
63682+ num_sprole_pws = arg->num_sprole_pws;
63683+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63684+
63685+ if (!acl_special_roles && num_sprole_pws)
63686+ return -ENOMEM;
63687+
63688+ for (i = 0; i < num_sprole_pws; i++) {
63689+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63690+ if (!sptmp)
63691+ return -ENOMEM;
63692+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63693+ return -EFAULT;
63694+
63695+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63696+ if (err)
63697+ return err;
63698+
63699+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63700+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63701+#endif
63702+
63703+ acl_special_roles[i] = sptmp;
63704+ }
63705+
63706+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63707+
63708+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63709+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63710+
63711+ if (!r_tmp)
63712+ return -ENOMEM;
63713+
63714+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63715+ return -EFAULT;
63716+
63717+ if (copy_acl_role_label(r_tmp, r_utmp2))
63718+ return -EFAULT;
63719+
63720+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63721+ if (err)
63722+ return err;
63723+
63724+ if (!strcmp(r_tmp->rolename, "default")
63725+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63726+ default_role = r_tmp;
63727+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63728+ kernel_role = r_tmp;
63729+ }
63730+
63731+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63732+ return -ENOMEM;
63733+
63734+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63735+ return -EFAULT;
63736+
63737+ r_tmp->hash = ghash;
63738+
63739+ num_subjs = count_user_subjs(r_tmp->hash->first);
63740+
63741+ r_tmp->subj_hash_size = num_subjs;
63742+ r_tmp->subj_hash =
63743+ (struct acl_subject_label **)
63744+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63745+
63746+ if (!r_tmp->subj_hash)
63747+ return -ENOMEM;
63748+
63749+ err = copy_user_allowedips(r_tmp);
63750+ if (err)
63751+ return err;
63752+
63753+ /* copy domain info */
63754+ if (r_tmp->domain_children != NULL) {
63755+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63756+ if (domainlist == NULL)
63757+ return -ENOMEM;
63758+
63759+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63760+ return -EFAULT;
63761+
63762+ r_tmp->domain_children = domainlist;
63763+ }
63764+
63765+ err = copy_user_transitions(r_tmp);
63766+ if (err)
63767+ return err;
63768+
63769+ memset(r_tmp->subj_hash, 0,
63770+ r_tmp->subj_hash_size *
63771+ sizeof (struct acl_subject_label *));
63772+
63773+ /* acquire the list of subjects, then NULL out
63774+ the list prior to parsing the subjects for this role,
63775+ as during this parsing the list is replaced with a list
63776+ of *nested* subjects for the role
63777+ */
63778+ subj_list = r_tmp->hash->first;
63779+
63780+ /* set nested subject list to null */
63781+ r_tmp->hash->first = NULL;
63782+
63783+ err = copy_user_subjs(subj_list, r_tmp);
63784+
63785+ if (err)
63786+ return err;
63787+
63788+ insert_acl_role_label(r_tmp);
63789+ }
63790+
63791+ if (default_role == NULL || kernel_role == NULL)
63792+ return -EINVAL;
63793+
63794+ return err;
63795+}
63796+
63797+static int
63798+gracl_init(struct gr_arg *args)
63799+{
63800+ int error = 0;
63801+
63802+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63803+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63804+
63805+ if (init_variables(args)) {
63806+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63807+ error = -ENOMEM;
63808+ free_variables();
63809+ goto out;
63810+ }
63811+
63812+ error = copy_user_acl(args);
63813+ free_init_variables();
63814+ if (error) {
63815+ free_variables();
63816+ goto out;
63817+ }
63818+
63819+ if ((error = gr_set_acls(0))) {
63820+ free_variables();
63821+ goto out;
63822+ }
63823+
63824+ pax_open_kernel();
63825+ gr_status |= GR_READY;
63826+ pax_close_kernel();
63827+
63828+ out:
63829+ return error;
63830+}
63831+
63832+/* derived from glibc fnmatch() 0: match, 1: no match*/
63833+
63834+static int
63835+glob_match(const char *p, const char *n)
63836+{
63837+ char c;
63838+
63839+ while ((c = *p++) != '\0') {
63840+ switch (c) {
63841+ case '?':
63842+ if (*n == '\0')
63843+ return 1;
63844+ else if (*n == '/')
63845+ return 1;
63846+ break;
63847+ case '\\':
63848+ if (*n != c)
63849+ return 1;
63850+ break;
63851+ case '*':
63852+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63853+ if (*n == '/')
63854+ return 1;
63855+ else if (c == '?') {
63856+ if (*n == '\0')
63857+ return 1;
63858+ else
63859+ ++n;
63860+ }
63861+ }
63862+ if (c == '\0') {
63863+ return 0;
63864+ } else {
63865+ const char *endp;
63866+
63867+ if ((endp = strchr(n, '/')) == NULL)
63868+ endp = n + strlen(n);
63869+
63870+ if (c == '[') {
63871+ for (--p; n < endp; ++n)
63872+ if (!glob_match(p, n))
63873+ return 0;
63874+ } else if (c == '/') {
63875+ while (*n != '\0' && *n != '/')
63876+ ++n;
63877+ if (*n == '/' && !glob_match(p, n + 1))
63878+ return 0;
63879+ } else {
63880+ for (--p; n < endp; ++n)
63881+ if (*n == c && !glob_match(p, n))
63882+ return 0;
63883+ }
63884+
63885+ return 1;
63886+ }
63887+ case '[':
63888+ {
63889+ int not;
63890+ char cold;
63891+
63892+ if (*n == '\0' || *n == '/')
63893+ return 1;
63894+
63895+ not = (*p == '!' || *p == '^');
63896+ if (not)
63897+ ++p;
63898+
63899+ c = *p++;
63900+ for (;;) {
63901+ unsigned char fn = (unsigned char)*n;
63902+
63903+ if (c == '\0')
63904+ return 1;
63905+ else {
63906+ if (c == fn)
63907+ goto matched;
63908+ cold = c;
63909+ c = *p++;
63910+
63911+ if (c == '-' && *p != ']') {
63912+ unsigned char cend = *p++;
63913+
63914+ if (cend == '\0')
63915+ return 1;
63916+
63917+ if (cold <= fn && fn <= cend)
63918+ goto matched;
63919+
63920+ c = *p++;
63921+ }
63922+ }
63923+
63924+ if (c == ']')
63925+ break;
63926+ }
63927+ if (!not)
63928+ return 1;
63929+ break;
63930+ matched:
63931+ while (c != ']') {
63932+ if (c == '\0')
63933+ return 1;
63934+
63935+ c = *p++;
63936+ }
63937+ if (not)
63938+ return 1;
63939+ }
63940+ break;
63941+ default:
63942+ if (c != *n)
63943+ return 1;
63944+ }
63945+
63946+ ++n;
63947+ }
63948+
63949+ if (*n == '\0')
63950+ return 0;
63951+
63952+ if (*n == '/')
63953+ return 0;
63954+
63955+ return 1;
63956+}
63957+
63958+static struct acl_object_label *
63959+chk_glob_label(struct acl_object_label *globbed,
63960+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63961+{
63962+ struct acl_object_label *tmp;
63963+
63964+ if (*path == NULL)
63965+ *path = gr_to_filename_nolock(dentry, mnt);
63966+
63967+ tmp = globbed;
63968+
63969+ while (tmp) {
63970+ if (!glob_match(tmp->filename, *path))
63971+ return tmp;
63972+ tmp = tmp->next;
63973+ }
63974+
63975+ return NULL;
63976+}
63977+
63978+static struct acl_object_label *
63979+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63980+ const ino_t curr_ino, const dev_t curr_dev,
63981+ const struct acl_subject_label *subj, char **path, const int checkglob)
63982+{
63983+ struct acl_subject_label *tmpsubj;
63984+ struct acl_object_label *retval;
63985+ struct acl_object_label *retval2;
63986+
63987+ tmpsubj = (struct acl_subject_label *) subj;
63988+ read_lock(&gr_inode_lock);
63989+ do {
63990+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
63991+ if (retval) {
63992+ if (checkglob && retval->globbed) {
63993+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
63994+ if (retval2)
63995+ retval = retval2;
63996+ }
63997+ break;
63998+ }
63999+ } while ((tmpsubj = tmpsubj->parent_subject));
64000+ read_unlock(&gr_inode_lock);
64001+
64002+ return retval;
64003+}
64004+
64005+static __inline__ struct acl_object_label *
64006+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64007+ struct dentry *curr_dentry,
64008+ const struct acl_subject_label *subj, char **path, const int checkglob)
64009+{
64010+ int newglob = checkglob;
64011+ ino_t inode;
64012+ dev_t device;
64013+
64014+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64015+ as we don't want a / * rule to match instead of the / object
64016+ don't do this for create lookups that call this function though, since they're looking up
64017+ on the parent and thus need globbing checks on all paths
64018+ */
64019+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64020+ newglob = GR_NO_GLOB;
64021+
64022+ spin_lock(&curr_dentry->d_lock);
64023+ inode = curr_dentry->d_inode->i_ino;
64024+ device = __get_dev(curr_dentry);
64025+ spin_unlock(&curr_dentry->d_lock);
64026+
64027+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64028+}
64029+
64030+#ifdef CONFIG_HUGETLBFS
64031+static inline bool
64032+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64033+{
64034+ int i;
64035+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64036+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64037+ return true;
64038+ }
64039+
64040+ return false;
64041+}
64042+#endif
64043+
64044+static struct acl_object_label *
64045+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64046+ const struct acl_subject_label *subj, char *path, const int checkglob)
64047+{
64048+ struct dentry *dentry = (struct dentry *) l_dentry;
64049+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64050+ struct mount *real_mnt = real_mount(mnt);
64051+ struct acl_object_label *retval;
64052+ struct dentry *parent;
64053+
64054+ br_read_lock(&vfsmount_lock);
64055+ write_seqlock(&rename_lock);
64056+
64057+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64058+#ifdef CONFIG_NET
64059+ mnt == sock_mnt ||
64060+#endif
64061+#ifdef CONFIG_HUGETLBFS
64062+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64063+#endif
64064+ /* ignore Eric Biederman */
64065+ IS_PRIVATE(l_dentry->d_inode))) {
64066+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64067+ goto out;
64068+ }
64069+
64070+ for (;;) {
64071+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64072+ break;
64073+
64074+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64075+ if (!mnt_has_parent(real_mnt))
64076+ break;
64077+
64078+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64079+ if (retval != NULL)
64080+ goto out;
64081+
64082+ dentry = real_mnt->mnt_mountpoint;
64083+ real_mnt = real_mnt->mnt_parent;
64084+ mnt = &real_mnt->mnt;
64085+ continue;
64086+ }
64087+
64088+ parent = dentry->d_parent;
64089+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64090+ if (retval != NULL)
64091+ goto out;
64092+
64093+ dentry = parent;
64094+ }
64095+
64096+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64097+
64098+ /* real_root is pinned so we don't have to hold a reference */
64099+ if (retval == NULL)
64100+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64101+out:
64102+ write_sequnlock(&rename_lock);
64103+ br_read_unlock(&vfsmount_lock);
64104+
64105+ BUG_ON(retval == NULL);
64106+
64107+ return retval;
64108+}
64109+
64110+static __inline__ struct acl_object_label *
64111+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64112+ const struct acl_subject_label *subj)
64113+{
64114+ char *path = NULL;
64115+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64116+}
64117+
64118+static __inline__ struct acl_object_label *
64119+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64120+ const struct acl_subject_label *subj)
64121+{
64122+ char *path = NULL;
64123+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64124+}
64125+
64126+static __inline__ struct acl_object_label *
64127+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64128+ const struct acl_subject_label *subj, char *path)
64129+{
64130+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64131+}
64132+
64133+static struct acl_subject_label *
64134+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64135+ const struct acl_role_label *role)
64136+{
64137+ struct dentry *dentry = (struct dentry *) l_dentry;
64138+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64139+ struct mount *real_mnt = real_mount(mnt);
64140+ struct acl_subject_label *retval;
64141+ struct dentry *parent;
64142+
64143+ br_read_lock(&vfsmount_lock);
64144+ write_seqlock(&rename_lock);
64145+
64146+ for (;;) {
64147+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64148+ break;
64149+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64150+ if (!mnt_has_parent(real_mnt))
64151+ break;
64152+
64153+ spin_lock(&dentry->d_lock);
64154+ read_lock(&gr_inode_lock);
64155+ retval =
64156+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64157+ __get_dev(dentry), role);
64158+ read_unlock(&gr_inode_lock);
64159+ spin_unlock(&dentry->d_lock);
64160+ if (retval != NULL)
64161+ goto out;
64162+
64163+ dentry = real_mnt->mnt_mountpoint;
64164+ real_mnt = real_mnt->mnt_parent;
64165+ mnt = &real_mnt->mnt;
64166+ continue;
64167+ }
64168+
64169+ spin_lock(&dentry->d_lock);
64170+ read_lock(&gr_inode_lock);
64171+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64172+ __get_dev(dentry), role);
64173+ read_unlock(&gr_inode_lock);
64174+ parent = dentry->d_parent;
64175+ spin_unlock(&dentry->d_lock);
64176+
64177+ if (retval != NULL)
64178+ goto out;
64179+
64180+ dentry = parent;
64181+ }
64182+
64183+ spin_lock(&dentry->d_lock);
64184+ read_lock(&gr_inode_lock);
64185+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64186+ __get_dev(dentry), role);
64187+ read_unlock(&gr_inode_lock);
64188+ spin_unlock(&dentry->d_lock);
64189+
64190+ if (unlikely(retval == NULL)) {
64191+ /* real_root is pinned, we don't need to hold a reference */
64192+ read_lock(&gr_inode_lock);
64193+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64194+ __get_dev(real_root.dentry), role);
64195+ read_unlock(&gr_inode_lock);
64196+ }
64197+out:
64198+ write_sequnlock(&rename_lock);
64199+ br_read_unlock(&vfsmount_lock);
64200+
64201+ BUG_ON(retval == NULL);
64202+
64203+ return retval;
64204+}
64205+
64206+static void
64207+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64208+{
64209+ struct task_struct *task = current;
64210+ const struct cred *cred = current_cred();
64211+
64212+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64213+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64214+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64215+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64216+
64217+ return;
64218+}
64219+
64220+static void
64221+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64222+{
64223+ struct task_struct *task = current;
64224+ const struct cred *cred = current_cred();
64225+
64226+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64227+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64228+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64229+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64230+
64231+ return;
64232+}
64233+
64234+static void
64235+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64236+{
64237+ struct task_struct *task = current;
64238+ const struct cred *cred = current_cred();
64239+
64240+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64241+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64242+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64243+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64244+
64245+ return;
64246+}
64247+
64248+__u32
64249+gr_search_file(const struct dentry * dentry, const __u32 mode,
64250+ const struct vfsmount * mnt)
64251+{
64252+ __u32 retval = mode;
64253+ struct acl_subject_label *curracl;
64254+ struct acl_object_label *currobj;
64255+
64256+ if (unlikely(!(gr_status & GR_READY)))
64257+ return (mode & ~GR_AUDITS);
64258+
64259+ curracl = current->acl;
64260+
64261+ currobj = chk_obj_label(dentry, mnt, curracl);
64262+ retval = currobj->mode & mode;
64263+
64264+ /* if we're opening a specified transfer file for writing
64265+ (e.g. /dev/initctl), then transfer our role to init
64266+ */
64267+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64268+ current->role->roletype & GR_ROLE_PERSIST)) {
64269+ struct task_struct *task = init_pid_ns.child_reaper;
64270+
64271+ if (task->role != current->role) {
64272+ task->acl_sp_role = 0;
64273+ task->acl_role_id = current->acl_role_id;
64274+ task->role = current->role;
64275+ rcu_read_lock();
64276+ read_lock(&grsec_exec_file_lock);
64277+ gr_apply_subject_to_task(task);
64278+ read_unlock(&grsec_exec_file_lock);
64279+ rcu_read_unlock();
64280+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64281+ }
64282+ }
64283+
64284+ if (unlikely
64285+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64286+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64287+ __u32 new_mode = mode;
64288+
64289+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64290+
64291+ retval = new_mode;
64292+
64293+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64294+ new_mode |= GR_INHERIT;
64295+
64296+ if (!(mode & GR_NOLEARN))
64297+ gr_log_learn(dentry, mnt, new_mode);
64298+ }
64299+
64300+ return retval;
64301+}
64302+
64303+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64304+ const struct dentry *parent,
64305+ const struct vfsmount *mnt)
64306+{
64307+ struct name_entry *match;
64308+ struct acl_object_label *matchpo;
64309+ struct acl_subject_label *curracl;
64310+ char *path;
64311+
64312+ if (unlikely(!(gr_status & GR_READY)))
64313+ return NULL;
64314+
64315+ preempt_disable();
64316+ path = gr_to_filename_rbac(new_dentry, mnt);
64317+ match = lookup_name_entry_create(path);
64318+
64319+ curracl = current->acl;
64320+
64321+ if (match) {
64322+ read_lock(&gr_inode_lock);
64323+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64324+ read_unlock(&gr_inode_lock);
64325+
64326+ if (matchpo) {
64327+ preempt_enable();
64328+ return matchpo;
64329+ }
64330+ }
64331+
64332+ // lookup parent
64333+
64334+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64335+
64336+ preempt_enable();
64337+ return matchpo;
64338+}
64339+
64340+__u32
64341+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64342+ const struct vfsmount * mnt, const __u32 mode)
64343+{
64344+ struct acl_object_label *matchpo;
64345+ __u32 retval;
64346+
64347+ if (unlikely(!(gr_status & GR_READY)))
64348+ return (mode & ~GR_AUDITS);
64349+
64350+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64351+
64352+ retval = matchpo->mode & mode;
64353+
64354+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64355+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64356+ __u32 new_mode = mode;
64357+
64358+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64359+
64360+ gr_log_learn(new_dentry, mnt, new_mode);
64361+ return new_mode;
64362+ }
64363+
64364+ return retval;
64365+}
64366+
64367+__u32
64368+gr_check_link(const struct dentry * new_dentry,
64369+ const struct dentry * parent_dentry,
64370+ const struct vfsmount * parent_mnt,
64371+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64372+{
64373+ struct acl_object_label *obj;
64374+ __u32 oldmode, newmode;
64375+ __u32 needmode;
64376+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64377+ GR_DELETE | GR_INHERIT;
64378+
64379+ if (unlikely(!(gr_status & GR_READY)))
64380+ return (GR_CREATE | GR_LINK);
64381+
64382+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64383+ oldmode = obj->mode;
64384+
64385+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64386+ newmode = obj->mode;
64387+
64388+ needmode = newmode & checkmodes;
64389+
64390+ // old name for hardlink must have at least the permissions of the new name
64391+ if ((oldmode & needmode) != needmode)
64392+ goto bad;
64393+
64394+ // if old name had restrictions/auditing, make sure the new name does as well
64395+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64396+
64397+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64398+ if (is_privileged_binary(old_dentry))
64399+ needmode |= GR_SETID;
64400+
64401+ if ((newmode & needmode) != needmode)
64402+ goto bad;
64403+
64404+ // enforce minimum permissions
64405+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64406+ return newmode;
64407+bad:
64408+ needmode = oldmode;
64409+ if (is_privileged_binary(old_dentry))
64410+ needmode |= GR_SETID;
64411+
64412+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64413+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64414+ return (GR_CREATE | GR_LINK);
64415+ } else if (newmode & GR_SUPPRESS)
64416+ return GR_SUPPRESS;
64417+ else
64418+ return 0;
64419+}
64420+
64421+int
64422+gr_check_hidden_task(const struct task_struct *task)
64423+{
64424+ if (unlikely(!(gr_status & GR_READY)))
64425+ return 0;
64426+
64427+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64428+ return 1;
64429+
64430+ return 0;
64431+}
64432+
64433+int
64434+gr_check_protected_task(const struct task_struct *task)
64435+{
64436+ if (unlikely(!(gr_status & GR_READY) || !task))
64437+ return 0;
64438+
64439+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64440+ task->acl != current->acl)
64441+ return 1;
64442+
64443+ return 0;
64444+}
64445+
64446+int
64447+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64448+{
64449+ struct task_struct *p;
64450+ int ret = 0;
64451+
64452+ if (unlikely(!(gr_status & GR_READY) || !pid))
64453+ return ret;
64454+
64455+ read_lock(&tasklist_lock);
64456+ do_each_pid_task(pid, type, p) {
64457+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64458+ p->acl != current->acl) {
64459+ ret = 1;
64460+ goto out;
64461+ }
64462+ } while_each_pid_task(pid, type, p);
64463+out:
64464+ read_unlock(&tasklist_lock);
64465+
64466+ return ret;
64467+}
64468+
64469+void
64470+gr_copy_label(struct task_struct *tsk)
64471+{
64472+ tsk->signal->used_accept = 0;
64473+ tsk->acl_sp_role = 0;
64474+ tsk->acl_role_id = current->acl_role_id;
64475+ tsk->acl = current->acl;
64476+ tsk->role = current->role;
64477+ tsk->signal->curr_ip = current->signal->curr_ip;
64478+ tsk->signal->saved_ip = current->signal->saved_ip;
64479+ if (current->exec_file)
64480+ get_file(current->exec_file);
64481+ tsk->exec_file = current->exec_file;
64482+ tsk->is_writable = current->is_writable;
64483+ if (unlikely(current->signal->used_accept)) {
64484+ current->signal->curr_ip = 0;
64485+ current->signal->saved_ip = 0;
64486+ }
64487+
64488+ return;
64489+}
64490+
64491+static void
64492+gr_set_proc_res(struct task_struct *task)
64493+{
64494+ struct acl_subject_label *proc;
64495+ unsigned short i;
64496+
64497+ proc = task->acl;
64498+
64499+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64500+ return;
64501+
64502+ for (i = 0; i < RLIM_NLIMITS; i++) {
64503+ if (!(proc->resmask & (1U << i)))
64504+ continue;
64505+
64506+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64507+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64508+
64509+ if (i == RLIMIT_CPU)
64510+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64511+ }
64512+
64513+ return;
64514+}
64515+
64516+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64517+
64518+int
64519+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64520+{
64521+ unsigned int i;
64522+ __u16 num;
64523+ uid_t *uidlist;
64524+ uid_t curuid;
64525+ int realok = 0;
64526+ int effectiveok = 0;
64527+ int fsok = 0;
64528+ uid_t globalreal, globaleffective, globalfs;
64529+
64530+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64531+ struct user_struct *user;
64532+
64533+ if (!uid_valid(real))
64534+ goto skipit;
64535+
64536+ /* find user based on global namespace */
64537+
64538+ globalreal = GR_GLOBAL_UID(real);
64539+
64540+ user = find_user(make_kuid(&init_user_ns, globalreal));
64541+ if (user == NULL)
64542+ goto skipit;
64543+
64544+ if (gr_process_kernel_setuid_ban(user)) {
64545+ /* for find_user */
64546+ free_uid(user);
64547+ return 1;
64548+ }
64549+
64550+ /* for find_user */
64551+ free_uid(user);
64552+
64553+skipit:
64554+#endif
64555+
64556+ if (unlikely(!(gr_status & GR_READY)))
64557+ return 0;
64558+
64559+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64560+ gr_log_learn_uid_change(real, effective, fs);
64561+
64562+ num = current->acl->user_trans_num;
64563+ uidlist = current->acl->user_transitions;
64564+
64565+ if (uidlist == NULL)
64566+ return 0;
64567+
64568+ if (!uid_valid(real)) {
64569+ realok = 1;
64570+ globalreal = (uid_t)-1;
64571+ } else {
64572+ globalreal = GR_GLOBAL_UID(real);
64573+ }
64574+ if (!uid_valid(effective)) {
64575+ effectiveok = 1;
64576+ globaleffective = (uid_t)-1;
64577+ } else {
64578+ globaleffective = GR_GLOBAL_UID(effective);
64579+ }
64580+ if (!uid_valid(fs)) {
64581+ fsok = 1;
64582+ globalfs = (uid_t)-1;
64583+ } else {
64584+ globalfs = GR_GLOBAL_UID(fs);
64585+ }
64586+
64587+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64588+ for (i = 0; i < num; i++) {
64589+ curuid = uidlist[i];
64590+ if (globalreal == curuid)
64591+ realok = 1;
64592+ if (globaleffective == curuid)
64593+ effectiveok = 1;
64594+ if (globalfs == curuid)
64595+ fsok = 1;
64596+ }
64597+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64598+ for (i = 0; i < num; i++) {
64599+ curuid = uidlist[i];
64600+ if (globalreal == curuid)
64601+ break;
64602+ if (globaleffective == curuid)
64603+ break;
64604+ if (globalfs == curuid)
64605+ break;
64606+ }
64607+ /* not in deny list */
64608+ if (i == num) {
64609+ realok = 1;
64610+ effectiveok = 1;
64611+ fsok = 1;
64612+ }
64613+ }
64614+
64615+ if (realok && effectiveok && fsok)
64616+ return 0;
64617+ else {
64618+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64619+ return 1;
64620+ }
64621+}
64622+
64623+int
64624+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64625+{
64626+ unsigned int i;
64627+ __u16 num;
64628+ gid_t *gidlist;
64629+ gid_t curgid;
64630+ int realok = 0;
64631+ int effectiveok = 0;
64632+ int fsok = 0;
64633+ gid_t globalreal, globaleffective, globalfs;
64634+
64635+ if (unlikely(!(gr_status & GR_READY)))
64636+ return 0;
64637+
64638+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64639+ gr_log_learn_gid_change(real, effective, fs);
64640+
64641+ num = current->acl->group_trans_num;
64642+ gidlist = current->acl->group_transitions;
64643+
64644+ if (gidlist == NULL)
64645+ return 0;
64646+
64647+ if (!gid_valid(real)) {
64648+ realok = 1;
64649+ globalreal = (gid_t)-1;
64650+ } else {
64651+ globalreal = GR_GLOBAL_GID(real);
64652+ }
64653+ if (!gid_valid(effective)) {
64654+ effectiveok = 1;
64655+ globaleffective = (gid_t)-1;
64656+ } else {
64657+ globaleffective = GR_GLOBAL_GID(effective);
64658+ }
64659+ if (!gid_valid(fs)) {
64660+ fsok = 1;
64661+ globalfs = (gid_t)-1;
64662+ } else {
64663+ globalfs = GR_GLOBAL_GID(fs);
64664+ }
64665+
64666+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64667+ for (i = 0; i < num; i++) {
64668+ curgid = gidlist[i];
64669+ if (globalreal == curgid)
64670+ realok = 1;
64671+ if (globaleffective == curgid)
64672+ effectiveok = 1;
64673+ if (globalfs == curgid)
64674+ fsok = 1;
64675+ }
64676+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64677+ for (i = 0; i < num; i++) {
64678+ curgid = gidlist[i];
64679+ if (globalreal == curgid)
64680+ break;
64681+ if (globaleffective == curgid)
64682+ break;
64683+ if (globalfs == curgid)
64684+ break;
64685+ }
64686+ /* not in deny list */
64687+ if (i == num) {
64688+ realok = 1;
64689+ effectiveok = 1;
64690+ fsok = 1;
64691+ }
64692+ }
64693+
64694+ if (realok && effectiveok && fsok)
64695+ return 0;
64696+ else {
64697+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64698+ return 1;
64699+ }
64700+}
64701+
64702+extern int gr_acl_is_capable(const int cap);
64703+
64704+void
64705+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64706+{
64707+ struct acl_role_label *role = task->role;
64708+ struct acl_subject_label *subj = NULL;
64709+ struct acl_object_label *obj;
64710+ struct file *filp;
64711+ uid_t uid;
64712+ gid_t gid;
64713+
64714+ if (unlikely(!(gr_status & GR_READY)))
64715+ return;
64716+
64717+ uid = GR_GLOBAL_UID(kuid);
64718+ gid = GR_GLOBAL_GID(kgid);
64719+
64720+ filp = task->exec_file;
64721+
64722+ /* kernel process, we'll give them the kernel role */
64723+ if (unlikely(!filp)) {
64724+ task->role = kernel_role;
64725+ task->acl = kernel_role->root_label;
64726+ return;
64727+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64728+ role = lookup_acl_role_label(task, uid, gid);
64729+
64730+ /* don't change the role if we're not a privileged process */
64731+ if (role && task->role != role &&
64732+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64733+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64734+ return;
64735+
64736+ /* perform subject lookup in possibly new role
64737+ we can use this result below in the case where role == task->role
64738+ */
64739+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64740+
64741+ /* if we changed uid/gid, but result in the same role
64742+ and are using inheritance, don't lose the inherited subject
64743+ if current subject is other than what normal lookup
64744+ would result in, we arrived via inheritance, don't
64745+ lose subject
64746+ */
64747+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64748+ (subj == task->acl)))
64749+ task->acl = subj;
64750+
64751+ task->role = role;
64752+
64753+ task->is_writable = 0;
64754+
64755+ /* ignore additional mmap checks for processes that are writable
64756+ by the default ACL */
64757+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64758+ if (unlikely(obj->mode & GR_WRITE))
64759+ task->is_writable = 1;
64760+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64761+ if (unlikely(obj->mode & GR_WRITE))
64762+ task->is_writable = 1;
64763+
64764+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64765+ 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);
64766+#endif
64767+
64768+ gr_set_proc_res(task);
64769+
64770+ return;
64771+}
64772+
64773+int
64774+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64775+ const int unsafe_flags)
64776+{
64777+ struct task_struct *task = current;
64778+ struct acl_subject_label *newacl;
64779+ struct acl_object_label *obj;
64780+ __u32 retmode;
64781+
64782+ if (unlikely(!(gr_status & GR_READY)))
64783+ return 0;
64784+
64785+ newacl = chk_subj_label(dentry, mnt, task->role);
64786+
64787+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64788+ did an exec
64789+ */
64790+ rcu_read_lock();
64791+ read_lock(&tasklist_lock);
64792+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64793+ (task->parent->acl->mode & GR_POVERRIDE))) {
64794+ read_unlock(&tasklist_lock);
64795+ rcu_read_unlock();
64796+ goto skip_check;
64797+ }
64798+ read_unlock(&tasklist_lock);
64799+ rcu_read_unlock();
64800+
64801+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64802+ !(task->role->roletype & GR_ROLE_GOD) &&
64803+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64804+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64805+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64806+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64807+ else
64808+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64809+ return -EACCES;
64810+ }
64811+
64812+skip_check:
64813+
64814+ obj = chk_obj_label(dentry, mnt, task->acl);
64815+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64816+
64817+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64818+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64819+ if (obj->nested)
64820+ task->acl = obj->nested;
64821+ else
64822+ task->acl = newacl;
64823+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64824+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64825+
64826+ task->is_writable = 0;
64827+
64828+ /* ignore additional mmap checks for processes that are writable
64829+ by the default ACL */
64830+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64831+ if (unlikely(obj->mode & GR_WRITE))
64832+ task->is_writable = 1;
64833+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64834+ if (unlikely(obj->mode & GR_WRITE))
64835+ task->is_writable = 1;
64836+
64837+ gr_set_proc_res(task);
64838+
64839+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64840+ 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);
64841+#endif
64842+ return 0;
64843+}
64844+
64845+/* always called with valid inodev ptr */
64846+static void
64847+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64848+{
64849+ struct acl_object_label *matchpo;
64850+ struct acl_subject_label *matchps;
64851+ struct acl_subject_label *subj;
64852+ struct acl_role_label *role;
64853+ unsigned int x;
64854+
64855+ FOR_EACH_ROLE_START(role)
64856+ FOR_EACH_SUBJECT_START(role, subj, x)
64857+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64858+ matchpo->mode |= GR_DELETED;
64859+ FOR_EACH_SUBJECT_END(subj,x)
64860+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64861+ /* nested subjects aren't in the role's subj_hash table */
64862+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64863+ matchpo->mode |= GR_DELETED;
64864+ FOR_EACH_NESTED_SUBJECT_END(subj)
64865+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64866+ matchps->mode |= GR_DELETED;
64867+ FOR_EACH_ROLE_END(role)
64868+
64869+ inodev->nentry->deleted = 1;
64870+
64871+ return;
64872+}
64873+
64874+void
64875+gr_handle_delete(const ino_t ino, const dev_t dev)
64876+{
64877+ struct inodev_entry *inodev;
64878+
64879+ if (unlikely(!(gr_status & GR_READY)))
64880+ return;
64881+
64882+ write_lock(&gr_inode_lock);
64883+ inodev = lookup_inodev_entry(ino, dev);
64884+ if (inodev != NULL)
64885+ do_handle_delete(inodev, ino, dev);
64886+ write_unlock(&gr_inode_lock);
64887+
64888+ return;
64889+}
64890+
64891+static void
64892+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64893+ const ino_t newinode, const dev_t newdevice,
64894+ struct acl_subject_label *subj)
64895+{
64896+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64897+ struct acl_object_label *match;
64898+
64899+ match = subj->obj_hash[index];
64900+
64901+ while (match && (match->inode != oldinode ||
64902+ match->device != olddevice ||
64903+ !(match->mode & GR_DELETED)))
64904+ match = match->next;
64905+
64906+ if (match && (match->inode == oldinode)
64907+ && (match->device == olddevice)
64908+ && (match->mode & GR_DELETED)) {
64909+ if (match->prev == NULL) {
64910+ subj->obj_hash[index] = match->next;
64911+ if (match->next != NULL)
64912+ match->next->prev = NULL;
64913+ } else {
64914+ match->prev->next = match->next;
64915+ if (match->next != NULL)
64916+ match->next->prev = match->prev;
64917+ }
64918+ match->prev = NULL;
64919+ match->next = NULL;
64920+ match->inode = newinode;
64921+ match->device = newdevice;
64922+ match->mode &= ~GR_DELETED;
64923+
64924+ insert_acl_obj_label(match, subj);
64925+ }
64926+
64927+ return;
64928+}
64929+
64930+static void
64931+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64932+ const ino_t newinode, const dev_t newdevice,
64933+ struct acl_role_label *role)
64934+{
64935+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64936+ struct acl_subject_label *match;
64937+
64938+ match = role->subj_hash[index];
64939+
64940+ while (match && (match->inode != oldinode ||
64941+ match->device != olddevice ||
64942+ !(match->mode & GR_DELETED)))
64943+ match = match->next;
64944+
64945+ if (match && (match->inode == oldinode)
64946+ && (match->device == olddevice)
64947+ && (match->mode & GR_DELETED)) {
64948+ if (match->prev == NULL) {
64949+ role->subj_hash[index] = match->next;
64950+ if (match->next != NULL)
64951+ match->next->prev = NULL;
64952+ } else {
64953+ match->prev->next = match->next;
64954+ if (match->next != NULL)
64955+ match->next->prev = match->prev;
64956+ }
64957+ match->prev = NULL;
64958+ match->next = NULL;
64959+ match->inode = newinode;
64960+ match->device = newdevice;
64961+ match->mode &= ~GR_DELETED;
64962+
64963+ insert_acl_subj_label(match, role);
64964+ }
64965+
64966+ return;
64967+}
64968+
64969+static void
64970+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64971+ const ino_t newinode, const dev_t newdevice)
64972+{
64973+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
64974+ struct inodev_entry *match;
64975+
64976+ match = inodev_set.i_hash[index];
64977+
64978+ while (match && (match->nentry->inode != oldinode ||
64979+ match->nentry->device != olddevice || !match->nentry->deleted))
64980+ match = match->next;
64981+
64982+ if (match && (match->nentry->inode == oldinode)
64983+ && (match->nentry->device == olddevice) &&
64984+ match->nentry->deleted) {
64985+ if (match->prev == NULL) {
64986+ inodev_set.i_hash[index] = match->next;
64987+ if (match->next != NULL)
64988+ match->next->prev = NULL;
64989+ } else {
64990+ match->prev->next = match->next;
64991+ if (match->next != NULL)
64992+ match->next->prev = match->prev;
64993+ }
64994+ match->prev = NULL;
64995+ match->next = NULL;
64996+ match->nentry->inode = newinode;
64997+ match->nentry->device = newdevice;
64998+ match->nentry->deleted = 0;
64999+
65000+ insert_inodev_entry(match);
65001+ }
65002+
65003+ return;
65004+}
65005+
65006+static void
65007+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65008+{
65009+ struct acl_subject_label *subj;
65010+ struct acl_role_label *role;
65011+ unsigned int x;
65012+
65013+ FOR_EACH_ROLE_START(role)
65014+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65015+
65016+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65017+ if ((subj->inode == ino) && (subj->device == dev)) {
65018+ subj->inode = ino;
65019+ subj->device = dev;
65020+ }
65021+ /* nested subjects aren't in the role's subj_hash table */
65022+ update_acl_obj_label(matchn->inode, matchn->device,
65023+ ino, dev, subj);
65024+ FOR_EACH_NESTED_SUBJECT_END(subj)
65025+ FOR_EACH_SUBJECT_START(role, subj, x)
65026+ update_acl_obj_label(matchn->inode, matchn->device,
65027+ ino, dev, subj);
65028+ FOR_EACH_SUBJECT_END(subj,x)
65029+ FOR_EACH_ROLE_END(role)
65030+
65031+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65032+
65033+ return;
65034+}
65035+
65036+static void
65037+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65038+ const struct vfsmount *mnt)
65039+{
65040+ ino_t ino = dentry->d_inode->i_ino;
65041+ dev_t dev = __get_dev(dentry);
65042+
65043+ __do_handle_create(matchn, ino, dev);
65044+
65045+ return;
65046+}
65047+
65048+void
65049+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65050+{
65051+ struct name_entry *matchn;
65052+
65053+ if (unlikely(!(gr_status & GR_READY)))
65054+ return;
65055+
65056+ preempt_disable();
65057+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65058+
65059+ if (unlikely((unsigned long)matchn)) {
65060+ write_lock(&gr_inode_lock);
65061+ do_handle_create(matchn, dentry, mnt);
65062+ write_unlock(&gr_inode_lock);
65063+ }
65064+ preempt_enable();
65065+
65066+ return;
65067+}
65068+
65069+void
65070+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65071+{
65072+ struct name_entry *matchn;
65073+
65074+ if (unlikely(!(gr_status & GR_READY)))
65075+ return;
65076+
65077+ preempt_disable();
65078+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65079+
65080+ if (unlikely((unsigned long)matchn)) {
65081+ write_lock(&gr_inode_lock);
65082+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65083+ write_unlock(&gr_inode_lock);
65084+ }
65085+ preempt_enable();
65086+
65087+ return;
65088+}
65089+
65090+void
65091+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65092+ struct dentry *old_dentry,
65093+ struct dentry *new_dentry,
65094+ struct vfsmount *mnt, const __u8 replace)
65095+{
65096+ struct name_entry *matchn;
65097+ struct inodev_entry *inodev;
65098+ struct inode *inode = new_dentry->d_inode;
65099+ ino_t old_ino = old_dentry->d_inode->i_ino;
65100+ dev_t old_dev = __get_dev(old_dentry);
65101+
65102+ /* vfs_rename swaps the name and parent link for old_dentry and
65103+ new_dentry
65104+ at this point, old_dentry has the new name, parent link, and inode
65105+ for the renamed file
65106+ if a file is being replaced by a rename, new_dentry has the inode
65107+ and name for the replaced file
65108+ */
65109+
65110+ if (unlikely(!(gr_status & GR_READY)))
65111+ return;
65112+
65113+ preempt_disable();
65114+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65115+
65116+ /* we wouldn't have to check d_inode if it weren't for
65117+ NFS silly-renaming
65118+ */
65119+
65120+ write_lock(&gr_inode_lock);
65121+ if (unlikely(replace && inode)) {
65122+ ino_t new_ino = inode->i_ino;
65123+ dev_t new_dev = __get_dev(new_dentry);
65124+
65125+ inodev = lookup_inodev_entry(new_ino, new_dev);
65126+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65127+ do_handle_delete(inodev, new_ino, new_dev);
65128+ }
65129+
65130+ inodev = lookup_inodev_entry(old_ino, old_dev);
65131+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65132+ do_handle_delete(inodev, old_ino, old_dev);
65133+
65134+ if (unlikely((unsigned long)matchn))
65135+ do_handle_create(matchn, old_dentry, mnt);
65136+
65137+ write_unlock(&gr_inode_lock);
65138+ preempt_enable();
65139+
65140+ return;
65141+}
65142+
65143+static int
65144+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65145+ unsigned char **sum)
65146+{
65147+ struct acl_role_label *r;
65148+ struct role_allowed_ip *ipp;
65149+ struct role_transition *trans;
65150+ unsigned int i;
65151+ int found = 0;
65152+ u32 curr_ip = current->signal->curr_ip;
65153+
65154+ current->signal->saved_ip = curr_ip;
65155+
65156+ /* check transition table */
65157+
65158+ for (trans = current->role->transitions; trans; trans = trans->next) {
65159+ if (!strcmp(rolename, trans->rolename)) {
65160+ found = 1;
65161+ break;
65162+ }
65163+ }
65164+
65165+ if (!found)
65166+ return 0;
65167+
65168+ /* handle special roles that do not require authentication
65169+ and check ip */
65170+
65171+ FOR_EACH_ROLE_START(r)
65172+ if (!strcmp(rolename, r->rolename) &&
65173+ (r->roletype & GR_ROLE_SPECIAL)) {
65174+ found = 0;
65175+ if (r->allowed_ips != NULL) {
65176+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65177+ if ((ntohl(curr_ip) & ipp->netmask) ==
65178+ (ntohl(ipp->addr) & ipp->netmask))
65179+ found = 1;
65180+ }
65181+ } else
65182+ found = 2;
65183+ if (!found)
65184+ return 0;
65185+
65186+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65187+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65188+ *salt = NULL;
65189+ *sum = NULL;
65190+ return 1;
65191+ }
65192+ }
65193+ FOR_EACH_ROLE_END(r)
65194+
65195+ for (i = 0; i < num_sprole_pws; i++) {
65196+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65197+ *salt = acl_special_roles[i]->salt;
65198+ *sum = acl_special_roles[i]->sum;
65199+ return 1;
65200+ }
65201+ }
65202+
65203+ return 0;
65204+}
65205+
65206+static void
65207+assign_special_role(char *rolename)
65208+{
65209+ struct acl_object_label *obj;
65210+ struct acl_role_label *r;
65211+ struct acl_role_label *assigned = NULL;
65212+ struct task_struct *tsk;
65213+ struct file *filp;
65214+
65215+ FOR_EACH_ROLE_START(r)
65216+ if (!strcmp(rolename, r->rolename) &&
65217+ (r->roletype & GR_ROLE_SPECIAL)) {
65218+ assigned = r;
65219+ break;
65220+ }
65221+ FOR_EACH_ROLE_END(r)
65222+
65223+ if (!assigned)
65224+ return;
65225+
65226+ read_lock(&tasklist_lock);
65227+ read_lock(&grsec_exec_file_lock);
65228+
65229+ tsk = current->real_parent;
65230+ if (tsk == NULL)
65231+ goto out_unlock;
65232+
65233+ filp = tsk->exec_file;
65234+ if (filp == NULL)
65235+ goto out_unlock;
65236+
65237+ tsk->is_writable = 0;
65238+
65239+ tsk->acl_sp_role = 1;
65240+ tsk->acl_role_id = ++acl_sp_role_value;
65241+ tsk->role = assigned;
65242+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65243+
65244+ /* ignore additional mmap checks for processes that are writable
65245+ by the default ACL */
65246+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65247+ if (unlikely(obj->mode & GR_WRITE))
65248+ tsk->is_writable = 1;
65249+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65250+ if (unlikely(obj->mode & GR_WRITE))
65251+ tsk->is_writable = 1;
65252+
65253+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65254+ 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));
65255+#endif
65256+
65257+out_unlock:
65258+ read_unlock(&grsec_exec_file_lock);
65259+ read_unlock(&tasklist_lock);
65260+ return;
65261+}
65262+
65263+int gr_check_secure_terminal(struct task_struct *task)
65264+{
65265+ struct task_struct *p, *p2, *p3;
65266+ struct files_struct *files;
65267+ struct fdtable *fdt;
65268+ struct file *our_file = NULL, *file;
65269+ int i;
65270+
65271+ if (task->signal->tty == NULL)
65272+ return 1;
65273+
65274+ files = get_files_struct(task);
65275+ if (files != NULL) {
65276+ rcu_read_lock();
65277+ fdt = files_fdtable(files);
65278+ for (i=0; i < fdt->max_fds; i++) {
65279+ file = fcheck_files(files, i);
65280+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65281+ get_file(file);
65282+ our_file = file;
65283+ }
65284+ }
65285+ rcu_read_unlock();
65286+ put_files_struct(files);
65287+ }
65288+
65289+ if (our_file == NULL)
65290+ return 1;
65291+
65292+ read_lock(&tasklist_lock);
65293+ do_each_thread(p2, p) {
65294+ files = get_files_struct(p);
65295+ if (files == NULL ||
65296+ (p->signal && p->signal->tty == task->signal->tty)) {
65297+ if (files != NULL)
65298+ put_files_struct(files);
65299+ continue;
65300+ }
65301+ rcu_read_lock();
65302+ fdt = files_fdtable(files);
65303+ for (i=0; i < fdt->max_fds; i++) {
65304+ file = fcheck_files(files, i);
65305+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65306+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65307+ p3 = task;
65308+ while (task_pid_nr(p3) > 0) {
65309+ if (p3 == p)
65310+ break;
65311+ p3 = p3->real_parent;
65312+ }
65313+ if (p3 == p)
65314+ break;
65315+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65316+ gr_handle_alertkill(p);
65317+ rcu_read_unlock();
65318+ put_files_struct(files);
65319+ read_unlock(&tasklist_lock);
65320+ fput(our_file);
65321+ return 0;
65322+ }
65323+ }
65324+ rcu_read_unlock();
65325+ put_files_struct(files);
65326+ } while_each_thread(p2, p);
65327+ read_unlock(&tasklist_lock);
65328+
65329+ fput(our_file);
65330+ return 1;
65331+}
65332+
65333+static int gr_rbac_disable(void *unused)
65334+{
65335+ pax_open_kernel();
65336+ gr_status &= ~GR_READY;
65337+ pax_close_kernel();
65338+
65339+ return 0;
65340+}
65341+
65342+ssize_t
65343+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65344+{
65345+ struct gr_arg_wrapper uwrap;
65346+ unsigned char *sprole_salt = NULL;
65347+ unsigned char *sprole_sum = NULL;
65348+ int error = 0;
65349+ int error2 = 0;
65350+ size_t req_count = 0;
65351+
65352+ mutex_lock(&gr_dev_mutex);
65353+
65354+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65355+ error = -EPERM;
65356+ goto out;
65357+ }
65358+
65359+#ifdef CONFIG_COMPAT
65360+ pax_open_kernel();
65361+ if (is_compat_task()) {
65362+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65363+ copy_gr_arg = &copy_gr_arg_compat;
65364+ copy_acl_object_label = &copy_acl_object_label_compat;
65365+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65366+ copy_acl_role_label = &copy_acl_role_label_compat;
65367+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65368+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65369+ copy_role_transition = &copy_role_transition_compat;
65370+ copy_sprole_pw = &copy_sprole_pw_compat;
65371+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65372+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65373+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65374+ } else {
65375+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65376+ copy_gr_arg = &copy_gr_arg_normal;
65377+ copy_acl_object_label = &copy_acl_object_label_normal;
65378+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65379+ copy_acl_role_label = &copy_acl_role_label_normal;
65380+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65381+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65382+ copy_role_transition = &copy_role_transition_normal;
65383+ copy_sprole_pw = &copy_sprole_pw_normal;
65384+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65385+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65386+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65387+ }
65388+ pax_close_kernel();
65389+#endif
65390+
65391+ req_count = get_gr_arg_wrapper_size();
65392+
65393+ if (count != req_count) {
65394+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65395+ error = -EINVAL;
65396+ goto out;
65397+ }
65398+
65399+
65400+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65401+ gr_auth_expires = 0;
65402+ gr_auth_attempts = 0;
65403+ }
65404+
65405+ error = copy_gr_arg_wrapper(buf, &uwrap);
65406+ if (error)
65407+ goto out;
65408+
65409+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65410+ if (error)
65411+ goto out;
65412+
65413+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65414+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65415+ time_after(gr_auth_expires, get_seconds())) {
65416+ error = -EBUSY;
65417+ goto out;
65418+ }
65419+
65420+ /* if non-root trying to do anything other than use a special role,
65421+ do not attempt authentication, do not count towards authentication
65422+ locking
65423+ */
65424+
65425+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65426+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65427+ gr_is_global_nonroot(current_uid())) {
65428+ error = -EPERM;
65429+ goto out;
65430+ }
65431+
65432+ /* ensure pw and special role name are null terminated */
65433+
65434+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65435+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65436+
65437+ /* Okay.
65438+ * We have our enough of the argument structure..(we have yet
65439+ * to copy_from_user the tables themselves) . Copy the tables
65440+ * only if we need them, i.e. for loading operations. */
65441+
65442+ switch (gr_usermode->mode) {
65443+ case GR_STATUS:
65444+ if (gr_status & GR_READY) {
65445+ error = 1;
65446+ if (!gr_check_secure_terminal(current))
65447+ error = 3;
65448+ } else
65449+ error = 2;
65450+ goto out;
65451+ case GR_SHUTDOWN:
65452+ if ((gr_status & GR_READY)
65453+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65454+ stop_machine(gr_rbac_disable, NULL, NULL);
65455+ free_variables();
65456+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65457+ memset(gr_system_salt, 0, GR_SALT_LEN);
65458+ memset(gr_system_sum, 0, GR_SHA_LEN);
65459+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65460+ } else if (gr_status & GR_READY) {
65461+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65462+ error = -EPERM;
65463+ } else {
65464+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65465+ error = -EAGAIN;
65466+ }
65467+ break;
65468+ case GR_ENABLE:
65469+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65470+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65471+ else {
65472+ if (gr_status & GR_READY)
65473+ error = -EAGAIN;
65474+ else
65475+ error = error2;
65476+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65477+ }
65478+ break;
65479+ case GR_RELOAD:
65480+ if (!(gr_status & GR_READY)) {
65481+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65482+ error = -EAGAIN;
65483+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65484+ stop_machine(gr_rbac_disable, NULL, NULL);
65485+ free_variables();
65486+ error2 = gracl_init(gr_usermode);
65487+ if (!error2)
65488+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65489+ else {
65490+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65491+ error = error2;
65492+ }
65493+ } else {
65494+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65495+ error = -EPERM;
65496+ }
65497+ break;
65498+ case GR_SEGVMOD:
65499+ if (unlikely(!(gr_status & GR_READY))) {
65500+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65501+ error = -EAGAIN;
65502+ break;
65503+ }
65504+
65505+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65506+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65507+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65508+ struct acl_subject_label *segvacl;
65509+ segvacl =
65510+ lookup_acl_subj_label(gr_usermode->segv_inode,
65511+ gr_usermode->segv_device,
65512+ current->role);
65513+ if (segvacl) {
65514+ segvacl->crashes = 0;
65515+ segvacl->expires = 0;
65516+ }
65517+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65518+ gr_remove_uid(gr_usermode->segv_uid);
65519+ }
65520+ } else {
65521+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65522+ error = -EPERM;
65523+ }
65524+ break;
65525+ case GR_SPROLE:
65526+ case GR_SPROLEPAM:
65527+ if (unlikely(!(gr_status & GR_READY))) {
65528+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65529+ error = -EAGAIN;
65530+ break;
65531+ }
65532+
65533+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65534+ current->role->expires = 0;
65535+ current->role->auth_attempts = 0;
65536+ }
65537+
65538+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65539+ time_after(current->role->expires, get_seconds())) {
65540+ error = -EBUSY;
65541+ goto out;
65542+ }
65543+
65544+ if (lookup_special_role_auth
65545+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65546+ && ((!sprole_salt && !sprole_sum)
65547+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65548+ char *p = "";
65549+ assign_special_role(gr_usermode->sp_role);
65550+ read_lock(&tasklist_lock);
65551+ if (current->real_parent)
65552+ p = current->real_parent->role->rolename;
65553+ read_unlock(&tasklist_lock);
65554+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65555+ p, acl_sp_role_value);
65556+ } else {
65557+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65558+ error = -EPERM;
65559+ if(!(current->role->auth_attempts++))
65560+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65561+
65562+ goto out;
65563+ }
65564+ break;
65565+ case GR_UNSPROLE:
65566+ if (unlikely(!(gr_status & GR_READY))) {
65567+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65568+ error = -EAGAIN;
65569+ break;
65570+ }
65571+
65572+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65573+ char *p = "";
65574+ int i = 0;
65575+
65576+ read_lock(&tasklist_lock);
65577+ if (current->real_parent) {
65578+ p = current->real_parent->role->rolename;
65579+ i = current->real_parent->acl_role_id;
65580+ }
65581+ read_unlock(&tasklist_lock);
65582+
65583+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65584+ gr_set_acls(1);
65585+ } else {
65586+ error = -EPERM;
65587+ goto out;
65588+ }
65589+ break;
65590+ default:
65591+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65592+ error = -EINVAL;
65593+ break;
65594+ }
65595+
65596+ if (error != -EPERM)
65597+ goto out;
65598+
65599+ if(!(gr_auth_attempts++))
65600+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65601+
65602+ out:
65603+ mutex_unlock(&gr_dev_mutex);
65604+
65605+ if (!error)
65606+ error = req_count;
65607+
65608+ return error;
65609+}
65610+
65611+/* must be called with
65612+ rcu_read_lock();
65613+ read_lock(&tasklist_lock);
65614+ read_lock(&grsec_exec_file_lock);
65615+*/
65616+int gr_apply_subject_to_task(struct task_struct *task)
65617+{
65618+ struct acl_object_label *obj;
65619+ char *tmpname;
65620+ struct acl_subject_label *tmpsubj;
65621+ struct file *filp;
65622+ struct name_entry *nmatch;
65623+
65624+ filp = task->exec_file;
65625+ if (filp == NULL)
65626+ return 0;
65627+
65628+ /* the following is to apply the correct subject
65629+ on binaries running when the RBAC system
65630+ is enabled, when the binaries have been
65631+ replaced or deleted since their execution
65632+ -----
65633+ when the RBAC system starts, the inode/dev
65634+ from exec_file will be one the RBAC system
65635+ is unaware of. It only knows the inode/dev
65636+ of the present file on disk, or the absence
65637+ of it.
65638+ */
65639+ preempt_disable();
65640+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65641+
65642+ nmatch = lookup_name_entry(tmpname);
65643+ preempt_enable();
65644+ tmpsubj = NULL;
65645+ if (nmatch) {
65646+ if (nmatch->deleted)
65647+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65648+ else
65649+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65650+ if (tmpsubj != NULL)
65651+ task->acl = tmpsubj;
65652+ }
65653+ if (tmpsubj == NULL)
65654+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65655+ task->role);
65656+ if (task->acl) {
65657+ task->is_writable = 0;
65658+ /* ignore additional mmap checks for processes that are writable
65659+ by the default ACL */
65660+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65661+ if (unlikely(obj->mode & GR_WRITE))
65662+ task->is_writable = 1;
65663+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65664+ if (unlikely(obj->mode & GR_WRITE))
65665+ task->is_writable = 1;
65666+
65667+ gr_set_proc_res(task);
65668+
65669+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65670+ 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);
65671+#endif
65672+ } else {
65673+ return 1;
65674+ }
65675+
65676+ return 0;
65677+}
65678+
65679+int
65680+gr_set_acls(const int type)
65681+{
65682+ struct task_struct *task, *task2;
65683+ struct acl_role_label *role = current->role;
65684+ __u16 acl_role_id = current->acl_role_id;
65685+ const struct cred *cred;
65686+ int ret;
65687+
65688+ rcu_read_lock();
65689+ read_lock(&tasklist_lock);
65690+ read_lock(&grsec_exec_file_lock);
65691+ do_each_thread(task2, task) {
65692+ /* check to see if we're called from the exit handler,
65693+ if so, only replace ACLs that have inherited the admin
65694+ ACL */
65695+
65696+ if (type && (task->role != role ||
65697+ task->acl_role_id != acl_role_id))
65698+ continue;
65699+
65700+ task->acl_role_id = 0;
65701+ task->acl_sp_role = 0;
65702+
65703+ if (task->exec_file) {
65704+ cred = __task_cred(task);
65705+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65706+ ret = gr_apply_subject_to_task(task);
65707+ if (ret) {
65708+ read_unlock(&grsec_exec_file_lock);
65709+ read_unlock(&tasklist_lock);
65710+ rcu_read_unlock();
65711+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65712+ return ret;
65713+ }
65714+ } else {
65715+ // it's a kernel process
65716+ task->role = kernel_role;
65717+ task->acl = kernel_role->root_label;
65718+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65719+ task->acl->mode &= ~GR_PROCFIND;
65720+#endif
65721+ }
65722+ } while_each_thread(task2, task);
65723+ read_unlock(&grsec_exec_file_lock);
65724+ read_unlock(&tasklist_lock);
65725+ rcu_read_unlock();
65726+
65727+ return 0;
65728+}
65729+
65730+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65731+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65732+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65733+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65734+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65735+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65736+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65737+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65738+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65739+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65740+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65741+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65742+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65743+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65744+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65745+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65746+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65747+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65748+};
65749+
65750+void
65751+gr_learn_resource(const struct task_struct *task,
65752+ const int res, const unsigned long wanted, const int gt)
65753+{
65754+ struct acl_subject_label *acl;
65755+ const struct cred *cred;
65756+
65757+ if (unlikely((gr_status & GR_READY) &&
65758+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65759+ goto skip_reslog;
65760+
65761+ gr_log_resource(task, res, wanted, gt);
65762+skip_reslog:
65763+
65764+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65765+ return;
65766+
65767+ acl = task->acl;
65768+
65769+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65770+ !(acl->resmask & (1U << (unsigned short) res))))
65771+ return;
65772+
65773+ if (wanted >= acl->res[res].rlim_cur) {
65774+ unsigned long res_add;
65775+
65776+ res_add = wanted + res_learn_bumps[res];
65777+
65778+ acl->res[res].rlim_cur = res_add;
65779+
65780+ if (wanted > acl->res[res].rlim_max)
65781+ acl->res[res].rlim_max = res_add;
65782+
65783+ /* only log the subject filename, since resource logging is supported for
65784+ single-subject learning only */
65785+ rcu_read_lock();
65786+ cred = __task_cred(task);
65787+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65788+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65789+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65790+ "", (unsigned long) res, &task->signal->saved_ip);
65791+ rcu_read_unlock();
65792+ }
65793+
65794+ return;
65795+}
65796+EXPORT_SYMBOL(gr_learn_resource);
65797+#endif
65798+
65799+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65800+void
65801+pax_set_initial_flags(struct linux_binprm *bprm)
65802+{
65803+ struct task_struct *task = current;
65804+ struct acl_subject_label *proc;
65805+ unsigned long flags;
65806+
65807+ if (unlikely(!(gr_status & GR_READY)))
65808+ return;
65809+
65810+ flags = pax_get_flags(task);
65811+
65812+ proc = task->acl;
65813+
65814+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65815+ flags &= ~MF_PAX_PAGEEXEC;
65816+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65817+ flags &= ~MF_PAX_SEGMEXEC;
65818+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65819+ flags &= ~MF_PAX_RANDMMAP;
65820+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65821+ flags &= ~MF_PAX_EMUTRAMP;
65822+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65823+ flags &= ~MF_PAX_MPROTECT;
65824+
65825+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65826+ flags |= MF_PAX_PAGEEXEC;
65827+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65828+ flags |= MF_PAX_SEGMEXEC;
65829+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65830+ flags |= MF_PAX_RANDMMAP;
65831+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65832+ flags |= MF_PAX_EMUTRAMP;
65833+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65834+ flags |= MF_PAX_MPROTECT;
65835+
65836+ pax_set_flags(task, flags);
65837+
65838+ return;
65839+}
65840+#endif
65841+
65842+int
65843+gr_handle_proc_ptrace(struct task_struct *task)
65844+{
65845+ struct file *filp;
65846+ struct task_struct *tmp = task;
65847+ struct task_struct *curtemp = current;
65848+ __u32 retmode;
65849+
65850+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65851+ if (unlikely(!(gr_status & GR_READY)))
65852+ return 0;
65853+#endif
65854+
65855+ read_lock(&tasklist_lock);
65856+ read_lock(&grsec_exec_file_lock);
65857+ filp = task->exec_file;
65858+
65859+ while (task_pid_nr(tmp) > 0) {
65860+ if (tmp == curtemp)
65861+ break;
65862+ tmp = tmp->real_parent;
65863+ }
65864+
65865+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65866+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65867+ read_unlock(&grsec_exec_file_lock);
65868+ read_unlock(&tasklist_lock);
65869+ return 1;
65870+ }
65871+
65872+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65873+ if (!(gr_status & GR_READY)) {
65874+ read_unlock(&grsec_exec_file_lock);
65875+ read_unlock(&tasklist_lock);
65876+ return 0;
65877+ }
65878+#endif
65879+
65880+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65881+ read_unlock(&grsec_exec_file_lock);
65882+ read_unlock(&tasklist_lock);
65883+
65884+ if (retmode & GR_NOPTRACE)
65885+ return 1;
65886+
65887+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65888+ && (current->acl != task->acl || (current->acl != current->role->root_label
65889+ && task_pid_nr(current) != task_pid_nr(task))))
65890+ return 1;
65891+
65892+ return 0;
65893+}
65894+
65895+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65896+{
65897+ if (unlikely(!(gr_status & GR_READY)))
65898+ return;
65899+
65900+ if (!(current->role->roletype & GR_ROLE_GOD))
65901+ return;
65902+
65903+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65904+ p->role->rolename, gr_task_roletype_to_char(p),
65905+ p->acl->filename);
65906+}
65907+
65908+int
65909+gr_handle_ptrace(struct task_struct *task, const long request)
65910+{
65911+ struct task_struct *tmp = task;
65912+ struct task_struct *curtemp = current;
65913+ __u32 retmode;
65914+
65915+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65916+ if (unlikely(!(gr_status & GR_READY)))
65917+ return 0;
65918+#endif
65919+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65920+ read_lock(&tasklist_lock);
65921+ while (task_pid_nr(tmp) > 0) {
65922+ if (tmp == curtemp)
65923+ break;
65924+ tmp = tmp->real_parent;
65925+ }
65926+
65927+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65928+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65929+ read_unlock(&tasklist_lock);
65930+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65931+ return 1;
65932+ }
65933+ read_unlock(&tasklist_lock);
65934+ }
65935+
65936+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65937+ if (!(gr_status & GR_READY))
65938+ return 0;
65939+#endif
65940+
65941+ read_lock(&grsec_exec_file_lock);
65942+ if (unlikely(!task->exec_file)) {
65943+ read_unlock(&grsec_exec_file_lock);
65944+ return 0;
65945+ }
65946+
65947+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65948+ read_unlock(&grsec_exec_file_lock);
65949+
65950+ if (retmode & GR_NOPTRACE) {
65951+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65952+ return 1;
65953+ }
65954+
65955+ if (retmode & GR_PTRACERD) {
65956+ switch (request) {
65957+ case PTRACE_SEIZE:
65958+ case PTRACE_POKETEXT:
65959+ case PTRACE_POKEDATA:
65960+ case PTRACE_POKEUSR:
65961+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65962+ case PTRACE_SETREGS:
65963+ case PTRACE_SETFPREGS:
65964+#endif
65965+#ifdef CONFIG_X86
65966+ case PTRACE_SETFPXREGS:
65967+#endif
65968+#ifdef CONFIG_ALTIVEC
65969+ case PTRACE_SETVRREGS:
65970+#endif
65971+ return 1;
65972+ default:
65973+ return 0;
65974+ }
65975+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65976+ !(current->role->roletype & GR_ROLE_GOD) &&
65977+ (current->acl != task->acl)) {
65978+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65979+ return 1;
65980+ }
65981+
65982+ return 0;
65983+}
65984+
65985+static int is_writable_mmap(const struct file *filp)
65986+{
65987+ struct task_struct *task = current;
65988+ struct acl_object_label *obj, *obj2;
65989+
65990+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
65991+ !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))) {
65992+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65993+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
65994+ task->role->root_label);
65995+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
65996+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
65997+ return 1;
65998+ }
65999+ }
66000+ return 0;
66001+}
66002+
66003+int
66004+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66005+{
66006+ __u32 mode;
66007+
66008+ if (unlikely(!file || !(prot & PROT_EXEC)))
66009+ return 1;
66010+
66011+ if (is_writable_mmap(file))
66012+ return 0;
66013+
66014+ mode =
66015+ gr_search_file(file->f_path.dentry,
66016+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66017+ file->f_path.mnt);
66018+
66019+ if (!gr_tpe_allow(file))
66020+ return 0;
66021+
66022+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66023+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66024+ return 0;
66025+ } else if (unlikely(!(mode & GR_EXEC))) {
66026+ return 0;
66027+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66028+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66029+ return 1;
66030+ }
66031+
66032+ return 1;
66033+}
66034+
66035+int
66036+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66037+{
66038+ __u32 mode;
66039+
66040+ if (unlikely(!file || !(prot & PROT_EXEC)))
66041+ return 1;
66042+
66043+ if (is_writable_mmap(file))
66044+ return 0;
66045+
66046+ mode =
66047+ gr_search_file(file->f_path.dentry,
66048+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66049+ file->f_path.mnt);
66050+
66051+ if (!gr_tpe_allow(file))
66052+ return 0;
66053+
66054+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66055+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66056+ return 0;
66057+ } else if (unlikely(!(mode & GR_EXEC))) {
66058+ return 0;
66059+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66060+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66061+ return 1;
66062+ }
66063+
66064+ return 1;
66065+}
66066+
66067+void
66068+gr_acl_handle_psacct(struct task_struct *task, const long code)
66069+{
66070+ unsigned long runtime;
66071+ unsigned long cputime;
66072+ unsigned int wday, cday;
66073+ __u8 whr, chr;
66074+ __u8 wmin, cmin;
66075+ __u8 wsec, csec;
66076+ struct timespec timeval;
66077+
66078+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66079+ !(task->acl->mode & GR_PROCACCT)))
66080+ return;
66081+
66082+ do_posix_clock_monotonic_gettime(&timeval);
66083+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66084+ wday = runtime / (3600 * 24);
66085+ runtime -= wday * (3600 * 24);
66086+ whr = runtime / 3600;
66087+ runtime -= whr * 3600;
66088+ wmin = runtime / 60;
66089+ runtime -= wmin * 60;
66090+ wsec = runtime;
66091+
66092+ cputime = (task->utime + task->stime) / HZ;
66093+ cday = cputime / (3600 * 24);
66094+ cputime -= cday * (3600 * 24);
66095+ chr = cputime / 3600;
66096+ cputime -= chr * 3600;
66097+ cmin = cputime / 60;
66098+ cputime -= cmin * 60;
66099+ csec = cputime;
66100+
66101+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66102+
66103+ return;
66104+}
66105+
66106+void gr_set_kernel_label(struct task_struct *task)
66107+{
66108+ if (gr_status & GR_READY) {
66109+ task->role = kernel_role;
66110+ task->acl = kernel_role->root_label;
66111+ }
66112+ return;
66113+}
66114+
66115+#ifdef CONFIG_TASKSTATS
66116+int gr_is_taskstats_denied(int pid)
66117+{
66118+ struct task_struct *task;
66119+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66120+ const struct cred *cred;
66121+#endif
66122+ int ret = 0;
66123+
66124+ /* restrict taskstats viewing to un-chrooted root users
66125+ who have the 'view' subject flag if the RBAC system is enabled
66126+ */
66127+
66128+ rcu_read_lock();
66129+ read_lock(&tasklist_lock);
66130+ task = find_task_by_vpid(pid);
66131+ if (task) {
66132+#ifdef CONFIG_GRKERNSEC_CHROOT
66133+ if (proc_is_chrooted(task))
66134+ ret = -EACCES;
66135+#endif
66136+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66137+ cred = __task_cred(task);
66138+#ifdef CONFIG_GRKERNSEC_PROC_USER
66139+ if (gr_is_global_nonroot(cred->uid))
66140+ ret = -EACCES;
66141+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66142+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66143+ ret = -EACCES;
66144+#endif
66145+#endif
66146+ if (gr_status & GR_READY) {
66147+ if (!(task->acl->mode & GR_VIEW))
66148+ ret = -EACCES;
66149+ }
66150+ } else
66151+ ret = -ENOENT;
66152+
66153+ read_unlock(&tasklist_lock);
66154+ rcu_read_unlock();
66155+
66156+ return ret;
66157+}
66158+#endif
66159+
66160+/* AUXV entries are filled via a descendant of search_binary_handler
66161+ after we've already applied the subject for the target
66162+*/
66163+int gr_acl_enable_at_secure(void)
66164+{
66165+ if (unlikely(!(gr_status & GR_READY)))
66166+ return 0;
66167+
66168+ if (current->acl->mode & GR_ATSECURE)
66169+ return 1;
66170+
66171+ return 0;
66172+}
66173+
66174+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66175+{
66176+ struct task_struct *task = current;
66177+ struct dentry *dentry = file->f_path.dentry;
66178+ struct vfsmount *mnt = file->f_path.mnt;
66179+ struct acl_object_label *obj, *tmp;
66180+ struct acl_subject_label *subj;
66181+ unsigned int bufsize;
66182+ int is_not_root;
66183+ char *path;
66184+ dev_t dev = __get_dev(dentry);
66185+
66186+ if (unlikely(!(gr_status & GR_READY)))
66187+ return 1;
66188+
66189+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66190+ return 1;
66191+
66192+ /* ignore Eric Biederman */
66193+ if (IS_PRIVATE(dentry->d_inode))
66194+ return 1;
66195+
66196+ subj = task->acl;
66197+ read_lock(&gr_inode_lock);
66198+ do {
66199+ obj = lookup_acl_obj_label(ino, dev, subj);
66200+ if (obj != NULL) {
66201+ read_unlock(&gr_inode_lock);
66202+ return (obj->mode & GR_FIND) ? 1 : 0;
66203+ }
66204+ } while ((subj = subj->parent_subject));
66205+ read_unlock(&gr_inode_lock);
66206+
66207+ /* this is purely an optimization since we're looking for an object
66208+ for the directory we're doing a readdir on
66209+ if it's possible for any globbed object to match the entry we're
66210+ filling into the directory, then the object we find here will be
66211+ an anchor point with attached globbed objects
66212+ */
66213+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66214+ if (obj->globbed == NULL)
66215+ return (obj->mode & GR_FIND) ? 1 : 0;
66216+
66217+ is_not_root = ((obj->filename[0] == '/') &&
66218+ (obj->filename[1] == '\0')) ? 0 : 1;
66219+ bufsize = PAGE_SIZE - namelen - is_not_root;
66220+
66221+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66222+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66223+ return 1;
66224+
66225+ preempt_disable();
66226+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66227+ bufsize);
66228+
66229+ bufsize = strlen(path);
66230+
66231+ /* if base is "/", don't append an additional slash */
66232+ if (is_not_root)
66233+ *(path + bufsize) = '/';
66234+ memcpy(path + bufsize + is_not_root, name, namelen);
66235+ *(path + bufsize + namelen + is_not_root) = '\0';
66236+
66237+ tmp = obj->globbed;
66238+ while (tmp) {
66239+ if (!glob_match(tmp->filename, path)) {
66240+ preempt_enable();
66241+ return (tmp->mode & GR_FIND) ? 1 : 0;
66242+ }
66243+ tmp = tmp->next;
66244+ }
66245+ preempt_enable();
66246+ return (obj->mode & GR_FIND) ? 1 : 0;
66247+}
66248+
66249+void gr_put_exec_file(struct task_struct *task)
66250+{
66251+ struct file *filp;
66252+
66253+ write_lock(&grsec_exec_file_lock);
66254+ filp = task->exec_file;
66255+ task->exec_file = NULL;
66256+ write_unlock(&grsec_exec_file_lock);
66257+
66258+ if (filp)
66259+ fput(filp);
66260+
66261+ return;
66262+}
66263+
66264+
66265+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66266+EXPORT_SYMBOL(gr_acl_is_enabled);
66267+#endif
66268+EXPORT_SYMBOL(gr_set_kernel_label);
66269+#ifdef CONFIG_SECURITY
66270+EXPORT_SYMBOL(gr_check_user_change);
66271+EXPORT_SYMBOL(gr_check_group_change);
66272+#endif
66273+
66274diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66275new file mode 100644
66276index 0000000..34fefda
66277--- /dev/null
66278+++ b/grsecurity/gracl_alloc.c
66279@@ -0,0 +1,105 @@
66280+#include <linux/kernel.h>
66281+#include <linux/mm.h>
66282+#include <linux/slab.h>
66283+#include <linux/vmalloc.h>
66284+#include <linux/gracl.h>
66285+#include <linux/grsecurity.h>
66286+
66287+static unsigned long alloc_stack_next = 1;
66288+static unsigned long alloc_stack_size = 1;
66289+static void **alloc_stack;
66290+
66291+static __inline__ int
66292+alloc_pop(void)
66293+{
66294+ if (alloc_stack_next == 1)
66295+ return 0;
66296+
66297+ kfree(alloc_stack[alloc_stack_next - 2]);
66298+
66299+ alloc_stack_next--;
66300+
66301+ return 1;
66302+}
66303+
66304+static __inline__ int
66305+alloc_push(void *buf)
66306+{
66307+ if (alloc_stack_next >= alloc_stack_size)
66308+ return 1;
66309+
66310+ alloc_stack[alloc_stack_next - 1] = buf;
66311+
66312+ alloc_stack_next++;
66313+
66314+ return 0;
66315+}
66316+
66317+void *
66318+acl_alloc(unsigned long len)
66319+{
66320+ void *ret = NULL;
66321+
66322+ if (!len || len > PAGE_SIZE)
66323+ goto out;
66324+
66325+ ret = kmalloc(len, GFP_KERNEL);
66326+
66327+ if (ret) {
66328+ if (alloc_push(ret)) {
66329+ kfree(ret);
66330+ ret = NULL;
66331+ }
66332+ }
66333+
66334+out:
66335+ return ret;
66336+}
66337+
66338+void *
66339+acl_alloc_num(unsigned long num, unsigned long len)
66340+{
66341+ if (!len || (num > (PAGE_SIZE / len)))
66342+ return NULL;
66343+
66344+ return acl_alloc(num * len);
66345+}
66346+
66347+void
66348+acl_free_all(void)
66349+{
66350+ if (gr_acl_is_enabled() || !alloc_stack)
66351+ return;
66352+
66353+ while (alloc_pop()) ;
66354+
66355+ if (alloc_stack) {
66356+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66357+ kfree(alloc_stack);
66358+ else
66359+ vfree(alloc_stack);
66360+ }
66361+
66362+ alloc_stack = NULL;
66363+ alloc_stack_size = 1;
66364+ alloc_stack_next = 1;
66365+
66366+ return;
66367+}
66368+
66369+int
66370+acl_alloc_stack_init(unsigned long size)
66371+{
66372+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66373+ alloc_stack =
66374+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66375+ else
66376+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66377+
66378+ alloc_stack_size = size;
66379+
66380+ if (!alloc_stack)
66381+ return 0;
66382+ else
66383+ return 1;
66384+}
66385diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66386new file mode 100644
66387index 0000000..bdd51ea
66388--- /dev/null
66389+++ b/grsecurity/gracl_cap.c
66390@@ -0,0 +1,110 @@
66391+#include <linux/kernel.h>
66392+#include <linux/module.h>
66393+#include <linux/sched.h>
66394+#include <linux/gracl.h>
66395+#include <linux/grsecurity.h>
66396+#include <linux/grinternal.h>
66397+
66398+extern const char *captab_log[];
66399+extern int captab_log_entries;
66400+
66401+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66402+{
66403+ struct acl_subject_label *curracl;
66404+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66405+ kernel_cap_t cap_audit = __cap_empty_set;
66406+
66407+ if (!gr_acl_is_enabled())
66408+ return 1;
66409+
66410+ curracl = task->acl;
66411+
66412+ cap_drop = curracl->cap_lower;
66413+ cap_mask = curracl->cap_mask;
66414+ cap_audit = curracl->cap_invert_audit;
66415+
66416+ while ((curracl = curracl->parent_subject)) {
66417+ /* if the cap isn't specified in the current computed mask but is specified in the
66418+ current level subject, and is lowered in the current level subject, then add
66419+ it to the set of dropped capabilities
66420+ otherwise, add the current level subject's mask to the current computed mask
66421+ */
66422+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66423+ cap_raise(cap_mask, cap);
66424+ if (cap_raised(curracl->cap_lower, cap))
66425+ cap_raise(cap_drop, cap);
66426+ if (cap_raised(curracl->cap_invert_audit, cap))
66427+ cap_raise(cap_audit, cap);
66428+ }
66429+ }
66430+
66431+ if (!cap_raised(cap_drop, cap)) {
66432+ if (cap_raised(cap_audit, cap))
66433+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66434+ return 1;
66435+ }
66436+
66437+ curracl = task->acl;
66438+
66439+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66440+ && cap_raised(cred->cap_effective, cap)) {
66441+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66442+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66443+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66444+ gr_to_filename(task->exec_file->f_path.dentry,
66445+ task->exec_file->f_path.mnt) : curracl->filename,
66446+ curracl->filename, 0UL,
66447+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66448+ return 1;
66449+ }
66450+
66451+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66452+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66453+
66454+ return 0;
66455+}
66456+
66457+int
66458+gr_acl_is_capable(const int cap)
66459+{
66460+ return gr_task_acl_is_capable(current, current_cred(), cap);
66461+}
66462+
66463+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66464+{
66465+ struct acl_subject_label *curracl;
66466+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66467+
66468+ if (!gr_acl_is_enabled())
66469+ return 1;
66470+
66471+ curracl = task->acl;
66472+
66473+ cap_drop = curracl->cap_lower;
66474+ cap_mask = curracl->cap_mask;
66475+
66476+ while ((curracl = curracl->parent_subject)) {
66477+ /* if the cap isn't specified in the current computed mask but is specified in the
66478+ current level subject, and is lowered in the current level subject, then add
66479+ it to the set of dropped capabilities
66480+ otherwise, add the current level subject's mask to the current computed mask
66481+ */
66482+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66483+ cap_raise(cap_mask, cap);
66484+ if (cap_raised(curracl->cap_lower, cap))
66485+ cap_raise(cap_drop, cap);
66486+ }
66487+ }
66488+
66489+ if (!cap_raised(cap_drop, cap))
66490+ return 1;
66491+
66492+ return 0;
66493+}
66494+
66495+int
66496+gr_acl_is_capable_nolog(const int cap)
66497+{
66498+ return gr_task_acl_is_capable_nolog(current, cap);
66499+}
66500+
66501diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66502new file mode 100644
66503index 0000000..a43dd06
66504--- /dev/null
66505+++ b/grsecurity/gracl_compat.c
66506@@ -0,0 +1,269 @@
66507+#include <linux/kernel.h>
66508+#include <linux/gracl.h>
66509+#include <linux/compat.h>
66510+#include <linux/gracl_compat.h>
66511+
66512+#include <asm/uaccess.h>
66513+
66514+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66515+{
66516+ struct gr_arg_wrapper_compat uwrapcompat;
66517+
66518+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66519+ return -EFAULT;
66520+
66521+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66522+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66523+ return -EINVAL;
66524+
66525+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66526+ uwrap->version = uwrapcompat.version;
66527+ uwrap->size = sizeof(struct gr_arg);
66528+
66529+ return 0;
66530+}
66531+
66532+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66533+{
66534+ struct gr_arg_compat argcompat;
66535+
66536+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66537+ return -EFAULT;
66538+
66539+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66540+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66541+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66542+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66543+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66544+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66545+
66546+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66547+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66548+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66549+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66550+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66551+ arg->segv_device = argcompat.segv_device;
66552+ arg->segv_inode = argcompat.segv_inode;
66553+ arg->segv_uid = argcompat.segv_uid;
66554+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66555+ arg->mode = argcompat.mode;
66556+
66557+ return 0;
66558+}
66559+
66560+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66561+{
66562+ struct acl_object_label_compat objcompat;
66563+
66564+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66565+ return -EFAULT;
66566+
66567+ obj->filename = compat_ptr(objcompat.filename);
66568+ obj->inode = objcompat.inode;
66569+ obj->device = objcompat.device;
66570+ obj->mode = objcompat.mode;
66571+
66572+ obj->nested = compat_ptr(objcompat.nested);
66573+ obj->globbed = compat_ptr(objcompat.globbed);
66574+
66575+ obj->prev = compat_ptr(objcompat.prev);
66576+ obj->next = compat_ptr(objcompat.next);
66577+
66578+ return 0;
66579+}
66580+
66581+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66582+{
66583+ unsigned int i;
66584+ struct acl_subject_label_compat subjcompat;
66585+
66586+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66587+ return -EFAULT;
66588+
66589+ subj->filename = compat_ptr(subjcompat.filename);
66590+ subj->inode = subjcompat.inode;
66591+ subj->device = subjcompat.device;
66592+ subj->mode = subjcompat.mode;
66593+ subj->cap_mask = subjcompat.cap_mask;
66594+ subj->cap_lower = subjcompat.cap_lower;
66595+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66596+
66597+ for (i = 0; i < GR_NLIMITS; i++) {
66598+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66599+ subj->res[i].rlim_cur = RLIM_INFINITY;
66600+ else
66601+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66602+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66603+ subj->res[i].rlim_max = RLIM_INFINITY;
66604+ else
66605+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66606+ }
66607+ subj->resmask = subjcompat.resmask;
66608+
66609+ subj->user_trans_type = subjcompat.user_trans_type;
66610+ subj->group_trans_type = subjcompat.group_trans_type;
66611+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66612+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66613+ subj->user_trans_num = subjcompat.user_trans_num;
66614+ subj->group_trans_num = subjcompat.group_trans_num;
66615+
66616+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66617+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66618+ subj->ip_type = subjcompat.ip_type;
66619+ subj->ips = compat_ptr(subjcompat.ips);
66620+ subj->ip_num = subjcompat.ip_num;
66621+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66622+
66623+ subj->crashes = subjcompat.crashes;
66624+ subj->expires = subjcompat.expires;
66625+
66626+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66627+ subj->hash = compat_ptr(subjcompat.hash);
66628+ subj->prev = compat_ptr(subjcompat.prev);
66629+ subj->next = compat_ptr(subjcompat.next);
66630+
66631+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66632+ subj->obj_hash_size = subjcompat.obj_hash_size;
66633+ subj->pax_flags = subjcompat.pax_flags;
66634+
66635+ return 0;
66636+}
66637+
66638+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66639+{
66640+ struct acl_role_label_compat rolecompat;
66641+
66642+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66643+ return -EFAULT;
66644+
66645+ role->rolename = compat_ptr(rolecompat.rolename);
66646+ role->uidgid = rolecompat.uidgid;
66647+ role->roletype = rolecompat.roletype;
66648+
66649+ role->auth_attempts = rolecompat.auth_attempts;
66650+ role->expires = rolecompat.expires;
66651+
66652+ role->root_label = compat_ptr(rolecompat.root_label);
66653+ role->hash = compat_ptr(rolecompat.hash);
66654+
66655+ role->prev = compat_ptr(rolecompat.prev);
66656+ role->next = compat_ptr(rolecompat.next);
66657+
66658+ role->transitions = compat_ptr(rolecompat.transitions);
66659+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66660+ role->domain_children = compat_ptr(rolecompat.domain_children);
66661+ role->domain_child_num = rolecompat.domain_child_num;
66662+
66663+ role->umask = rolecompat.umask;
66664+
66665+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66666+ role->subj_hash_size = rolecompat.subj_hash_size;
66667+
66668+ return 0;
66669+}
66670+
66671+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66672+{
66673+ struct role_allowed_ip_compat roleip_compat;
66674+
66675+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66676+ return -EFAULT;
66677+
66678+ roleip->addr = roleip_compat.addr;
66679+ roleip->netmask = roleip_compat.netmask;
66680+
66681+ roleip->prev = compat_ptr(roleip_compat.prev);
66682+ roleip->next = compat_ptr(roleip_compat.next);
66683+
66684+ return 0;
66685+}
66686+
66687+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66688+{
66689+ struct role_transition_compat trans_compat;
66690+
66691+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66692+ return -EFAULT;
66693+
66694+ trans->rolename = compat_ptr(trans_compat.rolename);
66695+
66696+ trans->prev = compat_ptr(trans_compat.prev);
66697+ trans->next = compat_ptr(trans_compat.next);
66698+
66699+ return 0;
66700+
66701+}
66702+
66703+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66704+{
66705+ struct gr_hash_struct_compat hash_compat;
66706+
66707+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66708+ return -EFAULT;
66709+
66710+ hash->table = compat_ptr(hash_compat.table);
66711+ hash->nametable = compat_ptr(hash_compat.nametable);
66712+ hash->first = compat_ptr(hash_compat.first);
66713+
66714+ hash->table_size = hash_compat.table_size;
66715+ hash->used_size = hash_compat.used_size;
66716+
66717+ hash->type = hash_compat.type;
66718+
66719+ return 0;
66720+}
66721+
66722+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66723+{
66724+ compat_uptr_t ptrcompat;
66725+
66726+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66727+ return -EFAULT;
66728+
66729+ *(void **)ptr = compat_ptr(ptrcompat);
66730+
66731+ return 0;
66732+}
66733+
66734+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66735+{
66736+ struct acl_ip_label_compat ip_compat;
66737+
66738+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66739+ return -EFAULT;
66740+
66741+ ip->iface = compat_ptr(ip_compat.iface);
66742+ ip->addr = ip_compat.addr;
66743+ ip->netmask = ip_compat.netmask;
66744+ ip->low = ip_compat.low;
66745+ ip->high = ip_compat.high;
66746+ ip->mode = ip_compat.mode;
66747+ ip->type = ip_compat.type;
66748+
66749+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66750+
66751+ ip->prev = compat_ptr(ip_compat.prev);
66752+ ip->next = compat_ptr(ip_compat.next);
66753+
66754+ return 0;
66755+}
66756+
66757+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66758+{
66759+ struct sprole_pw_compat pw_compat;
66760+
66761+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66762+ return -EFAULT;
66763+
66764+ pw->rolename = compat_ptr(pw_compat.rolename);
66765+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66766+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66767+
66768+ return 0;
66769+}
66770+
66771+size_t get_gr_arg_wrapper_size_compat(void)
66772+{
66773+ return sizeof(struct gr_arg_wrapper_compat);
66774+}
66775+
66776diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66777new file mode 100644
66778index 0000000..a340c17
66779--- /dev/null
66780+++ b/grsecurity/gracl_fs.c
66781@@ -0,0 +1,431 @@
66782+#include <linux/kernel.h>
66783+#include <linux/sched.h>
66784+#include <linux/types.h>
66785+#include <linux/fs.h>
66786+#include <linux/file.h>
66787+#include <linux/stat.h>
66788+#include <linux/grsecurity.h>
66789+#include <linux/grinternal.h>
66790+#include <linux/gracl.h>
66791+
66792+umode_t
66793+gr_acl_umask(void)
66794+{
66795+ if (unlikely(!gr_acl_is_enabled()))
66796+ return 0;
66797+
66798+ return current->role->umask;
66799+}
66800+
66801+__u32
66802+gr_acl_handle_hidden_file(const struct dentry * dentry,
66803+ const struct vfsmount * mnt)
66804+{
66805+ __u32 mode;
66806+
66807+ if (unlikely(!dentry->d_inode))
66808+ return GR_FIND;
66809+
66810+ mode =
66811+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66812+
66813+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66814+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66815+ return mode;
66816+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66817+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66818+ return 0;
66819+ } else if (unlikely(!(mode & GR_FIND)))
66820+ return 0;
66821+
66822+ return GR_FIND;
66823+}
66824+
66825+__u32
66826+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66827+ int acc_mode)
66828+{
66829+ __u32 reqmode = GR_FIND;
66830+ __u32 mode;
66831+
66832+ if (unlikely(!dentry->d_inode))
66833+ return reqmode;
66834+
66835+ if (acc_mode & MAY_APPEND)
66836+ reqmode |= GR_APPEND;
66837+ else if (acc_mode & MAY_WRITE)
66838+ reqmode |= GR_WRITE;
66839+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66840+ reqmode |= GR_READ;
66841+
66842+ mode =
66843+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66844+ mnt);
66845+
66846+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66847+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66848+ reqmode & GR_READ ? " reading" : "",
66849+ reqmode & GR_WRITE ? " writing" : reqmode &
66850+ GR_APPEND ? " appending" : "");
66851+ return reqmode;
66852+ } else
66853+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66854+ {
66855+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66856+ reqmode & GR_READ ? " reading" : "",
66857+ reqmode & GR_WRITE ? " writing" : reqmode &
66858+ GR_APPEND ? " appending" : "");
66859+ return 0;
66860+ } else if (unlikely((mode & reqmode) != reqmode))
66861+ return 0;
66862+
66863+ return reqmode;
66864+}
66865+
66866+__u32
66867+gr_acl_handle_creat(const struct dentry * dentry,
66868+ const struct dentry * p_dentry,
66869+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66870+ const int imode)
66871+{
66872+ __u32 reqmode = GR_WRITE | GR_CREATE;
66873+ __u32 mode;
66874+
66875+ if (acc_mode & MAY_APPEND)
66876+ reqmode |= GR_APPEND;
66877+ // if a directory was required or the directory already exists, then
66878+ // don't count this open as a read
66879+ if ((acc_mode & MAY_READ) &&
66880+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66881+ reqmode |= GR_READ;
66882+ if ((open_flags & O_CREAT) &&
66883+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66884+ reqmode |= GR_SETID;
66885+
66886+ mode =
66887+ gr_check_create(dentry, p_dentry, p_mnt,
66888+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66889+
66890+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66891+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66892+ reqmode & GR_READ ? " reading" : "",
66893+ reqmode & GR_WRITE ? " writing" : reqmode &
66894+ GR_APPEND ? " appending" : "");
66895+ return reqmode;
66896+ } else
66897+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66898+ {
66899+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66900+ reqmode & GR_READ ? " reading" : "",
66901+ reqmode & GR_WRITE ? " writing" : reqmode &
66902+ GR_APPEND ? " appending" : "");
66903+ return 0;
66904+ } else if (unlikely((mode & reqmode) != reqmode))
66905+ return 0;
66906+
66907+ return reqmode;
66908+}
66909+
66910+__u32
66911+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66912+ const int fmode)
66913+{
66914+ __u32 mode, reqmode = GR_FIND;
66915+
66916+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66917+ reqmode |= GR_EXEC;
66918+ if (fmode & S_IWOTH)
66919+ reqmode |= GR_WRITE;
66920+ if (fmode & S_IROTH)
66921+ reqmode |= GR_READ;
66922+
66923+ mode =
66924+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66925+ mnt);
66926+
66927+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66928+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66929+ reqmode & GR_READ ? " reading" : "",
66930+ reqmode & GR_WRITE ? " writing" : "",
66931+ reqmode & GR_EXEC ? " executing" : "");
66932+ return reqmode;
66933+ } else
66934+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66935+ {
66936+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66937+ reqmode & GR_READ ? " reading" : "",
66938+ reqmode & GR_WRITE ? " writing" : "",
66939+ reqmode & GR_EXEC ? " executing" : "");
66940+ return 0;
66941+ } else if (unlikely((mode & reqmode) != reqmode))
66942+ return 0;
66943+
66944+ return reqmode;
66945+}
66946+
66947+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66948+{
66949+ __u32 mode;
66950+
66951+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66952+
66953+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66954+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66955+ return mode;
66956+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66957+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66958+ return 0;
66959+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66960+ return 0;
66961+
66962+ return (reqmode);
66963+}
66964+
66965+__u32
66966+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66967+{
66968+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66969+}
66970+
66971+__u32
66972+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66973+{
66974+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66975+}
66976+
66977+__u32
66978+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66979+{
66980+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
66981+}
66982+
66983+__u32
66984+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
66985+{
66986+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
66987+}
66988+
66989+__u32
66990+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
66991+ umode_t *modeptr)
66992+{
66993+ umode_t mode;
66994+
66995+ *modeptr &= ~gr_acl_umask();
66996+ mode = *modeptr;
66997+
66998+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
66999+ return 1;
67000+
67001+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67002+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67003+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67004+ GR_CHMOD_ACL_MSG);
67005+ } else {
67006+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67007+ }
67008+}
67009+
67010+__u32
67011+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67012+{
67013+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67014+}
67015+
67016+__u32
67017+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67018+{
67019+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67020+}
67021+
67022+__u32
67023+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67024+{
67025+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67026+}
67027+
67028+__u32
67029+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67030+{
67031+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67032+ GR_UNIXCONNECT_ACL_MSG);
67033+}
67034+
67035+/* hardlinks require at minimum create and link permission,
67036+ any additional privilege required is based on the
67037+ privilege of the file being linked to
67038+*/
67039+__u32
67040+gr_acl_handle_link(const struct dentry * new_dentry,
67041+ const struct dentry * parent_dentry,
67042+ const struct vfsmount * parent_mnt,
67043+ const struct dentry * old_dentry,
67044+ const struct vfsmount * old_mnt, const struct filename *to)
67045+{
67046+ __u32 mode;
67047+ __u32 needmode = GR_CREATE | GR_LINK;
67048+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67049+
67050+ mode =
67051+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67052+ old_mnt);
67053+
67054+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67055+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67056+ return mode;
67057+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67058+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67059+ return 0;
67060+ } else if (unlikely((mode & needmode) != needmode))
67061+ return 0;
67062+
67063+ return 1;
67064+}
67065+
67066+__u32
67067+gr_acl_handle_symlink(const struct dentry * new_dentry,
67068+ const struct dentry * parent_dentry,
67069+ const struct vfsmount * parent_mnt, const struct filename *from)
67070+{
67071+ __u32 needmode = GR_WRITE | GR_CREATE;
67072+ __u32 mode;
67073+
67074+ mode =
67075+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67076+ GR_CREATE | GR_AUDIT_CREATE |
67077+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67078+
67079+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67080+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67081+ return mode;
67082+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67083+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67084+ return 0;
67085+ } else if (unlikely((mode & needmode) != needmode))
67086+ return 0;
67087+
67088+ return (GR_WRITE | GR_CREATE);
67089+}
67090+
67091+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)
67092+{
67093+ __u32 mode;
67094+
67095+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67096+
67097+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67098+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67099+ return mode;
67100+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67101+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67102+ return 0;
67103+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67104+ return 0;
67105+
67106+ return (reqmode);
67107+}
67108+
67109+__u32
67110+gr_acl_handle_mknod(const struct dentry * new_dentry,
67111+ const struct dentry * parent_dentry,
67112+ const struct vfsmount * parent_mnt,
67113+ const int mode)
67114+{
67115+ __u32 reqmode = GR_WRITE | GR_CREATE;
67116+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67117+ reqmode |= GR_SETID;
67118+
67119+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67120+ reqmode, GR_MKNOD_ACL_MSG);
67121+}
67122+
67123+__u32
67124+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67125+ const struct dentry *parent_dentry,
67126+ const struct vfsmount *parent_mnt)
67127+{
67128+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67129+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67130+}
67131+
67132+#define RENAME_CHECK_SUCCESS(old, new) \
67133+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67134+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67135+
67136+int
67137+gr_acl_handle_rename(struct dentry *new_dentry,
67138+ struct dentry *parent_dentry,
67139+ const struct vfsmount *parent_mnt,
67140+ struct dentry *old_dentry,
67141+ struct inode *old_parent_inode,
67142+ struct vfsmount *old_mnt, const struct filename *newname)
67143+{
67144+ __u32 comp1, comp2;
67145+ int error = 0;
67146+
67147+ if (unlikely(!gr_acl_is_enabled()))
67148+ return 0;
67149+
67150+ if (!new_dentry->d_inode) {
67151+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67152+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67153+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67154+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67155+ GR_DELETE | GR_AUDIT_DELETE |
67156+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67157+ GR_SUPPRESS, old_mnt);
67158+ } else {
67159+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67160+ GR_CREATE | GR_DELETE |
67161+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67162+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67163+ GR_SUPPRESS, parent_mnt);
67164+ comp2 =
67165+ gr_search_file(old_dentry,
67166+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67167+ GR_DELETE | GR_AUDIT_DELETE |
67168+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67169+ }
67170+
67171+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67172+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67173+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67174+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67175+ && !(comp2 & GR_SUPPRESS)) {
67176+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67177+ error = -EACCES;
67178+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67179+ error = -EACCES;
67180+
67181+ return error;
67182+}
67183+
67184+void
67185+gr_acl_handle_exit(void)
67186+{
67187+ u16 id;
67188+ char *rolename;
67189+
67190+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67191+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67192+ id = current->acl_role_id;
67193+ rolename = current->role->rolename;
67194+ gr_set_acls(1);
67195+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67196+ }
67197+
67198+ gr_put_exec_file(current);
67199+ return;
67200+}
67201+
67202+int
67203+gr_acl_handle_procpidmem(const struct task_struct *task)
67204+{
67205+ if (unlikely(!gr_acl_is_enabled()))
67206+ return 0;
67207+
67208+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67209+ return -EACCES;
67210+
67211+ return 0;
67212+}
67213diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67214new file mode 100644
67215index 0000000..f056b81
67216--- /dev/null
67217+++ b/grsecurity/gracl_ip.c
67218@@ -0,0 +1,386 @@
67219+#include <linux/kernel.h>
67220+#include <asm/uaccess.h>
67221+#include <asm/errno.h>
67222+#include <net/sock.h>
67223+#include <linux/file.h>
67224+#include <linux/fs.h>
67225+#include <linux/net.h>
67226+#include <linux/in.h>
67227+#include <linux/skbuff.h>
67228+#include <linux/ip.h>
67229+#include <linux/udp.h>
67230+#include <linux/types.h>
67231+#include <linux/sched.h>
67232+#include <linux/netdevice.h>
67233+#include <linux/inetdevice.h>
67234+#include <linux/gracl.h>
67235+#include <linux/grsecurity.h>
67236+#include <linux/grinternal.h>
67237+
67238+#define GR_BIND 0x01
67239+#define GR_CONNECT 0x02
67240+#define GR_INVERT 0x04
67241+#define GR_BINDOVERRIDE 0x08
67242+#define GR_CONNECTOVERRIDE 0x10
67243+#define GR_SOCK_FAMILY 0x20
67244+
67245+static const char * gr_protocols[IPPROTO_MAX] = {
67246+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67247+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67248+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67249+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67250+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67251+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67252+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67253+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67254+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67255+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67256+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67257+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67258+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67259+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67260+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67261+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67262+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67263+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67264+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67265+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67266+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67267+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67268+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67269+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67270+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67271+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67272+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67273+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67274+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67275+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67276+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67277+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67278+ };
67279+
67280+static const char * gr_socktypes[SOCK_MAX] = {
67281+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67282+ "unknown:7", "unknown:8", "unknown:9", "packet"
67283+ };
67284+
67285+static const char * gr_sockfamilies[AF_MAX+1] = {
67286+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67287+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67288+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67289+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67290+ };
67291+
67292+const char *
67293+gr_proto_to_name(unsigned char proto)
67294+{
67295+ return gr_protocols[proto];
67296+}
67297+
67298+const char *
67299+gr_socktype_to_name(unsigned char type)
67300+{
67301+ return gr_socktypes[type];
67302+}
67303+
67304+const char *
67305+gr_sockfamily_to_name(unsigned char family)
67306+{
67307+ return gr_sockfamilies[family];
67308+}
67309+
67310+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67311+
67312+int
67313+gr_search_socket(const int domain, const int type, const int protocol)
67314+{
67315+ struct acl_subject_label *curr;
67316+ const struct cred *cred = current_cred();
67317+
67318+ if (unlikely(!gr_acl_is_enabled()))
67319+ goto exit;
67320+
67321+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67322+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67323+ goto exit; // let the kernel handle it
67324+
67325+ curr = current->acl;
67326+
67327+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67328+ /* the family is allowed, if this is PF_INET allow it only if
67329+ the extra sock type/protocol checks pass */
67330+ if (domain == PF_INET)
67331+ goto inet_check;
67332+ goto exit;
67333+ } else {
67334+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67335+ __u32 fakeip = 0;
67336+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67337+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67338+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67339+ gr_to_filename(current->exec_file->f_path.dentry,
67340+ current->exec_file->f_path.mnt) :
67341+ curr->filename, curr->filename,
67342+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67343+ &current->signal->saved_ip);
67344+ goto exit;
67345+ }
67346+ goto exit_fail;
67347+ }
67348+
67349+inet_check:
67350+ /* the rest of this checking is for IPv4 only */
67351+ if (!curr->ips)
67352+ goto exit;
67353+
67354+ if ((curr->ip_type & (1U << type)) &&
67355+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67356+ goto exit;
67357+
67358+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67359+ /* we don't place acls on raw sockets , and sometimes
67360+ dgram/ip sockets are opened for ioctl and not
67361+ bind/connect, so we'll fake a bind learn log */
67362+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67363+ __u32 fakeip = 0;
67364+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67365+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67366+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67367+ gr_to_filename(current->exec_file->f_path.dentry,
67368+ current->exec_file->f_path.mnt) :
67369+ curr->filename, curr->filename,
67370+ &fakeip, 0, type,
67371+ protocol, GR_CONNECT, &current->signal->saved_ip);
67372+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67373+ __u32 fakeip = 0;
67374+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67375+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67376+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67377+ gr_to_filename(current->exec_file->f_path.dentry,
67378+ current->exec_file->f_path.mnt) :
67379+ curr->filename, curr->filename,
67380+ &fakeip, 0, type,
67381+ protocol, GR_BIND, &current->signal->saved_ip);
67382+ }
67383+ /* we'll log when they use connect or bind */
67384+ goto exit;
67385+ }
67386+
67387+exit_fail:
67388+ if (domain == PF_INET)
67389+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67390+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67391+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67392+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67393+ gr_socktype_to_name(type), protocol);
67394+
67395+ return 0;
67396+exit:
67397+ return 1;
67398+}
67399+
67400+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)
67401+{
67402+ if ((ip->mode & mode) &&
67403+ (ip_port >= ip->low) &&
67404+ (ip_port <= ip->high) &&
67405+ ((ntohl(ip_addr) & our_netmask) ==
67406+ (ntohl(our_addr) & our_netmask))
67407+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67408+ && (ip->type & (1U << type))) {
67409+ if (ip->mode & GR_INVERT)
67410+ return 2; // specifically denied
67411+ else
67412+ return 1; // allowed
67413+ }
67414+
67415+ return 0; // not specifically allowed, may continue parsing
67416+}
67417+
67418+static int
67419+gr_search_connectbind(const int full_mode, struct sock *sk,
67420+ struct sockaddr_in *addr, const int type)
67421+{
67422+ char iface[IFNAMSIZ] = {0};
67423+ struct acl_subject_label *curr;
67424+ struct acl_ip_label *ip;
67425+ struct inet_sock *isk;
67426+ struct net_device *dev;
67427+ struct in_device *idev;
67428+ unsigned long i;
67429+ int ret;
67430+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67431+ __u32 ip_addr = 0;
67432+ __u32 our_addr;
67433+ __u32 our_netmask;
67434+ char *p;
67435+ __u16 ip_port = 0;
67436+ const struct cred *cred = current_cred();
67437+
67438+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67439+ return 0;
67440+
67441+ curr = current->acl;
67442+ isk = inet_sk(sk);
67443+
67444+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67445+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67446+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67447+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67448+ struct sockaddr_in saddr;
67449+ int err;
67450+
67451+ saddr.sin_family = AF_INET;
67452+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67453+ saddr.sin_port = isk->inet_sport;
67454+
67455+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67456+ if (err)
67457+ return err;
67458+
67459+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67460+ if (err)
67461+ return err;
67462+ }
67463+
67464+ if (!curr->ips)
67465+ return 0;
67466+
67467+ ip_addr = addr->sin_addr.s_addr;
67468+ ip_port = ntohs(addr->sin_port);
67469+
67470+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67471+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67472+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67473+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67474+ gr_to_filename(current->exec_file->f_path.dentry,
67475+ current->exec_file->f_path.mnt) :
67476+ curr->filename, curr->filename,
67477+ &ip_addr, ip_port, type,
67478+ sk->sk_protocol, mode, &current->signal->saved_ip);
67479+ return 0;
67480+ }
67481+
67482+ for (i = 0; i < curr->ip_num; i++) {
67483+ ip = *(curr->ips + i);
67484+ if (ip->iface != NULL) {
67485+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67486+ p = strchr(iface, ':');
67487+ if (p != NULL)
67488+ *p = '\0';
67489+ dev = dev_get_by_name(sock_net(sk), iface);
67490+ if (dev == NULL)
67491+ continue;
67492+ idev = in_dev_get(dev);
67493+ if (idev == NULL) {
67494+ dev_put(dev);
67495+ continue;
67496+ }
67497+ rcu_read_lock();
67498+ for_ifa(idev) {
67499+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67500+ our_addr = ifa->ifa_address;
67501+ our_netmask = 0xffffffff;
67502+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67503+ if (ret == 1) {
67504+ rcu_read_unlock();
67505+ in_dev_put(idev);
67506+ dev_put(dev);
67507+ return 0;
67508+ } else if (ret == 2) {
67509+ rcu_read_unlock();
67510+ in_dev_put(idev);
67511+ dev_put(dev);
67512+ goto denied;
67513+ }
67514+ }
67515+ } endfor_ifa(idev);
67516+ rcu_read_unlock();
67517+ in_dev_put(idev);
67518+ dev_put(dev);
67519+ } else {
67520+ our_addr = ip->addr;
67521+ our_netmask = ip->netmask;
67522+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67523+ if (ret == 1)
67524+ return 0;
67525+ else if (ret == 2)
67526+ goto denied;
67527+ }
67528+ }
67529+
67530+denied:
67531+ if (mode == GR_BIND)
67532+ 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));
67533+ else if (mode == GR_CONNECT)
67534+ 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));
67535+
67536+ return -EACCES;
67537+}
67538+
67539+int
67540+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67541+{
67542+ /* always allow disconnection of dgram sockets with connect */
67543+ if (addr->sin_family == AF_UNSPEC)
67544+ return 0;
67545+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67546+}
67547+
67548+int
67549+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67550+{
67551+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67552+}
67553+
67554+int gr_search_listen(struct socket *sock)
67555+{
67556+ struct sock *sk = sock->sk;
67557+ struct sockaddr_in addr;
67558+
67559+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67560+ addr.sin_port = inet_sk(sk)->inet_sport;
67561+
67562+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67563+}
67564+
67565+int gr_search_accept(struct socket *sock)
67566+{
67567+ struct sock *sk = sock->sk;
67568+ struct sockaddr_in addr;
67569+
67570+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67571+ addr.sin_port = inet_sk(sk)->inet_sport;
67572+
67573+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67574+}
67575+
67576+int
67577+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67578+{
67579+ if (addr)
67580+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67581+ else {
67582+ struct sockaddr_in sin;
67583+ const struct inet_sock *inet = inet_sk(sk);
67584+
67585+ sin.sin_addr.s_addr = inet->inet_daddr;
67586+ sin.sin_port = inet->inet_dport;
67587+
67588+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67589+ }
67590+}
67591+
67592+int
67593+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67594+{
67595+ struct sockaddr_in sin;
67596+
67597+ if (unlikely(skb->len < sizeof (struct udphdr)))
67598+ return 0; // skip this packet
67599+
67600+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67601+ sin.sin_port = udp_hdr(skb)->source;
67602+
67603+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67604+}
67605diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67606new file mode 100644
67607index 0000000..25f54ef
67608--- /dev/null
67609+++ b/grsecurity/gracl_learn.c
67610@@ -0,0 +1,207 @@
67611+#include <linux/kernel.h>
67612+#include <linux/mm.h>
67613+#include <linux/sched.h>
67614+#include <linux/poll.h>
67615+#include <linux/string.h>
67616+#include <linux/file.h>
67617+#include <linux/types.h>
67618+#include <linux/vmalloc.h>
67619+#include <linux/grinternal.h>
67620+
67621+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67622+ size_t count, loff_t *ppos);
67623+extern int gr_acl_is_enabled(void);
67624+
67625+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67626+static int gr_learn_attached;
67627+
67628+/* use a 512k buffer */
67629+#define LEARN_BUFFER_SIZE (512 * 1024)
67630+
67631+static DEFINE_SPINLOCK(gr_learn_lock);
67632+static DEFINE_MUTEX(gr_learn_user_mutex);
67633+
67634+/* we need to maintain two buffers, so that the kernel context of grlearn
67635+ uses a semaphore around the userspace copying, and the other kernel contexts
67636+ use a spinlock when copying into the buffer, since they cannot sleep
67637+*/
67638+static char *learn_buffer;
67639+static char *learn_buffer_user;
67640+static int learn_buffer_len;
67641+static int learn_buffer_user_len;
67642+
67643+static ssize_t
67644+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67645+{
67646+ DECLARE_WAITQUEUE(wait, current);
67647+ ssize_t retval = 0;
67648+
67649+ add_wait_queue(&learn_wait, &wait);
67650+ set_current_state(TASK_INTERRUPTIBLE);
67651+ do {
67652+ mutex_lock(&gr_learn_user_mutex);
67653+ spin_lock(&gr_learn_lock);
67654+ if (learn_buffer_len)
67655+ break;
67656+ spin_unlock(&gr_learn_lock);
67657+ mutex_unlock(&gr_learn_user_mutex);
67658+ if (file->f_flags & O_NONBLOCK) {
67659+ retval = -EAGAIN;
67660+ goto out;
67661+ }
67662+ if (signal_pending(current)) {
67663+ retval = -ERESTARTSYS;
67664+ goto out;
67665+ }
67666+
67667+ schedule();
67668+ } while (1);
67669+
67670+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67671+ learn_buffer_user_len = learn_buffer_len;
67672+ retval = learn_buffer_len;
67673+ learn_buffer_len = 0;
67674+
67675+ spin_unlock(&gr_learn_lock);
67676+
67677+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67678+ retval = -EFAULT;
67679+
67680+ mutex_unlock(&gr_learn_user_mutex);
67681+out:
67682+ set_current_state(TASK_RUNNING);
67683+ remove_wait_queue(&learn_wait, &wait);
67684+ return retval;
67685+}
67686+
67687+static unsigned int
67688+poll_learn(struct file * file, poll_table * wait)
67689+{
67690+ poll_wait(file, &learn_wait, wait);
67691+
67692+ if (learn_buffer_len)
67693+ return (POLLIN | POLLRDNORM);
67694+
67695+ return 0;
67696+}
67697+
67698+void
67699+gr_clear_learn_entries(void)
67700+{
67701+ char *tmp;
67702+
67703+ mutex_lock(&gr_learn_user_mutex);
67704+ spin_lock(&gr_learn_lock);
67705+ tmp = learn_buffer;
67706+ learn_buffer = NULL;
67707+ spin_unlock(&gr_learn_lock);
67708+ if (tmp)
67709+ vfree(tmp);
67710+ if (learn_buffer_user != NULL) {
67711+ vfree(learn_buffer_user);
67712+ learn_buffer_user = NULL;
67713+ }
67714+ learn_buffer_len = 0;
67715+ mutex_unlock(&gr_learn_user_mutex);
67716+
67717+ return;
67718+}
67719+
67720+void
67721+gr_add_learn_entry(const char *fmt, ...)
67722+{
67723+ va_list args;
67724+ unsigned int len;
67725+
67726+ if (!gr_learn_attached)
67727+ return;
67728+
67729+ spin_lock(&gr_learn_lock);
67730+
67731+ /* leave a gap at the end so we know when it's "full" but don't have to
67732+ compute the exact length of the string we're trying to append
67733+ */
67734+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67735+ spin_unlock(&gr_learn_lock);
67736+ wake_up_interruptible(&learn_wait);
67737+ return;
67738+ }
67739+ if (learn_buffer == NULL) {
67740+ spin_unlock(&gr_learn_lock);
67741+ return;
67742+ }
67743+
67744+ va_start(args, fmt);
67745+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67746+ va_end(args);
67747+
67748+ learn_buffer_len += len + 1;
67749+
67750+ spin_unlock(&gr_learn_lock);
67751+ wake_up_interruptible(&learn_wait);
67752+
67753+ return;
67754+}
67755+
67756+static int
67757+open_learn(struct inode *inode, struct file *file)
67758+{
67759+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67760+ return -EBUSY;
67761+ if (file->f_mode & FMODE_READ) {
67762+ int retval = 0;
67763+ mutex_lock(&gr_learn_user_mutex);
67764+ if (learn_buffer == NULL)
67765+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67766+ if (learn_buffer_user == NULL)
67767+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67768+ if (learn_buffer == NULL) {
67769+ retval = -ENOMEM;
67770+ goto out_error;
67771+ }
67772+ if (learn_buffer_user == NULL) {
67773+ retval = -ENOMEM;
67774+ goto out_error;
67775+ }
67776+ learn_buffer_len = 0;
67777+ learn_buffer_user_len = 0;
67778+ gr_learn_attached = 1;
67779+out_error:
67780+ mutex_unlock(&gr_learn_user_mutex);
67781+ return retval;
67782+ }
67783+ return 0;
67784+}
67785+
67786+static int
67787+close_learn(struct inode *inode, struct file *file)
67788+{
67789+ if (file->f_mode & FMODE_READ) {
67790+ char *tmp = NULL;
67791+ mutex_lock(&gr_learn_user_mutex);
67792+ spin_lock(&gr_learn_lock);
67793+ tmp = learn_buffer;
67794+ learn_buffer = NULL;
67795+ spin_unlock(&gr_learn_lock);
67796+ if (tmp)
67797+ vfree(tmp);
67798+ if (learn_buffer_user != NULL) {
67799+ vfree(learn_buffer_user);
67800+ learn_buffer_user = NULL;
67801+ }
67802+ learn_buffer_len = 0;
67803+ learn_buffer_user_len = 0;
67804+ gr_learn_attached = 0;
67805+ mutex_unlock(&gr_learn_user_mutex);
67806+ }
67807+
67808+ return 0;
67809+}
67810+
67811+const struct file_operations grsec_fops = {
67812+ .read = read_learn,
67813+ .write = write_grsec_handler,
67814+ .open = open_learn,
67815+ .release = close_learn,
67816+ .poll = poll_learn,
67817+};
67818diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67819new file mode 100644
67820index 0000000..39645c9
67821--- /dev/null
67822+++ b/grsecurity/gracl_res.c
67823@@ -0,0 +1,68 @@
67824+#include <linux/kernel.h>
67825+#include <linux/sched.h>
67826+#include <linux/gracl.h>
67827+#include <linux/grinternal.h>
67828+
67829+static const char *restab_log[] = {
67830+ [RLIMIT_CPU] = "RLIMIT_CPU",
67831+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67832+ [RLIMIT_DATA] = "RLIMIT_DATA",
67833+ [RLIMIT_STACK] = "RLIMIT_STACK",
67834+ [RLIMIT_CORE] = "RLIMIT_CORE",
67835+ [RLIMIT_RSS] = "RLIMIT_RSS",
67836+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67837+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67838+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67839+ [RLIMIT_AS] = "RLIMIT_AS",
67840+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67841+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67842+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67843+ [RLIMIT_NICE] = "RLIMIT_NICE",
67844+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67845+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67846+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67847+};
67848+
67849+void
67850+gr_log_resource(const struct task_struct *task,
67851+ const int res, const unsigned long wanted, const int gt)
67852+{
67853+ const struct cred *cred;
67854+ unsigned long rlim;
67855+
67856+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67857+ return;
67858+
67859+ // not yet supported resource
67860+ if (unlikely(!restab_log[res]))
67861+ return;
67862+
67863+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67864+ rlim = task_rlimit_max(task, res);
67865+ else
67866+ rlim = task_rlimit(task, res);
67867+
67868+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67869+ return;
67870+
67871+ rcu_read_lock();
67872+ cred = __task_cred(task);
67873+
67874+ if (res == RLIMIT_NPROC &&
67875+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67876+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67877+ goto out_rcu_unlock;
67878+ else if (res == RLIMIT_MEMLOCK &&
67879+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67880+ goto out_rcu_unlock;
67881+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67882+ goto out_rcu_unlock;
67883+ rcu_read_unlock();
67884+
67885+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67886+
67887+ return;
67888+out_rcu_unlock:
67889+ rcu_read_unlock();
67890+ return;
67891+}
67892diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67893new file mode 100644
67894index 0000000..3c38bfe
67895--- /dev/null
67896+++ b/grsecurity/gracl_segv.c
67897@@ -0,0 +1,305 @@
67898+#include <linux/kernel.h>
67899+#include <linux/mm.h>
67900+#include <asm/uaccess.h>
67901+#include <asm/errno.h>
67902+#include <asm/mman.h>
67903+#include <net/sock.h>
67904+#include <linux/file.h>
67905+#include <linux/fs.h>
67906+#include <linux/net.h>
67907+#include <linux/in.h>
67908+#include <linux/slab.h>
67909+#include <linux/types.h>
67910+#include <linux/sched.h>
67911+#include <linux/timer.h>
67912+#include <linux/gracl.h>
67913+#include <linux/grsecurity.h>
67914+#include <linux/grinternal.h>
67915+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67916+#include <linux/magic.h>
67917+#include <linux/pagemap.h>
67918+#include "../fs/btrfs/async-thread.h"
67919+#include "../fs/btrfs/ctree.h"
67920+#include "../fs/btrfs/btrfs_inode.h"
67921+#endif
67922+
67923+static struct crash_uid *uid_set;
67924+static unsigned short uid_used;
67925+static DEFINE_SPINLOCK(gr_uid_lock);
67926+extern rwlock_t gr_inode_lock;
67927+extern struct acl_subject_label *
67928+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67929+ struct acl_role_label *role);
67930+
67931+static inline dev_t __get_dev(const struct dentry *dentry)
67932+{
67933+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67934+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67935+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67936+ else
67937+#endif
67938+ return dentry->d_sb->s_dev;
67939+}
67940+
67941+int
67942+gr_init_uidset(void)
67943+{
67944+ uid_set =
67945+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
67946+ uid_used = 0;
67947+
67948+ return uid_set ? 1 : 0;
67949+}
67950+
67951+void
67952+gr_free_uidset(void)
67953+{
67954+ if (uid_set)
67955+ kfree(uid_set);
67956+
67957+ return;
67958+}
67959+
67960+int
67961+gr_find_uid(const uid_t uid)
67962+{
67963+ struct crash_uid *tmp = uid_set;
67964+ uid_t buid;
67965+ int low = 0, high = uid_used - 1, mid;
67966+
67967+ while (high >= low) {
67968+ mid = (low + high) >> 1;
67969+ buid = tmp[mid].uid;
67970+ if (buid == uid)
67971+ return mid;
67972+ if (buid > uid)
67973+ high = mid - 1;
67974+ if (buid < uid)
67975+ low = mid + 1;
67976+ }
67977+
67978+ return -1;
67979+}
67980+
67981+static __inline__ void
67982+gr_insertsort(void)
67983+{
67984+ unsigned short i, j;
67985+ struct crash_uid index;
67986+
67987+ for (i = 1; i < uid_used; i++) {
67988+ index = uid_set[i];
67989+ j = i;
67990+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
67991+ uid_set[j] = uid_set[j - 1];
67992+ j--;
67993+ }
67994+ uid_set[j] = index;
67995+ }
67996+
67997+ return;
67998+}
67999+
68000+static __inline__ void
68001+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68002+{
68003+ int loc;
68004+ uid_t uid = GR_GLOBAL_UID(kuid);
68005+
68006+ if (uid_used == GR_UIDTABLE_MAX)
68007+ return;
68008+
68009+ loc = gr_find_uid(uid);
68010+
68011+ if (loc >= 0) {
68012+ uid_set[loc].expires = expires;
68013+ return;
68014+ }
68015+
68016+ uid_set[uid_used].uid = uid;
68017+ uid_set[uid_used].expires = expires;
68018+ uid_used++;
68019+
68020+ gr_insertsort();
68021+
68022+ return;
68023+}
68024+
68025+void
68026+gr_remove_uid(const unsigned short loc)
68027+{
68028+ unsigned short i;
68029+
68030+ for (i = loc + 1; i < uid_used; i++)
68031+ uid_set[i - 1] = uid_set[i];
68032+
68033+ uid_used--;
68034+
68035+ return;
68036+}
68037+
68038+int
68039+gr_check_crash_uid(const kuid_t kuid)
68040+{
68041+ int loc;
68042+ int ret = 0;
68043+ uid_t uid;
68044+
68045+ if (unlikely(!gr_acl_is_enabled()))
68046+ return 0;
68047+
68048+ uid = GR_GLOBAL_UID(kuid);
68049+
68050+ spin_lock(&gr_uid_lock);
68051+ loc = gr_find_uid(uid);
68052+
68053+ if (loc < 0)
68054+ goto out_unlock;
68055+
68056+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68057+ gr_remove_uid(loc);
68058+ else
68059+ ret = 1;
68060+
68061+out_unlock:
68062+ spin_unlock(&gr_uid_lock);
68063+ return ret;
68064+}
68065+
68066+static __inline__ int
68067+proc_is_setxid(const struct cred *cred)
68068+{
68069+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68070+ !uid_eq(cred->uid, cred->fsuid))
68071+ return 1;
68072+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68073+ !gid_eq(cred->gid, cred->fsgid))
68074+ return 1;
68075+
68076+ return 0;
68077+}
68078+
68079+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68080+
68081+void
68082+gr_handle_crash(struct task_struct *task, const int sig)
68083+{
68084+ struct acl_subject_label *curr;
68085+ struct task_struct *tsk, *tsk2;
68086+ const struct cred *cred;
68087+ const struct cred *cred2;
68088+
68089+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68090+ return;
68091+
68092+ if (unlikely(!gr_acl_is_enabled()))
68093+ return;
68094+
68095+ curr = task->acl;
68096+
68097+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68098+ return;
68099+
68100+ if (time_before_eq(curr->expires, get_seconds())) {
68101+ curr->expires = 0;
68102+ curr->crashes = 0;
68103+ }
68104+
68105+ curr->crashes++;
68106+
68107+ if (!curr->expires)
68108+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68109+
68110+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68111+ time_after(curr->expires, get_seconds())) {
68112+ rcu_read_lock();
68113+ cred = __task_cred(task);
68114+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68115+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68116+ spin_lock(&gr_uid_lock);
68117+ gr_insert_uid(cred->uid, curr->expires);
68118+ spin_unlock(&gr_uid_lock);
68119+ curr->expires = 0;
68120+ curr->crashes = 0;
68121+ read_lock(&tasklist_lock);
68122+ do_each_thread(tsk2, tsk) {
68123+ cred2 = __task_cred(tsk);
68124+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68125+ gr_fake_force_sig(SIGKILL, tsk);
68126+ } while_each_thread(tsk2, tsk);
68127+ read_unlock(&tasklist_lock);
68128+ } else {
68129+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68130+ read_lock(&tasklist_lock);
68131+ read_lock(&grsec_exec_file_lock);
68132+ do_each_thread(tsk2, tsk) {
68133+ if (likely(tsk != task)) {
68134+ // if this thread has the same subject as the one that triggered
68135+ // RES_CRASH and it's the same binary, kill it
68136+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68137+ gr_fake_force_sig(SIGKILL, tsk);
68138+ }
68139+ } while_each_thread(tsk2, tsk);
68140+ read_unlock(&grsec_exec_file_lock);
68141+ read_unlock(&tasklist_lock);
68142+ }
68143+ rcu_read_unlock();
68144+ }
68145+
68146+ return;
68147+}
68148+
68149+int
68150+gr_check_crash_exec(const struct file *filp)
68151+{
68152+ struct acl_subject_label *curr;
68153+
68154+ if (unlikely(!gr_acl_is_enabled()))
68155+ return 0;
68156+
68157+ read_lock(&gr_inode_lock);
68158+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68159+ __get_dev(filp->f_path.dentry),
68160+ current->role);
68161+ read_unlock(&gr_inode_lock);
68162+
68163+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68164+ (!curr->crashes && !curr->expires))
68165+ return 0;
68166+
68167+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68168+ time_after(curr->expires, get_seconds()))
68169+ return 1;
68170+ else if (time_before_eq(curr->expires, get_seconds())) {
68171+ curr->crashes = 0;
68172+ curr->expires = 0;
68173+ }
68174+
68175+ return 0;
68176+}
68177+
68178+void
68179+gr_handle_alertkill(struct task_struct *task)
68180+{
68181+ struct acl_subject_label *curracl;
68182+ __u32 curr_ip;
68183+ struct task_struct *p, *p2;
68184+
68185+ if (unlikely(!gr_acl_is_enabled()))
68186+ return;
68187+
68188+ curracl = task->acl;
68189+ curr_ip = task->signal->curr_ip;
68190+
68191+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68192+ read_lock(&tasklist_lock);
68193+ do_each_thread(p2, p) {
68194+ if (p->signal->curr_ip == curr_ip)
68195+ gr_fake_force_sig(SIGKILL, p);
68196+ } while_each_thread(p2, p);
68197+ read_unlock(&tasklist_lock);
68198+ } else if (curracl->mode & GR_KILLPROC)
68199+ gr_fake_force_sig(SIGKILL, task);
68200+
68201+ return;
68202+}
68203diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68204new file mode 100644
68205index 0000000..98011b0
68206--- /dev/null
68207+++ b/grsecurity/gracl_shm.c
68208@@ -0,0 +1,40 @@
68209+#include <linux/kernel.h>
68210+#include <linux/mm.h>
68211+#include <linux/sched.h>
68212+#include <linux/file.h>
68213+#include <linux/ipc.h>
68214+#include <linux/gracl.h>
68215+#include <linux/grsecurity.h>
68216+#include <linux/grinternal.h>
68217+
68218+int
68219+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68220+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68221+{
68222+ struct task_struct *task;
68223+
68224+ if (!gr_acl_is_enabled())
68225+ return 1;
68226+
68227+ rcu_read_lock();
68228+ read_lock(&tasklist_lock);
68229+
68230+ task = find_task_by_vpid(shm_cprid);
68231+
68232+ if (unlikely(!task))
68233+ task = find_task_by_vpid(shm_lapid);
68234+
68235+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68236+ (task_pid_nr(task) == shm_lapid)) &&
68237+ (task->acl->mode & GR_PROTSHM) &&
68238+ (task->acl != current->acl))) {
68239+ read_unlock(&tasklist_lock);
68240+ rcu_read_unlock();
68241+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68242+ return 0;
68243+ }
68244+ read_unlock(&tasklist_lock);
68245+ rcu_read_unlock();
68246+
68247+ return 1;
68248+}
68249diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68250new file mode 100644
68251index 0000000..bc0be01
68252--- /dev/null
68253+++ b/grsecurity/grsec_chdir.c
68254@@ -0,0 +1,19 @@
68255+#include <linux/kernel.h>
68256+#include <linux/sched.h>
68257+#include <linux/fs.h>
68258+#include <linux/file.h>
68259+#include <linux/grsecurity.h>
68260+#include <linux/grinternal.h>
68261+
68262+void
68263+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68264+{
68265+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68266+ if ((grsec_enable_chdir && grsec_enable_group &&
68267+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68268+ !grsec_enable_group)) {
68269+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68270+ }
68271+#endif
68272+ return;
68273+}
68274diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68275new file mode 100644
68276index 0000000..bd6e105
68277--- /dev/null
68278+++ b/grsecurity/grsec_chroot.c
68279@@ -0,0 +1,370 @@
68280+#include <linux/kernel.h>
68281+#include <linux/module.h>
68282+#include <linux/sched.h>
68283+#include <linux/file.h>
68284+#include <linux/fs.h>
68285+#include <linux/mount.h>
68286+#include <linux/types.h>
68287+#include "../fs/mount.h"
68288+#include <linux/grsecurity.h>
68289+#include <linux/grinternal.h>
68290+
68291+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68292+static int gr_init_ran;
68293+#endif
68294+
68295+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68296+{
68297+#ifdef CONFIG_GRKERNSEC
68298+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68299+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68300+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68301+ && gr_init_ran
68302+#endif
68303+ )
68304+ task->gr_is_chrooted = 1;
68305+ else {
68306+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68307+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68308+ gr_init_ran = 1;
68309+#endif
68310+ task->gr_is_chrooted = 0;
68311+ }
68312+
68313+ task->gr_chroot_dentry = path->dentry;
68314+#endif
68315+ return;
68316+}
68317+
68318+void gr_clear_chroot_entries(struct task_struct *task)
68319+{
68320+#ifdef CONFIG_GRKERNSEC
68321+ task->gr_is_chrooted = 0;
68322+ task->gr_chroot_dentry = NULL;
68323+#endif
68324+ return;
68325+}
68326+
68327+int
68328+gr_handle_chroot_unix(const pid_t pid)
68329+{
68330+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68331+ struct task_struct *p;
68332+
68333+ if (unlikely(!grsec_enable_chroot_unix))
68334+ return 1;
68335+
68336+ if (likely(!proc_is_chrooted(current)))
68337+ return 1;
68338+
68339+ rcu_read_lock();
68340+ read_lock(&tasklist_lock);
68341+ p = find_task_by_vpid_unrestricted(pid);
68342+ if (unlikely(p && !have_same_root(current, p))) {
68343+ read_unlock(&tasklist_lock);
68344+ rcu_read_unlock();
68345+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68346+ return 0;
68347+ }
68348+ read_unlock(&tasklist_lock);
68349+ rcu_read_unlock();
68350+#endif
68351+ return 1;
68352+}
68353+
68354+int
68355+gr_handle_chroot_nice(void)
68356+{
68357+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68358+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68359+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68360+ return -EPERM;
68361+ }
68362+#endif
68363+ return 0;
68364+}
68365+
68366+int
68367+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68368+{
68369+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68370+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68371+ && proc_is_chrooted(current)) {
68372+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68373+ return -EACCES;
68374+ }
68375+#endif
68376+ return 0;
68377+}
68378+
68379+int
68380+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68381+{
68382+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68383+ struct task_struct *p;
68384+ int ret = 0;
68385+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68386+ return ret;
68387+
68388+ read_lock(&tasklist_lock);
68389+ do_each_pid_task(pid, type, p) {
68390+ if (!have_same_root(current, p)) {
68391+ ret = 1;
68392+ goto out;
68393+ }
68394+ } while_each_pid_task(pid, type, p);
68395+out:
68396+ read_unlock(&tasklist_lock);
68397+ return ret;
68398+#endif
68399+ return 0;
68400+}
68401+
68402+int
68403+gr_pid_is_chrooted(struct task_struct *p)
68404+{
68405+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68406+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68407+ return 0;
68408+
68409+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68410+ !have_same_root(current, p)) {
68411+ return 1;
68412+ }
68413+#endif
68414+ return 0;
68415+}
68416+
68417+EXPORT_SYMBOL(gr_pid_is_chrooted);
68418+
68419+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68420+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68421+{
68422+ struct path path, currentroot;
68423+ int ret = 0;
68424+
68425+ path.dentry = (struct dentry *)u_dentry;
68426+ path.mnt = (struct vfsmount *)u_mnt;
68427+ get_fs_root(current->fs, &currentroot);
68428+ if (path_is_under(&path, &currentroot))
68429+ ret = 1;
68430+ path_put(&currentroot);
68431+
68432+ return ret;
68433+}
68434+#endif
68435+
68436+int
68437+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68438+{
68439+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68440+ if (!grsec_enable_chroot_fchdir)
68441+ return 1;
68442+
68443+ if (!proc_is_chrooted(current))
68444+ return 1;
68445+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68446+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68447+ return 0;
68448+ }
68449+#endif
68450+ return 1;
68451+}
68452+
68453+int
68454+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68455+ const time_t shm_createtime)
68456+{
68457+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68458+ struct task_struct *p;
68459+ time_t starttime;
68460+
68461+ if (unlikely(!grsec_enable_chroot_shmat))
68462+ return 1;
68463+
68464+ if (likely(!proc_is_chrooted(current)))
68465+ return 1;
68466+
68467+ rcu_read_lock();
68468+ read_lock(&tasklist_lock);
68469+
68470+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68471+ starttime = p->start_time.tv_sec;
68472+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68473+ if (have_same_root(current, p)) {
68474+ goto allow;
68475+ } else {
68476+ read_unlock(&tasklist_lock);
68477+ rcu_read_unlock();
68478+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68479+ return 0;
68480+ }
68481+ }
68482+ /* creator exited, pid reuse, fall through to next check */
68483+ }
68484+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68485+ if (unlikely(!have_same_root(current, p))) {
68486+ read_unlock(&tasklist_lock);
68487+ rcu_read_unlock();
68488+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68489+ return 0;
68490+ }
68491+ }
68492+
68493+allow:
68494+ read_unlock(&tasklist_lock);
68495+ rcu_read_unlock();
68496+#endif
68497+ return 1;
68498+}
68499+
68500+void
68501+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68502+{
68503+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68504+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68505+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68506+#endif
68507+ return;
68508+}
68509+
68510+int
68511+gr_handle_chroot_mknod(const struct dentry *dentry,
68512+ const struct vfsmount *mnt, const int mode)
68513+{
68514+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68515+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68516+ proc_is_chrooted(current)) {
68517+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68518+ return -EPERM;
68519+ }
68520+#endif
68521+ return 0;
68522+}
68523+
68524+int
68525+gr_handle_chroot_mount(const struct dentry *dentry,
68526+ const struct vfsmount *mnt, const char *dev_name)
68527+{
68528+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68529+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68530+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68531+ return -EPERM;
68532+ }
68533+#endif
68534+ return 0;
68535+}
68536+
68537+int
68538+gr_handle_chroot_pivot(void)
68539+{
68540+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68541+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68542+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68543+ return -EPERM;
68544+ }
68545+#endif
68546+ return 0;
68547+}
68548+
68549+int
68550+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68551+{
68552+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68553+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68554+ !gr_is_outside_chroot(dentry, mnt)) {
68555+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68556+ return -EPERM;
68557+ }
68558+#endif
68559+ return 0;
68560+}
68561+
68562+extern const char *captab_log[];
68563+extern int captab_log_entries;
68564+
68565+int
68566+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68567+{
68568+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68569+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68570+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68571+ if (cap_raised(chroot_caps, cap)) {
68572+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68573+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68574+ }
68575+ return 0;
68576+ }
68577+ }
68578+#endif
68579+ return 1;
68580+}
68581+
68582+int
68583+gr_chroot_is_capable(const int cap)
68584+{
68585+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68586+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68587+#endif
68588+ return 1;
68589+}
68590+
68591+int
68592+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68593+{
68594+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68595+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68596+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68597+ if (cap_raised(chroot_caps, cap)) {
68598+ return 0;
68599+ }
68600+ }
68601+#endif
68602+ return 1;
68603+}
68604+
68605+int
68606+gr_chroot_is_capable_nolog(const int cap)
68607+{
68608+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68609+ return gr_task_chroot_is_capable_nolog(current, cap);
68610+#endif
68611+ return 1;
68612+}
68613+
68614+int
68615+gr_handle_chroot_sysctl(const int op)
68616+{
68617+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68618+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68619+ proc_is_chrooted(current))
68620+ return -EACCES;
68621+#endif
68622+ return 0;
68623+}
68624+
68625+void
68626+gr_handle_chroot_chdir(const struct path *path)
68627+{
68628+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68629+ if (grsec_enable_chroot_chdir)
68630+ set_fs_pwd(current->fs, path);
68631+#endif
68632+ return;
68633+}
68634+
68635+int
68636+gr_handle_chroot_chmod(const struct dentry *dentry,
68637+ const struct vfsmount *mnt, const int mode)
68638+{
68639+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68640+ /* allow chmod +s on directories, but not files */
68641+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68642+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68643+ proc_is_chrooted(current)) {
68644+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68645+ return -EPERM;
68646+ }
68647+#endif
68648+ return 0;
68649+}
68650diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68651new file mode 100644
68652index 0000000..ce65ceb
68653--- /dev/null
68654+++ b/grsecurity/grsec_disabled.c
68655@@ -0,0 +1,434 @@
68656+#include <linux/kernel.h>
68657+#include <linux/module.h>
68658+#include <linux/sched.h>
68659+#include <linux/file.h>
68660+#include <linux/fs.h>
68661+#include <linux/kdev_t.h>
68662+#include <linux/net.h>
68663+#include <linux/in.h>
68664+#include <linux/ip.h>
68665+#include <linux/skbuff.h>
68666+#include <linux/sysctl.h>
68667+
68668+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68669+void
68670+pax_set_initial_flags(struct linux_binprm *bprm)
68671+{
68672+ return;
68673+}
68674+#endif
68675+
68676+#ifdef CONFIG_SYSCTL
68677+__u32
68678+gr_handle_sysctl(const struct ctl_table * table, const int op)
68679+{
68680+ return 0;
68681+}
68682+#endif
68683+
68684+#ifdef CONFIG_TASKSTATS
68685+int gr_is_taskstats_denied(int pid)
68686+{
68687+ return 0;
68688+}
68689+#endif
68690+
68691+int
68692+gr_acl_is_enabled(void)
68693+{
68694+ return 0;
68695+}
68696+
68697+void
68698+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68699+{
68700+ return;
68701+}
68702+
68703+int
68704+gr_handle_rawio(const struct inode *inode)
68705+{
68706+ return 0;
68707+}
68708+
68709+void
68710+gr_acl_handle_psacct(struct task_struct *task, const long code)
68711+{
68712+ return;
68713+}
68714+
68715+int
68716+gr_handle_ptrace(struct task_struct *task, const long request)
68717+{
68718+ return 0;
68719+}
68720+
68721+int
68722+gr_handle_proc_ptrace(struct task_struct *task)
68723+{
68724+ return 0;
68725+}
68726+
68727+int
68728+gr_set_acls(const int type)
68729+{
68730+ return 0;
68731+}
68732+
68733+int
68734+gr_check_hidden_task(const struct task_struct *tsk)
68735+{
68736+ return 0;
68737+}
68738+
68739+int
68740+gr_check_protected_task(const struct task_struct *task)
68741+{
68742+ return 0;
68743+}
68744+
68745+int
68746+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68747+{
68748+ return 0;
68749+}
68750+
68751+void
68752+gr_copy_label(struct task_struct *tsk)
68753+{
68754+ return;
68755+}
68756+
68757+void
68758+gr_set_pax_flags(struct task_struct *task)
68759+{
68760+ return;
68761+}
68762+
68763+int
68764+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68765+ const int unsafe_share)
68766+{
68767+ return 0;
68768+}
68769+
68770+void
68771+gr_handle_delete(const ino_t ino, const dev_t dev)
68772+{
68773+ return;
68774+}
68775+
68776+void
68777+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68778+{
68779+ return;
68780+}
68781+
68782+void
68783+gr_handle_crash(struct task_struct *task, const int sig)
68784+{
68785+ return;
68786+}
68787+
68788+int
68789+gr_check_crash_exec(const struct file *filp)
68790+{
68791+ return 0;
68792+}
68793+
68794+int
68795+gr_check_crash_uid(const kuid_t uid)
68796+{
68797+ return 0;
68798+}
68799+
68800+void
68801+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68802+ struct dentry *old_dentry,
68803+ struct dentry *new_dentry,
68804+ struct vfsmount *mnt, const __u8 replace)
68805+{
68806+ return;
68807+}
68808+
68809+int
68810+gr_search_socket(const int family, const int type, const int protocol)
68811+{
68812+ return 1;
68813+}
68814+
68815+int
68816+gr_search_connectbind(const int mode, const struct socket *sock,
68817+ const struct sockaddr_in *addr)
68818+{
68819+ return 0;
68820+}
68821+
68822+void
68823+gr_handle_alertkill(struct task_struct *task)
68824+{
68825+ return;
68826+}
68827+
68828+__u32
68829+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68830+{
68831+ return 1;
68832+}
68833+
68834+__u32
68835+gr_acl_handle_hidden_file(const struct dentry * dentry,
68836+ const struct vfsmount * mnt)
68837+{
68838+ return 1;
68839+}
68840+
68841+__u32
68842+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68843+ int acc_mode)
68844+{
68845+ return 1;
68846+}
68847+
68848+__u32
68849+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68850+{
68851+ return 1;
68852+}
68853+
68854+__u32
68855+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68856+{
68857+ return 1;
68858+}
68859+
68860+int
68861+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68862+ unsigned int *vm_flags)
68863+{
68864+ return 1;
68865+}
68866+
68867+__u32
68868+gr_acl_handle_truncate(const struct dentry * dentry,
68869+ const struct vfsmount * mnt)
68870+{
68871+ return 1;
68872+}
68873+
68874+__u32
68875+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68876+{
68877+ return 1;
68878+}
68879+
68880+__u32
68881+gr_acl_handle_access(const struct dentry * dentry,
68882+ const struct vfsmount * mnt, const int fmode)
68883+{
68884+ return 1;
68885+}
68886+
68887+__u32
68888+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68889+ umode_t *mode)
68890+{
68891+ return 1;
68892+}
68893+
68894+__u32
68895+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68896+{
68897+ return 1;
68898+}
68899+
68900+__u32
68901+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68902+{
68903+ return 1;
68904+}
68905+
68906+void
68907+grsecurity_init(void)
68908+{
68909+ return;
68910+}
68911+
68912+umode_t gr_acl_umask(void)
68913+{
68914+ return 0;
68915+}
68916+
68917+__u32
68918+gr_acl_handle_mknod(const struct dentry * new_dentry,
68919+ const struct dentry * parent_dentry,
68920+ const struct vfsmount * parent_mnt,
68921+ const int mode)
68922+{
68923+ return 1;
68924+}
68925+
68926+__u32
68927+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68928+ const struct dentry * parent_dentry,
68929+ const struct vfsmount * parent_mnt)
68930+{
68931+ return 1;
68932+}
68933+
68934+__u32
68935+gr_acl_handle_symlink(const struct dentry * new_dentry,
68936+ const struct dentry * parent_dentry,
68937+ const struct vfsmount * parent_mnt, const struct filename *from)
68938+{
68939+ return 1;
68940+}
68941+
68942+__u32
68943+gr_acl_handle_link(const struct dentry * new_dentry,
68944+ const struct dentry * parent_dentry,
68945+ const struct vfsmount * parent_mnt,
68946+ const struct dentry * old_dentry,
68947+ const struct vfsmount * old_mnt, const struct filename *to)
68948+{
68949+ return 1;
68950+}
68951+
68952+int
68953+gr_acl_handle_rename(const struct dentry *new_dentry,
68954+ const struct dentry *parent_dentry,
68955+ const struct vfsmount *parent_mnt,
68956+ const struct dentry *old_dentry,
68957+ const struct inode *old_parent_inode,
68958+ const struct vfsmount *old_mnt, const struct filename *newname)
68959+{
68960+ return 0;
68961+}
68962+
68963+int
68964+gr_acl_handle_filldir(const struct file *file, const char *name,
68965+ const int namelen, const ino_t ino)
68966+{
68967+ return 1;
68968+}
68969+
68970+int
68971+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68972+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68973+{
68974+ return 1;
68975+}
68976+
68977+int
68978+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
68979+{
68980+ return 0;
68981+}
68982+
68983+int
68984+gr_search_accept(const struct socket *sock)
68985+{
68986+ return 0;
68987+}
68988+
68989+int
68990+gr_search_listen(const struct socket *sock)
68991+{
68992+ return 0;
68993+}
68994+
68995+int
68996+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
68997+{
68998+ return 0;
68999+}
69000+
69001+__u32
69002+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69003+{
69004+ return 1;
69005+}
69006+
69007+__u32
69008+gr_acl_handle_creat(const struct dentry * dentry,
69009+ const struct dentry * p_dentry,
69010+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69011+ const int imode)
69012+{
69013+ return 1;
69014+}
69015+
69016+void
69017+gr_acl_handle_exit(void)
69018+{
69019+ return;
69020+}
69021+
69022+int
69023+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69024+{
69025+ return 1;
69026+}
69027+
69028+void
69029+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69030+{
69031+ return;
69032+}
69033+
69034+int
69035+gr_acl_handle_procpidmem(const struct task_struct *task)
69036+{
69037+ return 0;
69038+}
69039+
69040+int
69041+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69042+{
69043+ return 0;
69044+}
69045+
69046+int
69047+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69048+{
69049+ return 0;
69050+}
69051+
69052+void
69053+gr_set_kernel_label(struct task_struct *task)
69054+{
69055+ return;
69056+}
69057+
69058+int
69059+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69060+{
69061+ return 0;
69062+}
69063+
69064+int
69065+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69066+{
69067+ return 0;
69068+}
69069+
69070+int gr_acl_enable_at_secure(void)
69071+{
69072+ return 0;
69073+}
69074+
69075+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69076+{
69077+ return dentry->d_sb->s_dev;
69078+}
69079+
69080+void gr_put_exec_file(struct task_struct *task)
69081+{
69082+ return;
69083+}
69084+
69085+EXPORT_SYMBOL(gr_set_kernel_label);
69086+#ifdef CONFIG_SECURITY
69087+EXPORT_SYMBOL(gr_check_user_change);
69088+EXPORT_SYMBOL(gr_check_group_change);
69089+#endif
69090diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69091new file mode 100644
69092index 0000000..387032b
69093--- /dev/null
69094+++ b/grsecurity/grsec_exec.c
69095@@ -0,0 +1,187 @@
69096+#include <linux/kernel.h>
69097+#include <linux/sched.h>
69098+#include <linux/file.h>
69099+#include <linux/binfmts.h>
69100+#include <linux/fs.h>
69101+#include <linux/types.h>
69102+#include <linux/grdefs.h>
69103+#include <linux/grsecurity.h>
69104+#include <linux/grinternal.h>
69105+#include <linux/capability.h>
69106+#include <linux/module.h>
69107+#include <linux/compat.h>
69108+
69109+#include <asm/uaccess.h>
69110+
69111+#ifdef CONFIG_GRKERNSEC_EXECLOG
69112+static char gr_exec_arg_buf[132];
69113+static DEFINE_MUTEX(gr_exec_arg_mutex);
69114+#endif
69115+
69116+struct user_arg_ptr {
69117+#ifdef CONFIG_COMPAT
69118+ bool is_compat;
69119+#endif
69120+ union {
69121+ const char __user *const __user *native;
69122+#ifdef CONFIG_COMPAT
69123+ const compat_uptr_t __user *compat;
69124+#endif
69125+ } ptr;
69126+};
69127+
69128+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69129+
69130+void
69131+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69132+{
69133+#ifdef CONFIG_GRKERNSEC_EXECLOG
69134+ char *grarg = gr_exec_arg_buf;
69135+ unsigned int i, x, execlen = 0;
69136+ char c;
69137+
69138+ if (!((grsec_enable_execlog && grsec_enable_group &&
69139+ in_group_p(grsec_audit_gid))
69140+ || (grsec_enable_execlog && !grsec_enable_group)))
69141+ return;
69142+
69143+ mutex_lock(&gr_exec_arg_mutex);
69144+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69145+
69146+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69147+ const char __user *p;
69148+ unsigned int len;
69149+
69150+ p = get_user_arg_ptr(argv, i);
69151+ if (IS_ERR(p))
69152+ goto log;
69153+
69154+ len = strnlen_user(p, 128 - execlen);
69155+ if (len > 128 - execlen)
69156+ len = 128 - execlen;
69157+ else if (len > 0)
69158+ len--;
69159+ if (copy_from_user(grarg + execlen, p, len))
69160+ goto log;
69161+
69162+ /* rewrite unprintable characters */
69163+ for (x = 0; x < len; x++) {
69164+ c = *(grarg + execlen + x);
69165+ if (c < 32 || c > 126)
69166+ *(grarg + execlen + x) = ' ';
69167+ }
69168+
69169+ execlen += len;
69170+ *(grarg + execlen) = ' ';
69171+ *(grarg + execlen + 1) = '\0';
69172+ execlen++;
69173+ }
69174+
69175+ log:
69176+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69177+ bprm->file->f_path.mnt, grarg);
69178+ mutex_unlock(&gr_exec_arg_mutex);
69179+#endif
69180+ return;
69181+}
69182+
69183+#ifdef CONFIG_GRKERNSEC
69184+extern int gr_acl_is_capable(const int cap);
69185+extern int gr_acl_is_capable_nolog(const int cap);
69186+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69187+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69188+extern int gr_chroot_is_capable(const int cap);
69189+extern int gr_chroot_is_capable_nolog(const int cap);
69190+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69191+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69192+#endif
69193+
69194+const char *captab_log[] = {
69195+ "CAP_CHOWN",
69196+ "CAP_DAC_OVERRIDE",
69197+ "CAP_DAC_READ_SEARCH",
69198+ "CAP_FOWNER",
69199+ "CAP_FSETID",
69200+ "CAP_KILL",
69201+ "CAP_SETGID",
69202+ "CAP_SETUID",
69203+ "CAP_SETPCAP",
69204+ "CAP_LINUX_IMMUTABLE",
69205+ "CAP_NET_BIND_SERVICE",
69206+ "CAP_NET_BROADCAST",
69207+ "CAP_NET_ADMIN",
69208+ "CAP_NET_RAW",
69209+ "CAP_IPC_LOCK",
69210+ "CAP_IPC_OWNER",
69211+ "CAP_SYS_MODULE",
69212+ "CAP_SYS_RAWIO",
69213+ "CAP_SYS_CHROOT",
69214+ "CAP_SYS_PTRACE",
69215+ "CAP_SYS_PACCT",
69216+ "CAP_SYS_ADMIN",
69217+ "CAP_SYS_BOOT",
69218+ "CAP_SYS_NICE",
69219+ "CAP_SYS_RESOURCE",
69220+ "CAP_SYS_TIME",
69221+ "CAP_SYS_TTY_CONFIG",
69222+ "CAP_MKNOD",
69223+ "CAP_LEASE",
69224+ "CAP_AUDIT_WRITE",
69225+ "CAP_AUDIT_CONTROL",
69226+ "CAP_SETFCAP",
69227+ "CAP_MAC_OVERRIDE",
69228+ "CAP_MAC_ADMIN",
69229+ "CAP_SYSLOG",
69230+ "CAP_WAKE_ALARM"
69231+};
69232+
69233+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69234+
69235+int gr_is_capable(const int cap)
69236+{
69237+#ifdef CONFIG_GRKERNSEC
69238+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69239+ return 1;
69240+ return 0;
69241+#else
69242+ return 1;
69243+#endif
69244+}
69245+
69246+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69247+{
69248+#ifdef CONFIG_GRKERNSEC
69249+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69250+ return 1;
69251+ return 0;
69252+#else
69253+ return 1;
69254+#endif
69255+}
69256+
69257+int gr_is_capable_nolog(const int cap)
69258+{
69259+#ifdef CONFIG_GRKERNSEC
69260+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69261+ return 1;
69262+ return 0;
69263+#else
69264+ return 1;
69265+#endif
69266+}
69267+
69268+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69269+{
69270+#ifdef CONFIG_GRKERNSEC
69271+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69272+ return 1;
69273+ return 0;
69274+#else
69275+ return 1;
69276+#endif
69277+}
69278+
69279+EXPORT_SYMBOL(gr_is_capable);
69280+EXPORT_SYMBOL(gr_is_capable_nolog);
69281+EXPORT_SYMBOL(gr_task_is_capable);
69282+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69283diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69284new file mode 100644
69285index 0000000..06cc6ea
69286--- /dev/null
69287+++ b/grsecurity/grsec_fifo.c
69288@@ -0,0 +1,24 @@
69289+#include <linux/kernel.h>
69290+#include <linux/sched.h>
69291+#include <linux/fs.h>
69292+#include <linux/file.h>
69293+#include <linux/grinternal.h>
69294+
69295+int
69296+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69297+ const struct dentry *dir, const int flag, const int acc_mode)
69298+{
69299+#ifdef CONFIG_GRKERNSEC_FIFO
69300+ const struct cred *cred = current_cred();
69301+
69302+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69303+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69304+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69305+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69306+ if (!inode_permission(dentry->d_inode, acc_mode))
69307+ 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));
69308+ return -EACCES;
69309+ }
69310+#endif
69311+ return 0;
69312+}
69313diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69314new file mode 100644
69315index 0000000..8ca18bf
69316--- /dev/null
69317+++ b/grsecurity/grsec_fork.c
69318@@ -0,0 +1,23 @@
69319+#include <linux/kernel.h>
69320+#include <linux/sched.h>
69321+#include <linux/grsecurity.h>
69322+#include <linux/grinternal.h>
69323+#include <linux/errno.h>
69324+
69325+void
69326+gr_log_forkfail(const int retval)
69327+{
69328+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69329+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69330+ switch (retval) {
69331+ case -EAGAIN:
69332+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69333+ break;
69334+ case -ENOMEM:
69335+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69336+ break;
69337+ }
69338+ }
69339+#endif
69340+ return;
69341+}
69342diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69343new file mode 100644
69344index 0000000..99a0cb9
69345--- /dev/null
69346+++ b/grsecurity/grsec_init.c
69347@@ -0,0 +1,283 @@
69348+#include <linux/kernel.h>
69349+#include <linux/sched.h>
69350+#include <linux/mm.h>
69351+#include <linux/gracl.h>
69352+#include <linux/slab.h>
69353+#include <linux/vmalloc.h>
69354+#include <linux/percpu.h>
69355+#include <linux/module.h>
69356+
69357+int grsec_enable_ptrace_readexec;
69358+int grsec_enable_setxid;
69359+int grsec_enable_symlinkown;
69360+kgid_t grsec_symlinkown_gid;
69361+int grsec_enable_brute;
69362+int grsec_enable_link;
69363+int grsec_enable_dmesg;
69364+int grsec_enable_harden_ptrace;
69365+int grsec_enable_fifo;
69366+int grsec_enable_execlog;
69367+int grsec_enable_signal;
69368+int grsec_enable_forkfail;
69369+int grsec_enable_audit_ptrace;
69370+int grsec_enable_time;
69371+int grsec_enable_group;
69372+kgid_t grsec_audit_gid;
69373+int grsec_enable_chdir;
69374+int grsec_enable_mount;
69375+int grsec_enable_rofs;
69376+int grsec_deny_new_usb;
69377+int grsec_enable_chroot_findtask;
69378+int grsec_enable_chroot_mount;
69379+int grsec_enable_chroot_shmat;
69380+int grsec_enable_chroot_fchdir;
69381+int grsec_enable_chroot_double;
69382+int grsec_enable_chroot_pivot;
69383+int grsec_enable_chroot_chdir;
69384+int grsec_enable_chroot_chmod;
69385+int grsec_enable_chroot_mknod;
69386+int grsec_enable_chroot_nice;
69387+int grsec_enable_chroot_execlog;
69388+int grsec_enable_chroot_caps;
69389+int grsec_enable_chroot_sysctl;
69390+int grsec_enable_chroot_unix;
69391+int grsec_enable_tpe;
69392+kgid_t grsec_tpe_gid;
69393+int grsec_enable_blackhole;
69394+#ifdef CONFIG_IPV6_MODULE
69395+EXPORT_SYMBOL(grsec_enable_blackhole);
69396+#endif
69397+int grsec_lastack_retries;
69398+int grsec_enable_tpe_all;
69399+int grsec_enable_tpe_invert;
69400+int grsec_enable_socket_all;
69401+kgid_t grsec_socket_all_gid;
69402+int grsec_enable_socket_client;
69403+kgid_t grsec_socket_client_gid;
69404+int grsec_enable_socket_server;
69405+kgid_t grsec_socket_server_gid;
69406+int grsec_resource_logging;
69407+int grsec_disable_privio;
69408+int grsec_enable_log_rwxmaps;
69409+int grsec_lock;
69410+
69411+DEFINE_SPINLOCK(grsec_alert_lock);
69412+unsigned long grsec_alert_wtime = 0;
69413+unsigned long grsec_alert_fyet = 0;
69414+
69415+DEFINE_SPINLOCK(grsec_audit_lock);
69416+
69417+DEFINE_RWLOCK(grsec_exec_file_lock);
69418+
69419+char *gr_shared_page[4];
69420+
69421+char *gr_alert_log_fmt;
69422+char *gr_audit_log_fmt;
69423+char *gr_alert_log_buf;
69424+char *gr_audit_log_buf;
69425+
69426+extern struct gr_arg *gr_usermode;
69427+extern unsigned char *gr_system_salt;
69428+extern unsigned char *gr_system_sum;
69429+
69430+void __init
69431+grsecurity_init(void)
69432+{
69433+ int j;
69434+ /* create the per-cpu shared pages */
69435+
69436+#ifdef CONFIG_X86
69437+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69438+#endif
69439+
69440+ for (j = 0; j < 4; j++) {
69441+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69442+ if (gr_shared_page[j] == NULL) {
69443+ panic("Unable to allocate grsecurity shared page");
69444+ return;
69445+ }
69446+ }
69447+
69448+ /* allocate log buffers */
69449+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69450+ if (!gr_alert_log_fmt) {
69451+ panic("Unable to allocate grsecurity alert log format buffer");
69452+ return;
69453+ }
69454+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69455+ if (!gr_audit_log_fmt) {
69456+ panic("Unable to allocate grsecurity audit log format buffer");
69457+ return;
69458+ }
69459+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69460+ if (!gr_alert_log_buf) {
69461+ panic("Unable to allocate grsecurity alert log buffer");
69462+ return;
69463+ }
69464+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69465+ if (!gr_audit_log_buf) {
69466+ panic("Unable to allocate grsecurity audit log buffer");
69467+ return;
69468+ }
69469+
69470+ /* allocate memory for authentication structure */
69471+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69472+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69473+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69474+
69475+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69476+ panic("Unable to allocate grsecurity authentication structure");
69477+ return;
69478+ }
69479+
69480+
69481+#ifdef CONFIG_GRKERNSEC_IO
69482+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69483+ grsec_disable_privio = 1;
69484+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69485+ grsec_disable_privio = 1;
69486+#else
69487+ grsec_disable_privio = 0;
69488+#endif
69489+#endif
69490+
69491+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69492+ /* for backward compatibility, tpe_invert always defaults to on if
69493+ enabled in the kernel
69494+ */
69495+ grsec_enable_tpe_invert = 1;
69496+#endif
69497+
69498+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69499+#ifndef CONFIG_GRKERNSEC_SYSCTL
69500+ grsec_lock = 1;
69501+#endif
69502+
69503+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69504+ grsec_enable_log_rwxmaps = 1;
69505+#endif
69506+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69507+ grsec_enable_group = 1;
69508+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69509+#endif
69510+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69511+ grsec_enable_ptrace_readexec = 1;
69512+#endif
69513+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69514+ grsec_enable_chdir = 1;
69515+#endif
69516+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69517+ grsec_enable_harden_ptrace = 1;
69518+#endif
69519+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69520+ grsec_enable_mount = 1;
69521+#endif
69522+#ifdef CONFIG_GRKERNSEC_LINK
69523+ grsec_enable_link = 1;
69524+#endif
69525+#ifdef CONFIG_GRKERNSEC_BRUTE
69526+ grsec_enable_brute = 1;
69527+#endif
69528+#ifdef CONFIG_GRKERNSEC_DMESG
69529+ grsec_enable_dmesg = 1;
69530+#endif
69531+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69532+ grsec_enable_blackhole = 1;
69533+ grsec_lastack_retries = 4;
69534+#endif
69535+#ifdef CONFIG_GRKERNSEC_FIFO
69536+ grsec_enable_fifo = 1;
69537+#endif
69538+#ifdef CONFIG_GRKERNSEC_EXECLOG
69539+ grsec_enable_execlog = 1;
69540+#endif
69541+#ifdef CONFIG_GRKERNSEC_SETXID
69542+ grsec_enable_setxid = 1;
69543+#endif
69544+#ifdef CONFIG_GRKERNSEC_SIGNAL
69545+ grsec_enable_signal = 1;
69546+#endif
69547+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69548+ grsec_enable_forkfail = 1;
69549+#endif
69550+#ifdef CONFIG_GRKERNSEC_TIME
69551+ grsec_enable_time = 1;
69552+#endif
69553+#ifdef CONFIG_GRKERNSEC_RESLOG
69554+ grsec_resource_logging = 1;
69555+#endif
69556+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69557+ grsec_enable_chroot_findtask = 1;
69558+#endif
69559+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69560+ grsec_enable_chroot_unix = 1;
69561+#endif
69562+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69563+ grsec_enable_chroot_mount = 1;
69564+#endif
69565+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69566+ grsec_enable_chroot_fchdir = 1;
69567+#endif
69568+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69569+ grsec_enable_chroot_shmat = 1;
69570+#endif
69571+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69572+ grsec_enable_audit_ptrace = 1;
69573+#endif
69574+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69575+ grsec_enable_chroot_double = 1;
69576+#endif
69577+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69578+ grsec_enable_chroot_pivot = 1;
69579+#endif
69580+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69581+ grsec_enable_chroot_chdir = 1;
69582+#endif
69583+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69584+ grsec_enable_chroot_chmod = 1;
69585+#endif
69586+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69587+ grsec_enable_chroot_mknod = 1;
69588+#endif
69589+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69590+ grsec_enable_chroot_nice = 1;
69591+#endif
69592+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69593+ grsec_enable_chroot_execlog = 1;
69594+#endif
69595+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69596+ grsec_enable_chroot_caps = 1;
69597+#endif
69598+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69599+ grsec_enable_chroot_sysctl = 1;
69600+#endif
69601+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69602+ grsec_enable_symlinkown = 1;
69603+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69604+#endif
69605+#ifdef CONFIG_GRKERNSEC_TPE
69606+ grsec_enable_tpe = 1;
69607+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69608+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69609+ grsec_enable_tpe_all = 1;
69610+#endif
69611+#endif
69612+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69613+ grsec_enable_socket_all = 1;
69614+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69615+#endif
69616+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69617+ grsec_enable_socket_client = 1;
69618+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69619+#endif
69620+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69621+ grsec_enable_socket_server = 1;
69622+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69623+#endif
69624+#endif
69625+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69626+ grsec_deny_new_usb = 1;
69627+#endif
69628+
69629+ return;
69630+}
69631diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69632new file mode 100644
69633index 0000000..5e05e20
69634--- /dev/null
69635+++ b/grsecurity/grsec_link.c
69636@@ -0,0 +1,58 @@
69637+#include <linux/kernel.h>
69638+#include <linux/sched.h>
69639+#include <linux/fs.h>
69640+#include <linux/file.h>
69641+#include <linux/grinternal.h>
69642+
69643+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69644+{
69645+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69646+ const struct inode *link_inode = link->dentry->d_inode;
69647+
69648+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69649+ /* ignore root-owned links, e.g. /proc/self */
69650+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69651+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69652+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69653+ return 1;
69654+ }
69655+#endif
69656+ return 0;
69657+}
69658+
69659+int
69660+gr_handle_follow_link(const struct inode *parent,
69661+ const struct inode *inode,
69662+ const struct dentry *dentry, const struct vfsmount *mnt)
69663+{
69664+#ifdef CONFIG_GRKERNSEC_LINK
69665+ const struct cred *cred = current_cred();
69666+
69667+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69668+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69669+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69670+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69671+ return -EACCES;
69672+ }
69673+#endif
69674+ return 0;
69675+}
69676+
69677+int
69678+gr_handle_hardlink(const struct dentry *dentry,
69679+ const struct vfsmount *mnt,
69680+ struct inode *inode, const int mode, const struct filename *to)
69681+{
69682+#ifdef CONFIG_GRKERNSEC_LINK
69683+ const struct cred *cred = current_cred();
69684+
69685+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69686+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69687+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69688+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69689+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69690+ return -EPERM;
69691+ }
69692+#endif
69693+ return 0;
69694+}
69695diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69696new file mode 100644
69697index 0000000..dbe0a6b
69698--- /dev/null
69699+++ b/grsecurity/grsec_log.c
69700@@ -0,0 +1,341 @@
69701+#include <linux/kernel.h>
69702+#include <linux/sched.h>
69703+#include <linux/file.h>
69704+#include <linux/tty.h>
69705+#include <linux/fs.h>
69706+#include <linux/mm.h>
69707+#include <linux/grinternal.h>
69708+
69709+#ifdef CONFIG_TREE_PREEMPT_RCU
69710+#define DISABLE_PREEMPT() preempt_disable()
69711+#define ENABLE_PREEMPT() preempt_enable()
69712+#else
69713+#define DISABLE_PREEMPT()
69714+#define ENABLE_PREEMPT()
69715+#endif
69716+
69717+#define BEGIN_LOCKS(x) \
69718+ DISABLE_PREEMPT(); \
69719+ rcu_read_lock(); \
69720+ read_lock(&tasklist_lock); \
69721+ read_lock(&grsec_exec_file_lock); \
69722+ if (x != GR_DO_AUDIT) \
69723+ spin_lock(&grsec_alert_lock); \
69724+ else \
69725+ spin_lock(&grsec_audit_lock)
69726+
69727+#define END_LOCKS(x) \
69728+ if (x != GR_DO_AUDIT) \
69729+ spin_unlock(&grsec_alert_lock); \
69730+ else \
69731+ spin_unlock(&grsec_audit_lock); \
69732+ read_unlock(&grsec_exec_file_lock); \
69733+ read_unlock(&tasklist_lock); \
69734+ rcu_read_unlock(); \
69735+ ENABLE_PREEMPT(); \
69736+ if (x == GR_DONT_AUDIT) \
69737+ gr_handle_alertkill(current)
69738+
69739+enum {
69740+ FLOODING,
69741+ NO_FLOODING
69742+};
69743+
69744+extern char *gr_alert_log_fmt;
69745+extern char *gr_audit_log_fmt;
69746+extern char *gr_alert_log_buf;
69747+extern char *gr_audit_log_buf;
69748+
69749+static int gr_log_start(int audit)
69750+{
69751+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69752+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69753+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69754+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69755+ unsigned long curr_secs = get_seconds();
69756+
69757+ if (audit == GR_DO_AUDIT)
69758+ goto set_fmt;
69759+
69760+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69761+ grsec_alert_wtime = curr_secs;
69762+ grsec_alert_fyet = 0;
69763+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69764+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69765+ grsec_alert_fyet++;
69766+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69767+ grsec_alert_wtime = curr_secs;
69768+ grsec_alert_fyet++;
69769+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69770+ return FLOODING;
69771+ }
69772+ else return FLOODING;
69773+
69774+set_fmt:
69775+#endif
69776+ memset(buf, 0, PAGE_SIZE);
69777+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69778+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69779+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69780+ } else if (current->signal->curr_ip) {
69781+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69782+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69783+ } else if (gr_acl_is_enabled()) {
69784+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69785+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69786+ } else {
69787+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69788+ strcpy(buf, fmt);
69789+ }
69790+
69791+ return NO_FLOODING;
69792+}
69793+
69794+static void gr_log_middle(int audit, const char *msg, va_list ap)
69795+ __attribute__ ((format (printf, 2, 0)));
69796+
69797+static void gr_log_middle(int audit, const char *msg, va_list ap)
69798+{
69799+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69800+ unsigned int len = strlen(buf);
69801+
69802+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69803+
69804+ return;
69805+}
69806+
69807+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69808+ __attribute__ ((format (printf, 2, 3)));
69809+
69810+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69811+{
69812+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69813+ unsigned int len = strlen(buf);
69814+ va_list ap;
69815+
69816+ va_start(ap, msg);
69817+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69818+ va_end(ap);
69819+
69820+ return;
69821+}
69822+
69823+static void gr_log_end(int audit, int append_default)
69824+{
69825+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69826+ if (append_default) {
69827+ struct task_struct *task = current;
69828+ struct task_struct *parent = task->real_parent;
69829+ const struct cred *cred = __task_cred(task);
69830+ const struct cred *pcred = __task_cred(parent);
69831+ unsigned int len = strlen(buf);
69832+
69833+ 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));
69834+ }
69835+
69836+ printk("%s\n", buf);
69837+
69838+ return;
69839+}
69840+
69841+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69842+{
69843+ int logtype;
69844+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69845+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69846+ void *voidptr = NULL;
69847+ int num1 = 0, num2 = 0;
69848+ unsigned long ulong1 = 0, ulong2 = 0;
69849+ struct dentry *dentry = NULL;
69850+ struct vfsmount *mnt = NULL;
69851+ struct file *file = NULL;
69852+ struct task_struct *task = NULL;
69853+ struct vm_area_struct *vma = NULL;
69854+ const struct cred *cred, *pcred;
69855+ va_list ap;
69856+
69857+ BEGIN_LOCKS(audit);
69858+ logtype = gr_log_start(audit);
69859+ if (logtype == FLOODING) {
69860+ END_LOCKS(audit);
69861+ return;
69862+ }
69863+ va_start(ap, argtypes);
69864+ switch (argtypes) {
69865+ case GR_TTYSNIFF:
69866+ task = va_arg(ap, struct task_struct *);
69867+ 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));
69868+ break;
69869+ case GR_SYSCTL_HIDDEN:
69870+ str1 = va_arg(ap, char *);
69871+ gr_log_middle_varargs(audit, msg, result, str1);
69872+ break;
69873+ case GR_RBAC:
69874+ dentry = va_arg(ap, struct dentry *);
69875+ mnt = va_arg(ap, struct vfsmount *);
69876+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69877+ break;
69878+ case GR_RBAC_STR:
69879+ dentry = va_arg(ap, struct dentry *);
69880+ mnt = va_arg(ap, struct vfsmount *);
69881+ str1 = va_arg(ap, char *);
69882+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69883+ break;
69884+ case GR_STR_RBAC:
69885+ str1 = va_arg(ap, char *);
69886+ dentry = va_arg(ap, struct dentry *);
69887+ mnt = va_arg(ap, struct vfsmount *);
69888+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69889+ break;
69890+ case GR_RBAC_MODE2:
69891+ dentry = va_arg(ap, struct dentry *);
69892+ mnt = va_arg(ap, struct vfsmount *);
69893+ str1 = va_arg(ap, char *);
69894+ str2 = va_arg(ap, char *);
69895+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69896+ break;
69897+ case GR_RBAC_MODE3:
69898+ dentry = va_arg(ap, struct dentry *);
69899+ mnt = va_arg(ap, struct vfsmount *);
69900+ str1 = va_arg(ap, char *);
69901+ str2 = va_arg(ap, char *);
69902+ str3 = va_arg(ap, char *);
69903+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69904+ break;
69905+ case GR_FILENAME:
69906+ dentry = va_arg(ap, struct dentry *);
69907+ mnt = va_arg(ap, struct vfsmount *);
69908+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69909+ break;
69910+ case GR_STR_FILENAME:
69911+ str1 = va_arg(ap, char *);
69912+ dentry = va_arg(ap, struct dentry *);
69913+ mnt = va_arg(ap, struct vfsmount *);
69914+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69915+ break;
69916+ case GR_FILENAME_STR:
69917+ dentry = va_arg(ap, struct dentry *);
69918+ mnt = va_arg(ap, struct vfsmount *);
69919+ str1 = va_arg(ap, char *);
69920+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69921+ break;
69922+ case GR_FILENAME_TWO_INT:
69923+ dentry = va_arg(ap, struct dentry *);
69924+ mnt = va_arg(ap, struct vfsmount *);
69925+ num1 = va_arg(ap, int);
69926+ num2 = va_arg(ap, int);
69927+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69928+ break;
69929+ case GR_FILENAME_TWO_INT_STR:
69930+ dentry = va_arg(ap, struct dentry *);
69931+ mnt = va_arg(ap, struct vfsmount *);
69932+ num1 = va_arg(ap, int);
69933+ num2 = va_arg(ap, int);
69934+ str1 = va_arg(ap, char *);
69935+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69936+ break;
69937+ case GR_TEXTREL:
69938+ file = va_arg(ap, struct file *);
69939+ ulong1 = va_arg(ap, unsigned long);
69940+ ulong2 = va_arg(ap, unsigned long);
69941+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69942+ break;
69943+ case GR_PTRACE:
69944+ task = va_arg(ap, struct task_struct *);
69945+ 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));
69946+ break;
69947+ case GR_RESOURCE:
69948+ task = va_arg(ap, struct task_struct *);
69949+ cred = __task_cred(task);
69950+ pcred = __task_cred(task->real_parent);
69951+ ulong1 = va_arg(ap, unsigned long);
69952+ str1 = va_arg(ap, char *);
69953+ ulong2 = va_arg(ap, unsigned long);
69954+ 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));
69955+ break;
69956+ case GR_CAP:
69957+ task = va_arg(ap, struct task_struct *);
69958+ cred = __task_cred(task);
69959+ pcred = __task_cred(task->real_parent);
69960+ str1 = va_arg(ap, char *);
69961+ 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));
69962+ break;
69963+ case GR_SIG:
69964+ str1 = va_arg(ap, char *);
69965+ voidptr = va_arg(ap, void *);
69966+ gr_log_middle_varargs(audit, msg, str1, voidptr);
69967+ break;
69968+ case GR_SIG2:
69969+ task = va_arg(ap, struct task_struct *);
69970+ cred = __task_cred(task);
69971+ pcred = __task_cred(task->real_parent);
69972+ num1 = va_arg(ap, int);
69973+ 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));
69974+ break;
69975+ case GR_CRASH1:
69976+ task = va_arg(ap, struct task_struct *);
69977+ cred = __task_cred(task);
69978+ pcred = __task_cred(task->real_parent);
69979+ ulong1 = va_arg(ap, unsigned long);
69980+ 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);
69981+ break;
69982+ case GR_CRASH2:
69983+ task = va_arg(ap, struct task_struct *);
69984+ cred = __task_cred(task);
69985+ pcred = __task_cred(task->real_parent);
69986+ ulong1 = va_arg(ap, unsigned long);
69987+ 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);
69988+ break;
69989+ case GR_RWXMAP:
69990+ file = va_arg(ap, struct file *);
69991+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
69992+ break;
69993+ case GR_RWXMAPVMA:
69994+ vma = va_arg(ap, struct vm_area_struct *);
69995+ if (vma->vm_file)
69996+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
69997+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
69998+ str1 = "<stack>";
69999+ else if (vma->vm_start <= current->mm->brk &&
70000+ vma->vm_end >= current->mm->start_brk)
70001+ str1 = "<heap>";
70002+ else
70003+ str1 = "<anonymous mapping>";
70004+ gr_log_middle_varargs(audit, msg, str1);
70005+ break;
70006+ case GR_PSACCT:
70007+ {
70008+ unsigned int wday, cday;
70009+ __u8 whr, chr;
70010+ __u8 wmin, cmin;
70011+ __u8 wsec, csec;
70012+ char cur_tty[64] = { 0 };
70013+ char parent_tty[64] = { 0 };
70014+
70015+ task = va_arg(ap, struct task_struct *);
70016+ wday = va_arg(ap, unsigned int);
70017+ cday = va_arg(ap, unsigned int);
70018+ whr = va_arg(ap, int);
70019+ chr = va_arg(ap, int);
70020+ wmin = va_arg(ap, int);
70021+ cmin = va_arg(ap, int);
70022+ wsec = va_arg(ap, int);
70023+ csec = va_arg(ap, int);
70024+ ulong1 = va_arg(ap, unsigned long);
70025+ cred = __task_cred(task);
70026+ pcred = __task_cred(task->real_parent);
70027+
70028+ 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));
70029+ }
70030+ break;
70031+ default:
70032+ gr_log_middle(audit, msg, ap);
70033+ }
70034+ va_end(ap);
70035+ // these don't need DEFAULTSECARGS printed on the end
70036+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70037+ gr_log_end(audit, 0);
70038+ else
70039+ gr_log_end(audit, 1);
70040+ END_LOCKS(audit);
70041+}
70042diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70043new file mode 100644
70044index 0000000..f536303
70045--- /dev/null
70046+++ b/grsecurity/grsec_mem.c
70047@@ -0,0 +1,40 @@
70048+#include <linux/kernel.h>
70049+#include <linux/sched.h>
70050+#include <linux/mm.h>
70051+#include <linux/mman.h>
70052+#include <linux/grinternal.h>
70053+
70054+void
70055+gr_handle_ioperm(void)
70056+{
70057+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70058+ return;
70059+}
70060+
70061+void
70062+gr_handle_iopl(void)
70063+{
70064+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70065+ return;
70066+}
70067+
70068+void
70069+gr_handle_mem_readwrite(u64 from, u64 to)
70070+{
70071+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70072+ return;
70073+}
70074+
70075+void
70076+gr_handle_vm86(void)
70077+{
70078+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70079+ return;
70080+}
70081+
70082+void
70083+gr_log_badprocpid(const char *entry)
70084+{
70085+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70086+ return;
70087+}
70088diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70089new file mode 100644
70090index 0000000..2131422
70091--- /dev/null
70092+++ b/grsecurity/grsec_mount.c
70093@@ -0,0 +1,62 @@
70094+#include <linux/kernel.h>
70095+#include <linux/sched.h>
70096+#include <linux/mount.h>
70097+#include <linux/grsecurity.h>
70098+#include <linux/grinternal.h>
70099+
70100+void
70101+gr_log_remount(const char *devname, const int retval)
70102+{
70103+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70104+ if (grsec_enable_mount && (retval >= 0))
70105+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70106+#endif
70107+ return;
70108+}
70109+
70110+void
70111+gr_log_unmount(const char *devname, const int retval)
70112+{
70113+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70114+ if (grsec_enable_mount && (retval >= 0))
70115+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70116+#endif
70117+ return;
70118+}
70119+
70120+void
70121+gr_log_mount(const char *from, const char *to, const int retval)
70122+{
70123+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70124+ if (grsec_enable_mount && (retval >= 0))
70125+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70126+#endif
70127+ return;
70128+}
70129+
70130+int
70131+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70132+{
70133+#ifdef CONFIG_GRKERNSEC_ROFS
70134+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70135+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70136+ return -EPERM;
70137+ } else
70138+ return 0;
70139+#endif
70140+ return 0;
70141+}
70142+
70143+int
70144+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70145+{
70146+#ifdef CONFIG_GRKERNSEC_ROFS
70147+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70148+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70149+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70150+ return -EPERM;
70151+ } else
70152+ return 0;
70153+#endif
70154+ return 0;
70155+}
70156diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70157new file mode 100644
70158index 0000000..6ee9d50
70159--- /dev/null
70160+++ b/grsecurity/grsec_pax.c
70161@@ -0,0 +1,45 @@
70162+#include <linux/kernel.h>
70163+#include <linux/sched.h>
70164+#include <linux/mm.h>
70165+#include <linux/file.h>
70166+#include <linux/grinternal.h>
70167+#include <linux/grsecurity.h>
70168+
70169+void
70170+gr_log_textrel(struct vm_area_struct * vma)
70171+{
70172+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70173+ if (grsec_enable_log_rwxmaps)
70174+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70175+#endif
70176+ return;
70177+}
70178+
70179+void gr_log_ptgnustack(struct file *file)
70180+{
70181+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70182+ if (grsec_enable_log_rwxmaps)
70183+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70184+#endif
70185+ return;
70186+}
70187+
70188+void
70189+gr_log_rwxmmap(struct file *file)
70190+{
70191+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70192+ if (grsec_enable_log_rwxmaps)
70193+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70194+#endif
70195+ return;
70196+}
70197+
70198+void
70199+gr_log_rwxmprotect(struct vm_area_struct *vma)
70200+{
70201+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70202+ if (grsec_enable_log_rwxmaps)
70203+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70204+#endif
70205+ return;
70206+}
70207diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70208new file mode 100644
70209index 0000000..f7f29aa
70210--- /dev/null
70211+++ b/grsecurity/grsec_ptrace.c
70212@@ -0,0 +1,30 @@
70213+#include <linux/kernel.h>
70214+#include <linux/sched.h>
70215+#include <linux/grinternal.h>
70216+#include <linux/security.h>
70217+
70218+void
70219+gr_audit_ptrace(struct task_struct *task)
70220+{
70221+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70222+ if (grsec_enable_audit_ptrace)
70223+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70224+#endif
70225+ return;
70226+}
70227+
70228+int
70229+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70230+{
70231+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70232+ const struct dentry *dentry = file->f_path.dentry;
70233+ const struct vfsmount *mnt = file->f_path.mnt;
70234+
70235+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70236+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70237+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70238+ return -EACCES;
70239+ }
70240+#endif
70241+ return 0;
70242+}
70243diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70244new file mode 100644
70245index 0000000..4e29cc7
70246--- /dev/null
70247+++ b/grsecurity/grsec_sig.c
70248@@ -0,0 +1,246 @@
70249+#include <linux/kernel.h>
70250+#include <linux/sched.h>
70251+#include <linux/fs.h>
70252+#include <linux/delay.h>
70253+#include <linux/grsecurity.h>
70254+#include <linux/grinternal.h>
70255+#include <linux/hardirq.h>
70256+
70257+char *signames[] = {
70258+ [SIGSEGV] = "Segmentation fault",
70259+ [SIGILL] = "Illegal instruction",
70260+ [SIGABRT] = "Abort",
70261+ [SIGBUS] = "Invalid alignment/Bus error"
70262+};
70263+
70264+void
70265+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70266+{
70267+#ifdef CONFIG_GRKERNSEC_SIGNAL
70268+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70269+ (sig == SIGABRT) || (sig == SIGBUS))) {
70270+ if (task_pid_nr(t) == task_pid_nr(current)) {
70271+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70272+ } else {
70273+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70274+ }
70275+ }
70276+#endif
70277+ return;
70278+}
70279+
70280+int
70281+gr_handle_signal(const struct task_struct *p, const int sig)
70282+{
70283+#ifdef CONFIG_GRKERNSEC
70284+ /* ignore the 0 signal for protected task checks */
70285+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70286+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70287+ return -EPERM;
70288+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70289+ return -EPERM;
70290+ }
70291+#endif
70292+ return 0;
70293+}
70294+
70295+#ifdef CONFIG_GRKERNSEC
70296+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70297+
70298+int gr_fake_force_sig(int sig, struct task_struct *t)
70299+{
70300+ unsigned long int flags;
70301+ int ret, blocked, ignored;
70302+ struct k_sigaction *action;
70303+
70304+ spin_lock_irqsave(&t->sighand->siglock, flags);
70305+ action = &t->sighand->action[sig-1];
70306+ ignored = action->sa.sa_handler == SIG_IGN;
70307+ blocked = sigismember(&t->blocked, sig);
70308+ if (blocked || ignored) {
70309+ action->sa.sa_handler = SIG_DFL;
70310+ if (blocked) {
70311+ sigdelset(&t->blocked, sig);
70312+ recalc_sigpending_and_wake(t);
70313+ }
70314+ }
70315+ if (action->sa.sa_handler == SIG_DFL)
70316+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70317+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70318+
70319+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70320+
70321+ return ret;
70322+}
70323+#endif
70324+
70325+#ifdef CONFIG_GRKERNSEC_BRUTE
70326+#define GR_USER_BAN_TIME (15 * 60)
70327+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70328+
70329+static int __get_dumpable(unsigned long mm_flags)
70330+{
70331+ int ret;
70332+
70333+ ret = mm_flags & MMF_DUMPABLE_MASK;
70334+ return (ret >= 2) ? 2 : ret;
70335+}
70336+#endif
70337+
70338+void gr_handle_brute_attach(unsigned long mm_flags)
70339+{
70340+#ifdef CONFIG_GRKERNSEC_BRUTE
70341+ struct task_struct *p = current;
70342+ kuid_t uid = GLOBAL_ROOT_UID;
70343+ int daemon = 0;
70344+
70345+ if (!grsec_enable_brute)
70346+ return;
70347+
70348+ rcu_read_lock();
70349+ read_lock(&tasklist_lock);
70350+ read_lock(&grsec_exec_file_lock);
70351+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70352+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70353+ p->real_parent->brute = 1;
70354+ daemon = 1;
70355+ } else {
70356+ const struct cred *cred = __task_cred(p), *cred2;
70357+ struct task_struct *tsk, *tsk2;
70358+
70359+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70360+ struct user_struct *user;
70361+
70362+ uid = cred->uid;
70363+
70364+ /* this is put upon execution past expiration */
70365+ user = find_user(uid);
70366+ if (user == NULL)
70367+ goto unlock;
70368+ user->suid_banned = 1;
70369+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70370+ if (user->suid_ban_expires == ~0UL)
70371+ user->suid_ban_expires--;
70372+
70373+ /* only kill other threads of the same binary, from the same user */
70374+ do_each_thread(tsk2, tsk) {
70375+ cred2 = __task_cred(tsk);
70376+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70377+ gr_fake_force_sig(SIGKILL, tsk);
70378+ } while_each_thread(tsk2, tsk);
70379+ }
70380+ }
70381+unlock:
70382+ read_unlock(&grsec_exec_file_lock);
70383+ read_unlock(&tasklist_lock);
70384+ rcu_read_unlock();
70385+
70386+ if (gr_is_global_nonroot(uid))
70387+ 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);
70388+ else if (daemon)
70389+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70390+
70391+#endif
70392+ return;
70393+}
70394+
70395+void gr_handle_brute_check(void)
70396+{
70397+#ifdef CONFIG_GRKERNSEC_BRUTE
70398+ struct task_struct *p = current;
70399+
70400+ if (unlikely(p->brute)) {
70401+ if (!grsec_enable_brute)
70402+ p->brute = 0;
70403+ else if (time_before(get_seconds(), p->brute_expires))
70404+ msleep(30 * 1000);
70405+ }
70406+#endif
70407+ return;
70408+}
70409+
70410+void gr_handle_kernel_exploit(void)
70411+{
70412+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70413+ const struct cred *cred;
70414+ struct task_struct *tsk, *tsk2;
70415+ struct user_struct *user;
70416+ kuid_t uid;
70417+
70418+ if (in_irq() || in_serving_softirq() || in_nmi())
70419+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70420+
70421+ uid = current_uid();
70422+
70423+ if (gr_is_global_root(uid))
70424+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70425+ else {
70426+ /* kill all the processes of this user, hold a reference
70427+ to their creds struct, and prevent them from creating
70428+ another process until system reset
70429+ */
70430+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70431+ GR_GLOBAL_UID(uid));
70432+ /* we intentionally leak this ref */
70433+ user = get_uid(current->cred->user);
70434+ if (user)
70435+ user->kernel_banned = 1;
70436+
70437+ /* kill all processes of this user */
70438+ read_lock(&tasklist_lock);
70439+ do_each_thread(tsk2, tsk) {
70440+ cred = __task_cred(tsk);
70441+ if (uid_eq(cred->uid, uid))
70442+ gr_fake_force_sig(SIGKILL, tsk);
70443+ } while_each_thread(tsk2, tsk);
70444+ read_unlock(&tasklist_lock);
70445+ }
70446+#endif
70447+}
70448+
70449+#ifdef CONFIG_GRKERNSEC_BRUTE
70450+static bool suid_ban_expired(struct user_struct *user)
70451+{
70452+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70453+ user->suid_banned = 0;
70454+ user->suid_ban_expires = 0;
70455+ free_uid(user);
70456+ return true;
70457+ }
70458+
70459+ return false;
70460+}
70461+#endif
70462+
70463+int gr_process_kernel_exec_ban(void)
70464+{
70465+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70466+ if (unlikely(current->cred->user->kernel_banned))
70467+ return -EPERM;
70468+#endif
70469+ return 0;
70470+}
70471+
70472+int gr_process_kernel_setuid_ban(struct user_struct *user)
70473+{
70474+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70475+ if (unlikely(user->kernel_banned))
70476+ gr_fake_force_sig(SIGKILL, current);
70477+#endif
70478+ return 0;
70479+}
70480+
70481+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70482+{
70483+#ifdef CONFIG_GRKERNSEC_BRUTE
70484+ struct user_struct *user = current->cred->user;
70485+ if (unlikely(user->suid_banned)) {
70486+ if (suid_ban_expired(user))
70487+ return 0;
70488+ /* disallow execution of suid binaries only */
70489+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70490+ return -EPERM;
70491+ }
70492+#endif
70493+ return 0;
70494+}
70495diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70496new file mode 100644
70497index 0000000..4030d57
70498--- /dev/null
70499+++ b/grsecurity/grsec_sock.c
70500@@ -0,0 +1,244 @@
70501+#include <linux/kernel.h>
70502+#include <linux/module.h>
70503+#include <linux/sched.h>
70504+#include <linux/file.h>
70505+#include <linux/net.h>
70506+#include <linux/in.h>
70507+#include <linux/ip.h>
70508+#include <net/sock.h>
70509+#include <net/inet_sock.h>
70510+#include <linux/grsecurity.h>
70511+#include <linux/grinternal.h>
70512+#include <linux/gracl.h>
70513+
70514+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70515+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70516+
70517+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70518+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70519+
70520+#ifdef CONFIG_UNIX_MODULE
70521+EXPORT_SYMBOL(gr_acl_handle_unix);
70522+EXPORT_SYMBOL(gr_acl_handle_mknod);
70523+EXPORT_SYMBOL(gr_handle_chroot_unix);
70524+EXPORT_SYMBOL(gr_handle_create);
70525+#endif
70526+
70527+#ifdef CONFIG_GRKERNSEC
70528+#define gr_conn_table_size 32749
70529+struct conn_table_entry {
70530+ struct conn_table_entry *next;
70531+ struct signal_struct *sig;
70532+};
70533+
70534+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70535+DEFINE_SPINLOCK(gr_conn_table_lock);
70536+
70537+extern const char * gr_socktype_to_name(unsigned char type);
70538+extern const char * gr_proto_to_name(unsigned char proto);
70539+extern const char * gr_sockfamily_to_name(unsigned char family);
70540+
70541+static __inline__ int
70542+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70543+{
70544+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70545+}
70546+
70547+static __inline__ int
70548+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70549+ __u16 sport, __u16 dport)
70550+{
70551+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70552+ sig->gr_sport == sport && sig->gr_dport == dport))
70553+ return 1;
70554+ else
70555+ return 0;
70556+}
70557+
70558+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70559+{
70560+ struct conn_table_entry **match;
70561+ unsigned int index;
70562+
70563+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70564+ sig->gr_sport, sig->gr_dport,
70565+ gr_conn_table_size);
70566+
70567+ newent->sig = sig;
70568+
70569+ match = &gr_conn_table[index];
70570+ newent->next = *match;
70571+ *match = newent;
70572+
70573+ return;
70574+}
70575+
70576+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70577+{
70578+ struct conn_table_entry *match, *last = NULL;
70579+ unsigned int index;
70580+
70581+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70582+ sig->gr_sport, sig->gr_dport,
70583+ gr_conn_table_size);
70584+
70585+ match = gr_conn_table[index];
70586+ while (match && !conn_match(match->sig,
70587+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70588+ sig->gr_dport)) {
70589+ last = match;
70590+ match = match->next;
70591+ }
70592+
70593+ if (match) {
70594+ if (last)
70595+ last->next = match->next;
70596+ else
70597+ gr_conn_table[index] = NULL;
70598+ kfree(match);
70599+ }
70600+
70601+ return;
70602+}
70603+
70604+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70605+ __u16 sport, __u16 dport)
70606+{
70607+ struct conn_table_entry *match;
70608+ unsigned int index;
70609+
70610+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70611+
70612+ match = gr_conn_table[index];
70613+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70614+ match = match->next;
70615+
70616+ if (match)
70617+ return match->sig;
70618+ else
70619+ return NULL;
70620+}
70621+
70622+#endif
70623+
70624+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70625+{
70626+#ifdef CONFIG_GRKERNSEC
70627+ struct signal_struct *sig = task->signal;
70628+ struct conn_table_entry *newent;
70629+
70630+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70631+ if (newent == NULL)
70632+ return;
70633+ /* no bh lock needed since we are called with bh disabled */
70634+ spin_lock(&gr_conn_table_lock);
70635+ gr_del_task_from_ip_table_nolock(sig);
70636+ sig->gr_saddr = inet->inet_rcv_saddr;
70637+ sig->gr_daddr = inet->inet_daddr;
70638+ sig->gr_sport = inet->inet_sport;
70639+ sig->gr_dport = inet->inet_dport;
70640+ gr_add_to_task_ip_table_nolock(sig, newent);
70641+ spin_unlock(&gr_conn_table_lock);
70642+#endif
70643+ return;
70644+}
70645+
70646+void gr_del_task_from_ip_table(struct task_struct *task)
70647+{
70648+#ifdef CONFIG_GRKERNSEC
70649+ spin_lock_bh(&gr_conn_table_lock);
70650+ gr_del_task_from_ip_table_nolock(task->signal);
70651+ spin_unlock_bh(&gr_conn_table_lock);
70652+#endif
70653+ return;
70654+}
70655+
70656+void
70657+gr_attach_curr_ip(const struct sock *sk)
70658+{
70659+#ifdef CONFIG_GRKERNSEC
70660+ struct signal_struct *p, *set;
70661+ const struct inet_sock *inet = inet_sk(sk);
70662+
70663+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70664+ return;
70665+
70666+ set = current->signal;
70667+
70668+ spin_lock_bh(&gr_conn_table_lock);
70669+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70670+ inet->inet_dport, inet->inet_sport);
70671+ if (unlikely(p != NULL)) {
70672+ set->curr_ip = p->curr_ip;
70673+ set->used_accept = 1;
70674+ gr_del_task_from_ip_table_nolock(p);
70675+ spin_unlock_bh(&gr_conn_table_lock);
70676+ return;
70677+ }
70678+ spin_unlock_bh(&gr_conn_table_lock);
70679+
70680+ set->curr_ip = inet->inet_daddr;
70681+ set->used_accept = 1;
70682+#endif
70683+ return;
70684+}
70685+
70686+int
70687+gr_handle_sock_all(const int family, const int type, const int protocol)
70688+{
70689+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70690+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70691+ (family != AF_UNIX)) {
70692+ if (family == AF_INET)
70693+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70694+ else
70695+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70696+ return -EACCES;
70697+ }
70698+#endif
70699+ return 0;
70700+}
70701+
70702+int
70703+gr_handle_sock_server(const struct sockaddr *sck)
70704+{
70705+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70706+ if (grsec_enable_socket_server &&
70707+ in_group_p(grsec_socket_server_gid) &&
70708+ sck && (sck->sa_family != AF_UNIX) &&
70709+ (sck->sa_family != AF_LOCAL)) {
70710+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70711+ return -EACCES;
70712+ }
70713+#endif
70714+ return 0;
70715+}
70716+
70717+int
70718+gr_handle_sock_server_other(const struct sock *sck)
70719+{
70720+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70721+ if (grsec_enable_socket_server &&
70722+ in_group_p(grsec_socket_server_gid) &&
70723+ sck && (sck->sk_family != AF_UNIX) &&
70724+ (sck->sk_family != AF_LOCAL)) {
70725+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70726+ return -EACCES;
70727+ }
70728+#endif
70729+ return 0;
70730+}
70731+
70732+int
70733+gr_handle_sock_client(const struct sockaddr *sck)
70734+{
70735+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70736+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70737+ sck && (sck->sa_family != AF_UNIX) &&
70738+ (sck->sa_family != AF_LOCAL)) {
70739+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70740+ return -EACCES;
70741+ }
70742+#endif
70743+ return 0;
70744+}
70745diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70746new file mode 100644
70747index 0000000..a147ae7
70748--- /dev/null
70749+++ b/grsecurity/grsec_sysctl.c
70750@@ -0,0 +1,470 @@
70751+#include <linux/kernel.h>
70752+#include <linux/sched.h>
70753+#include <linux/sysctl.h>
70754+#include <linux/grsecurity.h>
70755+#include <linux/grinternal.h>
70756+
70757+int
70758+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70759+{
70760+#ifdef CONFIG_GRKERNSEC_SYSCTL
70761+ if (dirname == NULL || name == NULL)
70762+ return 0;
70763+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70764+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70765+ return -EACCES;
70766+ }
70767+#endif
70768+ return 0;
70769+}
70770+
70771+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70772+static int __maybe_unused __read_only one = 1;
70773+#endif
70774+
70775+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70776+ defined(CONFIG_GRKERNSEC_DENYUSB)
70777+struct ctl_table grsecurity_table[] = {
70778+#ifdef CONFIG_GRKERNSEC_SYSCTL
70779+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70780+#ifdef CONFIG_GRKERNSEC_IO
70781+ {
70782+ .procname = "disable_priv_io",
70783+ .data = &grsec_disable_privio,
70784+ .maxlen = sizeof(int),
70785+ .mode = 0600,
70786+ .proc_handler = &proc_dointvec,
70787+ },
70788+#endif
70789+#endif
70790+#ifdef CONFIG_GRKERNSEC_LINK
70791+ {
70792+ .procname = "linking_restrictions",
70793+ .data = &grsec_enable_link,
70794+ .maxlen = sizeof(int),
70795+ .mode = 0600,
70796+ .proc_handler = &proc_dointvec,
70797+ },
70798+#endif
70799+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70800+ {
70801+ .procname = "enforce_symlinksifowner",
70802+ .data = &grsec_enable_symlinkown,
70803+ .maxlen = sizeof(int),
70804+ .mode = 0600,
70805+ .proc_handler = &proc_dointvec,
70806+ },
70807+ {
70808+ .procname = "symlinkown_gid",
70809+ .data = &grsec_symlinkown_gid,
70810+ .maxlen = sizeof(int),
70811+ .mode = 0600,
70812+ .proc_handler = &proc_dointvec,
70813+ },
70814+#endif
70815+#ifdef CONFIG_GRKERNSEC_BRUTE
70816+ {
70817+ .procname = "deter_bruteforce",
70818+ .data = &grsec_enable_brute,
70819+ .maxlen = sizeof(int),
70820+ .mode = 0600,
70821+ .proc_handler = &proc_dointvec,
70822+ },
70823+#endif
70824+#ifdef CONFIG_GRKERNSEC_FIFO
70825+ {
70826+ .procname = "fifo_restrictions",
70827+ .data = &grsec_enable_fifo,
70828+ .maxlen = sizeof(int),
70829+ .mode = 0600,
70830+ .proc_handler = &proc_dointvec,
70831+ },
70832+#endif
70833+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70834+ {
70835+ .procname = "ptrace_readexec",
70836+ .data = &grsec_enable_ptrace_readexec,
70837+ .maxlen = sizeof(int),
70838+ .mode = 0600,
70839+ .proc_handler = &proc_dointvec,
70840+ },
70841+#endif
70842+#ifdef CONFIG_GRKERNSEC_SETXID
70843+ {
70844+ .procname = "consistent_setxid",
70845+ .data = &grsec_enable_setxid,
70846+ .maxlen = sizeof(int),
70847+ .mode = 0600,
70848+ .proc_handler = &proc_dointvec,
70849+ },
70850+#endif
70851+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70852+ {
70853+ .procname = "ip_blackhole",
70854+ .data = &grsec_enable_blackhole,
70855+ .maxlen = sizeof(int),
70856+ .mode = 0600,
70857+ .proc_handler = &proc_dointvec,
70858+ },
70859+ {
70860+ .procname = "lastack_retries",
70861+ .data = &grsec_lastack_retries,
70862+ .maxlen = sizeof(int),
70863+ .mode = 0600,
70864+ .proc_handler = &proc_dointvec,
70865+ },
70866+#endif
70867+#ifdef CONFIG_GRKERNSEC_EXECLOG
70868+ {
70869+ .procname = "exec_logging",
70870+ .data = &grsec_enable_execlog,
70871+ .maxlen = sizeof(int),
70872+ .mode = 0600,
70873+ .proc_handler = &proc_dointvec,
70874+ },
70875+#endif
70876+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70877+ {
70878+ .procname = "rwxmap_logging",
70879+ .data = &grsec_enable_log_rwxmaps,
70880+ .maxlen = sizeof(int),
70881+ .mode = 0600,
70882+ .proc_handler = &proc_dointvec,
70883+ },
70884+#endif
70885+#ifdef CONFIG_GRKERNSEC_SIGNAL
70886+ {
70887+ .procname = "signal_logging",
70888+ .data = &grsec_enable_signal,
70889+ .maxlen = sizeof(int),
70890+ .mode = 0600,
70891+ .proc_handler = &proc_dointvec,
70892+ },
70893+#endif
70894+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70895+ {
70896+ .procname = "forkfail_logging",
70897+ .data = &grsec_enable_forkfail,
70898+ .maxlen = sizeof(int),
70899+ .mode = 0600,
70900+ .proc_handler = &proc_dointvec,
70901+ },
70902+#endif
70903+#ifdef CONFIG_GRKERNSEC_TIME
70904+ {
70905+ .procname = "timechange_logging",
70906+ .data = &grsec_enable_time,
70907+ .maxlen = sizeof(int),
70908+ .mode = 0600,
70909+ .proc_handler = &proc_dointvec,
70910+ },
70911+#endif
70912+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70913+ {
70914+ .procname = "chroot_deny_shmat",
70915+ .data = &grsec_enable_chroot_shmat,
70916+ .maxlen = sizeof(int),
70917+ .mode = 0600,
70918+ .proc_handler = &proc_dointvec,
70919+ },
70920+#endif
70921+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70922+ {
70923+ .procname = "chroot_deny_unix",
70924+ .data = &grsec_enable_chroot_unix,
70925+ .maxlen = sizeof(int),
70926+ .mode = 0600,
70927+ .proc_handler = &proc_dointvec,
70928+ },
70929+#endif
70930+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70931+ {
70932+ .procname = "chroot_deny_mount",
70933+ .data = &grsec_enable_chroot_mount,
70934+ .maxlen = sizeof(int),
70935+ .mode = 0600,
70936+ .proc_handler = &proc_dointvec,
70937+ },
70938+#endif
70939+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70940+ {
70941+ .procname = "chroot_deny_fchdir",
70942+ .data = &grsec_enable_chroot_fchdir,
70943+ .maxlen = sizeof(int),
70944+ .mode = 0600,
70945+ .proc_handler = &proc_dointvec,
70946+ },
70947+#endif
70948+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70949+ {
70950+ .procname = "chroot_deny_chroot",
70951+ .data = &grsec_enable_chroot_double,
70952+ .maxlen = sizeof(int),
70953+ .mode = 0600,
70954+ .proc_handler = &proc_dointvec,
70955+ },
70956+#endif
70957+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70958+ {
70959+ .procname = "chroot_deny_pivot",
70960+ .data = &grsec_enable_chroot_pivot,
70961+ .maxlen = sizeof(int),
70962+ .mode = 0600,
70963+ .proc_handler = &proc_dointvec,
70964+ },
70965+#endif
70966+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70967+ {
70968+ .procname = "chroot_enforce_chdir",
70969+ .data = &grsec_enable_chroot_chdir,
70970+ .maxlen = sizeof(int),
70971+ .mode = 0600,
70972+ .proc_handler = &proc_dointvec,
70973+ },
70974+#endif
70975+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70976+ {
70977+ .procname = "chroot_deny_chmod",
70978+ .data = &grsec_enable_chroot_chmod,
70979+ .maxlen = sizeof(int),
70980+ .mode = 0600,
70981+ .proc_handler = &proc_dointvec,
70982+ },
70983+#endif
70984+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70985+ {
70986+ .procname = "chroot_deny_mknod",
70987+ .data = &grsec_enable_chroot_mknod,
70988+ .maxlen = sizeof(int),
70989+ .mode = 0600,
70990+ .proc_handler = &proc_dointvec,
70991+ },
70992+#endif
70993+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70994+ {
70995+ .procname = "chroot_restrict_nice",
70996+ .data = &grsec_enable_chroot_nice,
70997+ .maxlen = sizeof(int),
70998+ .mode = 0600,
70999+ .proc_handler = &proc_dointvec,
71000+ },
71001+#endif
71002+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71003+ {
71004+ .procname = "chroot_execlog",
71005+ .data = &grsec_enable_chroot_execlog,
71006+ .maxlen = sizeof(int),
71007+ .mode = 0600,
71008+ .proc_handler = &proc_dointvec,
71009+ },
71010+#endif
71011+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71012+ {
71013+ .procname = "chroot_caps",
71014+ .data = &grsec_enable_chroot_caps,
71015+ .maxlen = sizeof(int),
71016+ .mode = 0600,
71017+ .proc_handler = &proc_dointvec,
71018+ },
71019+#endif
71020+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71021+ {
71022+ .procname = "chroot_deny_sysctl",
71023+ .data = &grsec_enable_chroot_sysctl,
71024+ .maxlen = sizeof(int),
71025+ .mode = 0600,
71026+ .proc_handler = &proc_dointvec,
71027+ },
71028+#endif
71029+#ifdef CONFIG_GRKERNSEC_TPE
71030+ {
71031+ .procname = "tpe",
71032+ .data = &grsec_enable_tpe,
71033+ .maxlen = sizeof(int),
71034+ .mode = 0600,
71035+ .proc_handler = &proc_dointvec,
71036+ },
71037+ {
71038+ .procname = "tpe_gid",
71039+ .data = &grsec_tpe_gid,
71040+ .maxlen = sizeof(int),
71041+ .mode = 0600,
71042+ .proc_handler = &proc_dointvec,
71043+ },
71044+#endif
71045+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71046+ {
71047+ .procname = "tpe_invert",
71048+ .data = &grsec_enable_tpe_invert,
71049+ .maxlen = sizeof(int),
71050+ .mode = 0600,
71051+ .proc_handler = &proc_dointvec,
71052+ },
71053+#endif
71054+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71055+ {
71056+ .procname = "tpe_restrict_all",
71057+ .data = &grsec_enable_tpe_all,
71058+ .maxlen = sizeof(int),
71059+ .mode = 0600,
71060+ .proc_handler = &proc_dointvec,
71061+ },
71062+#endif
71063+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71064+ {
71065+ .procname = "socket_all",
71066+ .data = &grsec_enable_socket_all,
71067+ .maxlen = sizeof(int),
71068+ .mode = 0600,
71069+ .proc_handler = &proc_dointvec,
71070+ },
71071+ {
71072+ .procname = "socket_all_gid",
71073+ .data = &grsec_socket_all_gid,
71074+ .maxlen = sizeof(int),
71075+ .mode = 0600,
71076+ .proc_handler = &proc_dointvec,
71077+ },
71078+#endif
71079+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71080+ {
71081+ .procname = "socket_client",
71082+ .data = &grsec_enable_socket_client,
71083+ .maxlen = sizeof(int),
71084+ .mode = 0600,
71085+ .proc_handler = &proc_dointvec,
71086+ },
71087+ {
71088+ .procname = "socket_client_gid",
71089+ .data = &grsec_socket_client_gid,
71090+ .maxlen = sizeof(int),
71091+ .mode = 0600,
71092+ .proc_handler = &proc_dointvec,
71093+ },
71094+#endif
71095+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71096+ {
71097+ .procname = "socket_server",
71098+ .data = &grsec_enable_socket_server,
71099+ .maxlen = sizeof(int),
71100+ .mode = 0600,
71101+ .proc_handler = &proc_dointvec,
71102+ },
71103+ {
71104+ .procname = "socket_server_gid",
71105+ .data = &grsec_socket_server_gid,
71106+ .maxlen = sizeof(int),
71107+ .mode = 0600,
71108+ .proc_handler = &proc_dointvec,
71109+ },
71110+#endif
71111+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71112+ {
71113+ .procname = "audit_group",
71114+ .data = &grsec_enable_group,
71115+ .maxlen = sizeof(int),
71116+ .mode = 0600,
71117+ .proc_handler = &proc_dointvec,
71118+ },
71119+ {
71120+ .procname = "audit_gid",
71121+ .data = &grsec_audit_gid,
71122+ .maxlen = sizeof(int),
71123+ .mode = 0600,
71124+ .proc_handler = &proc_dointvec,
71125+ },
71126+#endif
71127+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71128+ {
71129+ .procname = "audit_chdir",
71130+ .data = &grsec_enable_chdir,
71131+ .maxlen = sizeof(int),
71132+ .mode = 0600,
71133+ .proc_handler = &proc_dointvec,
71134+ },
71135+#endif
71136+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71137+ {
71138+ .procname = "audit_mount",
71139+ .data = &grsec_enable_mount,
71140+ .maxlen = sizeof(int),
71141+ .mode = 0600,
71142+ .proc_handler = &proc_dointvec,
71143+ },
71144+#endif
71145+#ifdef CONFIG_GRKERNSEC_DMESG
71146+ {
71147+ .procname = "dmesg",
71148+ .data = &grsec_enable_dmesg,
71149+ .maxlen = sizeof(int),
71150+ .mode = 0600,
71151+ .proc_handler = &proc_dointvec,
71152+ },
71153+#endif
71154+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71155+ {
71156+ .procname = "chroot_findtask",
71157+ .data = &grsec_enable_chroot_findtask,
71158+ .maxlen = sizeof(int),
71159+ .mode = 0600,
71160+ .proc_handler = &proc_dointvec,
71161+ },
71162+#endif
71163+#ifdef CONFIG_GRKERNSEC_RESLOG
71164+ {
71165+ .procname = "resource_logging",
71166+ .data = &grsec_resource_logging,
71167+ .maxlen = sizeof(int),
71168+ .mode = 0600,
71169+ .proc_handler = &proc_dointvec,
71170+ },
71171+#endif
71172+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71173+ {
71174+ .procname = "audit_ptrace",
71175+ .data = &grsec_enable_audit_ptrace,
71176+ .maxlen = sizeof(int),
71177+ .mode = 0600,
71178+ .proc_handler = &proc_dointvec,
71179+ },
71180+#endif
71181+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71182+ {
71183+ .procname = "harden_ptrace",
71184+ .data = &grsec_enable_harden_ptrace,
71185+ .maxlen = sizeof(int),
71186+ .mode = 0600,
71187+ .proc_handler = &proc_dointvec,
71188+ },
71189+#endif
71190+ {
71191+ .procname = "grsec_lock",
71192+ .data = &grsec_lock,
71193+ .maxlen = sizeof(int),
71194+ .mode = 0600,
71195+ .proc_handler = &proc_dointvec,
71196+ },
71197+#endif
71198+#ifdef CONFIG_GRKERNSEC_ROFS
71199+ {
71200+ .procname = "romount_protect",
71201+ .data = &grsec_enable_rofs,
71202+ .maxlen = sizeof(int),
71203+ .mode = 0600,
71204+ .proc_handler = &proc_dointvec_minmax,
71205+ .extra1 = &one,
71206+ .extra2 = &one,
71207+ },
71208+#endif
71209+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71210+ {
71211+ .procname = "deny_new_usb",
71212+ .data = &grsec_deny_new_usb,
71213+ .maxlen = sizeof(int),
71214+ .mode = 0600,
71215+ .proc_handler = &proc_dointvec,
71216+ },
71217+#endif
71218+ { }
71219+};
71220+#endif
71221diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71222new file mode 100644
71223index 0000000..0dc13c3
71224--- /dev/null
71225+++ b/grsecurity/grsec_time.c
71226@@ -0,0 +1,16 @@
71227+#include <linux/kernel.h>
71228+#include <linux/sched.h>
71229+#include <linux/grinternal.h>
71230+#include <linux/module.h>
71231+
71232+void
71233+gr_log_timechange(void)
71234+{
71235+#ifdef CONFIG_GRKERNSEC_TIME
71236+ if (grsec_enable_time)
71237+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71238+#endif
71239+ return;
71240+}
71241+
71242+EXPORT_SYMBOL(gr_log_timechange);
71243diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71244new file mode 100644
71245index 0000000..ee57dcf
71246--- /dev/null
71247+++ b/grsecurity/grsec_tpe.c
71248@@ -0,0 +1,73 @@
71249+#include <linux/kernel.h>
71250+#include <linux/sched.h>
71251+#include <linux/file.h>
71252+#include <linux/fs.h>
71253+#include <linux/grinternal.h>
71254+
71255+extern int gr_acl_tpe_check(void);
71256+
71257+int
71258+gr_tpe_allow(const struct file *file)
71259+{
71260+#ifdef CONFIG_GRKERNSEC
71261+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71262+ const struct cred *cred = current_cred();
71263+ char *msg = NULL;
71264+ char *msg2 = NULL;
71265+
71266+ // never restrict root
71267+ if (gr_is_global_root(cred->uid))
71268+ return 1;
71269+
71270+ if (grsec_enable_tpe) {
71271+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71272+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71273+ msg = "not being in trusted group";
71274+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71275+ msg = "being in untrusted group";
71276+#else
71277+ if (in_group_p(grsec_tpe_gid))
71278+ msg = "being in untrusted group";
71279+#endif
71280+ }
71281+ if (!msg && gr_acl_tpe_check())
71282+ msg = "being in untrusted role";
71283+
71284+ // not in any affected group/role
71285+ if (!msg)
71286+ goto next_check;
71287+
71288+ if (gr_is_global_nonroot(inode->i_uid))
71289+ msg2 = "file in non-root-owned directory";
71290+ else if (inode->i_mode & S_IWOTH)
71291+ msg2 = "file in world-writable directory";
71292+ else if (inode->i_mode & S_IWGRP)
71293+ msg2 = "file in group-writable directory";
71294+
71295+ if (msg && msg2) {
71296+ char fullmsg[70] = {0};
71297+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71298+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71299+ return 0;
71300+ }
71301+ msg = NULL;
71302+next_check:
71303+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71304+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71305+ return 1;
71306+
71307+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71308+ msg = "directory not owned by user";
71309+ else if (inode->i_mode & S_IWOTH)
71310+ msg = "file in world-writable directory";
71311+ else if (inode->i_mode & S_IWGRP)
71312+ msg = "file in group-writable directory";
71313+
71314+ if (msg) {
71315+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71316+ return 0;
71317+ }
71318+#endif
71319+#endif
71320+ return 1;
71321+}
71322diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71323new file mode 100644
71324index 0000000..ae02d8e
71325--- /dev/null
71326+++ b/grsecurity/grsec_usb.c
71327@@ -0,0 +1,15 @@
71328+#include <linux/kernel.h>
71329+#include <linux/grinternal.h>
71330+#include <linux/module.h>
71331+
71332+int gr_handle_new_usb(void)
71333+{
71334+#ifdef CONFIG_GRKERNSEC_DENYUSB
71335+ if (grsec_deny_new_usb) {
71336+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71337+ return 1;
71338+ }
71339+#endif
71340+ return 0;
71341+}
71342+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71343diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71344new file mode 100644
71345index 0000000..9f7b1ac
71346--- /dev/null
71347+++ b/grsecurity/grsum.c
71348@@ -0,0 +1,61 @@
71349+#include <linux/err.h>
71350+#include <linux/kernel.h>
71351+#include <linux/sched.h>
71352+#include <linux/mm.h>
71353+#include <linux/scatterlist.h>
71354+#include <linux/crypto.h>
71355+#include <linux/gracl.h>
71356+
71357+
71358+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71359+#error "crypto and sha256 must be built into the kernel"
71360+#endif
71361+
71362+int
71363+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71364+{
71365+ char *p;
71366+ struct crypto_hash *tfm;
71367+ struct hash_desc desc;
71368+ struct scatterlist sg;
71369+ unsigned char temp_sum[GR_SHA_LEN];
71370+ volatile int retval = 0;
71371+ volatile int dummy = 0;
71372+ unsigned int i;
71373+
71374+ sg_init_table(&sg, 1);
71375+
71376+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71377+ if (IS_ERR(tfm)) {
71378+ /* should never happen, since sha256 should be built in */
71379+ return 1;
71380+ }
71381+
71382+ desc.tfm = tfm;
71383+ desc.flags = 0;
71384+
71385+ crypto_hash_init(&desc);
71386+
71387+ p = salt;
71388+ sg_set_buf(&sg, p, GR_SALT_LEN);
71389+ crypto_hash_update(&desc, &sg, sg.length);
71390+
71391+ p = entry->pw;
71392+ sg_set_buf(&sg, p, strlen(p));
71393+
71394+ crypto_hash_update(&desc, &sg, sg.length);
71395+
71396+ crypto_hash_final(&desc, temp_sum);
71397+
71398+ memset(entry->pw, 0, GR_PW_LEN);
71399+
71400+ for (i = 0; i < GR_SHA_LEN; i++)
71401+ if (sum[i] != temp_sum[i])
71402+ retval = 1;
71403+ else
71404+ dummy = 1; // waste a cycle
71405+
71406+ crypto_free_hash(tfm);
71407+
71408+ return retval;
71409+}
71410diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71411index 77ff547..181834f 100644
71412--- a/include/asm-generic/4level-fixup.h
71413+++ b/include/asm-generic/4level-fixup.h
71414@@ -13,8 +13,10 @@
71415 #define pmd_alloc(mm, pud, address) \
71416 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71417 NULL: pmd_offset(pud, address))
71418+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71419
71420 #define pud_alloc(mm, pgd, address) (pgd)
71421+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71422 #define pud_offset(pgd, start) (pgd)
71423 #define pud_none(pud) 0
71424 #define pud_bad(pud) 0
71425diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71426index b7babf0..04ad282 100644
71427--- a/include/asm-generic/atomic-long.h
71428+++ b/include/asm-generic/atomic-long.h
71429@@ -22,6 +22,12 @@
71430
71431 typedef atomic64_t atomic_long_t;
71432
71433+#ifdef CONFIG_PAX_REFCOUNT
71434+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71435+#else
71436+typedef atomic64_t atomic_long_unchecked_t;
71437+#endif
71438+
71439 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71440
71441 static inline long atomic_long_read(atomic_long_t *l)
71442@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71443 return (long)atomic64_read(v);
71444 }
71445
71446+#ifdef CONFIG_PAX_REFCOUNT
71447+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71448+{
71449+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71450+
71451+ return (long)atomic64_read_unchecked(v);
71452+}
71453+#endif
71454+
71455 static inline void atomic_long_set(atomic_long_t *l, long i)
71456 {
71457 atomic64_t *v = (atomic64_t *)l;
71458@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71459 atomic64_set(v, i);
71460 }
71461
71462+#ifdef CONFIG_PAX_REFCOUNT
71463+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71464+{
71465+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71466+
71467+ atomic64_set_unchecked(v, i);
71468+}
71469+#endif
71470+
71471 static inline void atomic_long_inc(atomic_long_t *l)
71472 {
71473 atomic64_t *v = (atomic64_t *)l;
71474@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71475 atomic64_inc(v);
71476 }
71477
71478+#ifdef CONFIG_PAX_REFCOUNT
71479+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71480+{
71481+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71482+
71483+ atomic64_inc_unchecked(v);
71484+}
71485+#endif
71486+
71487 static inline void atomic_long_dec(atomic_long_t *l)
71488 {
71489 atomic64_t *v = (atomic64_t *)l;
71490@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71491 atomic64_dec(v);
71492 }
71493
71494+#ifdef CONFIG_PAX_REFCOUNT
71495+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71496+{
71497+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71498+
71499+ atomic64_dec_unchecked(v);
71500+}
71501+#endif
71502+
71503 static inline void atomic_long_add(long i, atomic_long_t *l)
71504 {
71505 atomic64_t *v = (atomic64_t *)l;
71506@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71507 atomic64_add(i, v);
71508 }
71509
71510+#ifdef CONFIG_PAX_REFCOUNT
71511+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71512+{
71513+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71514+
71515+ atomic64_add_unchecked(i, v);
71516+}
71517+#endif
71518+
71519 static inline void atomic_long_sub(long i, atomic_long_t *l)
71520 {
71521 atomic64_t *v = (atomic64_t *)l;
71522@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71523 atomic64_sub(i, v);
71524 }
71525
71526+#ifdef CONFIG_PAX_REFCOUNT
71527+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71528+{
71529+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71530+
71531+ atomic64_sub_unchecked(i, v);
71532+}
71533+#endif
71534+
71535 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71536 {
71537 atomic64_t *v = (atomic64_t *)l;
71538@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71539 return (long)atomic64_add_return(i, v);
71540 }
71541
71542+#ifdef CONFIG_PAX_REFCOUNT
71543+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71544+{
71545+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71546+
71547+ return (long)atomic64_add_return_unchecked(i, v);
71548+}
71549+#endif
71550+
71551 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71552 {
71553 atomic64_t *v = (atomic64_t *)l;
71554@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71555 return (long)atomic64_inc_return(v);
71556 }
71557
71558+#ifdef CONFIG_PAX_REFCOUNT
71559+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71560+{
71561+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71562+
71563+ return (long)atomic64_inc_return_unchecked(v);
71564+}
71565+#endif
71566+
71567 static inline long atomic_long_dec_return(atomic_long_t *l)
71568 {
71569 atomic64_t *v = (atomic64_t *)l;
71570@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71571
71572 typedef atomic_t atomic_long_t;
71573
71574+#ifdef CONFIG_PAX_REFCOUNT
71575+typedef atomic_unchecked_t atomic_long_unchecked_t;
71576+#else
71577+typedef atomic_t atomic_long_unchecked_t;
71578+#endif
71579+
71580 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71581 static inline long atomic_long_read(atomic_long_t *l)
71582 {
71583@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71584 return (long)atomic_read(v);
71585 }
71586
71587+#ifdef CONFIG_PAX_REFCOUNT
71588+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71589+{
71590+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71591+
71592+ return (long)atomic_read_unchecked(v);
71593+}
71594+#endif
71595+
71596 static inline void atomic_long_set(atomic_long_t *l, long i)
71597 {
71598 atomic_t *v = (atomic_t *)l;
71599@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71600 atomic_set(v, i);
71601 }
71602
71603+#ifdef CONFIG_PAX_REFCOUNT
71604+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71605+{
71606+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71607+
71608+ atomic_set_unchecked(v, i);
71609+}
71610+#endif
71611+
71612 static inline void atomic_long_inc(atomic_long_t *l)
71613 {
71614 atomic_t *v = (atomic_t *)l;
71615@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71616 atomic_inc(v);
71617 }
71618
71619+#ifdef CONFIG_PAX_REFCOUNT
71620+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71621+{
71622+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71623+
71624+ atomic_inc_unchecked(v);
71625+}
71626+#endif
71627+
71628 static inline void atomic_long_dec(atomic_long_t *l)
71629 {
71630 atomic_t *v = (atomic_t *)l;
71631@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71632 atomic_dec(v);
71633 }
71634
71635+#ifdef CONFIG_PAX_REFCOUNT
71636+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71637+{
71638+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71639+
71640+ atomic_dec_unchecked(v);
71641+}
71642+#endif
71643+
71644 static inline void atomic_long_add(long i, atomic_long_t *l)
71645 {
71646 atomic_t *v = (atomic_t *)l;
71647@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71648 atomic_add(i, v);
71649 }
71650
71651+#ifdef CONFIG_PAX_REFCOUNT
71652+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71653+{
71654+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71655+
71656+ atomic_add_unchecked(i, v);
71657+}
71658+#endif
71659+
71660 static inline void atomic_long_sub(long i, atomic_long_t *l)
71661 {
71662 atomic_t *v = (atomic_t *)l;
71663@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71664 atomic_sub(i, v);
71665 }
71666
71667+#ifdef CONFIG_PAX_REFCOUNT
71668+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71669+{
71670+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71671+
71672+ atomic_sub_unchecked(i, v);
71673+}
71674+#endif
71675+
71676 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71677 {
71678 atomic_t *v = (atomic_t *)l;
71679@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71680 return (long)atomic_add_return(i, v);
71681 }
71682
71683+#ifdef CONFIG_PAX_REFCOUNT
71684+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71685+{
71686+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71687+
71688+ return (long)atomic_add_return_unchecked(i, v);
71689+}
71690+
71691+#endif
71692+
71693 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71694 {
71695 atomic_t *v = (atomic_t *)l;
71696@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71697 return (long)atomic_inc_return(v);
71698 }
71699
71700+#ifdef CONFIG_PAX_REFCOUNT
71701+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71702+{
71703+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71704+
71705+ return (long)atomic_inc_return_unchecked(v);
71706+}
71707+#endif
71708+
71709 static inline long atomic_long_dec_return(atomic_long_t *l)
71710 {
71711 atomic_t *v = (atomic_t *)l;
71712@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71713
71714 #endif /* BITS_PER_LONG == 64 */
71715
71716+#ifdef CONFIG_PAX_REFCOUNT
71717+static inline void pax_refcount_needs_these_functions(void)
71718+{
71719+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71720+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71721+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71722+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71723+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71724+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71725+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71726+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71727+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71728+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71729+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71730+#ifdef CONFIG_X86
71731+ atomic_clear_mask_unchecked(0, NULL);
71732+ atomic_set_mask_unchecked(0, NULL);
71733+#endif
71734+
71735+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71736+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71737+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71738+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71739+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71740+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71741+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71742+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71743+}
71744+#else
71745+#define atomic_read_unchecked(v) atomic_read(v)
71746+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71747+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71748+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71749+#define atomic_inc_unchecked(v) atomic_inc(v)
71750+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71751+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71752+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71753+#define atomic_dec_unchecked(v) atomic_dec(v)
71754+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71755+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71756+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71757+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71758+
71759+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71760+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71761+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71762+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71763+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71764+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71765+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71766+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71767+#endif
71768+
71769 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71770diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71771index 33bd2de..f31bff97 100644
71772--- a/include/asm-generic/atomic.h
71773+++ b/include/asm-generic/atomic.h
71774@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71775 * Atomically clears the bits set in @mask from @v
71776 */
71777 #ifndef atomic_clear_mask
71778-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71779+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71780 {
71781 unsigned long flags;
71782
71783diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71784index b18ce4f..2ee2843 100644
71785--- a/include/asm-generic/atomic64.h
71786+++ b/include/asm-generic/atomic64.h
71787@@ -16,6 +16,8 @@ typedef struct {
71788 long long counter;
71789 } atomic64_t;
71790
71791+typedef atomic64_t atomic64_unchecked_t;
71792+
71793 #define ATOMIC64_INIT(i) { (i) }
71794
71795 extern long long atomic64_read(const atomic64_t *v);
71796@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71797 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71798 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71799
71800+#define atomic64_read_unchecked(v) atomic64_read(v)
71801+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71802+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71803+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71804+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71805+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71806+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71807+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71808+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71809+
71810 #endif /* _ASM_GENERIC_ATOMIC64_H */
71811diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71812index 1bfcfe5..e04c5c9 100644
71813--- a/include/asm-generic/cache.h
71814+++ b/include/asm-generic/cache.h
71815@@ -6,7 +6,7 @@
71816 * cache lines need to provide their own cache.h.
71817 */
71818
71819-#define L1_CACHE_SHIFT 5
71820-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71821+#define L1_CACHE_SHIFT 5UL
71822+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71823
71824 #endif /* __ASM_GENERIC_CACHE_H */
71825diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71826index 0d68a1e..b74a761 100644
71827--- a/include/asm-generic/emergency-restart.h
71828+++ b/include/asm-generic/emergency-restart.h
71829@@ -1,7 +1,7 @@
71830 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71831 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71832
71833-static inline void machine_emergency_restart(void)
71834+static inline __noreturn void machine_emergency_restart(void)
71835 {
71836 machine_restart(NULL);
71837 }
71838diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71839index 90f99c7..00ce236 100644
71840--- a/include/asm-generic/kmap_types.h
71841+++ b/include/asm-generic/kmap_types.h
71842@@ -2,9 +2,9 @@
71843 #define _ASM_GENERIC_KMAP_TYPES_H
71844
71845 #ifdef __WITH_KM_FENCE
71846-# define KM_TYPE_NR 41
71847+# define KM_TYPE_NR 42
71848 #else
71849-# define KM_TYPE_NR 20
71850+# define KM_TYPE_NR 21
71851 #endif
71852
71853 #endif
71854diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71855index 9ceb03b..62b0b8f 100644
71856--- a/include/asm-generic/local.h
71857+++ b/include/asm-generic/local.h
71858@@ -23,24 +23,37 @@ typedef struct
71859 atomic_long_t a;
71860 } local_t;
71861
71862+typedef struct {
71863+ atomic_long_unchecked_t a;
71864+} local_unchecked_t;
71865+
71866 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71867
71868 #define local_read(l) atomic_long_read(&(l)->a)
71869+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71870 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71871+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71872 #define local_inc(l) atomic_long_inc(&(l)->a)
71873+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71874 #define local_dec(l) atomic_long_dec(&(l)->a)
71875+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71876 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71877+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71878 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71879+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71880
71881 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71882 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71883 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71884 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71885 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71886+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71887 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71888 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71889+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71890
71891 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71892+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71893 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71894 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71895 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71896diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71897index 725612b..9cc513a 100644
71898--- a/include/asm-generic/pgtable-nopmd.h
71899+++ b/include/asm-generic/pgtable-nopmd.h
71900@@ -1,14 +1,19 @@
71901 #ifndef _PGTABLE_NOPMD_H
71902 #define _PGTABLE_NOPMD_H
71903
71904-#ifndef __ASSEMBLY__
71905-
71906 #include <asm-generic/pgtable-nopud.h>
71907
71908-struct mm_struct;
71909-
71910 #define __PAGETABLE_PMD_FOLDED
71911
71912+#define PMD_SHIFT PUD_SHIFT
71913+#define PTRS_PER_PMD 1
71914+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71915+#define PMD_MASK (~(PMD_SIZE-1))
71916+
71917+#ifndef __ASSEMBLY__
71918+
71919+struct mm_struct;
71920+
71921 /*
71922 * Having the pmd type consist of a pud gets the size right, and allows
71923 * us to conceptually access the pud entry that this pmd is folded into
71924@@ -16,11 +21,6 @@ struct mm_struct;
71925 */
71926 typedef struct { pud_t pud; } pmd_t;
71927
71928-#define PMD_SHIFT PUD_SHIFT
71929-#define PTRS_PER_PMD 1
71930-#define PMD_SIZE (1UL << PMD_SHIFT)
71931-#define PMD_MASK (~(PMD_SIZE-1))
71932-
71933 /*
71934 * The "pud_xxx()" functions here are trivial for a folded two-level
71935 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71936diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71937index 810431d..0ec4804f 100644
71938--- a/include/asm-generic/pgtable-nopud.h
71939+++ b/include/asm-generic/pgtable-nopud.h
71940@@ -1,10 +1,15 @@
71941 #ifndef _PGTABLE_NOPUD_H
71942 #define _PGTABLE_NOPUD_H
71943
71944-#ifndef __ASSEMBLY__
71945-
71946 #define __PAGETABLE_PUD_FOLDED
71947
71948+#define PUD_SHIFT PGDIR_SHIFT
71949+#define PTRS_PER_PUD 1
71950+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
71951+#define PUD_MASK (~(PUD_SIZE-1))
71952+
71953+#ifndef __ASSEMBLY__
71954+
71955 /*
71956 * Having the pud type consist of a pgd gets the size right, and allows
71957 * us to conceptually access the pgd entry that this pud is folded into
71958@@ -12,11 +17,6 @@
71959 */
71960 typedef struct { pgd_t pgd; } pud_t;
71961
71962-#define PUD_SHIFT PGDIR_SHIFT
71963-#define PTRS_PER_PUD 1
71964-#define PUD_SIZE (1UL << PUD_SHIFT)
71965-#define PUD_MASK (~(PUD_SIZE-1))
71966-
71967 /*
71968 * The "pgd_xxx()" functions here are trivial for a folded two-level
71969 * setup: the pud is never bad, and a pud always exists (as it's folded
71970@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
71971 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
71972
71973 #define pgd_populate(mm, pgd, pud) do { } while (0)
71974+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
71975 /*
71976 * (puds are folded into pgds so this doesn't get actually called,
71977 * but the define is needed for a generic inline function.)
71978diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
71979index 0807ddf..cd67747 100644
71980--- a/include/asm-generic/pgtable.h
71981+++ b/include/asm-generic/pgtable.h
71982@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
71983 }
71984 #endif /* CONFIG_NUMA_BALANCING */
71985
71986+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
71987+#ifdef CONFIG_PAX_KERNEXEC
71988+#error KERNEXEC requires pax_open_kernel
71989+#else
71990+static inline unsigned long pax_open_kernel(void) { return 0; }
71991+#endif
71992+#endif
71993+
71994+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
71995+#ifdef CONFIG_PAX_KERNEXEC
71996+#error KERNEXEC requires pax_close_kernel
71997+#else
71998+static inline unsigned long pax_close_kernel(void) { return 0; }
71999+#endif
72000+#endif
72001+
72002 #endif /* CONFIG_MMU */
72003
72004 #endif /* !__ASSEMBLY__ */
72005diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72006index dc1269c..48a4f51 100644
72007--- a/include/asm-generic/uaccess.h
72008+++ b/include/asm-generic/uaccess.h
72009@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72010 return __clear_user(to, n);
72011 }
72012
72013+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72014+#ifdef CONFIG_PAX_MEMORY_UDEREF
72015+#error UDEREF requires pax_open_userland
72016+#else
72017+static inline unsigned long pax_open_userland(void) { return 0; }
72018+#endif
72019+#endif
72020+
72021+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72022+#ifdef CONFIG_PAX_MEMORY_UDEREF
72023+#error UDEREF requires pax_close_userland
72024+#else
72025+static inline unsigned long pax_close_userland(void) { return 0; }
72026+#endif
72027+#endif
72028+
72029 #endif /* __ASM_GENERIC_UACCESS_H */
72030diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72031index 69732d2..cbe16d9 100644
72032--- a/include/asm-generic/vmlinux.lds.h
72033+++ b/include/asm-generic/vmlinux.lds.h
72034@@ -227,6 +227,7 @@
72035 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72036 VMLINUX_SYMBOL(__start_rodata) = .; \
72037 *(.rodata) *(.rodata.*) \
72038+ *(.data..read_only) \
72039 *(__vermagic) /* Kernel version magic */ \
72040 . = ALIGN(8); \
72041 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72042@@ -710,17 +711,18 @@
72043 * section in the linker script will go there too. @phdr should have
72044 * a leading colon.
72045 *
72046- * Note that this macros defines __per_cpu_load as an absolute symbol.
72047+ * Note that this macros defines per_cpu_load as an absolute symbol.
72048 * If there is no need to put the percpu section at a predetermined
72049 * address, use PERCPU_SECTION.
72050 */
72051 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72052- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72053- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72054+ per_cpu_load = .; \
72055+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72056 - LOAD_OFFSET) { \
72057+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72058 PERCPU_INPUT(cacheline) \
72059 } phdr \
72060- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72061+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72062
72063 /**
72064 * PERCPU_SECTION - define output section for percpu area, simple version
72065diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72066index 418d270..bfd2794 100644
72067--- a/include/crypto/algapi.h
72068+++ b/include/crypto/algapi.h
72069@@ -34,7 +34,7 @@ struct crypto_type {
72070 unsigned int maskclear;
72071 unsigned int maskset;
72072 unsigned int tfmsize;
72073-};
72074+} __do_const;
72075
72076 struct crypto_instance {
72077 struct crypto_alg alg;
72078diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72079index 12083dc..39740ec 100644
72080--- a/include/drm/drmP.h
72081+++ b/include/drm/drmP.h
72082@@ -69,6 +69,7 @@
72083 #include <linux/workqueue.h>
72084 #include <linux/poll.h>
72085 #include <asm/pgalloc.h>
72086+#include <asm/local.h>
72087 #include <drm/drm.h>
72088 #include <drm/drm_sarea.h>
72089
72090@@ -293,10 +294,12 @@ do { \
72091 * \param cmd command.
72092 * \param arg argument.
72093 */
72094-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72095+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72096+ struct drm_file *file_priv);
72097+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72098 struct drm_file *file_priv);
72099
72100-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72101+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72102 unsigned long arg);
72103
72104 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72105@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72106 struct drm_ioctl_desc {
72107 unsigned int cmd;
72108 int flags;
72109- drm_ioctl_t *func;
72110+ drm_ioctl_t func;
72111 unsigned int cmd_drv;
72112 const char *name;
72113-};
72114+} __do_const;
72115
72116 /**
72117 * Creates a driver or general drm_ioctl_desc array entry for the given
72118@@ -1015,7 +1018,7 @@ struct drm_info_list {
72119 int (*show)(struct seq_file*, void*); /** show callback */
72120 u32 driver_features; /**< Required driver features for this entry */
72121 void *data;
72122-};
72123+} __do_const;
72124
72125 /**
72126 * debugfs node structure. This structure represents a debugfs file.
72127@@ -1088,7 +1091,7 @@ struct drm_device {
72128
72129 /** \name Usage Counters */
72130 /*@{ */
72131- int open_count; /**< Outstanding files open */
72132+ local_t open_count; /**< Outstanding files open */
72133 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72134 atomic_t vma_count; /**< Outstanding vma areas open */
72135 int buf_use; /**< Buffers in use -- cannot alloc */
72136@@ -1099,7 +1102,7 @@ struct drm_device {
72137 /*@{ */
72138 unsigned long counters;
72139 enum drm_stat_type types[15];
72140- atomic_t counts[15];
72141+ atomic_unchecked_t counts[15];
72142 /*@} */
72143
72144 struct list_head filelist;
72145diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72146index f43d556..94d9343 100644
72147--- a/include/drm/drm_crtc_helper.h
72148+++ b/include/drm/drm_crtc_helper.h
72149@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72150 struct drm_connector *connector);
72151 /* disable encoder when not in use - more explicit than dpms off */
72152 void (*disable)(struct drm_encoder *encoder);
72153-};
72154+} __no_const;
72155
72156 /**
72157 * drm_connector_helper_funcs - helper operations for connectors
72158diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72159index 72dcbe8..8db58d7 100644
72160--- a/include/drm/ttm/ttm_memory.h
72161+++ b/include/drm/ttm/ttm_memory.h
72162@@ -48,7 +48,7 @@
72163
72164 struct ttm_mem_shrink {
72165 int (*do_shrink) (struct ttm_mem_shrink *);
72166-};
72167+} __no_const;
72168
72169 /**
72170 * struct ttm_mem_global - Global memory accounting structure.
72171diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72172index 4b840e8..155d235 100644
72173--- a/include/keys/asymmetric-subtype.h
72174+++ b/include/keys/asymmetric-subtype.h
72175@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72176 /* Verify the signature on a key of this subtype (optional) */
72177 int (*verify_signature)(const struct key *key,
72178 const struct public_key_signature *sig);
72179-};
72180+} __do_const;
72181
72182 /**
72183 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72184diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72185index c1da539..1dcec55 100644
72186--- a/include/linux/atmdev.h
72187+++ b/include/linux/atmdev.h
72188@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72189 #endif
72190
72191 struct k_atm_aal_stats {
72192-#define __HANDLE_ITEM(i) atomic_t i
72193+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72194 __AAL_STAT_ITEMS
72195 #undef __HANDLE_ITEM
72196 };
72197@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72198 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72199 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72200 struct module *owner;
72201-};
72202+} __do_const ;
72203
72204 struct atmphy_ops {
72205 int (*start)(struct atm_dev *dev);
72206diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72207index 70cf138..0418ee2 100644
72208--- a/include/linux/binfmts.h
72209+++ b/include/linux/binfmts.h
72210@@ -73,8 +73,10 @@ struct linux_binfmt {
72211 int (*load_binary)(struct linux_binprm *);
72212 int (*load_shlib)(struct file *);
72213 int (*core_dump)(struct coredump_params *cprm);
72214+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72215+ void (*handle_mmap)(struct file *);
72216 unsigned long min_coredump; /* minimal dump size */
72217-};
72218+} __do_const;
72219
72220 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72221
72222diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72223index 2fdb4a4..54aad7e 100644
72224--- a/include/linux/blkdev.h
72225+++ b/include/linux/blkdev.h
72226@@ -1526,7 +1526,7 @@ struct block_device_operations {
72227 /* this callback is with swap_lock and sometimes page table lock held */
72228 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72229 struct module *owner;
72230-};
72231+} __do_const;
72232
72233 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72234 unsigned long);
72235diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72236index 7c2e030..b72475d 100644
72237--- a/include/linux/blktrace_api.h
72238+++ b/include/linux/blktrace_api.h
72239@@ -23,7 +23,7 @@ struct blk_trace {
72240 struct dentry *dir;
72241 struct dentry *dropped_file;
72242 struct dentry *msg_file;
72243- atomic_t dropped;
72244+ atomic_unchecked_t dropped;
72245 };
72246
72247 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72248diff --git a/include/linux/cache.h b/include/linux/cache.h
72249index 4c57065..40346da 100644
72250--- a/include/linux/cache.h
72251+++ b/include/linux/cache.h
72252@@ -16,6 +16,14 @@
72253 #define __read_mostly
72254 #endif
72255
72256+#ifndef __read_only
72257+#ifdef CONFIG_PAX_KERNEXEC
72258+#error KERNEXEC requires __read_only
72259+#else
72260+#define __read_only __read_mostly
72261+#endif
72262+#endif
72263+
72264 #ifndef ____cacheline_aligned
72265 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72266 #endif
72267diff --git a/include/linux/capability.h b/include/linux/capability.h
72268index d9a4f7f4..19f77d6 100644
72269--- a/include/linux/capability.h
72270+++ b/include/linux/capability.h
72271@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72272 extern bool nsown_capable(int cap);
72273 extern bool inode_capable(const struct inode *inode, int cap);
72274 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72275+extern bool capable_nolog(int cap);
72276+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72277+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72278
72279 /* audit system wants to get cap info from files as well */
72280 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72281
72282+extern int is_privileged_binary(const struct dentry *dentry);
72283+
72284 #endif /* !_LINUX_CAPABILITY_H */
72285diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72286index 8609d57..86e4d79 100644
72287--- a/include/linux/cdrom.h
72288+++ b/include/linux/cdrom.h
72289@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72290
72291 /* driver specifications */
72292 const int capability; /* capability flags */
72293- int n_minors; /* number of active minor devices */
72294 /* handle uniform packets for scsi type devices (scsi,atapi) */
72295 int (*generic_packet) (struct cdrom_device_info *,
72296 struct packet_command *);
72297diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72298index 4ce9056..86caac6 100644
72299--- a/include/linux/cleancache.h
72300+++ b/include/linux/cleancache.h
72301@@ -31,7 +31,7 @@ struct cleancache_ops {
72302 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72303 void (*invalidate_inode)(int, struct cleancache_filekey);
72304 void (*invalidate_fs)(int);
72305-};
72306+} __no_const;
72307
72308 extern struct cleancache_ops *
72309 cleancache_register_ops(struct cleancache_ops *ops);
72310diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72311index 1ec14a7..d0654a2 100644
72312--- a/include/linux/clk-provider.h
72313+++ b/include/linux/clk-provider.h
72314@@ -132,6 +132,7 @@ struct clk_ops {
72315 unsigned long);
72316 void (*init)(struct clk_hw *hw);
72317 };
72318+typedef struct clk_ops __no_const clk_ops_no_const;
72319
72320 /**
72321 * struct clk_init_data - holds init data that's common to all clocks and is
72322diff --git a/include/linux/compat.h b/include/linux/compat.h
72323index ec1aee4..1077986 100644
72324--- a/include/linux/compat.h
72325+++ b/include/linux/compat.h
72326@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72327 compat_size_t __user *len_ptr);
72328
72329 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72330-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72331+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72332 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72333 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72334 compat_ssize_t msgsz, int msgflg);
72335@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72336 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72337 compat_ulong_t addr, compat_ulong_t data);
72338 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72339- compat_long_t addr, compat_long_t data);
72340+ compat_ulong_t addr, compat_ulong_t data);
72341
72342 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72343 /*
72344diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72345index ded4299..da50e3b 100644
72346--- a/include/linux/compiler-gcc4.h
72347+++ b/include/linux/compiler-gcc4.h
72348@@ -39,9 +39,29 @@
72349 # define __compiletime_warning(message) __attribute__((warning(message)))
72350 # define __compiletime_error(message) __attribute__((error(message)))
72351 #endif /* __CHECKER__ */
72352+
72353+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72354+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72355+#define __bos0(ptr) __bos((ptr), 0)
72356+#define __bos1(ptr) __bos((ptr), 1)
72357 #endif /* GCC_VERSION >= 40300 */
72358
72359 #if GCC_VERSION >= 40500
72360+
72361+#ifdef CONSTIFY_PLUGIN
72362+#define __no_const __attribute__((no_const))
72363+#define __do_const __attribute__((do_const))
72364+#endif
72365+
72366+#ifdef SIZE_OVERFLOW_PLUGIN
72367+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72368+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72369+#endif
72370+
72371+#ifdef LATENT_ENTROPY_PLUGIN
72372+#define __latent_entropy __attribute__((latent_entropy))
72373+#endif
72374+
72375 /*
72376 * Mark a position in code as unreachable. This can be used to
72377 * suppress control flow warnings after asm blocks that transfer
72378diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72379index 92669cd..1771a15 100644
72380--- a/include/linux/compiler.h
72381+++ b/include/linux/compiler.h
72382@@ -5,11 +5,14 @@
72383
72384 #ifdef __CHECKER__
72385 # define __user __attribute__((noderef, address_space(1)))
72386+# define __force_user __force __user
72387 # define __kernel __attribute__((address_space(0)))
72388+# define __force_kernel __force __kernel
72389 # define __safe __attribute__((safe))
72390 # define __force __attribute__((force))
72391 # define __nocast __attribute__((nocast))
72392 # define __iomem __attribute__((noderef, address_space(2)))
72393+# define __force_iomem __force __iomem
72394 # define __must_hold(x) __attribute__((context(x,1,1)))
72395 # define __acquires(x) __attribute__((context(x,0,1)))
72396 # define __releases(x) __attribute__((context(x,1,0)))
72397@@ -17,20 +20,37 @@
72398 # define __release(x) __context__(x,-1)
72399 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72400 # define __percpu __attribute__((noderef, address_space(3)))
72401+# define __force_percpu __force __percpu
72402 #ifdef CONFIG_SPARSE_RCU_POINTER
72403 # define __rcu __attribute__((noderef, address_space(4)))
72404+# define __force_rcu __force __rcu
72405 #else
72406 # define __rcu
72407+# define __force_rcu
72408 #endif
72409 extern void __chk_user_ptr(const volatile void __user *);
72410 extern void __chk_io_ptr(const volatile void __iomem *);
72411 #else
72412-# define __user
72413-# define __kernel
72414+# ifdef CHECKER_PLUGIN
72415+//# define __user
72416+//# define __force_user
72417+//# define __kernel
72418+//# define __force_kernel
72419+# else
72420+# ifdef STRUCTLEAK_PLUGIN
72421+# define __user __attribute__((user))
72422+# else
72423+# define __user
72424+# endif
72425+# define __force_user
72426+# define __kernel
72427+# define __force_kernel
72428+# endif
72429 # define __safe
72430 # define __force
72431 # define __nocast
72432 # define __iomem
72433+# define __force_iomem
72434 # define __chk_user_ptr(x) (void)0
72435 # define __chk_io_ptr(x) (void)0
72436 # define __builtin_warning(x, y...) (1)
72437@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72438 # define __release(x) (void)0
72439 # define __cond_lock(x,c) (c)
72440 # define __percpu
72441+# define __force_percpu
72442 # define __rcu
72443+# define __force_rcu
72444 #endif
72445
72446 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72447@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72448 # define __attribute_const__ /* unimplemented */
72449 #endif
72450
72451+#ifndef __no_const
72452+# define __no_const
72453+#endif
72454+
72455+#ifndef __do_const
72456+# define __do_const
72457+#endif
72458+
72459+#ifndef __size_overflow
72460+# define __size_overflow(...)
72461+#endif
72462+
72463+#ifndef __intentional_overflow
72464+# define __intentional_overflow(...)
72465+#endif
72466+
72467+#ifndef __latent_entropy
72468+# define __latent_entropy
72469+#endif
72470+
72471 /*
72472 * Tell gcc if a function is cold. The compiler will assume any path
72473 * directly leading to the call is unlikely.
72474@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72475 #define __cold
72476 #endif
72477
72478+#ifndef __alloc_size
72479+#define __alloc_size(...)
72480+#endif
72481+
72482+#ifndef __bos
72483+#define __bos(ptr, arg)
72484+#endif
72485+
72486+#ifndef __bos0
72487+#define __bos0(ptr)
72488+#endif
72489+
72490+#ifndef __bos1
72491+#define __bos1(ptr)
72492+#endif
72493+
72494 /* Simple shorthand for a section definition */
72495 #ifndef __section
72496 # define __section(S) __attribute__ ((__section__(#S)))
72497@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72498 * use is to mediate communication between process-level code and irq/NMI
72499 * handlers, all running on the same CPU.
72500 */
72501-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72502+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72503+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72504
72505 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72506 #ifdef CONFIG_KPROBES
72507diff --git a/include/linux/completion.h b/include/linux/completion.h
72508index 3cd574d..adce5fa 100644
72509--- a/include/linux/completion.h
72510+++ b/include/linux/completion.h
72511@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72512 extern void wait_for_completion(struct completion *);
72513 extern void wait_for_completion_io(struct completion *);
72514 extern int wait_for_completion_interruptible(struct completion *x);
72515-extern int wait_for_completion_killable(struct completion *x);
72516+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72517 extern unsigned long wait_for_completion_timeout(struct completion *x,
72518 unsigned long timeout);
72519 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72520 unsigned long timeout);
72521 extern long wait_for_completion_interruptible_timeout(
72522- struct completion *x, unsigned long timeout);
72523+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72524 extern long wait_for_completion_killable_timeout(
72525- struct completion *x, unsigned long timeout);
72526+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72527 extern bool try_wait_for_completion(struct completion *x);
72528 extern bool completion_done(struct completion *x);
72529
72530diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72531index 34025df..d94bbbc 100644
72532--- a/include/linux/configfs.h
72533+++ b/include/linux/configfs.h
72534@@ -125,7 +125,7 @@ struct configfs_attribute {
72535 const char *ca_name;
72536 struct module *ca_owner;
72537 umode_t ca_mode;
72538-};
72539+} __do_const;
72540
72541 /*
72542 * Users often need to create attribute structures for their configurable
72543diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72544index 90d5a15..950cb80 100644
72545--- a/include/linux/cpufreq.h
72546+++ b/include/linux/cpufreq.h
72547@@ -266,7 +266,7 @@ struct cpufreq_driver {
72548 int (*suspend) (struct cpufreq_policy *policy);
72549 int (*resume) (struct cpufreq_policy *policy);
72550 struct freq_attr **attr;
72551-};
72552+} __do_const;
72553
72554 /* flags */
72555
72556@@ -325,6 +325,7 @@ struct global_attr {
72557 ssize_t (*store)(struct kobject *a, struct attribute *b,
72558 const char *c, size_t count);
72559 };
72560+typedef struct global_attr __no_const global_attr_no_const;
72561
72562 #define define_one_global_ro(_name) \
72563 static struct global_attr _name = \
72564diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72565index 0bc4b74..973b368 100644
72566--- a/include/linux/cpuidle.h
72567+++ b/include/linux/cpuidle.h
72568@@ -52,7 +52,8 @@ struct cpuidle_state {
72569 int index);
72570
72571 int (*enter_dead) (struct cpuidle_device *dev, int index);
72572-};
72573+} __do_const;
72574+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72575
72576 /* Idle State Flags */
72577 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72578@@ -191,7 +192,7 @@ struct cpuidle_governor {
72579 void (*reflect) (struct cpuidle_device *dev, int index);
72580
72581 struct module *owner;
72582-};
72583+} __do_const;
72584
72585 #ifdef CONFIG_CPU_IDLE
72586
72587diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72588index d08e4d2..95fad61 100644
72589--- a/include/linux/cpumask.h
72590+++ b/include/linux/cpumask.h
72591@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72592 }
72593
72594 /* Valid inputs for n are -1 and 0. */
72595-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72596+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72597 {
72598 return n+1;
72599 }
72600
72601-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72602+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72603 {
72604 return n+1;
72605 }
72606
72607-static inline unsigned int cpumask_next_and(int n,
72608+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72609 const struct cpumask *srcp,
72610 const struct cpumask *andp)
72611 {
72612@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72613 *
72614 * Returns >= nr_cpu_ids if no further cpus set.
72615 */
72616-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72617+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72618 {
72619 /* -1 is a legal arg here. */
72620 if (n != -1)
72621@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72622 *
72623 * Returns >= nr_cpu_ids if no further cpus unset.
72624 */
72625-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72626+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72627 {
72628 /* -1 is a legal arg here. */
72629 if (n != -1)
72630@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72631 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72632 }
72633
72634-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72635+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72636 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72637
72638 /**
72639diff --git a/include/linux/cred.h b/include/linux/cred.h
72640index 04421e8..6bce4ef 100644
72641--- a/include/linux/cred.h
72642+++ b/include/linux/cred.h
72643@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72644 static inline void validate_process_creds(void)
72645 {
72646 }
72647+static inline void validate_task_creds(struct task_struct *task)
72648+{
72649+}
72650 #endif
72651
72652 /**
72653diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72654index b92eadf..b4ecdc1 100644
72655--- a/include/linux/crypto.h
72656+++ b/include/linux/crypto.h
72657@@ -373,7 +373,7 @@ struct cipher_tfm {
72658 const u8 *key, unsigned int keylen);
72659 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72660 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72661-};
72662+} __no_const;
72663
72664 struct hash_tfm {
72665 int (*init)(struct hash_desc *desc);
72666@@ -394,13 +394,13 @@ struct compress_tfm {
72667 int (*cot_decompress)(struct crypto_tfm *tfm,
72668 const u8 *src, unsigned int slen,
72669 u8 *dst, unsigned int *dlen);
72670-};
72671+} __no_const;
72672
72673 struct rng_tfm {
72674 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72675 unsigned int dlen);
72676 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72677-};
72678+} __no_const;
72679
72680 #define crt_ablkcipher crt_u.ablkcipher
72681 #define crt_aead crt_u.aead
72682diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72683index 653589e..4ef254a 100644
72684--- a/include/linux/ctype.h
72685+++ b/include/linux/ctype.h
72686@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72687 * Fast implementation of tolower() for internal usage. Do not use in your
72688 * code.
72689 */
72690-static inline char _tolower(const char c)
72691+static inline unsigned char _tolower(const unsigned char c)
72692 {
72693 return c | 0x20;
72694 }
72695diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72696index 7925bf0..d5143d2 100644
72697--- a/include/linux/decompress/mm.h
72698+++ b/include/linux/decompress/mm.h
72699@@ -77,7 +77,7 @@ static void free(void *where)
72700 * warnings when not needed (indeed large_malloc / large_free are not
72701 * needed by inflate */
72702
72703-#define malloc(a) kmalloc(a, GFP_KERNEL)
72704+#define malloc(a) kmalloc((a), GFP_KERNEL)
72705 #define free(a) kfree(a)
72706
72707 #define large_malloc(a) vmalloc(a)
72708diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72709index 5f1ab92..39c35ae 100644
72710--- a/include/linux/devfreq.h
72711+++ b/include/linux/devfreq.h
72712@@ -114,7 +114,7 @@ struct devfreq_governor {
72713 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72714 int (*event_handler)(struct devfreq *devfreq,
72715 unsigned int event, void *data);
72716-};
72717+} __do_const;
72718
72719 /**
72720 * struct devfreq - Device devfreq structure
72721diff --git a/include/linux/device.h b/include/linux/device.h
72722index 22b546a..a573dc9 100644
72723--- a/include/linux/device.h
72724+++ b/include/linux/device.h
72725@@ -305,7 +305,7 @@ struct subsys_interface {
72726 struct list_head node;
72727 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72728 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72729-};
72730+} __do_const;
72731
72732 int subsys_interface_register(struct subsys_interface *sif);
72733 void subsys_interface_unregister(struct subsys_interface *sif);
72734@@ -493,7 +493,7 @@ struct device_type {
72735 void (*release)(struct device *dev);
72736
72737 const struct dev_pm_ops *pm;
72738-};
72739+} __do_const;
72740
72741 /* interface for exporting device attributes */
72742 struct device_attribute {
72743@@ -503,11 +503,12 @@ struct device_attribute {
72744 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72745 const char *buf, size_t count);
72746 };
72747+typedef struct device_attribute __no_const device_attribute_no_const;
72748
72749 struct dev_ext_attribute {
72750 struct device_attribute attr;
72751 void *var;
72752-};
72753+} __do_const;
72754
72755 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72756 char *buf);
72757diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72758index 94af418..b1ca7a2 100644
72759--- a/include/linux/dma-mapping.h
72760+++ b/include/linux/dma-mapping.h
72761@@ -54,7 +54,7 @@ struct dma_map_ops {
72762 u64 (*get_required_mask)(struct device *dev);
72763 #endif
72764 int is_phys;
72765-};
72766+} __do_const;
72767
72768 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72769
72770diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72771index cb286b1..923d066 100644
72772--- a/include/linux/dmaengine.h
72773+++ b/include/linux/dmaengine.h
72774@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72775 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72776 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72777
72778-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72779+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72780 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72781-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72782+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72783 struct dma_pinned_list *pinned_list, struct page *page,
72784 unsigned int offset, size_t len);
72785
72786diff --git a/include/linux/efi.h b/include/linux/efi.h
72787index 5f8f176..62a0556 100644
72788--- a/include/linux/efi.h
72789+++ b/include/linux/efi.h
72790@@ -745,6 +745,7 @@ struct efivar_operations {
72791 efi_set_variable_t *set_variable;
72792 efi_query_variable_store_t *query_variable_store;
72793 };
72794+typedef struct efivar_operations __no_const efivar_operations_no_const;
72795
72796 struct efivars {
72797 /*
72798diff --git a/include/linux/elf.h b/include/linux/elf.h
72799index 40a3c0e..4c45a38 100644
72800--- a/include/linux/elf.h
72801+++ b/include/linux/elf.h
72802@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72803 #define elf_note elf32_note
72804 #define elf_addr_t Elf32_Off
72805 #define Elf_Half Elf32_Half
72806+#define elf_dyn Elf32_Dyn
72807
72808 #else
72809
72810@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72811 #define elf_note elf64_note
72812 #define elf_addr_t Elf64_Off
72813 #define Elf_Half Elf64_Half
72814+#define elf_dyn Elf64_Dyn
72815
72816 #endif
72817
72818diff --git a/include/linux/err.h b/include/linux/err.h
72819index 221fcfb..f29e5e2 100644
72820--- a/include/linux/err.h
72821+++ b/include/linux/err.h
72822@@ -19,12 +19,12 @@
72823
72824 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72825
72826-static inline void * __must_check ERR_PTR(long error)
72827+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72828 {
72829 return (void *) error;
72830 }
72831
72832-static inline long __must_check PTR_ERR(__force const void *ptr)
72833+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72834 {
72835 return (long) ptr;
72836 }
72837diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72838index fcb51c8..bdafcf6 100644
72839--- a/include/linux/extcon.h
72840+++ b/include/linux/extcon.h
72841@@ -134,7 +134,7 @@ struct extcon_dev {
72842 /* /sys/class/extcon/.../mutually_exclusive/... */
72843 struct attribute_group attr_g_muex;
72844 struct attribute **attrs_muex;
72845- struct device_attribute *d_attrs_muex;
72846+ device_attribute_no_const *d_attrs_muex;
72847 };
72848
72849 /**
72850diff --git a/include/linux/fb.h b/include/linux/fb.h
72851index ffac70a..ca3e711 100644
72852--- a/include/linux/fb.h
72853+++ b/include/linux/fb.h
72854@@ -304,7 +304,7 @@ struct fb_ops {
72855 /* called at KDB enter and leave time to prepare the console */
72856 int (*fb_debug_enter)(struct fb_info *info);
72857 int (*fb_debug_leave)(struct fb_info *info);
72858-};
72859+} __do_const;
72860
72861 #ifdef CONFIG_FB_TILEBLITTING
72862 #define FB_TILE_CURSOR_NONE 0
72863diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72864index 085197b..0fa6f0b 100644
72865--- a/include/linux/fdtable.h
72866+++ b/include/linux/fdtable.h
72867@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72868 void put_files_struct(struct files_struct *fs);
72869 void reset_files_struct(struct files_struct *);
72870 int unshare_files(struct files_struct **);
72871-struct files_struct *dup_fd(struct files_struct *, int *);
72872+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72873 void do_close_on_exec(struct files_struct *);
72874 int iterate_fd(struct files_struct *, unsigned,
72875 int (*)(const void *, struct file *, unsigned),
72876diff --git a/include/linux/filter.h b/include/linux/filter.h
72877index a6ac848..a104a76 100644
72878--- a/include/linux/filter.h
72879+++ b/include/linux/filter.h
72880@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72881
72882 struct sk_buff;
72883 struct sock;
72884+struct bpf_jit_work;
72885
72886 struct sk_filter
72887 {
72888@@ -27,6 +28,9 @@ struct sk_filter
72889 unsigned int len; /* Number of filter blocks */
72890 unsigned int (*bpf_func)(const struct sk_buff *skb,
72891 const struct sock_filter *filter);
72892+#ifdef CONFIG_BPF_JIT
72893+ struct bpf_jit_work *work;
72894+#endif
72895 struct rcu_head rcu;
72896 struct sock_filter insns[0];
72897 };
72898diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72899index 8293262..2b3b8bd 100644
72900--- a/include/linux/frontswap.h
72901+++ b/include/linux/frontswap.h
72902@@ -11,7 +11,7 @@ struct frontswap_ops {
72903 int (*load)(unsigned, pgoff_t, struct page *);
72904 void (*invalidate_page)(unsigned, pgoff_t);
72905 void (*invalidate_area)(unsigned);
72906-};
72907+} __no_const;
72908
72909 extern bool frontswap_enabled;
72910 extern struct frontswap_ops *
72911diff --git a/include/linux/fs.h b/include/linux/fs.h
72912index 9818747..788bfbd 100644
72913--- a/include/linux/fs.h
72914+++ b/include/linux/fs.h
72915@@ -1554,7 +1554,8 @@ struct file_operations {
72916 long (*fallocate)(struct file *file, int mode, loff_t offset,
72917 loff_t len);
72918 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72919-};
72920+} __do_const;
72921+typedef struct file_operations __no_const file_operations_no_const;
72922
72923 struct inode_operations {
72924 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72925@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72926 return !IS_DEADDIR(inode);
72927 }
72928
72929+static inline bool is_sidechannel_device(const struct inode *inode)
72930+{
72931+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72932+ umode_t mode = inode->i_mode;
72933+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72934+#else
72935+ return false;
72936+#endif
72937+}
72938+
72939 #endif /* _LINUX_FS_H */
72940diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72941index 2b93a9a..855d94a 100644
72942--- a/include/linux/fs_struct.h
72943+++ b/include/linux/fs_struct.h
72944@@ -6,7 +6,7 @@
72945 #include <linux/seqlock.h>
72946
72947 struct fs_struct {
72948- int users;
72949+ atomic_t users;
72950 spinlock_t lock;
72951 seqcount_t seq;
72952 int umask;
72953diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
72954index a9ff9a3..1ba1788 100644
72955--- a/include/linux/fscache-cache.h
72956+++ b/include/linux/fscache-cache.h
72957@@ -113,7 +113,7 @@ struct fscache_operation {
72958 fscache_operation_release_t release;
72959 };
72960
72961-extern atomic_t fscache_op_debug_id;
72962+extern atomic_unchecked_t fscache_op_debug_id;
72963 extern void fscache_op_work_func(struct work_struct *work);
72964
72965 extern void fscache_enqueue_operation(struct fscache_operation *);
72966@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
72967 INIT_WORK(&op->work, fscache_op_work_func);
72968 atomic_set(&op->usage, 1);
72969 op->state = FSCACHE_OP_ST_INITIALISED;
72970- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
72971+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
72972 op->processor = processor;
72973 op->release = release;
72974 INIT_LIST_HEAD(&op->pend_link);
72975diff --git a/include/linux/fscache.h b/include/linux/fscache.h
72976index 7a08623..4c07b0f 100644
72977--- a/include/linux/fscache.h
72978+++ b/include/linux/fscache.h
72979@@ -152,7 +152,7 @@ struct fscache_cookie_def {
72980 * - this is mandatory for any object that may have data
72981 */
72982 void (*now_uncached)(void *cookie_netfs_data);
72983-};
72984+} __do_const;
72985
72986 /*
72987 * fscache cached network filesystem type
72988diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
72989index 1c804b0..1432c2b 100644
72990--- a/include/linux/fsnotify.h
72991+++ b/include/linux/fsnotify.h
72992@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
72993 struct inode *inode = file_inode(file);
72994 __u32 mask = FS_ACCESS;
72995
72996+ if (is_sidechannel_device(inode))
72997+ return;
72998+
72999 if (S_ISDIR(inode->i_mode))
73000 mask |= FS_ISDIR;
73001
73002@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73003 struct inode *inode = file_inode(file);
73004 __u32 mask = FS_MODIFY;
73005
73006+ if (is_sidechannel_device(inode))
73007+ return;
73008+
73009 if (S_ISDIR(inode->i_mode))
73010 mask |= FS_ISDIR;
73011
73012@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73013 */
73014 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73015 {
73016- return kstrdup(name, GFP_KERNEL);
73017+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73018 }
73019
73020 /*
73021diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73022index 9f3c275..8bdff5d 100644
73023--- a/include/linux/genhd.h
73024+++ b/include/linux/genhd.h
73025@@ -194,7 +194,7 @@ struct gendisk {
73026 struct kobject *slave_dir;
73027
73028 struct timer_rand_state *random;
73029- atomic_t sync_io; /* RAID */
73030+ atomic_unchecked_t sync_io; /* RAID */
73031 struct disk_events *ev;
73032 #ifdef CONFIG_BLK_DEV_INTEGRITY
73033 struct blk_integrity *integrity;
73034@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
73035 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
73036
73037 /* drivers/char/random.c */
73038-extern void add_disk_randomness(struct gendisk *disk);
73039+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
73040 extern void rand_initialize_disk(struct gendisk *disk);
73041
73042 static inline sector_t get_start_sect(struct block_device *bdev)
73043diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73044index 023bc34..b02b46a 100644
73045--- a/include/linux/genl_magic_func.h
73046+++ b/include/linux/genl_magic_func.h
73047@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73048 },
73049
73050 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73051-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73052+static struct genl_ops ZZZ_genl_ops[] = {
73053 #include GENL_MAGIC_INCLUDE_FILE
73054 };
73055
73056diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73057index 9b4dd49..61fd41d 100644
73058--- a/include/linux/gfp.h
73059+++ b/include/linux/gfp.h
73060@@ -35,6 +35,13 @@ struct vm_area_struct;
73061 #define ___GFP_NO_KSWAPD 0x400000u
73062 #define ___GFP_OTHER_NODE 0x800000u
73063 #define ___GFP_WRITE 0x1000000u
73064+
73065+#ifdef CONFIG_PAX_USERCOPY_SLABS
73066+#define ___GFP_USERCOPY 0x2000000u
73067+#else
73068+#define ___GFP_USERCOPY 0
73069+#endif
73070+
73071 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73072
73073 /*
73074@@ -92,6 +99,7 @@ struct vm_area_struct;
73075 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73076 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73077 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73078+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73079
73080 /*
73081 * This may seem redundant, but it's a way of annotating false positives vs.
73082@@ -99,7 +107,7 @@ struct vm_area_struct;
73083 */
73084 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73085
73086-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73087+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73088 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73089
73090 /* This equals 0, but use constants in case they ever change */
73091@@ -153,6 +161,8 @@ struct vm_area_struct;
73092 /* 4GB DMA on some platforms */
73093 #define GFP_DMA32 __GFP_DMA32
73094
73095+#define GFP_USERCOPY __GFP_USERCOPY
73096+
73097 /* Convert GFP flags to their corresponding migrate type */
73098 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73099 {
73100diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73101new file mode 100644
73102index 0000000..ebe6d72
73103--- /dev/null
73104+++ b/include/linux/gracl.h
73105@@ -0,0 +1,319 @@
73106+#ifndef GR_ACL_H
73107+#define GR_ACL_H
73108+
73109+#include <linux/grdefs.h>
73110+#include <linux/resource.h>
73111+#include <linux/capability.h>
73112+#include <linux/dcache.h>
73113+#include <asm/resource.h>
73114+
73115+/* Major status information */
73116+
73117+#define GR_VERSION "grsecurity 2.9.1"
73118+#define GRSECURITY_VERSION 0x2901
73119+
73120+enum {
73121+ GR_SHUTDOWN = 0,
73122+ GR_ENABLE = 1,
73123+ GR_SPROLE = 2,
73124+ GR_RELOAD = 3,
73125+ GR_SEGVMOD = 4,
73126+ GR_STATUS = 5,
73127+ GR_UNSPROLE = 6,
73128+ GR_PASSSET = 7,
73129+ GR_SPROLEPAM = 8,
73130+};
73131+
73132+/* Password setup definitions
73133+ * kernel/grhash.c */
73134+enum {
73135+ GR_PW_LEN = 128,
73136+ GR_SALT_LEN = 16,
73137+ GR_SHA_LEN = 32,
73138+};
73139+
73140+enum {
73141+ GR_SPROLE_LEN = 64,
73142+};
73143+
73144+enum {
73145+ GR_NO_GLOB = 0,
73146+ GR_REG_GLOB,
73147+ GR_CREATE_GLOB
73148+};
73149+
73150+#define GR_NLIMITS 32
73151+
73152+/* Begin Data Structures */
73153+
73154+struct sprole_pw {
73155+ unsigned char *rolename;
73156+ unsigned char salt[GR_SALT_LEN];
73157+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73158+};
73159+
73160+struct name_entry {
73161+ __u32 key;
73162+ ino_t inode;
73163+ dev_t device;
73164+ char *name;
73165+ __u16 len;
73166+ __u8 deleted;
73167+ struct name_entry *prev;
73168+ struct name_entry *next;
73169+};
73170+
73171+struct inodev_entry {
73172+ struct name_entry *nentry;
73173+ struct inodev_entry *prev;
73174+ struct inodev_entry *next;
73175+};
73176+
73177+struct acl_role_db {
73178+ struct acl_role_label **r_hash;
73179+ __u32 r_size;
73180+};
73181+
73182+struct inodev_db {
73183+ struct inodev_entry **i_hash;
73184+ __u32 i_size;
73185+};
73186+
73187+struct name_db {
73188+ struct name_entry **n_hash;
73189+ __u32 n_size;
73190+};
73191+
73192+struct crash_uid {
73193+ uid_t uid;
73194+ unsigned long expires;
73195+};
73196+
73197+struct gr_hash_struct {
73198+ void **table;
73199+ void **nametable;
73200+ void *first;
73201+ __u32 table_size;
73202+ __u32 used_size;
73203+ int type;
73204+};
73205+
73206+/* Userspace Grsecurity ACL data structures */
73207+
73208+struct acl_subject_label {
73209+ char *filename;
73210+ ino_t inode;
73211+ dev_t device;
73212+ __u32 mode;
73213+ kernel_cap_t cap_mask;
73214+ kernel_cap_t cap_lower;
73215+ kernel_cap_t cap_invert_audit;
73216+
73217+ struct rlimit res[GR_NLIMITS];
73218+ __u32 resmask;
73219+
73220+ __u8 user_trans_type;
73221+ __u8 group_trans_type;
73222+ uid_t *user_transitions;
73223+ gid_t *group_transitions;
73224+ __u16 user_trans_num;
73225+ __u16 group_trans_num;
73226+
73227+ __u32 sock_families[2];
73228+ __u32 ip_proto[8];
73229+ __u32 ip_type;
73230+ struct acl_ip_label **ips;
73231+ __u32 ip_num;
73232+ __u32 inaddr_any_override;
73233+
73234+ __u32 crashes;
73235+ unsigned long expires;
73236+
73237+ struct acl_subject_label *parent_subject;
73238+ struct gr_hash_struct *hash;
73239+ struct acl_subject_label *prev;
73240+ struct acl_subject_label *next;
73241+
73242+ struct acl_object_label **obj_hash;
73243+ __u32 obj_hash_size;
73244+ __u16 pax_flags;
73245+};
73246+
73247+struct role_allowed_ip {
73248+ __u32 addr;
73249+ __u32 netmask;
73250+
73251+ struct role_allowed_ip *prev;
73252+ struct role_allowed_ip *next;
73253+};
73254+
73255+struct role_transition {
73256+ char *rolename;
73257+
73258+ struct role_transition *prev;
73259+ struct role_transition *next;
73260+};
73261+
73262+struct acl_role_label {
73263+ char *rolename;
73264+ uid_t uidgid;
73265+ __u16 roletype;
73266+
73267+ __u16 auth_attempts;
73268+ unsigned long expires;
73269+
73270+ struct acl_subject_label *root_label;
73271+ struct gr_hash_struct *hash;
73272+
73273+ struct acl_role_label *prev;
73274+ struct acl_role_label *next;
73275+
73276+ struct role_transition *transitions;
73277+ struct role_allowed_ip *allowed_ips;
73278+ uid_t *domain_children;
73279+ __u16 domain_child_num;
73280+
73281+ umode_t umask;
73282+
73283+ struct acl_subject_label **subj_hash;
73284+ __u32 subj_hash_size;
73285+};
73286+
73287+struct user_acl_role_db {
73288+ struct acl_role_label **r_table;
73289+ __u32 num_pointers; /* Number of allocations to track */
73290+ __u32 num_roles; /* Number of roles */
73291+ __u32 num_domain_children; /* Number of domain children */
73292+ __u32 num_subjects; /* Number of subjects */
73293+ __u32 num_objects; /* Number of objects */
73294+};
73295+
73296+struct acl_object_label {
73297+ char *filename;
73298+ ino_t inode;
73299+ dev_t device;
73300+ __u32 mode;
73301+
73302+ struct acl_subject_label *nested;
73303+ struct acl_object_label *globbed;
73304+
73305+ /* next two structures not used */
73306+
73307+ struct acl_object_label *prev;
73308+ struct acl_object_label *next;
73309+};
73310+
73311+struct acl_ip_label {
73312+ char *iface;
73313+ __u32 addr;
73314+ __u32 netmask;
73315+ __u16 low, high;
73316+ __u8 mode;
73317+ __u32 type;
73318+ __u32 proto[8];
73319+
73320+ /* next two structures not used */
73321+
73322+ struct acl_ip_label *prev;
73323+ struct acl_ip_label *next;
73324+};
73325+
73326+struct gr_arg {
73327+ struct user_acl_role_db role_db;
73328+ unsigned char pw[GR_PW_LEN];
73329+ unsigned char salt[GR_SALT_LEN];
73330+ unsigned char sum[GR_SHA_LEN];
73331+ unsigned char sp_role[GR_SPROLE_LEN];
73332+ struct sprole_pw *sprole_pws;
73333+ dev_t segv_device;
73334+ ino_t segv_inode;
73335+ uid_t segv_uid;
73336+ __u16 num_sprole_pws;
73337+ __u16 mode;
73338+};
73339+
73340+struct gr_arg_wrapper {
73341+ struct gr_arg *arg;
73342+ __u32 version;
73343+ __u32 size;
73344+};
73345+
73346+struct subject_map {
73347+ struct acl_subject_label *user;
73348+ struct acl_subject_label *kernel;
73349+ struct subject_map *prev;
73350+ struct subject_map *next;
73351+};
73352+
73353+struct acl_subj_map_db {
73354+ struct subject_map **s_hash;
73355+ __u32 s_size;
73356+};
73357+
73358+/* End Data Structures Section */
73359+
73360+/* Hash functions generated by empirical testing by Brad Spengler
73361+ Makes good use of the low bits of the inode. Generally 0-1 times
73362+ in loop for successful match. 0-3 for unsuccessful match.
73363+ Shift/add algorithm with modulus of table size and an XOR*/
73364+
73365+static __inline__ unsigned int
73366+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73367+{
73368+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73369+}
73370+
73371+ static __inline__ unsigned int
73372+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73373+{
73374+ return ((const unsigned long)userp % sz);
73375+}
73376+
73377+static __inline__ unsigned int
73378+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73379+{
73380+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73381+}
73382+
73383+static __inline__ unsigned int
73384+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73385+{
73386+ return full_name_hash((const unsigned char *)name, len) % sz;
73387+}
73388+
73389+#define FOR_EACH_ROLE_START(role) \
73390+ role = role_list; \
73391+ while (role) {
73392+
73393+#define FOR_EACH_ROLE_END(role) \
73394+ role = role->prev; \
73395+ }
73396+
73397+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73398+ subj = NULL; \
73399+ iter = 0; \
73400+ while (iter < role->subj_hash_size) { \
73401+ if (subj == NULL) \
73402+ subj = role->subj_hash[iter]; \
73403+ if (subj == NULL) { \
73404+ iter++; \
73405+ continue; \
73406+ }
73407+
73408+#define FOR_EACH_SUBJECT_END(subj,iter) \
73409+ subj = subj->next; \
73410+ if (subj == NULL) \
73411+ iter++; \
73412+ }
73413+
73414+
73415+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73416+ subj = role->hash->first; \
73417+ while (subj != NULL) {
73418+
73419+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73420+ subj = subj->next; \
73421+ }
73422+
73423+#endif
73424+
73425diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73426new file mode 100644
73427index 0000000..33ebd1f
73428--- /dev/null
73429+++ b/include/linux/gracl_compat.h
73430@@ -0,0 +1,156 @@
73431+#ifndef GR_ACL_COMPAT_H
73432+#define GR_ACL_COMPAT_H
73433+
73434+#include <linux/resource.h>
73435+#include <asm/resource.h>
73436+
73437+struct sprole_pw_compat {
73438+ compat_uptr_t rolename;
73439+ unsigned char salt[GR_SALT_LEN];
73440+ unsigned char sum[GR_SHA_LEN];
73441+};
73442+
73443+struct gr_hash_struct_compat {
73444+ compat_uptr_t table;
73445+ compat_uptr_t nametable;
73446+ compat_uptr_t first;
73447+ __u32 table_size;
73448+ __u32 used_size;
73449+ int type;
73450+};
73451+
73452+struct acl_subject_label_compat {
73453+ compat_uptr_t filename;
73454+ compat_ino_t inode;
73455+ __u32 device;
73456+ __u32 mode;
73457+ kernel_cap_t cap_mask;
73458+ kernel_cap_t cap_lower;
73459+ kernel_cap_t cap_invert_audit;
73460+
73461+ struct compat_rlimit res[GR_NLIMITS];
73462+ __u32 resmask;
73463+
73464+ __u8 user_trans_type;
73465+ __u8 group_trans_type;
73466+ compat_uptr_t user_transitions;
73467+ compat_uptr_t group_transitions;
73468+ __u16 user_trans_num;
73469+ __u16 group_trans_num;
73470+
73471+ __u32 sock_families[2];
73472+ __u32 ip_proto[8];
73473+ __u32 ip_type;
73474+ compat_uptr_t ips;
73475+ __u32 ip_num;
73476+ __u32 inaddr_any_override;
73477+
73478+ __u32 crashes;
73479+ compat_ulong_t expires;
73480+
73481+ compat_uptr_t parent_subject;
73482+ compat_uptr_t hash;
73483+ compat_uptr_t prev;
73484+ compat_uptr_t next;
73485+
73486+ compat_uptr_t obj_hash;
73487+ __u32 obj_hash_size;
73488+ __u16 pax_flags;
73489+};
73490+
73491+struct role_allowed_ip_compat {
73492+ __u32 addr;
73493+ __u32 netmask;
73494+
73495+ compat_uptr_t prev;
73496+ compat_uptr_t next;
73497+};
73498+
73499+struct role_transition_compat {
73500+ compat_uptr_t rolename;
73501+
73502+ compat_uptr_t prev;
73503+ compat_uptr_t next;
73504+};
73505+
73506+struct acl_role_label_compat {
73507+ compat_uptr_t rolename;
73508+ uid_t uidgid;
73509+ __u16 roletype;
73510+
73511+ __u16 auth_attempts;
73512+ compat_ulong_t expires;
73513+
73514+ compat_uptr_t root_label;
73515+ compat_uptr_t hash;
73516+
73517+ compat_uptr_t prev;
73518+ compat_uptr_t next;
73519+
73520+ compat_uptr_t transitions;
73521+ compat_uptr_t allowed_ips;
73522+ compat_uptr_t domain_children;
73523+ __u16 domain_child_num;
73524+
73525+ umode_t umask;
73526+
73527+ compat_uptr_t subj_hash;
73528+ __u32 subj_hash_size;
73529+};
73530+
73531+struct user_acl_role_db_compat {
73532+ compat_uptr_t r_table;
73533+ __u32 num_pointers;
73534+ __u32 num_roles;
73535+ __u32 num_domain_children;
73536+ __u32 num_subjects;
73537+ __u32 num_objects;
73538+};
73539+
73540+struct acl_object_label_compat {
73541+ compat_uptr_t filename;
73542+ compat_ino_t inode;
73543+ __u32 device;
73544+ __u32 mode;
73545+
73546+ compat_uptr_t nested;
73547+ compat_uptr_t globbed;
73548+
73549+ compat_uptr_t prev;
73550+ compat_uptr_t next;
73551+};
73552+
73553+struct acl_ip_label_compat {
73554+ compat_uptr_t iface;
73555+ __u32 addr;
73556+ __u32 netmask;
73557+ __u16 low, high;
73558+ __u8 mode;
73559+ __u32 type;
73560+ __u32 proto[8];
73561+
73562+ compat_uptr_t prev;
73563+ compat_uptr_t next;
73564+};
73565+
73566+struct gr_arg_compat {
73567+ struct user_acl_role_db_compat role_db;
73568+ unsigned char pw[GR_PW_LEN];
73569+ unsigned char salt[GR_SALT_LEN];
73570+ unsigned char sum[GR_SHA_LEN];
73571+ unsigned char sp_role[GR_SPROLE_LEN];
73572+ compat_uptr_t sprole_pws;
73573+ __u32 segv_device;
73574+ compat_ino_t segv_inode;
73575+ uid_t segv_uid;
73576+ __u16 num_sprole_pws;
73577+ __u16 mode;
73578+};
73579+
73580+struct gr_arg_wrapper_compat {
73581+ compat_uptr_t arg;
73582+ __u32 version;
73583+ __u32 size;
73584+};
73585+
73586+#endif
73587diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73588new file mode 100644
73589index 0000000..323ecf2
73590--- /dev/null
73591+++ b/include/linux/gralloc.h
73592@@ -0,0 +1,9 @@
73593+#ifndef __GRALLOC_H
73594+#define __GRALLOC_H
73595+
73596+void acl_free_all(void);
73597+int acl_alloc_stack_init(unsigned long size);
73598+void *acl_alloc(unsigned long len);
73599+void *acl_alloc_num(unsigned long num, unsigned long len);
73600+
73601+#endif
73602diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73603new file mode 100644
73604index 0000000..be66033
73605--- /dev/null
73606+++ b/include/linux/grdefs.h
73607@@ -0,0 +1,140 @@
73608+#ifndef GRDEFS_H
73609+#define GRDEFS_H
73610+
73611+/* Begin grsecurity status declarations */
73612+
73613+enum {
73614+ GR_READY = 0x01,
73615+ GR_STATUS_INIT = 0x00 // disabled state
73616+};
73617+
73618+/* Begin ACL declarations */
73619+
73620+/* Role flags */
73621+
73622+enum {
73623+ GR_ROLE_USER = 0x0001,
73624+ GR_ROLE_GROUP = 0x0002,
73625+ GR_ROLE_DEFAULT = 0x0004,
73626+ GR_ROLE_SPECIAL = 0x0008,
73627+ GR_ROLE_AUTH = 0x0010,
73628+ GR_ROLE_NOPW = 0x0020,
73629+ GR_ROLE_GOD = 0x0040,
73630+ GR_ROLE_LEARN = 0x0080,
73631+ GR_ROLE_TPE = 0x0100,
73632+ GR_ROLE_DOMAIN = 0x0200,
73633+ GR_ROLE_PAM = 0x0400,
73634+ GR_ROLE_PERSIST = 0x0800
73635+};
73636+
73637+/* ACL Subject and Object mode flags */
73638+enum {
73639+ GR_DELETED = 0x80000000
73640+};
73641+
73642+/* ACL Object-only mode flags */
73643+enum {
73644+ GR_READ = 0x00000001,
73645+ GR_APPEND = 0x00000002,
73646+ GR_WRITE = 0x00000004,
73647+ GR_EXEC = 0x00000008,
73648+ GR_FIND = 0x00000010,
73649+ GR_INHERIT = 0x00000020,
73650+ GR_SETID = 0x00000040,
73651+ GR_CREATE = 0x00000080,
73652+ GR_DELETE = 0x00000100,
73653+ GR_LINK = 0x00000200,
73654+ GR_AUDIT_READ = 0x00000400,
73655+ GR_AUDIT_APPEND = 0x00000800,
73656+ GR_AUDIT_WRITE = 0x00001000,
73657+ GR_AUDIT_EXEC = 0x00002000,
73658+ GR_AUDIT_FIND = 0x00004000,
73659+ GR_AUDIT_INHERIT= 0x00008000,
73660+ GR_AUDIT_SETID = 0x00010000,
73661+ GR_AUDIT_CREATE = 0x00020000,
73662+ GR_AUDIT_DELETE = 0x00040000,
73663+ GR_AUDIT_LINK = 0x00080000,
73664+ GR_PTRACERD = 0x00100000,
73665+ GR_NOPTRACE = 0x00200000,
73666+ GR_SUPPRESS = 0x00400000,
73667+ GR_NOLEARN = 0x00800000,
73668+ GR_INIT_TRANSFER= 0x01000000
73669+};
73670+
73671+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73672+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73673+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73674+
73675+/* ACL subject-only mode flags */
73676+enum {
73677+ GR_KILL = 0x00000001,
73678+ GR_VIEW = 0x00000002,
73679+ GR_PROTECTED = 0x00000004,
73680+ GR_LEARN = 0x00000008,
73681+ GR_OVERRIDE = 0x00000010,
73682+ /* just a placeholder, this mode is only used in userspace */
73683+ GR_DUMMY = 0x00000020,
73684+ GR_PROTSHM = 0x00000040,
73685+ GR_KILLPROC = 0x00000080,
73686+ GR_KILLIPPROC = 0x00000100,
73687+ /* just a placeholder, this mode is only used in userspace */
73688+ GR_NOTROJAN = 0x00000200,
73689+ GR_PROTPROCFD = 0x00000400,
73690+ GR_PROCACCT = 0x00000800,
73691+ GR_RELAXPTRACE = 0x00001000,
73692+ //GR_NESTED = 0x00002000,
73693+ GR_INHERITLEARN = 0x00004000,
73694+ GR_PROCFIND = 0x00008000,
73695+ GR_POVERRIDE = 0x00010000,
73696+ GR_KERNELAUTH = 0x00020000,
73697+ GR_ATSECURE = 0x00040000,
73698+ GR_SHMEXEC = 0x00080000
73699+};
73700+
73701+enum {
73702+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73703+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73704+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73705+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73706+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73707+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73708+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73709+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73710+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73711+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73712+};
73713+
73714+enum {
73715+ GR_ID_USER = 0x01,
73716+ GR_ID_GROUP = 0x02,
73717+};
73718+
73719+enum {
73720+ GR_ID_ALLOW = 0x01,
73721+ GR_ID_DENY = 0x02,
73722+};
73723+
73724+#define GR_CRASH_RES 31
73725+#define GR_UIDTABLE_MAX 500
73726+
73727+/* begin resource learning section */
73728+enum {
73729+ GR_RLIM_CPU_BUMP = 60,
73730+ GR_RLIM_FSIZE_BUMP = 50000,
73731+ GR_RLIM_DATA_BUMP = 10000,
73732+ GR_RLIM_STACK_BUMP = 1000,
73733+ GR_RLIM_CORE_BUMP = 10000,
73734+ GR_RLIM_RSS_BUMP = 500000,
73735+ GR_RLIM_NPROC_BUMP = 1,
73736+ GR_RLIM_NOFILE_BUMP = 5,
73737+ GR_RLIM_MEMLOCK_BUMP = 50000,
73738+ GR_RLIM_AS_BUMP = 500000,
73739+ GR_RLIM_LOCKS_BUMP = 2,
73740+ GR_RLIM_SIGPENDING_BUMP = 5,
73741+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73742+ GR_RLIM_NICE_BUMP = 1,
73743+ GR_RLIM_RTPRIO_BUMP = 1,
73744+ GR_RLIM_RTTIME_BUMP = 1000000
73745+};
73746+
73747+#endif
73748diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73749new file mode 100644
73750index 0000000..e337683
73751--- /dev/null
73752+++ b/include/linux/grinternal.h
73753@@ -0,0 +1,229 @@
73754+#ifndef __GRINTERNAL_H
73755+#define __GRINTERNAL_H
73756+
73757+#ifdef CONFIG_GRKERNSEC
73758+
73759+#include <linux/fs.h>
73760+#include <linux/mnt_namespace.h>
73761+#include <linux/nsproxy.h>
73762+#include <linux/gracl.h>
73763+#include <linux/grdefs.h>
73764+#include <linux/grmsg.h>
73765+
73766+void gr_add_learn_entry(const char *fmt, ...)
73767+ __attribute__ ((format (printf, 1, 2)));
73768+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73769+ const struct vfsmount *mnt);
73770+__u32 gr_check_create(const struct dentry *new_dentry,
73771+ const struct dentry *parent,
73772+ const struct vfsmount *mnt, const __u32 mode);
73773+int gr_check_protected_task(const struct task_struct *task);
73774+__u32 to_gr_audit(const __u32 reqmode);
73775+int gr_set_acls(const int type);
73776+int gr_apply_subject_to_task(struct task_struct *task);
73777+int gr_acl_is_enabled(void);
73778+char gr_roletype_to_char(void);
73779+
73780+void gr_handle_alertkill(struct task_struct *task);
73781+char *gr_to_filename(const struct dentry *dentry,
73782+ const struct vfsmount *mnt);
73783+char *gr_to_filename1(const struct dentry *dentry,
73784+ const struct vfsmount *mnt);
73785+char *gr_to_filename2(const struct dentry *dentry,
73786+ const struct vfsmount *mnt);
73787+char *gr_to_filename3(const struct dentry *dentry,
73788+ const struct vfsmount *mnt);
73789+
73790+extern int grsec_enable_ptrace_readexec;
73791+extern int grsec_enable_harden_ptrace;
73792+extern int grsec_enable_link;
73793+extern int grsec_enable_fifo;
73794+extern int grsec_enable_execve;
73795+extern int grsec_enable_shm;
73796+extern int grsec_enable_execlog;
73797+extern int grsec_enable_signal;
73798+extern int grsec_enable_audit_ptrace;
73799+extern int grsec_enable_forkfail;
73800+extern int grsec_enable_time;
73801+extern int grsec_enable_rofs;
73802+extern int grsec_deny_new_usb;
73803+extern int grsec_enable_chroot_shmat;
73804+extern int grsec_enable_chroot_mount;
73805+extern int grsec_enable_chroot_double;
73806+extern int grsec_enable_chroot_pivot;
73807+extern int grsec_enable_chroot_chdir;
73808+extern int grsec_enable_chroot_chmod;
73809+extern int grsec_enable_chroot_mknod;
73810+extern int grsec_enable_chroot_fchdir;
73811+extern int grsec_enable_chroot_nice;
73812+extern int grsec_enable_chroot_execlog;
73813+extern int grsec_enable_chroot_caps;
73814+extern int grsec_enable_chroot_sysctl;
73815+extern int grsec_enable_chroot_unix;
73816+extern int grsec_enable_symlinkown;
73817+extern kgid_t grsec_symlinkown_gid;
73818+extern int grsec_enable_tpe;
73819+extern kgid_t grsec_tpe_gid;
73820+extern int grsec_enable_tpe_all;
73821+extern int grsec_enable_tpe_invert;
73822+extern int grsec_enable_socket_all;
73823+extern kgid_t grsec_socket_all_gid;
73824+extern int grsec_enable_socket_client;
73825+extern kgid_t grsec_socket_client_gid;
73826+extern int grsec_enable_socket_server;
73827+extern kgid_t grsec_socket_server_gid;
73828+extern kgid_t grsec_audit_gid;
73829+extern int grsec_enable_group;
73830+extern int grsec_enable_log_rwxmaps;
73831+extern int grsec_enable_mount;
73832+extern int grsec_enable_chdir;
73833+extern int grsec_resource_logging;
73834+extern int grsec_enable_blackhole;
73835+extern int grsec_lastack_retries;
73836+extern int grsec_enable_brute;
73837+extern int grsec_lock;
73838+
73839+extern spinlock_t grsec_alert_lock;
73840+extern unsigned long grsec_alert_wtime;
73841+extern unsigned long grsec_alert_fyet;
73842+
73843+extern spinlock_t grsec_audit_lock;
73844+
73845+extern rwlock_t grsec_exec_file_lock;
73846+
73847+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73848+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73849+ (tsk)->exec_file->f_path.mnt) : "/")
73850+
73851+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73852+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73853+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73854+
73855+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73856+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73857+ (tsk)->exec_file->f_path.mnt) : "/")
73858+
73859+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73860+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73861+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73862+
73863+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73864+
73865+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73866+
73867+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73868+{
73869+ if (file1 && file2) {
73870+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73871+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73872+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73873+ return true;
73874+ }
73875+
73876+ return false;
73877+}
73878+
73879+#define GR_CHROOT_CAPS {{ \
73880+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73881+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73882+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73883+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73884+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73885+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73886+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73887+
73888+#define security_learn(normal_msg,args...) \
73889+({ \
73890+ read_lock(&grsec_exec_file_lock); \
73891+ gr_add_learn_entry(normal_msg "\n", ## args); \
73892+ read_unlock(&grsec_exec_file_lock); \
73893+})
73894+
73895+enum {
73896+ GR_DO_AUDIT,
73897+ GR_DONT_AUDIT,
73898+ /* used for non-audit messages that we shouldn't kill the task on */
73899+ GR_DONT_AUDIT_GOOD
73900+};
73901+
73902+enum {
73903+ GR_TTYSNIFF,
73904+ GR_RBAC,
73905+ GR_RBAC_STR,
73906+ GR_STR_RBAC,
73907+ GR_RBAC_MODE2,
73908+ GR_RBAC_MODE3,
73909+ GR_FILENAME,
73910+ GR_SYSCTL_HIDDEN,
73911+ GR_NOARGS,
73912+ GR_ONE_INT,
73913+ GR_ONE_INT_TWO_STR,
73914+ GR_ONE_STR,
73915+ GR_STR_INT,
73916+ GR_TWO_STR_INT,
73917+ GR_TWO_INT,
73918+ GR_TWO_U64,
73919+ GR_THREE_INT,
73920+ GR_FIVE_INT_TWO_STR,
73921+ GR_TWO_STR,
73922+ GR_THREE_STR,
73923+ GR_FOUR_STR,
73924+ GR_STR_FILENAME,
73925+ GR_FILENAME_STR,
73926+ GR_FILENAME_TWO_INT,
73927+ GR_FILENAME_TWO_INT_STR,
73928+ GR_TEXTREL,
73929+ GR_PTRACE,
73930+ GR_RESOURCE,
73931+ GR_CAP,
73932+ GR_SIG,
73933+ GR_SIG2,
73934+ GR_CRASH1,
73935+ GR_CRASH2,
73936+ GR_PSACCT,
73937+ GR_RWXMAP,
73938+ GR_RWXMAPVMA
73939+};
73940+
73941+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73942+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73943+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
73944+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
73945+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
73946+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
73947+#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)
73948+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
73949+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
73950+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
73951+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
73952+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
73953+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
73954+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
73955+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
73956+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
73957+#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)
73958+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
73959+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
73960+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
73961+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
73962+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
73963+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
73964+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
73965+#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)
73966+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
73967+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
73968+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
73969+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
73970+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
73971+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
73972+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
73973+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
73974+#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)
73975+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
73976+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
73977+
73978+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
73979+
73980+#endif
73981+
73982+#endif
73983diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
73984new file mode 100644
73985index 0000000..a4396b5
73986--- /dev/null
73987+++ b/include/linux/grmsg.h
73988@@ -0,0 +1,113 @@
73989+#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"
73990+#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"
73991+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
73992+#define GR_STOPMOD_MSG "denied modification of module state by "
73993+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
73994+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
73995+#define GR_IOPERM_MSG "denied use of ioperm() by "
73996+#define GR_IOPL_MSG "denied use of iopl() by "
73997+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
73998+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
73999+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74000+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74001+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74002+#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"
74003+#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"
74004+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74005+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74006+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74007+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74008+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74009+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74010+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74011+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74012+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74013+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74014+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74015+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74016+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74017+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74018+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74019+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74020+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74021+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74022+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74023+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74024+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74025+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74026+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74027+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74028+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74029+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74030+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74031+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74032+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74033+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74034+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74035+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74036+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74037+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74038+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74039+#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"
74040+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74041+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74042+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74043+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74044+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74045+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74046+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74047+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74048+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74049+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74050+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74051+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74052+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74053+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74054+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74055+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74056+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74057+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74058+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74059+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74060+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74061+#define GR_NICE_CHROOT_MSG "denied priority change by "
74062+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74063+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74064+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74065+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74066+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74067+#define GR_TIME_MSG "time set by "
74068+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74069+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74070+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74071+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74072+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74073+#define GR_BIND_MSG "denied bind() by "
74074+#define GR_CONNECT_MSG "denied connect() by "
74075+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74076+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74077+#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"
74078+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74079+#define GR_CAP_ACL_MSG "use of %s denied for "
74080+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74081+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74082+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74083+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74084+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74085+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74086+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74087+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74088+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74089+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74090+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74091+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74092+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74093+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74094+#define GR_VM86_MSG "denied use of vm86 by "
74095+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74096+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74097+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74098+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74099+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74100+#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 "
74101+#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 "
74102diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74103new file mode 100644
74104index 0000000..d6f5a21
74105--- /dev/null
74106+++ b/include/linux/grsecurity.h
74107@@ -0,0 +1,244 @@
74108+#ifndef GR_SECURITY_H
74109+#define GR_SECURITY_H
74110+#include <linux/fs.h>
74111+#include <linux/fs_struct.h>
74112+#include <linux/binfmts.h>
74113+#include <linux/gracl.h>
74114+
74115+/* notify of brain-dead configs */
74116+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74117+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74118+#endif
74119+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74120+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74121+#endif
74122+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74123+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74124+#endif
74125+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74126+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74127+#endif
74128+
74129+int gr_handle_new_usb(void);
74130+
74131+void gr_handle_brute_attach(unsigned long mm_flags);
74132+void gr_handle_brute_check(void);
74133+void gr_handle_kernel_exploit(void);
74134+
74135+char gr_roletype_to_char(void);
74136+
74137+int gr_acl_enable_at_secure(void);
74138+
74139+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74140+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74141+
74142+void gr_del_task_from_ip_table(struct task_struct *p);
74143+
74144+int gr_pid_is_chrooted(struct task_struct *p);
74145+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74146+int gr_handle_chroot_nice(void);
74147+int gr_handle_chroot_sysctl(const int op);
74148+int gr_handle_chroot_setpriority(struct task_struct *p,
74149+ const int niceval);
74150+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74151+int gr_handle_chroot_chroot(const struct dentry *dentry,
74152+ const struct vfsmount *mnt);
74153+void gr_handle_chroot_chdir(const struct path *path);
74154+int gr_handle_chroot_chmod(const struct dentry *dentry,
74155+ const struct vfsmount *mnt, const int mode);
74156+int gr_handle_chroot_mknod(const struct dentry *dentry,
74157+ const struct vfsmount *mnt, const int mode);
74158+int gr_handle_chroot_mount(const struct dentry *dentry,
74159+ const struct vfsmount *mnt,
74160+ const char *dev_name);
74161+int gr_handle_chroot_pivot(void);
74162+int gr_handle_chroot_unix(const pid_t pid);
74163+
74164+int gr_handle_rawio(const struct inode *inode);
74165+
74166+void gr_handle_ioperm(void);
74167+void gr_handle_iopl(void);
74168+
74169+umode_t gr_acl_umask(void);
74170+
74171+int gr_tpe_allow(const struct file *file);
74172+
74173+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74174+void gr_clear_chroot_entries(struct task_struct *task);
74175+
74176+void gr_log_forkfail(const int retval);
74177+void gr_log_timechange(void);
74178+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74179+void gr_log_chdir(const struct dentry *dentry,
74180+ const struct vfsmount *mnt);
74181+void gr_log_chroot_exec(const struct dentry *dentry,
74182+ const struct vfsmount *mnt);
74183+void gr_log_remount(const char *devname, const int retval);
74184+void gr_log_unmount(const char *devname, const int retval);
74185+void gr_log_mount(const char *from, const char *to, const int retval);
74186+void gr_log_textrel(struct vm_area_struct *vma);
74187+void gr_log_ptgnustack(struct file *file);
74188+void gr_log_rwxmmap(struct file *file);
74189+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74190+
74191+int gr_handle_follow_link(const struct inode *parent,
74192+ const struct inode *inode,
74193+ const struct dentry *dentry,
74194+ const struct vfsmount *mnt);
74195+int gr_handle_fifo(const struct dentry *dentry,
74196+ const struct vfsmount *mnt,
74197+ const struct dentry *dir, const int flag,
74198+ const int acc_mode);
74199+int gr_handle_hardlink(const struct dentry *dentry,
74200+ const struct vfsmount *mnt,
74201+ struct inode *inode,
74202+ const int mode, const struct filename *to);
74203+
74204+int gr_is_capable(const int cap);
74205+int gr_is_capable_nolog(const int cap);
74206+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74207+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74208+
74209+void gr_copy_label(struct task_struct *tsk);
74210+void gr_handle_crash(struct task_struct *task, const int sig);
74211+int gr_handle_signal(const struct task_struct *p, const int sig);
74212+int gr_check_crash_uid(const kuid_t uid);
74213+int gr_check_protected_task(const struct task_struct *task);
74214+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74215+int gr_acl_handle_mmap(const struct file *file,
74216+ const unsigned long prot);
74217+int gr_acl_handle_mprotect(const struct file *file,
74218+ const unsigned long prot);
74219+int gr_check_hidden_task(const struct task_struct *tsk);
74220+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74221+ const struct vfsmount *mnt);
74222+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74223+ const struct vfsmount *mnt);
74224+__u32 gr_acl_handle_access(const struct dentry *dentry,
74225+ const struct vfsmount *mnt, const int fmode);
74226+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74227+ const struct vfsmount *mnt, umode_t *mode);
74228+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74229+ const struct vfsmount *mnt);
74230+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74231+ const struct vfsmount *mnt);
74232+int gr_handle_ptrace(struct task_struct *task, const long request);
74233+int gr_handle_proc_ptrace(struct task_struct *task);
74234+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74235+ const struct vfsmount *mnt);
74236+int gr_check_crash_exec(const struct file *filp);
74237+int gr_acl_is_enabled(void);
74238+void gr_set_kernel_label(struct task_struct *task);
74239+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74240+ const kgid_t gid);
74241+int gr_set_proc_label(const struct dentry *dentry,
74242+ const struct vfsmount *mnt,
74243+ const int unsafe_flags);
74244+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74245+ const struct vfsmount *mnt);
74246+__u32 gr_acl_handle_open(const struct dentry *dentry,
74247+ const struct vfsmount *mnt, int acc_mode);
74248+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74249+ const struct dentry *p_dentry,
74250+ const struct vfsmount *p_mnt,
74251+ int open_flags, int acc_mode, const int imode);
74252+void gr_handle_create(const struct dentry *dentry,
74253+ const struct vfsmount *mnt);
74254+void gr_handle_proc_create(const struct dentry *dentry,
74255+ const struct inode *inode);
74256+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74257+ const struct dentry *parent_dentry,
74258+ const struct vfsmount *parent_mnt,
74259+ const int mode);
74260+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74261+ const struct dentry *parent_dentry,
74262+ const struct vfsmount *parent_mnt);
74263+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74264+ const struct vfsmount *mnt);
74265+void gr_handle_delete(const ino_t ino, const dev_t dev);
74266+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74267+ const struct vfsmount *mnt);
74268+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74269+ const struct dentry *parent_dentry,
74270+ const struct vfsmount *parent_mnt,
74271+ const struct filename *from);
74272+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74273+ const struct dentry *parent_dentry,
74274+ const struct vfsmount *parent_mnt,
74275+ const struct dentry *old_dentry,
74276+ const struct vfsmount *old_mnt, const struct filename *to);
74277+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74278+int gr_acl_handle_rename(struct dentry *new_dentry,
74279+ struct dentry *parent_dentry,
74280+ const struct vfsmount *parent_mnt,
74281+ struct dentry *old_dentry,
74282+ struct inode *old_parent_inode,
74283+ struct vfsmount *old_mnt, const struct filename *newname);
74284+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74285+ struct dentry *old_dentry,
74286+ struct dentry *new_dentry,
74287+ struct vfsmount *mnt, const __u8 replace);
74288+__u32 gr_check_link(const struct dentry *new_dentry,
74289+ const struct dentry *parent_dentry,
74290+ const struct vfsmount *parent_mnt,
74291+ const struct dentry *old_dentry,
74292+ const struct vfsmount *old_mnt);
74293+int gr_acl_handle_filldir(const struct file *file, const char *name,
74294+ const unsigned int namelen, const ino_t ino);
74295+
74296+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74297+ const struct vfsmount *mnt);
74298+void gr_acl_handle_exit(void);
74299+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74300+int gr_acl_handle_procpidmem(const struct task_struct *task);
74301+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74302+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74303+void gr_audit_ptrace(struct task_struct *task);
74304+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74305+void gr_put_exec_file(struct task_struct *task);
74306+
74307+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74308+
74309+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74310+extern void gr_learn_resource(const struct task_struct *task, const int res,
74311+ const unsigned long wanted, const int gt);
74312+#else
74313+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74314+ const unsigned long wanted, const int gt)
74315+{
74316+}
74317+#endif
74318+
74319+#ifdef CONFIG_GRKERNSEC_RESLOG
74320+extern void gr_log_resource(const struct task_struct *task, const int res,
74321+ const unsigned long wanted, const int gt);
74322+#else
74323+static inline void gr_log_resource(const struct task_struct *task, const int res,
74324+ const unsigned long wanted, const int gt)
74325+{
74326+}
74327+#endif
74328+
74329+#ifdef CONFIG_GRKERNSEC
74330+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74331+void gr_handle_vm86(void);
74332+void gr_handle_mem_readwrite(u64 from, u64 to);
74333+
74334+void gr_log_badprocpid(const char *entry);
74335+
74336+extern int grsec_enable_dmesg;
74337+extern int grsec_disable_privio;
74338+
74339+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74340+extern kgid_t grsec_proc_gid;
74341+#endif
74342+
74343+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74344+extern int grsec_enable_chroot_findtask;
74345+#endif
74346+#ifdef CONFIG_GRKERNSEC_SETXID
74347+extern int grsec_enable_setxid;
74348+#endif
74349+#endif
74350+
74351+#endif
74352diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74353new file mode 100644
74354index 0000000..e7ffaaf
74355--- /dev/null
74356+++ b/include/linux/grsock.h
74357@@ -0,0 +1,19 @@
74358+#ifndef __GRSOCK_H
74359+#define __GRSOCK_H
74360+
74361+extern void gr_attach_curr_ip(const struct sock *sk);
74362+extern int gr_handle_sock_all(const int family, const int type,
74363+ const int protocol);
74364+extern int gr_handle_sock_server(const struct sockaddr *sck);
74365+extern int gr_handle_sock_server_other(const struct sock *sck);
74366+extern int gr_handle_sock_client(const struct sockaddr *sck);
74367+extern int gr_search_connect(struct socket * sock,
74368+ struct sockaddr_in * addr);
74369+extern int gr_search_bind(struct socket * sock,
74370+ struct sockaddr_in * addr);
74371+extern int gr_search_listen(struct socket * sock);
74372+extern int gr_search_accept(struct socket * sock);
74373+extern int gr_search_socket(const int domain, const int type,
74374+ const int protocol);
74375+
74376+#endif
74377diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74378index 7fb31da..08b5114 100644
74379--- a/include/linux/highmem.h
74380+++ b/include/linux/highmem.h
74381@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74382 kunmap_atomic(kaddr);
74383 }
74384
74385+static inline void sanitize_highpage(struct page *page)
74386+{
74387+ void *kaddr;
74388+ unsigned long flags;
74389+
74390+ local_irq_save(flags);
74391+ kaddr = kmap_atomic(page);
74392+ clear_page(kaddr);
74393+ kunmap_atomic(kaddr);
74394+ local_irq_restore(flags);
74395+}
74396+
74397 static inline void zero_user_segments(struct page *page,
74398 unsigned start1, unsigned end1,
74399 unsigned start2, unsigned end2)
74400diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74401index 1c7b89a..7f52502 100644
74402--- a/include/linux/hwmon-sysfs.h
74403+++ b/include/linux/hwmon-sysfs.h
74404@@ -25,7 +25,8 @@
74405 struct sensor_device_attribute{
74406 struct device_attribute dev_attr;
74407 int index;
74408-};
74409+} __do_const;
74410+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74411 #define to_sensor_dev_attr(_dev_attr) \
74412 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74413
74414@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74415 struct device_attribute dev_attr;
74416 u8 index;
74417 u8 nr;
74418-};
74419+} __do_const;
74420 #define to_sensor_dev_attr_2(_dev_attr) \
74421 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74422
74423diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74424index e988fa9..ff9f17e 100644
74425--- a/include/linux/i2c.h
74426+++ b/include/linux/i2c.h
74427@@ -366,6 +366,7 @@ struct i2c_algorithm {
74428 /* To determine what the adapter supports */
74429 u32 (*functionality) (struct i2c_adapter *);
74430 };
74431+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74432
74433 /**
74434 * struct i2c_bus_recovery_info - I2C bus recovery information
74435diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74436index d23c3c2..eb63c81 100644
74437--- a/include/linux/i2o.h
74438+++ b/include/linux/i2o.h
74439@@ -565,7 +565,7 @@ struct i2o_controller {
74440 struct i2o_device *exec; /* Executive */
74441 #if BITS_PER_LONG == 64
74442 spinlock_t context_list_lock; /* lock for context_list */
74443- atomic_t context_list_counter; /* needed for unique contexts */
74444+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74445 struct list_head context_list; /* list of context id's
74446 and pointers */
74447 #endif
74448diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74449index aff7ad8..3942bbd 100644
74450--- a/include/linux/if_pppox.h
74451+++ b/include/linux/if_pppox.h
74452@@ -76,7 +76,7 @@ struct pppox_proto {
74453 int (*ioctl)(struct socket *sock, unsigned int cmd,
74454 unsigned long arg);
74455 struct module *owner;
74456-};
74457+} __do_const;
74458
74459 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74460 extern void unregister_pppox_proto(int proto_num);
74461diff --git a/include/linux/init.h b/include/linux/init.h
74462index e73f2b7..cc996e0 100644
74463--- a/include/linux/init.h
74464+++ b/include/linux/init.h
74465@@ -39,9 +39,17 @@
74466 * Also note, that this data cannot be "const".
74467 */
74468
74469+#define add_init_latent_entropy __latent_entropy
74470+
74471+#ifdef CONFIG_MEMORY_HOTPLUG
74472+#define add_meminit_latent_entropy
74473+#else
74474+#define add_meminit_latent_entropy __latent_entropy
74475+#endif
74476+
74477 /* These are for everybody (although not all archs will actually
74478 discard it in modules) */
74479-#define __init __section(.init.text) __cold notrace
74480+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74481 #define __initdata __section(.init.data)
74482 #define __initconst __constsection(.init.rodata)
74483 #define __exitdata __section(.exit.data)
74484@@ -102,7 +110,7 @@
74485 #define __cpuexitconst
74486
74487 /* Used for MEMORY_HOTPLUG */
74488-#define __meminit __section(.meminit.text) __cold notrace
74489+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74490 #define __meminitdata __section(.meminit.data)
74491 #define __meminitconst __constsection(.meminit.rodata)
74492 #define __memexit __section(.memexit.text) __exitused __cold notrace
74493diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74494index 5cd0f09..c9f67cc 100644
74495--- a/include/linux/init_task.h
74496+++ b/include/linux/init_task.h
74497@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74498
74499 #define INIT_TASK_COMM "swapper"
74500
74501+#ifdef CONFIG_X86
74502+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74503+#else
74504+#define INIT_TASK_THREAD_INFO
74505+#endif
74506+
74507 /*
74508 * INIT_TASK is used to set up the first task table, touch at
74509 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74510@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74511 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74512 .comm = INIT_TASK_COMM, \
74513 .thread = INIT_THREAD, \
74514+ INIT_TASK_THREAD_INFO \
74515 .fs = &init_fs, \
74516 .files = &init_files, \
74517 .signal = &init_signals, \
74518diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74519index 5fa5afe..ac55b25 100644
74520--- a/include/linux/interrupt.h
74521+++ b/include/linux/interrupt.h
74522@@ -430,7 +430,7 @@ enum
74523 /* map softirq index to softirq name. update 'softirq_to_name' in
74524 * kernel/softirq.c when adding a new softirq.
74525 */
74526-extern char *softirq_to_name[NR_SOFTIRQS];
74527+extern const char * const softirq_to_name[NR_SOFTIRQS];
74528
74529 /* softirq mask and active fields moved to irq_cpustat_t in
74530 * asm/hardirq.h to get better cache usage. KAO
74531@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74532
74533 struct softirq_action
74534 {
74535- void (*action)(struct softirq_action *);
74536-};
74537+ void (*action)(void);
74538+} __no_const;
74539
74540 asmlinkage void do_softirq(void);
74541 asmlinkage void __do_softirq(void);
74542-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74543+extern void open_softirq(int nr, void (*action)(void));
74544 extern void softirq_init(void);
74545 extern void __raise_softirq_irqoff(unsigned int nr);
74546
74547diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74548index 3aeb730..2177f39 100644
74549--- a/include/linux/iommu.h
74550+++ b/include/linux/iommu.h
74551@@ -113,7 +113,7 @@ struct iommu_ops {
74552 u32 (*domain_get_windows)(struct iommu_domain *domain);
74553
74554 unsigned long pgsize_bitmap;
74555-};
74556+} __do_const;
74557
74558 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74559 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74560diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74561index 89b7c24..382af74 100644
74562--- a/include/linux/ioport.h
74563+++ b/include/linux/ioport.h
74564@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74565 int adjust_resource(struct resource *res, resource_size_t start,
74566 resource_size_t size);
74567 resource_size_t resource_alignment(struct resource *res);
74568-static inline resource_size_t resource_size(const struct resource *res)
74569+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74570 {
74571 return res->end - res->start + 1;
74572 }
74573diff --git a/include/linux/irq.h b/include/linux/irq.h
74574index f04d3ba..bcf2cfb 100644
74575--- a/include/linux/irq.h
74576+++ b/include/linux/irq.h
74577@@ -333,7 +333,8 @@ struct irq_chip {
74578 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74579
74580 unsigned long flags;
74581-};
74582+} __do_const;
74583+typedef struct irq_chip __no_const irq_chip_no_const;
74584
74585 /*
74586 * irq_chip specific flags
74587diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74588index 3e203eb..3fe68d0 100644
74589--- a/include/linux/irqchip/arm-gic.h
74590+++ b/include/linux/irqchip/arm-gic.h
74591@@ -59,9 +59,11 @@
74592
74593 #ifndef __ASSEMBLY__
74594
74595+#include <linux/irq.h>
74596+
74597 struct device_node;
74598
74599-extern struct irq_chip gic_arch_extn;
74600+extern irq_chip_no_const gic_arch_extn;
74601
74602 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74603 u32 offset, struct device_node *);
74604diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74605index 6883e19..e854fcb 100644
74606--- a/include/linux/kallsyms.h
74607+++ b/include/linux/kallsyms.h
74608@@ -15,7 +15,8 @@
74609
74610 struct module;
74611
74612-#ifdef CONFIG_KALLSYMS
74613+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74614+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74615 /* Lookup the address for a symbol. Returns 0 if not found. */
74616 unsigned long kallsyms_lookup_name(const char *name);
74617
74618@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74619 /* Stupid that this does nothing, but I didn't create this mess. */
74620 #define __print_symbol(fmt, addr)
74621 #endif /*CONFIG_KALLSYMS*/
74622+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74623+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74624+extern unsigned long kallsyms_lookup_name(const char *name);
74625+extern void __print_symbol(const char *fmt, unsigned long address);
74626+extern int sprint_backtrace(char *buffer, unsigned long address);
74627+extern int sprint_symbol(char *buffer, unsigned long address);
74628+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74629+const char *kallsyms_lookup(unsigned long addr,
74630+ unsigned long *symbolsize,
74631+ unsigned long *offset,
74632+ char **modname, char *namebuf);
74633+extern int kallsyms_lookup_size_offset(unsigned long addr,
74634+ unsigned long *symbolsize,
74635+ unsigned long *offset);
74636+#endif
74637
74638 /* This macro allows us to keep printk typechecking */
74639 static __printf(1, 2)
74640diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74641index 518a53a..5e28358 100644
74642--- a/include/linux/key-type.h
74643+++ b/include/linux/key-type.h
74644@@ -125,7 +125,7 @@ struct key_type {
74645 /* internal fields */
74646 struct list_head link; /* link in types list */
74647 struct lock_class_key lock_class; /* key->sem lock class */
74648-};
74649+} __do_const;
74650
74651 extern struct key_type key_type_keyring;
74652
74653diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74654index c6e091b..a940adf 100644
74655--- a/include/linux/kgdb.h
74656+++ b/include/linux/kgdb.h
74657@@ -52,7 +52,7 @@ extern int kgdb_connected;
74658 extern int kgdb_io_module_registered;
74659
74660 extern atomic_t kgdb_setting_breakpoint;
74661-extern atomic_t kgdb_cpu_doing_single_step;
74662+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74663
74664 extern struct task_struct *kgdb_usethread;
74665 extern struct task_struct *kgdb_contthread;
74666@@ -254,7 +254,7 @@ struct kgdb_arch {
74667 void (*correct_hw_break)(void);
74668
74669 void (*enable_nmi)(bool on);
74670-};
74671+} __do_const;
74672
74673 /**
74674 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74675@@ -279,7 +279,7 @@ struct kgdb_io {
74676 void (*pre_exception) (void);
74677 void (*post_exception) (void);
74678 int is_console;
74679-};
74680+} __do_const;
74681
74682 extern struct kgdb_arch arch_kgdb_ops;
74683
74684diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74685index 0555cc6..b16a7a4 100644
74686--- a/include/linux/kmod.h
74687+++ b/include/linux/kmod.h
74688@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74689 * usually useless though. */
74690 extern __printf(2, 3)
74691 int __request_module(bool wait, const char *name, ...);
74692+extern __printf(3, 4)
74693+int ___request_module(bool wait, char *param_name, const char *name, ...);
74694 #define request_module(mod...) __request_module(true, mod)
74695 #define request_module_nowait(mod...) __request_module(false, mod)
74696 #define try_then_request_module(x, mod...) \
74697diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74698index 939b112..ed6ed51 100644
74699--- a/include/linux/kobject.h
74700+++ b/include/linux/kobject.h
74701@@ -111,7 +111,7 @@ struct kobj_type {
74702 struct attribute **default_attrs;
74703 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74704 const void *(*namespace)(struct kobject *kobj);
74705-};
74706+} __do_const;
74707
74708 struct kobj_uevent_env {
74709 char *envp[UEVENT_NUM_ENVP];
74710@@ -134,6 +134,7 @@ struct kobj_attribute {
74711 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74712 const char *buf, size_t count);
74713 };
74714+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74715
74716 extern const struct sysfs_ops kobj_sysfs_ops;
74717
74718diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74719index f66b065..c2c29b4 100644
74720--- a/include/linux/kobject_ns.h
74721+++ b/include/linux/kobject_ns.h
74722@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74723 const void *(*netlink_ns)(struct sock *sk);
74724 const void *(*initial_ns)(void);
74725 void (*drop_ns)(void *);
74726-};
74727+} __do_const;
74728
74729 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74730 int kobj_ns_type_registered(enum kobj_ns_type type);
74731diff --git a/include/linux/kref.h b/include/linux/kref.h
74732index 484604d..0f6c5b6 100644
74733--- a/include/linux/kref.h
74734+++ b/include/linux/kref.h
74735@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74736 static inline int kref_sub(struct kref *kref, unsigned int count,
74737 void (*release)(struct kref *kref))
74738 {
74739- WARN_ON(release == NULL);
74740+ BUG_ON(release == NULL);
74741
74742 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74743 release(kref);
74744diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74745index a63d83e..77fd685 100644
74746--- a/include/linux/kvm_host.h
74747+++ b/include/linux/kvm_host.h
74748@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74749 {
74750 }
74751 #endif
74752-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74753+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74754 struct module *module);
74755 void kvm_exit(void);
74756
74757@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74758 struct kvm_guest_debug *dbg);
74759 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74760
74761-int kvm_arch_init(void *opaque);
74762+int kvm_arch_init(const void *opaque);
74763 void kvm_arch_exit(void);
74764
74765 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74766diff --git a/include/linux/libata.h b/include/linux/libata.h
74767index 4ea55bb..dcd2601 100644
74768--- a/include/linux/libata.h
74769+++ b/include/linux/libata.h
74770@@ -924,7 +924,7 @@ struct ata_port_operations {
74771 * fields must be pointers.
74772 */
74773 const struct ata_port_operations *inherits;
74774-};
74775+} __do_const;
74776
74777 struct ata_port_info {
74778 unsigned long flags;
74779diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74780index d3e8ad2..a949f68 100644
74781--- a/include/linux/linkage.h
74782+++ b/include/linux/linkage.h
74783@@ -31,6 +31,7 @@
74784 #endif
74785
74786 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74787+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74788 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74789
74790 /*
74791diff --git a/include/linux/list.h b/include/linux/list.h
74792index f4d8a2f..38e6e46 100644
74793--- a/include/linux/list.h
74794+++ b/include/linux/list.h
74795@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74796 extern void list_del(struct list_head *entry);
74797 #endif
74798
74799+extern void __pax_list_add(struct list_head *new,
74800+ struct list_head *prev,
74801+ struct list_head *next);
74802+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74803+{
74804+ __pax_list_add(new, head, head->next);
74805+}
74806+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74807+{
74808+ __pax_list_add(new, head->prev, head);
74809+}
74810+extern void pax_list_del(struct list_head *entry);
74811+
74812 /**
74813 * list_replace - replace old entry by new one
74814 * @old : the element to be replaced
74815@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74816 INIT_LIST_HEAD(entry);
74817 }
74818
74819+extern void pax_list_del_init(struct list_head *entry);
74820+
74821 /**
74822 * list_move - delete from one list and add as another's head
74823 * @list: the entry to move
74824diff --git a/include/linux/math64.h b/include/linux/math64.h
74825index 2913b86..8dcbb1e 100644
74826--- a/include/linux/math64.h
74827+++ b/include/linux/math64.h
74828@@ -15,7 +15,7 @@
74829 * This is commonly provided by 32bit archs to provide an optimized 64bit
74830 * divide.
74831 */
74832-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74833+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74834 {
74835 *remainder = dividend % divisor;
74836 return dividend / divisor;
74837@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74838 /**
74839 * div64_u64 - unsigned 64bit divide with 64bit divisor
74840 */
74841-static inline u64 div64_u64(u64 dividend, u64 divisor)
74842+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74843 {
74844 return dividend / divisor;
74845 }
74846@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74847 #define div64_ul(x, y) div_u64((x), (y))
74848
74849 #ifndef div_u64_rem
74850-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74851+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74852 {
74853 *remainder = do_div(dividend, divisor);
74854 return dividend;
74855@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74856 * divide.
74857 */
74858 #ifndef div_u64
74859-static inline u64 div_u64(u64 dividend, u32 divisor)
74860+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74861 {
74862 u32 remainder;
74863 return div_u64_rem(dividend, divisor, &remainder);
74864diff --git a/include/linux/mm.h b/include/linux/mm.h
74865index f022460..6ecf4f9 100644
74866--- a/include/linux/mm.h
74867+++ b/include/linux/mm.h
74868@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74869 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74870 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74871 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74872+
74873+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74874+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74875+#endif
74876+
74877 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74878
74879 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74880@@ -208,8 +213,8 @@ struct vm_operations_struct {
74881 /* called by access_process_vm when get_user_pages() fails, typically
74882 * for use by special VMAs that can switch between memory and hardware
74883 */
74884- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74885- void *buf, int len, int write);
74886+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74887+ void *buf, size_t len, int write);
74888 #ifdef CONFIG_NUMA
74889 /*
74890 * set_policy() op must add a reference to any non-NULL @new mempolicy
74891@@ -239,6 +244,7 @@ struct vm_operations_struct {
74892 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74893 unsigned long size, pgoff_t pgoff);
74894 };
74895+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74896
74897 struct mmu_gather;
74898 struct inode;
74899@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74900 unsigned long *pfn);
74901 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74902 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74903-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74904- void *buf, int len, int write);
74905+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74906+ void *buf, size_t len, int write);
74907
74908 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74909 loff_t const holebegin, loff_t const holelen)
74910@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74911 }
74912 #endif
74913
74914-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74915-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74916- void *buf, int len, int write);
74917+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74918+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74919+ void *buf, size_t len, int write);
74920
74921 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74922 unsigned long start, unsigned long nr_pages,
74923@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74924 int set_page_dirty_lock(struct page *page);
74925 int clear_page_dirty_for_io(struct page *page);
74926
74927-/* Is the vma a continuation of the stack vma above it? */
74928-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74929-{
74930- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74931-}
74932-
74933-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74934- unsigned long addr)
74935-{
74936- return (vma->vm_flags & VM_GROWSDOWN) &&
74937- (vma->vm_start == addr) &&
74938- !vma_growsdown(vma->vm_prev, addr);
74939-}
74940-
74941-/* Is the vma a continuation of the stack vma below it? */
74942-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74943-{
74944- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
74945-}
74946-
74947-static inline int stack_guard_page_end(struct vm_area_struct *vma,
74948- unsigned long addr)
74949-{
74950- return (vma->vm_flags & VM_GROWSUP) &&
74951- (vma->vm_end == addr) &&
74952- !vma_growsup(vma->vm_next, addr);
74953-}
74954-
74955 extern pid_t
74956 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
74957
74958@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
74959 }
74960 #endif
74961
74962+#ifdef CONFIG_MMU
74963+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
74964+#else
74965+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
74966+{
74967+ return __pgprot(0);
74968+}
74969+#endif
74970+
74971 int vma_wants_writenotify(struct vm_area_struct *vma);
74972
74973 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
74974@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
74975 {
74976 return 0;
74977 }
74978+
74979+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
74980+ unsigned long address)
74981+{
74982+ return 0;
74983+}
74984 #else
74985 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74986+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74987 #endif
74988
74989 #ifdef __PAGETABLE_PMD_FOLDED
74990@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
74991 {
74992 return 0;
74993 }
74994+
74995+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
74996+ unsigned long address)
74997+{
74998+ return 0;
74999+}
75000 #else
75001 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75002+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75003 #endif
75004
75005 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75006@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75007 NULL: pud_offset(pgd, address);
75008 }
75009
75010+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75011+{
75012+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75013+ NULL: pud_offset(pgd, address);
75014+}
75015+
75016 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75017 {
75018 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75019 NULL: pmd_offset(pud, address);
75020 }
75021+
75022+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75023+{
75024+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75025+ NULL: pmd_offset(pud, address);
75026+}
75027 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75028
75029 #if USE_SPLIT_PTLOCKS
75030@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75031 unsigned long len, unsigned long prot, unsigned long flags,
75032 unsigned long pgoff, unsigned long *populate);
75033 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75034+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75035
75036 #ifdef CONFIG_MMU
75037 extern int __mm_populate(unsigned long addr, unsigned long len,
75038@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75039 unsigned long high_limit;
75040 unsigned long align_mask;
75041 unsigned long align_offset;
75042+ unsigned long threadstack_offset;
75043 };
75044
75045-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75046-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75047+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75048+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75049
75050 /*
75051 * Search for an unmapped address range.
75052@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75053 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75054 */
75055 static inline unsigned long
75056-vm_unmapped_area(struct vm_unmapped_area_info *info)
75057+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75058 {
75059 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75060 return unmapped_area(info);
75061@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75062 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75063 struct vm_area_struct **pprev);
75064
75065+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75066+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75067+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75068+
75069 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75070 NULL if none. Assume start_addr < end_addr. */
75071 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75072@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75073 return vma;
75074 }
75075
75076-#ifdef CONFIG_MMU
75077-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75078-#else
75079-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75080-{
75081- return __pgprot(0);
75082-}
75083-#endif
75084-
75085 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75086 unsigned long change_prot_numa(struct vm_area_struct *vma,
75087 unsigned long start, unsigned long end);
75088@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75089 static inline void vm_stat_account(struct mm_struct *mm,
75090 unsigned long flags, struct file *file, long pages)
75091 {
75092+
75093+#ifdef CONFIG_PAX_RANDMMAP
75094+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75095+#endif
75096+
75097 mm->total_vm += pages;
75098 }
75099 #endif /* CONFIG_PROC_FS */
75100@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75101 extern int sysctl_memory_failure_early_kill;
75102 extern int sysctl_memory_failure_recovery;
75103 extern void shake_page(struct page *p, int access);
75104-extern atomic_long_t num_poisoned_pages;
75105+extern atomic_long_unchecked_t num_poisoned_pages;
75106 extern int soft_offline_page(struct page *page, int flags);
75107
75108 extern void dump_page(struct page *page);
75109@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75110 static inline void setup_nr_node_ids(void) {}
75111 #endif
75112
75113+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75114+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75115+#else
75116+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75117+#endif
75118+
75119 #endif /* __KERNEL__ */
75120 #endif /* _LINUX_MM_H */
75121diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75122index faf4b7c..1e70c6e 100644
75123--- a/include/linux/mm_types.h
75124+++ b/include/linux/mm_types.h
75125@@ -289,6 +289,8 @@ struct vm_area_struct {
75126 #ifdef CONFIG_NUMA
75127 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75128 #endif
75129+
75130+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75131 };
75132
75133 struct core_thread {
75134@@ -435,6 +437,24 @@ struct mm_struct {
75135 int first_nid;
75136 #endif
75137 struct uprobes_state uprobes_state;
75138+
75139+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75140+ unsigned long pax_flags;
75141+#endif
75142+
75143+#ifdef CONFIG_PAX_DLRESOLVE
75144+ unsigned long call_dl_resolve;
75145+#endif
75146+
75147+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75148+ unsigned long call_syscall;
75149+#endif
75150+
75151+#ifdef CONFIG_PAX_ASLR
75152+ unsigned long delta_mmap; /* randomized offset */
75153+ unsigned long delta_stack; /* randomized offset */
75154+#endif
75155+
75156 };
75157
75158 /* first nid will either be a valid NID or one of these values */
75159diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75160index c5d5278..f0b68c8 100644
75161--- a/include/linux/mmiotrace.h
75162+++ b/include/linux/mmiotrace.h
75163@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75164 /* Called from ioremap.c */
75165 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75166 void __iomem *addr);
75167-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75168+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75169
75170 /* For anyone to insert markers. Remember trailing newline. */
75171 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75172@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75173 {
75174 }
75175
75176-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75177+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75178 {
75179 }
75180
75181diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75182index af4a3b7..9ad8889 100644
75183--- a/include/linux/mmzone.h
75184+++ b/include/linux/mmzone.h
75185@@ -396,7 +396,7 @@ struct zone {
75186 unsigned long flags; /* zone flags, see below */
75187
75188 /* Zone statistics */
75189- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75190+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75191
75192 /*
75193 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75194diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75195index 45e9214..a7227d6 100644
75196--- a/include/linux/mod_devicetable.h
75197+++ b/include/linux/mod_devicetable.h
75198@@ -13,7 +13,7 @@
75199 typedef unsigned long kernel_ulong_t;
75200 #endif
75201
75202-#define PCI_ANY_ID (~0)
75203+#define PCI_ANY_ID ((__u16)~0)
75204
75205 struct pci_device_id {
75206 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75207@@ -139,7 +139,7 @@ struct usb_device_id {
75208 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75209 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75210
75211-#define HID_ANY_ID (~0)
75212+#define HID_ANY_ID (~0U)
75213 #define HID_BUS_ANY 0xffff
75214 #define HID_GROUP_ANY 0x0000
75215
75216@@ -467,7 +467,7 @@ struct dmi_system_id {
75217 const char *ident;
75218 struct dmi_strmatch matches[4];
75219 void *driver_data;
75220-};
75221+} __do_const;
75222 /*
75223 * struct dmi_device_id appears during expansion of
75224 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75225diff --git a/include/linux/module.h b/include/linux/module.h
75226index 46f1ea0..a34ca37 100644
75227--- a/include/linux/module.h
75228+++ b/include/linux/module.h
75229@@ -17,9 +17,11 @@
75230 #include <linux/moduleparam.h>
75231 #include <linux/tracepoint.h>
75232 #include <linux/export.h>
75233+#include <linux/fs.h>
75234
75235 #include <linux/percpu.h>
75236 #include <asm/module.h>
75237+#include <asm/pgtable.h>
75238
75239 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75240 #define MODULE_SIG_STRING "~Module signature appended~\n"
75241@@ -54,12 +56,13 @@ struct module_attribute {
75242 int (*test)(struct module *);
75243 void (*free)(struct module *);
75244 };
75245+typedef struct module_attribute __no_const module_attribute_no_const;
75246
75247 struct module_version_attribute {
75248 struct module_attribute mattr;
75249 const char *module_name;
75250 const char *version;
75251-} __attribute__ ((__aligned__(sizeof(void *))));
75252+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75253
75254 extern ssize_t __modver_version_show(struct module_attribute *,
75255 struct module_kobject *, char *);
75256@@ -232,7 +235,7 @@ struct module
75257
75258 /* Sysfs stuff. */
75259 struct module_kobject mkobj;
75260- struct module_attribute *modinfo_attrs;
75261+ module_attribute_no_const *modinfo_attrs;
75262 const char *version;
75263 const char *srcversion;
75264 struct kobject *holders_dir;
75265@@ -281,19 +284,16 @@ struct module
75266 int (*init)(void);
75267
75268 /* If this is non-NULL, vfree after init() returns */
75269- void *module_init;
75270+ void *module_init_rx, *module_init_rw;
75271
75272 /* Here is the actual code + data, vfree'd on unload. */
75273- void *module_core;
75274+ void *module_core_rx, *module_core_rw;
75275
75276 /* Here are the sizes of the init and core sections */
75277- unsigned int init_size, core_size;
75278+ unsigned int init_size_rw, core_size_rw;
75279
75280 /* The size of the executable code in each section. */
75281- unsigned int init_text_size, core_text_size;
75282-
75283- /* Size of RO sections of the module (text+rodata) */
75284- unsigned int init_ro_size, core_ro_size;
75285+ unsigned int init_size_rx, core_size_rx;
75286
75287 /* Arch-specific module values */
75288 struct mod_arch_specific arch;
75289@@ -349,6 +349,10 @@ struct module
75290 #ifdef CONFIG_EVENT_TRACING
75291 struct ftrace_event_call **trace_events;
75292 unsigned int num_trace_events;
75293+ struct file_operations trace_id;
75294+ struct file_operations trace_enable;
75295+ struct file_operations trace_format;
75296+ struct file_operations trace_filter;
75297 #endif
75298 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75299 unsigned int num_ftrace_callsites;
75300@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75301 bool is_module_percpu_address(unsigned long addr);
75302 bool is_module_text_address(unsigned long addr);
75303
75304+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75305+{
75306+
75307+#ifdef CONFIG_PAX_KERNEXEC
75308+ if (ktla_ktva(addr) >= (unsigned long)start &&
75309+ ktla_ktva(addr) < (unsigned long)start + size)
75310+ return 1;
75311+#endif
75312+
75313+ return ((void *)addr >= start && (void *)addr < start + size);
75314+}
75315+
75316+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75317+{
75318+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75319+}
75320+
75321+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75322+{
75323+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75324+}
75325+
75326+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75327+{
75328+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75329+}
75330+
75331+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75332+{
75333+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75334+}
75335+
75336 static inline int within_module_core(unsigned long addr, const struct module *mod)
75337 {
75338- return (unsigned long)mod->module_core <= addr &&
75339- addr < (unsigned long)mod->module_core + mod->core_size;
75340+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75341 }
75342
75343 static inline int within_module_init(unsigned long addr, const struct module *mod)
75344 {
75345- return (unsigned long)mod->module_init <= addr &&
75346- addr < (unsigned long)mod->module_init + mod->init_size;
75347+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75348 }
75349
75350 /* Search for module by name: must hold module_mutex. */
75351diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75352index 560ca53..ef621ef 100644
75353--- a/include/linux/moduleloader.h
75354+++ b/include/linux/moduleloader.h
75355@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75356 sections. Returns NULL on failure. */
75357 void *module_alloc(unsigned long size);
75358
75359+#ifdef CONFIG_PAX_KERNEXEC
75360+void *module_alloc_exec(unsigned long size);
75361+#else
75362+#define module_alloc_exec(x) module_alloc(x)
75363+#endif
75364+
75365 /* Free memory returned from module_alloc. */
75366 void module_free(struct module *mod, void *module_region);
75367
75368+#ifdef CONFIG_PAX_KERNEXEC
75369+void module_free_exec(struct module *mod, void *module_region);
75370+#else
75371+#define module_free_exec(x, y) module_free((x), (y))
75372+#endif
75373+
75374 /*
75375 * Apply the given relocation to the (simplified) ELF. Return -error
75376 * or 0.
75377@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75378 unsigned int relsec,
75379 struct module *me)
75380 {
75381+#ifdef CONFIG_MODULES
75382 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75383+#endif
75384 return -ENOEXEC;
75385 }
75386 #endif
75387@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75388 unsigned int relsec,
75389 struct module *me)
75390 {
75391+#ifdef CONFIG_MODULES
75392 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75393+#endif
75394 return -ENOEXEC;
75395 }
75396 #endif
75397diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75398index 27d9da3..5d94aa3 100644
75399--- a/include/linux/moduleparam.h
75400+++ b/include/linux/moduleparam.h
75401@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75402 * @len is usually just sizeof(string).
75403 */
75404 #define module_param_string(name, string, len, perm) \
75405- static const struct kparam_string __param_string_##name \
75406+ static const struct kparam_string __param_string_##name __used \
75407 = { len, string }; \
75408 __module_param_call(MODULE_PARAM_PREFIX, name, \
75409 &param_ops_string, \
75410@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75411 */
75412 #define module_param_array_named(name, array, type, nump, perm) \
75413 param_check_##type(name, &(array)[0]); \
75414- static const struct kparam_array __param_arr_##name \
75415+ static const struct kparam_array __param_arr_##name __used \
75416 = { .max = ARRAY_SIZE(array), .num = nump, \
75417 .ops = &param_ops_##type, \
75418 .elemsize = sizeof(array[0]), .elem = array }; \
75419diff --git a/include/linux/namei.h b/include/linux/namei.h
75420index 5a5ff57..5ae5070 100644
75421--- a/include/linux/namei.h
75422+++ b/include/linux/namei.h
75423@@ -19,7 +19,7 @@ struct nameidata {
75424 unsigned seq;
75425 int last_type;
75426 unsigned depth;
75427- char *saved_names[MAX_NESTED_LINKS + 1];
75428+ const char *saved_names[MAX_NESTED_LINKS + 1];
75429 };
75430
75431 /*
75432@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75433
75434 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75435
75436-static inline void nd_set_link(struct nameidata *nd, char *path)
75437+static inline void nd_set_link(struct nameidata *nd, const char *path)
75438 {
75439 nd->saved_names[nd->depth] = path;
75440 }
75441
75442-static inline char *nd_get_link(struct nameidata *nd)
75443+static inline const char *nd_get_link(const struct nameidata *nd)
75444 {
75445 return nd->saved_names[nd->depth];
75446 }
75447diff --git a/include/linux/net.h b/include/linux/net.h
75448index 4f27575..fc8a65f 100644
75449--- a/include/linux/net.h
75450+++ b/include/linux/net.h
75451@@ -183,7 +183,7 @@ struct net_proto_family {
75452 int (*create)(struct net *net, struct socket *sock,
75453 int protocol, int kern);
75454 struct module *owner;
75455-};
75456+} __do_const;
75457
75458 struct iovec;
75459 struct kvec;
75460diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75461index 9a41568..203d903 100644
75462--- a/include/linux/netdevice.h
75463+++ b/include/linux/netdevice.h
75464@@ -1061,6 +1061,7 @@ struct net_device_ops {
75465 int (*ndo_change_carrier)(struct net_device *dev,
75466 bool new_carrier);
75467 };
75468+typedef struct net_device_ops __no_const net_device_ops_no_const;
75469
75470 /*
75471 * The DEVICE structure.
75472@@ -1131,7 +1132,7 @@ struct net_device {
75473 int iflink;
75474
75475 struct net_device_stats stats;
75476- atomic_long_t rx_dropped; /* dropped packets by core network
75477+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75478 * Do not use this in drivers.
75479 */
75480
75481diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75482index de70f7b..2675e91 100644
75483--- a/include/linux/netfilter.h
75484+++ b/include/linux/netfilter.h
75485@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75486 #endif
75487 /* Use the module struct to lock set/get code in place */
75488 struct module *owner;
75489-};
75490+} __do_const;
75491
75492 /* Function to register/unregister hook points. */
75493 int nf_register_hook(struct nf_hook_ops *reg);
75494diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75495index d80e275..c3510b8 100644
75496--- a/include/linux/netfilter/ipset/ip_set.h
75497+++ b/include/linux/netfilter/ipset/ip_set.h
75498@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75499 /* Return true if "b" set is the same as "a"
75500 * according to the create set parameters */
75501 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75502-};
75503+} __do_const;
75504
75505 /* The core set type structure */
75506 struct ip_set_type {
75507diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75508index cadb740..d7c37c0 100644
75509--- a/include/linux/netfilter/nfnetlink.h
75510+++ b/include/linux/netfilter/nfnetlink.h
75511@@ -16,7 +16,7 @@ struct nfnl_callback {
75512 const struct nlattr * const cda[]);
75513 const struct nla_policy *policy; /* netlink attribute policy */
75514 const u_int16_t attr_count; /* number of nlattr's */
75515-};
75516+} __do_const;
75517
75518 struct nfnetlink_subsystem {
75519 const char *name;
75520diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75521new file mode 100644
75522index 0000000..33f4af8
75523--- /dev/null
75524+++ b/include/linux/netfilter/xt_gradm.h
75525@@ -0,0 +1,9 @@
75526+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75527+#define _LINUX_NETFILTER_XT_GRADM_H 1
75528+
75529+struct xt_gradm_mtinfo {
75530+ __u16 flags;
75531+ __u16 invflags;
75532+};
75533+
75534+#endif
75535diff --git a/include/linux/nls.h b/include/linux/nls.h
75536index 5dc635f..35f5e11 100644
75537--- a/include/linux/nls.h
75538+++ b/include/linux/nls.h
75539@@ -31,7 +31,7 @@ struct nls_table {
75540 const unsigned char *charset2upper;
75541 struct module *owner;
75542 struct nls_table *next;
75543-};
75544+} __do_const;
75545
75546 /* this value hold the maximum octet of charset */
75547 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75548diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75549index d14a4c3..a078786 100644
75550--- a/include/linux/notifier.h
75551+++ b/include/linux/notifier.h
75552@@ -54,7 +54,8 @@ struct notifier_block {
75553 notifier_fn_t notifier_call;
75554 struct notifier_block __rcu *next;
75555 int priority;
75556-};
75557+} __do_const;
75558+typedef struct notifier_block __no_const notifier_block_no_const;
75559
75560 struct atomic_notifier_head {
75561 spinlock_t lock;
75562diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75563index a4c5624..79d6d88 100644
75564--- a/include/linux/oprofile.h
75565+++ b/include/linux/oprofile.h
75566@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75567 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75568 char const * name, ulong * val);
75569
75570-/** Create a file for read-only access to an atomic_t. */
75571+/** Create a file for read-only access to an atomic_unchecked_t. */
75572 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75573- char const * name, atomic_t * val);
75574+ char const * name, atomic_unchecked_t * val);
75575
75576 /** create a directory */
75577 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75578diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75579index 8db71dc..a76bf2c 100644
75580--- a/include/linux/pci_hotplug.h
75581+++ b/include/linux/pci_hotplug.h
75582@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75583 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75584 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75585 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75586-};
75587+} __do_const;
75588+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75589
75590 /**
75591 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75592diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75593index c43f6ea..2d4416f 100644
75594--- a/include/linux/perf_event.h
75595+++ b/include/linux/perf_event.h
75596@@ -328,8 +328,8 @@ struct perf_event {
75597
75598 enum perf_event_active_state state;
75599 unsigned int attach_state;
75600- local64_t count;
75601- atomic64_t child_count;
75602+ local64_t count; /* PaX: fix it one day */
75603+ atomic64_unchecked_t child_count;
75604
75605 /*
75606 * These are the total time in nanoseconds that the event
75607@@ -380,8 +380,8 @@ struct perf_event {
75608 * These accumulate total time (in nanoseconds) that children
75609 * events have been enabled and running, respectively.
75610 */
75611- atomic64_t child_total_time_enabled;
75612- atomic64_t child_total_time_running;
75613+ atomic64_unchecked_t child_total_time_enabled;
75614+ atomic64_unchecked_t child_total_time_running;
75615
75616 /*
75617 * Protect attach/detach and child_list:
75618@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75619 entry->ip[entry->nr++] = ip;
75620 }
75621
75622-extern int sysctl_perf_event_paranoid;
75623+extern int sysctl_perf_event_legitimately_concerned;
75624 extern int sysctl_perf_event_mlock;
75625 extern int sysctl_perf_event_sample_rate;
75626 extern int sysctl_perf_cpu_time_max_percent;
75627@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75628 loff_t *ppos);
75629
75630
75631+static inline bool perf_paranoid_any(void)
75632+{
75633+ return sysctl_perf_event_legitimately_concerned > 2;
75634+}
75635+
75636 static inline bool perf_paranoid_tracepoint_raw(void)
75637 {
75638- return sysctl_perf_event_paranoid > -1;
75639+ return sysctl_perf_event_legitimately_concerned > -1;
75640 }
75641
75642 static inline bool perf_paranoid_cpu(void)
75643 {
75644- return sysctl_perf_event_paranoid > 0;
75645+ return sysctl_perf_event_legitimately_concerned > 0;
75646 }
75647
75648 static inline bool perf_paranoid_kernel(void)
75649 {
75650- return sysctl_perf_event_paranoid > 1;
75651+ return sysctl_perf_event_legitimately_concerned > 1;
75652 }
75653
75654 extern void perf_event_init(void);
75655@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75656 struct device_attribute attr;
75657 u64 id;
75658 const char *event_str;
75659-};
75660+} __do_const;
75661
75662 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75663 static struct perf_pmu_events_attr _var = { \
75664diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75665index b8809fe..ae4ccd0 100644
75666--- a/include/linux/pipe_fs_i.h
75667+++ b/include/linux/pipe_fs_i.h
75668@@ -47,10 +47,10 @@ struct pipe_inode_info {
75669 struct mutex mutex;
75670 wait_queue_head_t wait;
75671 unsigned int nrbufs, curbuf, buffers;
75672- unsigned int readers;
75673- unsigned int writers;
75674- unsigned int files;
75675- unsigned int waiting_writers;
75676+ atomic_t readers;
75677+ atomic_t writers;
75678+ atomic_t files;
75679+ atomic_t waiting_writers;
75680 unsigned int r_counter;
75681 unsigned int w_counter;
75682 struct page *tmp_page;
75683diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75684index 5f28cae..3d23723 100644
75685--- a/include/linux/platform_data/usb-ehci-s5p.h
75686+++ b/include/linux/platform_data/usb-ehci-s5p.h
75687@@ -14,7 +14,7 @@
75688 struct s5p_ehci_platdata {
75689 int (*phy_init)(struct platform_device *pdev, int type);
75690 int (*phy_exit)(struct platform_device *pdev, int type);
75691-};
75692+} __no_const;
75693
75694 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75695
75696diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75697index c256c59..8ea94c7 100644
75698--- a/include/linux/platform_data/usb-ohci-exynos.h
75699+++ b/include/linux/platform_data/usb-ohci-exynos.h
75700@@ -14,7 +14,7 @@
75701 struct exynos4_ohci_platdata {
75702 int (*phy_init)(struct platform_device *pdev, int type);
75703 int (*phy_exit)(struct platform_device *pdev, int type);
75704-};
75705+} __no_const;
75706
75707 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75708
75709diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75710index 7c1d252..c5c773e 100644
75711--- a/include/linux/pm_domain.h
75712+++ b/include/linux/pm_domain.h
75713@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75714
75715 struct gpd_cpu_data {
75716 unsigned int saved_exit_latency;
75717- struct cpuidle_state *idle_state;
75718+ cpuidle_state_no_const *idle_state;
75719 };
75720
75721 struct generic_pm_domain {
75722diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75723index 6fa7cea..7bf6415 100644
75724--- a/include/linux/pm_runtime.h
75725+++ b/include/linux/pm_runtime.h
75726@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75727
75728 static inline void pm_runtime_mark_last_busy(struct device *dev)
75729 {
75730- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75731+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75732 }
75733
75734 #else /* !CONFIG_PM_RUNTIME */
75735diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75736index 195aafc..49a7bc2 100644
75737--- a/include/linux/pnp.h
75738+++ b/include/linux/pnp.h
75739@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75740 struct pnp_fixup {
75741 char id[7];
75742 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75743-};
75744+} __do_const;
75745
75746 /* config parameters */
75747 #define PNP_CONFIG_NORMAL 0x0001
75748diff --git a/include/linux/poison.h b/include/linux/poison.h
75749index 2110a81..13a11bb 100644
75750--- a/include/linux/poison.h
75751+++ b/include/linux/poison.h
75752@@ -19,8 +19,8 @@
75753 * under normal circumstances, used to verify that nobody uses
75754 * non-initialized list entries.
75755 */
75756-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75757-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75758+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75759+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75760
75761 /********** include/linux/timer.h **********/
75762 /*
75763diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75764index d8b187c3..9a9257a 100644
75765--- a/include/linux/power/smartreflex.h
75766+++ b/include/linux/power/smartreflex.h
75767@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75768 int (*notify)(struct omap_sr *sr, u32 status);
75769 u8 notify_flags;
75770 u8 class_type;
75771-};
75772+} __do_const;
75773
75774 /**
75775 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75776diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75777index 4ea1d37..80f4b33 100644
75778--- a/include/linux/ppp-comp.h
75779+++ b/include/linux/ppp-comp.h
75780@@ -84,7 +84,7 @@ struct compressor {
75781 struct module *owner;
75782 /* Extra skb space needed by the compressor algorithm */
75783 unsigned int comp_extra;
75784-};
75785+} __do_const;
75786
75787 /*
75788 * The return value from decompress routine is the length of the
75789diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75790index f5d4723..a6ea2fa 100644
75791--- a/include/linux/preempt.h
75792+++ b/include/linux/preempt.h
75793@@ -18,8 +18,13 @@
75794 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75795 #endif
75796
75797+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75798+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75799+
75800 #define inc_preempt_count() add_preempt_count(1)
75801+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75802 #define dec_preempt_count() sub_preempt_count(1)
75803+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75804
75805 #define preempt_count() (current_thread_info()->preempt_count)
75806
75807@@ -64,6 +69,12 @@ do { \
75808 barrier(); \
75809 } while (0)
75810
75811+#define raw_preempt_disable() \
75812+do { \
75813+ raw_inc_preempt_count(); \
75814+ barrier(); \
75815+} while (0)
75816+
75817 #define sched_preempt_enable_no_resched() \
75818 do { \
75819 barrier(); \
75820@@ -72,6 +83,12 @@ do { \
75821
75822 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75823
75824+#define raw_preempt_enable_no_resched() \
75825+do { \
75826+ barrier(); \
75827+ raw_dec_preempt_count(); \
75828+} while (0)
75829+
75830 #define preempt_enable() \
75831 do { \
75832 preempt_enable_no_resched(); \
75833@@ -116,8 +133,10 @@ do { \
75834 * region.
75835 */
75836 #define preempt_disable() barrier()
75837+#define raw_preempt_disable() barrier()
75838 #define sched_preempt_enable_no_resched() barrier()
75839 #define preempt_enable_no_resched() barrier()
75840+#define raw_preempt_enable_no_resched() barrier()
75841 #define preempt_enable() barrier()
75842
75843 #define preempt_disable_notrace() barrier()
75844diff --git a/include/linux/printk.h b/include/linux/printk.h
75845index 22c7052..ad3fa0a 100644
75846--- a/include/linux/printk.h
75847+++ b/include/linux/printk.h
75848@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75849 void early_printk(const char *s, ...) { }
75850 #endif
75851
75852+extern int kptr_restrict;
75853+
75854 #ifdef CONFIG_PRINTK
75855 asmlinkage __printf(5, 0)
75856 int vprintk_emit(int facility, int level,
75857@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75858
75859 extern int printk_delay_msec;
75860 extern int dmesg_restrict;
75861-extern int kptr_restrict;
75862
75863 extern void wake_up_klogd(void);
75864
75865diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75866index 608e60a..c26f864 100644
75867--- a/include/linux/proc_fs.h
75868+++ b/include/linux/proc_fs.h
75869@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75870 return proc_create_data(name, mode, parent, proc_fops, NULL);
75871 }
75872
75873+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75874+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75875+{
75876+#ifdef CONFIG_GRKERNSEC_PROC_USER
75877+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75878+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75879+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75880+#else
75881+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75882+#endif
75883+}
75884+
75885+
75886 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75887 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75888 extern void *PDE_DATA(const struct inode *);
75889diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75890index 34a1e10..03a6d03 100644
75891--- a/include/linux/proc_ns.h
75892+++ b/include/linux/proc_ns.h
75893@@ -14,7 +14,7 @@ struct proc_ns_operations {
75894 void (*put)(void *ns);
75895 int (*install)(struct nsproxy *nsproxy, void *ns);
75896 unsigned int (*inum)(void *ns);
75897-};
75898+} __do_const;
75899
75900 struct proc_ns {
75901 void *ns;
75902diff --git a/include/linux/random.h b/include/linux/random.h
75903index 6312dd9..2561947 100644
75904--- a/include/linux/random.h
75905+++ b/include/linux/random.h
75906@@ -10,9 +10,19 @@
75907
75908
75909 extern void add_device_randomness(const void *, unsigned int);
75910+
75911+static inline void add_latent_entropy(void)
75912+{
75913+
75914+#ifdef LATENT_ENTROPY_PLUGIN
75915+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75916+#endif
75917+
75918+}
75919+
75920 extern void add_input_randomness(unsigned int type, unsigned int code,
75921- unsigned int value);
75922-extern void add_interrupt_randomness(int irq, int irq_flags);
75923+ unsigned int value) __latent_entropy;
75924+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75925
75926 extern void get_random_bytes(void *buf, int nbytes);
75927 extern void get_random_bytes_arch(void *buf, int nbytes);
75928@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
75929 u32 prandom_u32_state(struct rnd_state *);
75930 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75931
75932+static inline unsigned long pax_get_random_long(void)
75933+{
75934+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75935+}
75936+
75937 /*
75938 * Handle minimum values for seeds
75939 */
75940diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75941index 4106721..132d42c 100644
75942--- a/include/linux/rculist.h
75943+++ b/include/linux/rculist.h
75944@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
75945 struct list_head *prev, struct list_head *next);
75946 #endif
75947
75948+extern void __pax_list_add_rcu(struct list_head *new,
75949+ struct list_head *prev, struct list_head *next);
75950+
75951 /**
75952 * list_add_rcu - add a new entry to rcu-protected list
75953 * @new: new entry to be added
75954@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
75955 __list_add_rcu(new, head, head->next);
75956 }
75957
75958+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
75959+{
75960+ __pax_list_add_rcu(new, head, head->next);
75961+}
75962+
75963 /**
75964 * list_add_tail_rcu - add a new entry to rcu-protected list
75965 * @new: new entry to be added
75966@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
75967 __list_add_rcu(new, head->prev, head);
75968 }
75969
75970+static inline void pax_list_add_tail_rcu(struct list_head *new,
75971+ struct list_head *head)
75972+{
75973+ __pax_list_add_rcu(new, head->prev, head);
75974+}
75975+
75976 /**
75977 * list_del_rcu - deletes entry from list without re-initialization
75978 * @entry: the element to delete from the list.
75979@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
75980 entry->prev = LIST_POISON2;
75981 }
75982
75983+extern void pax_list_del_rcu(struct list_head *entry);
75984+
75985 /**
75986 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
75987 * @n: the element to delete from the hash list.
75988diff --git a/include/linux/reboot.h b/include/linux/reboot.h
75989index 8e00f9f..9449b55 100644
75990--- a/include/linux/reboot.h
75991+++ b/include/linux/reboot.h
75992@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
75993 * Architecture-specific implementations of sys_reboot commands.
75994 */
75995
75996-extern void machine_restart(char *cmd);
75997-extern void machine_halt(void);
75998-extern void machine_power_off(void);
75999+extern void machine_restart(char *cmd) __noreturn;
76000+extern void machine_halt(void) __noreturn;
76001+extern void machine_power_off(void) __noreturn;
76002
76003 extern void machine_shutdown(void);
76004 struct pt_regs;
76005@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76006 */
76007
76008 extern void kernel_restart_prepare(char *cmd);
76009-extern void kernel_restart(char *cmd);
76010-extern void kernel_halt(void);
76011-extern void kernel_power_off(void);
76012+extern void kernel_restart(char *cmd) __noreturn;
76013+extern void kernel_halt(void) __noreturn;
76014+extern void kernel_power_off(void) __noreturn;
76015
76016 extern int C_A_D; /* for sysctl */
76017 void ctrl_alt_del(void);
76018@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76019 * Emergency restart, callable from an interrupt handler.
76020 */
76021
76022-extern void emergency_restart(void);
76023+extern void emergency_restart(void) __noreturn;
76024 #include <asm/emergency-restart.h>
76025
76026 #endif /* _LINUX_REBOOT_H */
76027diff --git a/include/linux/regset.h b/include/linux/regset.h
76028index 8e0c9fe..ac4d221 100644
76029--- a/include/linux/regset.h
76030+++ b/include/linux/regset.h
76031@@ -161,7 +161,8 @@ struct user_regset {
76032 unsigned int align;
76033 unsigned int bias;
76034 unsigned int core_note_type;
76035-};
76036+} __do_const;
76037+typedef struct user_regset __no_const user_regset_no_const;
76038
76039 /**
76040 * struct user_regset_view - available regsets
76041diff --git a/include/linux/relay.h b/include/linux/relay.h
76042index d7c8359..818daf5 100644
76043--- a/include/linux/relay.h
76044+++ b/include/linux/relay.h
76045@@ -157,7 +157,7 @@ struct rchan_callbacks
76046 * The callback should return 0 if successful, negative if not.
76047 */
76048 int (*remove_buf_file)(struct dentry *dentry);
76049-};
76050+} __no_const;
76051
76052 /*
76053 * CONFIG_RELAY kernel API, kernel/relay.c
76054diff --git a/include/linux/rio.h b/include/linux/rio.h
76055index b71d573..2f940bd 100644
76056--- a/include/linux/rio.h
76057+++ b/include/linux/rio.h
76058@@ -355,7 +355,7 @@ struct rio_ops {
76059 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76060 u64 rstart, u32 size, u32 flags);
76061 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76062-};
76063+} __no_const;
76064
76065 #define RIO_RESOURCE_MEM 0x00000100
76066 #define RIO_RESOURCE_DOORBELL 0x00000200
76067diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76068index 6dacb93..6174423 100644
76069--- a/include/linux/rmap.h
76070+++ b/include/linux/rmap.h
76071@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76072 void anon_vma_init(void); /* create anon_vma_cachep */
76073 int anon_vma_prepare(struct vm_area_struct *);
76074 void unlink_anon_vmas(struct vm_area_struct *);
76075-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76076-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76077+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76078+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76079
76080 static inline void anon_vma_merge(struct vm_area_struct *vma,
76081 struct vm_area_struct *next)
76082diff --git a/include/linux/sched.h b/include/linux/sched.h
76083index 078066d..4090b3b 100644
76084--- a/include/linux/sched.h
76085+++ b/include/linux/sched.h
76086@@ -62,6 +62,7 @@ struct bio_list;
76087 struct fs_struct;
76088 struct perf_event_context;
76089 struct blk_plug;
76090+struct linux_binprm;
76091
76092 /*
76093 * List of flags we want to share for kernel threads,
76094@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76095 extern int in_sched_functions(unsigned long addr);
76096
76097 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76098-extern signed long schedule_timeout(signed long timeout);
76099+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76100 extern signed long schedule_timeout_interruptible(signed long timeout);
76101 extern signed long schedule_timeout_killable(signed long timeout);
76102 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76103@@ -314,6 +315,19 @@ struct nsproxy;
76104 struct user_namespace;
76105
76106 #ifdef CONFIG_MMU
76107+
76108+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76109+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76110+#else
76111+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76112+{
76113+ return 0;
76114+}
76115+#endif
76116+
76117+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76118+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76119+
76120 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76121 extern unsigned long
76122 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76123@@ -589,6 +603,17 @@ struct signal_struct {
76124 #ifdef CONFIG_TASKSTATS
76125 struct taskstats *stats;
76126 #endif
76127+
76128+#ifdef CONFIG_GRKERNSEC
76129+ u32 curr_ip;
76130+ u32 saved_ip;
76131+ u32 gr_saddr;
76132+ u32 gr_daddr;
76133+ u16 gr_sport;
76134+ u16 gr_dport;
76135+ u8 used_accept:1;
76136+#endif
76137+
76138 #ifdef CONFIG_AUDIT
76139 unsigned audit_tty;
76140 unsigned audit_tty_log_passwd;
76141@@ -669,6 +694,14 @@ struct user_struct {
76142 struct key *session_keyring; /* UID's default session keyring */
76143 #endif
76144
76145+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76146+ unsigned char kernel_banned;
76147+#endif
76148+#ifdef CONFIG_GRKERNSEC_BRUTE
76149+ unsigned char suid_banned;
76150+ unsigned long suid_ban_expires;
76151+#endif
76152+
76153 /* Hash table maintenance information */
76154 struct hlist_node uidhash_node;
76155 kuid_t uid;
76156@@ -1151,8 +1184,8 @@ struct task_struct {
76157 struct list_head thread_group;
76158
76159 struct completion *vfork_done; /* for vfork() */
76160- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76161- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76162+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76163+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76164
76165 cputime_t utime, stime, utimescaled, stimescaled;
76166 cputime_t gtime;
76167@@ -1177,11 +1210,6 @@ struct task_struct {
76168 struct task_cputime cputime_expires;
76169 struct list_head cpu_timers[3];
76170
76171-/* process credentials */
76172- const struct cred __rcu *real_cred; /* objective and real subjective task
76173- * credentials (COW) */
76174- const struct cred __rcu *cred; /* effective (overridable) subjective task
76175- * credentials (COW) */
76176 char comm[TASK_COMM_LEN]; /* executable name excluding path
76177 - access with [gs]et_task_comm (which lock
76178 it with task_lock())
76179@@ -1198,6 +1226,10 @@ struct task_struct {
76180 #endif
76181 /* CPU-specific state of this task */
76182 struct thread_struct thread;
76183+/* thread_info moved to task_struct */
76184+#ifdef CONFIG_X86
76185+ struct thread_info tinfo;
76186+#endif
76187 /* filesystem information */
76188 struct fs_struct *fs;
76189 /* open file information */
76190@@ -1271,6 +1303,10 @@ struct task_struct {
76191 gfp_t lockdep_reclaim_gfp;
76192 #endif
76193
76194+/* process credentials */
76195+ const struct cred __rcu *real_cred; /* objective and real subjective task
76196+ * credentials (COW) */
76197+
76198 /* journalling filesystem info */
76199 void *journal_info;
76200
76201@@ -1309,6 +1345,10 @@ struct task_struct {
76202 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76203 struct list_head cg_list;
76204 #endif
76205+
76206+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76207+ * credentials (COW) */
76208+
76209 #ifdef CONFIG_FUTEX
76210 struct robust_list_head __user *robust_list;
76211 #ifdef CONFIG_COMPAT
76212@@ -1406,8 +1446,76 @@ struct task_struct {
76213 unsigned int sequential_io;
76214 unsigned int sequential_io_avg;
76215 #endif
76216+
76217+#ifdef CONFIG_GRKERNSEC
76218+ /* grsecurity */
76219+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76220+ u64 exec_id;
76221+#endif
76222+#ifdef CONFIG_GRKERNSEC_SETXID
76223+ const struct cred *delayed_cred;
76224+#endif
76225+ struct dentry *gr_chroot_dentry;
76226+ struct acl_subject_label *acl;
76227+ struct acl_role_label *role;
76228+ struct file *exec_file;
76229+ unsigned long brute_expires;
76230+ u16 acl_role_id;
76231+ /* is this the task that authenticated to the special role */
76232+ u8 acl_sp_role;
76233+ u8 is_writable;
76234+ u8 brute;
76235+ u8 gr_is_chrooted;
76236+#endif
76237+
76238 };
76239
76240+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76241+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76242+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76243+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76244+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76245+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76246+
76247+#ifdef CONFIG_PAX_SOFTMODE
76248+extern int pax_softmode;
76249+#endif
76250+
76251+extern int pax_check_flags(unsigned long *);
76252+
76253+/* if tsk != current then task_lock must be held on it */
76254+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76255+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76256+{
76257+ if (likely(tsk->mm))
76258+ return tsk->mm->pax_flags;
76259+ else
76260+ return 0UL;
76261+}
76262+
76263+/* if tsk != current then task_lock must be held on it */
76264+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76265+{
76266+ if (likely(tsk->mm)) {
76267+ tsk->mm->pax_flags = flags;
76268+ return 0;
76269+ }
76270+ return -EINVAL;
76271+}
76272+#endif
76273+
76274+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76275+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76276+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76277+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76278+#endif
76279+
76280+struct path;
76281+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76282+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76283+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76284+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76285+
76286 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76287 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76288
76289@@ -1466,7 +1574,7 @@ struct pid_namespace;
76290 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76291 struct pid_namespace *ns);
76292
76293-static inline pid_t task_pid_nr(struct task_struct *tsk)
76294+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76295 {
76296 return tsk->pid;
76297 }
76298@@ -1916,7 +2024,9 @@ void yield(void);
76299 extern struct exec_domain default_exec_domain;
76300
76301 union thread_union {
76302+#ifndef CONFIG_X86
76303 struct thread_info thread_info;
76304+#endif
76305 unsigned long stack[THREAD_SIZE/sizeof(long)];
76306 };
76307
76308@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76309 */
76310
76311 extern struct task_struct *find_task_by_vpid(pid_t nr);
76312+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76313 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76314 struct pid_namespace *ns);
76315
76316@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76317 extern void exit_itimers(struct signal_struct *);
76318 extern void flush_itimer_signals(void);
76319
76320-extern void do_group_exit(int);
76321+extern __noreturn void do_group_exit(int);
76322
76323 extern int allow_signal(int);
76324 extern int disallow_signal(int);
76325@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76326
76327 #endif
76328
76329-static inline int object_is_on_stack(void *obj)
76330+static inline int object_starts_on_stack(void *obj)
76331 {
76332- void *stack = task_stack_page(current);
76333+ const void *stack = task_stack_page(current);
76334
76335 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76336 }
76337diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76338index bf8086b..962b035 100644
76339--- a/include/linux/sched/sysctl.h
76340+++ b/include/linux/sched/sysctl.h
76341@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76342 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76343
76344 extern int sysctl_max_map_count;
76345+extern unsigned long sysctl_heap_stack_gap;
76346
76347 extern unsigned int sysctl_sched_latency;
76348 extern unsigned int sysctl_sched_min_granularity;
76349diff --git a/include/linux/security.h b/include/linux/security.h
76350index 7ce53ae..8ee24a5 100644
76351--- a/include/linux/security.h
76352+++ b/include/linux/security.h
76353@@ -27,6 +27,7 @@
76354 #include <linux/slab.h>
76355 #include <linux/err.h>
76356 #include <linux/string.h>
76357+#include <linux/grsecurity.h>
76358
76359 struct linux_binprm;
76360 struct cred;
76361@@ -116,8 +117,6 @@ struct seq_file;
76362
76363 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76364
76365-void reset_security_ops(void);
76366-
76367 #ifdef CONFIG_MMU
76368 extern unsigned long mmap_min_addr;
76369 extern unsigned long dac_mmap_min_addr;
76370diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76371index 4e32edc..f8f2d18 100644
76372--- a/include/linux/seq_file.h
76373+++ b/include/linux/seq_file.h
76374@@ -26,6 +26,9 @@ struct seq_file {
76375 struct mutex lock;
76376 const struct seq_operations *op;
76377 int poll_event;
76378+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76379+ u64 exec_id;
76380+#endif
76381 #ifdef CONFIG_USER_NS
76382 struct user_namespace *user_ns;
76383 #endif
76384@@ -38,6 +41,7 @@ struct seq_operations {
76385 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76386 int (*show) (struct seq_file *m, void *v);
76387 };
76388+typedef struct seq_operations __no_const seq_operations_no_const;
76389
76390 #define SEQ_SKIP 1
76391
76392diff --git a/include/linux/shm.h b/include/linux/shm.h
76393index 429c199..4d42e38 100644
76394--- a/include/linux/shm.h
76395+++ b/include/linux/shm.h
76396@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76397
76398 /* The task created the shm object. NULL if the task is dead. */
76399 struct task_struct *shm_creator;
76400+#ifdef CONFIG_GRKERNSEC
76401+ time_t shm_createtime;
76402+ pid_t shm_lapid;
76403+#endif
76404 };
76405
76406 /* shm_mode upper byte flags */
76407diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76408index 3b71a4e..5c9f309 100644
76409--- a/include/linux/skbuff.h
76410+++ b/include/linux/skbuff.h
76411@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76412 extern struct sk_buff *__alloc_skb(unsigned int size,
76413 gfp_t priority, int flags, int node);
76414 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76415-static inline struct sk_buff *alloc_skb(unsigned int size,
76416+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76417 gfp_t priority)
76418 {
76419 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76420@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76421 */
76422 static inline int skb_queue_empty(const struct sk_buff_head *list)
76423 {
76424- return list->next == (struct sk_buff *)list;
76425+ return list->next == (const struct sk_buff *)list;
76426 }
76427
76428 /**
76429@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76430 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76431 const struct sk_buff *skb)
76432 {
76433- return skb->next == (struct sk_buff *)list;
76434+ return skb->next == (const struct sk_buff *)list;
76435 }
76436
76437 /**
76438@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76439 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76440 const struct sk_buff *skb)
76441 {
76442- return skb->prev == (struct sk_buff *)list;
76443+ return skb->prev == (const struct sk_buff *)list;
76444 }
76445
76446 /**
76447@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76448 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76449 */
76450 #ifndef NET_SKB_PAD
76451-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76452+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76453 #endif
76454
76455 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76456@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76457 int noblock, int *err);
76458 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76459 struct poll_table_struct *wait);
76460-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76461+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76462 int offset, struct iovec *to,
76463 int size);
76464 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76465@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76466 nf_bridge_put(skb->nf_bridge);
76467 skb->nf_bridge = NULL;
76468 #endif
76469+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76470+ skb->nf_trace = 0;
76471+#endif
76472 }
76473
76474 static inline void nf_reset_trace(struct sk_buff *skb)
76475diff --git a/include/linux/slab.h b/include/linux/slab.h
76476index 6c5cc0e..9ca0fd6 100644
76477--- a/include/linux/slab.h
76478+++ b/include/linux/slab.h
76479@@ -12,15 +12,29 @@
76480 #include <linux/gfp.h>
76481 #include <linux/types.h>
76482 #include <linux/workqueue.h>
76483-
76484+#include <linux/err.h>
76485
76486 /*
76487 * Flags to pass to kmem_cache_create().
76488 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76489 */
76490 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76491+
76492+#ifdef CONFIG_PAX_USERCOPY_SLABS
76493+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76494+#else
76495+#define SLAB_USERCOPY 0x00000000UL
76496+#endif
76497+
76498 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76499 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76500+
76501+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76502+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76503+#else
76504+#define SLAB_NO_SANITIZE 0x00000000UL
76505+#endif
76506+
76507 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76508 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76509 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76510@@ -89,10 +103,13 @@
76511 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76512 * Both make kfree a no-op.
76513 */
76514-#define ZERO_SIZE_PTR ((void *)16)
76515+#define ZERO_SIZE_PTR \
76516+({ \
76517+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76518+ (void *)(-MAX_ERRNO-1L); \
76519+})
76520
76521-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76522- (unsigned long)ZERO_SIZE_PTR)
76523+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76524
76525
76526 struct mem_cgroup;
76527@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76528 void kfree(const void *);
76529 void kzfree(const void *);
76530 size_t ksize(const void *);
76531+const char *check_heap_object(const void *ptr, unsigned long n);
76532+bool is_usercopy_object(const void *ptr);
76533
76534 /*
76535 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76536@@ -164,7 +183,7 @@ struct kmem_cache {
76537 unsigned int align; /* Alignment as calculated */
76538 unsigned long flags; /* Active flags on the slab */
76539 const char *name; /* Slab name for sysfs */
76540- int refcount; /* Use counter */
76541+ atomic_t refcount; /* Use counter */
76542 void (*ctor)(void *); /* Called on object slot creation */
76543 struct list_head list; /* List of all slab caches on the system */
76544 };
76545@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76546 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76547 #endif
76548
76549+#ifdef CONFIG_PAX_USERCOPY_SLABS
76550+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76551+#endif
76552+
76553 /*
76554 * Figure out which kmalloc slab an allocation of a certain size
76555 * belongs to.
76556@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76557 * 2 = 120 .. 192 bytes
76558 * n = 2^(n-1) .. 2^n -1
76559 */
76560-static __always_inline int kmalloc_index(size_t size)
76561+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76562 {
76563 if (!size)
76564 return 0;
76565@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76566 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76567 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76568 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76569-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76570+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76571 #define kmalloc_track_caller(size, flags) \
76572 __kmalloc_track_caller(size, flags, _RET_IP_)
76573 #else
76574@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76575 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76576 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76577 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76578-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76579+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76580 #define kmalloc_node_track_caller(size, flags, node) \
76581 __kmalloc_node_track_caller(size, flags, node, \
76582 _RET_IP_)
76583diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76584index cd40158..4e2f7af 100644
76585--- a/include/linux/slab_def.h
76586+++ b/include/linux/slab_def.h
76587@@ -50,7 +50,7 @@ struct kmem_cache {
76588 /* 4) cache creation/removal */
76589 const char *name;
76590 struct list_head list;
76591- int refcount;
76592+ atomic_t refcount;
76593 int object_size;
76594 int align;
76595
76596@@ -66,10 +66,14 @@ struct kmem_cache {
76597 unsigned long node_allocs;
76598 unsigned long node_frees;
76599 unsigned long node_overflow;
76600- atomic_t allochit;
76601- atomic_t allocmiss;
76602- atomic_t freehit;
76603- atomic_t freemiss;
76604+ atomic_unchecked_t allochit;
76605+ atomic_unchecked_t allocmiss;
76606+ atomic_unchecked_t freehit;
76607+ atomic_unchecked_t freemiss;
76608+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76609+ atomic_unchecked_t sanitized;
76610+ atomic_unchecked_t not_sanitized;
76611+#endif
76612
76613 /*
76614 * If debugging is enabled, then the allocator can add additional
76615@@ -103,7 +107,7 @@ struct kmem_cache {
76616 };
76617
76618 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76619-void *__kmalloc(size_t size, gfp_t flags);
76620+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76621
76622 #ifdef CONFIG_TRACING
76623 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76624@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76625 cachep = kmalloc_dma_caches[i];
76626 else
76627 #endif
76628+
76629+#ifdef CONFIG_PAX_USERCOPY_SLABS
76630+ if (flags & GFP_USERCOPY)
76631+ cachep = kmalloc_usercopy_caches[i];
76632+ else
76633+#endif
76634+
76635 cachep = kmalloc_caches[i];
76636
76637 ret = kmem_cache_alloc_trace(cachep, flags, size);
76638@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76639 }
76640
76641 #ifdef CONFIG_NUMA
76642-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76643+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76644 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76645
76646 #ifdef CONFIG_TRACING
76647@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76648 cachep = kmalloc_dma_caches[i];
76649 else
76650 #endif
76651+
76652+#ifdef CONFIG_PAX_USERCOPY_SLABS
76653+ if (flags & GFP_USERCOPY)
76654+ cachep = kmalloc_usercopy_caches[i];
76655+ else
76656+#endif
76657+
76658 cachep = kmalloc_caches[i];
76659
76660 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76661diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76662index 095a5a4..4b82027 100644
76663--- a/include/linux/slob_def.h
76664+++ b/include/linux/slob_def.h
76665@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76666 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76667 }
76668
76669-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76670+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76671
76672 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76673 {
76674@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76675 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76676 }
76677
76678-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76679+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76680 {
76681 return kmalloc(size, flags);
76682 }
76683diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76684index 027276f..092bfe8 100644
76685--- a/include/linux/slub_def.h
76686+++ b/include/linux/slub_def.h
76687@@ -80,7 +80,7 @@ struct kmem_cache {
76688 struct kmem_cache_order_objects max;
76689 struct kmem_cache_order_objects min;
76690 gfp_t allocflags; /* gfp flags to use on each alloc */
76691- int refcount; /* Refcount for slab cache destroy */
76692+ atomic_t refcount; /* Refcount for slab cache destroy */
76693 void (*ctor)(void *);
76694 int inuse; /* Offset to metadata */
76695 int align; /* Alignment */
76696@@ -105,7 +105,7 @@ struct kmem_cache {
76697 };
76698
76699 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76700-void *__kmalloc(size_t size, gfp_t flags);
76701+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76702
76703 static __always_inline void *
76704 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76705@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76706 }
76707 #endif
76708
76709-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76710+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76711 {
76712 unsigned int order = get_order(size);
76713 return kmalloc_order_trace(size, flags, order);
76714@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76715 }
76716
76717 #ifdef CONFIG_NUMA
76718-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76719+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76720 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76721
76722 #ifdef CONFIG_TRACING
76723diff --git a/include/linux/smp.h b/include/linux/smp.h
76724index c181399..09d7b92 100644
76725--- a/include/linux/smp.h
76726+++ b/include/linux/smp.h
76727@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76728 #endif
76729
76730 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76731+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76732 #define put_cpu() preempt_enable()
76733+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76734
76735 /*
76736 * Callback to arch code if there's nosmp or maxcpus=0 on the
76737diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76738index 54f91d3..be2c379 100644
76739--- a/include/linux/sock_diag.h
76740+++ b/include/linux/sock_diag.h
76741@@ -11,7 +11,7 @@ struct sock;
76742 struct sock_diag_handler {
76743 __u8 family;
76744 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76745-};
76746+} __do_const;
76747
76748 int sock_diag_register(const struct sock_diag_handler *h);
76749 void sock_diag_unregister(const struct sock_diag_handler *h);
76750diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76751index 680f9a3..f13aeb0 100644
76752--- a/include/linux/sonet.h
76753+++ b/include/linux/sonet.h
76754@@ -7,7 +7,7 @@
76755 #include <uapi/linux/sonet.h>
76756
76757 struct k_sonet_stats {
76758-#define __HANDLE_ITEM(i) atomic_t i
76759+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76760 __SONET_ITEMS
76761 #undef __HANDLE_ITEM
76762 };
76763diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76764index 07d8e53..dc934c9 100644
76765--- a/include/linux/sunrpc/addr.h
76766+++ b/include/linux/sunrpc/addr.h
76767@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76768 {
76769 switch (sap->sa_family) {
76770 case AF_INET:
76771- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76772+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76773 case AF_INET6:
76774- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76775+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76776 }
76777 return 0;
76778 }
76779@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76780 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76781 const struct sockaddr *src)
76782 {
76783- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76784+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76785 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76786
76787 dsin->sin_family = ssin->sin_family;
76788@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76789 if (sa->sa_family != AF_INET6)
76790 return 0;
76791
76792- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76793+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76794 }
76795
76796 #endif /* _LINUX_SUNRPC_ADDR_H */
76797diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76798index bfe11be..12bc8c4 100644
76799--- a/include/linux/sunrpc/clnt.h
76800+++ b/include/linux/sunrpc/clnt.h
76801@@ -96,7 +96,7 @@ struct rpc_procinfo {
76802 unsigned int p_timer; /* Which RTT timer to use */
76803 u32 p_statidx; /* Which procedure to account */
76804 const char * p_name; /* name of procedure */
76805-};
76806+} __do_const;
76807
76808 #ifdef __KERNEL__
76809
76810diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76811index 1f0216b..6a4fa50 100644
76812--- a/include/linux/sunrpc/svc.h
76813+++ b/include/linux/sunrpc/svc.h
76814@@ -411,7 +411,7 @@ struct svc_procedure {
76815 unsigned int pc_count; /* call count */
76816 unsigned int pc_cachetype; /* cache info (NFS) */
76817 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76818-};
76819+} __do_const;
76820
76821 /*
76822 * Function prototypes.
76823diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76824index 0b8e3e6..33e0a01 100644
76825--- a/include/linux/sunrpc/svc_rdma.h
76826+++ b/include/linux/sunrpc/svc_rdma.h
76827@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76828 extern unsigned int svcrdma_max_requests;
76829 extern unsigned int svcrdma_max_req_size;
76830
76831-extern atomic_t rdma_stat_recv;
76832-extern atomic_t rdma_stat_read;
76833-extern atomic_t rdma_stat_write;
76834-extern atomic_t rdma_stat_sq_starve;
76835-extern atomic_t rdma_stat_rq_starve;
76836-extern atomic_t rdma_stat_rq_poll;
76837-extern atomic_t rdma_stat_rq_prod;
76838-extern atomic_t rdma_stat_sq_poll;
76839-extern atomic_t rdma_stat_sq_prod;
76840+extern atomic_unchecked_t rdma_stat_recv;
76841+extern atomic_unchecked_t rdma_stat_read;
76842+extern atomic_unchecked_t rdma_stat_write;
76843+extern atomic_unchecked_t rdma_stat_sq_starve;
76844+extern atomic_unchecked_t rdma_stat_rq_starve;
76845+extern atomic_unchecked_t rdma_stat_rq_poll;
76846+extern atomic_unchecked_t rdma_stat_rq_prod;
76847+extern atomic_unchecked_t rdma_stat_sq_poll;
76848+extern atomic_unchecked_t rdma_stat_sq_prod;
76849
76850 #define RPCRDMA_VERSION 1
76851
76852diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76853index 8d71d65..f79586e 100644
76854--- a/include/linux/sunrpc/svcauth.h
76855+++ b/include/linux/sunrpc/svcauth.h
76856@@ -120,7 +120,7 @@ struct auth_ops {
76857 int (*release)(struct svc_rqst *rq);
76858 void (*domain_release)(struct auth_domain *);
76859 int (*set_client)(struct svc_rqst *rq);
76860-};
76861+} __do_const;
76862
76863 #define SVC_GARBAGE 1
76864 #define SVC_SYSERR 2
76865diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76866index a5ffd32..0935dea 100644
76867--- a/include/linux/swiotlb.h
76868+++ b/include/linux/swiotlb.h
76869@@ -60,7 +60,8 @@ extern void
76870
76871 extern void
76872 swiotlb_free_coherent(struct device *hwdev, size_t size,
76873- void *vaddr, dma_addr_t dma_handle);
76874+ void *vaddr, dma_addr_t dma_handle,
76875+ struct dma_attrs *attrs);
76876
76877 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76878 unsigned long offset, size_t size,
76879diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76880index 84662ec..5271947 100644
76881--- a/include/linux/syscalls.h
76882+++ b/include/linux/syscalls.h
76883@@ -97,8 +97,14 @@ struct sigaltstack;
76884 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76885
76886 #define __SC_DECL(t, a) t a
76887+#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))
76888 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76889-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76890+#define __SC_LONG(t, a) __typeof( \
76891+ __builtin_choose_expr( \
76892+ sizeof(t) > sizeof(int), \
76893+ (t) 0, \
76894+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76895+ )) a
76896 #define __SC_CAST(t, a) (t) a
76897 #define __SC_ARGS(t, a) a
76898 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76899@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76900 asmlinkage long sys_fsync(unsigned int fd);
76901 asmlinkage long sys_fdatasync(unsigned int fd);
76902 asmlinkage long sys_bdflush(int func, long data);
76903-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76904- char __user *type, unsigned long flags,
76905+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76906+ const char __user *type, unsigned long flags,
76907 void __user *data);
76908-asmlinkage long sys_umount(char __user *name, int flags);
76909-asmlinkage long sys_oldumount(char __user *name);
76910+asmlinkage long sys_umount(const char __user *name, int flags);
76911+asmlinkage long sys_oldumount(const char __user *name);
76912 asmlinkage long sys_truncate(const char __user *path, long length);
76913 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76914 asmlinkage long sys_stat(const char __user *filename,
76915@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76916 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76917 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76918 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76919- struct sockaddr __user *, int);
76920+ struct sockaddr __user *, int) __intentional_overflow(0);
76921 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76922 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76923 unsigned int vlen, unsigned flags);
76924diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76925index 27b3b0b..e093dd9 100644
76926--- a/include/linux/syscore_ops.h
76927+++ b/include/linux/syscore_ops.h
76928@@ -16,7 +16,7 @@ struct syscore_ops {
76929 int (*suspend)(void);
76930 void (*resume)(void);
76931 void (*shutdown)(void);
76932-};
76933+} __do_const;
76934
76935 extern void register_syscore_ops(struct syscore_ops *ops);
76936 extern void unregister_syscore_ops(struct syscore_ops *ops);
76937diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
76938index 14a8ff2..af52bad 100644
76939--- a/include/linux/sysctl.h
76940+++ b/include/linux/sysctl.h
76941@@ -34,13 +34,13 @@ struct ctl_table_root;
76942 struct ctl_table_header;
76943 struct ctl_dir;
76944
76945-typedef struct ctl_table ctl_table;
76946-
76947 typedef int proc_handler (struct ctl_table *ctl, int write,
76948 void __user *buffer, size_t *lenp, loff_t *ppos);
76949
76950 extern int proc_dostring(struct ctl_table *, int,
76951 void __user *, size_t *, loff_t *);
76952+extern int proc_dostring_modpriv(struct ctl_table *, int,
76953+ void __user *, size_t *, loff_t *);
76954 extern int proc_dointvec(struct ctl_table *, int,
76955 void __user *, size_t *, loff_t *);
76956 extern int proc_dointvec_minmax(struct ctl_table *, int,
76957@@ -115,7 +115,9 @@ struct ctl_table
76958 struct ctl_table_poll *poll;
76959 void *extra1;
76960 void *extra2;
76961-};
76962+} __do_const;
76963+typedef struct ctl_table __no_const ctl_table_no_const;
76964+typedef struct ctl_table ctl_table;
76965
76966 struct ctl_node {
76967 struct rb_node node;
76968diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
76969index 9e8a9b5..753de68 100644
76970--- a/include/linux/sysfs.h
76971+++ b/include/linux/sysfs.h
76972@@ -33,7 +33,8 @@ struct attribute {
76973 struct lock_class_key *key;
76974 struct lock_class_key skey;
76975 #endif
76976-};
76977+} __do_const;
76978+typedef struct attribute __no_const attribute_no_const;
76979
76980 /**
76981 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
76982@@ -62,7 +63,8 @@ struct attribute_group {
76983 struct attribute *, int);
76984 struct attribute **attrs;
76985 struct bin_attribute **bin_attrs;
76986-};
76987+} __do_const;
76988+typedef struct attribute_group __no_const attribute_group_no_const;
76989
76990 /**
76991 * Use these macros to make defining attributes easier. See include/linux/device.h
76992@@ -123,7 +125,8 @@ struct bin_attribute {
76993 char *, loff_t, size_t);
76994 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
76995 struct vm_area_struct *vma);
76996-};
76997+} __do_const;
76998+typedef struct bin_attribute __no_const bin_attribute_no_const;
76999
77000 /**
77001 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77002diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77003index 7faf933..9b85a0c 100644
77004--- a/include/linux/sysrq.h
77005+++ b/include/linux/sysrq.h
77006@@ -16,6 +16,7 @@
77007
77008 #include <linux/errno.h>
77009 #include <linux/types.h>
77010+#include <linux/compiler.h>
77011
77012 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77013 #define SYSRQ_DEFAULT_ENABLE 1
77014@@ -36,7 +37,7 @@ struct sysrq_key_op {
77015 char *help_msg;
77016 char *action_msg;
77017 int enable_mask;
77018-};
77019+} __do_const;
77020
77021 #ifdef CONFIG_MAGIC_SYSRQ
77022
77023diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77024index e7e0473..7989295 100644
77025--- a/include/linux/thread_info.h
77026+++ b/include/linux/thread_info.h
77027@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77028 #error "no set_restore_sigmask() provided and default one won't work"
77029 #endif
77030
77031+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77032+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77033+{
77034+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77035+ if (!__builtin_constant_p(n))
77036+#endif
77037+ __check_object_size(ptr, n, to_user);
77038+}
77039+
77040 #endif /* __KERNEL__ */
77041
77042 #endif /* _LINUX_THREAD_INFO_H */
77043diff --git a/include/linux/tty.h b/include/linux/tty.h
77044index 01ac30e..bf18a71 100644
77045--- a/include/linux/tty.h
77046+++ b/include/linux/tty.h
77047@@ -194,7 +194,7 @@ struct tty_port {
77048 const struct tty_port_operations *ops; /* Port operations */
77049 spinlock_t lock; /* Lock protecting tty field */
77050 int blocked_open; /* Waiting to open */
77051- int count; /* Usage count */
77052+ atomic_t count; /* Usage count */
77053 wait_queue_head_t open_wait; /* Open waiters */
77054 wait_queue_head_t close_wait; /* Close waiters */
77055 wait_queue_head_t delta_msr_wait; /* Modem status change */
77056@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77057 struct tty_struct *tty, struct file *filp);
77058 static inline int tty_port_users(struct tty_port *port)
77059 {
77060- return port->count + port->blocked_open;
77061+ return atomic_read(&port->count) + port->blocked_open;
77062 }
77063
77064 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77065diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77066index 756a609..b302dd6 100644
77067--- a/include/linux/tty_driver.h
77068+++ b/include/linux/tty_driver.h
77069@@ -285,7 +285,7 @@ struct tty_operations {
77070 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77071 #endif
77072 const struct file_operations *proc_fops;
77073-};
77074+} __do_const;
77075
77076 struct tty_driver {
77077 int magic; /* magic number for this structure */
77078diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77079index a1b0489..f02e17c 100644
77080--- a/include/linux/tty_ldisc.h
77081+++ b/include/linux/tty_ldisc.h
77082@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77083
77084 struct module *owner;
77085
77086- int refcount;
77087+ atomic_t refcount;
77088 };
77089
77090 struct tty_ldisc {
77091diff --git a/include/linux/types.h b/include/linux/types.h
77092index 4d118ba..c3ee9bf 100644
77093--- a/include/linux/types.h
77094+++ b/include/linux/types.h
77095@@ -176,10 +176,26 @@ typedef struct {
77096 int counter;
77097 } atomic_t;
77098
77099+#ifdef CONFIG_PAX_REFCOUNT
77100+typedef struct {
77101+ int counter;
77102+} atomic_unchecked_t;
77103+#else
77104+typedef atomic_t atomic_unchecked_t;
77105+#endif
77106+
77107 #ifdef CONFIG_64BIT
77108 typedef struct {
77109 long counter;
77110 } atomic64_t;
77111+
77112+#ifdef CONFIG_PAX_REFCOUNT
77113+typedef struct {
77114+ long counter;
77115+} atomic64_unchecked_t;
77116+#else
77117+typedef atomic64_t atomic64_unchecked_t;
77118+#endif
77119 #endif
77120
77121 struct list_head {
77122diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77123index 5ca0951..ab496a5 100644
77124--- a/include/linux/uaccess.h
77125+++ b/include/linux/uaccess.h
77126@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77127 long ret; \
77128 mm_segment_t old_fs = get_fs(); \
77129 \
77130- set_fs(KERNEL_DS); \
77131 pagefault_disable(); \
77132- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77133- pagefault_enable(); \
77134+ set_fs(KERNEL_DS); \
77135+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77136 set_fs(old_fs); \
77137+ pagefault_enable(); \
77138 ret; \
77139 })
77140
77141diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77142index 8e522cbc..aa8572d 100644
77143--- a/include/linux/uidgid.h
77144+++ b/include/linux/uidgid.h
77145@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77146
77147 #endif /* CONFIG_USER_NS */
77148
77149+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77150+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77151+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77152+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77153+
77154 #endif /* _LINUX_UIDGID_H */
77155diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77156index 99c1b4d..562e6f3 100644
77157--- a/include/linux/unaligned/access_ok.h
77158+++ b/include/linux/unaligned/access_ok.h
77159@@ -4,34 +4,34 @@
77160 #include <linux/kernel.h>
77161 #include <asm/byteorder.h>
77162
77163-static inline u16 get_unaligned_le16(const void *p)
77164+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77165 {
77166- return le16_to_cpup((__le16 *)p);
77167+ return le16_to_cpup((const __le16 *)p);
77168 }
77169
77170-static inline u32 get_unaligned_le32(const void *p)
77171+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77172 {
77173- return le32_to_cpup((__le32 *)p);
77174+ return le32_to_cpup((const __le32 *)p);
77175 }
77176
77177-static inline u64 get_unaligned_le64(const void *p)
77178+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77179 {
77180- return le64_to_cpup((__le64 *)p);
77181+ return le64_to_cpup((const __le64 *)p);
77182 }
77183
77184-static inline u16 get_unaligned_be16(const void *p)
77185+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77186 {
77187- return be16_to_cpup((__be16 *)p);
77188+ return be16_to_cpup((const __be16 *)p);
77189 }
77190
77191-static inline u32 get_unaligned_be32(const void *p)
77192+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77193 {
77194- return be32_to_cpup((__be32 *)p);
77195+ return be32_to_cpup((const __be32 *)p);
77196 }
77197
77198-static inline u64 get_unaligned_be64(const void *p)
77199+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77200 {
77201- return be64_to_cpup((__be64 *)p);
77202+ return be64_to_cpup((const __be64 *)p);
77203 }
77204
77205 static inline void put_unaligned_le16(u16 val, void *p)
77206diff --git a/include/linux/usb.h b/include/linux/usb.h
77207index 0eec268..4496526 100644
77208--- a/include/linux/usb.h
77209+++ b/include/linux/usb.h
77210@@ -560,7 +560,7 @@ struct usb_device {
77211 int maxchild;
77212
77213 u32 quirks;
77214- atomic_t urbnum;
77215+ atomic_unchecked_t urbnum;
77216
77217 unsigned long active_duration;
77218
77219@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77220
77221 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77222 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77223- void *data, __u16 size, int timeout);
77224+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77225 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77226 void *data, int len, int *actual_length, int timeout);
77227 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77228diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77229index e452ba6..78f8e80 100644
77230--- a/include/linux/usb/renesas_usbhs.h
77231+++ b/include/linux/usb/renesas_usbhs.h
77232@@ -39,7 +39,7 @@ enum {
77233 */
77234 struct renesas_usbhs_driver_callback {
77235 int (*notify_hotplug)(struct platform_device *pdev);
77236-};
77237+} __no_const;
77238
77239 /*
77240 * callback functions for platform
77241diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77242index 6f8fbcf..8259001 100644
77243--- a/include/linux/vermagic.h
77244+++ b/include/linux/vermagic.h
77245@@ -25,9 +25,35 @@
77246 #define MODULE_ARCH_VERMAGIC ""
77247 #endif
77248
77249+#ifdef CONFIG_PAX_REFCOUNT
77250+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77251+#else
77252+#define MODULE_PAX_REFCOUNT ""
77253+#endif
77254+
77255+#ifdef CONSTIFY_PLUGIN
77256+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77257+#else
77258+#define MODULE_CONSTIFY_PLUGIN ""
77259+#endif
77260+
77261+#ifdef STACKLEAK_PLUGIN
77262+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77263+#else
77264+#define MODULE_STACKLEAK_PLUGIN ""
77265+#endif
77266+
77267+#ifdef CONFIG_GRKERNSEC
77268+#define MODULE_GRSEC "GRSEC "
77269+#else
77270+#define MODULE_GRSEC ""
77271+#endif
77272+
77273 #define VERMAGIC_STRING \
77274 UTS_RELEASE " " \
77275 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77276 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77277- MODULE_ARCH_VERMAGIC
77278+ MODULE_ARCH_VERMAGIC \
77279+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77280+ MODULE_GRSEC
77281
77282diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77283index 4b8a891..c20e936 100644
77284--- a/include/linux/vmalloc.h
77285+++ b/include/linux/vmalloc.h
77286@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77287 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77288 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77289 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77290+
77291+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77292+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77293+#endif
77294+
77295 /* bits [20..32] reserved for arch specific ioremap internals */
77296
77297 /*
77298@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77299 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77300 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77301 unsigned long start, unsigned long end, gfp_t gfp_mask,
77302- pgprot_t prot, int node, const void *caller);
77303+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77304 extern void vfree(const void *addr);
77305
77306 extern void *vmap(struct page **pages, unsigned int count,
77307@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77308 extern void free_vm_area(struct vm_struct *area);
77309
77310 /* for /dev/kmem */
77311-extern long vread(char *buf, char *addr, unsigned long count);
77312-extern long vwrite(char *buf, char *addr, unsigned long count);
77313+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77314+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77315
77316 /*
77317 * Internals. Dont't use..
77318diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77319index c586679..f06b389 100644
77320--- a/include/linux/vmstat.h
77321+++ b/include/linux/vmstat.h
77322@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77323 /*
77324 * Zone based page accounting with per cpu differentials.
77325 */
77326-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77327+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77328
77329 static inline void zone_page_state_add(long x, struct zone *zone,
77330 enum zone_stat_item item)
77331 {
77332- atomic_long_add(x, &zone->vm_stat[item]);
77333- atomic_long_add(x, &vm_stat[item]);
77334+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77335+ atomic_long_add_unchecked(x, &vm_stat[item]);
77336 }
77337
77338 static inline unsigned long global_page_state(enum zone_stat_item item)
77339 {
77340- long x = atomic_long_read(&vm_stat[item]);
77341+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77342 #ifdef CONFIG_SMP
77343 if (x < 0)
77344 x = 0;
77345@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77346 static inline unsigned long zone_page_state(struct zone *zone,
77347 enum zone_stat_item item)
77348 {
77349- long x = atomic_long_read(&zone->vm_stat[item]);
77350+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77351 #ifdef CONFIG_SMP
77352 if (x < 0)
77353 x = 0;
77354@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77355 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77356 enum zone_stat_item item)
77357 {
77358- long x = atomic_long_read(&zone->vm_stat[item]);
77359+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77360
77361 #ifdef CONFIG_SMP
77362 int cpu;
77363@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77364
77365 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77366 {
77367- atomic_long_inc(&zone->vm_stat[item]);
77368- atomic_long_inc(&vm_stat[item]);
77369+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77370+ atomic_long_inc_unchecked(&vm_stat[item]);
77371 }
77372
77373 static inline void __inc_zone_page_state(struct page *page,
77374@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77375
77376 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77377 {
77378- atomic_long_dec(&zone->vm_stat[item]);
77379- atomic_long_dec(&vm_stat[item]);
77380+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77381+ atomic_long_dec_unchecked(&vm_stat[item]);
77382 }
77383
77384 static inline void __dec_zone_page_state(struct page *page,
77385diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77386index fdbafc6..49dfe4f 100644
77387--- a/include/linux/xattr.h
77388+++ b/include/linux/xattr.h
77389@@ -28,7 +28,7 @@ struct xattr_handler {
77390 size_t size, int handler_flags);
77391 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77392 size_t size, int flags, int handler_flags);
77393-};
77394+} __do_const;
77395
77396 struct xattr {
77397 char *name;
77398@@ -37,6 +37,9 @@ struct xattr {
77399 };
77400
77401 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77402+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77403+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77404+#endif
77405 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77406 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77407 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77408diff --git a/include/linux/yam.h b/include/linux/yam.h
77409index 7fe2822..512cdc2 100644
77410--- a/include/linux/yam.h
77411+++ b/include/linux/yam.h
77412@@ -77,6 +77,6 @@ struct yamdrv_ioctl_cfg {
77413
77414 struct yamdrv_ioctl_mcs {
77415 int cmd;
77416- int bitrate;
77417+ unsigned int bitrate;
77418 unsigned char bits[YAM_FPGA_SIZE];
77419 };
77420diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77421index 9c5a6b4..09c9438 100644
77422--- a/include/linux/zlib.h
77423+++ b/include/linux/zlib.h
77424@@ -31,6 +31,7 @@
77425 #define _ZLIB_H
77426
77427 #include <linux/zconf.h>
77428+#include <linux/compiler.h>
77429
77430 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77431 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77432@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77433
77434 /* basic functions */
77435
77436-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77437+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77438 /*
77439 Returns the number of bytes that needs to be allocated for a per-
77440 stream workspace with the specified parameters. A pointer to this
77441diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77442index c768c9f..bdcaa5a 100644
77443--- a/include/media/v4l2-dev.h
77444+++ b/include/media/v4l2-dev.h
77445@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77446 int (*mmap) (struct file *, struct vm_area_struct *);
77447 int (*open) (struct file *);
77448 int (*release) (struct file *);
77449-};
77450+} __do_const;
77451
77452 /*
77453 * Newer version of video_device, handled by videodev2.c
77454diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77455index c9b1593..a572459 100644
77456--- a/include/media/v4l2-device.h
77457+++ b/include/media/v4l2-device.h
77458@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77459 this function returns 0. If the name ends with a digit (e.g. cx18),
77460 then the name will be set to cx18-0 since cx180 looks really odd. */
77461 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77462- atomic_t *instance);
77463+ atomic_unchecked_t *instance);
77464
77465 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77466 Since the parent disappears this ensures that v4l2_dev doesn't have an
77467diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77468index d9fa68f..45c88d1 100644
77469--- a/include/net/9p/transport.h
77470+++ b/include/net/9p/transport.h
77471@@ -63,7 +63,7 @@ struct p9_trans_module {
77472 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77473 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77474 char *, char *, int , int, int, int);
77475-};
77476+} __do_const;
77477
77478 void v9fs_register_trans(struct p9_trans_module *m);
77479 void v9fs_unregister_trans(struct p9_trans_module *m);
77480diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77481index 1a966af..2767cf6 100644
77482--- a/include/net/bluetooth/l2cap.h
77483+++ b/include/net/bluetooth/l2cap.h
77484@@ -551,7 +551,7 @@ struct l2cap_ops {
77485 void (*defer) (struct l2cap_chan *chan);
77486 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77487 unsigned long len, int nb);
77488-};
77489+} __do_const;
77490
77491 struct l2cap_conn {
77492 struct hci_conn *hcon;
77493diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77494index f2ae33d..c457cf0 100644
77495--- a/include/net/caif/cfctrl.h
77496+++ b/include/net/caif/cfctrl.h
77497@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77498 void (*radioset_rsp)(void);
77499 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77500 struct cflayer *client_layer);
77501-};
77502+} __no_const;
77503
77504 /* Link Setup Parameters for CAIF-Links. */
77505 struct cfctrl_link_param {
77506@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77507 struct cfctrl {
77508 struct cfsrvl serv;
77509 struct cfctrl_rsp res;
77510- atomic_t req_seq_no;
77511- atomic_t rsp_seq_no;
77512+ atomic_unchecked_t req_seq_no;
77513+ atomic_unchecked_t rsp_seq_no;
77514 struct list_head list;
77515 /* Protects from simultaneous access to first_req list */
77516 spinlock_t info_list_lock;
77517diff --git a/include/net/flow.h b/include/net/flow.h
77518index 628e11b..4c475df 100644
77519--- a/include/net/flow.h
77520+++ b/include/net/flow.h
77521@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77522
77523 extern void flow_cache_flush(void);
77524 extern void flow_cache_flush_deferred(void);
77525-extern atomic_t flow_cache_genid;
77526+extern atomic_unchecked_t flow_cache_genid;
77527
77528 #endif
77529diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77530index 8e0b6c8..73cf605 100644
77531--- a/include/net/genetlink.h
77532+++ b/include/net/genetlink.h
77533@@ -120,7 +120,7 @@ struct genl_ops {
77534 struct netlink_callback *cb);
77535 int (*done)(struct netlink_callback *cb);
77536 struct list_head ops_list;
77537-};
77538+} __do_const;
77539
77540 extern int __genl_register_family(struct genl_family *family);
77541
77542diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77543index 734d9b5..48a9a4b 100644
77544--- a/include/net/gro_cells.h
77545+++ b/include/net/gro_cells.h
77546@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77547 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77548
77549 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77550- atomic_long_inc(&dev->rx_dropped);
77551+ atomic_long_inc_unchecked(&dev->rx_dropped);
77552 kfree_skb(skb);
77553 return;
77554 }
77555diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77556index de2c785..0588a6b 100644
77557--- a/include/net/inet_connection_sock.h
77558+++ b/include/net/inet_connection_sock.h
77559@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77560 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77561 int (*bind_conflict)(const struct sock *sk,
77562 const struct inet_bind_bucket *tb, bool relax);
77563-};
77564+} __do_const;
77565
77566 /** inet_connection_sock - INET connection oriented sock
77567 *
77568diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77569index 53f464d..0bd0b49 100644
77570--- a/include/net/inetpeer.h
77571+++ b/include/net/inetpeer.h
77572@@ -47,8 +47,8 @@ struct inet_peer {
77573 */
77574 union {
77575 struct {
77576- atomic_t rid; /* Frag reception counter */
77577- atomic_t ip_id_count; /* IP ID for the next packet */
77578+ atomic_unchecked_t rid; /* Frag reception counter */
77579+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77580 };
77581 struct rcu_head rcu;
77582 struct inet_peer *gc_next;
77583@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77584 /* can be called with or without local BH being disabled */
77585 static inline int inet_getid(struct inet_peer *p, int more)
77586 {
77587- int old, new;
77588+ int id;
77589 more++;
77590 inet_peer_refcheck(p);
77591- do {
77592- old = atomic_read(&p->ip_id_count);
77593- new = old + more;
77594- if (!new)
77595- new = 1;
77596- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77597- return new;
77598+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77599+ if (!id)
77600+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77601+ return id;
77602 }
77603
77604 #endif /* _NET_INETPEER_H */
77605diff --git a/include/net/ip.h b/include/net/ip.h
77606index edfa591..a643b82 100644
77607--- a/include/net/ip.h
77608+++ b/include/net/ip.h
77609@@ -202,7 +202,7 @@ extern struct local_ports {
77610 } sysctl_local_ports;
77611 extern void inet_get_local_port_range(int *low, int *high);
77612
77613-extern unsigned long *sysctl_local_reserved_ports;
77614+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77615 static inline int inet_is_reserved_local_port(int port)
77616 {
77617 return test_bit(port, sysctl_local_reserved_ports);
77618diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77619index cbf2be3..3683f6d 100644
77620--- a/include/net/ip_fib.h
77621+++ b/include/net/ip_fib.h
77622@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77623
77624 #define FIB_RES_SADDR(net, res) \
77625 ((FIB_RES_NH(res).nh_saddr_genid == \
77626- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77627+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77628 FIB_RES_NH(res).nh_saddr : \
77629 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77630 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77631diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77632index f0d70f0..185f15b 100644
77633--- a/include/net/ip_vs.h
77634+++ b/include/net/ip_vs.h
77635@@ -588,7 +588,7 @@ struct ip_vs_conn {
77636 struct ip_vs_conn *control; /* Master control connection */
77637 atomic_t n_control; /* Number of controlled ones */
77638 struct ip_vs_dest *dest; /* real server */
77639- atomic_t in_pkts; /* incoming packet counter */
77640+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77641
77642 /* packet transmitter for different forwarding methods. If it
77643 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77644@@ -737,7 +737,7 @@ struct ip_vs_dest {
77645 __be16 port; /* port number of the server */
77646 union nf_inet_addr addr; /* IP address of the server */
77647 volatile unsigned int flags; /* dest status flags */
77648- atomic_t conn_flags; /* flags to copy to conn */
77649+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77650 atomic_t weight; /* server weight */
77651
77652 atomic_t refcnt; /* reference counter */
77653@@ -993,11 +993,11 @@ struct netns_ipvs {
77654 /* ip_vs_lblc */
77655 int sysctl_lblc_expiration;
77656 struct ctl_table_header *lblc_ctl_header;
77657- struct ctl_table *lblc_ctl_table;
77658+ ctl_table_no_const *lblc_ctl_table;
77659 /* ip_vs_lblcr */
77660 int sysctl_lblcr_expiration;
77661 struct ctl_table_header *lblcr_ctl_header;
77662- struct ctl_table *lblcr_ctl_table;
77663+ ctl_table_no_const *lblcr_ctl_table;
77664 /* ip_vs_est */
77665 struct list_head est_list; /* estimator list */
77666 spinlock_t est_lock;
77667diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77668index 80ffde3..968b0f4 100644
77669--- a/include/net/irda/ircomm_tty.h
77670+++ b/include/net/irda/ircomm_tty.h
77671@@ -35,6 +35,7 @@
77672 #include <linux/termios.h>
77673 #include <linux/timer.h>
77674 #include <linux/tty.h> /* struct tty_struct */
77675+#include <asm/local.h>
77676
77677 #include <net/irda/irias_object.h>
77678 #include <net/irda/ircomm_core.h>
77679diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77680index 714cc9a..ea05f3e 100644
77681--- a/include/net/iucv/af_iucv.h
77682+++ b/include/net/iucv/af_iucv.h
77683@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77684 struct iucv_sock_list {
77685 struct hlist_head head;
77686 rwlock_t lock;
77687- atomic_t autobind_name;
77688+ atomic_unchecked_t autobind_name;
77689 };
77690
77691 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77692diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77693index df83f69..9b640b8 100644
77694--- a/include/net/llc_c_ac.h
77695+++ b/include/net/llc_c_ac.h
77696@@ -87,7 +87,7 @@
77697 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77698 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77699
77700-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77701+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77702
77703 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77704 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77705diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77706index 6ca3113..f8026dd 100644
77707--- a/include/net/llc_c_ev.h
77708+++ b/include/net/llc_c_ev.h
77709@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77710 return (struct llc_conn_state_ev *)skb->cb;
77711 }
77712
77713-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77714-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77715+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77716+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77717
77718 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77719 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77720diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77721index 0e79cfb..f46db31 100644
77722--- a/include/net/llc_c_st.h
77723+++ b/include/net/llc_c_st.h
77724@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77725 u8 next_state;
77726 llc_conn_ev_qfyr_t *ev_qualifiers;
77727 llc_conn_action_t *ev_actions;
77728-};
77729+} __do_const;
77730
77731 struct llc_conn_state {
77732 u8 current_state;
77733diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77734index 37a3bbd..55a4241 100644
77735--- a/include/net/llc_s_ac.h
77736+++ b/include/net/llc_s_ac.h
77737@@ -23,7 +23,7 @@
77738 #define SAP_ACT_TEST_IND 9
77739
77740 /* All action functions must look like this */
77741-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77742+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77743
77744 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77745 struct sk_buff *skb);
77746diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77747index 567c681..cd73ac0 100644
77748--- a/include/net/llc_s_st.h
77749+++ b/include/net/llc_s_st.h
77750@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77751 llc_sap_ev_t ev;
77752 u8 next_state;
77753 llc_sap_action_t *ev_actions;
77754-};
77755+} __do_const;
77756
77757 struct llc_sap_state {
77758 u8 curr_state;
77759diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77760index 551ba6a..11c99c1 100644
77761--- a/include/net/mac80211.h
77762+++ b/include/net/mac80211.h
77763@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77764 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77765 struct dentry *dir);
77766 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77767-};
77768+} __do_const;
77769
77770 static inline int rate_supported(struct ieee80211_sta *sta,
77771 enum ieee80211_band band,
77772diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77773index 7e748ad..5c6229b 100644
77774--- a/include/net/neighbour.h
77775+++ b/include/net/neighbour.h
77776@@ -123,7 +123,7 @@ struct neigh_ops {
77777 void (*error_report)(struct neighbour *, struct sk_buff *);
77778 int (*output)(struct neighbour *, struct sk_buff *);
77779 int (*connected_output)(struct neighbour *, struct sk_buff *);
77780-};
77781+} __do_const;
77782
77783 struct pneigh_entry {
77784 struct pneigh_entry *next;
77785diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77786index 84e37b1..8eba19a 100644
77787--- a/include/net/net_namespace.h
77788+++ b/include/net/net_namespace.h
77789@@ -119,8 +119,8 @@ struct net {
77790 struct netns_ipvs *ipvs;
77791 #endif
77792 struct sock *diag_nlsk;
77793- atomic_t rt_genid;
77794- atomic_t fnhe_genid;
77795+ atomic_unchecked_t rt_genid;
77796+ atomic_unchecked_t fnhe_genid;
77797 };
77798
77799 /*
77800@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77801 #define __net_init __init
77802 #define __net_exit __exit_refok
77803 #define __net_initdata __initdata
77804+#ifdef CONSTIFY_PLUGIN
77805 #define __net_initconst __initconst
77806+#else
77807+#define __net_initconst __initdata
77808+#endif
77809 #endif
77810
77811 struct pernet_operations {
77812@@ -287,7 +291,7 @@ struct pernet_operations {
77813 void (*exit_batch)(struct list_head *net_exit_list);
77814 int *id;
77815 size_t size;
77816-};
77817+} __do_const;
77818
77819 /*
77820 * Use these carefully. If you implement a network device and it
77821@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77822
77823 static inline int rt_genid(struct net *net)
77824 {
77825- return atomic_read(&net->rt_genid);
77826+ return atomic_read_unchecked(&net->rt_genid);
77827 }
77828
77829 static inline void rt_genid_bump(struct net *net)
77830 {
77831- atomic_inc(&net->rt_genid);
77832+ atomic_inc_unchecked(&net->rt_genid);
77833 }
77834
77835 static inline int fnhe_genid(struct net *net)
77836 {
77837- return atomic_read(&net->fnhe_genid);
77838+ return atomic_read_unchecked(&net->fnhe_genid);
77839 }
77840
77841 static inline void fnhe_genid_bump(struct net *net)
77842 {
77843- atomic_inc(&net->fnhe_genid);
77844+ atomic_inc_unchecked(&net->fnhe_genid);
77845 }
77846
77847 #endif /* __NET_NET_NAMESPACE_H */
77848diff --git a/include/net/netdma.h b/include/net/netdma.h
77849index 8ba8ce2..99b7fff 100644
77850--- a/include/net/netdma.h
77851+++ b/include/net/netdma.h
77852@@ -24,7 +24,7 @@
77853 #include <linux/dmaengine.h>
77854 #include <linux/skbuff.h>
77855
77856-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77857+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77858 struct sk_buff *skb, int offset, struct iovec *to,
77859 size_t len, struct dma_pinned_list *pinned_list);
77860
77861diff --git a/include/net/netlink.h b/include/net/netlink.h
77862index 9690b0f..87aded7 100644
77863--- a/include/net/netlink.h
77864+++ b/include/net/netlink.h
77865@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77866 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77867 {
77868 if (mark)
77869- skb_trim(skb, (unsigned char *) mark - skb->data);
77870+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77871 }
77872
77873 /**
77874diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77875index c9c0c53..53f24c3 100644
77876--- a/include/net/netns/conntrack.h
77877+++ b/include/net/netns/conntrack.h
77878@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77879 struct nf_proto_net {
77880 #ifdef CONFIG_SYSCTL
77881 struct ctl_table_header *ctl_table_header;
77882- struct ctl_table *ctl_table;
77883+ ctl_table_no_const *ctl_table;
77884 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77885 struct ctl_table_header *ctl_compat_header;
77886- struct ctl_table *ctl_compat_table;
77887+ ctl_table_no_const *ctl_compat_table;
77888 #endif
77889 #endif
77890 unsigned int users;
77891@@ -58,7 +58,7 @@ struct nf_ip_net {
77892 struct nf_icmp_net icmpv6;
77893 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77894 struct ctl_table_header *ctl_table_header;
77895- struct ctl_table *ctl_table;
77896+ ctl_table_no_const *ctl_table;
77897 #endif
77898 };
77899
77900diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77901index 2ba9de8..47bd6c7 100644
77902--- a/include/net/netns/ipv4.h
77903+++ b/include/net/netns/ipv4.h
77904@@ -67,7 +67,7 @@ struct netns_ipv4 {
77905 kgid_t sysctl_ping_group_range[2];
77906 long sysctl_tcp_mem[3];
77907
77908- atomic_t dev_addr_genid;
77909+ atomic_unchecked_t dev_addr_genid;
77910
77911 #ifdef CONFIG_IP_MROUTE
77912 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77913diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77914index 005e2c2..023d340 100644
77915--- a/include/net/netns/ipv6.h
77916+++ b/include/net/netns/ipv6.h
77917@@ -71,7 +71,7 @@ struct netns_ipv6 {
77918 struct fib_rules_ops *mr6_rules_ops;
77919 #endif
77920 #endif
77921- atomic_t dev_addr_genid;
77922+ atomic_unchecked_t dev_addr_genid;
77923 };
77924
77925 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77926diff --git a/include/net/ping.h b/include/net/ping.h
77927index 5db0224..0d65365 100644
77928--- a/include/net/ping.h
77929+++ b/include/net/ping.h
77930@@ -55,7 +55,7 @@ struct ping_iter_state {
77931 extern struct proto ping_prot;
77932 extern struct ping_table ping_table;
77933 #if IS_ENABLED(CONFIG_IPV6)
77934-extern struct pingv6_ops pingv6_ops;
77935+extern struct pingv6_ops *pingv6_ops;
77936 #endif
77937
77938 struct pingfakehdr {
77939diff --git a/include/net/protocol.h b/include/net/protocol.h
77940index 047c047..b9dad15 100644
77941--- a/include/net/protocol.h
77942+++ b/include/net/protocol.h
77943@@ -44,7 +44,7 @@ struct net_protocol {
77944 void (*err_handler)(struct sk_buff *skb, u32 info);
77945 unsigned int no_policy:1,
77946 netns_ok:1;
77947-};
77948+} __do_const;
77949
77950 #if IS_ENABLED(CONFIG_IPV6)
77951 struct inet6_protocol {
77952@@ -57,7 +57,7 @@ struct inet6_protocol {
77953 u8 type, u8 code, int offset,
77954 __be32 info);
77955 unsigned int flags; /* INET6_PROTO_xxx */
77956-};
77957+} __do_const;
77958
77959 #define INET6_PROTO_NOPOLICY 0x1
77960 #define INET6_PROTO_FINAL 0x2
77961diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
77962index 7026648..584cc8c 100644
77963--- a/include/net/rtnetlink.h
77964+++ b/include/net/rtnetlink.h
77965@@ -81,7 +81,7 @@ struct rtnl_link_ops {
77966 const struct net_device *dev);
77967 unsigned int (*get_num_tx_queues)(void);
77968 unsigned int (*get_num_rx_queues)(void);
77969-};
77970+} __do_const;
77971
77972 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
77973 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
77974diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
77975index 2a82d13..62a31c2 100644
77976--- a/include/net/sctp/sm.h
77977+++ b/include/net/sctp/sm.h
77978@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
77979 typedef struct {
77980 sctp_state_fn_t *fn;
77981 const char *name;
77982-} sctp_sm_table_entry_t;
77983+} __do_const sctp_sm_table_entry_t;
77984
77985 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
77986 * currently in use.
77987@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
77988 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
77989
77990 /* Extern declarations for major data structures. */
77991-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77992+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77993
77994
77995 /* Get the size of a DATA chunk payload. */
77996diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
77997index e745c92..3641448 100644
77998--- a/include/net/sctp/structs.h
77999+++ b/include/net/sctp/structs.h
78000@@ -516,7 +516,7 @@ struct sctp_pf {
78001 struct sctp_association *asoc);
78002 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78003 struct sctp_af *af;
78004-};
78005+} __do_const;
78006
78007
78008 /* Structure to track chunk fragments that have been acked, but peer
78009diff --git a/include/net/sock.h b/include/net/sock.h
78010index 31d5cfb..9ee0602 100644
78011--- a/include/net/sock.h
78012+++ b/include/net/sock.h
78013@@ -331,7 +331,7 @@ struct sock {
78014 unsigned int sk_napi_id;
78015 unsigned int sk_ll_usec;
78016 #endif
78017- atomic_t sk_drops;
78018+ atomic_unchecked_t sk_drops;
78019 int sk_rcvbuf;
78020
78021 struct sk_filter __rcu *sk_filter;
78022@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78023 }
78024
78025 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78026- char __user *from, char *to,
78027+ char __user *from, unsigned char *to,
78028 int copy, int offset)
78029 {
78030 if (skb->ip_summed == CHECKSUM_NONE) {
78031@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78032 }
78033 }
78034
78035-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78036+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78037
78038 /**
78039 * sk_page_frag - return an appropriate page_frag
78040diff --git a/include/net/tcp.h b/include/net/tcp.h
78041index d198005..c974a393 100644
78042--- a/include/net/tcp.h
78043+++ b/include/net/tcp.h
78044@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78045 extern void tcp_xmit_retransmit_queue(struct sock *);
78046 extern void tcp_simple_retransmit(struct sock *);
78047 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78048-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78049+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78050
78051 extern void tcp_send_probe0(struct sock *);
78052 extern void tcp_send_partial(struct sock *);
78053@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78054 struct inet6_skb_parm h6;
78055 #endif
78056 } header; /* For incoming frames */
78057- __u32 seq; /* Starting sequence number */
78058- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78059+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78060+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78061 __u32 when; /* used to compute rtt's */
78062 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78063
78064@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78065
78066 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78067 /* 1 byte hole */
78068- __u32 ack_seq; /* Sequence number ACK'd */
78069+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78070 };
78071
78072 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78073diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78074index e823786..53b0608 100644
78075--- a/include/net/xfrm.h
78076+++ b/include/net/xfrm.h
78077@@ -287,7 +287,6 @@ struct xfrm_dst;
78078 struct xfrm_policy_afinfo {
78079 unsigned short family;
78080 struct dst_ops *dst_ops;
78081- void (*garbage_collect)(struct net *net);
78082 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78083 const xfrm_address_t *saddr,
78084 const xfrm_address_t *daddr);
78085@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78086 struct net_device *dev,
78087 const struct flowi *fl);
78088 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78089-};
78090+} __do_const;
78091
78092 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78093 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78094@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78095 int (*transport_finish)(struct sk_buff *skb,
78096 int async);
78097 void (*local_error)(struct sk_buff *skb, u32 mtu);
78098-};
78099+} __do_const;
78100
78101 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78102 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78103@@ -427,7 +426,7 @@ struct xfrm_mode {
78104 struct module *owner;
78105 unsigned int encap;
78106 int flags;
78107-};
78108+} __do_const;
78109
78110 /* Flags for xfrm_mode. */
78111 enum {
78112@@ -524,7 +523,7 @@ struct xfrm_policy {
78113 struct timer_list timer;
78114
78115 struct flow_cache_object flo;
78116- atomic_t genid;
78117+ atomic_unchecked_t genid;
78118 u32 priority;
78119 u32 index;
78120 struct xfrm_mark mark;
78121@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78122 }
78123
78124 extern void xfrm_garbage_collect(struct net *net);
78125+extern void xfrm_garbage_collect_deferred(struct net *net);
78126
78127 #else
78128
78129@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78130 static inline void xfrm_garbage_collect(struct net *net)
78131 {
78132 }
78133+static inline void xfrm_garbage_collect_deferred(struct net *net)
78134+{
78135+}
78136 #endif
78137
78138 static __inline__
78139diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78140index 1a046b1..ee0bef0 100644
78141--- a/include/rdma/iw_cm.h
78142+++ b/include/rdma/iw_cm.h
78143@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78144 int backlog);
78145
78146 int (*destroy_listen)(struct iw_cm_id *cm_id);
78147-};
78148+} __no_const;
78149
78150 /**
78151 * iw_create_cm_id - Create an IW CM identifier.
78152diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78153index e1379b4..67eafbe 100644
78154--- a/include/scsi/libfc.h
78155+++ b/include/scsi/libfc.h
78156@@ -762,6 +762,7 @@ struct libfc_function_template {
78157 */
78158 void (*disc_stop_final) (struct fc_lport *);
78159 };
78160+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78161
78162 /**
78163 * struct fc_disc - Discovery context
78164@@ -866,7 +867,7 @@ struct fc_lport {
78165 struct fc_vport *vport;
78166
78167 /* Operational Information */
78168- struct libfc_function_template tt;
78169+ libfc_function_template_no_const tt;
78170 u8 link_up;
78171 u8 qfull;
78172 enum fc_lport_state state;
78173diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78174index a44954c..5da04b2 100644
78175--- a/include/scsi/scsi_device.h
78176+++ b/include/scsi/scsi_device.h
78177@@ -172,9 +172,9 @@ struct scsi_device {
78178 unsigned int max_device_blocked; /* what device_blocked counts down from */
78179 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78180
78181- atomic_t iorequest_cnt;
78182- atomic_t iodone_cnt;
78183- atomic_t ioerr_cnt;
78184+ atomic_unchecked_t iorequest_cnt;
78185+ atomic_unchecked_t iodone_cnt;
78186+ atomic_unchecked_t ioerr_cnt;
78187
78188 struct device sdev_gendev,
78189 sdev_dev;
78190diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78191index b797e8f..8e2c3aa 100644
78192--- a/include/scsi/scsi_transport_fc.h
78193+++ b/include/scsi/scsi_transport_fc.h
78194@@ -751,7 +751,8 @@ struct fc_function_template {
78195 unsigned long show_host_system_hostname:1;
78196
78197 unsigned long disable_target_scan:1;
78198-};
78199+} __do_const;
78200+typedef struct fc_function_template __no_const fc_function_template_no_const;
78201
78202
78203 /**
78204diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78205index 9031a26..750d592 100644
78206--- a/include/sound/compress_driver.h
78207+++ b/include/sound/compress_driver.h
78208@@ -128,7 +128,7 @@ struct snd_compr_ops {
78209 struct snd_compr_caps *caps);
78210 int (*get_codec_caps) (struct snd_compr_stream *stream,
78211 struct snd_compr_codec_caps *codec);
78212-};
78213+} __no_const;
78214
78215 /**
78216 * struct snd_compr: Compressed device
78217diff --git a/include/sound/soc.h b/include/sound/soc.h
78218index 6eabee7..58afb50 100644
78219--- a/include/sound/soc.h
78220+++ b/include/sound/soc.h
78221@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78222 /* probe ordering - for components with runtime dependencies */
78223 int probe_order;
78224 int remove_order;
78225-};
78226+} __do_const;
78227
78228 /* SoC platform interface */
78229 struct snd_soc_platform_driver {
78230@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78231 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78232 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78233 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78234-};
78235+} __do_const;
78236
78237 struct snd_soc_platform {
78238 const char *name;
78239diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78240index e34fc90..ecefa2c 100644
78241--- a/include/target/target_core_base.h
78242+++ b/include/target/target_core_base.h
78243@@ -643,7 +643,7 @@ struct se_device {
78244 spinlock_t stats_lock;
78245 /* Active commands on this virtual SE device */
78246 atomic_t simple_cmds;
78247- atomic_t dev_ordered_id;
78248+ atomic_unchecked_t dev_ordered_id;
78249 atomic_t dev_ordered_sync;
78250 atomic_t dev_qf_count;
78251 int export_count;
78252diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78253new file mode 100644
78254index 0000000..fb634b7
78255--- /dev/null
78256+++ b/include/trace/events/fs.h
78257@@ -0,0 +1,53 @@
78258+#undef TRACE_SYSTEM
78259+#define TRACE_SYSTEM fs
78260+
78261+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78262+#define _TRACE_FS_H
78263+
78264+#include <linux/fs.h>
78265+#include <linux/tracepoint.h>
78266+
78267+TRACE_EVENT(do_sys_open,
78268+
78269+ TP_PROTO(const char *filename, int flags, int mode),
78270+
78271+ TP_ARGS(filename, flags, mode),
78272+
78273+ TP_STRUCT__entry(
78274+ __string( filename, filename )
78275+ __field( int, flags )
78276+ __field( int, mode )
78277+ ),
78278+
78279+ TP_fast_assign(
78280+ __assign_str(filename, filename);
78281+ __entry->flags = flags;
78282+ __entry->mode = mode;
78283+ ),
78284+
78285+ TP_printk("\"%s\" %x %o",
78286+ __get_str(filename), __entry->flags, __entry->mode)
78287+);
78288+
78289+TRACE_EVENT(open_exec,
78290+
78291+ TP_PROTO(const char *filename),
78292+
78293+ TP_ARGS(filename),
78294+
78295+ TP_STRUCT__entry(
78296+ __string( filename, filename )
78297+ ),
78298+
78299+ TP_fast_assign(
78300+ __assign_str(filename, filename);
78301+ ),
78302+
78303+ TP_printk("\"%s\"",
78304+ __get_str(filename))
78305+);
78306+
78307+#endif /* _TRACE_FS_H */
78308+
78309+/* This part must be outside protection */
78310+#include <trace/define_trace.h>
78311diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78312index 1c09820..7f5ec79 100644
78313--- a/include/trace/events/irq.h
78314+++ b/include/trace/events/irq.h
78315@@ -36,7 +36,7 @@ struct softirq_action;
78316 */
78317 TRACE_EVENT(irq_handler_entry,
78318
78319- TP_PROTO(int irq, struct irqaction *action),
78320+ TP_PROTO(int irq, const struct irqaction *action),
78321
78322 TP_ARGS(irq, action),
78323
78324@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78325 */
78326 TRACE_EVENT(irq_handler_exit,
78327
78328- TP_PROTO(int irq, struct irqaction *action, int ret),
78329+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78330
78331 TP_ARGS(irq, action, ret),
78332
78333diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78334index 7caf44c..23c6f27 100644
78335--- a/include/uapi/linux/a.out.h
78336+++ b/include/uapi/linux/a.out.h
78337@@ -39,6 +39,14 @@ enum machine_type {
78338 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78339 };
78340
78341+/* Constants for the N_FLAGS field */
78342+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78343+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78344+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78345+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78346+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78347+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78348+
78349 #if !defined (N_MAGIC)
78350 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78351 #endif
78352diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78353index d876736..ccce5c0 100644
78354--- a/include/uapi/linux/byteorder/little_endian.h
78355+++ b/include/uapi/linux/byteorder/little_endian.h
78356@@ -42,51 +42,51 @@
78357
78358 static inline __le64 __cpu_to_le64p(const __u64 *p)
78359 {
78360- return (__force __le64)*p;
78361+ return (__force const __le64)*p;
78362 }
78363-static inline __u64 __le64_to_cpup(const __le64 *p)
78364+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78365 {
78366- return (__force __u64)*p;
78367+ return (__force const __u64)*p;
78368 }
78369 static inline __le32 __cpu_to_le32p(const __u32 *p)
78370 {
78371- return (__force __le32)*p;
78372+ return (__force const __le32)*p;
78373 }
78374 static inline __u32 __le32_to_cpup(const __le32 *p)
78375 {
78376- return (__force __u32)*p;
78377+ return (__force const __u32)*p;
78378 }
78379 static inline __le16 __cpu_to_le16p(const __u16 *p)
78380 {
78381- return (__force __le16)*p;
78382+ return (__force const __le16)*p;
78383 }
78384 static inline __u16 __le16_to_cpup(const __le16 *p)
78385 {
78386- return (__force __u16)*p;
78387+ return (__force const __u16)*p;
78388 }
78389 static inline __be64 __cpu_to_be64p(const __u64 *p)
78390 {
78391- return (__force __be64)__swab64p(p);
78392+ return (__force const __be64)__swab64p(p);
78393 }
78394 static inline __u64 __be64_to_cpup(const __be64 *p)
78395 {
78396- return __swab64p((__u64 *)p);
78397+ return __swab64p((const __u64 *)p);
78398 }
78399 static inline __be32 __cpu_to_be32p(const __u32 *p)
78400 {
78401- return (__force __be32)__swab32p(p);
78402+ return (__force const __be32)__swab32p(p);
78403 }
78404-static inline __u32 __be32_to_cpup(const __be32 *p)
78405+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78406 {
78407- return __swab32p((__u32 *)p);
78408+ return __swab32p((const __u32 *)p);
78409 }
78410 static inline __be16 __cpu_to_be16p(const __u16 *p)
78411 {
78412- return (__force __be16)__swab16p(p);
78413+ return (__force const __be16)__swab16p(p);
78414 }
78415 static inline __u16 __be16_to_cpup(const __be16 *p)
78416 {
78417- return __swab16p((__u16 *)p);
78418+ return __swab16p((const __u16 *)p);
78419 }
78420 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78421 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78422diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78423index ef6103b..d4e65dd 100644
78424--- a/include/uapi/linux/elf.h
78425+++ b/include/uapi/linux/elf.h
78426@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78427 #define PT_GNU_EH_FRAME 0x6474e550
78428
78429 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78430+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78431+
78432+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78433+
78434+/* Constants for the e_flags field */
78435+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78436+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78437+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78438+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78439+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78440+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78441
78442 /*
78443 * Extended Numbering
78444@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78445 #define DT_DEBUG 21
78446 #define DT_TEXTREL 22
78447 #define DT_JMPREL 23
78448+#define DT_FLAGS 30
78449+ #define DF_TEXTREL 0x00000004
78450 #define DT_ENCODING 32
78451 #define OLD_DT_LOOS 0x60000000
78452 #define DT_LOOS 0x6000000d
78453@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78454 #define PF_W 0x2
78455 #define PF_X 0x1
78456
78457+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78458+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78459+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78460+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78461+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78462+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78463+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78464+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78465+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78466+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78467+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78468+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78469+
78470 typedef struct elf32_phdr{
78471 Elf32_Word p_type;
78472 Elf32_Off p_offset;
78473@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78474 #define EI_OSABI 7
78475 #define EI_PAD 8
78476
78477+#define EI_PAX 14
78478+
78479 #define ELFMAG0 0x7f /* EI_MAG */
78480 #define ELFMAG1 'E'
78481 #define ELFMAG2 'L'
78482diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78483index aa169c4..6a2771d 100644
78484--- a/include/uapi/linux/personality.h
78485+++ b/include/uapi/linux/personality.h
78486@@ -30,6 +30,7 @@ enum {
78487 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78488 ADDR_NO_RANDOMIZE | \
78489 ADDR_COMPAT_LAYOUT | \
78490+ ADDR_LIMIT_3GB | \
78491 MMAP_PAGE_ZERO)
78492
78493 /*
78494diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78495index 7530e74..e714828 100644
78496--- a/include/uapi/linux/screen_info.h
78497+++ b/include/uapi/linux/screen_info.h
78498@@ -43,7 +43,8 @@ struct screen_info {
78499 __u16 pages; /* 0x32 */
78500 __u16 vesa_attributes; /* 0x34 */
78501 __u32 capabilities; /* 0x36 */
78502- __u8 _reserved[6]; /* 0x3a */
78503+ __u16 vesapm_size; /* 0x3a */
78504+ __u8 _reserved[4]; /* 0x3c */
78505 } __attribute__((packed));
78506
78507 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78508diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78509index 0e011eb..82681b1 100644
78510--- a/include/uapi/linux/swab.h
78511+++ b/include/uapi/linux/swab.h
78512@@ -43,7 +43,7 @@
78513 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78514 */
78515
78516-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78517+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78518 {
78519 #ifdef __HAVE_BUILTIN_BSWAP16__
78520 return __builtin_bswap16(val);
78521@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78522 #endif
78523 }
78524
78525-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78526+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78527 {
78528 #ifdef __HAVE_BUILTIN_BSWAP32__
78529 return __builtin_bswap32(val);
78530@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78531 #endif
78532 }
78533
78534-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78535+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78536 {
78537 #ifdef __HAVE_BUILTIN_BSWAP64__
78538 return __builtin_bswap64(val);
78539diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78540index 6d67213..8dab561 100644
78541--- a/include/uapi/linux/sysctl.h
78542+++ b/include/uapi/linux/sysctl.h
78543@@ -155,7 +155,11 @@ enum
78544 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78545 };
78546
78547-
78548+#ifdef CONFIG_PAX_SOFTMODE
78549+enum {
78550+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78551+};
78552+#endif
78553
78554 /* CTL_VM names: */
78555 enum
78556diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78557index e4629b9..6958086 100644
78558--- a/include/uapi/linux/xattr.h
78559+++ b/include/uapi/linux/xattr.h
78560@@ -63,5 +63,9 @@
78561 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78562 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78563
78564+/* User namespace */
78565+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78566+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78567+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78568
78569 #endif /* _UAPI_LINUX_XATTR_H */
78570diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78571index f9466fa..f4e2b81 100644
78572--- a/include/video/udlfb.h
78573+++ b/include/video/udlfb.h
78574@@ -53,10 +53,10 @@ struct dlfb_data {
78575 u32 pseudo_palette[256];
78576 int blank_mode; /*one of FB_BLANK_ */
78577 /* blit-only rendering path metrics, exposed through sysfs */
78578- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78579- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78580- atomic_t bytes_sent; /* to usb, after compression including overhead */
78581- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78582+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78583+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78584+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78585+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78586 };
78587
78588 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78589diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78590index 30f5362..8ed8ac9 100644
78591--- a/include/video/uvesafb.h
78592+++ b/include/video/uvesafb.h
78593@@ -122,6 +122,7 @@ struct uvesafb_par {
78594 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78595 u8 pmi_setpal; /* PMI for palette changes */
78596 u16 *pmi_base; /* protected mode interface location */
78597+ u8 *pmi_code; /* protected mode code location */
78598 void *pmi_start;
78599 void *pmi_pal;
78600 u8 *vbe_state_orig; /*
78601diff --git a/init/Kconfig b/init/Kconfig
78602index fed81b5..0d3b964 100644
78603--- a/init/Kconfig
78604+++ b/init/Kconfig
78605@@ -1069,6 +1069,7 @@ endif # CGROUPS
78606
78607 config CHECKPOINT_RESTORE
78608 bool "Checkpoint/restore support" if EXPERT
78609+ depends on !GRKERNSEC
78610 default n
78611 help
78612 Enables additional kernel features in a sake of checkpoint/restore.
78613@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78614
78615 config COMPAT_BRK
78616 bool "Disable heap randomization"
78617- default y
78618+ default n
78619 help
78620 Randomizing heap placement makes heap exploits harder, but it
78621 also breaks ancient binaries (including anything libc5 based).
78622@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78623 config STOP_MACHINE
78624 bool
78625 default y
78626- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78627+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78628 help
78629 Need stop_machine() primitive.
78630
78631diff --git a/init/Makefile b/init/Makefile
78632index 7bc47ee..6da2dc7 100644
78633--- a/init/Makefile
78634+++ b/init/Makefile
78635@@ -2,6 +2,9 @@
78636 # Makefile for the linux kernel.
78637 #
78638
78639+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78640+asflags-y := $(GCC_PLUGINS_AFLAGS)
78641+
78642 obj-y := main.o version.o mounts.o
78643 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78644 obj-y += noinitramfs.o
78645diff --git a/init/do_mounts.c b/init/do_mounts.c
78646index 816014c..c2054db 100644
78647--- a/init/do_mounts.c
78648+++ b/init/do_mounts.c
78649@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78650 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78651 {
78652 struct super_block *s;
78653- int err = sys_mount(name, "/root", fs, flags, data);
78654+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78655 if (err)
78656 return err;
78657
78658- sys_chdir("/root");
78659+ sys_chdir((const char __force_user *)"/root");
78660 s = current->fs->pwd.dentry->d_sb;
78661 ROOT_DEV = s->s_dev;
78662 printk(KERN_INFO
78663@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78664 va_start(args, fmt);
78665 vsprintf(buf, fmt, args);
78666 va_end(args);
78667- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78668+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78669 if (fd >= 0) {
78670 sys_ioctl(fd, FDEJECT, 0);
78671 sys_close(fd);
78672 }
78673 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78674- fd = sys_open("/dev/console", O_RDWR, 0);
78675+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78676 if (fd >= 0) {
78677 sys_ioctl(fd, TCGETS, (long)&termios);
78678 termios.c_lflag &= ~ICANON;
78679 sys_ioctl(fd, TCSETSF, (long)&termios);
78680- sys_read(fd, &c, 1);
78681+ sys_read(fd, (char __user *)&c, 1);
78682 termios.c_lflag |= ICANON;
78683 sys_ioctl(fd, TCSETSF, (long)&termios);
78684 sys_close(fd);
78685@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78686 mount_root();
78687 out:
78688 devtmpfs_mount("dev");
78689- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78690- sys_chroot(".");
78691+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78692+ sys_chroot((const char __force_user *)".");
78693 }
78694diff --git a/init/do_mounts.h b/init/do_mounts.h
78695index f5b978a..69dbfe8 100644
78696--- a/init/do_mounts.h
78697+++ b/init/do_mounts.h
78698@@ -15,15 +15,15 @@ extern int root_mountflags;
78699
78700 static inline int create_dev(char *name, dev_t dev)
78701 {
78702- sys_unlink(name);
78703- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78704+ sys_unlink((char __force_user *)name);
78705+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78706 }
78707
78708 #if BITS_PER_LONG == 32
78709 static inline u32 bstat(char *name)
78710 {
78711 struct stat64 stat;
78712- if (sys_stat64(name, &stat) != 0)
78713+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78714 return 0;
78715 if (!S_ISBLK(stat.st_mode))
78716 return 0;
78717@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78718 static inline u32 bstat(char *name)
78719 {
78720 struct stat stat;
78721- if (sys_newstat(name, &stat) != 0)
78722+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78723 return 0;
78724 if (!S_ISBLK(stat.st_mode))
78725 return 0;
78726diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78727index 3e0878e..8a9d7a0 100644
78728--- a/init/do_mounts_initrd.c
78729+++ b/init/do_mounts_initrd.c
78730@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78731 {
78732 sys_unshare(CLONE_FS | CLONE_FILES);
78733 /* stdin/stdout/stderr for /linuxrc */
78734- sys_open("/dev/console", O_RDWR, 0);
78735+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78736 sys_dup(0);
78737 sys_dup(0);
78738 /* move initrd over / and chdir/chroot in initrd root */
78739- sys_chdir("/root");
78740- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78741- sys_chroot(".");
78742+ sys_chdir((const char __force_user *)"/root");
78743+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78744+ sys_chroot((const char __force_user *)".");
78745 sys_setsid();
78746 return 0;
78747 }
78748@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78749 create_dev("/dev/root.old", Root_RAM0);
78750 /* mount initrd on rootfs' /root */
78751 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78752- sys_mkdir("/old", 0700);
78753- sys_chdir("/old");
78754+ sys_mkdir((const char __force_user *)"/old", 0700);
78755+ sys_chdir((const char __force_user *)"/old");
78756
78757 /* try loading default modules from initrd */
78758 load_default_modules();
78759@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78760 current->flags &= ~PF_FREEZER_SKIP;
78761
78762 /* move initrd to rootfs' /old */
78763- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78764+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78765 /* switch root and cwd back to / of rootfs */
78766- sys_chroot("..");
78767+ sys_chroot((const char __force_user *)"..");
78768
78769 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78770- sys_chdir("/old");
78771+ sys_chdir((const char __force_user *)"/old");
78772 return;
78773 }
78774
78775- sys_chdir("/");
78776+ sys_chdir((const char __force_user *)"/");
78777 ROOT_DEV = new_decode_dev(real_root_dev);
78778 mount_root();
78779
78780 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78781- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78782+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78783 if (!error)
78784 printk("okay\n");
78785 else {
78786- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78787+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78788 if (error == -ENOENT)
78789 printk("/initrd does not exist. Ignored.\n");
78790 else
78791 printk("failed\n");
78792 printk(KERN_NOTICE "Unmounting old root\n");
78793- sys_umount("/old", MNT_DETACH);
78794+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78795 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78796 if (fd < 0) {
78797 error = fd;
78798@@ -127,11 +127,11 @@ int __init initrd_load(void)
78799 * mounted in the normal path.
78800 */
78801 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78802- sys_unlink("/initrd.image");
78803+ sys_unlink((const char __force_user *)"/initrd.image");
78804 handle_initrd();
78805 return 1;
78806 }
78807 }
78808- sys_unlink("/initrd.image");
78809+ sys_unlink((const char __force_user *)"/initrd.image");
78810 return 0;
78811 }
78812diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78813index 8cb6db5..d729f50 100644
78814--- a/init/do_mounts_md.c
78815+++ b/init/do_mounts_md.c
78816@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78817 partitioned ? "_d" : "", minor,
78818 md_setup_args[ent].device_names);
78819
78820- fd = sys_open(name, 0, 0);
78821+ fd = sys_open((char __force_user *)name, 0, 0);
78822 if (fd < 0) {
78823 printk(KERN_ERR "md: open failed - cannot start "
78824 "array %s\n", name);
78825@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78826 * array without it
78827 */
78828 sys_close(fd);
78829- fd = sys_open(name, 0, 0);
78830+ fd = sys_open((char __force_user *)name, 0, 0);
78831 sys_ioctl(fd, BLKRRPART, 0);
78832 }
78833 sys_close(fd);
78834@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78835
78836 wait_for_device_probe();
78837
78838- fd = sys_open("/dev/md0", 0, 0);
78839+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78840 if (fd >= 0) {
78841 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78842 sys_close(fd);
78843diff --git a/init/init_task.c b/init/init_task.c
78844index ba0a7f36..2bcf1d5 100644
78845--- a/init/init_task.c
78846+++ b/init/init_task.c
78847@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78848 * Initial thread structure. Alignment of this is handled by a special
78849 * linker map entry.
78850 */
78851+#ifdef CONFIG_X86
78852+union thread_union init_thread_union __init_task_data;
78853+#else
78854 union thread_union init_thread_union __init_task_data =
78855 { INIT_THREAD_INFO(init_task) };
78856+#endif
78857diff --git a/init/initramfs.c b/init/initramfs.c
78858index a67ef9d..2d17ed9 100644
78859--- a/init/initramfs.c
78860+++ b/init/initramfs.c
78861@@ -84,7 +84,7 @@ static void __init free_hash(void)
78862 }
78863 }
78864
78865-static long __init do_utime(char *filename, time_t mtime)
78866+static long __init do_utime(char __force_user *filename, time_t mtime)
78867 {
78868 struct timespec t[2];
78869
78870@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78871 struct dir_entry *de, *tmp;
78872 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78873 list_del(&de->list);
78874- do_utime(de->name, de->mtime);
78875+ do_utime((char __force_user *)de->name, de->mtime);
78876 kfree(de->name);
78877 kfree(de);
78878 }
78879@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78880 if (nlink >= 2) {
78881 char *old = find_link(major, minor, ino, mode, collected);
78882 if (old)
78883- return (sys_link(old, collected) < 0) ? -1 : 1;
78884+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78885 }
78886 return 0;
78887 }
78888@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78889 {
78890 struct stat st;
78891
78892- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78893+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78894 if (S_ISDIR(st.st_mode))
78895- sys_rmdir(path);
78896+ sys_rmdir((char __force_user *)path);
78897 else
78898- sys_unlink(path);
78899+ sys_unlink((char __force_user *)path);
78900 }
78901 }
78902
78903@@ -315,7 +315,7 @@ static int __init do_name(void)
78904 int openflags = O_WRONLY|O_CREAT;
78905 if (ml != 1)
78906 openflags |= O_TRUNC;
78907- wfd = sys_open(collected, openflags, mode);
78908+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78909
78910 if (wfd >= 0) {
78911 sys_fchown(wfd, uid, gid);
78912@@ -327,17 +327,17 @@ static int __init do_name(void)
78913 }
78914 }
78915 } else if (S_ISDIR(mode)) {
78916- sys_mkdir(collected, mode);
78917- sys_chown(collected, uid, gid);
78918- sys_chmod(collected, mode);
78919+ sys_mkdir((char __force_user *)collected, mode);
78920+ sys_chown((char __force_user *)collected, uid, gid);
78921+ sys_chmod((char __force_user *)collected, mode);
78922 dir_add(collected, mtime);
78923 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78924 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78925 if (maybe_link() == 0) {
78926- sys_mknod(collected, mode, rdev);
78927- sys_chown(collected, uid, gid);
78928- sys_chmod(collected, mode);
78929- do_utime(collected, mtime);
78930+ sys_mknod((char __force_user *)collected, mode, rdev);
78931+ sys_chown((char __force_user *)collected, uid, gid);
78932+ sys_chmod((char __force_user *)collected, mode);
78933+ do_utime((char __force_user *)collected, mtime);
78934 }
78935 }
78936 return 0;
78937@@ -346,15 +346,15 @@ static int __init do_name(void)
78938 static int __init do_copy(void)
78939 {
78940 if (count >= body_len) {
78941- sys_write(wfd, victim, body_len);
78942+ sys_write(wfd, (char __force_user *)victim, body_len);
78943 sys_close(wfd);
78944- do_utime(vcollected, mtime);
78945+ do_utime((char __force_user *)vcollected, mtime);
78946 kfree(vcollected);
78947 eat(body_len);
78948 state = SkipIt;
78949 return 0;
78950 } else {
78951- sys_write(wfd, victim, count);
78952+ sys_write(wfd, (char __force_user *)victim, count);
78953 body_len -= count;
78954 eat(count);
78955 return 1;
78956@@ -365,9 +365,9 @@ static int __init do_symlink(void)
78957 {
78958 collected[N_ALIGN(name_len) + body_len] = '\0';
78959 clean_path(collected, 0);
78960- sys_symlink(collected + N_ALIGN(name_len), collected);
78961- sys_lchown(collected, uid, gid);
78962- do_utime(collected, mtime);
78963+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
78964+ sys_lchown((char __force_user *)collected, uid, gid);
78965+ do_utime((char __force_user *)collected, mtime);
78966 state = SkipIt;
78967 next_state = Reset;
78968 return 0;
78969@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
78970 {
78971 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
78972 if (err)
78973- panic(err); /* Failed to decompress INTERNAL initramfs */
78974+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
78975 if (initrd_start) {
78976 #ifdef CONFIG_BLK_DEV_RAM
78977 int fd;
78978diff --git a/init/main.c b/init/main.c
78979index 586cd33..f1af30f 100644
78980--- a/init/main.c
78981+++ b/init/main.c
78982@@ -102,6 +102,8 @@ static inline void mark_rodata_ro(void) { }
78983 extern void tc_init(void);
78984 #endif
78985
78986+extern void grsecurity_init(void);
78987+
78988 /*
78989 * Debug helper: via this flag we know that we are in 'early bootup code'
78990 * where only the boot processor is running with IRQ disabled. This means
78991@@ -155,6 +157,74 @@ static int __init set_reset_devices(char *str)
78992
78993 __setup("reset_devices", set_reset_devices);
78994
78995+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78996+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
78997+static int __init setup_grsec_proc_gid(char *str)
78998+{
78999+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79000+ return 1;
79001+}
79002+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79003+#endif
79004+
79005+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79006+unsigned long pax_user_shadow_base __read_only;
79007+EXPORT_SYMBOL(pax_user_shadow_base);
79008+extern char pax_enter_kernel_user[];
79009+extern char pax_exit_kernel_user[];
79010+#endif
79011+
79012+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79013+static int __init setup_pax_nouderef(char *str)
79014+{
79015+#ifdef CONFIG_X86_32
79016+ unsigned int cpu;
79017+ struct desc_struct *gdt;
79018+
79019+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79020+ gdt = get_cpu_gdt_table(cpu);
79021+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79022+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79023+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79024+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79025+ }
79026+ loadsegment(ds, __KERNEL_DS);
79027+ loadsegment(es, __KERNEL_DS);
79028+ loadsegment(ss, __KERNEL_DS);
79029+#else
79030+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79031+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79032+ clone_pgd_mask = ~(pgdval_t)0UL;
79033+ pax_user_shadow_base = 0UL;
79034+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79035+#endif
79036+
79037+ return 0;
79038+}
79039+early_param("pax_nouderef", setup_pax_nouderef);
79040+
79041+#ifdef CONFIG_X86_64
79042+static int __init setup_pax_weakuderef(char *str)
79043+{
79044+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79045+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79046+ return 1;
79047+}
79048+__setup("pax_weakuderef", setup_pax_weakuderef);
79049+#endif
79050+#endif
79051+
79052+#ifdef CONFIG_PAX_SOFTMODE
79053+int pax_softmode;
79054+
79055+static int __init setup_pax_softmode(char *str)
79056+{
79057+ get_option(&str, &pax_softmode);
79058+ return 1;
79059+}
79060+__setup("pax_softmode=", setup_pax_softmode);
79061+#endif
79062+
79063 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79064 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79065 static const char *panic_later, *panic_param;
79066@@ -680,25 +750,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79067 {
79068 int count = preempt_count();
79069 int ret;
79070- char msgbuf[64];
79071+ const char *msg1 = "", *msg2 = "";
79072
79073 if (initcall_debug)
79074 ret = do_one_initcall_debug(fn);
79075 else
79076 ret = fn();
79077
79078- msgbuf[0] = 0;
79079-
79080 if (preempt_count() != count) {
79081- sprintf(msgbuf, "preemption imbalance ");
79082+ msg1 = " preemption imbalance";
79083 preempt_count() = count;
79084 }
79085 if (irqs_disabled()) {
79086- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79087+ msg2 = " disabled interrupts";
79088 local_irq_enable();
79089 }
79090- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79091+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79092
79093+ add_latent_entropy();
79094 return ret;
79095 }
79096
79097@@ -805,8 +874,8 @@ static int run_init_process(const char *init_filename)
79098 {
79099 argv_init[0] = init_filename;
79100 return do_execve(init_filename,
79101- (const char __user *const __user *)argv_init,
79102- (const char __user *const __user *)envp_init);
79103+ (const char __user *const __force_user *)argv_init,
79104+ (const char __user *const __force_user *)envp_init);
79105 }
79106
79107 static noinline void __init kernel_init_freeable(void);
79108@@ -883,7 +952,7 @@ static noinline void __init kernel_init_freeable(void)
79109 do_basic_setup();
79110
79111 /* Open the /dev/console on the rootfs, this should never fail */
79112- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79113+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79114 pr_err("Warning: unable to open an initial console.\n");
79115
79116 (void) sys_dup(0);
79117@@ -896,11 +965,13 @@ static noinline void __init kernel_init_freeable(void)
79118 if (!ramdisk_execute_command)
79119 ramdisk_execute_command = "/init";
79120
79121- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79122+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79123 ramdisk_execute_command = NULL;
79124 prepare_namespace();
79125 }
79126
79127+ grsecurity_init();
79128+
79129 /*
79130 * Ok, we have completed the initial bootup, and
79131 * we're essentially up and running. Get rid of the
79132diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79133index 130dfec..cc88451 100644
79134--- a/ipc/ipc_sysctl.c
79135+++ b/ipc/ipc_sysctl.c
79136@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79137 static int proc_ipc_dointvec(ctl_table *table, int write,
79138 void __user *buffer, size_t *lenp, loff_t *ppos)
79139 {
79140- struct ctl_table ipc_table;
79141+ ctl_table_no_const ipc_table;
79142
79143 memcpy(&ipc_table, table, sizeof(ipc_table));
79144 ipc_table.data = get_ipc(table);
79145@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79146 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79147 void __user *buffer, size_t *lenp, loff_t *ppos)
79148 {
79149- struct ctl_table ipc_table;
79150+ ctl_table_no_const ipc_table;
79151
79152 memcpy(&ipc_table, table, sizeof(ipc_table));
79153 ipc_table.data = get_ipc(table);
79154@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79155 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79156 void __user *buffer, size_t *lenp, loff_t *ppos)
79157 {
79158- struct ctl_table ipc_table;
79159+ ctl_table_no_const ipc_table;
79160 size_t lenp_bef = *lenp;
79161 int rc;
79162
79163@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79164 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79165 void __user *buffer, size_t *lenp, loff_t *ppos)
79166 {
79167- struct ctl_table ipc_table;
79168+ ctl_table_no_const ipc_table;
79169 memcpy(&ipc_table, table, sizeof(ipc_table));
79170 ipc_table.data = get_ipc(table);
79171
79172@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79173 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79174 void __user *buffer, size_t *lenp, loff_t *ppos)
79175 {
79176- struct ctl_table ipc_table;
79177+ ctl_table_no_const ipc_table;
79178 size_t lenp_bef = *lenp;
79179 int oldval;
79180 int rc;
79181diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79182index 383d638..943fdbb 100644
79183--- a/ipc/mq_sysctl.c
79184+++ b/ipc/mq_sysctl.c
79185@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79186 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79187 void __user *buffer, size_t *lenp, loff_t *ppos)
79188 {
79189- struct ctl_table mq_table;
79190+ ctl_table_no_const mq_table;
79191 memcpy(&mq_table, table, sizeof(mq_table));
79192 mq_table.data = get_mq(table);
79193
79194diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79195index ae1996d..a35f2cc 100644
79196--- a/ipc/mqueue.c
79197+++ b/ipc/mqueue.c
79198@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79199 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79200 info->attr.mq_msgsize);
79201
79202+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79203 spin_lock(&mq_lock);
79204 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79205 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79206diff --git a/ipc/msg.c b/ipc/msg.c
79207index 558aa91..359e718 100644
79208--- a/ipc/msg.c
79209+++ b/ipc/msg.c
79210@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79211 return security_msg_queue_associate(msq, msgflg);
79212 }
79213
79214+static struct ipc_ops msg_ops = {
79215+ .getnew = newque,
79216+ .associate = msg_security,
79217+ .more_checks = NULL
79218+};
79219+
79220 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79221 {
79222 struct ipc_namespace *ns;
79223- struct ipc_ops msg_ops;
79224 struct ipc_params msg_params;
79225
79226 ns = current->nsproxy->ipc_ns;
79227
79228- msg_ops.getnew = newque;
79229- msg_ops.associate = msg_security;
79230- msg_ops.more_checks = NULL;
79231-
79232 msg_params.key = key;
79233 msg_params.flg = msgflg;
79234
79235diff --git a/ipc/sem.c b/ipc/sem.c
79236index 8e2bf30..a711151 100644
79237--- a/ipc/sem.c
79238+++ b/ipc/sem.c
79239@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79240 return 0;
79241 }
79242
79243+static struct ipc_ops sem_ops = {
79244+ .getnew = newary,
79245+ .associate = sem_security,
79246+ .more_checks = sem_more_checks
79247+};
79248+
79249 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79250 {
79251 struct ipc_namespace *ns;
79252- struct ipc_ops sem_ops;
79253 struct ipc_params sem_params;
79254
79255 ns = current->nsproxy->ipc_ns;
79256@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79257 if (nsems < 0 || nsems > ns->sc_semmsl)
79258 return -EINVAL;
79259
79260- sem_ops.getnew = newary;
79261- sem_ops.associate = sem_security;
79262- sem_ops.more_checks = sem_more_checks;
79263-
79264 sem_params.key = key;
79265 sem_params.flg = semflg;
79266 sem_params.u.nsems = nsems;
79267diff --git a/ipc/shm.c b/ipc/shm.c
79268index d697396..40e887d 100644
79269--- a/ipc/shm.c
79270+++ b/ipc/shm.c
79271@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79272 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79273 #endif
79274
79275+#ifdef CONFIG_GRKERNSEC
79276+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79277+ const time_t shm_createtime, const kuid_t cuid,
79278+ const int shmid);
79279+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79280+ const time_t shm_createtime);
79281+#endif
79282+
79283 void shm_init_ns(struct ipc_namespace *ns)
79284 {
79285 ns->shm_ctlmax = SHMMAX;
79286@@ -551,6 +559,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79287 shp->shm_lprid = 0;
79288 shp->shm_atim = shp->shm_dtim = 0;
79289 shp->shm_ctim = get_seconds();
79290+#ifdef CONFIG_GRKERNSEC
79291+ {
79292+ struct timespec timeval;
79293+ do_posix_clock_monotonic_gettime(&timeval);
79294+
79295+ shp->shm_createtime = timeval.tv_sec;
79296+ }
79297+#endif
79298 shp->shm_segsz = size;
79299 shp->shm_nattch = 0;
79300 shp->shm_file = file;
79301@@ -604,18 +620,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79302 return 0;
79303 }
79304
79305+static struct ipc_ops shm_ops = {
79306+ .getnew = newseg,
79307+ .associate = shm_security,
79308+ .more_checks = shm_more_checks
79309+};
79310+
79311 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79312 {
79313 struct ipc_namespace *ns;
79314- struct ipc_ops shm_ops;
79315 struct ipc_params shm_params;
79316
79317 ns = current->nsproxy->ipc_ns;
79318
79319- shm_ops.getnew = newseg;
79320- shm_ops.associate = shm_security;
79321- shm_ops.more_checks = shm_more_checks;
79322-
79323 shm_params.key = key;
79324 shm_params.flg = shmflg;
79325 shm_params.u.size = size;
79326@@ -1076,6 +1093,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79327 f_mode = FMODE_READ | FMODE_WRITE;
79328 }
79329 if (shmflg & SHM_EXEC) {
79330+
79331+#ifdef CONFIG_PAX_MPROTECT
79332+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79333+ goto out;
79334+#endif
79335+
79336 prot |= PROT_EXEC;
79337 acc_mode |= S_IXUGO;
79338 }
79339@@ -1100,10 +1123,22 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79340 if (err)
79341 goto out_unlock;
79342
79343+#ifdef CONFIG_GRKERNSEC
79344+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79345+ shp->shm_perm.cuid, shmid) ||
79346+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79347+ err = -EACCES;
79348+ goto out_unlock;
79349+ }
79350+#endif
79351+
79352 ipc_lock_object(&shp->shm_perm);
79353 path = shp->shm_file->f_path;
79354 path_get(&path);
79355 shp->shm_nattch++;
79356+#ifdef CONFIG_GRKERNSEC
79357+ shp->shm_lapid = current->pid;
79358+#endif
79359 size = i_size_read(path.dentry->d_inode);
79360 ipc_unlock_object(&shp->shm_perm);
79361 rcu_read_unlock();
79362diff --git a/kernel/acct.c b/kernel/acct.c
79363index 8d6e145..33e0b1e 100644
79364--- a/kernel/acct.c
79365+++ b/kernel/acct.c
79366@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79367 */
79368 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79369 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79370- file->f_op->write(file, (char *)&ac,
79371+ file->f_op->write(file, (char __force_user *)&ac,
79372 sizeof(acct_t), &file->f_pos);
79373 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79374 set_fs(fs);
79375diff --git a/kernel/audit.c b/kernel/audit.c
79376index 7b0e23a..5b27ab9 100644
79377--- a/kernel/audit.c
79378+++ b/kernel/audit.c
79379@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79380 3) suppressed due to audit_rate_limit
79381 4) suppressed due to audit_backlog_limit
79382 */
79383-static atomic_t audit_lost = ATOMIC_INIT(0);
79384+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79385
79386 /* The netlink socket. */
79387 static struct sock *audit_sock;
79388@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79389 unsigned long now;
79390 int print;
79391
79392- atomic_inc(&audit_lost);
79393+ atomic_inc_unchecked(&audit_lost);
79394
79395 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79396
79397@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79398 printk(KERN_WARNING
79399 "audit: audit_lost=%d audit_rate_limit=%d "
79400 "audit_backlog_limit=%d\n",
79401- atomic_read(&audit_lost),
79402+ atomic_read_unchecked(&audit_lost),
79403 audit_rate_limit,
79404 audit_backlog_limit);
79405 audit_panic(message);
79406@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79407
79408 switch (msg_type) {
79409 case AUDIT_GET:
79410+ status_set.mask = 0;
79411 status_set.enabled = audit_enabled;
79412 status_set.failure = audit_failure;
79413 status_set.pid = audit_pid;
79414 status_set.rate_limit = audit_rate_limit;
79415 status_set.backlog_limit = audit_backlog_limit;
79416- status_set.lost = atomic_read(&audit_lost);
79417+ status_set.lost = atomic_read_unchecked(&audit_lost);
79418 status_set.backlog = skb_queue_len(&audit_skb_queue);
79419 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79420 &status_set, sizeof(status_set));
79421 break;
79422 case AUDIT_SET:
79423- if (nlh->nlmsg_len < sizeof(struct audit_status))
79424+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
79425 return -EINVAL;
79426 status_get = (struct audit_status *)data;
79427 if (status_get->mask & AUDIT_STATUS_ENABLED) {
79428@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79429
79430 memset(&s, 0, sizeof(s));
79431 /* guard against past and future API changes */
79432- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
79433+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
79434 if ((s.enabled != 0 && s.enabled != 1) ||
79435 (s.log_passwd != 0 && s.log_passwd != 1))
79436 return -EINVAL;
79437diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79438index 9845cb3..3ec9369 100644
79439--- a/kernel/auditsc.c
79440+++ b/kernel/auditsc.c
79441@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79442 }
79443
79444 /* global counter which is incremented every time something logs in */
79445-static atomic_t session_id = ATOMIC_INIT(0);
79446+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79447
79448 /**
79449 * audit_set_loginuid - set current task's audit_context loginuid
79450@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79451 return -EPERM;
79452 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79453
79454- sessionid = atomic_inc_return(&session_id);
79455+ sessionid = atomic_inc_return_unchecked(&session_id);
79456 if (context && context->in_syscall) {
79457 struct audit_buffer *ab;
79458
79459diff --git a/kernel/capability.c b/kernel/capability.c
79460index f6c2ce5..982c0f9 100644
79461--- a/kernel/capability.c
79462+++ b/kernel/capability.c
79463@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79464 * before modification is attempted and the application
79465 * fails.
79466 */
79467+ if (tocopy > ARRAY_SIZE(kdata))
79468+ return -EFAULT;
79469+
79470 if (copy_to_user(dataptr, kdata, tocopy
79471 * sizeof(struct __user_cap_data_struct))) {
79472 return -EFAULT;
79473@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79474 int ret;
79475
79476 rcu_read_lock();
79477- ret = security_capable(__task_cred(t), ns, cap);
79478+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79479+ gr_task_is_capable(t, __task_cred(t), cap);
79480 rcu_read_unlock();
79481
79482- return (ret == 0);
79483+ return ret;
79484 }
79485
79486 /**
79487@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79488 int ret;
79489
79490 rcu_read_lock();
79491- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79492+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79493 rcu_read_unlock();
79494
79495- return (ret == 0);
79496+ return ret;
79497 }
79498
79499 /**
79500@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79501 BUG();
79502 }
79503
79504- if (security_capable(current_cred(), ns, cap) == 0) {
79505+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79506 current->flags |= PF_SUPERPRIV;
79507 return true;
79508 }
79509@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79510 }
79511 EXPORT_SYMBOL(ns_capable);
79512
79513+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79514+{
79515+ if (unlikely(!cap_valid(cap))) {
79516+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79517+ BUG();
79518+ }
79519+
79520+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79521+ current->flags |= PF_SUPERPRIV;
79522+ return true;
79523+ }
79524+ return false;
79525+}
79526+EXPORT_SYMBOL(ns_capable_nolog);
79527+
79528 /**
79529 * file_ns_capable - Determine if the file's opener had a capability in effect
79530 * @file: The file we want to check
79531@@ -432,6 +451,12 @@ bool capable(int cap)
79532 }
79533 EXPORT_SYMBOL(capable);
79534
79535+bool capable_nolog(int cap)
79536+{
79537+ return ns_capable_nolog(&init_user_ns, cap);
79538+}
79539+EXPORT_SYMBOL(capable_nolog);
79540+
79541 /**
79542 * nsown_capable - Check superior capability to one's own user_ns
79543 * @cap: The capability in question
79544@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79545
79546 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79547 }
79548+
79549+bool inode_capable_nolog(const struct inode *inode, int cap)
79550+{
79551+ struct user_namespace *ns = current_user_ns();
79552+
79553+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79554+}
79555diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79556index e919633..f46b08f 100644
79557--- a/kernel/cgroup.c
79558+++ b/kernel/cgroup.c
79559@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79560 struct css_set *cset = link->cset;
79561 struct task_struct *task;
79562 int count = 0;
79563- seq_printf(seq, "css_set %p\n", cset);
79564+ seq_printf(seq, "css_set %pK\n", cset);
79565 list_for_each_entry(task, &cset->tasks, cg_list) {
79566 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79567 seq_puts(seq, " ...\n");
79568diff --git a/kernel/compat.c b/kernel/compat.c
79569index 0a09e48..f44f3f0 100644
79570--- a/kernel/compat.c
79571+++ b/kernel/compat.c
79572@@ -13,6 +13,7 @@
79573
79574 #include <linux/linkage.h>
79575 #include <linux/compat.h>
79576+#include <linux/module.h>
79577 #include <linux/errno.h>
79578 #include <linux/time.h>
79579 #include <linux/signal.h>
79580@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79581 mm_segment_t oldfs;
79582 long ret;
79583
79584- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79585+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79586 oldfs = get_fs();
79587 set_fs(KERNEL_DS);
79588 ret = hrtimer_nanosleep_restart(restart);
79589@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79590 oldfs = get_fs();
79591 set_fs(KERNEL_DS);
79592 ret = hrtimer_nanosleep(&tu,
79593- rmtp ? (struct timespec __user *)&rmt : NULL,
79594+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79595 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79596 set_fs(oldfs);
79597
79598@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79599 mm_segment_t old_fs = get_fs();
79600
79601 set_fs(KERNEL_DS);
79602- ret = sys_sigpending((old_sigset_t __user *) &s);
79603+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79604 set_fs(old_fs);
79605 if (ret == 0)
79606 ret = put_user(s, set);
79607@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79608 mm_segment_t old_fs = get_fs();
79609
79610 set_fs(KERNEL_DS);
79611- ret = sys_old_getrlimit(resource, &r);
79612+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79613 set_fs(old_fs);
79614
79615 if (!ret) {
79616@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79617 set_fs (KERNEL_DS);
79618 ret = sys_wait4(pid,
79619 (stat_addr ?
79620- (unsigned int __user *) &status : NULL),
79621- options, (struct rusage __user *) &r);
79622+ (unsigned int __force_user *) &status : NULL),
79623+ options, (struct rusage __force_user *) &r);
79624 set_fs (old_fs);
79625
79626 if (ret > 0) {
79627@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79628 memset(&info, 0, sizeof(info));
79629
79630 set_fs(KERNEL_DS);
79631- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79632- uru ? (struct rusage __user *)&ru : NULL);
79633+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79634+ uru ? (struct rusage __force_user *)&ru : NULL);
79635 set_fs(old_fs);
79636
79637 if ((ret < 0) || (info.si_signo == 0))
79638@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79639 oldfs = get_fs();
79640 set_fs(KERNEL_DS);
79641 err = sys_timer_settime(timer_id, flags,
79642- (struct itimerspec __user *) &newts,
79643- (struct itimerspec __user *) &oldts);
79644+ (struct itimerspec __force_user *) &newts,
79645+ (struct itimerspec __force_user *) &oldts);
79646 set_fs(oldfs);
79647 if (!err && old && put_compat_itimerspec(old, &oldts))
79648 return -EFAULT;
79649@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79650 oldfs = get_fs();
79651 set_fs(KERNEL_DS);
79652 err = sys_timer_gettime(timer_id,
79653- (struct itimerspec __user *) &ts);
79654+ (struct itimerspec __force_user *) &ts);
79655 set_fs(oldfs);
79656 if (!err && put_compat_itimerspec(setting, &ts))
79657 return -EFAULT;
79658@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79659 oldfs = get_fs();
79660 set_fs(KERNEL_DS);
79661 err = sys_clock_settime(which_clock,
79662- (struct timespec __user *) &ts);
79663+ (struct timespec __force_user *) &ts);
79664 set_fs(oldfs);
79665 return err;
79666 }
79667@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79668 oldfs = get_fs();
79669 set_fs(KERNEL_DS);
79670 err = sys_clock_gettime(which_clock,
79671- (struct timespec __user *) &ts);
79672+ (struct timespec __force_user *) &ts);
79673 set_fs(oldfs);
79674 if (!err && put_compat_timespec(&ts, tp))
79675 return -EFAULT;
79676@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79677
79678 oldfs = get_fs();
79679 set_fs(KERNEL_DS);
79680- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79681+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79682 set_fs(oldfs);
79683
79684 err = compat_put_timex(utp, &txc);
79685@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79686 oldfs = get_fs();
79687 set_fs(KERNEL_DS);
79688 err = sys_clock_getres(which_clock,
79689- (struct timespec __user *) &ts);
79690+ (struct timespec __force_user *) &ts);
79691 set_fs(oldfs);
79692 if (!err && tp && put_compat_timespec(&ts, tp))
79693 return -EFAULT;
79694@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79695 long err;
79696 mm_segment_t oldfs;
79697 struct timespec tu;
79698- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79699+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79700
79701- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79702+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79703 oldfs = get_fs();
79704 set_fs(KERNEL_DS);
79705 err = clock_nanosleep_restart(restart);
79706@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79707 oldfs = get_fs();
79708 set_fs(KERNEL_DS);
79709 err = sys_clock_nanosleep(which_clock, flags,
79710- (struct timespec __user *) &in,
79711- (struct timespec __user *) &out);
79712+ (struct timespec __force_user *) &in,
79713+ (struct timespec __force_user *) &out);
79714 set_fs(oldfs);
79715
79716 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79717diff --git a/kernel/configs.c b/kernel/configs.c
79718index c18b1f1..b9a0132 100644
79719--- a/kernel/configs.c
79720+++ b/kernel/configs.c
79721@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79722 struct proc_dir_entry *entry;
79723
79724 /* create the current config file */
79725+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79726+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79727+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79728+ &ikconfig_file_ops);
79729+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79730+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79731+ &ikconfig_file_ops);
79732+#endif
79733+#else
79734 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79735 &ikconfig_file_ops);
79736+#endif
79737+
79738 if (!entry)
79739 return -ENOMEM;
79740
79741diff --git a/kernel/cred.c b/kernel/cred.c
79742index e0573a4..3874e41 100644
79743--- a/kernel/cred.c
79744+++ b/kernel/cred.c
79745@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79746 validate_creds(cred);
79747 alter_cred_subscribers(cred, -1);
79748 put_cred(cred);
79749+
79750+#ifdef CONFIG_GRKERNSEC_SETXID
79751+ cred = (struct cred *) tsk->delayed_cred;
79752+ if (cred != NULL) {
79753+ tsk->delayed_cred = NULL;
79754+ validate_creds(cred);
79755+ alter_cred_subscribers(cred, -1);
79756+ put_cred(cred);
79757+ }
79758+#endif
79759 }
79760
79761 /**
79762@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79763 * Always returns 0 thus allowing this function to be tail-called at the end
79764 * of, say, sys_setgid().
79765 */
79766-int commit_creds(struct cred *new)
79767+static int __commit_creds(struct cred *new)
79768 {
79769 struct task_struct *task = current;
79770 const struct cred *old = task->real_cred;
79771@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79772
79773 get_cred(new); /* we will require a ref for the subj creds too */
79774
79775+ gr_set_role_label(task, new->uid, new->gid);
79776+
79777 /* dumpability changes */
79778 if (!uid_eq(old->euid, new->euid) ||
79779 !gid_eq(old->egid, new->egid) ||
79780@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79781 put_cred(old);
79782 return 0;
79783 }
79784+#ifdef CONFIG_GRKERNSEC_SETXID
79785+extern int set_user(struct cred *new);
79786+
79787+void gr_delayed_cred_worker(void)
79788+{
79789+ const struct cred *new = current->delayed_cred;
79790+ struct cred *ncred;
79791+
79792+ current->delayed_cred = NULL;
79793+
79794+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79795+ // from doing get_cred on it when queueing this
79796+ put_cred(new);
79797+ return;
79798+ } else if (new == NULL)
79799+ return;
79800+
79801+ ncred = prepare_creds();
79802+ if (!ncred)
79803+ goto die;
79804+ // uids
79805+ ncred->uid = new->uid;
79806+ ncred->euid = new->euid;
79807+ ncred->suid = new->suid;
79808+ ncred->fsuid = new->fsuid;
79809+ // gids
79810+ ncred->gid = new->gid;
79811+ ncred->egid = new->egid;
79812+ ncred->sgid = new->sgid;
79813+ ncred->fsgid = new->fsgid;
79814+ // groups
79815+ if (set_groups(ncred, new->group_info) < 0) {
79816+ abort_creds(ncred);
79817+ goto die;
79818+ }
79819+ // caps
79820+ ncred->securebits = new->securebits;
79821+ ncred->cap_inheritable = new->cap_inheritable;
79822+ ncred->cap_permitted = new->cap_permitted;
79823+ ncred->cap_effective = new->cap_effective;
79824+ ncred->cap_bset = new->cap_bset;
79825+
79826+ if (set_user(ncred)) {
79827+ abort_creds(ncred);
79828+ goto die;
79829+ }
79830+
79831+ // from doing get_cred on it when queueing this
79832+ put_cred(new);
79833+
79834+ __commit_creds(ncred);
79835+ return;
79836+die:
79837+ // from doing get_cred on it when queueing this
79838+ put_cred(new);
79839+ do_group_exit(SIGKILL);
79840+}
79841+#endif
79842+
79843+int commit_creds(struct cred *new)
79844+{
79845+#ifdef CONFIG_GRKERNSEC_SETXID
79846+ int ret;
79847+ int schedule_it = 0;
79848+ struct task_struct *t;
79849+
79850+ /* we won't get called with tasklist_lock held for writing
79851+ and interrupts disabled as the cred struct in that case is
79852+ init_cred
79853+ */
79854+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79855+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79856+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79857+ schedule_it = 1;
79858+ }
79859+ ret = __commit_creds(new);
79860+ if (schedule_it) {
79861+ rcu_read_lock();
79862+ read_lock(&tasklist_lock);
79863+ for (t = next_thread(current); t != current;
79864+ t = next_thread(t)) {
79865+ if (t->delayed_cred == NULL) {
79866+ t->delayed_cred = get_cred(new);
79867+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79868+ set_tsk_need_resched(t);
79869+ }
79870+ }
79871+ read_unlock(&tasklist_lock);
79872+ rcu_read_unlock();
79873+ }
79874+ return ret;
79875+#else
79876+ return __commit_creds(new);
79877+#endif
79878+}
79879+
79880 EXPORT_SYMBOL(commit_creds);
79881
79882 /**
79883diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79884index 0506d44..2c20034 100644
79885--- a/kernel/debug/debug_core.c
79886+++ b/kernel/debug/debug_core.c
79887@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79888 */
79889 static atomic_t masters_in_kgdb;
79890 static atomic_t slaves_in_kgdb;
79891-static atomic_t kgdb_break_tasklet_var;
79892+static atomic_unchecked_t kgdb_break_tasklet_var;
79893 atomic_t kgdb_setting_breakpoint;
79894
79895 struct task_struct *kgdb_usethread;
79896@@ -133,7 +133,7 @@ int kgdb_single_step;
79897 static pid_t kgdb_sstep_pid;
79898
79899 /* to keep track of the CPU which is doing the single stepping*/
79900-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79901+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79902
79903 /*
79904 * If you are debugging a problem where roundup (the collection of
79905@@ -541,7 +541,7 @@ return_normal:
79906 * kernel will only try for the value of sstep_tries before
79907 * giving up and continuing on.
79908 */
79909- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79910+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79911 (kgdb_info[cpu].task &&
79912 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79913 atomic_set(&kgdb_active, -1);
79914@@ -635,8 +635,8 @@ cpu_master_loop:
79915 }
79916
79917 kgdb_restore:
79918- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79919- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79920+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79921+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79922 if (kgdb_info[sstep_cpu].task)
79923 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79924 else
79925@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79926 static void kgdb_tasklet_bpt(unsigned long ing)
79927 {
79928 kgdb_breakpoint();
79929- atomic_set(&kgdb_break_tasklet_var, 0);
79930+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79931 }
79932
79933 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
79934
79935 void kgdb_schedule_breakpoint(void)
79936 {
79937- if (atomic_read(&kgdb_break_tasklet_var) ||
79938+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
79939 atomic_read(&kgdb_active) != -1 ||
79940 atomic_read(&kgdb_setting_breakpoint))
79941 return;
79942- atomic_inc(&kgdb_break_tasklet_var);
79943+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
79944 tasklet_schedule(&kgdb_tasklet_breakpoint);
79945 }
79946 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
79947diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
79948index 00eb8f7..d7e3244 100644
79949--- a/kernel/debug/kdb/kdb_main.c
79950+++ b/kernel/debug/kdb/kdb_main.c
79951@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
79952 continue;
79953
79954 kdb_printf("%-20s%8u 0x%p ", mod->name,
79955- mod->core_size, (void *)mod);
79956+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
79957 #ifdef CONFIG_MODULE_UNLOAD
79958 kdb_printf("%4ld ", module_refcount(mod));
79959 #endif
79960@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
79961 kdb_printf(" (Loading)");
79962 else
79963 kdb_printf(" (Live)");
79964- kdb_printf(" 0x%p", mod->module_core);
79965+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
79966
79967 #ifdef CONFIG_MODULE_UNLOAD
79968 {
79969diff --git a/kernel/events/core.c b/kernel/events/core.c
79970index f86599e..b18b180 100644
79971--- a/kernel/events/core.c
79972+++ b/kernel/events/core.c
79973@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
79974 * 0 - disallow raw tracepoint access for unpriv
79975 * 1 - disallow cpu events for unpriv
79976 * 2 - disallow kernel profiling for unpriv
79977+ * 3 - disallow all unpriv perf event use
79978 */
79979-int sysctl_perf_event_paranoid __read_mostly = 1;
79980+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79981+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
79982+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
79983+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
79984+#else
79985+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
79986+#endif
79987
79988 /* Minimum for 512 kiB + 1 user control page */
79989 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
79990@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
79991 update_perf_cpu_limits();
79992 }
79993
79994-static atomic64_t perf_event_id;
79995+static atomic64_unchecked_t perf_event_id;
79996
79997 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
79998 enum event_type_t event_type);
79999@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80000
80001 static inline u64 perf_event_count(struct perf_event *event)
80002 {
80003- return local64_read(&event->count) + atomic64_read(&event->child_count);
80004+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80005 }
80006
80007 static u64 perf_event_read(struct perf_event *event)
80008@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80009 mutex_lock(&event->child_mutex);
80010 total += perf_event_read(event);
80011 *enabled += event->total_time_enabled +
80012- atomic64_read(&event->child_total_time_enabled);
80013+ atomic64_read_unchecked(&event->child_total_time_enabled);
80014 *running += event->total_time_running +
80015- atomic64_read(&event->child_total_time_running);
80016+ atomic64_read_unchecked(&event->child_total_time_running);
80017
80018 list_for_each_entry(child, &event->child_list, child_list) {
80019 total += perf_event_read(child);
80020@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80021 userpg->offset -= local64_read(&event->hw.prev_count);
80022
80023 userpg->time_enabled = enabled +
80024- atomic64_read(&event->child_total_time_enabled);
80025+ atomic64_read_unchecked(&event->child_total_time_enabled);
80026
80027 userpg->time_running = running +
80028- atomic64_read(&event->child_total_time_running);
80029+ atomic64_read_unchecked(&event->child_total_time_running);
80030
80031 arch_perf_update_userpage(userpg, now);
80032
80033@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80034
80035 /* Data. */
80036 sp = perf_user_stack_pointer(regs);
80037- rem = __output_copy_user(handle, (void *) sp, dump_size);
80038+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80039 dyn_size = dump_size - rem;
80040
80041 perf_output_skip(handle, rem);
80042@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80043 values[n++] = perf_event_count(event);
80044 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80045 values[n++] = enabled +
80046- atomic64_read(&event->child_total_time_enabled);
80047+ atomic64_read_unchecked(&event->child_total_time_enabled);
80048 }
80049 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80050 values[n++] = running +
80051- atomic64_read(&event->child_total_time_running);
80052+ atomic64_read_unchecked(&event->child_total_time_running);
80053 }
80054 if (read_format & PERF_FORMAT_ID)
80055 values[n++] = primary_event_id(event);
80056@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80057 * need to add enough zero bytes after the string to handle
80058 * the 64bit alignment we do later.
80059 */
80060- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80061+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80062 if (!buf) {
80063 name = strncpy(tmp, "//enomem", sizeof(tmp));
80064 goto got_name;
80065 }
80066- name = d_path(&file->f_path, buf, PATH_MAX);
80067+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80068 if (IS_ERR(name)) {
80069 name = strncpy(tmp, "//toolong", sizeof(tmp));
80070 goto got_name;
80071@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80072 event->parent = parent_event;
80073
80074 event->ns = get_pid_ns(task_active_pid_ns(current));
80075- event->id = atomic64_inc_return(&perf_event_id);
80076+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80077
80078 event->state = PERF_EVENT_STATE_INACTIVE;
80079
80080@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80081 if (flags & ~PERF_FLAG_ALL)
80082 return -EINVAL;
80083
80084+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80085+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80086+ return -EACCES;
80087+#endif
80088+
80089 err = perf_copy_attr(attr_uptr, &attr);
80090 if (err)
80091 return err;
80092@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80093 /*
80094 * Add back the child's count to the parent's count:
80095 */
80096- atomic64_add(child_val, &parent_event->child_count);
80097- atomic64_add(child_event->total_time_enabled,
80098+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80099+ atomic64_add_unchecked(child_event->total_time_enabled,
80100 &parent_event->child_total_time_enabled);
80101- atomic64_add(child_event->total_time_running,
80102+ atomic64_add_unchecked(child_event->total_time_running,
80103 &parent_event->child_total_time_running);
80104
80105 /*
80106diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80107index ca65997..60df03d 100644
80108--- a/kernel/events/internal.h
80109+++ b/kernel/events/internal.h
80110@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80111 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80112 }
80113
80114-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80115-static inline unsigned int \
80116+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80117+static inline unsigned long \
80118 func_name(struct perf_output_handle *handle, \
80119- const void *buf, unsigned int len) \
80120+ const void user *buf, unsigned long len) \
80121 { \
80122 unsigned long size, written; \
80123 \
80124@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80125 return n;
80126 }
80127
80128-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80129+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80130
80131 #define MEMCPY_SKIP(dst, src, n) (n)
80132
80133-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80134+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80135
80136 #ifndef arch_perf_out_copy_user
80137 #define arch_perf_out_copy_user __copy_from_user_inatomic
80138 #endif
80139
80140-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80141+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80142
80143 /* Callchain handling */
80144 extern struct perf_callchain_entry *
80145diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80146index ad8e1bd..fed7ba9 100644
80147--- a/kernel/events/uprobes.c
80148+++ b/kernel/events/uprobes.c
80149@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80150 {
80151 struct page *page;
80152 uprobe_opcode_t opcode;
80153- int result;
80154+ long result;
80155
80156 pagefault_disable();
80157 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80158diff --git a/kernel/exit.c b/kernel/exit.c
80159index a949819..a5f127d 100644
80160--- a/kernel/exit.c
80161+++ b/kernel/exit.c
80162@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80163 struct task_struct *leader;
80164 int zap_leader;
80165 repeat:
80166+#ifdef CONFIG_NET
80167+ gr_del_task_from_ip_table(p);
80168+#endif
80169+
80170 /* don't need to get the RCU readlock here - the process is dead and
80171 * can't be modifying its own credentials. But shut RCU-lockdep up */
80172 rcu_read_lock();
80173@@ -329,7 +333,7 @@ int allow_signal(int sig)
80174 * know it'll be handled, so that they don't get converted to
80175 * SIGKILL or just silently dropped.
80176 */
80177- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80178+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80179 recalc_sigpending();
80180 spin_unlock_irq(&current->sighand->siglock);
80181 return 0;
80182@@ -698,6 +702,8 @@ void do_exit(long code)
80183 struct task_struct *tsk = current;
80184 int group_dead;
80185
80186+ set_fs(USER_DS);
80187+
80188 profile_task_exit(tsk);
80189
80190 WARN_ON(blk_needs_flush_plug(tsk));
80191@@ -714,7 +720,6 @@ void do_exit(long code)
80192 * mm_release()->clear_child_tid() from writing to a user-controlled
80193 * kernel address.
80194 */
80195- set_fs(USER_DS);
80196
80197 ptrace_event(PTRACE_EVENT_EXIT, code);
80198
80199@@ -773,6 +778,9 @@ void do_exit(long code)
80200 tsk->exit_code = code;
80201 taskstats_exit(tsk, group_dead);
80202
80203+ gr_acl_handle_psacct(tsk, code);
80204+ gr_acl_handle_exit();
80205+
80206 exit_mm(tsk);
80207
80208 if (group_dead)
80209@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80210 * Take down every thread in the group. This is called by fatal signals
80211 * as well as by sys_exit_group (below).
80212 */
80213-void
80214+__noreturn void
80215 do_group_exit(int exit_code)
80216 {
80217 struct signal_struct *sig = current->signal;
80218diff --git a/kernel/fork.c b/kernel/fork.c
80219index 200a7a2..43e52da 100644
80220--- a/kernel/fork.c
80221+++ b/kernel/fork.c
80222@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80223 *stackend = STACK_END_MAGIC; /* for overflow detection */
80224
80225 #ifdef CONFIG_CC_STACKPROTECTOR
80226- tsk->stack_canary = get_random_int();
80227+ tsk->stack_canary = pax_get_random_long();
80228 #endif
80229
80230 /*
80231@@ -345,13 +345,81 @@ free_tsk:
80232 }
80233
80234 #ifdef CONFIG_MMU
80235-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80236+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80237 {
80238- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80239- struct rb_node **rb_link, *rb_parent;
80240- int retval;
80241+ struct vm_area_struct *tmp;
80242 unsigned long charge;
80243 struct mempolicy *pol;
80244+ struct file *file;
80245+
80246+ charge = 0;
80247+ if (mpnt->vm_flags & VM_ACCOUNT) {
80248+ unsigned long len = vma_pages(mpnt);
80249+
80250+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80251+ goto fail_nomem;
80252+ charge = len;
80253+ }
80254+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80255+ if (!tmp)
80256+ goto fail_nomem;
80257+ *tmp = *mpnt;
80258+ tmp->vm_mm = mm;
80259+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80260+ pol = mpol_dup(vma_policy(mpnt));
80261+ if (IS_ERR(pol))
80262+ goto fail_nomem_policy;
80263+ vma_set_policy(tmp, pol);
80264+ if (anon_vma_fork(tmp, mpnt))
80265+ goto fail_nomem_anon_vma_fork;
80266+ tmp->vm_flags &= ~VM_LOCKED;
80267+ tmp->vm_next = tmp->vm_prev = NULL;
80268+ tmp->vm_mirror = NULL;
80269+ file = tmp->vm_file;
80270+ if (file) {
80271+ struct inode *inode = file_inode(file);
80272+ struct address_space *mapping = file->f_mapping;
80273+
80274+ get_file(file);
80275+ if (tmp->vm_flags & VM_DENYWRITE)
80276+ atomic_dec(&inode->i_writecount);
80277+ mutex_lock(&mapping->i_mmap_mutex);
80278+ if (tmp->vm_flags & VM_SHARED)
80279+ mapping->i_mmap_writable++;
80280+ flush_dcache_mmap_lock(mapping);
80281+ /* insert tmp into the share list, just after mpnt */
80282+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80283+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80284+ else
80285+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80286+ flush_dcache_mmap_unlock(mapping);
80287+ mutex_unlock(&mapping->i_mmap_mutex);
80288+ }
80289+
80290+ /*
80291+ * Clear hugetlb-related page reserves for children. This only
80292+ * affects MAP_PRIVATE mappings. Faults generated by the child
80293+ * are not guaranteed to succeed, even if read-only
80294+ */
80295+ if (is_vm_hugetlb_page(tmp))
80296+ reset_vma_resv_huge_pages(tmp);
80297+
80298+ return tmp;
80299+
80300+fail_nomem_anon_vma_fork:
80301+ mpol_put(pol);
80302+fail_nomem_policy:
80303+ kmem_cache_free(vm_area_cachep, tmp);
80304+fail_nomem:
80305+ vm_unacct_memory(charge);
80306+ return NULL;
80307+}
80308+
80309+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80310+{
80311+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80312+ struct rb_node **rb_link, *rb_parent;
80313+ int retval;
80314
80315 uprobe_start_dup_mmap();
80316 down_write(&oldmm->mmap_sem);
80317@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80318
80319 prev = NULL;
80320 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80321- struct file *file;
80322-
80323 if (mpnt->vm_flags & VM_DONTCOPY) {
80324 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80325 -vma_pages(mpnt));
80326 continue;
80327 }
80328- charge = 0;
80329- if (mpnt->vm_flags & VM_ACCOUNT) {
80330- unsigned long len = vma_pages(mpnt);
80331-
80332- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80333- goto fail_nomem;
80334- charge = len;
80335- }
80336- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80337- if (!tmp)
80338- goto fail_nomem;
80339- *tmp = *mpnt;
80340- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80341- pol = mpol_dup(vma_policy(mpnt));
80342- retval = PTR_ERR(pol);
80343- if (IS_ERR(pol))
80344- goto fail_nomem_policy;
80345- vma_set_policy(tmp, pol);
80346- tmp->vm_mm = mm;
80347- if (anon_vma_fork(tmp, mpnt))
80348- goto fail_nomem_anon_vma_fork;
80349- tmp->vm_flags &= ~VM_LOCKED;
80350- tmp->vm_next = tmp->vm_prev = NULL;
80351- file = tmp->vm_file;
80352- if (file) {
80353- struct inode *inode = file_inode(file);
80354- struct address_space *mapping = file->f_mapping;
80355-
80356- get_file(file);
80357- if (tmp->vm_flags & VM_DENYWRITE)
80358- atomic_dec(&inode->i_writecount);
80359- mutex_lock(&mapping->i_mmap_mutex);
80360- if (tmp->vm_flags & VM_SHARED)
80361- mapping->i_mmap_writable++;
80362- flush_dcache_mmap_lock(mapping);
80363- /* insert tmp into the share list, just after mpnt */
80364- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80365- vma_nonlinear_insert(tmp,
80366- &mapping->i_mmap_nonlinear);
80367- else
80368- vma_interval_tree_insert_after(tmp, mpnt,
80369- &mapping->i_mmap);
80370- flush_dcache_mmap_unlock(mapping);
80371- mutex_unlock(&mapping->i_mmap_mutex);
80372+ tmp = dup_vma(mm, oldmm, mpnt);
80373+ if (!tmp) {
80374+ retval = -ENOMEM;
80375+ goto out;
80376 }
80377
80378 /*
80379@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80380 if (retval)
80381 goto out;
80382 }
80383+
80384+#ifdef CONFIG_PAX_SEGMEXEC
80385+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80386+ struct vm_area_struct *mpnt_m;
80387+
80388+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80389+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80390+
80391+ if (!mpnt->vm_mirror)
80392+ continue;
80393+
80394+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80395+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80396+ mpnt->vm_mirror = mpnt_m;
80397+ } else {
80398+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80399+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80400+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80401+ mpnt->vm_mirror->vm_mirror = mpnt;
80402+ }
80403+ }
80404+ BUG_ON(mpnt_m);
80405+ }
80406+#endif
80407+
80408 /* a new mm has just been created */
80409 arch_dup_mmap(oldmm, mm);
80410 retval = 0;
80411@@ -471,14 +522,6 @@ out:
80412 up_write(&oldmm->mmap_sem);
80413 uprobe_end_dup_mmap();
80414 return retval;
80415-fail_nomem_anon_vma_fork:
80416- mpol_put(pol);
80417-fail_nomem_policy:
80418- kmem_cache_free(vm_area_cachep, tmp);
80419-fail_nomem:
80420- retval = -ENOMEM;
80421- vm_unacct_memory(charge);
80422- goto out;
80423 }
80424
80425 static inline int mm_alloc_pgd(struct mm_struct *mm)
80426@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80427 return ERR_PTR(err);
80428
80429 mm = get_task_mm(task);
80430- if (mm && mm != current->mm &&
80431- !ptrace_may_access(task, mode)) {
80432+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80433+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80434 mmput(mm);
80435 mm = ERR_PTR(-EACCES);
80436 }
80437@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80438 spin_unlock(&fs->lock);
80439 return -EAGAIN;
80440 }
80441- fs->users++;
80442+ atomic_inc(&fs->users);
80443 spin_unlock(&fs->lock);
80444 return 0;
80445 }
80446 tsk->fs = copy_fs_struct(fs);
80447 if (!tsk->fs)
80448 return -ENOMEM;
80449+ /* Carry through gr_chroot_dentry and is_chrooted instead
80450+ of recomputing it here. Already copied when the task struct
80451+ is duplicated. This allows pivot_root to not be treated as
80452+ a chroot
80453+ */
80454+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80455+
80456 return 0;
80457 }
80458
80459@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80460 * parts of the process environment (as per the clone
80461 * flags). The actual kick-off is left to the caller.
80462 */
80463-static struct task_struct *copy_process(unsigned long clone_flags,
80464+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80465 unsigned long stack_start,
80466 unsigned long stack_size,
80467 int __user *child_tidptr,
80468@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80469 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80470 #endif
80471 retval = -EAGAIN;
80472+
80473+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80474+
80475 if (atomic_read(&p->real_cred->user->processes) >=
80476 task_rlimit(p, RLIMIT_NPROC)) {
80477 if (p->real_cred->user != INIT_USER &&
80478@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80479 goto bad_fork_free_pid;
80480 }
80481
80482+ /* synchronizes with gr_set_acls()
80483+ we need to call this past the point of no return for fork()
80484+ */
80485+ gr_copy_label(p);
80486+
80487 if (likely(p->pid)) {
80488 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80489
80490@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80491 bad_fork_free:
80492 free_task(p);
80493 fork_out:
80494+ gr_log_forkfail(retval);
80495+
80496 return ERR_PTR(retval);
80497 }
80498
80499@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80500
80501 p = copy_process(clone_flags, stack_start, stack_size,
80502 child_tidptr, NULL, trace);
80503+ add_latent_entropy();
80504 /*
80505 * Do this prior waking up the new thread - the thread pointer
80506 * might get invalid after that point, if the thread exits quickly.
80507@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80508 if (clone_flags & CLONE_PARENT_SETTID)
80509 put_user(nr, parent_tidptr);
80510
80511+ gr_handle_brute_check();
80512+
80513 if (clone_flags & CLONE_VFORK) {
80514 p->vfork_done = &vfork;
80515 init_completion(&vfork);
80516@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80517 mm_cachep = kmem_cache_create("mm_struct",
80518 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80519 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80520- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80521+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80522 mmap_init();
80523 nsproxy_cache_init();
80524 }
80525@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80526 return 0;
80527
80528 /* don't need lock here; in the worst case we'll do useless copy */
80529- if (fs->users == 1)
80530+ if (atomic_read(&fs->users) == 1)
80531 return 0;
80532
80533 *new_fsp = copy_fs_struct(fs);
80534@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80535 fs = current->fs;
80536 spin_lock(&fs->lock);
80537 current->fs = new_fs;
80538- if (--fs->users)
80539+ gr_set_chroot_entries(current, &current->fs->root);
80540+ if (atomic_dec_return(&fs->users))
80541 new_fs = NULL;
80542 else
80543 new_fs = fs;
80544diff --git a/kernel/futex.c b/kernel/futex.c
80545index c3a1a55..e32b4a98 100644
80546--- a/kernel/futex.c
80547+++ b/kernel/futex.c
80548@@ -54,6 +54,7 @@
80549 #include <linux/mount.h>
80550 #include <linux/pagemap.h>
80551 #include <linux/syscalls.h>
80552+#include <linux/ptrace.h>
80553 #include <linux/signal.h>
80554 #include <linux/export.h>
80555 #include <linux/magic.h>
80556@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80557 struct page *page, *page_head;
80558 int err, ro = 0;
80559
80560+#ifdef CONFIG_PAX_SEGMEXEC
80561+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80562+ return -EFAULT;
80563+#endif
80564+
80565 /*
80566 * The futex address must be "naturally" aligned.
80567 */
80568@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80569
80570 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80571 {
80572- int ret;
80573+ unsigned long ret;
80574
80575 pagefault_disable();
80576 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80577@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80578 {
80579 u32 curval;
80580 int i;
80581+ mm_segment_t oldfs;
80582
80583 /*
80584 * This will fail and we want it. Some arch implementations do
80585@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80586 * implementation, the non-functional ones will return
80587 * -ENOSYS.
80588 */
80589+ oldfs = get_fs();
80590+ set_fs(USER_DS);
80591 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80592 futex_cmpxchg_enabled = 1;
80593+ set_fs(oldfs);
80594
80595 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80596 plist_head_init(&futex_queues[i].chain);
80597diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80598index f9f44fd..29885e4 100644
80599--- a/kernel/futex_compat.c
80600+++ b/kernel/futex_compat.c
80601@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80602 return 0;
80603 }
80604
80605-static void __user *futex_uaddr(struct robust_list __user *entry,
80606+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80607 compat_long_t futex_offset)
80608 {
80609 compat_uptr_t base = ptr_to_compat(entry);
80610diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80611index 9b22d03..6295b62 100644
80612--- a/kernel/gcov/base.c
80613+++ b/kernel/gcov/base.c
80614@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80615 }
80616
80617 #ifdef CONFIG_MODULES
80618-static inline int within(void *addr, void *start, unsigned long size)
80619-{
80620- return ((addr >= start) && (addr < start + size));
80621-}
80622-
80623 /* Update list and generate events when modules are unloaded. */
80624 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80625 void *data)
80626@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80627 prev = NULL;
80628 /* Remove entries located in module from linked list. */
80629 for (info = gcov_info_head; info; info = info->next) {
80630- if (within(info, mod->module_core, mod->core_size)) {
80631+ if (within_module_core_rw((unsigned long)info, mod)) {
80632 if (prev)
80633 prev->next = info->next;
80634 else
80635diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80636index 383319b..56ebb13 100644
80637--- a/kernel/hrtimer.c
80638+++ b/kernel/hrtimer.c
80639@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80640 local_irq_restore(flags);
80641 }
80642
80643-static void run_hrtimer_softirq(struct softirq_action *h)
80644+static __latent_entropy void run_hrtimer_softirq(void)
80645 {
80646 hrtimer_peek_ahead_timers();
80647 }
80648diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80649index 55fcce6..0e4cf34 100644
80650--- a/kernel/irq_work.c
80651+++ b/kernel/irq_work.c
80652@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80653 return NOTIFY_OK;
80654 }
80655
80656-static struct notifier_block cpu_notify;
80657+static struct notifier_block cpu_notify = {
80658+ .notifier_call = irq_work_cpu_notify,
80659+ .priority = 0,
80660+};
80661
80662 static __init int irq_work_init_cpu_notifier(void)
80663 {
80664- cpu_notify.notifier_call = irq_work_cpu_notify;
80665- cpu_notify.priority = 0;
80666 register_cpu_notifier(&cpu_notify);
80667 return 0;
80668 }
80669diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80670index 60f48fa..7f3a770 100644
80671--- a/kernel/jump_label.c
80672+++ b/kernel/jump_label.c
80673@@ -13,6 +13,7 @@
80674 #include <linux/sort.h>
80675 #include <linux/err.h>
80676 #include <linux/static_key.h>
80677+#include <linux/mm.h>
80678
80679 #ifdef HAVE_JUMP_LABEL
80680
80681@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80682
80683 size = (((unsigned long)stop - (unsigned long)start)
80684 / sizeof(struct jump_entry));
80685+ pax_open_kernel();
80686 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80687+ pax_close_kernel();
80688 }
80689
80690 static void jump_label_update(struct static_key *key, int enable);
80691@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80692 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80693 struct jump_entry *iter;
80694
80695+ pax_open_kernel();
80696 for (iter = iter_start; iter < iter_stop; iter++) {
80697 if (within_module_init(iter->code, mod))
80698 iter->code = 0;
80699 }
80700+ pax_close_kernel();
80701 }
80702
80703 static int
80704diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80705index 3127ad5..159d880 100644
80706--- a/kernel/kallsyms.c
80707+++ b/kernel/kallsyms.c
80708@@ -11,6 +11,9 @@
80709 * Changed the compression method from stem compression to "table lookup"
80710 * compression (see scripts/kallsyms.c for a more complete description)
80711 */
80712+#ifdef CONFIG_GRKERNSEC_HIDESYM
80713+#define __INCLUDED_BY_HIDESYM 1
80714+#endif
80715 #include <linux/kallsyms.h>
80716 #include <linux/module.h>
80717 #include <linux/init.h>
80718@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80719
80720 static inline int is_kernel_inittext(unsigned long addr)
80721 {
80722+ if (system_state != SYSTEM_BOOTING)
80723+ return 0;
80724+
80725 if (addr >= (unsigned long)_sinittext
80726 && addr <= (unsigned long)_einittext)
80727 return 1;
80728 return 0;
80729 }
80730
80731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80732+#ifdef CONFIG_MODULES
80733+static inline int is_module_text(unsigned long addr)
80734+{
80735+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80736+ return 1;
80737+
80738+ addr = ktla_ktva(addr);
80739+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80740+}
80741+#else
80742+static inline int is_module_text(unsigned long addr)
80743+{
80744+ return 0;
80745+}
80746+#endif
80747+#endif
80748+
80749 static inline int is_kernel_text(unsigned long addr)
80750 {
80751 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80752@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80753
80754 static inline int is_kernel(unsigned long addr)
80755 {
80756+
80757+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80758+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80759+ return 1;
80760+
80761+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80762+#else
80763 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80764+#endif
80765+
80766 return 1;
80767 return in_gate_area_no_mm(addr);
80768 }
80769
80770 static int is_ksym_addr(unsigned long addr)
80771 {
80772+
80773+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80774+ if (is_module_text(addr))
80775+ return 0;
80776+#endif
80777+
80778 if (all_var)
80779 return is_kernel(addr);
80780
80781@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80782
80783 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80784 {
80785- iter->name[0] = '\0';
80786 iter->nameoff = get_symbol_offset(new_pos);
80787 iter->pos = new_pos;
80788 }
80789@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80790 {
80791 struct kallsym_iter *iter = m->private;
80792
80793+#ifdef CONFIG_GRKERNSEC_HIDESYM
80794+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80795+ return 0;
80796+#endif
80797+
80798 /* Some debugging symbols have no name. Ignore them. */
80799 if (!iter->name[0])
80800 return 0;
80801@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80802 */
80803 type = iter->exported ? toupper(iter->type) :
80804 tolower(iter->type);
80805+
80806 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80807 type, iter->name, iter->module_name);
80808 } else
80809@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80810 struct kallsym_iter *iter;
80811 int ret;
80812
80813- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80814+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80815 if (!iter)
80816 return -ENOMEM;
80817 reset_iter(iter, 0);
80818diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80819index e30ac0f..3528cac 100644
80820--- a/kernel/kcmp.c
80821+++ b/kernel/kcmp.c
80822@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80823 struct task_struct *task1, *task2;
80824 int ret;
80825
80826+#ifdef CONFIG_GRKERNSEC
80827+ return -ENOSYS;
80828+#endif
80829+
80830 rcu_read_lock();
80831
80832 /*
80833diff --git a/kernel/kexec.c b/kernel/kexec.c
80834index 59f7b55..4022f65 100644
80835--- a/kernel/kexec.c
80836+++ b/kernel/kexec.c
80837@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80838 unsigned long flags)
80839 {
80840 struct compat_kexec_segment in;
80841- struct kexec_segment out, __user *ksegments;
80842+ struct kexec_segment out;
80843+ struct kexec_segment __user *ksegments;
80844 unsigned long i, result;
80845
80846 /* Don't allow clients that don't understand the native
80847diff --git a/kernel/kmod.c b/kernel/kmod.c
80848index b086006..a27913b 100644
80849--- a/kernel/kmod.c
80850+++ b/kernel/kmod.c
80851@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80852 kfree(info->argv);
80853 }
80854
80855-static int call_modprobe(char *module_name, int wait)
80856+static int call_modprobe(char *module_name, char *module_param, int wait)
80857 {
80858 struct subprocess_info *info;
80859 static char *envp[] = {
80860@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80861 NULL
80862 };
80863
80864- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80865+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80866 if (!argv)
80867 goto out;
80868
80869@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80870 argv[1] = "-q";
80871 argv[2] = "--";
80872 argv[3] = module_name; /* check free_modprobe_argv() */
80873- argv[4] = NULL;
80874+ argv[4] = module_param;
80875+ argv[5] = NULL;
80876
80877 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80878 NULL, free_modprobe_argv, NULL);
80879@@ -129,9 +130,8 @@ out:
80880 * If module auto-loading support is disabled then this function
80881 * becomes a no-operation.
80882 */
80883-int __request_module(bool wait, const char *fmt, ...)
80884+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80885 {
80886- va_list args;
80887 char module_name[MODULE_NAME_LEN];
80888 unsigned int max_modprobes;
80889 int ret;
80890@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80891 if (!modprobe_path[0])
80892 return 0;
80893
80894- va_start(args, fmt);
80895- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80896- va_end(args);
80897+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80898 if (ret >= MODULE_NAME_LEN)
80899 return -ENAMETOOLONG;
80900
80901@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80902 if (ret)
80903 return ret;
80904
80905+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80906+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80907+ /* hack to workaround consolekit/udisks stupidity */
80908+ read_lock(&tasklist_lock);
80909+ if (!strcmp(current->comm, "mount") &&
80910+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80911+ read_unlock(&tasklist_lock);
80912+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80913+ return -EPERM;
80914+ }
80915+ read_unlock(&tasklist_lock);
80916+ }
80917+#endif
80918+
80919 /* If modprobe needs a service that is in a module, we get a recursive
80920 * loop. Limit the number of running kmod threads to max_threads/2 or
80921 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80922@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80923
80924 trace_module_request(module_name, wait, _RET_IP_);
80925
80926- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80927+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80928
80929 atomic_dec(&kmod_concurrent);
80930 return ret;
80931 }
80932+
80933+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
80934+{
80935+ va_list args;
80936+ int ret;
80937+
80938+ va_start(args, fmt);
80939+ ret = ____request_module(wait, module_param, fmt, args);
80940+ va_end(args);
80941+
80942+ return ret;
80943+}
80944+
80945+int __request_module(bool wait, const char *fmt, ...)
80946+{
80947+ va_list args;
80948+ int ret;
80949+
80950+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80951+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80952+ char module_param[MODULE_NAME_LEN];
80953+
80954+ memset(module_param, 0, sizeof(module_param));
80955+
80956+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
80957+
80958+ va_start(args, fmt);
80959+ ret = ____request_module(wait, module_param, fmt, args);
80960+ va_end(args);
80961+
80962+ return ret;
80963+ }
80964+#endif
80965+
80966+ va_start(args, fmt);
80967+ ret = ____request_module(wait, NULL, fmt, args);
80968+ va_end(args);
80969+
80970+ return ret;
80971+}
80972+
80973 EXPORT_SYMBOL(__request_module);
80974 #endif /* CONFIG_MODULES */
80975
80976@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
80977 *
80978 * Thus the __user pointer cast is valid here.
80979 */
80980- sys_wait4(pid, (int __user *)&ret, 0, NULL);
80981+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
80982
80983 /*
80984 * If ret is 0, either ____call_usermodehelper failed and the
80985@@ -650,7 +703,7 @@ EXPORT_SYMBOL(call_usermodehelper);
80986 static int proc_cap_handler(struct ctl_table *table, int write,
80987 void __user *buffer, size_t *lenp, loff_t *ppos)
80988 {
80989- struct ctl_table t;
80990+ ctl_table_no_const t;
80991 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
80992 kernel_cap_t new_cap;
80993 int err, i;
80994diff --git a/kernel/kprobes.c b/kernel/kprobes.c
80995index 6e33498..3133bd3 100644
80996--- a/kernel/kprobes.c
80997+++ b/kernel/kprobes.c
80998@@ -31,6 +31,9 @@
80999 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81000 * <prasanna@in.ibm.com> added function-return probes.
81001 */
81002+#ifdef CONFIG_GRKERNSEC_HIDESYM
81003+#define __INCLUDED_BY_HIDESYM 1
81004+#endif
81005 #include <linux/kprobes.h>
81006 #include <linux/hash.h>
81007 #include <linux/init.h>
81008@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81009 * kernel image and loaded module images reside. This is required
81010 * so x86_64 can correctly handle the %rip-relative fixups.
81011 */
81012- kip->insns = module_alloc(PAGE_SIZE);
81013+ kip->insns = module_alloc_exec(PAGE_SIZE);
81014 if (!kip->insns) {
81015 kfree(kip);
81016 return NULL;
81017@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81018 */
81019 if (!list_is_singular(&kip->list)) {
81020 list_del(&kip->list);
81021- module_free(NULL, kip->insns);
81022+ module_free_exec(NULL, kip->insns);
81023 kfree(kip);
81024 }
81025 return 1;
81026@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81027 {
81028 int i, err = 0;
81029 unsigned long offset = 0, size = 0;
81030- char *modname, namebuf[128];
81031+ char *modname, namebuf[KSYM_NAME_LEN];
81032 const char *symbol_name;
81033 void *addr;
81034 struct kprobe_blackpoint *kb;
81035@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81036 kprobe_type = "k";
81037
81038 if (sym)
81039- seq_printf(pi, "%p %s %s+0x%x %s ",
81040+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81041 p->addr, kprobe_type, sym, offset,
81042 (modname ? modname : " "));
81043 else
81044- seq_printf(pi, "%p %s %p ",
81045+ seq_printf(pi, "%pK %s %pK ",
81046 p->addr, kprobe_type, p->addr);
81047
81048 if (!pp)
81049@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81050 const char *sym = NULL;
81051 unsigned int i = *(loff_t *) v;
81052 unsigned long offset = 0;
81053- char *modname, namebuf[128];
81054+ char *modname, namebuf[KSYM_NAME_LEN];
81055
81056 head = &kprobe_table[i];
81057 preempt_disable();
81058diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81059index 6ada93c..dce7d5d 100644
81060--- a/kernel/ksysfs.c
81061+++ b/kernel/ksysfs.c
81062@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81063 {
81064 if (count+1 > UEVENT_HELPER_PATH_LEN)
81065 return -ENOENT;
81066+ if (!capable(CAP_SYS_ADMIN))
81067+ return -EPERM;
81068 memcpy(uevent_helper, buf, count);
81069 uevent_helper[count] = '\0';
81070 if (count && uevent_helper[count-1] == '\n')
81071@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81072 return count;
81073 }
81074
81075-static struct bin_attribute notes_attr = {
81076+static bin_attribute_no_const notes_attr __read_only = {
81077 .attr = {
81078 .name = "notes",
81079 .mode = S_IRUGO,
81080diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81081index e16c45b..6f49c48 100644
81082--- a/kernel/lockdep.c
81083+++ b/kernel/lockdep.c
81084@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81085 end = (unsigned long) &_end,
81086 addr = (unsigned long) obj;
81087
81088+#ifdef CONFIG_PAX_KERNEXEC
81089+ start = ktla_ktva(start);
81090+#endif
81091+
81092 /*
81093 * static variable?
81094 */
81095@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81096 if (!static_obj(lock->key)) {
81097 debug_locks_off();
81098 printk("INFO: trying to register non-static key.\n");
81099+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81100 printk("the code is fine but needs lockdep annotation.\n");
81101 printk("turning off the locking correctness validator.\n");
81102 dump_stack();
81103@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81104 if (!class)
81105 return 0;
81106 }
81107- atomic_inc((atomic_t *)&class->ops);
81108+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81109 if (very_verbose(class)) {
81110 printk("\nacquire class [%p] %s", class->key, class->name);
81111 if (class->name_version > 1)
81112diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81113index b2c71c5..7b88d63 100644
81114--- a/kernel/lockdep_proc.c
81115+++ b/kernel/lockdep_proc.c
81116@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81117 return 0;
81118 }
81119
81120- seq_printf(m, "%p", class->key);
81121+ seq_printf(m, "%pK", class->key);
81122 #ifdef CONFIG_DEBUG_LOCKDEP
81123 seq_printf(m, " OPS:%8ld", class->ops);
81124 #endif
81125@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81126
81127 list_for_each_entry(entry, &class->locks_after, entry) {
81128 if (entry->distance == 1) {
81129- seq_printf(m, " -> [%p] ", entry->class->key);
81130+ seq_printf(m, " -> [%pK] ", entry->class->key);
81131 print_name(m, entry->class);
81132 seq_puts(m, "\n");
81133 }
81134@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81135 if (!class->key)
81136 continue;
81137
81138- seq_printf(m, "[%p] ", class->key);
81139+ seq_printf(m, "[%pK] ", class->key);
81140 print_name(m, class);
81141 seq_puts(m, "\n");
81142 }
81143@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81144 if (!i)
81145 seq_line(m, '-', 40-namelen, namelen);
81146
81147- snprintf(ip, sizeof(ip), "[<%p>]",
81148+ snprintf(ip, sizeof(ip), "[<%pK>]",
81149 (void *)class->contention_point[i]);
81150 seq_printf(m, "%40s %14lu %29s %pS\n",
81151 name, stats->contention_point[i],
81152@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81153 if (!i)
81154 seq_line(m, '-', 40-namelen, namelen);
81155
81156- snprintf(ip, sizeof(ip), "[<%p>]",
81157+ snprintf(ip, sizeof(ip), "[<%pK>]",
81158 (void *)class->contending_point[i]);
81159 seq_printf(m, "%40s %14lu %29s %pS\n",
81160 name, stats->contending_point[i],
81161diff --git a/kernel/module.c b/kernel/module.c
81162index 2069158..71101bb 100644
81163--- a/kernel/module.c
81164+++ b/kernel/module.c
81165@@ -61,6 +61,7 @@
81166 #include <linux/pfn.h>
81167 #include <linux/bsearch.h>
81168 #include <linux/fips.h>
81169+#include <linux/grsecurity.h>
81170 #include <uapi/linux/module.h>
81171 #include "module-internal.h"
81172
81173@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81174
81175 /* Bounds of module allocation, for speeding __module_address.
81176 * Protected by module_mutex. */
81177-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81178+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81179+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81180
81181 int register_module_notifier(struct notifier_block * nb)
81182 {
81183@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81184 return true;
81185
81186 list_for_each_entry_rcu(mod, &modules, list) {
81187- struct symsearch arr[] = {
81188+ struct symsearch modarr[] = {
81189 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81190 NOT_GPL_ONLY, false },
81191 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81192@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81193 if (mod->state == MODULE_STATE_UNFORMED)
81194 continue;
81195
81196- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81197+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81198 return true;
81199 }
81200 return false;
81201@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81202 if (!pcpusec->sh_size)
81203 return 0;
81204
81205- if (align > PAGE_SIZE) {
81206+ if (align-1 >= PAGE_SIZE) {
81207 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81208 mod->name, align, PAGE_SIZE);
81209 align = PAGE_SIZE;
81210@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81211 static ssize_t show_coresize(struct module_attribute *mattr,
81212 struct module_kobject *mk, char *buffer)
81213 {
81214- return sprintf(buffer, "%u\n", mk->mod->core_size);
81215+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81216 }
81217
81218 static struct module_attribute modinfo_coresize =
81219@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81220 static ssize_t show_initsize(struct module_attribute *mattr,
81221 struct module_kobject *mk, char *buffer)
81222 {
81223- return sprintf(buffer, "%u\n", mk->mod->init_size);
81224+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81225 }
81226
81227 static struct module_attribute modinfo_initsize =
81228@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81229 */
81230 #ifdef CONFIG_SYSFS
81231
81232-#ifdef CONFIG_KALLSYMS
81233+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81234 static inline bool sect_empty(const Elf_Shdr *sect)
81235 {
81236 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81237@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81238 {
81239 unsigned int notes, loaded, i;
81240 struct module_notes_attrs *notes_attrs;
81241- struct bin_attribute *nattr;
81242+ bin_attribute_no_const *nattr;
81243
81244 /* failed to create section attributes, so can't create notes */
81245 if (!mod->sect_attrs)
81246@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81247 static int module_add_modinfo_attrs(struct module *mod)
81248 {
81249 struct module_attribute *attr;
81250- struct module_attribute *temp_attr;
81251+ module_attribute_no_const *temp_attr;
81252 int error = 0;
81253 int i;
81254
81255@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81256
81257 static void unset_module_core_ro_nx(struct module *mod)
81258 {
81259- set_page_attributes(mod->module_core + mod->core_text_size,
81260- mod->module_core + mod->core_size,
81261+ set_page_attributes(mod->module_core_rw,
81262+ mod->module_core_rw + mod->core_size_rw,
81263 set_memory_x);
81264- set_page_attributes(mod->module_core,
81265- mod->module_core + mod->core_ro_size,
81266+ set_page_attributes(mod->module_core_rx,
81267+ mod->module_core_rx + mod->core_size_rx,
81268 set_memory_rw);
81269 }
81270
81271 static void unset_module_init_ro_nx(struct module *mod)
81272 {
81273- set_page_attributes(mod->module_init + mod->init_text_size,
81274- mod->module_init + mod->init_size,
81275+ set_page_attributes(mod->module_init_rw,
81276+ mod->module_init_rw + mod->init_size_rw,
81277 set_memory_x);
81278- set_page_attributes(mod->module_init,
81279- mod->module_init + mod->init_ro_size,
81280+ set_page_attributes(mod->module_init_rx,
81281+ mod->module_init_rx + mod->init_size_rx,
81282 set_memory_rw);
81283 }
81284
81285@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81286 list_for_each_entry_rcu(mod, &modules, list) {
81287 if (mod->state == MODULE_STATE_UNFORMED)
81288 continue;
81289- if ((mod->module_core) && (mod->core_text_size)) {
81290- set_page_attributes(mod->module_core,
81291- mod->module_core + mod->core_text_size,
81292+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81293+ set_page_attributes(mod->module_core_rx,
81294+ mod->module_core_rx + mod->core_size_rx,
81295 set_memory_rw);
81296 }
81297- if ((mod->module_init) && (mod->init_text_size)) {
81298- set_page_attributes(mod->module_init,
81299- mod->module_init + mod->init_text_size,
81300+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81301+ set_page_attributes(mod->module_init_rx,
81302+ mod->module_init_rx + mod->init_size_rx,
81303 set_memory_rw);
81304 }
81305 }
81306@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81307 list_for_each_entry_rcu(mod, &modules, list) {
81308 if (mod->state == MODULE_STATE_UNFORMED)
81309 continue;
81310- if ((mod->module_core) && (mod->core_text_size)) {
81311- set_page_attributes(mod->module_core,
81312- mod->module_core + mod->core_text_size,
81313+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81314+ set_page_attributes(mod->module_core_rx,
81315+ mod->module_core_rx + mod->core_size_rx,
81316 set_memory_ro);
81317 }
81318- if ((mod->module_init) && (mod->init_text_size)) {
81319- set_page_attributes(mod->module_init,
81320- mod->module_init + mod->init_text_size,
81321+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81322+ set_page_attributes(mod->module_init_rx,
81323+ mod->module_init_rx + mod->init_size_rx,
81324 set_memory_ro);
81325 }
81326 }
81327@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81328
81329 /* This may be NULL, but that's OK */
81330 unset_module_init_ro_nx(mod);
81331- module_free(mod, mod->module_init);
81332+ module_free(mod, mod->module_init_rw);
81333+ module_free_exec(mod, mod->module_init_rx);
81334 kfree(mod->args);
81335 percpu_modfree(mod);
81336
81337 /* Free lock-classes: */
81338- lockdep_free_key_range(mod->module_core, mod->core_size);
81339+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81340+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81341
81342 /* Finally, free the core (containing the module structure) */
81343 unset_module_core_ro_nx(mod);
81344- module_free(mod, mod->module_core);
81345+ module_free_exec(mod, mod->module_core_rx);
81346+ module_free(mod, mod->module_core_rw);
81347
81348 #ifdef CONFIG_MPU
81349 update_protections(current->mm);
81350@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81351 int ret = 0;
81352 const struct kernel_symbol *ksym;
81353
81354+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81355+ int is_fs_load = 0;
81356+ int register_filesystem_found = 0;
81357+ char *p;
81358+
81359+ p = strstr(mod->args, "grsec_modharden_fs");
81360+ if (p) {
81361+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81362+ /* copy \0 as well */
81363+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81364+ is_fs_load = 1;
81365+ }
81366+#endif
81367+
81368 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81369 const char *name = info->strtab + sym[i].st_name;
81370
81371+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81372+ /* it's a real shame this will never get ripped and copied
81373+ upstream! ;(
81374+ */
81375+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81376+ register_filesystem_found = 1;
81377+#endif
81378+
81379 switch (sym[i].st_shndx) {
81380 case SHN_COMMON:
81381 /* We compiled with -fno-common. These are not
81382@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81383 ksym = resolve_symbol_wait(mod, info, name);
81384 /* Ok if resolved. */
81385 if (ksym && !IS_ERR(ksym)) {
81386+ pax_open_kernel();
81387 sym[i].st_value = ksym->value;
81388+ pax_close_kernel();
81389 break;
81390 }
81391
81392@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81393 secbase = (unsigned long)mod_percpu(mod);
81394 else
81395 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81396+ pax_open_kernel();
81397 sym[i].st_value += secbase;
81398+ pax_close_kernel();
81399 break;
81400 }
81401 }
81402
81403+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81404+ if (is_fs_load && !register_filesystem_found) {
81405+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81406+ ret = -EPERM;
81407+ }
81408+#endif
81409+
81410 return ret;
81411 }
81412
81413@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81414 || s->sh_entsize != ~0UL
81415 || strstarts(sname, ".init"))
81416 continue;
81417- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81418+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81419+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81420+ else
81421+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81422 pr_debug("\t%s\n", sname);
81423 }
81424- switch (m) {
81425- case 0: /* executable */
81426- mod->core_size = debug_align(mod->core_size);
81427- mod->core_text_size = mod->core_size;
81428- break;
81429- case 1: /* RO: text and ro-data */
81430- mod->core_size = debug_align(mod->core_size);
81431- mod->core_ro_size = mod->core_size;
81432- break;
81433- case 3: /* whole core */
81434- mod->core_size = debug_align(mod->core_size);
81435- break;
81436- }
81437 }
81438
81439 pr_debug("Init section allocation order:\n");
81440@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81441 || s->sh_entsize != ~0UL
81442 || !strstarts(sname, ".init"))
81443 continue;
81444- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81445- | INIT_OFFSET_MASK);
81446+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81447+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81448+ else
81449+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81450+ s->sh_entsize |= INIT_OFFSET_MASK;
81451 pr_debug("\t%s\n", sname);
81452 }
81453- switch (m) {
81454- case 0: /* executable */
81455- mod->init_size = debug_align(mod->init_size);
81456- mod->init_text_size = mod->init_size;
81457- break;
81458- case 1: /* RO: text and ro-data */
81459- mod->init_size = debug_align(mod->init_size);
81460- mod->init_ro_size = mod->init_size;
81461- break;
81462- case 3: /* whole init */
81463- mod->init_size = debug_align(mod->init_size);
81464- break;
81465- }
81466 }
81467 }
81468
81469@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81470
81471 /* Put symbol section at end of init part of module. */
81472 symsect->sh_flags |= SHF_ALLOC;
81473- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81474+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81475 info->index.sym) | INIT_OFFSET_MASK;
81476 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81477
81478@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81479 }
81480
81481 /* Append room for core symbols at end of core part. */
81482- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81483- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81484- mod->core_size += strtab_size;
81485+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81486+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81487+ mod->core_size_rx += strtab_size;
81488
81489 /* Put string table section at end of init part of module. */
81490 strsect->sh_flags |= SHF_ALLOC;
81491- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81492+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81493 info->index.str) | INIT_OFFSET_MASK;
81494 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81495 }
81496@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81497 /* Make sure we get permanent strtab: don't use info->strtab. */
81498 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81499
81500+ pax_open_kernel();
81501+
81502 /* Set types up while we still have access to sections. */
81503 for (i = 0; i < mod->num_symtab; i++)
81504 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81505
81506- mod->core_symtab = dst = mod->module_core + info->symoffs;
81507- mod->core_strtab = s = mod->module_core + info->stroffs;
81508+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81509+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81510 src = mod->symtab;
81511 for (ndst = i = 0; i < mod->num_symtab; i++) {
81512 if (i == 0 ||
81513@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81514 }
81515 }
81516 mod->core_num_syms = ndst;
81517+
81518+ pax_close_kernel();
81519 }
81520 #else
81521 static inline void layout_symtab(struct module *mod, struct load_info *info)
81522@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81523 return vmalloc_exec(size);
81524 }
81525
81526-static void *module_alloc_update_bounds(unsigned long size)
81527+static void *module_alloc_update_bounds_rw(unsigned long size)
81528 {
81529 void *ret = module_alloc(size);
81530
81531 if (ret) {
81532 mutex_lock(&module_mutex);
81533 /* Update module bounds. */
81534- if ((unsigned long)ret < module_addr_min)
81535- module_addr_min = (unsigned long)ret;
81536- if ((unsigned long)ret + size > module_addr_max)
81537- module_addr_max = (unsigned long)ret + size;
81538+ if ((unsigned long)ret < module_addr_min_rw)
81539+ module_addr_min_rw = (unsigned long)ret;
81540+ if ((unsigned long)ret + size > module_addr_max_rw)
81541+ module_addr_max_rw = (unsigned long)ret + size;
81542+ mutex_unlock(&module_mutex);
81543+ }
81544+ return ret;
81545+}
81546+
81547+static void *module_alloc_update_bounds_rx(unsigned long size)
81548+{
81549+ void *ret = module_alloc_exec(size);
81550+
81551+ if (ret) {
81552+ mutex_lock(&module_mutex);
81553+ /* Update module bounds. */
81554+ if ((unsigned long)ret < module_addr_min_rx)
81555+ module_addr_min_rx = (unsigned long)ret;
81556+ if ((unsigned long)ret + size > module_addr_max_rx)
81557+ module_addr_max_rx = (unsigned long)ret + size;
81558 mutex_unlock(&module_mutex);
81559 }
81560 return ret;
81561@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81562 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81563 {
81564 const char *modmagic = get_modinfo(info, "vermagic");
81565+ const char *license = get_modinfo(info, "license");
81566 int err;
81567
81568+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81569+ if (!license || !license_is_gpl_compatible(license))
81570+ return -ENOEXEC;
81571+#endif
81572+
81573 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81574 modmagic = NULL;
81575
81576@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81577 }
81578
81579 /* Set up license info based on the info section */
81580- set_license(mod, get_modinfo(info, "license"));
81581+ set_license(mod, license);
81582
81583 return 0;
81584 }
81585@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81586 void *ptr;
81587
81588 /* Do the allocs. */
81589- ptr = module_alloc_update_bounds(mod->core_size);
81590+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81591 /*
81592 * The pointer to this block is stored in the module structure
81593 * which is inside the block. Just mark it as not being a
81594@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81595 if (!ptr)
81596 return -ENOMEM;
81597
81598- memset(ptr, 0, mod->core_size);
81599- mod->module_core = ptr;
81600+ memset(ptr, 0, mod->core_size_rw);
81601+ mod->module_core_rw = ptr;
81602
81603- if (mod->init_size) {
81604- ptr = module_alloc_update_bounds(mod->init_size);
81605+ if (mod->init_size_rw) {
81606+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81607 /*
81608 * The pointer to this block is stored in the module structure
81609 * which is inside the block. This block doesn't need to be
81610@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81611 */
81612 kmemleak_ignore(ptr);
81613 if (!ptr) {
81614- module_free(mod, mod->module_core);
81615+ module_free(mod, mod->module_core_rw);
81616 return -ENOMEM;
81617 }
81618- memset(ptr, 0, mod->init_size);
81619- mod->module_init = ptr;
81620+ memset(ptr, 0, mod->init_size_rw);
81621+ mod->module_init_rw = ptr;
81622 } else
81623- mod->module_init = NULL;
81624+ mod->module_init_rw = NULL;
81625+
81626+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81627+ kmemleak_not_leak(ptr);
81628+ if (!ptr) {
81629+ if (mod->module_init_rw)
81630+ module_free(mod, mod->module_init_rw);
81631+ module_free(mod, mod->module_core_rw);
81632+ return -ENOMEM;
81633+ }
81634+
81635+ pax_open_kernel();
81636+ memset(ptr, 0, mod->core_size_rx);
81637+ pax_close_kernel();
81638+ mod->module_core_rx = ptr;
81639+
81640+ if (mod->init_size_rx) {
81641+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81642+ kmemleak_ignore(ptr);
81643+ if (!ptr && mod->init_size_rx) {
81644+ module_free_exec(mod, mod->module_core_rx);
81645+ if (mod->module_init_rw)
81646+ module_free(mod, mod->module_init_rw);
81647+ module_free(mod, mod->module_core_rw);
81648+ return -ENOMEM;
81649+ }
81650+
81651+ pax_open_kernel();
81652+ memset(ptr, 0, mod->init_size_rx);
81653+ pax_close_kernel();
81654+ mod->module_init_rx = ptr;
81655+ } else
81656+ mod->module_init_rx = NULL;
81657
81658 /* Transfer each section which specifies SHF_ALLOC */
81659 pr_debug("final section addresses:\n");
81660@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81661 if (!(shdr->sh_flags & SHF_ALLOC))
81662 continue;
81663
81664- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81665- dest = mod->module_init
81666- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81667- else
81668- dest = mod->module_core + shdr->sh_entsize;
81669+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81670+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81671+ dest = mod->module_init_rw
81672+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81673+ else
81674+ dest = mod->module_init_rx
81675+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81676+ } else {
81677+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81678+ dest = mod->module_core_rw + shdr->sh_entsize;
81679+ else
81680+ dest = mod->module_core_rx + shdr->sh_entsize;
81681+ }
81682+
81683+ if (shdr->sh_type != SHT_NOBITS) {
81684+
81685+#ifdef CONFIG_PAX_KERNEXEC
81686+#ifdef CONFIG_X86_64
81687+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81688+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81689+#endif
81690+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81691+ pax_open_kernel();
81692+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81693+ pax_close_kernel();
81694+ } else
81695+#endif
81696
81697- if (shdr->sh_type != SHT_NOBITS)
81698 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81699+ }
81700 /* Update sh_addr to point to copy in image. */
81701- shdr->sh_addr = (unsigned long)dest;
81702+
81703+#ifdef CONFIG_PAX_KERNEXEC
81704+ if (shdr->sh_flags & SHF_EXECINSTR)
81705+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81706+ else
81707+#endif
81708+
81709+ shdr->sh_addr = (unsigned long)dest;
81710 pr_debug("\t0x%lx %s\n",
81711 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81712 }
81713@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81714 * Do it before processing of module parameters, so the module
81715 * can provide parameter accessor functions of its own.
81716 */
81717- if (mod->module_init)
81718- flush_icache_range((unsigned long)mod->module_init,
81719- (unsigned long)mod->module_init
81720- + mod->init_size);
81721- flush_icache_range((unsigned long)mod->module_core,
81722- (unsigned long)mod->module_core + mod->core_size);
81723+ if (mod->module_init_rx)
81724+ flush_icache_range((unsigned long)mod->module_init_rx,
81725+ (unsigned long)mod->module_init_rx
81726+ + mod->init_size_rx);
81727+ flush_icache_range((unsigned long)mod->module_core_rx,
81728+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81729
81730 set_fs(old_fs);
81731 }
81732@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81733 static void module_deallocate(struct module *mod, struct load_info *info)
81734 {
81735 percpu_modfree(mod);
81736- module_free(mod, mod->module_init);
81737- module_free(mod, mod->module_core);
81738+ module_free_exec(mod, mod->module_init_rx);
81739+ module_free_exec(mod, mod->module_core_rx);
81740+ module_free(mod, mod->module_init_rw);
81741+ module_free(mod, mod->module_core_rw);
81742 }
81743
81744 int __weak module_finalize(const Elf_Ehdr *hdr,
81745@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81746 static int post_relocation(struct module *mod, const struct load_info *info)
81747 {
81748 /* Sort exception table now relocations are done. */
81749+ pax_open_kernel();
81750 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81751+ pax_close_kernel();
81752
81753 /* Copy relocated percpu area over. */
81754 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81755@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81756 MODULE_STATE_COMING, mod);
81757
81758 /* Set RO and NX regions for core */
81759- set_section_ro_nx(mod->module_core,
81760- mod->core_text_size,
81761- mod->core_ro_size,
81762- mod->core_size);
81763+ set_section_ro_nx(mod->module_core_rx,
81764+ mod->core_size_rx,
81765+ mod->core_size_rx,
81766+ mod->core_size_rx);
81767
81768 /* Set RO and NX regions for init */
81769- set_section_ro_nx(mod->module_init,
81770- mod->init_text_size,
81771- mod->init_ro_size,
81772- mod->init_size);
81773+ set_section_ro_nx(mod->module_init_rx,
81774+ mod->init_size_rx,
81775+ mod->init_size_rx,
81776+ mod->init_size_rx);
81777
81778 do_mod_ctors(mod);
81779 /* Start the module */
81780@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81781 mod->strtab = mod->core_strtab;
81782 #endif
81783 unset_module_init_ro_nx(mod);
81784- module_free(mod, mod->module_init);
81785- mod->module_init = NULL;
81786- mod->init_size = 0;
81787- mod->init_ro_size = 0;
81788- mod->init_text_size = 0;
81789+ module_free(mod, mod->module_init_rw);
81790+ module_free_exec(mod, mod->module_init_rx);
81791+ mod->module_init_rw = NULL;
81792+ mod->module_init_rx = NULL;
81793+ mod->init_size_rw = 0;
81794+ mod->init_size_rx = 0;
81795 mutex_unlock(&module_mutex);
81796 wake_up_all(&module_wq);
81797
81798@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81799 if (err)
81800 goto free_unload;
81801
81802+ /* Now copy in args */
81803+ mod->args = strndup_user(uargs, ~0UL >> 1);
81804+ if (IS_ERR(mod->args)) {
81805+ err = PTR_ERR(mod->args);
81806+ goto free_unload;
81807+ }
81808+
81809 /* Set up MODINFO_ATTR fields */
81810 setup_modinfo(mod, info);
81811
81812+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81813+ {
81814+ char *p, *p2;
81815+
81816+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81817+ 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);
81818+ err = -EPERM;
81819+ goto free_modinfo;
81820+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81821+ p += sizeof("grsec_modharden_normal") - 1;
81822+ p2 = strstr(p, "_");
81823+ if (p2) {
81824+ *p2 = '\0';
81825+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81826+ *p2 = '_';
81827+ }
81828+ err = -EPERM;
81829+ goto free_modinfo;
81830+ }
81831+ }
81832+#endif
81833+
81834 /* Fix up syms, so that st_value is a pointer to location. */
81835 err = simplify_symbols(mod, info);
81836 if (err < 0)
81837@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81838
81839 flush_module_icache(mod);
81840
81841- /* Now copy in args */
81842- mod->args = strndup_user(uargs, ~0UL >> 1);
81843- if (IS_ERR(mod->args)) {
81844- err = PTR_ERR(mod->args);
81845- goto free_arch_cleanup;
81846- }
81847-
81848 dynamic_debug_setup(info->debug, info->num_debug);
81849
81850 /* Finally it's fully formed, ready to start executing. */
81851@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81852 ddebug_cleanup:
81853 dynamic_debug_remove(info->debug);
81854 synchronize_sched();
81855- kfree(mod->args);
81856- free_arch_cleanup:
81857 module_arch_cleanup(mod);
81858 free_modinfo:
81859 free_modinfo(mod);
81860+ kfree(mod->args);
81861 free_unload:
81862 module_unload_free(mod);
81863 unlink_mod:
81864@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81865 unsigned long nextval;
81866
81867 /* At worse, next value is at end of module */
81868- if (within_module_init(addr, mod))
81869- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81870+ if (within_module_init_rx(addr, mod))
81871+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81872+ else if (within_module_init_rw(addr, mod))
81873+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81874+ else if (within_module_core_rx(addr, mod))
81875+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81876+ else if (within_module_core_rw(addr, mod))
81877+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81878 else
81879- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81880+ return NULL;
81881
81882 /* Scan for closest preceding symbol, and next symbol. (ELF
81883 starts real symbols at 1). */
81884@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81885 return 0;
81886
81887 seq_printf(m, "%s %u",
81888- mod->name, mod->init_size + mod->core_size);
81889+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81890 print_unload_info(m, mod);
81891
81892 /* Informative for users. */
81893@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81894 mod->state == MODULE_STATE_COMING ? "Loading":
81895 "Live");
81896 /* Used by oprofile and other similar tools. */
81897- seq_printf(m, " 0x%pK", mod->module_core);
81898+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81899
81900 /* Taints info */
81901 if (mod->taints)
81902@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81903
81904 static int __init proc_modules_init(void)
81905 {
81906+#ifndef CONFIG_GRKERNSEC_HIDESYM
81907+#ifdef CONFIG_GRKERNSEC_PROC_USER
81908+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81909+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81910+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81911+#else
81912 proc_create("modules", 0, NULL, &proc_modules_operations);
81913+#endif
81914+#else
81915+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81916+#endif
81917 return 0;
81918 }
81919 module_init(proc_modules_init);
81920@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81921 {
81922 struct module *mod;
81923
81924- if (addr < module_addr_min || addr > module_addr_max)
81925+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81926+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81927 return NULL;
81928
81929 list_for_each_entry_rcu(mod, &modules, list) {
81930 if (mod->state == MODULE_STATE_UNFORMED)
81931 continue;
81932- if (within_module_core(addr, mod)
81933- || within_module_init(addr, mod))
81934+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
81935 return mod;
81936 }
81937 return NULL;
81938@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
81939 */
81940 struct module *__module_text_address(unsigned long addr)
81941 {
81942- struct module *mod = __module_address(addr);
81943+ struct module *mod;
81944+
81945+#ifdef CONFIG_X86_32
81946+ addr = ktla_ktva(addr);
81947+#endif
81948+
81949+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
81950+ return NULL;
81951+
81952+ mod = __module_address(addr);
81953+
81954 if (mod) {
81955 /* Make sure it's within the text section. */
81956- if (!within(addr, mod->module_init, mod->init_text_size)
81957- && !within(addr, mod->module_core, mod->core_text_size))
81958+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
81959 mod = NULL;
81960 }
81961 return mod;
81962diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
81963index 7e3443f..b2a1e6b 100644
81964--- a/kernel/mutex-debug.c
81965+++ b/kernel/mutex-debug.c
81966@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
81967 }
81968
81969 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81970- struct thread_info *ti)
81971+ struct task_struct *task)
81972 {
81973 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
81974
81975 /* Mark the current thread as blocked on the lock: */
81976- ti->task->blocked_on = waiter;
81977+ task->blocked_on = waiter;
81978 }
81979
81980 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81981- struct thread_info *ti)
81982+ struct task_struct *task)
81983 {
81984 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
81985- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
81986- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
81987- ti->task->blocked_on = NULL;
81988+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
81989+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
81990+ task->blocked_on = NULL;
81991
81992 list_del_init(&waiter->list);
81993 waiter->task = NULL;
81994diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
81995index 0799fd3..d06ae3b 100644
81996--- a/kernel/mutex-debug.h
81997+++ b/kernel/mutex-debug.h
81998@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
81999 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82000 extern void debug_mutex_add_waiter(struct mutex *lock,
82001 struct mutex_waiter *waiter,
82002- struct thread_info *ti);
82003+ struct task_struct *task);
82004 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82005- struct thread_info *ti);
82006+ struct task_struct *task);
82007 extern void debug_mutex_unlock(struct mutex *lock);
82008 extern void debug_mutex_init(struct mutex *lock, const char *name,
82009 struct lock_class_key *key);
82010diff --git a/kernel/mutex.c b/kernel/mutex.c
82011index a52ee7bb..f361f16 100644
82012--- a/kernel/mutex.c
82013+++ b/kernel/mutex.c
82014@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82015 node->locked = 1;
82016 return;
82017 }
82018- ACCESS_ONCE(prev->next) = node;
82019+ ACCESS_ONCE_RW(prev->next) = node;
82020 smp_wmb();
82021 /* Wait until the lock holder passes the lock down */
82022 while (!ACCESS_ONCE(node->locked))
82023@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82024 while (!(next = ACCESS_ONCE(node->next)))
82025 arch_mutex_cpu_relax();
82026 }
82027- ACCESS_ONCE(next->locked) = 1;
82028+ ACCESS_ONCE_RW(next->locked) = 1;
82029 smp_wmb();
82030 }
82031
82032@@ -514,7 +514,7 @@ slowpath:
82033 spin_lock_mutex(&lock->wait_lock, flags);
82034
82035 debug_mutex_lock_common(lock, &waiter);
82036- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82037+ debug_mutex_add_waiter(lock, &waiter, task);
82038
82039 /* add waiting tasks to the end of the waitqueue (FIFO): */
82040 list_add_tail(&waiter.list, &lock->wait_list);
82041@@ -565,7 +565,7 @@ slowpath:
82042 done:
82043 lock_acquired(&lock->dep_map, ip);
82044 /* got the lock - rejoice! */
82045- mutex_remove_waiter(lock, &waiter, current_thread_info());
82046+ mutex_remove_waiter(lock, &waiter, task);
82047 mutex_set_owner(lock);
82048
82049 if (!__builtin_constant_p(ww_ctx == NULL)) {
82050@@ -604,7 +604,7 @@ done:
82051 return 0;
82052
82053 err:
82054- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82055+ mutex_remove_waiter(lock, &waiter, task);
82056 spin_unlock_mutex(&lock->wait_lock, flags);
82057 debug_mutex_free_waiter(&waiter);
82058 mutex_release(&lock->dep_map, 1, ip);
82059diff --git a/kernel/notifier.c b/kernel/notifier.c
82060index 2d5cc4c..d9ea600 100644
82061--- a/kernel/notifier.c
82062+++ b/kernel/notifier.c
82063@@ -5,6 +5,7 @@
82064 #include <linux/rcupdate.h>
82065 #include <linux/vmalloc.h>
82066 #include <linux/reboot.h>
82067+#include <linux/mm.h>
82068
82069 /*
82070 * Notifier list for kernel code which wants to be called
82071@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82072 while ((*nl) != NULL) {
82073 if (n->priority > (*nl)->priority)
82074 break;
82075- nl = &((*nl)->next);
82076+ nl = (struct notifier_block **)&((*nl)->next);
82077 }
82078- n->next = *nl;
82079+ pax_open_kernel();
82080+ *(const void **)&n->next = *nl;
82081 rcu_assign_pointer(*nl, n);
82082+ pax_close_kernel();
82083 return 0;
82084 }
82085
82086@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82087 return 0;
82088 if (n->priority > (*nl)->priority)
82089 break;
82090- nl = &((*nl)->next);
82091+ nl = (struct notifier_block **)&((*nl)->next);
82092 }
82093- n->next = *nl;
82094+ pax_open_kernel();
82095+ *(const void **)&n->next = *nl;
82096 rcu_assign_pointer(*nl, n);
82097+ pax_close_kernel();
82098 return 0;
82099 }
82100
82101@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82102 {
82103 while ((*nl) != NULL) {
82104 if ((*nl) == n) {
82105+ pax_open_kernel();
82106 rcu_assign_pointer(*nl, n->next);
82107+ pax_close_kernel();
82108 return 0;
82109 }
82110- nl = &((*nl)->next);
82111+ nl = (struct notifier_block **)&((*nl)->next);
82112 }
82113 return -ENOENT;
82114 }
82115diff --git a/kernel/panic.c b/kernel/panic.c
82116index 8018646..b6a5b4f 100644
82117--- a/kernel/panic.c
82118+++ b/kernel/panic.c
82119@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82120 disable_trace_on_warning();
82121
82122 pr_warn("------------[ cut here ]------------\n");
82123- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82124+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82125 raw_smp_processor_id(), current->pid, file, line, caller);
82126
82127 if (args)
82128@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82129 */
82130 void __stack_chk_fail(void)
82131 {
82132- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82133+ dump_stack();
82134+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82135 __builtin_return_address(0));
82136 }
82137 EXPORT_SYMBOL(__stack_chk_fail);
82138diff --git a/kernel/pid.c b/kernel/pid.c
82139index ebe5e80..5d6d634 100644
82140--- a/kernel/pid.c
82141+++ b/kernel/pid.c
82142@@ -33,6 +33,7 @@
82143 #include <linux/rculist.h>
82144 #include <linux/bootmem.h>
82145 #include <linux/hash.h>
82146+#include <linux/security.h>
82147 #include <linux/pid_namespace.h>
82148 #include <linux/init_task.h>
82149 #include <linux/syscalls.h>
82150@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82151
82152 int pid_max = PID_MAX_DEFAULT;
82153
82154-#define RESERVED_PIDS 300
82155+#define RESERVED_PIDS 500
82156
82157 int pid_max_min = RESERVED_PIDS + 1;
82158 int pid_max_max = PID_MAX_LIMIT;
82159@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
82160 */
82161 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82162 {
82163+ struct task_struct *task;
82164+
82165 rcu_lockdep_assert(rcu_read_lock_held(),
82166 "find_task_by_pid_ns() needs rcu_read_lock()"
82167 " protection");
82168- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82169+
82170+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82171+
82172+ if (gr_pid_is_chrooted(task))
82173+ return NULL;
82174+
82175+ return task;
82176 }
82177
82178 struct task_struct *find_task_by_vpid(pid_t vnr)
82179@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82180 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82181 }
82182
82183+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82184+{
82185+ rcu_lockdep_assert(rcu_read_lock_held(),
82186+ "find_task_by_pid_ns() needs rcu_read_lock()"
82187+ " protection");
82188+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82189+}
82190+
82191 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82192 {
82193 struct pid *pid;
82194diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82195index 601bb36..f7e6f34 100644
82196--- a/kernel/pid_namespace.c
82197+++ b/kernel/pid_namespace.c
82198@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82199 void __user *buffer, size_t *lenp, loff_t *ppos)
82200 {
82201 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82202- struct ctl_table tmp = *table;
82203+ ctl_table_no_const tmp = *table;
82204
82205 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82206 return -EPERM;
82207diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82208index c7f31aa..2b44977 100644
82209--- a/kernel/posix-cpu-timers.c
82210+++ b/kernel/posix-cpu-timers.c
82211@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82212
82213 static __init int init_posix_cpu_timers(void)
82214 {
82215- struct k_clock process = {
82216+ static struct k_clock process = {
82217 .clock_getres = process_cpu_clock_getres,
82218 .clock_get = process_cpu_clock_get,
82219 .timer_create = process_cpu_timer_create,
82220 .nsleep = process_cpu_nsleep,
82221 .nsleep_restart = process_cpu_nsleep_restart,
82222 };
82223- struct k_clock thread = {
82224+ static struct k_clock thread = {
82225 .clock_getres = thread_cpu_clock_getres,
82226 .clock_get = thread_cpu_clock_get,
82227 .timer_create = thread_cpu_timer_create,
82228diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82229index 424c2d4..679242f 100644
82230--- a/kernel/posix-timers.c
82231+++ b/kernel/posix-timers.c
82232@@ -43,6 +43,7 @@
82233 #include <linux/hash.h>
82234 #include <linux/posix-clock.h>
82235 #include <linux/posix-timers.h>
82236+#include <linux/grsecurity.h>
82237 #include <linux/syscalls.h>
82238 #include <linux/wait.h>
82239 #include <linux/workqueue.h>
82240@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82241 * which we beg off on and pass to do_sys_settimeofday().
82242 */
82243
82244-static struct k_clock posix_clocks[MAX_CLOCKS];
82245+static struct k_clock *posix_clocks[MAX_CLOCKS];
82246
82247 /*
82248 * These ones are defined below.
82249@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82250 */
82251 static __init int init_posix_timers(void)
82252 {
82253- struct k_clock clock_realtime = {
82254+ static struct k_clock clock_realtime = {
82255 .clock_getres = hrtimer_get_res,
82256 .clock_get = posix_clock_realtime_get,
82257 .clock_set = posix_clock_realtime_set,
82258@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82259 .timer_get = common_timer_get,
82260 .timer_del = common_timer_del,
82261 };
82262- struct k_clock clock_monotonic = {
82263+ static struct k_clock clock_monotonic = {
82264 .clock_getres = hrtimer_get_res,
82265 .clock_get = posix_ktime_get_ts,
82266 .nsleep = common_nsleep,
82267@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82268 .timer_get = common_timer_get,
82269 .timer_del = common_timer_del,
82270 };
82271- struct k_clock clock_monotonic_raw = {
82272+ static struct k_clock clock_monotonic_raw = {
82273 .clock_getres = hrtimer_get_res,
82274 .clock_get = posix_get_monotonic_raw,
82275 };
82276- struct k_clock clock_realtime_coarse = {
82277+ static struct k_clock clock_realtime_coarse = {
82278 .clock_getres = posix_get_coarse_res,
82279 .clock_get = posix_get_realtime_coarse,
82280 };
82281- struct k_clock clock_monotonic_coarse = {
82282+ static struct k_clock clock_monotonic_coarse = {
82283 .clock_getres = posix_get_coarse_res,
82284 .clock_get = posix_get_monotonic_coarse,
82285 };
82286- struct k_clock clock_tai = {
82287+ static struct k_clock clock_tai = {
82288 .clock_getres = hrtimer_get_res,
82289 .clock_get = posix_get_tai,
82290 .nsleep = common_nsleep,
82291@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82292 .timer_get = common_timer_get,
82293 .timer_del = common_timer_del,
82294 };
82295- struct k_clock clock_boottime = {
82296+ static struct k_clock clock_boottime = {
82297 .clock_getres = hrtimer_get_res,
82298 .clock_get = posix_get_boottime,
82299 .nsleep = common_nsleep,
82300@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82301 return;
82302 }
82303
82304- posix_clocks[clock_id] = *new_clock;
82305+ posix_clocks[clock_id] = new_clock;
82306 }
82307 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82308
82309@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82310 return (id & CLOCKFD_MASK) == CLOCKFD ?
82311 &clock_posix_dynamic : &clock_posix_cpu;
82312
82313- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82314+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82315 return NULL;
82316- return &posix_clocks[id];
82317+ return posix_clocks[id];
82318 }
82319
82320 static int common_timer_create(struct k_itimer *new_timer)
82321@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82322 struct k_clock *kc = clockid_to_kclock(which_clock);
82323 struct k_itimer *new_timer;
82324 int error, new_timer_id;
82325- sigevent_t event;
82326+ sigevent_t event = { };
82327 int it_id_set = IT_ID_NOT_SET;
82328
82329 if (!kc)
82330@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82331 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82332 return -EFAULT;
82333
82334+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82335+ have their clock_set fptr set to a nosettime dummy function
82336+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82337+ call common_clock_set, which calls do_sys_settimeofday, which
82338+ we hook
82339+ */
82340+
82341 return kc->clock_set(which_clock, &new_tp);
82342 }
82343
82344diff --git a/kernel/power/process.c b/kernel/power/process.c
82345index 06ec886..9dba35e 100644
82346--- a/kernel/power/process.c
82347+++ b/kernel/power/process.c
82348@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82349 unsigned int elapsed_msecs;
82350 bool wakeup = false;
82351 int sleep_usecs = USEC_PER_MSEC;
82352+ bool timedout = false;
82353
82354 do_gettimeofday(&start);
82355
82356@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82357
82358 while (true) {
82359 todo = 0;
82360+ if (time_after(jiffies, end_time))
82361+ timedout = true;
82362 read_lock(&tasklist_lock);
82363 do_each_thread(g, p) {
82364 if (p == current || !freeze_task(p))
82365 continue;
82366
82367- if (!freezer_should_skip(p))
82368+ if (!freezer_should_skip(p)) {
82369 todo++;
82370+ if (timedout) {
82371+ printk(KERN_ERR "Task refusing to freeze:\n");
82372+ sched_show_task(p);
82373+ }
82374+ }
82375 } while_each_thread(g, p);
82376 read_unlock(&tasklist_lock);
82377
82378@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82379 todo += wq_busy;
82380 }
82381
82382- if (!todo || time_after(jiffies, end_time))
82383+ if (!todo || timedout)
82384 break;
82385
82386 if (pm_wakeup_pending()) {
82387diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82388index 5b5a708..ec7637e 100644
82389--- a/kernel/printk/printk.c
82390+++ b/kernel/printk/printk.c
82391@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82392 if (from_file && type != SYSLOG_ACTION_OPEN)
82393 return 0;
82394
82395+#ifdef CONFIG_GRKERNSEC_DMESG
82396+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82397+ return -EPERM;
82398+#endif
82399+
82400 if (syslog_action_restricted(type)) {
82401 if (capable(CAP_SYSLOG))
82402 return 0;
82403diff --git a/kernel/profile.c b/kernel/profile.c
82404index 6631e1e..310c266 100644
82405--- a/kernel/profile.c
82406+++ b/kernel/profile.c
82407@@ -37,7 +37,7 @@ struct profile_hit {
82408 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82409 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82410
82411-static atomic_t *prof_buffer;
82412+static atomic_unchecked_t *prof_buffer;
82413 static unsigned long prof_len, prof_shift;
82414
82415 int prof_on __read_mostly;
82416@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82417 hits[i].pc = 0;
82418 continue;
82419 }
82420- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82421+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82422 hits[i].hits = hits[i].pc = 0;
82423 }
82424 }
82425@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82426 * Add the current hit(s) and flush the write-queue out
82427 * to the global buffer:
82428 */
82429- atomic_add(nr_hits, &prof_buffer[pc]);
82430+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82431 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82432- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82433+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82434 hits[i].pc = hits[i].hits = 0;
82435 }
82436 out:
82437@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82438 {
82439 unsigned long pc;
82440 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82441- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82442+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82443 }
82444 #endif /* !CONFIG_SMP */
82445
82446@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82447 return -EFAULT;
82448 buf++; p++; count--; read++;
82449 }
82450- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82451+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82452 if (copy_to_user(buf, (void *)pnt, count))
82453 return -EFAULT;
82454 read += count;
82455@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82456 }
82457 #endif
82458 profile_discard_flip_buffers();
82459- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82460+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82461 return count;
82462 }
82463
82464diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82465index a146ee3..ffed4c3 100644
82466--- a/kernel/ptrace.c
82467+++ b/kernel/ptrace.c
82468@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82469 if (seize)
82470 flags |= PT_SEIZED;
82471 rcu_read_lock();
82472- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82473+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82474 flags |= PT_PTRACE_CAP;
82475 rcu_read_unlock();
82476 task->ptrace = flags;
82477@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82478 break;
82479 return -EIO;
82480 }
82481- if (copy_to_user(dst, buf, retval))
82482+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82483 return -EFAULT;
82484 copied += retval;
82485 src += retval;
82486@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82487 bool seized = child->ptrace & PT_SEIZED;
82488 int ret = -EIO;
82489 siginfo_t siginfo, *si;
82490- void __user *datavp = (void __user *) data;
82491+ void __user *datavp = (__force void __user *) data;
82492 unsigned long __user *datalp = datavp;
82493 unsigned long flags;
82494
82495@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82496 goto out;
82497 }
82498
82499+ if (gr_handle_ptrace(child, request)) {
82500+ ret = -EPERM;
82501+ goto out_put_task_struct;
82502+ }
82503+
82504 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82505 ret = ptrace_attach(child, request, addr, data);
82506 /*
82507 * Some architectures need to do book-keeping after
82508 * a ptrace attach.
82509 */
82510- if (!ret)
82511+ if (!ret) {
82512 arch_ptrace_attach(child);
82513+ gr_audit_ptrace(child);
82514+ }
82515 goto out_put_task_struct;
82516 }
82517
82518@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82519 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82520 if (copied != sizeof(tmp))
82521 return -EIO;
82522- return put_user(tmp, (unsigned long __user *)data);
82523+ return put_user(tmp, (__force unsigned long __user *)data);
82524 }
82525
82526 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82527@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82528 }
82529
82530 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82531- compat_long_t addr, compat_long_t data)
82532+ compat_ulong_t addr, compat_ulong_t data)
82533 {
82534 struct task_struct *child;
82535 long ret;
82536@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82537 goto out;
82538 }
82539
82540+ if (gr_handle_ptrace(child, request)) {
82541+ ret = -EPERM;
82542+ goto out_put_task_struct;
82543+ }
82544+
82545 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82546 ret = ptrace_attach(child, request, addr, data);
82547 /*
82548 * Some architectures need to do book-keeping after
82549 * a ptrace attach.
82550 */
82551- if (!ret)
82552+ if (!ret) {
82553 arch_ptrace_attach(child);
82554+ gr_audit_ptrace(child);
82555+ }
82556 goto out_put_task_struct;
82557 }
82558
82559diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82560index cce6ba8..7c758b1f 100644
82561--- a/kernel/rcupdate.c
82562+++ b/kernel/rcupdate.c
82563@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82564 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82565 */
82566 if (till_stall_check < 3) {
82567- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82568+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82569 till_stall_check = 3;
82570 } else if (till_stall_check > 300) {
82571- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82572+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82573 till_stall_check = 300;
82574 }
82575 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82576diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82577index aa34411..4832cd4 100644
82578--- a/kernel/rcutiny.c
82579+++ b/kernel/rcutiny.c
82580@@ -45,7 +45,7 @@
82581 /* Forward declarations for rcutiny_plugin.h. */
82582 struct rcu_ctrlblk;
82583 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82584-static void rcu_process_callbacks(struct softirq_action *unused);
82585+static void rcu_process_callbacks(void);
82586 static void __call_rcu(struct rcu_head *head,
82587 void (*func)(struct rcu_head *rcu),
82588 struct rcu_ctrlblk *rcp);
82589@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82590 false));
82591 }
82592
82593-static void rcu_process_callbacks(struct softirq_action *unused)
82594+static __latent_entropy void rcu_process_callbacks(void)
82595 {
82596 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82597 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82598diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82599index f4871e5..8ef5741 100644
82600--- a/kernel/rcutorture.c
82601+++ b/kernel/rcutorture.c
82602@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82603 { 0 };
82604 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82605 { 0 };
82606-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82607-static atomic_t n_rcu_torture_alloc;
82608-static atomic_t n_rcu_torture_alloc_fail;
82609-static atomic_t n_rcu_torture_free;
82610-static atomic_t n_rcu_torture_mberror;
82611-static atomic_t n_rcu_torture_error;
82612+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82613+static atomic_unchecked_t n_rcu_torture_alloc;
82614+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82615+static atomic_unchecked_t n_rcu_torture_free;
82616+static atomic_unchecked_t n_rcu_torture_mberror;
82617+static atomic_unchecked_t n_rcu_torture_error;
82618 static long n_rcu_torture_barrier_error;
82619 static long n_rcu_torture_boost_ktrerror;
82620 static long n_rcu_torture_boost_rterror;
82621@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82622
82623 spin_lock_bh(&rcu_torture_lock);
82624 if (list_empty(&rcu_torture_freelist)) {
82625- atomic_inc(&n_rcu_torture_alloc_fail);
82626+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82627 spin_unlock_bh(&rcu_torture_lock);
82628 return NULL;
82629 }
82630- atomic_inc(&n_rcu_torture_alloc);
82631+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82632 p = rcu_torture_freelist.next;
82633 list_del_init(p);
82634 spin_unlock_bh(&rcu_torture_lock);
82635@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82636 static void
82637 rcu_torture_free(struct rcu_torture *p)
82638 {
82639- atomic_inc(&n_rcu_torture_free);
82640+ atomic_inc_unchecked(&n_rcu_torture_free);
82641 spin_lock_bh(&rcu_torture_lock);
82642 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82643 spin_unlock_bh(&rcu_torture_lock);
82644@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82645 i = rp->rtort_pipe_count;
82646 if (i > RCU_TORTURE_PIPE_LEN)
82647 i = RCU_TORTURE_PIPE_LEN;
82648- atomic_inc(&rcu_torture_wcount[i]);
82649+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82650 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82651 rp->rtort_mbtest = 0;
82652 rcu_torture_free(rp);
82653@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82654 i = rp->rtort_pipe_count;
82655 if (i > RCU_TORTURE_PIPE_LEN)
82656 i = RCU_TORTURE_PIPE_LEN;
82657- atomic_inc(&rcu_torture_wcount[i]);
82658+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82659 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82660 rp->rtort_mbtest = 0;
82661 list_del(&rp->rtort_free);
82662@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82663 i = old_rp->rtort_pipe_count;
82664 if (i > RCU_TORTURE_PIPE_LEN)
82665 i = RCU_TORTURE_PIPE_LEN;
82666- atomic_inc(&rcu_torture_wcount[i]);
82667+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82668 old_rp->rtort_pipe_count++;
82669 cur_ops->deferred_free(old_rp);
82670 }
82671@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82672 return;
82673 }
82674 if (p->rtort_mbtest == 0)
82675- atomic_inc(&n_rcu_torture_mberror);
82676+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82677 spin_lock(&rand_lock);
82678 cur_ops->read_delay(&rand);
82679 n_rcu_torture_timers++;
82680@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82681 continue;
82682 }
82683 if (p->rtort_mbtest == 0)
82684- atomic_inc(&n_rcu_torture_mberror);
82685+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82686 cur_ops->read_delay(&rand);
82687 preempt_disable();
82688 pipe_count = p->rtort_pipe_count;
82689@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82690 rcu_torture_current,
82691 rcu_torture_current_version,
82692 list_empty(&rcu_torture_freelist),
82693- atomic_read(&n_rcu_torture_alloc),
82694- atomic_read(&n_rcu_torture_alloc_fail),
82695- atomic_read(&n_rcu_torture_free));
82696+ atomic_read_unchecked(&n_rcu_torture_alloc),
82697+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82698+ atomic_read_unchecked(&n_rcu_torture_free));
82699 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82700- atomic_read(&n_rcu_torture_mberror),
82701+ atomic_read_unchecked(&n_rcu_torture_mberror),
82702 n_rcu_torture_boost_ktrerror,
82703 n_rcu_torture_boost_rterror);
82704 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82705@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82706 n_barrier_attempts,
82707 n_rcu_torture_barrier_error);
82708 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82709- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82710+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82711 n_rcu_torture_barrier_error != 0 ||
82712 n_rcu_torture_boost_ktrerror != 0 ||
82713 n_rcu_torture_boost_rterror != 0 ||
82714 n_rcu_torture_boost_failure != 0 ||
82715 i > 1) {
82716 cnt += sprintf(&page[cnt], "!!! ");
82717- atomic_inc(&n_rcu_torture_error);
82718+ atomic_inc_unchecked(&n_rcu_torture_error);
82719 WARN_ON_ONCE(1);
82720 }
82721 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82722@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82723 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82724 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82725 cnt += sprintf(&page[cnt], " %d",
82726- atomic_read(&rcu_torture_wcount[i]));
82727+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82728 }
82729 cnt += sprintf(&page[cnt], "\n");
82730 if (cur_ops->stats)
82731@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82732
82733 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82734
82735- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82736+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82737 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82738 else if (n_online_successes != n_online_attempts ||
82739 n_offline_successes != n_offline_attempts)
82740@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82741
82742 rcu_torture_current = NULL;
82743 rcu_torture_current_version = 0;
82744- atomic_set(&n_rcu_torture_alloc, 0);
82745- atomic_set(&n_rcu_torture_alloc_fail, 0);
82746- atomic_set(&n_rcu_torture_free, 0);
82747- atomic_set(&n_rcu_torture_mberror, 0);
82748- atomic_set(&n_rcu_torture_error, 0);
82749+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82750+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82751+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82752+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82753+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82754 n_rcu_torture_barrier_error = 0;
82755 n_rcu_torture_boost_ktrerror = 0;
82756 n_rcu_torture_boost_rterror = 0;
82757 n_rcu_torture_boost_failure = 0;
82758 n_rcu_torture_boosts = 0;
82759 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82760- atomic_set(&rcu_torture_wcount[i], 0);
82761+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82762 for_each_possible_cpu(cpu) {
82763 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82764 per_cpu(rcu_torture_count, cpu)[i] = 0;
82765diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82766index 068de3a..5e7db2f 100644
82767--- a/kernel/rcutree.c
82768+++ b/kernel/rcutree.c
82769@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82770 rcu_prepare_for_idle(smp_processor_id());
82771 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82772 smp_mb__before_atomic_inc(); /* See above. */
82773- atomic_inc(&rdtp->dynticks);
82774+ atomic_inc_unchecked(&rdtp->dynticks);
82775 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82776- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82777+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82778
82779 /*
82780 * It is illegal to enter an extended quiescent state while
82781@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82782 int user)
82783 {
82784 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82785- atomic_inc(&rdtp->dynticks);
82786+ atomic_inc_unchecked(&rdtp->dynticks);
82787 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82788 smp_mb__after_atomic_inc(); /* See above. */
82789- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82790+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82791 rcu_cleanup_after_idle(smp_processor_id());
82792 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82793 if (!user && !is_idle_task(current)) {
82794@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82795 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82796
82797 if (rdtp->dynticks_nmi_nesting == 0 &&
82798- (atomic_read(&rdtp->dynticks) & 0x1))
82799+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82800 return;
82801 rdtp->dynticks_nmi_nesting++;
82802 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82803- atomic_inc(&rdtp->dynticks);
82804+ atomic_inc_unchecked(&rdtp->dynticks);
82805 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82806 smp_mb__after_atomic_inc(); /* See above. */
82807- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82808+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82809 }
82810
82811 /**
82812@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82813 return;
82814 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82815 smp_mb__before_atomic_inc(); /* See above. */
82816- atomic_inc(&rdtp->dynticks);
82817+ atomic_inc_unchecked(&rdtp->dynticks);
82818 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82819- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82820+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82821 }
82822
82823 /**
82824@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82825 int ret;
82826
82827 preempt_disable();
82828- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82829+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82830 preempt_enable();
82831 return ret;
82832 }
82833@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82834 */
82835 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82836 {
82837- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82838+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82839 return (rdp->dynticks_snap & 0x1) == 0;
82840 }
82841
82842@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82843 unsigned int curr;
82844 unsigned int snap;
82845
82846- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82847+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82848 snap = (unsigned int)rdp->dynticks_snap;
82849
82850 /*
82851@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82852 rdp = this_cpu_ptr(rsp->rda);
82853 rcu_preempt_check_blocked_tasks(rnp);
82854 rnp->qsmask = rnp->qsmaskinit;
82855- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82856+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82857 WARN_ON_ONCE(rnp->completed != rsp->completed);
82858- ACCESS_ONCE(rnp->completed) = rsp->completed;
82859+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82860 if (rnp == rdp->mynode)
82861 __note_gp_changes(rsp, rnp, rdp);
82862 rcu_preempt_boost_start_gp(rnp);
82863@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82864 */
82865 rcu_for_each_node_breadth_first(rsp, rnp) {
82866 raw_spin_lock_irq(&rnp->lock);
82867- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82868+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82869 rdp = this_cpu_ptr(rsp->rda);
82870 if (rnp == rdp->mynode)
82871 __note_gp_changes(rsp, rnp, rdp);
82872@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82873 rsp->qlen += rdp->qlen;
82874 rdp->n_cbs_orphaned += rdp->qlen;
82875 rdp->qlen_lazy = 0;
82876- ACCESS_ONCE(rdp->qlen) = 0;
82877+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82878 }
82879
82880 /*
82881@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82882 }
82883 smp_mb(); /* List handling before counting for rcu_barrier(). */
82884 rdp->qlen_lazy -= count_lazy;
82885- ACCESS_ONCE(rdp->qlen) -= count;
82886+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82887 rdp->n_cbs_invoked += count;
82888
82889 /* Reinstate batch limit if we have worked down the excess. */
82890@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82891 /*
82892 * Do RCU core processing for the current CPU.
82893 */
82894-static void rcu_process_callbacks(struct softirq_action *unused)
82895+static __latent_entropy void rcu_process_callbacks(void)
82896 {
82897 struct rcu_state *rsp;
82898
82899@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82900 local_irq_restore(flags);
82901 return;
82902 }
82903- ACCESS_ONCE(rdp->qlen)++;
82904+ ACCESS_ONCE_RW(rdp->qlen)++;
82905 if (lazy)
82906 rdp->qlen_lazy++;
82907 else
82908@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82909 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82910 * course be required on a 64-bit system.
82911 */
82912- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82913+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82914 (ulong)atomic_long_read(&rsp->expedited_done) +
82915 ULONG_MAX / 8)) {
82916 synchronize_sched();
82917- atomic_long_inc(&rsp->expedited_wrap);
82918+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82919 return;
82920 }
82921
82922@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82923 * Take a ticket. Note that atomic_inc_return() implies a
82924 * full memory barrier.
82925 */
82926- snap = atomic_long_inc_return(&rsp->expedited_start);
82927+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82928 firstsnap = snap;
82929 get_online_cpus();
82930 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82931@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
82932 synchronize_sched_expedited_cpu_stop,
82933 NULL) == -EAGAIN) {
82934 put_online_cpus();
82935- atomic_long_inc(&rsp->expedited_tryfail);
82936+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
82937
82938 /* Check to see if someone else did our work for us. */
82939 s = atomic_long_read(&rsp->expedited_done);
82940 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82941 /* ensure test happens before caller kfree */
82942 smp_mb__before_atomic_inc(); /* ^^^ */
82943- atomic_long_inc(&rsp->expedited_workdone1);
82944+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
82945 return;
82946 }
82947
82948@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
82949 udelay(trycount * num_online_cpus());
82950 } else {
82951 wait_rcu_gp(call_rcu_sched);
82952- atomic_long_inc(&rsp->expedited_normal);
82953+ atomic_long_inc_unchecked(&rsp->expedited_normal);
82954 return;
82955 }
82956
82957@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
82958 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82959 /* ensure test happens before caller kfree */
82960 smp_mb__before_atomic_inc(); /* ^^^ */
82961- atomic_long_inc(&rsp->expedited_workdone2);
82962+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
82963 return;
82964 }
82965
82966@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
82967 * period works for us.
82968 */
82969 get_online_cpus();
82970- snap = atomic_long_read(&rsp->expedited_start);
82971+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
82972 smp_mb(); /* ensure read is before try_stop_cpus(). */
82973 }
82974- atomic_long_inc(&rsp->expedited_stoppedcpus);
82975+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
82976
82977 /*
82978 * Everyone up to our most recent fetch is covered by our grace
82979@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
82980 * than we did already did their update.
82981 */
82982 do {
82983- atomic_long_inc(&rsp->expedited_done_tries);
82984+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
82985 s = atomic_long_read(&rsp->expedited_done);
82986 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
82987 /* ensure test happens before caller kfree */
82988 smp_mb__before_atomic_inc(); /* ^^^ */
82989- atomic_long_inc(&rsp->expedited_done_lost);
82990+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
82991 break;
82992 }
82993 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
82994- atomic_long_inc(&rsp->expedited_done_exit);
82995+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
82996
82997 put_online_cpus();
82998 }
82999@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83000 * ACCESS_ONCE() to prevent the compiler from speculating
83001 * the increment to precede the early-exit check.
83002 */
83003- ACCESS_ONCE(rsp->n_barrier_done)++;
83004+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83005 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83006 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83007 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83008@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83009
83010 /* Increment ->n_barrier_done to prevent duplicate work. */
83011 smp_mb(); /* Keep increment after above mechanism. */
83012- ACCESS_ONCE(rsp->n_barrier_done)++;
83013+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83014 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83015 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83016 smp_mb(); /* Keep increment before caller's subsequent code. */
83017@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83018 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83019 init_callback_list(rdp);
83020 rdp->qlen_lazy = 0;
83021- ACCESS_ONCE(rdp->qlen) = 0;
83022+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83023 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83024 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83025- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83026+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83027 rdp->cpu = cpu;
83028 rdp->rsp = rsp;
83029 rcu_boot_init_nocb_percpu_data(rdp);
83030@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83031 rdp->blimit = blimit;
83032 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83033 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83034- atomic_set(&rdp->dynticks->dynticks,
83035- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83036+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83037+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83038 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83039
83040 /* Add CPU to rcu_node bitmasks. */
83041diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83042index b383258..2440c1e 100644
83043--- a/kernel/rcutree.h
83044+++ b/kernel/rcutree.h
83045@@ -87,7 +87,7 @@ struct rcu_dynticks {
83046 long long dynticks_nesting; /* Track irq/process nesting level. */
83047 /* Process level is worth LLONG_MAX/2. */
83048 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83049- atomic_t dynticks; /* Even value for idle, else odd. */
83050+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83051 #ifdef CONFIG_RCU_FAST_NO_HZ
83052 bool all_lazy; /* Are all CPU's CBs lazy? */
83053 unsigned long nonlazy_posted;
83054@@ -419,17 +419,17 @@ struct rcu_state {
83055 /* _rcu_barrier(). */
83056 /* End of fields guarded by barrier_mutex. */
83057
83058- atomic_long_t expedited_start; /* Starting ticket. */
83059- atomic_long_t expedited_done; /* Done ticket. */
83060- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83061- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83062- atomic_long_t expedited_workdone1; /* # done by others #1. */
83063- atomic_long_t expedited_workdone2; /* # done by others #2. */
83064- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83065- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83066- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83067- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83068- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83069+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83070+ atomic_long_t expedited_done; /* Done ticket. */
83071+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83072+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83073+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83074+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83075+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83076+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83077+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83078+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83079+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83080
83081 unsigned long jiffies_force_qs; /* Time at which to invoke */
83082 /* force_quiescent_state(). */
83083diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83084index 769e12e..7b2139b 100644
83085--- a/kernel/rcutree_plugin.h
83086+++ b/kernel/rcutree_plugin.h
83087@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83088
83089 /* Clean up and exit. */
83090 smp_mb(); /* ensure expedited GP seen before counter increment. */
83091- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83092+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83093 unlock_mb_ret:
83094 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83095 mb_ret:
83096@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83097 free_cpumask_var(cm);
83098 }
83099
83100-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83101+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83102 .store = &rcu_cpu_kthread_task,
83103 .thread_should_run = rcu_cpu_kthread_should_run,
83104 .thread_fn = rcu_cpu_kthread,
83105@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83106 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83107 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83108 cpu, ticks_value, ticks_title,
83109- atomic_read(&rdtp->dynticks) & 0xfff,
83110+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83111 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83112 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83113 fast_no_hz);
83114@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83115
83116 /* Enqueue the callback on the nocb list and update counts. */
83117 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83118- ACCESS_ONCE(*old_rhpp) = rhp;
83119+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83120 atomic_long_add(rhcount, &rdp->nocb_q_count);
83121 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83122
83123@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83124 * Extract queued callbacks, update counts, and wait
83125 * for a grace period to elapse.
83126 */
83127- ACCESS_ONCE(rdp->nocb_head) = NULL;
83128+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83129 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83130 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83131 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83132- ACCESS_ONCE(rdp->nocb_p_count) += c;
83133- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83134+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83135+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83136 rcu_nocb_wait_gp(rdp);
83137
83138 /* Each pass through the following loop invokes a callback. */
83139@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83140 list = next;
83141 }
83142 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83143- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83144- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83145+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83146+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83147 rdp->n_nocbs_invoked += c;
83148 }
83149 return 0;
83150@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83151 t = kthread_run(rcu_nocb_kthread, rdp,
83152 "rcuo%c/%d", rsp->abbr, cpu);
83153 BUG_ON(IS_ERR(t));
83154- ACCESS_ONCE(rdp->nocb_kthread) = t;
83155+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83156 }
83157 }
83158
83159diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83160index cf6c174..a8f4b50 100644
83161--- a/kernel/rcutree_trace.c
83162+++ b/kernel/rcutree_trace.c
83163@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83164 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83165 rdp->passed_quiesce, rdp->qs_pending);
83166 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83167- atomic_read(&rdp->dynticks->dynticks),
83168+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83169 rdp->dynticks->dynticks_nesting,
83170 rdp->dynticks->dynticks_nmi_nesting,
83171 rdp->dynticks_fqs);
83172@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83173 struct rcu_state *rsp = (struct rcu_state *)m->private;
83174
83175 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",
83176- atomic_long_read(&rsp->expedited_start),
83177+ atomic_long_read_unchecked(&rsp->expedited_start),
83178 atomic_long_read(&rsp->expedited_done),
83179- atomic_long_read(&rsp->expedited_wrap),
83180- atomic_long_read(&rsp->expedited_tryfail),
83181- atomic_long_read(&rsp->expedited_workdone1),
83182- atomic_long_read(&rsp->expedited_workdone2),
83183- atomic_long_read(&rsp->expedited_normal),
83184- atomic_long_read(&rsp->expedited_stoppedcpus),
83185- atomic_long_read(&rsp->expedited_done_tries),
83186- atomic_long_read(&rsp->expedited_done_lost),
83187- atomic_long_read(&rsp->expedited_done_exit));
83188+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83189+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83190+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83191+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83192+ atomic_long_read_unchecked(&rsp->expedited_normal),
83193+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83194+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83195+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83196+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83197 return 0;
83198 }
83199
83200diff --git a/kernel/resource.c b/kernel/resource.c
83201index 3f285dc..5755f62 100644
83202--- a/kernel/resource.c
83203+++ b/kernel/resource.c
83204@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83205
83206 static int __init ioresources_init(void)
83207 {
83208+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83209+#ifdef CONFIG_GRKERNSEC_PROC_USER
83210+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83211+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83212+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83213+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83214+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83215+#endif
83216+#else
83217 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83218 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83219+#endif
83220 return 0;
83221 }
83222 __initcall(ioresources_init);
83223diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83224index 1d96dd0..994ff19 100644
83225--- a/kernel/rtmutex-tester.c
83226+++ b/kernel/rtmutex-tester.c
83227@@ -22,7 +22,7 @@
83228 #define MAX_RT_TEST_MUTEXES 8
83229
83230 static spinlock_t rttest_lock;
83231-static atomic_t rttest_event;
83232+static atomic_unchecked_t rttest_event;
83233
83234 struct test_thread_data {
83235 int opcode;
83236@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83237
83238 case RTTEST_LOCKCONT:
83239 td->mutexes[td->opdata] = 1;
83240- td->event = atomic_add_return(1, &rttest_event);
83241+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83242 return 0;
83243
83244 case RTTEST_RESET:
83245@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83246 return 0;
83247
83248 case RTTEST_RESETEVENT:
83249- atomic_set(&rttest_event, 0);
83250+ atomic_set_unchecked(&rttest_event, 0);
83251 return 0;
83252
83253 default:
83254@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83255 return ret;
83256
83257 td->mutexes[id] = 1;
83258- td->event = atomic_add_return(1, &rttest_event);
83259+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83260 rt_mutex_lock(&mutexes[id]);
83261- td->event = atomic_add_return(1, &rttest_event);
83262+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83263 td->mutexes[id] = 4;
83264 return 0;
83265
83266@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83267 return ret;
83268
83269 td->mutexes[id] = 1;
83270- td->event = atomic_add_return(1, &rttest_event);
83271+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83272 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83273- td->event = atomic_add_return(1, &rttest_event);
83274+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83275 td->mutexes[id] = ret ? 0 : 4;
83276 return ret ? -EINTR : 0;
83277
83278@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83279 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83280 return ret;
83281
83282- td->event = atomic_add_return(1, &rttest_event);
83283+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83284 rt_mutex_unlock(&mutexes[id]);
83285- td->event = atomic_add_return(1, &rttest_event);
83286+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83287 td->mutexes[id] = 0;
83288 return 0;
83289
83290@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83291 break;
83292
83293 td->mutexes[dat] = 2;
83294- td->event = atomic_add_return(1, &rttest_event);
83295+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83296 break;
83297
83298 default:
83299@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83300 return;
83301
83302 td->mutexes[dat] = 3;
83303- td->event = atomic_add_return(1, &rttest_event);
83304+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83305 break;
83306
83307 case RTTEST_LOCKNOWAIT:
83308@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83309 return;
83310
83311 td->mutexes[dat] = 1;
83312- td->event = atomic_add_return(1, &rttest_event);
83313+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83314 return;
83315
83316 default:
83317diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83318index 4a07353..66b5291 100644
83319--- a/kernel/sched/auto_group.c
83320+++ b/kernel/sched/auto_group.c
83321@@ -11,7 +11,7 @@
83322
83323 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83324 static struct autogroup autogroup_default;
83325-static atomic_t autogroup_seq_nr;
83326+static atomic_unchecked_t autogroup_seq_nr;
83327
83328 void __init autogroup_init(struct task_struct *init_task)
83329 {
83330@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83331
83332 kref_init(&ag->kref);
83333 init_rwsem(&ag->lock);
83334- ag->id = atomic_inc_return(&autogroup_seq_nr);
83335+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83336 ag->tg = tg;
83337 #ifdef CONFIG_RT_GROUP_SCHED
83338 /*
83339diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83340index 05c39f0..442e6fe 100644
83341--- a/kernel/sched/core.c
83342+++ b/kernel/sched/core.c
83343@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83344 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83345 * or number of jiffies left till timeout) if completed.
83346 */
83347-long __sched
83348+long __sched __intentional_overflow(-1)
83349 wait_for_completion_interruptible_timeout(struct completion *x,
83350 unsigned long timeout)
83351 {
83352@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83353 *
83354 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83355 */
83356-int __sched wait_for_completion_killable(struct completion *x)
83357+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83358 {
83359 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83360 if (t == -ERESTARTSYS)
83361@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83362 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83363 * or number of jiffies left till timeout) if completed.
83364 */
83365-long __sched
83366+long __sched __intentional_overflow(-1)
83367 wait_for_completion_killable_timeout(struct completion *x,
83368 unsigned long timeout)
83369 {
83370@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83371 /* convert nice value [19,-20] to rlimit style value [1,40] */
83372 int nice_rlim = 20 - nice;
83373
83374+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83375+
83376 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83377 capable(CAP_SYS_NICE));
83378 }
83379@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83380 if (nice > 19)
83381 nice = 19;
83382
83383- if (increment < 0 && !can_nice(current, nice))
83384+ if (increment < 0 && (!can_nice(current, nice) ||
83385+ gr_handle_chroot_nice()))
83386 return -EPERM;
83387
83388 retval = security_task_setnice(current, nice);
83389@@ -3344,6 +3347,7 @@ recheck:
83390 unsigned long rlim_rtprio =
83391 task_rlimit(p, RLIMIT_RTPRIO);
83392
83393+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83394 /* can't set/change the rt policy */
83395 if (policy != p->policy && !rlim_rtprio)
83396 return -EPERM;
83397@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83398
83399 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83400
83401-static struct ctl_table sd_ctl_dir[] = {
83402+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83403 {
83404 .procname = "sched_domain",
83405 .mode = 0555,
83406@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83407 {}
83408 };
83409
83410-static struct ctl_table *sd_alloc_ctl_entry(int n)
83411+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83412 {
83413- struct ctl_table *entry =
83414+ ctl_table_no_const *entry =
83415 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83416
83417 return entry;
83418 }
83419
83420-static void sd_free_ctl_entry(struct ctl_table **tablep)
83421+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83422 {
83423- struct ctl_table *entry;
83424+ ctl_table_no_const *entry;
83425
83426 /*
83427 * In the intermediate directories, both the child directory and
83428@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83429 * will always be set. In the lowest directory the names are
83430 * static strings and all have proc handlers.
83431 */
83432- for (entry = *tablep; entry->mode; entry++) {
83433- if (entry->child)
83434- sd_free_ctl_entry(&entry->child);
83435+ for (entry = tablep; entry->mode; entry++) {
83436+ if (entry->child) {
83437+ sd_free_ctl_entry(entry->child);
83438+ pax_open_kernel();
83439+ entry->child = NULL;
83440+ pax_close_kernel();
83441+ }
83442 if (entry->proc_handler == NULL)
83443 kfree(entry->procname);
83444 }
83445
83446- kfree(*tablep);
83447- *tablep = NULL;
83448+ kfree(tablep);
83449 }
83450
83451 static int min_load_idx = 0;
83452 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83453
83454 static void
83455-set_table_entry(struct ctl_table *entry,
83456+set_table_entry(ctl_table_no_const *entry,
83457 const char *procname, void *data, int maxlen,
83458 umode_t mode, proc_handler *proc_handler,
83459 bool load_idx)
83460@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83461 static struct ctl_table *
83462 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83463 {
83464- struct ctl_table *table = sd_alloc_ctl_entry(13);
83465+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83466
83467 if (table == NULL)
83468 return NULL;
83469@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83470 return table;
83471 }
83472
83473-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83474+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83475 {
83476- struct ctl_table *entry, *table;
83477+ ctl_table_no_const *entry, *table;
83478 struct sched_domain *sd;
83479 int domain_num = 0, i;
83480 char buf[32];
83481@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83482 static void register_sched_domain_sysctl(void)
83483 {
83484 int i, cpu_num = num_possible_cpus();
83485- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83486+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83487 char buf[32];
83488
83489 WARN_ON(sd_ctl_dir[0].child);
83490+ pax_open_kernel();
83491 sd_ctl_dir[0].child = entry;
83492+ pax_close_kernel();
83493
83494 if (entry == NULL)
83495 return;
83496@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83497 if (sd_sysctl_header)
83498 unregister_sysctl_table(sd_sysctl_header);
83499 sd_sysctl_header = NULL;
83500- if (sd_ctl_dir[0].child)
83501- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83502+ if (sd_ctl_dir[0].child) {
83503+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83504+ pax_open_kernel();
83505+ sd_ctl_dir[0].child = NULL;
83506+ pax_close_kernel();
83507+ }
83508 }
83509 #else
83510 static void register_sched_domain_sysctl(void)
83511diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83512index 31cbc15..ba68c15 100644
83513--- a/kernel/sched/fair.c
83514+++ b/kernel/sched/fair.c
83515@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83516
83517 static void reset_ptenuma_scan(struct task_struct *p)
83518 {
83519- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83520+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83521 p->mm->numa_scan_offset = 0;
83522 }
83523
83524@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83525 * run_rebalance_domains is triggered when needed from the scheduler tick.
83526 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83527 */
83528-static void run_rebalance_domains(struct softirq_action *h)
83529+static __latent_entropy void run_rebalance_domains(void)
83530 {
83531 int this_cpu = smp_processor_id();
83532 struct rq *this_rq = cpu_rq(this_cpu);
83533diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83534index ef0a7b2..1b728c1 100644
83535--- a/kernel/sched/sched.h
83536+++ b/kernel/sched/sched.h
83537@@ -1004,7 +1004,7 @@ struct sched_class {
83538 #ifdef CONFIG_FAIR_GROUP_SCHED
83539 void (*task_move_group) (struct task_struct *p, int on_rq);
83540 #endif
83541-};
83542+} __do_const;
83543
83544 #define sched_class_highest (&stop_sched_class)
83545 #define for_each_class(class) \
83546diff --git a/kernel/signal.c b/kernel/signal.c
83547index 50e4107..9409983 100644
83548--- a/kernel/signal.c
83549+++ b/kernel/signal.c
83550@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83551
83552 int print_fatal_signals __read_mostly;
83553
83554-static void __user *sig_handler(struct task_struct *t, int sig)
83555+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83556 {
83557 return t->sighand->action[sig - 1].sa.sa_handler;
83558 }
83559
83560-static int sig_handler_ignored(void __user *handler, int sig)
83561+static int sig_handler_ignored(__sighandler_t handler, int sig)
83562 {
83563 /* Is it explicitly or implicitly ignored? */
83564 return handler == SIG_IGN ||
83565@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83566
83567 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83568 {
83569- void __user *handler;
83570+ __sighandler_t handler;
83571
83572 handler = sig_handler(t, sig);
83573
83574@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83575 atomic_inc(&user->sigpending);
83576 rcu_read_unlock();
83577
83578+ if (!override_rlimit)
83579+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83580+
83581 if (override_rlimit ||
83582 atomic_read(&user->sigpending) <=
83583 task_rlimit(t, RLIMIT_SIGPENDING)) {
83584@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83585
83586 int unhandled_signal(struct task_struct *tsk, int sig)
83587 {
83588- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83589+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83590 if (is_global_init(tsk))
83591 return 1;
83592 if (handler != SIG_IGN && handler != SIG_DFL)
83593@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83594 }
83595 }
83596
83597+ /* allow glibc communication via tgkill to other threads in our
83598+ thread group */
83599+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83600+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83601+ && gr_handle_signal(t, sig))
83602+ return -EPERM;
83603+
83604 return security_task_kill(t, info, sig, 0);
83605 }
83606
83607@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83608 return send_signal(sig, info, p, 1);
83609 }
83610
83611-static int
83612+int
83613 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83614 {
83615 return send_signal(sig, info, t, 0);
83616@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83617 unsigned long int flags;
83618 int ret, blocked, ignored;
83619 struct k_sigaction *action;
83620+ int is_unhandled = 0;
83621
83622 spin_lock_irqsave(&t->sighand->siglock, flags);
83623 action = &t->sighand->action[sig-1];
83624@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83625 }
83626 if (action->sa.sa_handler == SIG_DFL)
83627 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83628+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83629+ is_unhandled = 1;
83630 ret = specific_send_sig_info(sig, info, t);
83631 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83632
83633+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83634+ normal operation */
83635+ if (is_unhandled) {
83636+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83637+ gr_handle_crash(t, sig);
83638+ }
83639+
83640 return ret;
83641 }
83642
83643@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83644 ret = check_kill_permission(sig, info, p);
83645 rcu_read_unlock();
83646
83647- if (!ret && sig)
83648+ if (!ret && sig) {
83649 ret = do_send_sig_info(sig, info, p, true);
83650+ if (!ret)
83651+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83652+ }
83653
83654 return ret;
83655 }
83656@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83657 int error = -ESRCH;
83658
83659 rcu_read_lock();
83660- p = find_task_by_vpid(pid);
83661+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83662+ /* allow glibc communication via tgkill to other threads in our
83663+ thread group */
83664+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83665+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83666+ p = find_task_by_vpid_unrestricted(pid);
83667+ else
83668+#endif
83669+ p = find_task_by_vpid(pid);
83670 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83671 error = check_kill_permission(sig, info, p);
83672 /*
83673@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83674 }
83675 seg = get_fs();
83676 set_fs(KERNEL_DS);
83677- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83678- (stack_t __force __user *) &uoss,
83679+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83680+ (stack_t __force_user *) &uoss,
83681 compat_user_stack_pointer());
83682 set_fs(seg);
83683 if (ret >= 0 && uoss_ptr) {
83684diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83685index eb89e18..a4e6792 100644
83686--- a/kernel/smpboot.c
83687+++ b/kernel/smpboot.c
83688@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83689 }
83690 smpboot_unpark_thread(plug_thread, cpu);
83691 }
83692- list_add(&plug_thread->list, &hotplug_threads);
83693+ pax_list_add(&plug_thread->list, &hotplug_threads);
83694 out:
83695 mutex_unlock(&smpboot_threads_lock);
83696 return ret;
83697@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83698 {
83699 get_online_cpus();
83700 mutex_lock(&smpboot_threads_lock);
83701- list_del(&plug_thread->list);
83702+ pax_list_del(&plug_thread->list);
83703 smpboot_destroy_threads(plug_thread);
83704 mutex_unlock(&smpboot_threads_lock);
83705 put_online_cpus();
83706diff --git a/kernel/softirq.c b/kernel/softirq.c
83707index adf6c00..5d89b73 100644
83708--- a/kernel/softirq.c
83709+++ b/kernel/softirq.c
83710@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83711 EXPORT_SYMBOL(irq_stat);
83712 #endif
83713
83714-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83715+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83716
83717 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83718
83719-char *softirq_to_name[NR_SOFTIRQS] = {
83720+const char * const softirq_to_name[NR_SOFTIRQS] = {
83721 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83722 "TASKLET", "SCHED", "HRTIMER", "RCU"
83723 };
83724@@ -248,7 +248,7 @@ restart:
83725 kstat_incr_softirqs_this_cpu(vec_nr);
83726
83727 trace_softirq_entry(vec_nr);
83728- h->action(h);
83729+ h->action();
83730 trace_softirq_exit(vec_nr);
83731 if (unlikely(prev_count != preempt_count())) {
83732 printk(KERN_ERR "huh, entered softirq %u %s %p"
83733@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83734 or_softirq_pending(1UL << nr);
83735 }
83736
83737-void open_softirq(int nr, void (*action)(struct softirq_action *))
83738+void __init open_softirq(int nr, void (*action)(void))
83739 {
83740 softirq_vec[nr].action = action;
83741 }
83742@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83743
83744 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83745
83746-static void tasklet_action(struct softirq_action *a)
83747+static __latent_entropy void tasklet_action(void)
83748 {
83749 struct tasklet_struct *list;
83750
83751@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
83752 }
83753 }
83754
83755-static void tasklet_hi_action(struct softirq_action *a)
83756+static __latent_entropy void tasklet_hi_action(void)
83757 {
83758 struct tasklet_struct *list;
83759
83760@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
83761 .notifier_call = cpu_callback
83762 };
83763
83764-static struct smp_hotplug_thread softirq_threads = {
83765+static struct smp_hotplug_thread softirq_threads __read_only = {
83766 .store = &ksoftirqd,
83767 .thread_should_run = ksoftirqd_should_run,
83768 .thread_fn = run_ksoftirqd,
83769diff --git a/kernel/srcu.c b/kernel/srcu.c
83770index 01d5ccb..cdcbee6 100644
83771--- a/kernel/srcu.c
83772+++ b/kernel/srcu.c
83773@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83774
83775 idx = ACCESS_ONCE(sp->completed) & 0x1;
83776 preempt_disable();
83777- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83778+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83779 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83780- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83781+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83782 preempt_enable();
83783 return idx;
83784 }
83785diff --git a/kernel/sys.c b/kernel/sys.c
83786index 771129b..dc0c7e3 100644
83787--- a/kernel/sys.c
83788+++ b/kernel/sys.c
83789@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83790 error = -EACCES;
83791 goto out;
83792 }
83793+
83794+ if (gr_handle_chroot_setpriority(p, niceval)) {
83795+ error = -EACCES;
83796+ goto out;
83797+ }
83798+
83799 no_nice = security_task_setnice(p, niceval);
83800 if (no_nice) {
83801 error = no_nice;
83802@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83803 goto error;
83804 }
83805
83806+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83807+ goto error;
83808+
83809 if (rgid != (gid_t) -1 ||
83810 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83811 new->sgid = new->egid;
83812@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83813 old = current_cred();
83814
83815 retval = -EPERM;
83816+
83817+ if (gr_check_group_change(kgid, kgid, kgid))
83818+ goto error;
83819+
83820 if (nsown_capable(CAP_SETGID))
83821 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83822 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83823@@ -404,7 +417,7 @@ error:
83824 /*
83825 * change the user struct in a credentials set to match the new UID
83826 */
83827-static int set_user(struct cred *new)
83828+int set_user(struct cred *new)
83829 {
83830 struct user_struct *new_user;
83831
83832@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83833 goto error;
83834 }
83835
83836+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83837+ goto error;
83838+
83839 if (!uid_eq(new->uid, old->uid)) {
83840 retval = set_user(new);
83841 if (retval < 0)
83842@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83843 old = current_cred();
83844
83845 retval = -EPERM;
83846+
83847+ if (gr_check_crash_uid(kuid))
83848+ goto error;
83849+ if (gr_check_user_change(kuid, kuid, kuid))
83850+ goto error;
83851+
83852 if (nsown_capable(CAP_SETUID)) {
83853 new->suid = new->uid = kuid;
83854 if (!uid_eq(kuid, old->uid)) {
83855@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83856 goto error;
83857 }
83858
83859+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83860+ goto error;
83861+
83862 if (ruid != (uid_t) -1) {
83863 new->uid = kruid;
83864 if (!uid_eq(kruid, old->uid)) {
83865@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83866 goto error;
83867 }
83868
83869+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83870+ goto error;
83871+
83872 if (rgid != (gid_t) -1)
83873 new->gid = krgid;
83874 if (egid != (gid_t) -1)
83875@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83876 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83877 nsown_capable(CAP_SETUID)) {
83878 if (!uid_eq(kuid, old->fsuid)) {
83879+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83880+ goto error;
83881+
83882 new->fsuid = kuid;
83883 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83884 goto change_okay;
83885 }
83886 }
83887
83888+error:
83889 abort_creds(new);
83890 return old_fsuid;
83891
83892@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83893 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83894 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83895 nsown_capable(CAP_SETGID)) {
83896+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83897+ goto error;
83898+
83899 if (!gid_eq(kgid, old->fsgid)) {
83900 new->fsgid = kgid;
83901 goto change_okay;
83902 }
83903 }
83904
83905+error:
83906 abort_creds(new);
83907 return old_fsgid;
83908
83909@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83910 return -EFAULT;
83911
83912 down_read(&uts_sem);
83913- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83914+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83915 __OLD_UTS_LEN);
83916 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83917- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83918+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83919 __OLD_UTS_LEN);
83920 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83921- error |= __copy_to_user(&name->release, &utsname()->release,
83922+ error |= __copy_to_user(name->release, &utsname()->release,
83923 __OLD_UTS_LEN);
83924 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83925- error |= __copy_to_user(&name->version, &utsname()->version,
83926+ error |= __copy_to_user(name->version, &utsname()->version,
83927 __OLD_UTS_LEN);
83928 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83929- error |= __copy_to_user(&name->machine, &utsname()->machine,
83930+ error |= __copy_to_user(name->machine, &utsname()->machine,
83931 __OLD_UTS_LEN);
83932 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
83933 up_read(&uts_sem);
83934@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
83935 */
83936 new_rlim->rlim_cur = 1;
83937 }
83938+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
83939+ is changed to a lower value. Since tasks can be created by the same
83940+ user in between this limit change and an execve by this task, force
83941+ a recheck only for this task by setting PF_NPROC_EXCEEDED
83942+ */
83943+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
83944+ tsk->flags |= PF_NPROC_EXCEEDED;
83945 }
83946 if (!retval) {
83947 if (old_rlim)
83948diff --git a/kernel/sysctl.c b/kernel/sysctl.c
83949index 07f6fc4..65fb3d4 100644
83950--- a/kernel/sysctl.c
83951+++ b/kernel/sysctl.c
83952@@ -93,7 +93,6 @@
83953
83954
83955 #if defined(CONFIG_SYSCTL)
83956-
83957 /* External variables not in a header file. */
83958 extern int sysctl_overcommit_memory;
83959 extern int sysctl_overcommit_ratio;
83960@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
83961
83962 /* Constants used for minimum and maximum */
83963 #ifdef CONFIG_LOCKUP_DETECTOR
83964-static int sixty = 60;
83965+static int sixty __read_only = 60;
83966 #endif
83967
83968-static int zero;
83969-static int __maybe_unused one = 1;
83970-static int __maybe_unused two = 2;
83971-static int __maybe_unused three = 3;
83972-static unsigned long one_ul = 1;
83973-static int one_hundred = 100;
83974+static int neg_one __read_only = -1;
83975+static int zero __read_only = 0;
83976+static int __maybe_unused one __read_only = 1;
83977+static int __maybe_unused two __read_only = 2;
83978+static int __maybe_unused three __read_only = 3;
83979+static unsigned long one_ul __read_only = 1;
83980+static int one_hundred __read_only = 100;
83981 #ifdef CONFIG_PRINTK
83982-static int ten_thousand = 10000;
83983+static int ten_thousand __read_only = 10000;
83984 #endif
83985
83986 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
83987@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
83988 void __user *buffer, size_t *lenp, loff_t *ppos);
83989 #endif
83990
83991-#ifdef CONFIG_PRINTK
83992 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
83993 void __user *buffer, size_t *lenp, loff_t *ppos);
83994-#endif
83995
83996 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
83997 void __user *buffer, size_t *lenp, loff_t *ppos);
83998@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
83999
84000 #endif
84001
84002+extern struct ctl_table grsecurity_table[];
84003+
84004 static struct ctl_table kern_table[];
84005 static struct ctl_table vm_table[];
84006 static struct ctl_table fs_table[];
84007@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84008 int sysctl_legacy_va_layout;
84009 #endif
84010
84011+#ifdef CONFIG_PAX_SOFTMODE
84012+static ctl_table pax_table[] = {
84013+ {
84014+ .procname = "softmode",
84015+ .data = &pax_softmode,
84016+ .maxlen = sizeof(unsigned int),
84017+ .mode = 0600,
84018+ .proc_handler = &proc_dointvec,
84019+ },
84020+
84021+ { }
84022+};
84023+#endif
84024+
84025 /* The default sysctl tables: */
84026
84027 static struct ctl_table sysctl_base_table[] = {
84028@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84029 #endif
84030
84031 static struct ctl_table kern_table[] = {
84032+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84033+ {
84034+ .procname = "grsecurity",
84035+ .mode = 0500,
84036+ .child = grsecurity_table,
84037+ },
84038+#endif
84039+
84040+#ifdef CONFIG_PAX_SOFTMODE
84041+ {
84042+ .procname = "pax",
84043+ .mode = 0500,
84044+ .child = pax_table,
84045+ },
84046+#endif
84047+
84048 {
84049 .procname = "sched_child_runs_first",
84050 .data = &sysctl_sched_child_runs_first,
84051@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84052 .data = &modprobe_path,
84053 .maxlen = KMOD_PATH_LEN,
84054 .mode = 0644,
84055- .proc_handler = proc_dostring,
84056+ .proc_handler = proc_dostring_modpriv,
84057 },
84058 {
84059 .procname = "modules_disabled",
84060@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84061 .extra1 = &zero,
84062 .extra2 = &one,
84063 },
84064+#endif
84065 {
84066 .procname = "kptr_restrict",
84067 .data = &kptr_restrict,
84068 .maxlen = sizeof(int),
84069 .mode = 0644,
84070 .proc_handler = proc_dointvec_minmax_sysadmin,
84071+#ifdef CONFIG_GRKERNSEC_HIDESYM
84072+ .extra1 = &two,
84073+#else
84074 .extra1 = &zero,
84075+#endif
84076 .extra2 = &two,
84077 },
84078-#endif
84079 {
84080 .procname = "ngroups_max",
84081 .data = &ngroups_max,
84082@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84083 */
84084 {
84085 .procname = "perf_event_paranoid",
84086- .data = &sysctl_perf_event_paranoid,
84087- .maxlen = sizeof(sysctl_perf_event_paranoid),
84088+ .data = &sysctl_perf_event_legitimately_concerned,
84089+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84090 .mode = 0644,
84091- .proc_handler = proc_dointvec,
84092+ /* go ahead, be a hero */
84093+ .proc_handler = proc_dointvec_minmax_sysadmin,
84094+ .extra1 = &neg_one,
84095+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84096+ .extra2 = &three,
84097+#else
84098+ .extra2 = &two,
84099+#endif
84100 },
84101 {
84102 .procname = "perf_event_mlock_kb",
84103@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84104 .proc_handler = proc_dointvec_minmax,
84105 .extra1 = &zero,
84106 },
84107+ {
84108+ .procname = "heap_stack_gap",
84109+ .data = &sysctl_heap_stack_gap,
84110+ .maxlen = sizeof(sysctl_heap_stack_gap),
84111+ .mode = 0644,
84112+ .proc_handler = proc_doulongvec_minmax,
84113+ },
84114 #else
84115 {
84116 .procname = "nr_trim_pages",
84117@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84118 buffer, lenp, ppos);
84119 }
84120
84121+int proc_dostring_modpriv(struct ctl_table *table, int write,
84122+ void __user *buffer, size_t *lenp, loff_t *ppos)
84123+{
84124+ if (write && !capable(CAP_SYS_MODULE))
84125+ return -EPERM;
84126+
84127+ return _proc_do_string(table->data, table->maxlen, write,
84128+ buffer, lenp, ppos);
84129+}
84130+
84131 static size_t proc_skip_spaces(char **buf)
84132 {
84133 size_t ret;
84134@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84135 len = strlen(tmp);
84136 if (len > *size)
84137 len = *size;
84138+ if (len > sizeof(tmp))
84139+ len = sizeof(tmp);
84140 if (copy_to_user(*buf, tmp, len))
84141 return -EFAULT;
84142 *size -= len;
84143@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84144 static int proc_taint(struct ctl_table *table, int write,
84145 void __user *buffer, size_t *lenp, loff_t *ppos)
84146 {
84147- struct ctl_table t;
84148+ ctl_table_no_const t;
84149 unsigned long tmptaint = get_taint();
84150 int err;
84151
84152@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84153 return err;
84154 }
84155
84156-#ifdef CONFIG_PRINTK
84157 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84158 void __user *buffer, size_t *lenp, loff_t *ppos)
84159 {
84160@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84161
84162 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84163 }
84164-#endif
84165
84166 struct do_proc_dointvec_minmax_conv_param {
84167 int *min;
84168@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84169 *i = val;
84170 } else {
84171 val = convdiv * (*i) / convmul;
84172- if (!first)
84173+ if (!first) {
84174 err = proc_put_char(&buffer, &left, '\t');
84175+ if (err)
84176+ break;
84177+ }
84178 err = proc_put_long(&buffer, &left, val, false);
84179 if (err)
84180 break;
84181@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84182 return -ENOSYS;
84183 }
84184
84185+int proc_dostring_modpriv(struct ctl_table *table, int write,
84186+ void __user *buffer, size_t *lenp, loff_t *ppos)
84187+{
84188+ return -ENOSYS;
84189+}
84190+
84191 int proc_dointvec(struct ctl_table *table, int write,
84192 void __user *buffer, size_t *lenp, loff_t *ppos)
84193 {
84194@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84195 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84196 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84197 EXPORT_SYMBOL(proc_dostring);
84198+EXPORT_SYMBOL(proc_dostring_modpriv);
84199 EXPORT_SYMBOL(proc_doulongvec_minmax);
84200 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84201diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84202index 145bb4d..b2aa969 100644
84203--- a/kernel/taskstats.c
84204+++ b/kernel/taskstats.c
84205@@ -28,9 +28,12 @@
84206 #include <linux/fs.h>
84207 #include <linux/file.h>
84208 #include <linux/pid_namespace.h>
84209+#include <linux/grsecurity.h>
84210 #include <net/genetlink.h>
84211 #include <linux/atomic.h>
84212
84213+extern int gr_is_taskstats_denied(int pid);
84214+
84215 /*
84216 * Maximum length of a cpumask that can be specified in
84217 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84218@@ -570,6 +573,9 @@ err:
84219
84220 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84221 {
84222+ if (gr_is_taskstats_denied(current->pid))
84223+ return -EACCES;
84224+
84225 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84226 return cmd_attr_register_cpumask(info);
84227 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84228diff --git a/kernel/time.c b/kernel/time.c
84229index 7c7964c..784a599 100644
84230--- a/kernel/time.c
84231+++ b/kernel/time.c
84232@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84233 return error;
84234
84235 if (tz) {
84236+ /* we log in do_settimeofday called below, so don't log twice
84237+ */
84238+ if (!tv)
84239+ gr_log_timechange();
84240+
84241 sys_tz = *tz;
84242 update_vsyscall_tz();
84243 if (firsttime) {
84244@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84245 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84246 * value to a scaled second value.
84247 */
84248-unsigned long
84249+unsigned long __intentional_overflow(-1)
84250 timespec_to_jiffies(const struct timespec *value)
84251 {
84252 unsigned long sec = value->tv_sec;
84253diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84254index eec50fc..65e5df6 100644
84255--- a/kernel/time/alarmtimer.c
84256+++ b/kernel/time/alarmtimer.c
84257@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84258 struct platform_device *pdev;
84259 int error = 0;
84260 int i;
84261- struct k_clock alarm_clock = {
84262+ static struct k_clock alarm_clock = {
84263 .clock_getres = alarm_clock_getres,
84264 .clock_get = alarm_clock_get,
84265 .timer_create = alarm_timer_create,
84266diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84267index 947ba25..20cbade 100644
84268--- a/kernel/time/timekeeping.c
84269+++ b/kernel/time/timekeeping.c
84270@@ -15,6 +15,7 @@
84271 #include <linux/init.h>
84272 #include <linux/mm.h>
84273 #include <linux/sched.h>
84274+#include <linux/grsecurity.h>
84275 #include <linux/syscore_ops.h>
84276 #include <linux/clocksource.h>
84277 #include <linux/jiffies.h>
84278@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84279 if (!timespec_valid_strict(tv))
84280 return -EINVAL;
84281
84282+ gr_log_timechange();
84283+
84284 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84285 write_seqcount_begin(&timekeeper_seq);
84286
84287diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84288index 61ed862..3b52c65 100644
84289--- a/kernel/time/timer_list.c
84290+++ b/kernel/time/timer_list.c
84291@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84292
84293 static void print_name_offset(struct seq_file *m, void *sym)
84294 {
84295+#ifdef CONFIG_GRKERNSEC_HIDESYM
84296+ SEQ_printf(m, "<%p>", NULL);
84297+#else
84298 char symname[KSYM_NAME_LEN];
84299
84300 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84301 SEQ_printf(m, "<%pK>", sym);
84302 else
84303 SEQ_printf(m, "%s", symname);
84304+#endif
84305 }
84306
84307 static void
84308@@ -119,7 +123,11 @@ next_one:
84309 static void
84310 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84311 {
84312+#ifdef CONFIG_GRKERNSEC_HIDESYM
84313+ SEQ_printf(m, " .base: %p\n", NULL);
84314+#else
84315 SEQ_printf(m, " .base: %pK\n", base);
84316+#endif
84317 SEQ_printf(m, " .index: %d\n",
84318 base->index);
84319 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84320@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84321 {
84322 struct proc_dir_entry *pe;
84323
84324+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84325+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84326+#else
84327 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84328+#endif
84329 if (!pe)
84330 return -ENOMEM;
84331 return 0;
84332diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84333index 0b537f2..40d6c20 100644
84334--- a/kernel/time/timer_stats.c
84335+++ b/kernel/time/timer_stats.c
84336@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84337 static unsigned long nr_entries;
84338 static struct entry entries[MAX_ENTRIES];
84339
84340-static atomic_t overflow_count;
84341+static atomic_unchecked_t overflow_count;
84342
84343 /*
84344 * The entries are in a hash-table, for fast lookup:
84345@@ -140,7 +140,7 @@ static void reset_entries(void)
84346 nr_entries = 0;
84347 memset(entries, 0, sizeof(entries));
84348 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84349- atomic_set(&overflow_count, 0);
84350+ atomic_set_unchecked(&overflow_count, 0);
84351 }
84352
84353 static struct entry *alloc_entry(void)
84354@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84355 if (likely(entry))
84356 entry->count++;
84357 else
84358- atomic_inc(&overflow_count);
84359+ atomic_inc_unchecked(&overflow_count);
84360
84361 out_unlock:
84362 raw_spin_unlock_irqrestore(lock, flags);
84363@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84364
84365 static void print_name_offset(struct seq_file *m, unsigned long addr)
84366 {
84367+#ifdef CONFIG_GRKERNSEC_HIDESYM
84368+ seq_printf(m, "<%p>", NULL);
84369+#else
84370 char symname[KSYM_NAME_LEN];
84371
84372 if (lookup_symbol_name(addr, symname) < 0)
84373- seq_printf(m, "<%p>", (void *)addr);
84374+ seq_printf(m, "<%pK>", (void *)addr);
84375 else
84376 seq_printf(m, "%s", symname);
84377+#endif
84378 }
84379
84380 static int tstats_show(struct seq_file *m, void *v)
84381@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84382
84383 seq_puts(m, "Timer Stats Version: v0.2\n");
84384 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84385- if (atomic_read(&overflow_count))
84386+ if (atomic_read_unchecked(&overflow_count))
84387 seq_printf(m, "Overflow: %d entries\n",
84388- atomic_read(&overflow_count));
84389+ atomic_read_unchecked(&overflow_count));
84390
84391 for (i = 0; i < nr_entries; i++) {
84392 entry = entries + i;
84393@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84394 {
84395 struct proc_dir_entry *pe;
84396
84397+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84398+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84399+#else
84400 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84401+#endif
84402 if (!pe)
84403 return -ENOMEM;
84404 return 0;
84405diff --git a/kernel/timer.c b/kernel/timer.c
84406index 4296d13..0164b04 100644
84407--- a/kernel/timer.c
84408+++ b/kernel/timer.c
84409@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84410 /*
84411 * This function runs timers and the timer-tq in bottom half context.
84412 */
84413-static void run_timer_softirq(struct softirq_action *h)
84414+static __latent_entropy void run_timer_softirq(void)
84415 {
84416 struct tvec_base *base = __this_cpu_read(tvec_bases);
84417
84418@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84419 *
84420 * In all cases the return value is guaranteed to be non-negative.
84421 */
84422-signed long __sched schedule_timeout(signed long timeout)
84423+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84424 {
84425 struct timer_list timer;
84426 unsigned long expire;
84427diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84428index b8b8560..75b1a09 100644
84429--- a/kernel/trace/blktrace.c
84430+++ b/kernel/trace/blktrace.c
84431@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84432 struct blk_trace *bt = filp->private_data;
84433 char buf[16];
84434
84435- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84436+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84437
84438 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84439 }
84440@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84441 return 1;
84442
84443 bt = buf->chan->private_data;
84444- atomic_inc(&bt->dropped);
84445+ atomic_inc_unchecked(&bt->dropped);
84446 return 0;
84447 }
84448
84449@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84450
84451 bt->dir = dir;
84452 bt->dev = dev;
84453- atomic_set(&bt->dropped, 0);
84454+ atomic_set_unchecked(&bt->dropped, 0);
84455
84456 ret = -EIO;
84457 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84458diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84459index a6d098c..bb8cf65 100644
84460--- a/kernel/trace/ftrace.c
84461+++ b/kernel/trace/ftrace.c
84462@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84463 if (unlikely(ftrace_disabled))
84464 return 0;
84465
84466+ ret = ftrace_arch_code_modify_prepare();
84467+ FTRACE_WARN_ON(ret);
84468+ if (ret)
84469+ return 0;
84470+
84471 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84472+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84473 if (ret) {
84474 ftrace_bug(ret, ip);
84475- return 0;
84476 }
84477- return 1;
84478+ return ret ? 0 : 1;
84479 }
84480
84481 /*
84482@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84483 if (!count)
84484 return 0;
84485
84486+ pax_open_kernel();
84487 sort(start, count, sizeof(*start),
84488 ftrace_cmp_ips, ftrace_swap_ips);
84489+ pax_close_kernel();
84490
84491 start_pg = ftrace_allocate_pages(count);
84492 if (!start_pg)
84493@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84494 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84495
84496 static int ftrace_graph_active;
84497-static struct notifier_block ftrace_suspend_notifier;
84498-
84499 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84500 {
84501 return 0;
84502@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84503 return NOTIFY_DONE;
84504 }
84505
84506+static struct notifier_block ftrace_suspend_notifier = {
84507+ .notifier_call = ftrace_suspend_notifier_call
84508+};
84509+
84510 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84511 trace_func_graph_ent_t entryfunc)
84512 {
84513@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84514 goto out;
84515 }
84516
84517- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84518 register_pm_notifier(&ftrace_suspend_notifier);
84519
84520 ftrace_graph_active++;
84521diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84522index cc2f66f..05edd54 100644
84523--- a/kernel/trace/ring_buffer.c
84524+++ b/kernel/trace/ring_buffer.c
84525@@ -352,9 +352,9 @@ struct buffer_data_page {
84526 */
84527 struct buffer_page {
84528 struct list_head list; /* list of buffer pages */
84529- local_t write; /* index for next write */
84530+ local_unchecked_t write; /* index for next write */
84531 unsigned read; /* index for next read */
84532- local_t entries; /* entries on this page */
84533+ local_unchecked_t entries; /* entries on this page */
84534 unsigned long real_end; /* real end of data */
84535 struct buffer_data_page *page; /* Actual data page */
84536 };
84537@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84538 unsigned long last_overrun;
84539 local_t entries_bytes;
84540 local_t entries;
84541- local_t overrun;
84542- local_t commit_overrun;
84543+ local_unchecked_t overrun;
84544+ local_unchecked_t commit_overrun;
84545 local_t dropped_events;
84546 local_t committing;
84547 local_t commits;
84548@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84549 *
84550 * We add a counter to the write field to denote this.
84551 */
84552- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84553- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84554+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84555+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84556
84557 /*
84558 * Just make sure we have seen our old_write and synchronize
84559@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84560 * cmpxchg to only update if an interrupt did not already
84561 * do it for us. If the cmpxchg fails, we don't care.
84562 */
84563- (void)local_cmpxchg(&next_page->write, old_write, val);
84564- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84565+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84566+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84567
84568 /*
84569 * No need to worry about races with clearing out the commit.
84570@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84571
84572 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84573 {
84574- return local_read(&bpage->entries) & RB_WRITE_MASK;
84575+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84576 }
84577
84578 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84579 {
84580- return local_read(&bpage->write) & RB_WRITE_MASK;
84581+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84582 }
84583
84584 static int
84585@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84586 * bytes consumed in ring buffer from here.
84587 * Increment overrun to account for the lost events.
84588 */
84589- local_add(page_entries, &cpu_buffer->overrun);
84590+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84591 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84592 }
84593
84594@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84595 * it is our responsibility to update
84596 * the counters.
84597 */
84598- local_add(entries, &cpu_buffer->overrun);
84599+ local_add_unchecked(entries, &cpu_buffer->overrun);
84600 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84601
84602 /*
84603@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84604 if (tail == BUF_PAGE_SIZE)
84605 tail_page->real_end = 0;
84606
84607- local_sub(length, &tail_page->write);
84608+ local_sub_unchecked(length, &tail_page->write);
84609 return;
84610 }
84611
84612@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84613 rb_event_set_padding(event);
84614
84615 /* Set the write back to the previous setting */
84616- local_sub(length, &tail_page->write);
84617+ local_sub_unchecked(length, &tail_page->write);
84618 return;
84619 }
84620
84621@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84622
84623 /* Set write to end of buffer */
84624 length = (tail + length) - BUF_PAGE_SIZE;
84625- local_sub(length, &tail_page->write);
84626+ local_sub_unchecked(length, &tail_page->write);
84627 }
84628
84629 /*
84630@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84631 * about it.
84632 */
84633 if (unlikely(next_page == commit_page)) {
84634- local_inc(&cpu_buffer->commit_overrun);
84635+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84636 goto out_reset;
84637 }
84638
84639@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84640 cpu_buffer->tail_page) &&
84641 (cpu_buffer->commit_page ==
84642 cpu_buffer->reader_page))) {
84643- local_inc(&cpu_buffer->commit_overrun);
84644+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84645 goto out_reset;
84646 }
84647 }
84648@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84649 length += RB_LEN_TIME_EXTEND;
84650
84651 tail_page = cpu_buffer->tail_page;
84652- write = local_add_return(length, &tail_page->write);
84653+ write = local_add_return_unchecked(length, &tail_page->write);
84654
84655 /* set write to only the index of the write */
84656 write &= RB_WRITE_MASK;
84657@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84658 kmemcheck_annotate_bitfield(event, bitfield);
84659 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84660
84661- local_inc(&tail_page->entries);
84662+ local_inc_unchecked(&tail_page->entries);
84663
84664 /*
84665 * If this is the first commit on the page, then update
84666@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84667
84668 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84669 unsigned long write_mask =
84670- local_read(&bpage->write) & ~RB_WRITE_MASK;
84671+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84672 unsigned long event_length = rb_event_length(event);
84673 /*
84674 * This is on the tail page. It is possible that
84675@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84676 */
84677 old_index += write_mask;
84678 new_index += write_mask;
84679- index = local_cmpxchg(&bpage->write, old_index, new_index);
84680+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84681 if (index == old_index) {
84682 /* update counters */
84683 local_sub(event_length, &cpu_buffer->entries_bytes);
84684@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84685
84686 /* Do the likely case first */
84687 if (likely(bpage->page == (void *)addr)) {
84688- local_dec(&bpage->entries);
84689+ local_dec_unchecked(&bpage->entries);
84690 return;
84691 }
84692
84693@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84694 start = bpage;
84695 do {
84696 if (bpage->page == (void *)addr) {
84697- local_dec(&bpage->entries);
84698+ local_dec_unchecked(&bpage->entries);
84699 return;
84700 }
84701 rb_inc_page(cpu_buffer, &bpage);
84702@@ -3139,7 +3139,7 @@ static inline unsigned long
84703 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84704 {
84705 return local_read(&cpu_buffer->entries) -
84706- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84707+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84708 }
84709
84710 /**
84711@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84712 return 0;
84713
84714 cpu_buffer = buffer->buffers[cpu];
84715- ret = local_read(&cpu_buffer->overrun);
84716+ ret = local_read_unchecked(&cpu_buffer->overrun);
84717
84718 return ret;
84719 }
84720@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84721 return 0;
84722
84723 cpu_buffer = buffer->buffers[cpu];
84724- ret = local_read(&cpu_buffer->commit_overrun);
84725+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84726
84727 return ret;
84728 }
84729@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84730 /* if you care about this being correct, lock the buffer */
84731 for_each_buffer_cpu(buffer, cpu) {
84732 cpu_buffer = buffer->buffers[cpu];
84733- overruns += local_read(&cpu_buffer->overrun);
84734+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84735 }
84736
84737 return overruns;
84738@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84739 /*
84740 * Reset the reader page to size zero.
84741 */
84742- local_set(&cpu_buffer->reader_page->write, 0);
84743- local_set(&cpu_buffer->reader_page->entries, 0);
84744+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84745+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84746 local_set(&cpu_buffer->reader_page->page->commit, 0);
84747 cpu_buffer->reader_page->real_end = 0;
84748
84749@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84750 * want to compare with the last_overrun.
84751 */
84752 smp_mb();
84753- overwrite = local_read(&(cpu_buffer->overrun));
84754+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84755
84756 /*
84757 * Here's the tricky part.
84758@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84759
84760 cpu_buffer->head_page
84761 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84762- local_set(&cpu_buffer->head_page->write, 0);
84763- local_set(&cpu_buffer->head_page->entries, 0);
84764+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84765+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84766 local_set(&cpu_buffer->head_page->page->commit, 0);
84767
84768 cpu_buffer->head_page->read = 0;
84769@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84770
84771 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84772 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84773- local_set(&cpu_buffer->reader_page->write, 0);
84774- local_set(&cpu_buffer->reader_page->entries, 0);
84775+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84776+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84777 local_set(&cpu_buffer->reader_page->page->commit, 0);
84778 cpu_buffer->reader_page->read = 0;
84779
84780 local_set(&cpu_buffer->entries_bytes, 0);
84781- local_set(&cpu_buffer->overrun, 0);
84782- local_set(&cpu_buffer->commit_overrun, 0);
84783+ local_set_unchecked(&cpu_buffer->overrun, 0);
84784+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84785 local_set(&cpu_buffer->dropped_events, 0);
84786 local_set(&cpu_buffer->entries, 0);
84787 local_set(&cpu_buffer->committing, 0);
84788@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84789 rb_init_page(bpage);
84790 bpage = reader->page;
84791 reader->page = *data_page;
84792- local_set(&reader->write, 0);
84793- local_set(&reader->entries, 0);
84794+ local_set_unchecked(&reader->write, 0);
84795+ local_set_unchecked(&reader->entries, 0);
84796 reader->read = 0;
84797 *data_page = bpage;
84798
84799diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84800index 496f94d..754aeea 100644
84801--- a/kernel/trace/trace.c
84802+++ b/kernel/trace/trace.c
84803@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84804 return 0;
84805 }
84806
84807-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84808+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84809 {
84810 /* do nothing if flag is already set */
84811 if (!!(trace_flags & mask) == !!enabled)
84812diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84813index afaae41..64871f8 100644
84814--- a/kernel/trace/trace.h
84815+++ b/kernel/trace/trace.h
84816@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84817 void trace_printk_init_buffers(void);
84818 void trace_printk_start_comm(void);
84819 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84820-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84821+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84822
84823 /*
84824 * Normal trace_printk() and friends allocates special buffers
84825diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84826index 26dc348..8708ca7 100644
84827--- a/kernel/trace/trace_clock.c
84828+++ b/kernel/trace/trace_clock.c
84829@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84830 return now;
84831 }
84832
84833-static atomic64_t trace_counter;
84834+static atomic64_unchecked_t trace_counter;
84835
84836 /*
84837 * trace_clock_counter(): simply an atomic counter.
84838@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84839 */
84840 u64 notrace trace_clock_counter(void)
84841 {
84842- return atomic64_add_return(1, &trace_counter);
84843+ return atomic64_inc_return_unchecked(&trace_counter);
84844 }
84845diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84846index 29a7ebc..eb473cf 100644
84847--- a/kernel/trace/trace_events.c
84848+++ b/kernel/trace/trace_events.c
84849@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84850 struct ftrace_module_file_ops {
84851 struct list_head list;
84852 struct module *mod;
84853- struct file_operations id;
84854- struct file_operations enable;
84855- struct file_operations format;
84856- struct file_operations filter;
84857 };
84858
84859 static struct ftrace_module_file_ops *
84860@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84861
84862 file_ops->mod = mod;
84863
84864- file_ops->id = ftrace_event_id_fops;
84865- file_ops->id.owner = mod;
84866-
84867- file_ops->enable = ftrace_enable_fops;
84868- file_ops->enable.owner = mod;
84869-
84870- file_ops->filter = ftrace_event_filter_fops;
84871- file_ops->filter.owner = mod;
84872-
84873- file_ops->format = ftrace_event_format_fops;
84874- file_ops->format.owner = mod;
84875+ pax_open_kernel();
84876+ mod->trace_id.owner = mod;
84877+ mod->trace_enable.owner = mod;
84878+ mod->trace_filter.owner = mod;
84879+ mod->trace_format.owner = mod;
84880+ pax_close_kernel();
84881
84882 list_add(&file_ops->list, &ftrace_module_file_list);
84883
84884@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84885 struct ftrace_module_file_ops *file_ops)
84886 {
84887 return __trace_add_new_event(call, tr,
84888- &file_ops->id, &file_ops->enable,
84889- &file_ops->filter, &file_ops->format);
84890+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84891+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84892 }
84893
84894 #else
84895diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84896index b3dcfb2..ebee344 100644
84897--- a/kernel/trace/trace_mmiotrace.c
84898+++ b/kernel/trace/trace_mmiotrace.c
84899@@ -24,7 +24,7 @@ struct header_iter {
84900 static struct trace_array *mmio_trace_array;
84901 static bool overrun_detected;
84902 static unsigned long prev_overruns;
84903-static atomic_t dropped_count;
84904+static atomic_unchecked_t dropped_count;
84905
84906 static void mmio_reset_data(struct trace_array *tr)
84907 {
84908@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84909
84910 static unsigned long count_overruns(struct trace_iterator *iter)
84911 {
84912- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84913+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84914 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84915
84916 if (over > prev_overruns)
84917@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84918 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84919 sizeof(*entry), 0, pc);
84920 if (!event) {
84921- atomic_inc(&dropped_count);
84922+ atomic_inc_unchecked(&dropped_count);
84923 return;
84924 }
84925 entry = ring_buffer_event_data(event);
84926@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84927 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84928 sizeof(*entry), 0, pc);
84929 if (!event) {
84930- atomic_inc(&dropped_count);
84931+ atomic_inc_unchecked(&dropped_count);
84932 return;
84933 }
84934 entry = ring_buffer_event_data(event);
84935diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
84936index 34e7cba..6f9a729 100644
84937--- a/kernel/trace/trace_output.c
84938+++ b/kernel/trace/trace_output.c
84939@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
84940
84941 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
84942 if (!IS_ERR(p)) {
84943- p = mangle_path(s->buffer + s->len, p, "\n");
84944+ p = mangle_path(s->buffer + s->len, p, "\n\\");
84945 if (p) {
84946 s->len = p - s->buffer;
84947 return 1;
84948@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
84949 goto out;
84950 }
84951
84952+ pax_open_kernel();
84953 if (event->funcs->trace == NULL)
84954- event->funcs->trace = trace_nop_print;
84955+ *(void **)&event->funcs->trace = trace_nop_print;
84956 if (event->funcs->raw == NULL)
84957- event->funcs->raw = trace_nop_print;
84958+ *(void **)&event->funcs->raw = trace_nop_print;
84959 if (event->funcs->hex == NULL)
84960- event->funcs->hex = trace_nop_print;
84961+ *(void **)&event->funcs->hex = trace_nop_print;
84962 if (event->funcs->binary == NULL)
84963- event->funcs->binary = trace_nop_print;
84964+ *(void **)&event->funcs->binary = trace_nop_print;
84965+ pax_close_kernel();
84966
84967 key = event->type & (EVENT_HASHSIZE - 1);
84968
84969diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
84970index b20428c..4845a10 100644
84971--- a/kernel/trace/trace_stack.c
84972+++ b/kernel/trace/trace_stack.c
84973@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
84974 return;
84975
84976 /* we do not handle interrupt stacks yet */
84977- if (!object_is_on_stack(stack))
84978+ if (!object_starts_on_stack(stack))
84979 return;
84980
84981 local_irq_save(flags);
84982diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
84983index 9064b91..1f5d2f8 100644
84984--- a/kernel/user_namespace.c
84985+++ b/kernel/user_namespace.c
84986@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
84987 !kgid_has_mapping(parent_ns, group))
84988 return -EPERM;
84989
84990+#ifdef CONFIG_GRKERNSEC
84991+ /*
84992+ * This doesn't really inspire confidence:
84993+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
84994+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
84995+ * Increases kernel attack surface in areas developers
84996+ * previously cared little about ("low importance due
84997+ * to requiring "root" capability")
84998+ * To be removed when this code receives *proper* review
84999+ */
85000+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85001+ !capable(CAP_SETGID))
85002+ return -EPERM;
85003+#endif
85004+
85005 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85006 if (!ns)
85007 return -ENOMEM;
85008@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85009 if (atomic_read(&current->mm->mm_users) > 1)
85010 return -EINVAL;
85011
85012- if (current->fs->users != 1)
85013+ if (atomic_read(&current->fs->users) != 1)
85014 return -EINVAL;
85015
85016 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85017diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85018index 4f69f9a..7c6f8f8 100644
85019--- a/kernel/utsname_sysctl.c
85020+++ b/kernel/utsname_sysctl.c
85021@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85022 static int proc_do_uts_string(ctl_table *table, int write,
85023 void __user *buffer, size_t *lenp, loff_t *ppos)
85024 {
85025- struct ctl_table uts_table;
85026+ ctl_table_no_const uts_table;
85027 int r;
85028 memcpy(&uts_table, table, sizeof(uts_table));
85029 uts_table.data = get_uts(table, write);
85030diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85031index 1241d8c..d5cfc28 100644
85032--- a/kernel/watchdog.c
85033+++ b/kernel/watchdog.c
85034@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85035 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85036 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85037
85038-static struct smp_hotplug_thread watchdog_threads = {
85039+static struct smp_hotplug_thread watchdog_threads __read_only = {
85040 .store = &softlockup_watchdog,
85041 .thread_should_run = watchdog_should_run,
85042 .thread_fn = watchdog,
85043diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85044index e93f7b9..989fcd7 100644
85045--- a/kernel/workqueue.c
85046+++ b/kernel/workqueue.c
85047@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85048 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85049 worker_flags |= WORKER_REBOUND;
85050 worker_flags &= ~WORKER_UNBOUND;
85051- ACCESS_ONCE(worker->flags) = worker_flags;
85052+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85053 }
85054
85055 spin_unlock_irq(&pool->lock);
85056diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85057index 1501aa5..e771896 100644
85058--- a/lib/Kconfig.debug
85059+++ b/lib/Kconfig.debug
85060@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85061
85062 config DEBUG_WW_MUTEX_SLOWPATH
85063 bool "Wait/wound mutex debugging: Slowpath testing"
85064- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85065+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85066 select DEBUG_LOCK_ALLOC
85067 select DEBUG_SPINLOCK
85068 select DEBUG_MUTEXES
85069@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85070
85071 config DEBUG_LOCK_ALLOC
85072 bool "Lock debugging: detect incorrect freeing of live locks"
85073- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85074+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85075 select DEBUG_SPINLOCK
85076 select DEBUG_MUTEXES
85077 select LOCKDEP
85078@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85079
85080 config PROVE_LOCKING
85081 bool "Lock debugging: prove locking correctness"
85082- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85083+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85084 select LOCKDEP
85085 select DEBUG_SPINLOCK
85086 select DEBUG_MUTEXES
85087@@ -914,7 +914,7 @@ config LOCKDEP
85088
85089 config LOCK_STAT
85090 bool "Lock usage statistics"
85091- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85092+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85093 select LOCKDEP
85094 select DEBUG_SPINLOCK
85095 select DEBUG_MUTEXES
85096@@ -1357,6 +1357,7 @@ config LATENCYTOP
85097 depends on DEBUG_KERNEL
85098 depends on STACKTRACE_SUPPORT
85099 depends on PROC_FS
85100+ depends on !GRKERNSEC_HIDESYM
85101 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85102 select KALLSYMS
85103 select KALLSYMS_ALL
85104@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85105 config DEBUG_STRICT_USER_COPY_CHECKS
85106 bool "Strict user copy size checks"
85107 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85108- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85109+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85110 help
85111 Enabling this option turns a certain set of sanity checks for user
85112 copy operations into compile time failures.
85113@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85114
85115 config PROVIDE_OHCI1394_DMA_INIT
85116 bool "Remote debugging over FireWire early on boot"
85117- depends on PCI && X86
85118+ depends on PCI && X86 && !GRKERNSEC
85119 help
85120 If you want to debug problems which hang or crash the kernel early
85121 on boot and the crashing machine has a FireWire port, you can use
85122@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85123
85124 config FIREWIRE_OHCI_REMOTE_DMA
85125 bool "Remote debugging over FireWire with firewire-ohci"
85126- depends on FIREWIRE_OHCI
85127+ depends on FIREWIRE_OHCI && !GRKERNSEC
85128 help
85129 This option lets you use the FireWire bus for remote debugging
85130 with help of the firewire-ohci driver. It enables unfiltered
85131diff --git a/lib/Makefile b/lib/Makefile
85132index 7baccfd..3ceb95f 100644
85133--- a/lib/Makefile
85134+++ b/lib/Makefile
85135@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85136
85137 obj-$(CONFIG_BTREE) += btree.o
85138 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85139-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85140+obj-y += list_debug.o
85141 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85142
85143 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85144diff --git a/lib/bitmap.c b/lib/bitmap.c
85145index 06f7e4f..f3cf2b0 100644
85146--- a/lib/bitmap.c
85147+++ b/lib/bitmap.c
85148@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85149 {
85150 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85151 u32 chunk;
85152- const char __user __force *ubuf = (const char __user __force *)buf;
85153+ const char __user *ubuf = (const char __force_user *)buf;
85154
85155 bitmap_zero(maskp, nmaskbits);
85156
85157@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85158 {
85159 if (!access_ok(VERIFY_READ, ubuf, ulen))
85160 return -EFAULT;
85161- return __bitmap_parse((const char __force *)ubuf,
85162+ return __bitmap_parse((const char __force_kernel *)ubuf,
85163 ulen, 1, maskp, nmaskbits);
85164
85165 }
85166@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85167 {
85168 unsigned a, b;
85169 int c, old_c, totaldigits;
85170- const char __user __force *ubuf = (const char __user __force *)buf;
85171+ const char __user *ubuf = (const char __force_user *)buf;
85172 int exp_digit, in_range;
85173
85174 totaldigits = c = 0;
85175@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85176 {
85177 if (!access_ok(VERIFY_READ, ubuf, ulen))
85178 return -EFAULT;
85179- return __bitmap_parselist((const char __force *)ubuf,
85180+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85181 ulen, 1, maskp, nmaskbits);
85182 }
85183 EXPORT_SYMBOL(bitmap_parselist_user);
85184diff --git a/lib/bug.c b/lib/bug.c
85185index 1686034..a9c00c8 100644
85186--- a/lib/bug.c
85187+++ b/lib/bug.c
85188@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85189 return BUG_TRAP_TYPE_NONE;
85190
85191 bug = find_bug(bugaddr);
85192+ if (!bug)
85193+ return BUG_TRAP_TYPE_NONE;
85194
85195 file = NULL;
85196 line = 0;
85197diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85198index 37061ed..da83f48 100644
85199--- a/lib/debugobjects.c
85200+++ b/lib/debugobjects.c
85201@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85202 if (limit > 4)
85203 return;
85204
85205- is_on_stack = object_is_on_stack(addr);
85206+ is_on_stack = object_starts_on_stack(addr);
85207 if (is_on_stack == onstack)
85208 return;
85209
85210diff --git a/lib/devres.c b/lib/devres.c
85211index 8235331..5881053 100644
85212--- a/lib/devres.c
85213+++ b/lib/devres.c
85214@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85215 void devm_iounmap(struct device *dev, void __iomem *addr)
85216 {
85217 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85218- (void *)addr));
85219+ (void __force *)addr));
85220 iounmap(addr);
85221 }
85222 EXPORT_SYMBOL(devm_iounmap);
85223@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85224 {
85225 ioport_unmap(addr);
85226 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85227- devm_ioport_map_match, (void *)addr));
85228+ devm_ioport_map_match, (void __force *)addr));
85229 }
85230 EXPORT_SYMBOL(devm_ioport_unmap);
85231 #endif /* CONFIG_HAS_IOPORT */
85232diff --git a/lib/div64.c b/lib/div64.c
85233index a163b6c..9618fa5 100644
85234--- a/lib/div64.c
85235+++ b/lib/div64.c
85236@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85237 EXPORT_SYMBOL(__div64_32);
85238
85239 #ifndef div_s64_rem
85240-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85241+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85242 {
85243 u64 quotient;
85244
85245@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85246 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85247 */
85248 #ifndef div64_u64
85249-u64 div64_u64(u64 dividend, u64 divisor)
85250+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85251 {
85252 u32 high = divisor >> 32;
85253 u64 quot;
85254diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85255index d87a17a..ac0d79a 100644
85256--- a/lib/dma-debug.c
85257+++ b/lib/dma-debug.c
85258@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85259
85260 void dma_debug_add_bus(struct bus_type *bus)
85261 {
85262- struct notifier_block *nb;
85263+ notifier_block_no_const *nb;
85264
85265 if (global_disable)
85266 return;
85267@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85268
85269 static void check_for_stack(struct device *dev, void *addr)
85270 {
85271- if (object_is_on_stack(addr))
85272+ if (object_starts_on_stack(addr))
85273 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85274 "stack [addr=%p]\n", addr);
85275 }
85276diff --git a/lib/inflate.c b/lib/inflate.c
85277index 013a761..c28f3fc 100644
85278--- a/lib/inflate.c
85279+++ b/lib/inflate.c
85280@@ -269,7 +269,7 @@ static void free(void *where)
85281 malloc_ptr = free_mem_ptr;
85282 }
85283 #else
85284-#define malloc(a) kmalloc(a, GFP_KERNEL)
85285+#define malloc(a) kmalloc((a), GFP_KERNEL)
85286 #define free(a) kfree(a)
85287 #endif
85288
85289diff --git a/lib/ioremap.c b/lib/ioremap.c
85290index 0c9216c..863bd89 100644
85291--- a/lib/ioremap.c
85292+++ b/lib/ioremap.c
85293@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85294 unsigned long next;
85295
85296 phys_addr -= addr;
85297- pmd = pmd_alloc(&init_mm, pud, addr);
85298+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85299 if (!pmd)
85300 return -ENOMEM;
85301 do {
85302@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85303 unsigned long next;
85304
85305 phys_addr -= addr;
85306- pud = pud_alloc(&init_mm, pgd, addr);
85307+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85308 if (!pud)
85309 return -ENOMEM;
85310 do {
85311diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85312index bd2bea9..6b3c95e 100644
85313--- a/lib/is_single_threaded.c
85314+++ b/lib/is_single_threaded.c
85315@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85316 struct task_struct *p, *t;
85317 bool ret;
85318
85319+ if (!mm)
85320+ return true;
85321+
85322 if (atomic_read(&task->signal->live) != 1)
85323 return false;
85324
85325diff --git a/lib/kobject.c b/lib/kobject.c
85326index 4a1f33d..2f3ca75 100644
85327--- a/lib/kobject.c
85328+++ b/lib/kobject.c
85329@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85330
85331
85332 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85333-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85334+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85335
85336-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85337+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85338 {
85339 enum kobj_ns_type type = ops->type;
85340 int error;
85341diff --git a/lib/list_debug.c b/lib/list_debug.c
85342index c24c2f7..06e070b 100644
85343--- a/lib/list_debug.c
85344+++ b/lib/list_debug.c
85345@@ -11,7 +11,9 @@
85346 #include <linux/bug.h>
85347 #include <linux/kernel.h>
85348 #include <linux/rculist.h>
85349+#include <linux/mm.h>
85350
85351+#ifdef CONFIG_DEBUG_LIST
85352 /*
85353 * Insert a new entry between two known consecutive entries.
85354 *
85355@@ -19,21 +21,32 @@
85356 * the prev/next entries already!
85357 */
85358
85359-void __list_add(struct list_head *new,
85360- struct list_head *prev,
85361- struct list_head *next)
85362+static bool __list_add_debug(struct list_head *new,
85363+ struct list_head *prev,
85364+ struct list_head *next)
85365 {
85366- WARN(next->prev != prev,
85367+ if (WARN(next->prev != prev,
85368 "list_add corruption. next->prev should be "
85369 "prev (%p), but was %p. (next=%p).\n",
85370- prev, next->prev, next);
85371- WARN(prev->next != next,
85372+ prev, next->prev, next) ||
85373+ WARN(prev->next != next,
85374 "list_add corruption. prev->next should be "
85375 "next (%p), but was %p. (prev=%p).\n",
85376- next, prev->next, prev);
85377- WARN(new == prev || new == next,
85378- "list_add double add: new=%p, prev=%p, next=%p.\n",
85379- new, prev, next);
85380+ next, prev->next, prev) ||
85381+ WARN(new == prev || new == next,
85382+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85383+ new, prev, next))
85384+ return false;
85385+ return true;
85386+}
85387+
85388+void __list_add(struct list_head *new,
85389+ struct list_head *prev,
85390+ struct list_head *next)
85391+{
85392+ if (!__list_add_debug(new, prev, next))
85393+ return;
85394+
85395 next->prev = new;
85396 new->next = next;
85397 new->prev = prev;
85398@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85399 }
85400 EXPORT_SYMBOL(__list_add);
85401
85402-void __list_del_entry(struct list_head *entry)
85403+static bool __list_del_entry_debug(struct list_head *entry)
85404 {
85405 struct list_head *prev, *next;
85406
85407@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85408 WARN(next->prev != entry,
85409 "list_del corruption. next->prev should be %p, "
85410 "but was %p\n", entry, next->prev))
85411+ return false;
85412+ return true;
85413+}
85414+
85415+void __list_del_entry(struct list_head *entry)
85416+{
85417+ if (!__list_del_entry_debug(entry))
85418 return;
85419
85420- __list_del(prev, next);
85421+ __list_del(entry->prev, entry->next);
85422 }
85423 EXPORT_SYMBOL(__list_del_entry);
85424
85425@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85426 void __list_add_rcu(struct list_head *new,
85427 struct list_head *prev, struct list_head *next)
85428 {
85429- WARN(next->prev != prev,
85430- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85431- prev, next->prev, next);
85432- WARN(prev->next != next,
85433- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85434- next, prev->next, prev);
85435+ if (!__list_add_debug(new, prev, next))
85436+ return;
85437+
85438 new->next = next;
85439 new->prev = prev;
85440 rcu_assign_pointer(list_next_rcu(prev), new);
85441 next->prev = new;
85442 }
85443 EXPORT_SYMBOL(__list_add_rcu);
85444+#endif
85445+
85446+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85447+{
85448+#ifdef CONFIG_DEBUG_LIST
85449+ if (!__list_add_debug(new, prev, next))
85450+ return;
85451+#endif
85452+
85453+ pax_open_kernel();
85454+ next->prev = new;
85455+ new->next = next;
85456+ new->prev = prev;
85457+ prev->next = new;
85458+ pax_close_kernel();
85459+}
85460+EXPORT_SYMBOL(__pax_list_add);
85461+
85462+void pax_list_del(struct list_head *entry)
85463+{
85464+#ifdef CONFIG_DEBUG_LIST
85465+ if (!__list_del_entry_debug(entry))
85466+ return;
85467+#endif
85468+
85469+ pax_open_kernel();
85470+ __list_del(entry->prev, entry->next);
85471+ entry->next = LIST_POISON1;
85472+ entry->prev = LIST_POISON2;
85473+ pax_close_kernel();
85474+}
85475+EXPORT_SYMBOL(pax_list_del);
85476+
85477+void pax_list_del_init(struct list_head *entry)
85478+{
85479+ pax_open_kernel();
85480+ __list_del(entry->prev, entry->next);
85481+ INIT_LIST_HEAD(entry);
85482+ pax_close_kernel();
85483+}
85484+EXPORT_SYMBOL(pax_list_del_init);
85485+
85486+void __pax_list_add_rcu(struct list_head *new,
85487+ struct list_head *prev, struct list_head *next)
85488+{
85489+#ifdef CONFIG_DEBUG_LIST
85490+ if (!__list_add_debug(new, prev, next))
85491+ return;
85492+#endif
85493+
85494+ pax_open_kernel();
85495+ new->next = next;
85496+ new->prev = prev;
85497+ rcu_assign_pointer(list_next_rcu(prev), new);
85498+ next->prev = new;
85499+ pax_close_kernel();
85500+}
85501+EXPORT_SYMBOL(__pax_list_add_rcu);
85502+
85503+void pax_list_del_rcu(struct list_head *entry)
85504+{
85505+#ifdef CONFIG_DEBUG_LIST
85506+ if (!__list_del_entry_debug(entry))
85507+ return;
85508+#endif
85509+
85510+ pax_open_kernel();
85511+ __list_del(entry->prev, entry->next);
85512+ entry->next = LIST_POISON1;
85513+ entry->prev = LIST_POISON2;
85514+ pax_close_kernel();
85515+}
85516+EXPORT_SYMBOL(pax_list_del_rcu);
85517diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85518index 7deeb62..144eb47 100644
85519--- a/lib/percpu-refcount.c
85520+++ b/lib/percpu-refcount.c
85521@@ -29,7 +29,7 @@
85522 * can't hit 0 before we've added up all the percpu refs.
85523 */
85524
85525-#define PCPU_COUNT_BIAS (1U << 31)
85526+#define PCPU_COUNT_BIAS (1U << 30)
85527
85528 /**
85529 * percpu_ref_init - initialize a percpu refcount
85530diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85531index e796429..6e38f9f 100644
85532--- a/lib/radix-tree.c
85533+++ b/lib/radix-tree.c
85534@@ -92,7 +92,7 @@ struct radix_tree_preload {
85535 int nr;
85536 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85537 };
85538-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85539+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85540
85541 static inline void *ptr_to_indirect(void *ptr)
85542 {
85543diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85544index bb2b201..46abaf9 100644
85545--- a/lib/strncpy_from_user.c
85546+++ b/lib/strncpy_from_user.c
85547@@ -21,7 +21,7 @@
85548 */
85549 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85550 {
85551- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85552+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85553 long res = 0;
85554
85555 /*
85556diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85557index a28df52..3d55877 100644
85558--- a/lib/strnlen_user.c
85559+++ b/lib/strnlen_user.c
85560@@ -26,7 +26,7 @@
85561 */
85562 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85563 {
85564- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85565+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85566 long align, res = 0;
85567 unsigned long c;
85568
85569diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85570index d23762e..e21eab2 100644
85571--- a/lib/swiotlb.c
85572+++ b/lib/swiotlb.c
85573@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85574
85575 void
85576 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85577- dma_addr_t dev_addr)
85578+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85579 {
85580 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85581
85582diff --git a/lib/usercopy.c b/lib/usercopy.c
85583index 4f5b1dd..7cab418 100644
85584--- a/lib/usercopy.c
85585+++ b/lib/usercopy.c
85586@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85587 WARN(1, "Buffer overflow detected!\n");
85588 }
85589 EXPORT_SYMBOL(copy_from_user_overflow);
85590+
85591+void copy_to_user_overflow(void)
85592+{
85593+ WARN(1, "Buffer overflow detected!\n");
85594+}
85595+EXPORT_SYMBOL(copy_to_user_overflow);
85596diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85597index 739a363..aa668d7 100644
85598--- a/lib/vsprintf.c
85599+++ b/lib/vsprintf.c
85600@@ -16,6 +16,9 @@
85601 * - scnprintf and vscnprintf
85602 */
85603
85604+#ifdef CONFIG_GRKERNSEC_HIDESYM
85605+#define __INCLUDED_BY_HIDESYM 1
85606+#endif
85607 #include <stdarg.h>
85608 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85609 #include <linux/types.h>
85610@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85611 return number(buf, end, *(const netdev_features_t *)addr, spec);
85612 }
85613
85614+#ifdef CONFIG_GRKERNSEC_HIDESYM
85615+int kptr_restrict __read_mostly = 2;
85616+#else
85617 int kptr_restrict __read_mostly;
85618+#endif
85619
85620 /*
85621 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85622@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85623 * - 'f' For simple symbolic function names without offset
85624 * - 'S' For symbolic direct pointers with offset
85625 * - 's' For symbolic direct pointers without offset
85626+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85627 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85628 * - 'B' For backtraced symbolic direct pointers with offset
85629 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85630@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85631
85632 if (!ptr && *fmt != 'K') {
85633 /*
85634- * Print (null) with the same width as a pointer so it makes
85635+ * Print (nil) with the same width as a pointer so it makes
85636 * tabular output look nice.
85637 */
85638 if (spec.field_width == -1)
85639 spec.field_width = default_width;
85640- return string(buf, end, "(null)", spec);
85641+ return string(buf, end, "(nil)", spec);
85642 }
85643
85644 switch (*fmt) {
85645@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85646 /* Fallthrough */
85647 case 'S':
85648 case 's':
85649+#ifdef CONFIG_GRKERNSEC_HIDESYM
85650+ break;
85651+#else
85652+ return symbol_string(buf, end, ptr, spec, fmt);
85653+#endif
85654+ case 'A':
85655 case 'B':
85656 return symbol_string(buf, end, ptr, spec, fmt);
85657 case 'R':
85658@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85659 va_end(va);
85660 return buf;
85661 }
85662+ case 'P':
85663+ break;
85664 case 'K':
85665 /*
85666 * %pK cannot be used in IRQ context because its test
85667@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85668 return number(buf, end,
85669 (unsigned long long) *((phys_addr_t *)ptr), spec);
85670 }
85671+
85672+#ifdef CONFIG_GRKERNSEC_HIDESYM
85673+ /* 'P' = approved pointers to copy to userland,
85674+ as in the /proc/kallsyms case, as we make it display nothing
85675+ for non-root users, and the real contents for root users
85676+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85677+ above
85678+ */
85679+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85680+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85681+ dump_stack();
85682+ ptr = NULL;
85683+ }
85684+#endif
85685+
85686 spec.flags |= SMALL;
85687 if (spec.field_width == -1) {
85688 spec.field_width = default_width;
85689@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85690 typeof(type) value; \
85691 if (sizeof(type) == 8) { \
85692 args = PTR_ALIGN(args, sizeof(u32)); \
85693- *(u32 *)&value = *(u32 *)args; \
85694- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85695+ *(u32 *)&value = *(const u32 *)args; \
85696+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85697 } else { \
85698 args = PTR_ALIGN(args, sizeof(type)); \
85699- value = *(typeof(type) *)args; \
85700+ value = *(const typeof(type) *)args; \
85701 } \
85702 args += sizeof(type); \
85703 value; \
85704@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85705 case FORMAT_TYPE_STR: {
85706 const char *str_arg = args;
85707 args += strlen(str_arg) + 1;
85708- str = string(str, end, (char *)str_arg, spec);
85709+ str = string(str, end, str_arg, spec);
85710 break;
85711 }
85712
85713diff --git a/localversion-grsec b/localversion-grsec
85714new file mode 100644
85715index 0000000..7cd6065
85716--- /dev/null
85717+++ b/localversion-grsec
85718@@ -0,0 +1 @@
85719+-grsec
85720diff --git a/mm/Kconfig b/mm/Kconfig
85721index 6509d27..dbec5b8 100644
85722--- a/mm/Kconfig
85723+++ b/mm/Kconfig
85724@@ -317,10 +317,10 @@ config KSM
85725 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85726
85727 config DEFAULT_MMAP_MIN_ADDR
85728- int "Low address space to protect from user allocation"
85729+ int "Low address space to protect from user allocation"
85730 depends on MMU
85731- default 4096
85732- help
85733+ default 65536
85734+ help
85735 This is the portion of low virtual memory which should be protected
85736 from userspace allocation. Keeping a user from writing to low pages
85737 can help reduce the impact of kernel NULL pointer bugs.
85738@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85739
85740 config HWPOISON_INJECT
85741 tristate "HWPoison pages injector"
85742- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85743+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85744 select PROC_PAGE_MONITOR
85745
85746 config NOMMU_INITIAL_TRIM_EXCESS
85747diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85748index e04454c..ca5be3e 100644
85749--- a/mm/backing-dev.c
85750+++ b/mm/backing-dev.c
85751@@ -12,7 +12,7 @@
85752 #include <linux/device.h>
85753 #include <trace/events/writeback.h>
85754
85755-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85756+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85757
85758 struct backing_dev_info default_backing_dev_info = {
85759 .name = "default",
85760@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85761 return err;
85762
85763 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85764- atomic_long_inc_return(&bdi_seq));
85765+ atomic_long_inc_return_unchecked(&bdi_seq));
85766 if (err) {
85767 bdi_destroy(bdi);
85768 return err;
85769diff --git a/mm/filemap.c b/mm/filemap.c
85770index 4b51ac1..5aa90ff 100644
85771--- a/mm/filemap.c
85772+++ b/mm/filemap.c
85773@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85774 struct address_space *mapping = file->f_mapping;
85775
85776 if (!mapping->a_ops->readpage)
85777- return -ENOEXEC;
85778+ return -ENODEV;
85779 file_accessed(file);
85780 vma->vm_ops = &generic_file_vm_ops;
85781 return 0;
85782@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85783
85784 while (bytes) {
85785 char __user *buf = iov->iov_base + base;
85786- int copy = min(bytes, iov->iov_len - base);
85787+ size_t copy = min(bytes, iov->iov_len - base);
85788
85789 base = 0;
85790 left = __copy_from_user_inatomic(vaddr, buf, copy);
85791@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85792 BUG_ON(!in_atomic());
85793 kaddr = kmap_atomic(page);
85794 if (likely(i->nr_segs == 1)) {
85795- int left;
85796+ size_t left;
85797 char __user *buf = i->iov->iov_base + i->iov_offset;
85798 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85799 copied = bytes - left;
85800@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85801
85802 kaddr = kmap(page);
85803 if (likely(i->nr_segs == 1)) {
85804- int left;
85805+ size_t left;
85806 char __user *buf = i->iov->iov_base + i->iov_offset;
85807 left = __copy_from_user(kaddr + offset, buf, bytes);
85808 copied = bytes - left;
85809@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85810 * zero-length segments (without overruning the iovec).
85811 */
85812 while (bytes || unlikely(i->count && !iov->iov_len)) {
85813- int copy;
85814+ size_t copy;
85815
85816 copy = min(bytes, iov->iov_len - base);
85817 BUG_ON(!i->count || i->count < copy);
85818@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85819 *pos = i_size_read(inode);
85820
85821 if (limit != RLIM_INFINITY) {
85822+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85823 if (*pos >= limit) {
85824 send_sig(SIGXFSZ, current, 0);
85825 return -EFBIG;
85826diff --git a/mm/fremap.c b/mm/fremap.c
85827index 5bff081..d8189a9 100644
85828--- a/mm/fremap.c
85829+++ b/mm/fremap.c
85830@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85831 retry:
85832 vma = find_vma(mm, start);
85833
85834+#ifdef CONFIG_PAX_SEGMEXEC
85835+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85836+ goto out;
85837+#endif
85838+
85839 /*
85840 * Make sure the vma is shared, that it supports prefaulting,
85841 * and that the remapped range is valid and fully within
85842diff --git a/mm/highmem.c b/mm/highmem.c
85843index b32b70c..e512eb0 100644
85844--- a/mm/highmem.c
85845+++ b/mm/highmem.c
85846@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85847 * So no dangers, even with speculative execution.
85848 */
85849 page = pte_page(pkmap_page_table[i]);
85850+ pax_open_kernel();
85851 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85852-
85853+ pax_close_kernel();
85854 set_page_address(page, NULL);
85855 need_flush = 1;
85856 }
85857@@ -198,9 +199,11 @@ start:
85858 }
85859 }
85860 vaddr = PKMAP_ADDR(last_pkmap_nr);
85861+
85862+ pax_open_kernel();
85863 set_pte_at(&init_mm, vaddr,
85864 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85865-
85866+ pax_close_kernel();
85867 pkmap_count[last_pkmap_nr] = 1;
85868 set_page_address(page, (void *)vaddr);
85869
85870diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85871index b60f330..ee7de7e 100644
85872--- a/mm/hugetlb.c
85873+++ b/mm/hugetlb.c
85874@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85875 struct hstate *h = &default_hstate;
85876 unsigned long tmp;
85877 int ret;
85878+ ctl_table_no_const hugetlb_table;
85879
85880 tmp = h->max_huge_pages;
85881
85882 if (write && h->order >= MAX_ORDER)
85883 return -EINVAL;
85884
85885- table->data = &tmp;
85886- table->maxlen = sizeof(unsigned long);
85887- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85888+ hugetlb_table = *table;
85889+ hugetlb_table.data = &tmp;
85890+ hugetlb_table.maxlen = sizeof(unsigned long);
85891+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85892 if (ret)
85893 goto out;
85894
85895@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85896 struct hstate *h = &default_hstate;
85897 unsigned long tmp;
85898 int ret;
85899+ ctl_table_no_const hugetlb_table;
85900
85901 tmp = h->nr_overcommit_huge_pages;
85902
85903 if (write && h->order >= MAX_ORDER)
85904 return -EINVAL;
85905
85906- table->data = &tmp;
85907- table->maxlen = sizeof(unsigned long);
85908- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85909+ hugetlb_table = *table;
85910+ hugetlb_table.data = &tmp;
85911+ hugetlb_table.maxlen = sizeof(unsigned long);
85912+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85913 if (ret)
85914 goto out;
85915
85916@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
85917 return 1;
85918 }
85919
85920+#ifdef CONFIG_PAX_SEGMEXEC
85921+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
85922+{
85923+ struct mm_struct *mm = vma->vm_mm;
85924+ struct vm_area_struct *vma_m;
85925+ unsigned long address_m;
85926+ pte_t *ptep_m;
85927+
85928+ vma_m = pax_find_mirror_vma(vma);
85929+ if (!vma_m)
85930+ return;
85931+
85932+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85933+ address_m = address + SEGMEXEC_TASK_SIZE;
85934+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
85935+ get_page(page_m);
85936+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
85937+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
85938+}
85939+#endif
85940+
85941 /*
85942 * Hugetlb_cow() should be called with page lock of the original hugepage held.
85943 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
85944@@ -2663,6 +2688,11 @@ retry_avoidcopy:
85945 make_huge_pte(vma, new_page, 1));
85946 page_remove_rmap(old_page);
85947 hugepage_add_new_anon_rmap(new_page, vma, address);
85948+
85949+#ifdef CONFIG_PAX_SEGMEXEC
85950+ pax_mirror_huge_pte(vma, address, new_page);
85951+#endif
85952+
85953 /* Make the old page be freed below */
85954 new_page = old_page;
85955 }
85956@@ -2821,6 +2851,10 @@ retry:
85957 && (vma->vm_flags & VM_SHARED)));
85958 set_huge_pte_at(mm, address, ptep, new_pte);
85959
85960+#ifdef CONFIG_PAX_SEGMEXEC
85961+ pax_mirror_huge_pte(vma, address, page);
85962+#endif
85963+
85964 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
85965 /* Optimization, do the COW without a second fault */
85966 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
85967@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85968 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
85969 struct hstate *h = hstate_vma(vma);
85970
85971+#ifdef CONFIG_PAX_SEGMEXEC
85972+ struct vm_area_struct *vma_m;
85973+#endif
85974+
85975 address &= huge_page_mask(h);
85976
85977 ptep = huge_pte_offset(mm, address);
85978@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85979 VM_FAULT_SET_HINDEX(hstate_index(h));
85980 }
85981
85982+#ifdef CONFIG_PAX_SEGMEXEC
85983+ vma_m = pax_find_mirror_vma(vma);
85984+ if (vma_m) {
85985+ unsigned long address_m;
85986+
85987+ if (vma->vm_start > vma_m->vm_start) {
85988+ address_m = address;
85989+ address -= SEGMEXEC_TASK_SIZE;
85990+ vma = vma_m;
85991+ h = hstate_vma(vma);
85992+ } else
85993+ address_m = address + SEGMEXEC_TASK_SIZE;
85994+
85995+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
85996+ return VM_FAULT_OOM;
85997+ address_m &= HPAGE_MASK;
85998+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
85999+ }
86000+#endif
86001+
86002 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86003 if (!ptep)
86004 return VM_FAULT_OOM;
86005diff --git a/mm/internal.h b/mm/internal.h
86006index 4390ac6..fc60373c 100644
86007--- a/mm/internal.h
86008+++ b/mm/internal.h
86009@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86010 * in mm/page_alloc.c
86011 */
86012 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86013+extern void free_compound_page(struct page *page);
86014 extern void prep_compound_page(struct page *page, unsigned long order);
86015 #ifdef CONFIG_MEMORY_FAILURE
86016 extern bool is_free_buddy_page(struct page *page);
86017@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86018
86019 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86020 unsigned long, unsigned long,
86021- unsigned long, unsigned long);
86022+ unsigned long, unsigned long) __intentional_overflow(-1);
86023
86024 extern void set_pageblock_order(void);
86025 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86026diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86027index c8d7f31..2dbeffd 100644
86028--- a/mm/kmemleak.c
86029+++ b/mm/kmemleak.c
86030@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86031
86032 for (i = 0; i < object->trace_len; i++) {
86033 void *ptr = (void *)object->trace[i];
86034- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86035+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86036 }
86037 }
86038
86039@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86040 return -ENOMEM;
86041 }
86042
86043- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86044+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86045 &kmemleak_fops);
86046 if (!dentry)
86047 pr_warning("Failed to create the debugfs kmemleak file\n");
86048diff --git a/mm/maccess.c b/mm/maccess.c
86049index d53adf9..03a24bf 100644
86050--- a/mm/maccess.c
86051+++ b/mm/maccess.c
86052@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86053 set_fs(KERNEL_DS);
86054 pagefault_disable();
86055 ret = __copy_from_user_inatomic(dst,
86056- (__force const void __user *)src, size);
86057+ (const void __force_user *)src, size);
86058 pagefault_enable();
86059 set_fs(old_fs);
86060
86061@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86062
86063 set_fs(KERNEL_DS);
86064 pagefault_disable();
86065- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86066+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86067 pagefault_enable();
86068 set_fs(old_fs);
86069
86070diff --git a/mm/madvise.c b/mm/madvise.c
86071index 7055883..aafb1ed 100644
86072--- a/mm/madvise.c
86073+++ b/mm/madvise.c
86074@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86075 pgoff_t pgoff;
86076 unsigned long new_flags = vma->vm_flags;
86077
86078+#ifdef CONFIG_PAX_SEGMEXEC
86079+ struct vm_area_struct *vma_m;
86080+#endif
86081+
86082 switch (behavior) {
86083 case MADV_NORMAL:
86084 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86085@@ -126,6 +130,13 @@ success:
86086 /*
86087 * vm_flags is protected by the mmap_sem held in write mode.
86088 */
86089+
86090+#ifdef CONFIG_PAX_SEGMEXEC
86091+ vma_m = pax_find_mirror_vma(vma);
86092+ if (vma_m)
86093+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86094+#endif
86095+
86096 vma->vm_flags = new_flags;
86097
86098 out:
86099@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86100 struct vm_area_struct ** prev,
86101 unsigned long start, unsigned long end)
86102 {
86103+
86104+#ifdef CONFIG_PAX_SEGMEXEC
86105+ struct vm_area_struct *vma_m;
86106+#endif
86107+
86108 *prev = vma;
86109 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86110 return -EINVAL;
86111@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86112 zap_page_range(vma, start, end - start, &details);
86113 } else
86114 zap_page_range(vma, start, end - start, NULL);
86115+
86116+#ifdef CONFIG_PAX_SEGMEXEC
86117+ vma_m = pax_find_mirror_vma(vma);
86118+ if (vma_m) {
86119+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86120+ struct zap_details details = {
86121+ .nonlinear_vma = vma_m,
86122+ .last_index = ULONG_MAX,
86123+ };
86124+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86125+ } else
86126+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86127+ }
86128+#endif
86129+
86130 return 0;
86131 }
86132
86133@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86134 if (end < start)
86135 return error;
86136
86137+#ifdef CONFIG_PAX_SEGMEXEC
86138+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86139+ if (end > SEGMEXEC_TASK_SIZE)
86140+ return error;
86141+ } else
86142+#endif
86143+
86144+ if (end > TASK_SIZE)
86145+ return error;
86146+
86147 error = 0;
86148 if (end == start)
86149 return error;
86150diff --git a/mm/memcontrol.c b/mm/memcontrol.c
86151index aa44621..99011b3 100644
86152--- a/mm/memcontrol.c
86153+++ b/mm/memcontrol.c
86154@@ -2772,6 +2772,8 @@ done:
86155 return 0;
86156 nomem:
86157 *ptr = NULL;
86158+ if (gfp_mask & __GFP_NOFAIL)
86159+ return 0;
86160 return -ENOMEM;
86161 bypass:
86162 *ptr = root_mem_cgroup;
86163diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86164index 2c13aa7..64cbc3f 100644
86165--- a/mm/memory-failure.c
86166+++ b/mm/memory-failure.c
86167@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86168
86169 int sysctl_memory_failure_recovery __read_mostly = 1;
86170
86171-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86172+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86173
86174 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86175
86176@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86177 pfn, t->comm, t->pid);
86178 si.si_signo = SIGBUS;
86179 si.si_errno = 0;
86180- si.si_addr = (void *)addr;
86181+ si.si_addr = (void __user *)addr;
86182 #ifdef __ARCH_SI_TRAPNO
86183 si.si_trapno = trapno;
86184 #endif
86185@@ -760,7 +760,7 @@ static struct page_state {
86186 unsigned long res;
86187 char *msg;
86188 int (*action)(struct page *p, unsigned long pfn);
86189-} error_states[] = {
86190+} __do_const error_states[] = {
86191 { reserved, reserved, "reserved kernel", me_kernel },
86192 /*
86193 * free pages are specially detected outside this table:
86194@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86195 nr_pages = 1 << compound_order(hpage);
86196 else /* normal page or thp */
86197 nr_pages = 1;
86198- atomic_long_add(nr_pages, &num_poisoned_pages);
86199+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86200
86201 /*
86202 * We need/can do nothing about count=0 pages.
86203@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86204 if (!PageHWPoison(hpage)
86205 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86206 || (p != hpage && TestSetPageHWPoison(hpage))) {
86207- atomic_long_sub(nr_pages, &num_poisoned_pages);
86208+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86209 return 0;
86210 }
86211 set_page_hwpoison_huge_page(hpage);
86212@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86213 }
86214 if (hwpoison_filter(p)) {
86215 if (TestClearPageHWPoison(p))
86216- atomic_long_sub(nr_pages, &num_poisoned_pages);
86217+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86218 unlock_page(hpage);
86219 put_page(hpage);
86220 return 0;
86221@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86222 return 0;
86223 }
86224 if (TestClearPageHWPoison(p))
86225- atomic_long_sub(nr_pages, &num_poisoned_pages);
86226+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86227 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86228 return 0;
86229 }
86230@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86231 */
86232 if (TestClearPageHWPoison(page)) {
86233 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86234- atomic_long_sub(nr_pages, &num_poisoned_pages);
86235+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86236 freeit = 1;
86237 if (PageHuge(page))
86238 clear_page_hwpoison_huge_page(page);
86239@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86240 } else {
86241 set_page_hwpoison_huge_page(hpage);
86242 dequeue_hwpoisoned_huge_page(hpage);
86243- atomic_long_add(1 << compound_trans_order(hpage),
86244+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86245 &num_poisoned_pages);
86246 }
86247 return ret;
86248@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86249 if (PageHuge(page)) {
86250 set_page_hwpoison_huge_page(hpage);
86251 dequeue_hwpoisoned_huge_page(hpage);
86252- atomic_long_add(1 << compound_trans_order(hpage),
86253+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86254 &num_poisoned_pages);
86255 } else {
86256 SetPageHWPoison(page);
86257- atomic_long_inc(&num_poisoned_pages);
86258+ atomic_long_inc_unchecked(&num_poisoned_pages);
86259 }
86260 }
86261 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86262@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86263 put_page(page);
86264 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86265 SetPageHWPoison(page);
86266- atomic_long_inc(&num_poisoned_pages);
86267+ atomic_long_inc_unchecked(&num_poisoned_pages);
86268 return 0;
86269 }
86270
86271@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86272 if (!is_free_buddy_page(page))
86273 pr_info("soft offline: %#lx: page leaked\n",
86274 pfn);
86275- atomic_long_inc(&num_poisoned_pages);
86276+ atomic_long_inc_unchecked(&num_poisoned_pages);
86277 }
86278 } else {
86279 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86280diff --git a/mm/memory.c b/mm/memory.c
86281index af84bc0..2ed0816 100644
86282--- a/mm/memory.c
86283+++ b/mm/memory.c
86284@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86285 free_pte_range(tlb, pmd, addr);
86286 } while (pmd++, addr = next, addr != end);
86287
86288+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86289 start &= PUD_MASK;
86290 if (start < floor)
86291 return;
86292@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86293 pmd = pmd_offset(pud, start);
86294 pud_clear(pud);
86295 pmd_free_tlb(tlb, pmd, start);
86296+#endif
86297+
86298 }
86299
86300 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86301@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86302 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86303 } while (pud++, addr = next, addr != end);
86304
86305+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86306 start &= PGDIR_MASK;
86307 if (start < floor)
86308 return;
86309@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86310 pud = pud_offset(pgd, start);
86311 pgd_clear(pgd);
86312 pud_free_tlb(tlb, pud, start);
86313+#endif
86314+
86315 }
86316
86317 /*
86318@@ -1645,12 +1651,6 @@ no_page_table:
86319 return page;
86320 }
86321
86322-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86323-{
86324- return stack_guard_page_start(vma, addr) ||
86325- stack_guard_page_end(vma, addr+PAGE_SIZE);
86326-}
86327-
86328 /**
86329 * __get_user_pages() - pin user pages in memory
86330 * @tsk: task_struct of target task
86331@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86332
86333 i = 0;
86334
86335- do {
86336+ while (nr_pages) {
86337 struct vm_area_struct *vma;
86338
86339- vma = find_extend_vma(mm, start);
86340+ vma = find_vma(mm, start);
86341 if (!vma && in_gate_area(mm, start)) {
86342 unsigned long pg = start & PAGE_MASK;
86343 pgd_t *pgd;
86344@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86345 goto next_page;
86346 }
86347
86348- if (!vma ||
86349+ if (!vma || start < vma->vm_start ||
86350 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86351 !(vm_flags & vma->vm_flags))
86352 return i ? : -EFAULT;
86353@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86354 int ret;
86355 unsigned int fault_flags = 0;
86356
86357- /* For mlock, just skip the stack guard page. */
86358- if (foll_flags & FOLL_MLOCK) {
86359- if (stack_guard_page(vma, start))
86360- goto next_page;
86361- }
86362 if (foll_flags & FOLL_WRITE)
86363 fault_flags |= FAULT_FLAG_WRITE;
86364 if (nonblocking)
86365@@ -1902,7 +1897,7 @@ next_page:
86366 start += page_increm * PAGE_SIZE;
86367 nr_pages -= page_increm;
86368 } while (nr_pages && start < vma->vm_end);
86369- } while (nr_pages);
86370+ }
86371 return i;
86372 }
86373 EXPORT_SYMBOL(__get_user_pages);
86374@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86375 page_add_file_rmap(page);
86376 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86377
86378+#ifdef CONFIG_PAX_SEGMEXEC
86379+ pax_mirror_file_pte(vma, addr, page, ptl);
86380+#endif
86381+
86382 retval = 0;
86383 pte_unmap_unlock(pte, ptl);
86384 return retval;
86385@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86386 if (!page_count(page))
86387 return -EINVAL;
86388 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86389+
86390+#ifdef CONFIG_PAX_SEGMEXEC
86391+ struct vm_area_struct *vma_m;
86392+#endif
86393+
86394 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86395 BUG_ON(vma->vm_flags & VM_PFNMAP);
86396 vma->vm_flags |= VM_MIXEDMAP;
86397+
86398+#ifdef CONFIG_PAX_SEGMEXEC
86399+ vma_m = pax_find_mirror_vma(vma);
86400+ if (vma_m)
86401+ vma_m->vm_flags |= VM_MIXEDMAP;
86402+#endif
86403+
86404 }
86405 return insert_page(vma, addr, page, vma->vm_page_prot);
86406 }
86407@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86408 unsigned long pfn)
86409 {
86410 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86411+ BUG_ON(vma->vm_mirror);
86412
86413 if (addr < vma->vm_start || addr >= vma->vm_end)
86414 return -EFAULT;
86415@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86416
86417 BUG_ON(pud_huge(*pud));
86418
86419- pmd = pmd_alloc(mm, pud, addr);
86420+ pmd = (mm == &init_mm) ?
86421+ pmd_alloc_kernel(mm, pud, addr) :
86422+ pmd_alloc(mm, pud, addr);
86423 if (!pmd)
86424 return -ENOMEM;
86425 do {
86426@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86427 unsigned long next;
86428 int err;
86429
86430- pud = pud_alloc(mm, pgd, addr);
86431+ pud = (mm == &init_mm) ?
86432+ pud_alloc_kernel(mm, pgd, addr) :
86433+ pud_alloc(mm, pgd, addr);
86434 if (!pud)
86435 return -ENOMEM;
86436 do {
86437@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86438 copy_user_highpage(dst, src, va, vma);
86439 }
86440
86441+#ifdef CONFIG_PAX_SEGMEXEC
86442+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86443+{
86444+ struct mm_struct *mm = vma->vm_mm;
86445+ spinlock_t *ptl;
86446+ pte_t *pte, entry;
86447+
86448+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86449+ entry = *pte;
86450+ if (!pte_present(entry)) {
86451+ if (!pte_none(entry)) {
86452+ BUG_ON(pte_file(entry));
86453+ free_swap_and_cache(pte_to_swp_entry(entry));
86454+ pte_clear_not_present_full(mm, address, pte, 0);
86455+ }
86456+ } else {
86457+ struct page *page;
86458+
86459+ flush_cache_page(vma, address, pte_pfn(entry));
86460+ entry = ptep_clear_flush(vma, address, pte);
86461+ BUG_ON(pte_dirty(entry));
86462+ page = vm_normal_page(vma, address, entry);
86463+ if (page) {
86464+ update_hiwater_rss(mm);
86465+ if (PageAnon(page))
86466+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86467+ else
86468+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86469+ page_remove_rmap(page);
86470+ page_cache_release(page);
86471+ }
86472+ }
86473+ pte_unmap_unlock(pte, ptl);
86474+}
86475+
86476+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86477+ *
86478+ * the ptl of the lower mapped page is held on entry and is not released on exit
86479+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86480+ */
86481+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86482+{
86483+ struct mm_struct *mm = vma->vm_mm;
86484+ unsigned long address_m;
86485+ spinlock_t *ptl_m;
86486+ struct vm_area_struct *vma_m;
86487+ pmd_t *pmd_m;
86488+ pte_t *pte_m, entry_m;
86489+
86490+ BUG_ON(!page_m || !PageAnon(page_m));
86491+
86492+ vma_m = pax_find_mirror_vma(vma);
86493+ if (!vma_m)
86494+ return;
86495+
86496+ BUG_ON(!PageLocked(page_m));
86497+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86498+ address_m = address + SEGMEXEC_TASK_SIZE;
86499+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86500+ pte_m = pte_offset_map(pmd_m, address_m);
86501+ ptl_m = pte_lockptr(mm, pmd_m);
86502+ if (ptl != ptl_m) {
86503+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86504+ if (!pte_none(*pte_m))
86505+ goto out;
86506+ }
86507+
86508+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86509+ page_cache_get(page_m);
86510+ page_add_anon_rmap(page_m, vma_m, address_m);
86511+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86512+ set_pte_at(mm, address_m, pte_m, entry_m);
86513+ update_mmu_cache(vma_m, address_m, pte_m);
86514+out:
86515+ if (ptl != ptl_m)
86516+ spin_unlock(ptl_m);
86517+ pte_unmap(pte_m);
86518+ unlock_page(page_m);
86519+}
86520+
86521+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86522+{
86523+ struct mm_struct *mm = vma->vm_mm;
86524+ unsigned long address_m;
86525+ spinlock_t *ptl_m;
86526+ struct vm_area_struct *vma_m;
86527+ pmd_t *pmd_m;
86528+ pte_t *pte_m, entry_m;
86529+
86530+ BUG_ON(!page_m || PageAnon(page_m));
86531+
86532+ vma_m = pax_find_mirror_vma(vma);
86533+ if (!vma_m)
86534+ return;
86535+
86536+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86537+ address_m = address + SEGMEXEC_TASK_SIZE;
86538+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86539+ pte_m = pte_offset_map(pmd_m, address_m);
86540+ ptl_m = pte_lockptr(mm, pmd_m);
86541+ if (ptl != ptl_m) {
86542+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86543+ if (!pte_none(*pte_m))
86544+ goto out;
86545+ }
86546+
86547+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86548+ page_cache_get(page_m);
86549+ page_add_file_rmap(page_m);
86550+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86551+ set_pte_at(mm, address_m, pte_m, entry_m);
86552+ update_mmu_cache(vma_m, address_m, pte_m);
86553+out:
86554+ if (ptl != ptl_m)
86555+ spin_unlock(ptl_m);
86556+ pte_unmap(pte_m);
86557+}
86558+
86559+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86560+{
86561+ struct mm_struct *mm = vma->vm_mm;
86562+ unsigned long address_m;
86563+ spinlock_t *ptl_m;
86564+ struct vm_area_struct *vma_m;
86565+ pmd_t *pmd_m;
86566+ pte_t *pte_m, entry_m;
86567+
86568+ vma_m = pax_find_mirror_vma(vma);
86569+ if (!vma_m)
86570+ return;
86571+
86572+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86573+ address_m = address + SEGMEXEC_TASK_SIZE;
86574+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86575+ pte_m = pte_offset_map(pmd_m, address_m);
86576+ ptl_m = pte_lockptr(mm, pmd_m);
86577+ if (ptl != ptl_m) {
86578+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86579+ if (!pte_none(*pte_m))
86580+ goto out;
86581+ }
86582+
86583+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86584+ set_pte_at(mm, address_m, pte_m, entry_m);
86585+out:
86586+ if (ptl != ptl_m)
86587+ spin_unlock(ptl_m);
86588+ pte_unmap(pte_m);
86589+}
86590+
86591+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86592+{
86593+ struct page *page_m;
86594+ pte_t entry;
86595+
86596+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86597+ goto out;
86598+
86599+ entry = *pte;
86600+ page_m = vm_normal_page(vma, address, entry);
86601+ if (!page_m)
86602+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86603+ else if (PageAnon(page_m)) {
86604+ if (pax_find_mirror_vma(vma)) {
86605+ pte_unmap_unlock(pte, ptl);
86606+ lock_page(page_m);
86607+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86608+ if (pte_same(entry, *pte))
86609+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86610+ else
86611+ unlock_page(page_m);
86612+ }
86613+ } else
86614+ pax_mirror_file_pte(vma, address, page_m, ptl);
86615+
86616+out:
86617+ pte_unmap_unlock(pte, ptl);
86618+}
86619+#endif
86620+
86621 /*
86622 * This routine handles present pages, when users try to write
86623 * to a shared page. It is done by copying the page to a new address
86624@@ -2809,6 +3005,12 @@ gotten:
86625 */
86626 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86627 if (likely(pte_same(*page_table, orig_pte))) {
86628+
86629+#ifdef CONFIG_PAX_SEGMEXEC
86630+ if (pax_find_mirror_vma(vma))
86631+ BUG_ON(!trylock_page(new_page));
86632+#endif
86633+
86634 if (old_page) {
86635 if (!PageAnon(old_page)) {
86636 dec_mm_counter_fast(mm, MM_FILEPAGES);
86637@@ -2860,6 +3062,10 @@ gotten:
86638 page_remove_rmap(old_page);
86639 }
86640
86641+#ifdef CONFIG_PAX_SEGMEXEC
86642+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86643+#endif
86644+
86645 /* Free the old page.. */
86646 new_page = old_page;
86647 ret |= VM_FAULT_WRITE;
86648@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86649 swap_free(entry);
86650 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86651 try_to_free_swap(page);
86652+
86653+#ifdef CONFIG_PAX_SEGMEXEC
86654+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86655+#endif
86656+
86657 unlock_page(page);
86658 if (page != swapcache) {
86659 /*
86660@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86661
86662 /* No need to invalidate - it was non-present before */
86663 update_mmu_cache(vma, address, page_table);
86664+
86665+#ifdef CONFIG_PAX_SEGMEXEC
86666+ pax_mirror_anon_pte(vma, address, page, ptl);
86667+#endif
86668+
86669 unlock:
86670 pte_unmap_unlock(page_table, ptl);
86671 out:
86672@@ -3179,40 +3395,6 @@ out_release:
86673 }
86674
86675 /*
86676- * This is like a special single-page "expand_{down|up}wards()",
86677- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86678- * doesn't hit another vma.
86679- */
86680-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86681-{
86682- address &= PAGE_MASK;
86683- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86684- struct vm_area_struct *prev = vma->vm_prev;
86685-
86686- /*
86687- * Is there a mapping abutting this one below?
86688- *
86689- * That's only ok if it's the same stack mapping
86690- * that has gotten split..
86691- */
86692- if (prev && prev->vm_end == address)
86693- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86694-
86695- expand_downwards(vma, address - PAGE_SIZE);
86696- }
86697- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86698- struct vm_area_struct *next = vma->vm_next;
86699-
86700- /* As VM_GROWSDOWN but s/below/above/ */
86701- if (next && next->vm_start == address + PAGE_SIZE)
86702- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86703-
86704- expand_upwards(vma, address + PAGE_SIZE);
86705- }
86706- return 0;
86707-}
86708-
86709-/*
86710 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86711 * but allow concurrent faults), and pte mapped but not yet locked.
86712 * We return with mmap_sem still held, but pte unmapped and unlocked.
86713@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86714 unsigned long address, pte_t *page_table, pmd_t *pmd,
86715 unsigned int flags)
86716 {
86717- struct page *page;
86718+ struct page *page = NULL;
86719 spinlock_t *ptl;
86720 pte_t entry;
86721
86722- pte_unmap(page_table);
86723-
86724- /* Check if we need to add a guard page to the stack */
86725- if (check_stack_guard_page(vma, address) < 0)
86726- return VM_FAULT_SIGBUS;
86727-
86728- /* Use the zero-page for reads */
86729 if (!(flags & FAULT_FLAG_WRITE)) {
86730 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86731 vma->vm_page_prot));
86732- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86733+ ptl = pte_lockptr(mm, pmd);
86734+ spin_lock(ptl);
86735 if (!pte_none(*page_table))
86736 goto unlock;
86737 goto setpte;
86738 }
86739
86740 /* Allocate our own private page. */
86741+ pte_unmap(page_table);
86742+
86743 if (unlikely(anon_vma_prepare(vma)))
86744 goto oom;
86745 page = alloc_zeroed_user_highpage_movable(vma, address);
86746@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86747 if (!pte_none(*page_table))
86748 goto release;
86749
86750+#ifdef CONFIG_PAX_SEGMEXEC
86751+ if (pax_find_mirror_vma(vma))
86752+ BUG_ON(!trylock_page(page));
86753+#endif
86754+
86755 inc_mm_counter_fast(mm, MM_ANONPAGES);
86756 page_add_new_anon_rmap(page, vma, address);
86757 setpte:
86758@@ -3272,6 +3455,12 @@ setpte:
86759
86760 /* No need to invalidate - it was non-present before */
86761 update_mmu_cache(vma, address, page_table);
86762+
86763+#ifdef CONFIG_PAX_SEGMEXEC
86764+ if (page)
86765+ pax_mirror_anon_pte(vma, address, page, ptl);
86766+#endif
86767+
86768 unlock:
86769 pte_unmap_unlock(page_table, ptl);
86770 return 0;
86771@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86772 */
86773 /* Only go through if we didn't race with anybody else... */
86774 if (likely(pte_same(*page_table, orig_pte))) {
86775+
86776+#ifdef CONFIG_PAX_SEGMEXEC
86777+ if (anon && pax_find_mirror_vma(vma))
86778+ BUG_ON(!trylock_page(page));
86779+#endif
86780+
86781 flush_icache_page(vma, page);
86782 entry = mk_pte(page, vma->vm_page_prot);
86783 if (flags & FAULT_FLAG_WRITE)
86784@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86785
86786 /* no need to invalidate: a not-present page won't be cached */
86787 update_mmu_cache(vma, address, page_table);
86788+
86789+#ifdef CONFIG_PAX_SEGMEXEC
86790+ if (anon)
86791+ pax_mirror_anon_pte(vma, address, page, ptl);
86792+ else
86793+ pax_mirror_file_pte(vma, address, page, ptl);
86794+#endif
86795+
86796 } else {
86797 if (cow_page)
86798 mem_cgroup_uncharge_page(cow_page);
86799@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86800 if (flags & FAULT_FLAG_WRITE)
86801 flush_tlb_fix_spurious_fault(vma, address);
86802 }
86803+
86804+#ifdef CONFIG_PAX_SEGMEXEC
86805+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86806+ return 0;
86807+#endif
86808+
86809 unlock:
86810 pte_unmap_unlock(pte, ptl);
86811 return 0;
86812@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86813 pmd_t *pmd;
86814 pte_t *pte;
86815
86816+#ifdef CONFIG_PAX_SEGMEXEC
86817+ struct vm_area_struct *vma_m;
86818+#endif
86819+
86820 __set_current_state(TASK_RUNNING);
86821
86822 count_vm_event(PGFAULT);
86823@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86824 if (unlikely(is_vm_hugetlb_page(vma)))
86825 return hugetlb_fault(mm, vma, address, flags);
86826
86827+#ifdef CONFIG_PAX_SEGMEXEC
86828+ vma_m = pax_find_mirror_vma(vma);
86829+ if (vma_m) {
86830+ unsigned long address_m;
86831+ pgd_t *pgd_m;
86832+ pud_t *pud_m;
86833+ pmd_t *pmd_m;
86834+
86835+ if (vma->vm_start > vma_m->vm_start) {
86836+ address_m = address;
86837+ address -= SEGMEXEC_TASK_SIZE;
86838+ vma = vma_m;
86839+ } else
86840+ address_m = address + SEGMEXEC_TASK_SIZE;
86841+
86842+ pgd_m = pgd_offset(mm, address_m);
86843+ pud_m = pud_alloc(mm, pgd_m, address_m);
86844+ if (!pud_m)
86845+ return VM_FAULT_OOM;
86846+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86847+ if (!pmd_m)
86848+ return VM_FAULT_OOM;
86849+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86850+ return VM_FAULT_OOM;
86851+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86852+ }
86853+#endif
86854+
86855 retry:
86856 pgd = pgd_offset(mm, address);
86857 pud = pud_alloc(mm, pgd, address);
86858@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86859 spin_unlock(&mm->page_table_lock);
86860 return 0;
86861 }
86862+
86863+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86864+{
86865+ pud_t *new = pud_alloc_one(mm, address);
86866+ if (!new)
86867+ return -ENOMEM;
86868+
86869+ smp_wmb(); /* See comment in __pte_alloc */
86870+
86871+ spin_lock(&mm->page_table_lock);
86872+ if (pgd_present(*pgd)) /* Another has populated it */
86873+ pud_free(mm, new);
86874+ else
86875+ pgd_populate_kernel(mm, pgd, new);
86876+ spin_unlock(&mm->page_table_lock);
86877+ return 0;
86878+}
86879 #endif /* __PAGETABLE_PUD_FOLDED */
86880
86881 #ifndef __PAGETABLE_PMD_FOLDED
86882@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86883 spin_unlock(&mm->page_table_lock);
86884 return 0;
86885 }
86886+
86887+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86888+{
86889+ pmd_t *new = pmd_alloc_one(mm, address);
86890+ if (!new)
86891+ return -ENOMEM;
86892+
86893+ smp_wmb(); /* See comment in __pte_alloc */
86894+
86895+ spin_lock(&mm->page_table_lock);
86896+#ifndef __ARCH_HAS_4LEVEL_HACK
86897+ if (pud_present(*pud)) /* Another has populated it */
86898+ pmd_free(mm, new);
86899+ else
86900+ pud_populate_kernel(mm, pud, new);
86901+#else
86902+ if (pgd_present(*pud)) /* Another has populated it */
86903+ pmd_free(mm, new);
86904+ else
86905+ pgd_populate_kernel(mm, pud, new);
86906+#endif /* __ARCH_HAS_4LEVEL_HACK */
86907+ spin_unlock(&mm->page_table_lock);
86908+ return 0;
86909+}
86910 #endif /* __PAGETABLE_PMD_FOLDED */
86911
86912 #if !defined(__HAVE_ARCH_GATE_AREA)
86913@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
86914 gate_vma.vm_start = FIXADDR_USER_START;
86915 gate_vma.vm_end = FIXADDR_USER_END;
86916 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
86917- gate_vma.vm_page_prot = __P101;
86918+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
86919
86920 return 0;
86921 }
86922@@ -4059,8 +4341,8 @@ out:
86923 return ret;
86924 }
86925
86926-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86927- void *buf, int len, int write)
86928+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86929+ void *buf, size_t len, int write)
86930 {
86931 resource_size_t phys_addr;
86932 unsigned long prot = 0;
86933@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86934 * Access another process' address space as given in mm. If non-NULL, use the
86935 * given task for page fault accounting.
86936 */
86937-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86938- unsigned long addr, void *buf, int len, int write)
86939+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86940+ unsigned long addr, void *buf, size_t len, int write)
86941 {
86942 struct vm_area_struct *vma;
86943 void *old_buf = buf;
86944@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86945 down_read(&mm->mmap_sem);
86946 /* ignore errors, just check how much was successfully transferred */
86947 while (len) {
86948- int bytes, ret, offset;
86949+ ssize_t bytes, ret, offset;
86950 void *maddr;
86951 struct page *page = NULL;
86952
86953@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86954 *
86955 * The caller must hold a reference on @mm.
86956 */
86957-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86958- void *buf, int len, int write)
86959+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
86960+ void *buf, size_t len, int write)
86961 {
86962 return __access_remote_vm(NULL, mm, addr, buf, len, write);
86963 }
86964@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86965 * Source/target buffer must be kernel space,
86966 * Do not walk the page table directly, use get_user_pages
86967 */
86968-int access_process_vm(struct task_struct *tsk, unsigned long addr,
86969- void *buf, int len, int write)
86970+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
86971+ void *buf, size_t len, int write)
86972 {
86973 struct mm_struct *mm;
86974- int ret;
86975+ ssize_t ret;
86976
86977 mm = get_task_mm(tsk);
86978 if (!mm)
86979diff --git a/mm/mempolicy.c b/mm/mempolicy.c
86980index 4baf12e..5497066 100644
86981--- a/mm/mempolicy.c
86982+++ b/mm/mempolicy.c
86983@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86984 unsigned long vmstart;
86985 unsigned long vmend;
86986
86987+#ifdef CONFIG_PAX_SEGMEXEC
86988+ struct vm_area_struct *vma_m;
86989+#endif
86990+
86991 vma = find_vma(mm, start);
86992 if (!vma || vma->vm_start > start)
86993 return -EFAULT;
86994@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86995 err = vma_replace_policy(vma, new_pol);
86996 if (err)
86997 goto out;
86998+
86999+#ifdef CONFIG_PAX_SEGMEXEC
87000+ vma_m = pax_find_mirror_vma(vma);
87001+ if (vma_m) {
87002+ err = vma_replace_policy(vma_m, new_pol);
87003+ if (err)
87004+ goto out;
87005+ }
87006+#endif
87007+
87008 }
87009
87010 out:
87011@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87012
87013 if (end < start)
87014 return -EINVAL;
87015+
87016+#ifdef CONFIG_PAX_SEGMEXEC
87017+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87018+ if (end > SEGMEXEC_TASK_SIZE)
87019+ return -EINVAL;
87020+ } else
87021+#endif
87022+
87023+ if (end > TASK_SIZE)
87024+ return -EINVAL;
87025+
87026 if (end == start)
87027 return 0;
87028
87029@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87030 */
87031 tcred = __task_cred(task);
87032 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87033- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87034- !capable(CAP_SYS_NICE)) {
87035+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87036 rcu_read_unlock();
87037 err = -EPERM;
87038 goto out_put;
87039@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87040 goto out;
87041 }
87042
87043+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87044+ if (mm != current->mm &&
87045+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87046+ mmput(mm);
87047+ err = -EPERM;
87048+ goto out;
87049+ }
87050+#endif
87051+
87052 err = do_migrate_pages(mm, old, new,
87053 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87054
87055diff --git a/mm/migrate.c b/mm/migrate.c
87056index 25ca7ca..abe1836 100644
87057--- a/mm/migrate.c
87058+++ b/mm/migrate.c
87059@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87060 */
87061 tcred = __task_cred(task);
87062 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87063- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87064- !capable(CAP_SYS_NICE)) {
87065+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87066 rcu_read_unlock();
87067 err = -EPERM;
87068 goto out;
87069diff --git a/mm/mlock.c b/mm/mlock.c
87070index 79b7cf7..37472bf 100644
87071--- a/mm/mlock.c
87072+++ b/mm/mlock.c
87073@@ -13,6 +13,7 @@
87074 #include <linux/pagemap.h>
87075 #include <linux/mempolicy.h>
87076 #include <linux/syscalls.h>
87077+#include <linux/security.h>
87078 #include <linux/sched.h>
87079 #include <linux/export.h>
87080 #include <linux/rmap.h>
87081@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87082 {
87083 unsigned long nstart, end, tmp;
87084 struct vm_area_struct * vma, * prev;
87085- int error;
87086+ int error = 0;
87087
87088 VM_BUG_ON(start & ~PAGE_MASK);
87089 VM_BUG_ON(len != PAGE_ALIGN(len));
87090@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87091 return -EINVAL;
87092 if (end == start)
87093 return 0;
87094+ if (end > TASK_SIZE)
87095+ return -EINVAL;
87096+
87097 vma = find_vma(current->mm, start);
87098 if (!vma || vma->vm_start > start)
87099 return -ENOMEM;
87100@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87101 for (nstart = start ; ; ) {
87102 vm_flags_t newflags;
87103
87104+#ifdef CONFIG_PAX_SEGMEXEC
87105+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87106+ break;
87107+#endif
87108+
87109 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87110
87111 newflags = vma->vm_flags & ~VM_LOCKED;
87112@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87113 lock_limit >>= PAGE_SHIFT;
87114
87115 /* check against resource limits */
87116+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87117 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87118 error = do_mlock(start, len, 1);
87119 up_write(&current->mm->mmap_sem);
87120@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
87121 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87122 vm_flags_t newflags;
87123
87124+#ifdef CONFIG_PAX_SEGMEXEC
87125+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87126+ break;
87127+#endif
87128+
87129 newflags = vma->vm_flags & ~VM_LOCKED;
87130 if (flags & MCL_CURRENT)
87131 newflags |= VM_LOCKED;
87132
87133 /* Ignore errors */
87134 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
87135+ cond_resched();
87136 }
87137 out:
87138 return 0;
87139@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87140 lock_limit >>= PAGE_SHIFT;
87141
87142 ret = -ENOMEM;
87143+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87144 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87145 capable(CAP_IPC_LOCK))
87146 ret = do_mlockall(flags);
87147diff --git a/mm/mmap.c b/mm/mmap.c
87148index f9c97d1..3468d3b 100644
87149--- a/mm/mmap.c
87150+++ b/mm/mmap.c
87151@@ -36,6 +36,7 @@
87152 #include <linux/sched/sysctl.h>
87153 #include <linux/notifier.h>
87154 #include <linux/memory.h>
87155+#include <linux/random.h>
87156
87157 #include <asm/uaccess.h>
87158 #include <asm/cacheflush.h>
87159@@ -52,6 +53,16 @@
87160 #define arch_rebalance_pgtables(addr, len) (addr)
87161 #endif
87162
87163+static inline void verify_mm_writelocked(struct mm_struct *mm)
87164+{
87165+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87166+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87167+ up_read(&mm->mmap_sem);
87168+ BUG();
87169+ }
87170+#endif
87171+}
87172+
87173 static void unmap_region(struct mm_struct *mm,
87174 struct vm_area_struct *vma, struct vm_area_struct *prev,
87175 unsigned long start, unsigned long end);
87176@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87177 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87178 *
87179 */
87180-pgprot_t protection_map[16] = {
87181+pgprot_t protection_map[16] __read_only = {
87182 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87183 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87184 };
87185
87186-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87187+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87188 {
87189- return __pgprot(pgprot_val(protection_map[vm_flags &
87190+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87191 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87192 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87193+
87194+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87195+ if (!(__supported_pte_mask & _PAGE_NX) &&
87196+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87197+ (vm_flags & (VM_READ | VM_WRITE)))
87198+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87199+#endif
87200+
87201+ return prot;
87202 }
87203 EXPORT_SYMBOL(vm_get_page_prot);
87204
87205@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87206 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87207 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87208 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87209+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87210 /*
87211 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87212 * other variables. It can be updated by several CPUs frequently.
87213@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87214 struct vm_area_struct *next = vma->vm_next;
87215
87216 might_sleep();
87217+ BUG_ON(vma->vm_mirror);
87218 if (vma->vm_ops && vma->vm_ops->close)
87219 vma->vm_ops->close(vma);
87220 if (vma->vm_file)
87221@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87222 * not page aligned -Ram Gupta
87223 */
87224 rlim = rlimit(RLIMIT_DATA);
87225+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87226 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87227 (mm->end_data - mm->start_data) > rlim)
87228 goto out;
87229@@ -933,6 +956,12 @@ static int
87230 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87231 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87232 {
87233+
87234+#ifdef CONFIG_PAX_SEGMEXEC
87235+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87236+ return 0;
87237+#endif
87238+
87239 if (is_mergeable_vma(vma, file, vm_flags) &&
87240 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87241 if (vma->vm_pgoff == vm_pgoff)
87242@@ -952,6 +981,12 @@ static int
87243 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87244 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87245 {
87246+
87247+#ifdef CONFIG_PAX_SEGMEXEC
87248+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87249+ return 0;
87250+#endif
87251+
87252 if (is_mergeable_vma(vma, file, vm_flags) &&
87253 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87254 pgoff_t vm_pglen;
87255@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87256 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87257 struct vm_area_struct *prev, unsigned long addr,
87258 unsigned long end, unsigned long vm_flags,
87259- struct anon_vma *anon_vma, struct file *file,
87260+ struct anon_vma *anon_vma, struct file *file,
87261 pgoff_t pgoff, struct mempolicy *policy)
87262 {
87263 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87264 struct vm_area_struct *area, *next;
87265 int err;
87266
87267+#ifdef CONFIG_PAX_SEGMEXEC
87268+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87269+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87270+
87271+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87272+#endif
87273+
87274 /*
87275 * We later require that vma->vm_flags == vm_flags,
87276 * so this tests vma->vm_flags & VM_SPECIAL, too.
87277@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87278 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87279 next = next->vm_next;
87280
87281+#ifdef CONFIG_PAX_SEGMEXEC
87282+ if (prev)
87283+ prev_m = pax_find_mirror_vma(prev);
87284+ if (area)
87285+ area_m = pax_find_mirror_vma(area);
87286+ if (next)
87287+ next_m = pax_find_mirror_vma(next);
87288+#endif
87289+
87290 /*
87291 * Can it merge with the predecessor?
87292 */
87293@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87294 /* cases 1, 6 */
87295 err = vma_adjust(prev, prev->vm_start,
87296 next->vm_end, prev->vm_pgoff, NULL);
87297- } else /* cases 2, 5, 7 */
87298+
87299+#ifdef CONFIG_PAX_SEGMEXEC
87300+ if (!err && prev_m)
87301+ err = vma_adjust(prev_m, prev_m->vm_start,
87302+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87303+#endif
87304+
87305+ } else { /* cases 2, 5, 7 */
87306 err = vma_adjust(prev, prev->vm_start,
87307 end, prev->vm_pgoff, NULL);
87308+
87309+#ifdef CONFIG_PAX_SEGMEXEC
87310+ if (!err && prev_m)
87311+ err = vma_adjust(prev_m, prev_m->vm_start,
87312+ end_m, prev_m->vm_pgoff, NULL);
87313+#endif
87314+
87315+ }
87316 if (err)
87317 return NULL;
87318 khugepaged_enter_vma_merge(prev);
87319@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87320 mpol_equal(policy, vma_policy(next)) &&
87321 can_vma_merge_before(next, vm_flags,
87322 anon_vma, file, pgoff+pglen)) {
87323- if (prev && addr < prev->vm_end) /* case 4 */
87324+ if (prev && addr < prev->vm_end) { /* case 4 */
87325 err = vma_adjust(prev, prev->vm_start,
87326 addr, prev->vm_pgoff, NULL);
87327- else /* cases 3, 8 */
87328+
87329+#ifdef CONFIG_PAX_SEGMEXEC
87330+ if (!err && prev_m)
87331+ err = vma_adjust(prev_m, prev_m->vm_start,
87332+ addr_m, prev_m->vm_pgoff, NULL);
87333+#endif
87334+
87335+ } else { /* cases 3, 8 */
87336 err = vma_adjust(area, addr, next->vm_end,
87337 next->vm_pgoff - pglen, NULL);
87338+
87339+#ifdef CONFIG_PAX_SEGMEXEC
87340+ if (!err && area_m)
87341+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87342+ next_m->vm_pgoff - pglen, NULL);
87343+#endif
87344+
87345+ }
87346 if (err)
87347 return NULL;
87348 khugepaged_enter_vma_merge(area);
87349@@ -1165,8 +1246,10 @@ none:
87350 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87351 struct file *file, long pages)
87352 {
87353- const unsigned long stack_flags
87354- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87355+
87356+#ifdef CONFIG_PAX_RANDMMAP
87357+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87358+#endif
87359
87360 mm->total_vm += pages;
87361
87362@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87363 mm->shared_vm += pages;
87364 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87365 mm->exec_vm += pages;
87366- } else if (flags & stack_flags)
87367+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87368 mm->stack_vm += pages;
87369 }
87370 #endif /* CONFIG_PROC_FS */
87371@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87372 * (the exception is when the underlying filesystem is noexec
87373 * mounted, in which case we dont add PROT_EXEC.)
87374 */
87375- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87376+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87377 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87378 prot |= PROT_EXEC;
87379
87380@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87381 /* Obtain the address to map to. we verify (or select) it and ensure
87382 * that it represents a valid section of the address space.
87383 */
87384- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87385+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87386 if (addr & ~PAGE_MASK)
87387 return addr;
87388
87389@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87390 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87391 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87392
87393+#ifdef CONFIG_PAX_MPROTECT
87394+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87395+
87396+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87397+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87398+ mm->binfmt->handle_mmap)
87399+ mm->binfmt->handle_mmap(file);
87400+#endif
87401+
87402+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87403+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87404+ gr_log_rwxmmap(file);
87405+
87406+#ifdef CONFIG_PAX_EMUPLT
87407+ vm_flags &= ~VM_EXEC;
87408+#else
87409+ return -EPERM;
87410+#endif
87411+
87412+ }
87413+
87414+ if (!(vm_flags & VM_EXEC))
87415+ vm_flags &= ~VM_MAYEXEC;
87416+#else
87417+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87418+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87419+#endif
87420+ else
87421+ vm_flags &= ~VM_MAYWRITE;
87422+ }
87423+#endif
87424+
87425+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87426+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87427+ vm_flags &= ~VM_PAGEEXEC;
87428+#endif
87429+
87430 if (flags & MAP_LOCKED)
87431 if (!can_do_mlock())
87432 return -EPERM;
87433@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87434 locked += mm->locked_vm;
87435 lock_limit = rlimit(RLIMIT_MEMLOCK);
87436 lock_limit >>= PAGE_SHIFT;
87437+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87438 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87439 return -EAGAIN;
87440 }
87441@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87442 vm_flags |= VM_NORESERVE;
87443 }
87444
87445+ if (!gr_acl_handle_mmap(file, prot))
87446+ return -EACCES;
87447+
87448 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87449 if (!IS_ERR_VALUE(addr) &&
87450 ((vm_flags & VM_LOCKED) ||
87451@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87452 vm_flags_t vm_flags = vma->vm_flags;
87453
87454 /* If it was private or non-writable, the write bit is already clear */
87455- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87456+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87457 return 0;
87458
87459 /* The backer wishes to know when pages are first written to? */
87460@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87461 unsigned long charged = 0;
87462 struct inode *inode = file ? file_inode(file) : NULL;
87463
87464+#ifdef CONFIG_PAX_SEGMEXEC
87465+ struct vm_area_struct *vma_m = NULL;
87466+#endif
87467+
87468+ /*
87469+ * mm->mmap_sem is required to protect against another thread
87470+ * changing the mappings in case we sleep.
87471+ */
87472+ verify_mm_writelocked(mm);
87473+
87474 /* Check against address space limit. */
87475+
87476+#ifdef CONFIG_PAX_RANDMMAP
87477+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87478+#endif
87479+
87480 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87481 unsigned long nr_pages;
87482
87483@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87484
87485 /* Clear old maps */
87486 error = -ENOMEM;
87487-munmap_back:
87488 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87489 if (do_munmap(mm, addr, len))
87490 return -ENOMEM;
87491- goto munmap_back;
87492+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87493 }
87494
87495 /*
87496@@ -1536,6 +1674,16 @@ munmap_back:
87497 goto unacct_error;
87498 }
87499
87500+#ifdef CONFIG_PAX_SEGMEXEC
87501+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87502+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87503+ if (!vma_m) {
87504+ error = -ENOMEM;
87505+ goto free_vma;
87506+ }
87507+ }
87508+#endif
87509+
87510 vma->vm_mm = mm;
87511 vma->vm_start = addr;
87512 vma->vm_end = addr + len;
87513@@ -1560,6 +1708,13 @@ munmap_back:
87514 if (error)
87515 goto unmap_and_free_vma;
87516
87517+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87518+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87519+ vma->vm_flags |= VM_PAGEEXEC;
87520+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87521+ }
87522+#endif
87523+
87524 /* Can addr have changed??
87525 *
87526 * Answer: Yes, several device drivers can do it in their
87527@@ -1598,6 +1753,11 @@ munmap_back:
87528 vma_link(mm, vma, prev, rb_link, rb_parent);
87529 file = vma->vm_file;
87530
87531+#ifdef CONFIG_PAX_SEGMEXEC
87532+ if (vma_m)
87533+ BUG_ON(pax_mirror_vma(vma_m, vma));
87534+#endif
87535+
87536 /* Once vma denies write, undo our temporary denial count */
87537 if (correct_wcount)
87538 atomic_inc(&inode->i_writecount);
87539@@ -1605,6 +1765,7 @@ out:
87540 perf_event_mmap(vma);
87541
87542 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87543+ track_exec_limit(mm, addr, addr + len, vm_flags);
87544 if (vm_flags & VM_LOCKED) {
87545 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87546 vma == get_gate_vma(current->mm)))
87547@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87548 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87549 charged = 0;
87550 free_vma:
87551+
87552+#ifdef CONFIG_PAX_SEGMEXEC
87553+ if (vma_m)
87554+ kmem_cache_free(vm_area_cachep, vma_m);
87555+#endif
87556+
87557 kmem_cache_free(vm_area_cachep, vma);
87558 unacct_error:
87559 if (charged)
87560@@ -1635,7 +1802,63 @@ unacct_error:
87561 return error;
87562 }
87563
87564-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87565+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87566+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87567+{
87568+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87569+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87570+
87571+ return 0;
87572+}
87573+#endif
87574+
87575+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87576+{
87577+ if (!vma) {
87578+#ifdef CONFIG_STACK_GROWSUP
87579+ if (addr > sysctl_heap_stack_gap)
87580+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87581+ else
87582+ vma = find_vma(current->mm, 0);
87583+ if (vma && (vma->vm_flags & VM_GROWSUP))
87584+ return false;
87585+#endif
87586+ return true;
87587+ }
87588+
87589+ if (addr + len > vma->vm_start)
87590+ return false;
87591+
87592+ if (vma->vm_flags & VM_GROWSDOWN)
87593+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87594+#ifdef CONFIG_STACK_GROWSUP
87595+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87596+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87597+#endif
87598+ else if (offset)
87599+ return offset <= vma->vm_start - addr - len;
87600+
87601+ return true;
87602+}
87603+
87604+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87605+{
87606+ if (vma->vm_start < len)
87607+ return -ENOMEM;
87608+
87609+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87610+ if (offset <= vma->vm_start - len)
87611+ return vma->vm_start - len - offset;
87612+ else
87613+ return -ENOMEM;
87614+ }
87615+
87616+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87617+ return vma->vm_start - len - sysctl_heap_stack_gap;
87618+ return -ENOMEM;
87619+}
87620+
87621+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87622 {
87623 /*
87624 * We implement the search by looking for an rbtree node that
87625@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87626 }
87627 }
87628
87629- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87630+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87631 check_current:
87632 /* Check if current node has a suitable gap */
87633 if (gap_start > high_limit)
87634 return -ENOMEM;
87635+
87636+ if (gap_end - gap_start > info->threadstack_offset)
87637+ gap_start += info->threadstack_offset;
87638+ else
87639+ gap_start = gap_end;
87640+
87641+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87642+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87643+ gap_start += sysctl_heap_stack_gap;
87644+ else
87645+ gap_start = gap_end;
87646+ }
87647+ if (vma->vm_flags & VM_GROWSDOWN) {
87648+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87649+ gap_end -= sysctl_heap_stack_gap;
87650+ else
87651+ gap_end = gap_start;
87652+ }
87653 if (gap_end >= low_limit && gap_end - gap_start >= length)
87654 goto found;
87655
87656@@ -1737,7 +1978,7 @@ found:
87657 return gap_start;
87658 }
87659
87660-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87661+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87662 {
87663 struct mm_struct *mm = current->mm;
87664 struct vm_area_struct *vma;
87665@@ -1791,6 +2032,24 @@ check_current:
87666 gap_end = vma->vm_start;
87667 if (gap_end < low_limit)
87668 return -ENOMEM;
87669+
87670+ if (gap_end - gap_start > info->threadstack_offset)
87671+ gap_end -= info->threadstack_offset;
87672+ else
87673+ gap_end = gap_start;
87674+
87675+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87676+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87677+ gap_start += sysctl_heap_stack_gap;
87678+ else
87679+ gap_start = gap_end;
87680+ }
87681+ if (vma->vm_flags & VM_GROWSDOWN) {
87682+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87683+ gap_end -= sysctl_heap_stack_gap;
87684+ else
87685+ gap_end = gap_start;
87686+ }
87687 if (gap_start <= high_limit && gap_end - gap_start >= length)
87688 goto found;
87689
87690@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87691 struct mm_struct *mm = current->mm;
87692 struct vm_area_struct *vma;
87693 struct vm_unmapped_area_info info;
87694+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87695
87696 if (len > TASK_SIZE)
87697 return -ENOMEM;
87698@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87699 if (flags & MAP_FIXED)
87700 return addr;
87701
87702+#ifdef CONFIG_PAX_RANDMMAP
87703+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87704+#endif
87705+
87706 if (addr) {
87707 addr = PAGE_ALIGN(addr);
87708 vma = find_vma(mm, addr);
87709- if (TASK_SIZE - len >= addr &&
87710- (!vma || addr + len <= vma->vm_start))
87711+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87712 return addr;
87713 }
87714
87715 info.flags = 0;
87716 info.length = len;
87717 info.low_limit = TASK_UNMAPPED_BASE;
87718+
87719+#ifdef CONFIG_PAX_RANDMMAP
87720+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87721+ info.low_limit += mm->delta_mmap;
87722+#endif
87723+
87724 info.high_limit = TASK_SIZE;
87725 info.align_mask = 0;
87726+ info.threadstack_offset = offset;
87727 return vm_unmapped_area(&info);
87728 }
87729 #endif
87730@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87731 struct mm_struct *mm = current->mm;
87732 unsigned long addr = addr0;
87733 struct vm_unmapped_area_info info;
87734+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87735
87736 /* requested length too big for entire address space */
87737 if (len > TASK_SIZE)
87738@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87739 if (flags & MAP_FIXED)
87740 return addr;
87741
87742+#ifdef CONFIG_PAX_RANDMMAP
87743+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87744+#endif
87745+
87746 /* requesting a specific address */
87747 if (addr) {
87748 addr = PAGE_ALIGN(addr);
87749 vma = find_vma(mm, addr);
87750- if (TASK_SIZE - len >= addr &&
87751- (!vma || addr + len <= vma->vm_start))
87752+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87753 return addr;
87754 }
87755
87756@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87757 info.low_limit = PAGE_SIZE;
87758 info.high_limit = mm->mmap_base;
87759 info.align_mask = 0;
87760+ info.threadstack_offset = offset;
87761 addr = vm_unmapped_area(&info);
87762
87763 /*
87764@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87765 VM_BUG_ON(addr != -ENOMEM);
87766 info.flags = 0;
87767 info.low_limit = TASK_UNMAPPED_BASE;
87768+
87769+#ifdef CONFIG_PAX_RANDMMAP
87770+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87771+ info.low_limit += mm->delta_mmap;
87772+#endif
87773+
87774 info.high_limit = TASK_SIZE;
87775 addr = vm_unmapped_area(&info);
87776 }
87777@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87778 return vma;
87779 }
87780
87781+#ifdef CONFIG_PAX_SEGMEXEC
87782+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87783+{
87784+ struct vm_area_struct *vma_m;
87785+
87786+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87787+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87788+ BUG_ON(vma->vm_mirror);
87789+ return NULL;
87790+ }
87791+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87792+ vma_m = vma->vm_mirror;
87793+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87794+ BUG_ON(vma->vm_file != vma_m->vm_file);
87795+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87796+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87797+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87798+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87799+ return vma_m;
87800+}
87801+#endif
87802+
87803 /*
87804 * Verify that the stack growth is acceptable and
87805 * update accounting. This is shared with both the
87806@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87807 return -ENOMEM;
87808
87809 /* Stack limit test */
87810+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87811 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87812 return -ENOMEM;
87813
87814@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87815 locked = mm->locked_vm + grow;
87816 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87817 limit >>= PAGE_SHIFT;
87818+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87819 if (locked > limit && !capable(CAP_IPC_LOCK))
87820 return -ENOMEM;
87821 }
87822@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87823 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87824 * vma is the last one with address > vma->vm_end. Have to extend vma.
87825 */
87826+#ifndef CONFIG_IA64
87827+static
87828+#endif
87829 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87830 {
87831 int error;
87832+ bool locknext;
87833
87834 if (!(vma->vm_flags & VM_GROWSUP))
87835 return -EFAULT;
87836
87837+ /* Also guard against wrapping around to address 0. */
87838+ if (address < PAGE_ALIGN(address+1))
87839+ address = PAGE_ALIGN(address+1);
87840+ else
87841+ return -ENOMEM;
87842+
87843 /*
87844 * We must make sure the anon_vma is allocated
87845 * so that the anon_vma locking is not a noop.
87846 */
87847 if (unlikely(anon_vma_prepare(vma)))
87848 return -ENOMEM;
87849+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87850+ if (locknext && anon_vma_prepare(vma->vm_next))
87851+ return -ENOMEM;
87852 vma_lock_anon_vma(vma);
87853+ if (locknext)
87854+ vma_lock_anon_vma(vma->vm_next);
87855
87856 /*
87857 * vma->vm_start/vm_end cannot change under us because the caller
87858 * is required to hold the mmap_sem in read mode. We need the
87859- * anon_vma lock to serialize against concurrent expand_stacks.
87860- * Also guard against wrapping around to address 0.
87861+ * anon_vma locks to serialize against concurrent expand_stacks
87862+ * and expand_upwards.
87863 */
87864- if (address < PAGE_ALIGN(address+4))
87865- address = PAGE_ALIGN(address+4);
87866- else {
87867- vma_unlock_anon_vma(vma);
87868- return -ENOMEM;
87869- }
87870 error = 0;
87871
87872 /* Somebody else might have raced and expanded it already */
87873- if (address > vma->vm_end) {
87874+ 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)
87875+ error = -ENOMEM;
87876+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87877 unsigned long size, grow;
87878
87879 size = address - vma->vm_start;
87880@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87881 }
87882 }
87883 }
87884+ if (locknext)
87885+ vma_unlock_anon_vma(vma->vm_next);
87886 vma_unlock_anon_vma(vma);
87887 khugepaged_enter_vma_merge(vma);
87888 validate_mm(vma->vm_mm);
87889@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87890 unsigned long address)
87891 {
87892 int error;
87893+ bool lockprev = false;
87894+ struct vm_area_struct *prev;
87895
87896 /*
87897 * We must make sure the anon_vma is allocated
87898@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87899 if (error)
87900 return error;
87901
87902+ prev = vma->vm_prev;
87903+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87904+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87905+#endif
87906+ if (lockprev && anon_vma_prepare(prev))
87907+ return -ENOMEM;
87908+ if (lockprev)
87909+ vma_lock_anon_vma(prev);
87910+
87911 vma_lock_anon_vma(vma);
87912
87913 /*
87914@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
87915 */
87916
87917 /* Somebody else might have raced and expanded it already */
87918- if (address < vma->vm_start) {
87919+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
87920+ error = -ENOMEM;
87921+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
87922 unsigned long size, grow;
87923
87924+#ifdef CONFIG_PAX_SEGMEXEC
87925+ struct vm_area_struct *vma_m;
87926+
87927+ vma_m = pax_find_mirror_vma(vma);
87928+#endif
87929+
87930 size = vma->vm_end - address;
87931 grow = (vma->vm_start - address) >> PAGE_SHIFT;
87932
87933@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
87934 vma->vm_pgoff -= grow;
87935 anon_vma_interval_tree_post_update_vma(vma);
87936 vma_gap_update(vma);
87937+
87938+#ifdef CONFIG_PAX_SEGMEXEC
87939+ if (vma_m) {
87940+ anon_vma_interval_tree_pre_update_vma(vma_m);
87941+ vma_m->vm_start -= grow << PAGE_SHIFT;
87942+ vma_m->vm_pgoff -= grow;
87943+ anon_vma_interval_tree_post_update_vma(vma_m);
87944+ vma_gap_update(vma_m);
87945+ }
87946+#endif
87947+
87948 spin_unlock(&vma->vm_mm->page_table_lock);
87949
87950+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
87951 perf_event_mmap(vma);
87952 }
87953 }
87954 }
87955 vma_unlock_anon_vma(vma);
87956+ if (lockprev)
87957+ vma_unlock_anon_vma(prev);
87958 khugepaged_enter_vma_merge(vma);
87959 validate_mm(vma->vm_mm);
87960 return error;
87961@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
87962 do {
87963 long nrpages = vma_pages(vma);
87964
87965+#ifdef CONFIG_PAX_SEGMEXEC
87966+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
87967+ vma = remove_vma(vma);
87968+ continue;
87969+ }
87970+#endif
87971+
87972 if (vma->vm_flags & VM_ACCOUNT)
87973 nr_accounted += nrpages;
87974 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
87975@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
87976 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
87977 vma->vm_prev = NULL;
87978 do {
87979+
87980+#ifdef CONFIG_PAX_SEGMEXEC
87981+ if (vma->vm_mirror) {
87982+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
87983+ vma->vm_mirror->vm_mirror = NULL;
87984+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
87985+ vma->vm_mirror = NULL;
87986+ }
87987+#endif
87988+
87989 vma_rb_erase(vma, &mm->mm_rb);
87990 mm->map_count--;
87991 tail_vma = vma;
87992@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87993 struct vm_area_struct *new;
87994 int err = -ENOMEM;
87995
87996+#ifdef CONFIG_PAX_SEGMEXEC
87997+ struct vm_area_struct *vma_m, *new_m = NULL;
87998+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
87999+#endif
88000+
88001 if (is_vm_hugetlb_page(vma) && (addr &
88002 ~(huge_page_mask(hstate_vma(vma)))))
88003 return -EINVAL;
88004
88005+#ifdef CONFIG_PAX_SEGMEXEC
88006+ vma_m = pax_find_mirror_vma(vma);
88007+#endif
88008+
88009 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88010 if (!new)
88011 goto out_err;
88012
88013+#ifdef CONFIG_PAX_SEGMEXEC
88014+ if (vma_m) {
88015+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88016+ if (!new_m) {
88017+ kmem_cache_free(vm_area_cachep, new);
88018+ goto out_err;
88019+ }
88020+ }
88021+#endif
88022+
88023 /* most fields are the same, copy all, and then fixup */
88024 *new = *vma;
88025
88026@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88027 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88028 }
88029
88030+#ifdef CONFIG_PAX_SEGMEXEC
88031+ if (vma_m) {
88032+ *new_m = *vma_m;
88033+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88034+ new_m->vm_mirror = new;
88035+ new->vm_mirror = new_m;
88036+
88037+ if (new_below)
88038+ new_m->vm_end = addr_m;
88039+ else {
88040+ new_m->vm_start = addr_m;
88041+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88042+ }
88043+ }
88044+#endif
88045+
88046 pol = mpol_dup(vma_policy(vma));
88047 if (IS_ERR(pol)) {
88048 err = PTR_ERR(pol);
88049@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88050 else
88051 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88052
88053+#ifdef CONFIG_PAX_SEGMEXEC
88054+ if (!err && vma_m) {
88055+ if (anon_vma_clone(new_m, vma_m))
88056+ goto out_free_mpol;
88057+
88058+ mpol_get(pol);
88059+ vma_set_policy(new_m, pol);
88060+
88061+ if (new_m->vm_file)
88062+ get_file(new_m->vm_file);
88063+
88064+ if (new_m->vm_ops && new_m->vm_ops->open)
88065+ new_m->vm_ops->open(new_m);
88066+
88067+ if (new_below)
88068+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88069+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88070+ else
88071+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88072+
88073+ if (err) {
88074+ if (new_m->vm_ops && new_m->vm_ops->close)
88075+ new_m->vm_ops->close(new_m);
88076+ if (new_m->vm_file)
88077+ fput(new_m->vm_file);
88078+ mpol_put(pol);
88079+ }
88080+ }
88081+#endif
88082+
88083 /* Success. */
88084 if (!err)
88085 return 0;
88086@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88087 new->vm_ops->close(new);
88088 if (new->vm_file)
88089 fput(new->vm_file);
88090- unlink_anon_vmas(new);
88091 out_free_mpol:
88092 mpol_put(pol);
88093 out_free_vma:
88094+
88095+#ifdef CONFIG_PAX_SEGMEXEC
88096+ if (new_m) {
88097+ unlink_anon_vmas(new_m);
88098+ kmem_cache_free(vm_area_cachep, new_m);
88099+ }
88100+#endif
88101+
88102+ unlink_anon_vmas(new);
88103 kmem_cache_free(vm_area_cachep, new);
88104 out_err:
88105 return err;
88106@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88107 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88108 unsigned long addr, int new_below)
88109 {
88110+
88111+#ifdef CONFIG_PAX_SEGMEXEC
88112+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88113+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88114+ if (mm->map_count >= sysctl_max_map_count-1)
88115+ return -ENOMEM;
88116+ } else
88117+#endif
88118+
88119 if (mm->map_count >= sysctl_max_map_count)
88120 return -ENOMEM;
88121
88122@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88123 * work. This now handles partial unmappings.
88124 * Jeremy Fitzhardinge <jeremy@goop.org>
88125 */
88126+#ifdef CONFIG_PAX_SEGMEXEC
88127 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88128 {
88129+ int ret = __do_munmap(mm, start, len);
88130+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88131+ return ret;
88132+
88133+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88134+}
88135+
88136+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88137+#else
88138+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88139+#endif
88140+{
88141 unsigned long end;
88142 struct vm_area_struct *vma, *prev, *last;
88143
88144+ /*
88145+ * mm->mmap_sem is required to protect against another thread
88146+ * changing the mappings in case we sleep.
88147+ */
88148+ verify_mm_writelocked(mm);
88149+
88150 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88151 return -EINVAL;
88152
88153@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88154 /* Fix up all other VM information */
88155 remove_vma_list(mm, vma);
88156
88157+ track_exec_limit(mm, start, end, 0UL);
88158+
88159 return 0;
88160 }
88161
88162@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88163 int ret;
88164 struct mm_struct *mm = current->mm;
88165
88166+
88167+#ifdef CONFIG_PAX_SEGMEXEC
88168+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88169+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88170+ return -EINVAL;
88171+#endif
88172+
88173 down_write(&mm->mmap_sem);
88174 ret = do_munmap(mm, start, len);
88175 up_write(&mm->mmap_sem);
88176@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88177 return vm_munmap(addr, len);
88178 }
88179
88180-static inline void verify_mm_writelocked(struct mm_struct *mm)
88181-{
88182-#ifdef CONFIG_DEBUG_VM
88183- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88184- WARN_ON(1);
88185- up_read(&mm->mmap_sem);
88186- }
88187-#endif
88188-}
88189-
88190 /*
88191 * this is really a simplified "do_mmap". it only handles
88192 * anonymous maps. eventually we may be able to do some
88193@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88194 struct rb_node ** rb_link, * rb_parent;
88195 pgoff_t pgoff = addr >> PAGE_SHIFT;
88196 int error;
88197+ unsigned long charged;
88198
88199 len = PAGE_ALIGN(len);
88200 if (!len)
88201@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88202
88203 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88204
88205+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88206+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88207+ flags &= ~VM_EXEC;
88208+
88209+#ifdef CONFIG_PAX_MPROTECT
88210+ if (mm->pax_flags & MF_PAX_MPROTECT)
88211+ flags &= ~VM_MAYEXEC;
88212+#endif
88213+
88214+ }
88215+#endif
88216+
88217 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88218 if (error & ~PAGE_MASK)
88219 return error;
88220
88221+ charged = len >> PAGE_SHIFT;
88222+
88223 /*
88224 * mlock MCL_FUTURE?
88225 */
88226 if (mm->def_flags & VM_LOCKED) {
88227 unsigned long locked, lock_limit;
88228- locked = len >> PAGE_SHIFT;
88229+ locked = charged;
88230 locked += mm->locked_vm;
88231 lock_limit = rlimit(RLIMIT_MEMLOCK);
88232 lock_limit >>= PAGE_SHIFT;
88233@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88234 /*
88235 * Clear old maps. this also does some error checking for us
88236 */
88237- munmap_back:
88238 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88239 if (do_munmap(mm, addr, len))
88240 return -ENOMEM;
88241- goto munmap_back;
88242+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88243 }
88244
88245 /* Check against address space limits *after* clearing old maps... */
88246- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88247+ if (!may_expand_vm(mm, charged))
88248 return -ENOMEM;
88249
88250 if (mm->map_count > sysctl_max_map_count)
88251 return -ENOMEM;
88252
88253- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88254+ if (security_vm_enough_memory_mm(mm, charged))
88255 return -ENOMEM;
88256
88257 /* Can we just expand an old private anonymous mapping? */
88258@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88259 */
88260 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88261 if (!vma) {
88262- vm_unacct_memory(len >> PAGE_SHIFT);
88263+ vm_unacct_memory(charged);
88264 return -ENOMEM;
88265 }
88266
88267@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88268 vma_link(mm, vma, prev, rb_link, rb_parent);
88269 out:
88270 perf_event_mmap(vma);
88271- mm->total_vm += len >> PAGE_SHIFT;
88272+ mm->total_vm += charged;
88273 if (flags & VM_LOCKED)
88274- mm->locked_vm += (len >> PAGE_SHIFT);
88275+ mm->locked_vm += charged;
88276+ track_exec_limit(mm, addr, addr + len, flags);
88277 return addr;
88278 }
88279
88280@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88281 while (vma) {
88282 if (vma->vm_flags & VM_ACCOUNT)
88283 nr_accounted += vma_pages(vma);
88284+ vma->vm_mirror = NULL;
88285 vma = remove_vma(vma);
88286 }
88287 vm_unacct_memory(nr_accounted);
88288@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88289 struct vm_area_struct *prev;
88290 struct rb_node **rb_link, *rb_parent;
88291
88292+#ifdef CONFIG_PAX_SEGMEXEC
88293+ struct vm_area_struct *vma_m = NULL;
88294+#endif
88295+
88296+ if (security_mmap_addr(vma->vm_start))
88297+ return -EPERM;
88298+
88299 /*
88300 * The vm_pgoff of a purely anonymous vma should be irrelevant
88301 * until its first write fault, when page's anon_vma and index
88302@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88303 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88304 return -ENOMEM;
88305
88306+#ifdef CONFIG_PAX_SEGMEXEC
88307+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88308+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88309+ if (!vma_m)
88310+ return -ENOMEM;
88311+ }
88312+#endif
88313+
88314 vma_link(mm, vma, prev, rb_link, rb_parent);
88315+
88316+#ifdef CONFIG_PAX_SEGMEXEC
88317+ if (vma_m)
88318+ BUG_ON(pax_mirror_vma(vma_m, vma));
88319+#endif
88320+
88321 return 0;
88322 }
88323
88324@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88325 struct mempolicy *pol;
88326 bool faulted_in_anon_vma = true;
88327
88328+ BUG_ON(vma->vm_mirror);
88329+
88330 /*
88331 * If anonymous vma has not yet been faulted, update new pgoff
88332 * to match new location, to increase its chance of merging.
88333@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88334 return NULL;
88335 }
88336
88337+#ifdef CONFIG_PAX_SEGMEXEC
88338+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88339+{
88340+ struct vm_area_struct *prev_m;
88341+ struct rb_node **rb_link_m, *rb_parent_m;
88342+ struct mempolicy *pol_m;
88343+
88344+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88345+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88346+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88347+ *vma_m = *vma;
88348+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88349+ if (anon_vma_clone(vma_m, vma))
88350+ return -ENOMEM;
88351+ pol_m = vma_policy(vma_m);
88352+ mpol_get(pol_m);
88353+ vma_set_policy(vma_m, pol_m);
88354+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88355+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88356+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88357+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88358+ if (vma_m->vm_file)
88359+ get_file(vma_m->vm_file);
88360+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88361+ vma_m->vm_ops->open(vma_m);
88362+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88363+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88364+ vma_m->vm_mirror = vma;
88365+ vma->vm_mirror = vma_m;
88366+ return 0;
88367+}
88368+#endif
88369+
88370 /*
88371 * Return true if the calling process may expand its vm space by the passed
88372 * number of pages
88373@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88374
88375 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88376
88377+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88378 if (cur + npages > lim)
88379 return 0;
88380 return 1;
88381@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88382 vma->vm_start = addr;
88383 vma->vm_end = addr + len;
88384
88385+#ifdef CONFIG_PAX_MPROTECT
88386+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88387+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88388+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88389+ return -EPERM;
88390+ if (!(vm_flags & VM_EXEC))
88391+ vm_flags &= ~VM_MAYEXEC;
88392+#else
88393+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88394+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88395+#endif
88396+ else
88397+ vm_flags &= ~VM_MAYWRITE;
88398+ }
88399+#endif
88400+
88401 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88402 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88403
88404diff --git a/mm/mprotect.c b/mm/mprotect.c
88405index 94722a4..e661e29 100644
88406--- a/mm/mprotect.c
88407+++ b/mm/mprotect.c
88408@@ -23,10 +23,18 @@
88409 #include <linux/mmu_notifier.h>
88410 #include <linux/migrate.h>
88411 #include <linux/perf_event.h>
88412+#include <linux/sched/sysctl.h>
88413+
88414+#ifdef CONFIG_PAX_MPROTECT
88415+#include <linux/elf.h>
88416+#include <linux/binfmts.h>
88417+#endif
88418+
88419 #include <asm/uaccess.h>
88420 #include <asm/pgtable.h>
88421 #include <asm/cacheflush.h>
88422 #include <asm/tlbflush.h>
88423+#include <asm/mmu_context.h>
88424
88425 #ifndef pgprot_modify
88426 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88427@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88428 return pages;
88429 }
88430
88431+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88432+/* called while holding the mmap semaphor for writing except stack expansion */
88433+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88434+{
88435+ unsigned long oldlimit, newlimit = 0UL;
88436+
88437+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88438+ return;
88439+
88440+ spin_lock(&mm->page_table_lock);
88441+ oldlimit = mm->context.user_cs_limit;
88442+ if ((prot & VM_EXEC) && oldlimit < end)
88443+ /* USER_CS limit moved up */
88444+ newlimit = end;
88445+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88446+ /* USER_CS limit moved down */
88447+ newlimit = start;
88448+
88449+ if (newlimit) {
88450+ mm->context.user_cs_limit = newlimit;
88451+
88452+#ifdef CONFIG_SMP
88453+ wmb();
88454+ cpus_clear(mm->context.cpu_user_cs_mask);
88455+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88456+#endif
88457+
88458+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88459+ }
88460+ spin_unlock(&mm->page_table_lock);
88461+ if (newlimit == end) {
88462+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88463+
88464+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88465+ if (is_vm_hugetlb_page(vma))
88466+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88467+ else
88468+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88469+ }
88470+}
88471+#endif
88472+
88473 int
88474 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88475 unsigned long start, unsigned long end, unsigned long newflags)
88476@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88477 int error;
88478 int dirty_accountable = 0;
88479
88480+#ifdef CONFIG_PAX_SEGMEXEC
88481+ struct vm_area_struct *vma_m = NULL;
88482+ unsigned long start_m, end_m;
88483+
88484+ start_m = start + SEGMEXEC_TASK_SIZE;
88485+ end_m = end + SEGMEXEC_TASK_SIZE;
88486+#endif
88487+
88488 if (newflags == oldflags) {
88489 *pprev = vma;
88490 return 0;
88491 }
88492
88493+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88494+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88495+
88496+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88497+ return -ENOMEM;
88498+
88499+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88500+ return -ENOMEM;
88501+ }
88502+
88503 /*
88504 * If we make a private mapping writable we increase our commit;
88505 * but (without finer accounting) cannot reduce our commit if we
88506@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88507 }
88508 }
88509
88510+#ifdef CONFIG_PAX_SEGMEXEC
88511+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88512+ if (start != vma->vm_start) {
88513+ error = split_vma(mm, vma, start, 1);
88514+ if (error)
88515+ goto fail;
88516+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88517+ *pprev = (*pprev)->vm_next;
88518+ }
88519+
88520+ if (end != vma->vm_end) {
88521+ error = split_vma(mm, vma, end, 0);
88522+ if (error)
88523+ goto fail;
88524+ }
88525+
88526+ if (pax_find_mirror_vma(vma)) {
88527+ error = __do_munmap(mm, start_m, end_m - start_m);
88528+ if (error)
88529+ goto fail;
88530+ } else {
88531+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88532+ if (!vma_m) {
88533+ error = -ENOMEM;
88534+ goto fail;
88535+ }
88536+ vma->vm_flags = newflags;
88537+ error = pax_mirror_vma(vma_m, vma);
88538+ if (error) {
88539+ vma->vm_flags = oldflags;
88540+ goto fail;
88541+ }
88542+ }
88543+ }
88544+#endif
88545+
88546 /*
88547 * First try to merge with previous and/or next vma.
88548 */
88549@@ -296,9 +400,21 @@ success:
88550 * vm_flags and vm_page_prot are protected by the mmap_sem
88551 * held in write mode.
88552 */
88553+
88554+#ifdef CONFIG_PAX_SEGMEXEC
88555+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88556+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88557+#endif
88558+
88559 vma->vm_flags = newflags;
88560+
88561+#ifdef CONFIG_PAX_MPROTECT
88562+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88563+ mm->binfmt->handle_mprotect(vma, newflags);
88564+#endif
88565+
88566 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88567- vm_get_page_prot(newflags));
88568+ vm_get_page_prot(vma->vm_flags));
88569
88570 if (vma_wants_writenotify(vma)) {
88571 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88572@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88573 end = start + len;
88574 if (end <= start)
88575 return -ENOMEM;
88576+
88577+#ifdef CONFIG_PAX_SEGMEXEC
88578+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88579+ if (end > SEGMEXEC_TASK_SIZE)
88580+ return -EINVAL;
88581+ } else
88582+#endif
88583+
88584+ if (end > TASK_SIZE)
88585+ return -EINVAL;
88586+
88587 if (!arch_validate_prot(prot))
88588 return -EINVAL;
88589
88590@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88591 /*
88592 * Does the application expect PROT_READ to imply PROT_EXEC:
88593 */
88594- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88595+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88596 prot |= PROT_EXEC;
88597
88598 vm_flags = calc_vm_prot_bits(prot);
88599@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88600 if (start > vma->vm_start)
88601 prev = vma;
88602
88603+#ifdef CONFIG_PAX_MPROTECT
88604+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88605+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88606+#endif
88607+
88608 for (nstart = start ; ; ) {
88609 unsigned long newflags;
88610
88611@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88612
88613 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88614 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88615+ if (prot & (PROT_WRITE | PROT_EXEC))
88616+ gr_log_rwxmprotect(vma);
88617+
88618+ error = -EACCES;
88619+ goto out;
88620+ }
88621+
88622+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88623 error = -EACCES;
88624 goto out;
88625 }
88626@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88627 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88628 if (error)
88629 goto out;
88630+
88631+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88632+
88633 nstart = tmp;
88634
88635 if (nstart < prev->vm_end)
88636diff --git a/mm/mremap.c b/mm/mremap.c
88637index 0843feb..5607f47 100644
88638--- a/mm/mremap.c
88639+++ b/mm/mremap.c
88640@@ -25,6 +25,7 @@
88641 #include <asm/uaccess.h>
88642 #include <asm/cacheflush.h>
88643 #include <asm/tlbflush.h>
88644+#include <asm/pgalloc.h>
88645
88646 #include "internal.h"
88647
88648@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88649 return NULL;
88650
88651 pmd = pmd_alloc(mm, pud, addr);
88652- if (!pmd)
88653+ if (!pmd) {
88654+ pud_free(mm, pud);
88655 return NULL;
88656+ }
88657
88658 VM_BUG_ON(pmd_trans_huge(*pmd));
88659
88660@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88661 continue;
88662 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88663 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88664+
88665+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88666+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88667+ pte = pte_exprotect(pte);
88668+#endif
88669+
88670 pte = move_soft_dirty_pte(pte);
88671 set_pte_at(mm, new_addr, new_pte, pte);
88672 }
88673@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88674 if (is_vm_hugetlb_page(vma))
88675 goto Einval;
88676
88677+#ifdef CONFIG_PAX_SEGMEXEC
88678+ if (pax_find_mirror_vma(vma))
88679+ goto Einval;
88680+#endif
88681+
88682 /* We can't remap across vm area boundaries */
88683 if (old_len > vma->vm_end - addr)
88684 goto Efault;
88685@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88686 unsigned long ret = -EINVAL;
88687 unsigned long charged = 0;
88688 unsigned long map_flags;
88689+ unsigned long pax_task_size = TASK_SIZE;
88690
88691 if (new_addr & ~PAGE_MASK)
88692 goto out;
88693
88694- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88695+#ifdef CONFIG_PAX_SEGMEXEC
88696+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88697+ pax_task_size = SEGMEXEC_TASK_SIZE;
88698+#endif
88699+
88700+ pax_task_size -= PAGE_SIZE;
88701+
88702+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88703 goto out;
88704
88705 /* Check if the location we're moving into overlaps the
88706 * old location at all, and fail if it does.
88707 */
88708- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88709- goto out;
88710-
88711- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88712+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88713 goto out;
88714
88715 ret = do_munmap(mm, new_addr, new_len);
88716@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88717 unsigned long ret = -EINVAL;
88718 unsigned long charged = 0;
88719 bool locked = false;
88720+ unsigned long pax_task_size = TASK_SIZE;
88721
88722 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88723 return ret;
88724@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88725 if (!new_len)
88726 return ret;
88727
88728+#ifdef CONFIG_PAX_SEGMEXEC
88729+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88730+ pax_task_size = SEGMEXEC_TASK_SIZE;
88731+#endif
88732+
88733+ pax_task_size -= PAGE_SIZE;
88734+
88735+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88736+ old_len > pax_task_size || addr > pax_task_size-old_len)
88737+ return ret;
88738+
88739 down_write(&current->mm->mmap_sem);
88740
88741 if (flags & MREMAP_FIXED) {
88742@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88743 new_addr = addr;
88744 }
88745 ret = addr;
88746+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88747 goto out;
88748 }
88749 }
88750@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88751 goto out;
88752 }
88753
88754+ map_flags = vma->vm_flags;
88755 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88756+ if (!(ret & ~PAGE_MASK)) {
88757+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88758+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88759+ }
88760 }
88761 out:
88762 if (ret & ~PAGE_MASK)
88763diff --git a/mm/nommu.c b/mm/nommu.c
88764index ecd1f15..77039bd 100644
88765--- a/mm/nommu.c
88766+++ b/mm/nommu.c
88767@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88768 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88769 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88770 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88771-int heap_stack_gap = 0;
88772
88773 atomic_long_t mmap_pages_allocated;
88774
88775@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88776 EXPORT_SYMBOL(find_vma);
88777
88778 /*
88779- * find a VMA
88780- * - we don't extend stack VMAs under NOMMU conditions
88781- */
88782-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88783-{
88784- return find_vma(mm, addr);
88785-}
88786-
88787-/*
88788 * expand a stack to a given address
88789 * - not supported under NOMMU conditions
88790 */
88791@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88792
88793 /* most fields are the same, copy all, and then fixup */
88794 *new = *vma;
88795+ INIT_LIST_HEAD(&new->anon_vma_chain);
88796 *region = *vma->vm_region;
88797 new->vm_region = region;
88798
88799@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88800 }
88801 EXPORT_SYMBOL(generic_file_remap_pages);
88802
88803-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88804- unsigned long addr, void *buf, int len, int write)
88805+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88806+ unsigned long addr, void *buf, size_t len, int write)
88807 {
88808 struct vm_area_struct *vma;
88809
88810@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88811 *
88812 * The caller must hold a reference on @mm.
88813 */
88814-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88815- void *buf, int len, int write)
88816+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88817+ void *buf, size_t len, int write)
88818 {
88819 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88820 }
88821@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88822 * Access another process' address space.
88823 * - source/target buffer must be kernel space
88824 */
88825-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88826+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88827 {
88828 struct mm_struct *mm;
88829
88830diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88831index 3f0c895..60cd104 100644
88832--- a/mm/page-writeback.c
88833+++ b/mm/page-writeback.c
88834@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88835 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88836 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88837 */
88838-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88839+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88840 unsigned long thresh,
88841 unsigned long bg_thresh,
88842 unsigned long dirty,
88843diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88844index b100255..fba1254 100644
88845--- a/mm/page_alloc.c
88846+++ b/mm/page_alloc.c
88847@@ -60,6 +60,7 @@
88848 #include <linux/page-debug-flags.h>
88849 #include <linux/hugetlb.h>
88850 #include <linux/sched/rt.h>
88851+#include <linux/random.h>
88852
88853 #include <asm/sections.h>
88854 #include <asm/tlbflush.h>
88855@@ -353,7 +354,7 @@ out:
88856 * This usage means that zero-order pages may not be compound.
88857 */
88858
88859-static void free_compound_page(struct page *page)
88860+void free_compound_page(struct page *page)
88861 {
88862 __free_pages_ok(page, compound_order(page));
88863 }
88864@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88865 int i;
88866 int bad = 0;
88867
88868+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88869+ unsigned long index = 1UL << order;
88870+#endif
88871+
88872 trace_mm_page_free(page, order);
88873 kmemcheck_free_shadow(page, order);
88874
88875@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88876 debug_check_no_obj_freed(page_address(page),
88877 PAGE_SIZE << order);
88878 }
88879+
88880+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88881+ for (; index; --index)
88882+ sanitize_highpage(page + index - 1);
88883+#endif
88884+
88885 arch_free_page(page, order);
88886 kernel_map_pages(page, 1 << order, 0);
88887
88888@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88889 local_irq_restore(flags);
88890 }
88891
88892+#ifdef CONFIG_PAX_LATENT_ENTROPY
88893+bool __meminitdata extra_latent_entropy;
88894+
88895+static int __init setup_pax_extra_latent_entropy(char *str)
88896+{
88897+ extra_latent_entropy = true;
88898+ return 0;
88899+}
88900+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88901+
88902+volatile u64 latent_entropy;
88903+EXPORT_SYMBOL(latent_entropy);
88904+#endif
88905+
88906 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88907 {
88908 unsigned int nr_pages = 1 << order;
88909@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88910 set_page_count(p, 0);
88911 }
88912
88913+#ifdef CONFIG_PAX_LATENT_ENTROPY
88914+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88915+ u64 hash = 0;
88916+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88917+ const u64 *data = lowmem_page_address(page);
88918+
88919+ for (index = 0; index < end; index++)
88920+ hash ^= hash + data[index];
88921+ latent_entropy ^= hash;
88922+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
88923+ }
88924+#endif
88925+
88926 page_zone(page)->managed_pages += 1 << order;
88927 set_page_refcounted(page);
88928 __free_pages(page, order);
88929@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
88930 arch_alloc_page(page, order);
88931 kernel_map_pages(page, 1 << order, 1);
88932
88933+#ifndef CONFIG_PAX_MEMORY_SANITIZE
88934 if (gfp_flags & __GFP_ZERO)
88935 prep_zero_page(page, order, gfp_flags);
88936+#endif
88937
88938 if (order && (gfp_flags & __GFP_COMP))
88939 prep_compound_page(page, order);
88940diff --git a/mm/page_io.c b/mm/page_io.c
88941index ba05b64..ef2f314 100644
88942--- a/mm/page_io.c
88943+++ b/mm/page_io.c
88944@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
88945 struct file *swap_file = sis->swap_file;
88946 struct address_space *mapping = swap_file->f_mapping;
88947 struct iovec iov = {
88948- .iov_base = kmap(page),
88949+ .iov_base = (void __force_user *)kmap(page),
88950 .iov_len = PAGE_SIZE,
88951 };
88952
88953diff --git a/mm/percpu.c b/mm/percpu.c
88954index 8c8e08f..73a5cda 100644
88955--- a/mm/percpu.c
88956+++ b/mm/percpu.c
88957@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
88958 static unsigned int pcpu_high_unit_cpu __read_mostly;
88959
88960 /* the address of the first chunk which starts with the kernel static area */
88961-void *pcpu_base_addr __read_mostly;
88962+void *pcpu_base_addr __read_only;
88963 EXPORT_SYMBOL_GPL(pcpu_base_addr);
88964
88965 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
88966diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
88967index fd26d04..0cea1b0 100644
88968--- a/mm/process_vm_access.c
88969+++ b/mm/process_vm_access.c
88970@@ -13,6 +13,7 @@
88971 #include <linux/uio.h>
88972 #include <linux/sched.h>
88973 #include <linux/highmem.h>
88974+#include <linux/security.h>
88975 #include <linux/ptrace.h>
88976 #include <linux/slab.h>
88977 #include <linux/syscalls.h>
88978@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
88979 size_t iov_l_curr_offset = 0;
88980 ssize_t iov_len;
88981
88982+ return -ENOSYS; // PaX: until properly audited
88983+
88984 /*
88985 * Work out how many pages of struct pages we're going to need
88986 * when eventually calling get_user_pages
88987 */
88988 for (i = 0; i < riovcnt; i++) {
88989 iov_len = rvec[i].iov_len;
88990- if (iov_len > 0) {
88991- nr_pages_iov = ((unsigned long)rvec[i].iov_base
88992- + iov_len)
88993- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
88994- / PAGE_SIZE + 1;
88995- nr_pages = max(nr_pages, nr_pages_iov);
88996- }
88997+ if (iov_len <= 0)
88998+ continue;
88999+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89000+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89001+ nr_pages = max(nr_pages, nr_pages_iov);
89002 }
89003
89004 if (nr_pages == 0)
89005@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89006 goto free_proc_pages;
89007 }
89008
89009+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89010+ rc = -EPERM;
89011+ goto put_task_struct;
89012+ }
89013+
89014 mm = mm_access(task, PTRACE_MODE_ATTACH);
89015 if (!mm || IS_ERR(mm)) {
89016 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89017diff --git a/mm/rmap.c b/mm/rmap.c
89018index b2e29ac..4168491 100644
89019--- a/mm/rmap.c
89020+++ b/mm/rmap.c
89021@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89022 struct anon_vma *anon_vma = vma->anon_vma;
89023 struct anon_vma_chain *avc;
89024
89025+#ifdef CONFIG_PAX_SEGMEXEC
89026+ struct anon_vma_chain *avc_m = NULL;
89027+#endif
89028+
89029 might_sleep();
89030 if (unlikely(!anon_vma)) {
89031 struct mm_struct *mm = vma->vm_mm;
89032@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89033 if (!avc)
89034 goto out_enomem;
89035
89036+#ifdef CONFIG_PAX_SEGMEXEC
89037+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89038+ if (!avc_m)
89039+ goto out_enomem_free_avc;
89040+#endif
89041+
89042 anon_vma = find_mergeable_anon_vma(vma);
89043 allocated = NULL;
89044 if (!anon_vma) {
89045@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89046 /* page_table_lock to protect against threads */
89047 spin_lock(&mm->page_table_lock);
89048 if (likely(!vma->anon_vma)) {
89049+
89050+#ifdef CONFIG_PAX_SEGMEXEC
89051+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89052+
89053+ if (vma_m) {
89054+ BUG_ON(vma_m->anon_vma);
89055+ vma_m->anon_vma = anon_vma;
89056+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89057+ avc_m = NULL;
89058+ }
89059+#endif
89060+
89061 vma->anon_vma = anon_vma;
89062 anon_vma_chain_link(vma, avc, anon_vma);
89063 allocated = NULL;
89064@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89065
89066 if (unlikely(allocated))
89067 put_anon_vma(allocated);
89068+
89069+#ifdef CONFIG_PAX_SEGMEXEC
89070+ if (unlikely(avc_m))
89071+ anon_vma_chain_free(avc_m);
89072+#endif
89073+
89074 if (unlikely(avc))
89075 anon_vma_chain_free(avc);
89076 }
89077 return 0;
89078
89079 out_enomem_free_avc:
89080+
89081+#ifdef CONFIG_PAX_SEGMEXEC
89082+ if (avc_m)
89083+ anon_vma_chain_free(avc_m);
89084+#endif
89085+
89086 anon_vma_chain_free(avc);
89087 out_enomem:
89088 return -ENOMEM;
89089@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89090 * Attach the anon_vmas from src to dst.
89091 * Returns 0 on success, -ENOMEM on failure.
89092 */
89093-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89094+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89095 {
89096 struct anon_vma_chain *avc, *pavc;
89097 struct anon_vma *root = NULL;
89098@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89099 * the corresponding VMA in the parent process is attached to.
89100 * Returns 0 on success, non-zero on failure.
89101 */
89102-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89103+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89104 {
89105 struct anon_vma_chain *avc;
89106 struct anon_vma *anon_vma;
89107@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89108 void __init anon_vma_init(void)
89109 {
89110 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89111- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89112- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89113+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89114+ anon_vma_ctor);
89115+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89116+ SLAB_PANIC|SLAB_NO_SANITIZE);
89117 }
89118
89119 /*
89120diff --git a/mm/shmem.c b/mm/shmem.c
89121index e43dc55..930e3a2 100644
89122--- a/mm/shmem.c
89123+++ b/mm/shmem.c
89124@@ -33,7 +33,7 @@
89125 #include <linux/swap.h>
89126 #include <linux/aio.h>
89127
89128-static struct vfsmount *shm_mnt;
89129+struct vfsmount *shm_mnt;
89130
89131 #ifdef CONFIG_SHMEM
89132 /*
89133@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89134 #define BOGO_DIRENT_SIZE 20
89135
89136 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89137-#define SHORT_SYMLINK_LEN 128
89138+#define SHORT_SYMLINK_LEN 64
89139
89140 /*
89141 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89142@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89143 static int shmem_xattr_validate(const char *name)
89144 {
89145 struct { const char *prefix; size_t len; } arr[] = {
89146+
89147+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89148+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89149+#endif
89150+
89151 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89152 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89153 };
89154@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89155 if (err)
89156 return err;
89157
89158+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89159+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89160+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89161+ return -EOPNOTSUPP;
89162+ if (size > 8)
89163+ return -EINVAL;
89164+ }
89165+#endif
89166+
89167 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89168 }
89169
89170@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89171 int err = -ENOMEM;
89172
89173 /* Round up to L1_CACHE_BYTES to resist false sharing */
89174- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89175- L1_CACHE_BYTES), GFP_KERNEL);
89176+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89177 if (!sbinfo)
89178 return -ENOMEM;
89179
89180diff --git a/mm/slab.c b/mm/slab.c
89181index 2580db0..0523956 100644
89182--- a/mm/slab.c
89183+++ b/mm/slab.c
89184@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89185 if ((x)->max_freeable < i) \
89186 (x)->max_freeable = i; \
89187 } while (0)
89188-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89189-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89190-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89191-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89192+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89193+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89194+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89195+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89196+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89197+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89198 #else
89199 #define STATS_INC_ACTIVE(x) do { } while (0)
89200 #define STATS_DEC_ACTIVE(x) do { } while (0)
89201@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89202 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89203 #define STATS_INC_FREEHIT(x) do { } while (0)
89204 #define STATS_INC_FREEMISS(x) do { } while (0)
89205+#define STATS_INC_SANITIZED(x) do { } while (0)
89206+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89207 #endif
89208
89209 #if DEBUG
89210@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89211 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89212 */
89213 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89214- const struct slab *slab, void *obj)
89215+ const struct slab *slab, const void *obj)
89216 {
89217 u32 offset = (obj - slab->s_mem);
89218 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89219@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89220 */
89221
89222 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89223- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89224+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89225
89226 if (INDEX_AC != INDEX_NODE)
89227 kmalloc_caches[INDEX_NODE] =
89228 create_kmalloc_cache("kmalloc-node",
89229- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89230+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89231
89232 slab_early_init = 0;
89233
89234@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89235 struct array_cache *ac = cpu_cache_get(cachep);
89236
89237 check_irq_off();
89238+
89239+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89240+ if (pax_sanitize_slab) {
89241+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89242+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89243+
89244+ if (cachep->ctor)
89245+ cachep->ctor(objp);
89246+
89247+ STATS_INC_SANITIZED(cachep);
89248+ } else
89249+ STATS_INC_NOT_SANITIZED(cachep);
89250+ }
89251+#endif
89252+
89253 kmemleak_free_recursive(objp, cachep->flags);
89254 objp = cache_free_debugcheck(cachep, objp, caller);
89255
89256@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89257
89258 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89259 return;
89260+ VM_BUG_ON(!virt_addr_valid(objp));
89261 local_irq_save(flags);
89262 kfree_debugcheck(objp);
89263 c = virt_to_cache(objp);
89264@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89265 }
89266 /* cpu stats */
89267 {
89268- unsigned long allochit = atomic_read(&cachep->allochit);
89269- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89270- unsigned long freehit = atomic_read(&cachep->freehit);
89271- unsigned long freemiss = atomic_read(&cachep->freemiss);
89272+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89273+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89274+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89275+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89276
89277 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89278 allochit, allocmiss, freehit, freemiss);
89279 }
89280+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89281+ {
89282+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89283+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89284+
89285+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89286+ }
89287+#endif
89288 #endif
89289 }
89290
89291@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89292 static int __init slab_proc_init(void)
89293 {
89294 #ifdef CONFIG_DEBUG_SLAB_LEAK
89295- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89296+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89297 #endif
89298 return 0;
89299 }
89300 module_init(slab_proc_init);
89301 #endif
89302
89303+bool is_usercopy_object(const void *ptr)
89304+{
89305+ struct page *page;
89306+ struct kmem_cache *cachep;
89307+
89308+ if (ZERO_OR_NULL_PTR(ptr))
89309+ return false;
89310+
89311+ if (!slab_is_available())
89312+ return false;
89313+
89314+ if (!virt_addr_valid(ptr))
89315+ return false;
89316+
89317+ page = virt_to_head_page(ptr);
89318+
89319+ if (!PageSlab(page))
89320+ return false;
89321+
89322+ cachep = page->slab_cache;
89323+ return cachep->flags & SLAB_USERCOPY;
89324+}
89325+
89326+#ifdef CONFIG_PAX_USERCOPY
89327+const char *check_heap_object(const void *ptr, unsigned long n)
89328+{
89329+ struct page *page;
89330+ struct kmem_cache *cachep;
89331+ struct slab *slabp;
89332+ unsigned int objnr;
89333+ unsigned long offset;
89334+
89335+ if (ZERO_OR_NULL_PTR(ptr))
89336+ return "<null>";
89337+
89338+ if (!virt_addr_valid(ptr))
89339+ return NULL;
89340+
89341+ page = virt_to_head_page(ptr);
89342+
89343+ if (!PageSlab(page))
89344+ return NULL;
89345+
89346+ cachep = page->slab_cache;
89347+ if (!(cachep->flags & SLAB_USERCOPY))
89348+ return cachep->name;
89349+
89350+ slabp = page->slab_page;
89351+ objnr = obj_to_index(cachep, slabp, ptr);
89352+ BUG_ON(objnr >= cachep->num);
89353+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89354+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89355+ return NULL;
89356+
89357+ return cachep->name;
89358+}
89359+#endif
89360+
89361 /**
89362 * ksize - get the actual amount of memory allocated for a given object
89363 * @objp: Pointer to the object
89364diff --git a/mm/slab.h b/mm/slab.h
89365index a535033..2f98fe5 100644
89366--- a/mm/slab.h
89367+++ b/mm/slab.h
89368@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89369 /* The slab cache that manages slab cache information */
89370 extern struct kmem_cache *kmem_cache;
89371
89372+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89373+#ifdef CONFIG_X86_64
89374+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89375+#else
89376+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89377+#endif
89378+extern bool pax_sanitize_slab;
89379+#endif
89380+
89381 unsigned long calculate_alignment(unsigned long flags,
89382 unsigned long align, unsigned long size);
89383
89384@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89385
89386 /* Legal flag mask for kmem_cache_create(), for various configurations */
89387 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89388- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89389+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89390+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89391
89392 #if defined(CONFIG_DEBUG_SLAB)
89393 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89394@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89395 return s;
89396
89397 page = virt_to_head_page(x);
89398+
89399+ BUG_ON(!PageSlab(page));
89400+
89401 cachep = page->slab_cache;
89402 if (slab_equal_or_root(cachep, s))
89403 return cachep;
89404diff --git a/mm/slab_common.c b/mm/slab_common.c
89405index 538bade..36fed99 100644
89406--- a/mm/slab_common.c
89407+++ b/mm/slab_common.c
89408@@ -22,11 +22,22 @@
89409
89410 #include "slab.h"
89411
89412-enum slab_state slab_state;
89413+enum slab_state slab_state __read_only;
89414 LIST_HEAD(slab_caches);
89415 DEFINE_MUTEX(slab_mutex);
89416 struct kmem_cache *kmem_cache;
89417
89418+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89419+bool pax_sanitize_slab __read_only = true;
89420+static int __init pax_sanitize_slab_setup(char *str)
89421+{
89422+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89423+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89424+ return 1;
89425+}
89426+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89427+#endif
89428+
89429 #ifdef CONFIG_DEBUG_VM
89430 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89431 size_t size)
89432@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89433
89434 err = __kmem_cache_create(s, flags);
89435 if (!err) {
89436- s->refcount = 1;
89437+ atomic_set(&s->refcount, 1);
89438 list_add(&s->list, &slab_caches);
89439 memcg_cache_list_add(memcg, s);
89440 } else {
89441@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89442
89443 get_online_cpus();
89444 mutex_lock(&slab_mutex);
89445- s->refcount--;
89446- if (!s->refcount) {
89447+ if (atomic_dec_and_test(&s->refcount)) {
89448 list_del(&s->list);
89449
89450 if (!__kmem_cache_shutdown(s)) {
89451@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89452 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89453 name, size, err);
89454
89455- s->refcount = -1; /* Exempt from merging for now */
89456+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89457 }
89458
89459 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89460@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89461
89462 create_boot_cache(s, name, size, flags);
89463 list_add(&s->list, &slab_caches);
89464- s->refcount = 1;
89465+ atomic_set(&s->refcount, 1);
89466 return s;
89467 }
89468
89469@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89470 EXPORT_SYMBOL(kmalloc_dma_caches);
89471 #endif
89472
89473+#ifdef CONFIG_PAX_USERCOPY_SLABS
89474+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89475+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89476+#endif
89477+
89478 /*
89479 * Conversion table for small slabs sizes / 8 to the index in the
89480 * kmalloc array. This is necessary for slabs < 192 since we have non power
89481@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89482 return kmalloc_dma_caches[index];
89483
89484 #endif
89485+
89486+#ifdef CONFIG_PAX_USERCOPY_SLABS
89487+ if (unlikely((flags & GFP_USERCOPY)))
89488+ return kmalloc_usercopy_caches[index];
89489+
89490+#endif
89491+
89492 return kmalloc_caches[index];
89493 }
89494
89495@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89496 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89497 if (!kmalloc_caches[i]) {
89498 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89499- 1 << i, flags);
89500+ 1 << i, SLAB_USERCOPY | flags);
89501 }
89502
89503 /*
89504@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89505 * earlier power of two caches
89506 */
89507 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89508- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89509+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89510
89511 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89512- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89513+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89514 }
89515
89516 /* Kmalloc array is now usable */
89517@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89518 }
89519 }
89520 #endif
89521+
89522+#ifdef CONFIG_PAX_USERCOPY_SLABS
89523+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89524+ struct kmem_cache *s = kmalloc_caches[i];
89525+
89526+ if (s) {
89527+ int size = kmalloc_size(i);
89528+ char *n = kasprintf(GFP_NOWAIT,
89529+ "usercopy-kmalloc-%d", size);
89530+
89531+ BUG_ON(!n);
89532+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89533+ size, SLAB_USERCOPY | flags);
89534+ }
89535+ }
89536+#endif
89537+
89538 }
89539 #endif /* !CONFIG_SLOB */
89540
89541@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89542 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89543 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89544 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89545+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89546+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89547+#endif
89548 #endif
89549 seq_putc(m, '\n');
89550 }
89551diff --git a/mm/slob.c b/mm/slob.c
89552index 91bd3f2..e2f549e 100644
89553--- a/mm/slob.c
89554+++ b/mm/slob.c
89555@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89556 /*
89557 * Return the size of a slob block.
89558 */
89559-static slobidx_t slob_units(slob_t *s)
89560+static slobidx_t slob_units(const slob_t *s)
89561 {
89562 if (s->units > 0)
89563 return s->units;
89564@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89565 /*
89566 * Return the next free slob block pointer after this one.
89567 */
89568-static slob_t *slob_next(slob_t *s)
89569+static slob_t *slob_next(const slob_t *s)
89570 {
89571 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89572 slobidx_t next;
89573@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89574 /*
89575 * Returns true if s is the last free block in its page.
89576 */
89577-static int slob_last(slob_t *s)
89578+static int slob_last(const slob_t *s)
89579 {
89580 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89581 }
89582
89583-static void *slob_new_pages(gfp_t gfp, int order, int node)
89584+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89585 {
89586- void *page;
89587+ struct page *page;
89588
89589 #ifdef CONFIG_NUMA
89590 if (node != NUMA_NO_NODE)
89591@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89592 if (!page)
89593 return NULL;
89594
89595- return page_address(page);
89596+ __SetPageSlab(page);
89597+ return page;
89598 }
89599
89600-static void slob_free_pages(void *b, int order)
89601+static void slob_free_pages(struct page *sp, int order)
89602 {
89603 if (current->reclaim_state)
89604 current->reclaim_state->reclaimed_slab += 1 << order;
89605- free_pages((unsigned long)b, order);
89606+ __ClearPageSlab(sp);
89607+ page_mapcount_reset(sp);
89608+ sp->private = 0;
89609+ __free_pages(sp, order);
89610 }
89611
89612 /*
89613@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89614
89615 /* Not enough space: must allocate a new page */
89616 if (!b) {
89617- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89618- if (!b)
89619+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89620+ if (!sp)
89621 return NULL;
89622- sp = virt_to_page(b);
89623- __SetPageSlab(sp);
89624+ b = page_address(sp);
89625
89626 spin_lock_irqsave(&slob_lock, flags);
89627 sp->units = SLOB_UNITS(PAGE_SIZE);
89628 sp->freelist = b;
89629+ sp->private = 0;
89630 INIT_LIST_HEAD(&sp->list);
89631 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89632 set_slob_page_free(sp, slob_list);
89633@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89634 if (slob_page_free(sp))
89635 clear_slob_page_free(sp);
89636 spin_unlock_irqrestore(&slob_lock, flags);
89637- __ClearPageSlab(sp);
89638- page_mapcount_reset(sp);
89639- slob_free_pages(b, 0);
89640+ slob_free_pages(sp, 0);
89641 return;
89642 }
89643
89644+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89645+ if (pax_sanitize_slab)
89646+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89647+#endif
89648+
89649 if (!slob_page_free(sp)) {
89650 /* This slob page is about to become partially free. Easy! */
89651 sp->units = units;
89652@@ -424,11 +431,10 @@ out:
89653 */
89654
89655 static __always_inline void *
89656-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89657+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89658 {
89659- unsigned int *m;
89660- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89661- void *ret;
89662+ slob_t *m;
89663+ void *ret = NULL;
89664
89665 gfp &= gfp_allowed_mask;
89666
89667@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89668
89669 if (!m)
89670 return NULL;
89671- *m = size;
89672+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89673+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89674+ m[0].units = size;
89675+ m[1].units = align;
89676 ret = (void *)m + align;
89677
89678 trace_kmalloc_node(caller, ret,
89679 size, size + align, gfp, node);
89680 } else {
89681 unsigned int order = get_order(size);
89682+ struct page *page;
89683
89684 if (likely(order))
89685 gfp |= __GFP_COMP;
89686- ret = slob_new_pages(gfp, order, node);
89687+ page = slob_new_pages(gfp, order, node);
89688+ if (page) {
89689+ ret = page_address(page);
89690+ page->private = size;
89691+ }
89692
89693 trace_kmalloc_node(caller, ret,
89694 size, PAGE_SIZE << order, gfp, node);
89695 }
89696
89697- kmemleak_alloc(ret, size, 1, gfp);
89698+ return ret;
89699+}
89700+
89701+static __always_inline void *
89702+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89703+{
89704+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89705+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89706+
89707+ if (!ZERO_OR_NULL_PTR(ret))
89708+ kmemleak_alloc(ret, size, 1, gfp);
89709 return ret;
89710 }
89711
89712@@ -493,34 +517,112 @@ void kfree(const void *block)
89713 return;
89714 kmemleak_free(block);
89715
89716+ VM_BUG_ON(!virt_addr_valid(block));
89717 sp = virt_to_page(block);
89718- if (PageSlab(sp)) {
89719+ VM_BUG_ON(!PageSlab(sp));
89720+ if (!sp->private) {
89721 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89722- unsigned int *m = (unsigned int *)(block - align);
89723- slob_free(m, *m + align);
89724- } else
89725+ slob_t *m = (slob_t *)(block - align);
89726+ slob_free(m, m[0].units + align);
89727+ } else {
89728+ __ClearPageSlab(sp);
89729+ page_mapcount_reset(sp);
89730+ sp->private = 0;
89731 __free_pages(sp, compound_order(sp));
89732+ }
89733 }
89734 EXPORT_SYMBOL(kfree);
89735
89736+bool is_usercopy_object(const void *ptr)
89737+{
89738+ if (!slab_is_available())
89739+ return false;
89740+
89741+ // PAX: TODO
89742+
89743+ return false;
89744+}
89745+
89746+#ifdef CONFIG_PAX_USERCOPY
89747+const char *check_heap_object(const void *ptr, unsigned long n)
89748+{
89749+ struct page *page;
89750+ const slob_t *free;
89751+ const void *base;
89752+ unsigned long flags;
89753+
89754+ if (ZERO_OR_NULL_PTR(ptr))
89755+ return "<null>";
89756+
89757+ if (!virt_addr_valid(ptr))
89758+ return NULL;
89759+
89760+ page = virt_to_head_page(ptr);
89761+ if (!PageSlab(page))
89762+ return NULL;
89763+
89764+ if (page->private) {
89765+ base = page;
89766+ if (base <= ptr && n <= page->private - (ptr - base))
89767+ return NULL;
89768+ return "<slob>";
89769+ }
89770+
89771+ /* some tricky double walking to find the chunk */
89772+ spin_lock_irqsave(&slob_lock, flags);
89773+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89774+ free = page->freelist;
89775+
89776+ while (!slob_last(free) && (void *)free <= ptr) {
89777+ base = free + slob_units(free);
89778+ free = slob_next(free);
89779+ }
89780+
89781+ while (base < (void *)free) {
89782+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89783+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89784+ int offset;
89785+
89786+ if (ptr < base + align)
89787+ break;
89788+
89789+ offset = ptr - base - align;
89790+ if (offset >= m) {
89791+ base += size;
89792+ continue;
89793+ }
89794+
89795+ if (n > m - offset)
89796+ break;
89797+
89798+ spin_unlock_irqrestore(&slob_lock, flags);
89799+ return NULL;
89800+ }
89801+
89802+ spin_unlock_irqrestore(&slob_lock, flags);
89803+ return "<slob>";
89804+}
89805+#endif
89806+
89807 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89808 size_t ksize(const void *block)
89809 {
89810 struct page *sp;
89811 int align;
89812- unsigned int *m;
89813+ slob_t *m;
89814
89815 BUG_ON(!block);
89816 if (unlikely(block == ZERO_SIZE_PTR))
89817 return 0;
89818
89819 sp = virt_to_page(block);
89820- if (unlikely(!PageSlab(sp)))
89821- return PAGE_SIZE << compound_order(sp);
89822+ VM_BUG_ON(!PageSlab(sp));
89823+ if (sp->private)
89824+ return sp->private;
89825
89826 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89827- m = (unsigned int *)(block - align);
89828- return SLOB_UNITS(*m) * SLOB_UNIT;
89829+ m = (slob_t *)(block - align);
89830+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89831 }
89832 EXPORT_SYMBOL(ksize);
89833
89834@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89835
89836 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89837 {
89838- void *b;
89839+ void *b = NULL;
89840
89841 flags &= gfp_allowed_mask;
89842
89843 lockdep_trace_alloc(flags);
89844
89845+#ifdef CONFIG_PAX_USERCOPY_SLABS
89846+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89847+#else
89848 if (c->size < PAGE_SIZE) {
89849 b = slob_alloc(c->size, flags, c->align, node);
89850 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89851 SLOB_UNITS(c->size) * SLOB_UNIT,
89852 flags, node);
89853 } else {
89854- b = slob_new_pages(flags, get_order(c->size), node);
89855+ struct page *sp;
89856+
89857+ sp = slob_new_pages(flags, get_order(c->size), node);
89858+ if (sp) {
89859+ b = page_address(sp);
89860+ sp->private = c->size;
89861+ }
89862 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89863 PAGE_SIZE << get_order(c->size),
89864 flags, node);
89865 }
89866+#endif
89867
89868 if (b && c->ctor)
89869 c->ctor(b);
89870@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89871
89872 static void __kmem_cache_free(void *b, int size)
89873 {
89874- if (size < PAGE_SIZE)
89875+ struct page *sp;
89876+
89877+ sp = virt_to_page(b);
89878+ BUG_ON(!PageSlab(sp));
89879+ if (!sp->private)
89880 slob_free(b, size);
89881 else
89882- slob_free_pages(b, get_order(size));
89883+ slob_free_pages(sp, get_order(size));
89884 }
89885
89886 static void kmem_rcu_free(struct rcu_head *head)
89887@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89888
89889 void kmem_cache_free(struct kmem_cache *c, void *b)
89890 {
89891+ int size = c->size;
89892+
89893+#ifdef CONFIG_PAX_USERCOPY_SLABS
89894+ if (size + c->align < PAGE_SIZE) {
89895+ size += c->align;
89896+ b -= c->align;
89897+ }
89898+#endif
89899+
89900 kmemleak_free_recursive(b, c->flags);
89901 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89902 struct slob_rcu *slob_rcu;
89903- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89904- slob_rcu->size = c->size;
89905+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89906+ slob_rcu->size = size;
89907 call_rcu(&slob_rcu->head, kmem_rcu_free);
89908 } else {
89909- __kmem_cache_free(b, c->size);
89910+ __kmem_cache_free(b, size);
89911 }
89912
89913+#ifdef CONFIG_PAX_USERCOPY_SLABS
89914+ trace_kfree(_RET_IP_, b);
89915+#else
89916 trace_kmem_cache_free(_RET_IP_, b);
89917+#endif
89918+
89919 }
89920 EXPORT_SYMBOL(kmem_cache_free);
89921
89922diff --git a/mm/slub.c b/mm/slub.c
89923index e3ba1f2..bd45dac 100644
89924--- a/mm/slub.c
89925+++ b/mm/slub.c
89926@@ -207,7 +207,7 @@ struct track {
89927
89928 enum track_item { TRACK_ALLOC, TRACK_FREE };
89929
89930-#ifdef CONFIG_SYSFS
89931+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89932 static int sysfs_slab_add(struct kmem_cache *);
89933 static int sysfs_slab_alias(struct kmem_cache *, const char *);
89934 static void sysfs_slab_remove(struct kmem_cache *);
89935@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
89936 if (!t->addr)
89937 return;
89938
89939- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
89940+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
89941 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
89942 #ifdef CONFIG_STACKTRACE
89943 {
89944@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
89945
89946 slab_free_hook(s, x);
89947
89948+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89949+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
89950+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
89951+ if (s->ctor)
89952+ s->ctor(x);
89953+ }
89954+#endif
89955+
89956 redo:
89957 /*
89958 * Determine the currently cpus per cpu slab.
89959@@ -2676,7 +2684,7 @@ static int slub_min_objects;
89960 * Merge control. If this is set then no merging of slab caches will occur.
89961 * (Could be removed. This was introduced to pacify the merge skeptics.)
89962 */
89963-static int slub_nomerge;
89964+static int slub_nomerge = 1;
89965
89966 /*
89967 * Calculate the order of allocation given an slab object size.
89968@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
89969 s->inuse = size;
89970
89971 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
89972+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89973+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
89974+#endif
89975 s->ctor)) {
89976 /*
89977 * Relocate free pointer after the object if it is not
89978@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
89979 EXPORT_SYMBOL(__kmalloc_node);
89980 #endif
89981
89982+bool is_usercopy_object(const void *ptr)
89983+{
89984+ struct page *page;
89985+ struct kmem_cache *s;
89986+
89987+ if (ZERO_OR_NULL_PTR(ptr))
89988+ return false;
89989+
89990+ if (!slab_is_available())
89991+ return false;
89992+
89993+ if (!virt_addr_valid(ptr))
89994+ return false;
89995+
89996+ page = virt_to_head_page(ptr);
89997+
89998+ if (!PageSlab(page))
89999+ return false;
90000+
90001+ s = page->slab_cache;
90002+ return s->flags & SLAB_USERCOPY;
90003+}
90004+
90005+#ifdef CONFIG_PAX_USERCOPY
90006+const char *check_heap_object(const void *ptr, unsigned long n)
90007+{
90008+ struct page *page;
90009+ struct kmem_cache *s;
90010+ unsigned long offset;
90011+
90012+ if (ZERO_OR_NULL_PTR(ptr))
90013+ return "<null>";
90014+
90015+ if (!virt_addr_valid(ptr))
90016+ return NULL;
90017+
90018+ page = virt_to_head_page(ptr);
90019+
90020+ if (!PageSlab(page))
90021+ return NULL;
90022+
90023+ s = page->slab_cache;
90024+ if (!(s->flags & SLAB_USERCOPY))
90025+ return s->name;
90026+
90027+ offset = (ptr - page_address(page)) % s->size;
90028+ if (offset <= s->object_size && n <= s->object_size - offset)
90029+ return NULL;
90030+
90031+ return s->name;
90032+}
90033+#endif
90034+
90035 size_t ksize(const void *object)
90036 {
90037 struct page *page;
90038@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90039 if (unlikely(ZERO_OR_NULL_PTR(x)))
90040 return;
90041
90042+ VM_BUG_ON(!virt_addr_valid(x));
90043 page = virt_to_head_page(x);
90044 if (unlikely(!PageSlab(page))) {
90045 BUG_ON(!PageCompound(page));
90046@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90047 /*
90048 * We may have set a slab to be unmergeable during bootstrap.
90049 */
90050- if (s->refcount < 0)
90051+ if (atomic_read(&s->refcount) < 0)
90052 return 1;
90053
90054 return 0;
90055@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90056
90057 s = find_mergeable(memcg, size, align, flags, name, ctor);
90058 if (s) {
90059- s->refcount++;
90060+ atomic_inc(&s->refcount);
90061 /*
90062 * Adjust the object sizes so that we clear
90063 * the complete object on kzalloc.
90064@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90065 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90066
90067 if (sysfs_slab_alias(s, name)) {
90068- s->refcount--;
90069+ atomic_dec(&s->refcount);
90070 s = NULL;
90071 }
90072 }
90073@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90074 }
90075 #endif
90076
90077-#ifdef CONFIG_SYSFS
90078+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90079 static int count_inuse(struct page *page)
90080 {
90081 return page->inuse;
90082@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90083 validate_slab_cache(kmalloc_caches[9]);
90084 }
90085 #else
90086-#ifdef CONFIG_SYSFS
90087+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90088 static void resiliency_test(void) {};
90089 #endif
90090 #endif
90091
90092-#ifdef CONFIG_SYSFS
90093+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90094 enum slab_stat_type {
90095 SL_ALL, /* All slabs */
90096 SL_PARTIAL, /* Only partially allocated slabs */
90097@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90098
90099 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90100 {
90101- return sprintf(buf, "%d\n", s->refcount - 1);
90102+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90103 }
90104 SLAB_ATTR_RO(aliases);
90105
90106@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90107 SLAB_ATTR_RO(cache_dma);
90108 #endif
90109
90110+#ifdef CONFIG_PAX_USERCOPY_SLABS
90111+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90112+{
90113+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90114+}
90115+SLAB_ATTR_RO(usercopy);
90116+#endif
90117+
90118 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90119 {
90120 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90121@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90122 #ifdef CONFIG_ZONE_DMA
90123 &cache_dma_attr.attr,
90124 #endif
90125+#ifdef CONFIG_PAX_USERCOPY_SLABS
90126+ &usercopy_attr.attr,
90127+#endif
90128 #ifdef CONFIG_NUMA
90129 &remote_node_defrag_ratio_attr.attr,
90130 #endif
90131@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90132 return name;
90133 }
90134
90135+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90136 static int sysfs_slab_add(struct kmem_cache *s)
90137 {
90138 int err;
90139@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90140 }
90141
90142 s->kobj.kset = slab_kset;
90143- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90144+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90145 if (err) {
90146 kobject_put(&s->kobj);
90147 return err;
90148@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90149 kobject_del(&s->kobj);
90150 kobject_put(&s->kobj);
90151 }
90152+#endif
90153
90154 /*
90155 * Need to buffer aliases during bootup until sysfs becomes
90156@@ -5213,6 +5291,7 @@ struct saved_alias {
90157
90158 static struct saved_alias *alias_list;
90159
90160+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90161 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90162 {
90163 struct saved_alias *al;
90164@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90165 alias_list = al;
90166 return 0;
90167 }
90168+#endif
90169
90170 static int __init slab_sysfs_init(void)
90171 {
90172diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90173index 27eeab3..7c3f7f2 100644
90174--- a/mm/sparse-vmemmap.c
90175+++ b/mm/sparse-vmemmap.c
90176@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90177 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90178 if (!p)
90179 return NULL;
90180- pud_populate(&init_mm, pud, p);
90181+ pud_populate_kernel(&init_mm, pud, p);
90182 }
90183 return pud;
90184 }
90185@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90186 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90187 if (!p)
90188 return NULL;
90189- pgd_populate(&init_mm, pgd, p);
90190+ pgd_populate_kernel(&init_mm, pgd, p);
90191 }
90192 return pgd;
90193 }
90194diff --git a/mm/sparse.c b/mm/sparse.c
90195index 308d503..3dbbd04 100644
90196--- a/mm/sparse.c
90197+++ b/mm/sparse.c
90198@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90199
90200 for (i = 0; i < PAGES_PER_SECTION; i++) {
90201 if (PageHWPoison(&memmap[i])) {
90202- atomic_long_sub(1, &num_poisoned_pages);
90203+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90204 ClearPageHWPoison(&memmap[i]);
90205 }
90206 }
90207diff --git a/mm/swap.c b/mm/swap.c
90208index c899502..d4dc2cd 100644
90209--- a/mm/swap.c
90210+++ b/mm/swap.c
90211@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
90212
90213 __page_cache_release(page);
90214 dtor = get_compound_page_dtor(page);
90215+ if (!PageHuge(page))
90216+ BUG_ON(dtor != free_compound_page);
90217 (*dtor)(page);
90218 }
90219
90220diff --git a/mm/swapfile.c b/mm/swapfile.c
90221index 6cf2e60..d204b3e 100644
90222--- a/mm/swapfile.c
90223+++ b/mm/swapfile.c
90224@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90225
90226 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90227 /* Activity counter to indicate that a swapon or swapoff has occurred */
90228-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90229+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90230
90231 static inline unsigned char swap_count(unsigned char ent)
90232 {
90233@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90234 }
90235 filp_close(swap_file, NULL);
90236 err = 0;
90237- atomic_inc(&proc_poll_event);
90238+ atomic_inc_unchecked(&proc_poll_event);
90239 wake_up_interruptible(&proc_poll_wait);
90240
90241 out_dput:
90242@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90243
90244 poll_wait(file, &proc_poll_wait, wait);
90245
90246- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90247- seq->poll_event = atomic_read(&proc_poll_event);
90248+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90249+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90250 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90251 }
90252
90253@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90254 return ret;
90255
90256 seq = file->private_data;
90257- seq->poll_event = atomic_read(&proc_poll_event);
90258+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90259 return 0;
90260 }
90261
90262@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90263 (frontswap_map) ? "FS" : "");
90264
90265 mutex_unlock(&swapon_mutex);
90266- atomic_inc(&proc_poll_event);
90267+ atomic_inc_unchecked(&proc_poll_event);
90268 wake_up_interruptible(&proc_poll_wait);
90269
90270 if (S_ISREG(inode->i_mode))
90271diff --git a/mm/util.c b/mm/util.c
90272index 7441c41..c3de793 100644
90273--- a/mm/util.c
90274+++ b/mm/util.c
90275@@ -294,6 +294,12 @@ done:
90276 void arch_pick_mmap_layout(struct mm_struct *mm)
90277 {
90278 mm->mmap_base = TASK_UNMAPPED_BASE;
90279+
90280+#ifdef CONFIG_PAX_RANDMMAP
90281+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90282+ mm->mmap_base += mm->delta_mmap;
90283+#endif
90284+
90285 mm->get_unmapped_area = arch_get_unmapped_area;
90286 }
90287 #endif
90288diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90289index 13a5495..6707d97 100644
90290--- a/mm/vmalloc.c
90291+++ b/mm/vmalloc.c
90292@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90293
90294 pte = pte_offset_kernel(pmd, addr);
90295 do {
90296- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90297- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90298+
90299+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90300+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90301+ BUG_ON(!pte_exec(*pte));
90302+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90303+ continue;
90304+ }
90305+#endif
90306+
90307+ {
90308+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90309+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90310+ }
90311 } while (pte++, addr += PAGE_SIZE, addr != end);
90312 }
90313
90314@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90315 pte = pte_alloc_kernel(pmd, addr);
90316 if (!pte)
90317 return -ENOMEM;
90318+
90319+ pax_open_kernel();
90320 do {
90321 struct page *page = pages[*nr];
90322
90323- if (WARN_ON(!pte_none(*pte)))
90324+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90325+ if (pgprot_val(prot) & _PAGE_NX)
90326+#endif
90327+
90328+ if (!pte_none(*pte)) {
90329+ pax_close_kernel();
90330+ WARN_ON(1);
90331 return -EBUSY;
90332- if (WARN_ON(!page))
90333+ }
90334+ if (!page) {
90335+ pax_close_kernel();
90336+ WARN_ON(1);
90337 return -ENOMEM;
90338+ }
90339 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90340 (*nr)++;
90341 } while (pte++, addr += PAGE_SIZE, addr != end);
90342+ pax_close_kernel();
90343 return 0;
90344 }
90345
90346@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90347 pmd_t *pmd;
90348 unsigned long next;
90349
90350- pmd = pmd_alloc(&init_mm, pud, addr);
90351+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90352 if (!pmd)
90353 return -ENOMEM;
90354 do {
90355@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90356 pud_t *pud;
90357 unsigned long next;
90358
90359- pud = pud_alloc(&init_mm, pgd, addr);
90360+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90361 if (!pud)
90362 return -ENOMEM;
90363 do {
90364@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90365 if (addr >= MODULES_VADDR && addr < MODULES_END)
90366 return 1;
90367 #endif
90368+
90369+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90370+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90371+ return 1;
90372+#endif
90373+
90374 return is_vmalloc_addr(x);
90375 }
90376
90377@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90378
90379 if (!pgd_none(*pgd)) {
90380 pud_t *pud = pud_offset(pgd, addr);
90381+#ifdef CONFIG_X86
90382+ if (!pud_large(*pud))
90383+#endif
90384 if (!pud_none(*pud)) {
90385 pmd_t *pmd = pmd_offset(pud, addr);
90386+#ifdef CONFIG_X86
90387+ if (!pmd_large(*pmd))
90388+#endif
90389 if (!pmd_none(*pmd)) {
90390 pte_t *ptep, pte;
90391
90392@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90393 * Allocate a region of KVA of the specified size and alignment, within the
90394 * vstart and vend.
90395 */
90396-static struct vmap_area *alloc_vmap_area(unsigned long size,
90397+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90398 unsigned long align,
90399 unsigned long vstart, unsigned long vend,
90400 int node, gfp_t gfp_mask)
90401@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90402 struct vm_struct *area;
90403
90404 BUG_ON(in_interrupt());
90405+
90406+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90407+ if (flags & VM_KERNEXEC) {
90408+ if (start != VMALLOC_START || end != VMALLOC_END)
90409+ return NULL;
90410+ start = (unsigned long)MODULES_EXEC_VADDR;
90411+ end = (unsigned long)MODULES_EXEC_END;
90412+ }
90413+#endif
90414+
90415 if (flags & VM_IOREMAP)
90416 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90417
90418@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90419 if (count > totalram_pages)
90420 return NULL;
90421
90422+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90423+ if (!(pgprot_val(prot) & _PAGE_NX))
90424+ flags |= VM_KERNEXEC;
90425+#endif
90426+
90427 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90428 __builtin_return_address(0));
90429 if (!area)
90430@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90431 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90432 goto fail;
90433
90434+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90435+ if (!(pgprot_val(prot) & _PAGE_NX))
90436+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90437+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90438+ else
90439+#endif
90440+
90441 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90442 start, end, node, gfp_mask, caller);
90443 if (!area)
90444@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90445 * For tight control over page level allocator and protection flags
90446 * use __vmalloc() instead.
90447 */
90448-
90449 void *vmalloc_exec(unsigned long size)
90450 {
90451- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90452+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90453 NUMA_NO_NODE, __builtin_return_address(0));
90454 }
90455
90456@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90457 {
90458 struct vm_struct *area;
90459
90460+ BUG_ON(vma->vm_mirror);
90461+
90462 size = PAGE_ALIGN(size);
90463
90464 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90465@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90466 v->addr, v->addr + v->size, v->size);
90467
90468 if (v->caller)
90469+#ifdef CONFIG_GRKERNSEC_HIDESYM
90470+ seq_printf(m, " %pK", v->caller);
90471+#else
90472 seq_printf(m, " %pS", v->caller);
90473+#endif
90474
90475 if (v->nr_pages)
90476 seq_printf(m, " pages=%d", v->nr_pages);
90477diff --git a/mm/vmstat.c b/mm/vmstat.c
90478index 20c2ef4..15e7ab7 100644
90479--- a/mm/vmstat.c
90480+++ b/mm/vmstat.c
90481@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90482 *
90483 * vm_stat contains the global counters
90484 */
90485-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90486+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90487 EXPORT_SYMBOL(vm_stat);
90488
90489 #ifdef CONFIG_SMP
90490@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90491 v = p->vm_stat_diff[i];
90492 p->vm_stat_diff[i] = 0;
90493 local_irq_restore(flags);
90494- atomic_long_add(v, &zone->vm_stat[i]);
90495+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90496 global_diff[i] += v;
90497 #ifdef CONFIG_NUMA
90498 /* 3 seconds idle till flush */
90499@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90500
90501 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90502 if (global_diff[i])
90503- atomic_long_add(global_diff[i], &vm_stat[i]);
90504+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90505 }
90506
90507 /*
90508@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90509 if (pset->vm_stat_diff[i]) {
90510 int v = pset->vm_stat_diff[i];
90511 pset->vm_stat_diff[i] = 0;
90512- atomic_long_add(v, &zone->vm_stat[i]);
90513- atomic_long_add(v, &vm_stat[i]);
90514+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90515+ atomic_long_add_unchecked(v, &vm_stat[i]);
90516 }
90517 }
90518 #endif
90519@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90520 start_cpu_timer(cpu);
90521 #endif
90522 #ifdef CONFIG_PROC_FS
90523- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90524- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90525- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90526- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90527+ {
90528+ mode_t gr_mode = S_IRUGO;
90529+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90530+ gr_mode = S_IRUSR;
90531+#endif
90532+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90533+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90534+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90535+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90536+#else
90537+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90538+#endif
90539+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90540+ }
90541 #endif
90542 return 0;
90543 }
90544diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90545index 2fb2d88..8c06e40 100644
90546--- a/net/8021q/vlan.c
90547+++ b/net/8021q/vlan.c
90548@@ -469,7 +469,7 @@ out:
90549 return NOTIFY_DONE;
90550 }
90551
90552-static struct notifier_block vlan_notifier_block __read_mostly = {
90553+static struct notifier_block vlan_notifier_block = {
90554 .notifier_call = vlan_device_event,
90555 };
90556
90557@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90558 err = -EPERM;
90559 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90560 break;
90561- if ((args.u.name_type >= 0) &&
90562- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90563+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90564 struct vlan_net *vn;
90565
90566 vn = net_generic(net, vlan_net_id);
90567diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
90568index 3091297..c7e634a 100644
90569--- a/net/8021q/vlan_netlink.c
90570+++ b/net/8021q/vlan_netlink.c
90571@@ -171,7 +171,7 @@ static size_t vlan_get_size(const struct net_device *dev)
90572
90573 return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */
90574 nla_total_size(2) + /* IFLA_VLAN_ID */
90575- sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */
90576+ nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
90577 vlan_qos_map_size(vlan->nr_ingress_mappings) +
90578 vlan_qos_map_size(vlan->nr_egress_mappings);
90579 }
90580diff --git a/net/9p/mod.c b/net/9p/mod.c
90581index 6ab36ae..6f1841b 100644
90582--- a/net/9p/mod.c
90583+++ b/net/9p/mod.c
90584@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90585 void v9fs_register_trans(struct p9_trans_module *m)
90586 {
90587 spin_lock(&v9fs_trans_lock);
90588- list_add_tail(&m->list, &v9fs_trans_list);
90589+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90590 spin_unlock(&v9fs_trans_lock);
90591 }
90592 EXPORT_SYMBOL(v9fs_register_trans);
90593@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90594 void v9fs_unregister_trans(struct p9_trans_module *m)
90595 {
90596 spin_lock(&v9fs_trans_lock);
90597- list_del_init(&m->list);
90598+ pax_list_del_init((struct list_head *)&m->list);
90599 spin_unlock(&v9fs_trans_lock);
90600 }
90601 EXPORT_SYMBOL(v9fs_unregister_trans);
90602diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90603index 3ffda1b..fceac96 100644
90604--- a/net/9p/trans_fd.c
90605+++ b/net/9p/trans_fd.c
90606@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90607 oldfs = get_fs();
90608 set_fs(get_ds());
90609 /* The cast to a user pointer is valid due to the set_fs() */
90610- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90611+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90612 set_fs(oldfs);
90613
90614 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90615diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90616index 876fbe8..8bbea9f 100644
90617--- a/net/atm/atm_misc.c
90618+++ b/net/atm/atm_misc.c
90619@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90620 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90621 return 1;
90622 atm_return(vcc, truesize);
90623- atomic_inc(&vcc->stats->rx_drop);
90624+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90625 return 0;
90626 }
90627 EXPORT_SYMBOL(atm_charge);
90628@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90629 }
90630 }
90631 atm_return(vcc, guess);
90632- atomic_inc(&vcc->stats->rx_drop);
90633+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90634 return NULL;
90635 }
90636 EXPORT_SYMBOL(atm_alloc_charge);
90637@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90638
90639 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90640 {
90641-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90642+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90643 __SONET_ITEMS
90644 #undef __HANDLE_ITEM
90645 }
90646@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90647
90648 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90649 {
90650-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90651+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90652 __SONET_ITEMS
90653 #undef __HANDLE_ITEM
90654 }
90655diff --git a/net/atm/lec.h b/net/atm/lec.h
90656index 4149db1..f2ab682 100644
90657--- a/net/atm/lec.h
90658+++ b/net/atm/lec.h
90659@@ -48,7 +48,7 @@ struct lane2_ops {
90660 const u8 *tlvs, u32 sizeoftlvs);
90661 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90662 const u8 *tlvs, u32 sizeoftlvs);
90663-};
90664+} __no_const;
90665
90666 /*
90667 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90668diff --git a/net/atm/proc.c b/net/atm/proc.c
90669index bbb6461..cf04016 100644
90670--- a/net/atm/proc.c
90671+++ b/net/atm/proc.c
90672@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90673 const struct k_atm_aal_stats *stats)
90674 {
90675 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90676- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90677- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90678- atomic_read(&stats->rx_drop));
90679+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90680+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90681+ atomic_read_unchecked(&stats->rx_drop));
90682 }
90683
90684 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90685diff --git a/net/atm/resources.c b/net/atm/resources.c
90686index 0447d5d..3cf4728 100644
90687--- a/net/atm/resources.c
90688+++ b/net/atm/resources.c
90689@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90690 static void copy_aal_stats(struct k_atm_aal_stats *from,
90691 struct atm_aal_stats *to)
90692 {
90693-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90694+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90695 __AAL_STAT_ITEMS
90696 #undef __HANDLE_ITEM
90697 }
90698@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90699 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90700 struct atm_aal_stats *to)
90701 {
90702-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90703+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90704 __AAL_STAT_ITEMS
90705 #undef __HANDLE_ITEM
90706 }
90707diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90708index 919a5ce..cc6b444 100644
90709--- a/net/ax25/sysctl_net_ax25.c
90710+++ b/net/ax25/sysctl_net_ax25.c
90711@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90712 {
90713 char path[sizeof("net/ax25/") + IFNAMSIZ];
90714 int k;
90715- struct ctl_table *table;
90716+ ctl_table_no_const *table;
90717
90718 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90719 if (!table)
90720diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90721index 62da527..aa27535 100644
90722--- a/net/batman-adv/bat_iv_ogm.c
90723+++ b/net/batman-adv/bat_iv_ogm.c
90724@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90725
90726 /* randomize initial seqno to avoid collision */
90727 get_random_bytes(&random_seqno, sizeof(random_seqno));
90728- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90729+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90730
90731 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90732 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90733@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90734 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90735
90736 /* change sequence number to network order */
90737- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90738+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90739 batadv_ogm_packet->seqno = htonl(seqno);
90740- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90741+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90742
90743 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90744 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90745@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90746 return;
90747
90748 /* could be changed by schedule_own_packet() */
90749- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90750+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90751
90752 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90753 has_directlink_flag = 1;
90754diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90755index c478e6b..469fd2f 100644
90756--- a/net/batman-adv/hard-interface.c
90757+++ b/net/batman-adv/hard-interface.c
90758@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90759 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90760 dev_add_pack(&hard_iface->batman_adv_ptype);
90761
90762- atomic_set(&hard_iface->frag_seqno, 1);
90763+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90764 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90765 hard_iface->net_dev->name);
90766
90767diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90768index 33b6144..3212ac5 100644
90769--- a/net/batman-adv/soft-interface.c
90770+++ b/net/batman-adv/soft-interface.c
90771@@ -261,7 +261,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90772 primary_if->net_dev->dev_addr, ETH_ALEN);
90773
90774 /* set broadcast sequence number */
90775- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90776+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90777 bcast_packet->seqno = htonl(seqno);
90778
90779 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90780@@ -481,7 +481,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90781 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90782
90783 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90784- atomic_set(&bat_priv->bcast_seqno, 1);
90785+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90786 atomic_set(&bat_priv->tt.vn, 0);
90787 atomic_set(&bat_priv->tt.local_changes, 0);
90788 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90789diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90790index b2c94e1..3d47e07 100644
90791--- a/net/batman-adv/types.h
90792+++ b/net/batman-adv/types.h
90793@@ -51,7 +51,7 @@
90794 struct batadv_hard_iface_bat_iv {
90795 unsigned char *ogm_buff;
90796 int ogm_buff_len;
90797- atomic_t ogm_seqno;
90798+ atomic_unchecked_t ogm_seqno;
90799 };
90800
90801 /**
90802@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90803 int16_t if_num;
90804 char if_status;
90805 struct net_device *net_dev;
90806- atomic_t frag_seqno;
90807+ atomic_unchecked_t frag_seqno;
90808 uint8_t num_bcasts;
90809 struct kobject *hardif_obj;
90810 atomic_t refcount;
90811@@ -560,7 +560,7 @@ struct batadv_priv {
90812 #ifdef CONFIG_BATMAN_ADV_DEBUG
90813 atomic_t log_level;
90814 #endif
90815- atomic_t bcast_seqno;
90816+ atomic_unchecked_t bcast_seqno;
90817 atomic_t bcast_queue_left;
90818 atomic_t batman_queue_left;
90819 char num_ifaces;
90820diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90821index 857e1b8..5ad07b2 100644
90822--- a/net/batman-adv/unicast.c
90823+++ b/net/batman-adv/unicast.c
90824@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90825 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90826 frag2->flags = large_tail;
90827
90828- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90829+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90830 frag1->seqno = htons(seqno - 1);
90831 frag2->seqno = htons(seqno);
90832
90833diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90834index 9bd7d95..6c4884f 100644
90835--- a/net/bluetooth/hci_sock.c
90836+++ b/net/bluetooth/hci_sock.c
90837@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90838 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90839 }
90840
90841- len = min_t(unsigned int, len, sizeof(uf));
90842+ len = min((size_t)len, sizeof(uf));
90843 if (copy_from_user(&uf, optval, len)) {
90844 err = -EFAULT;
90845 break;
90846diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90847index 8c3499b..2661c6a 100644
90848--- a/net/bluetooth/l2cap_core.c
90849+++ b/net/bluetooth/l2cap_core.c
90850@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90851 break;
90852
90853 case L2CAP_CONF_RFC:
90854- if (olen == sizeof(rfc))
90855- memcpy(&rfc, (void *)val, olen);
90856+ if (olen != sizeof(rfc))
90857+ break;
90858+
90859+ memcpy(&rfc, (void *)val, olen);
90860
90861 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90862 rfc.mode != chan->mode)
90863diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90864index 0098af8..fb5a31f 100644
90865--- a/net/bluetooth/l2cap_sock.c
90866+++ b/net/bluetooth/l2cap_sock.c
90867@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90868 struct sock *sk = sock->sk;
90869 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90870 struct l2cap_options opts;
90871- int len, err = 0;
90872+ int err = 0;
90873+ size_t len = optlen;
90874 u32 opt;
90875
90876 BT_DBG("sk %p", sk);
90877@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90878 opts.max_tx = chan->max_tx;
90879 opts.txwin_size = chan->tx_win;
90880
90881- len = min_t(unsigned int, sizeof(opts), optlen);
90882+ len = min(sizeof(opts), len);
90883 if (copy_from_user((char *) &opts, optval, len)) {
90884 err = -EFAULT;
90885 break;
90886@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90887 struct bt_security sec;
90888 struct bt_power pwr;
90889 struct l2cap_conn *conn;
90890- int len, err = 0;
90891+ int err = 0;
90892+ size_t len = optlen;
90893 u32 opt;
90894
90895 BT_DBG("sk %p", sk);
90896@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90897
90898 sec.level = BT_SECURITY_LOW;
90899
90900- len = min_t(unsigned int, sizeof(sec), optlen);
90901+ len = min(sizeof(sec), len);
90902 if (copy_from_user((char *) &sec, optval, len)) {
90903 err = -EFAULT;
90904 break;
90905@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90906
90907 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90908
90909- len = min_t(unsigned int, sizeof(pwr), optlen);
90910+ len = min(sizeof(pwr), len);
90911 if (copy_from_user((char *) &pwr, optval, len)) {
90912 err = -EFAULT;
90913 break;
90914diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90915index 30b3721..c1bd0a0 100644
90916--- a/net/bluetooth/rfcomm/sock.c
90917+++ b/net/bluetooth/rfcomm/sock.c
90918@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90919 struct sock *sk = sock->sk;
90920 struct bt_security sec;
90921 int err = 0;
90922- size_t len;
90923+ size_t len = optlen;
90924 u32 opt;
90925
90926 BT_DBG("sk %p", sk);
90927@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90928
90929 sec.level = BT_SECURITY_LOW;
90930
90931- len = min_t(unsigned int, sizeof(sec), optlen);
90932+ len = min(sizeof(sec), len);
90933 if (copy_from_user((char *) &sec, optval, len)) {
90934 err = -EFAULT;
90935 break;
90936diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
90937index b6e44ad..5b0d514 100644
90938--- a/net/bluetooth/rfcomm/tty.c
90939+++ b/net/bluetooth/rfcomm/tty.c
90940@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
90941 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
90942
90943 spin_lock_irqsave(&dev->port.lock, flags);
90944- if (dev->port.count > 0) {
90945+ if (atomic_read(&dev->port.count) > 0) {
90946 spin_unlock_irqrestore(&dev->port.lock, flags);
90947 return;
90948 }
90949@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
90950 return -ENODEV;
90951
90952 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
90953- dev->channel, dev->port.count);
90954+ dev->channel, atomic_read(&dev->port.count));
90955
90956 spin_lock_irqsave(&dev->port.lock, flags);
90957- if (++dev->port.count > 1) {
90958+ if (atomic_inc_return(&dev->port.count) > 1) {
90959 spin_unlock_irqrestore(&dev->port.lock, flags);
90960 return 0;
90961 }
90962@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
90963 return;
90964
90965 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
90966- dev->port.count);
90967+ atomic_read(&dev->port.count));
90968
90969 spin_lock_irqsave(&dev->port.lock, flags);
90970- if (!--dev->port.count) {
90971+ if (!atomic_dec_return(&dev->port.count)) {
90972 spin_unlock_irqrestore(&dev->port.lock, flags);
90973 if (dev->tty_dev->parent)
90974 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
90975diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
90976index 5180938..7c470c3 100644
90977--- a/net/bridge/netfilter/ebt_ulog.c
90978+++ b/net/bridge/netfilter/ebt_ulog.c
90979@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90980 ub->qlen++;
90981
90982 pm = nlmsg_data(nlh);
90983+ memset(pm, 0, sizeof(*pm));
90984
90985 /* Fill in the ulog data */
90986 pm->version = EBT_ULOG_VERSION;
90987@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90988 pm->hook = hooknr;
90989 if (uloginfo->prefix != NULL)
90990 strcpy(pm->prefix, uloginfo->prefix);
90991- else
90992- *(pm->prefix) = '\0';
90993
90994 if (in) {
90995 strcpy(pm->physindev, in->name);
90996@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
90997 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
90998 else
90999 strcpy(pm->indev, in->name);
91000- } else
91001- pm->indev[0] = pm->physindev[0] = '\0';
91002+ }
91003
91004 if (out) {
91005 /* If out exists, then out is a bridge port */
91006 strcpy(pm->physoutdev, out->name);
91007 /* rcu_read_lock()ed by nf_hook_slow */
91008 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
91009- } else
91010- pm->outdev[0] = pm->physoutdev[0] = '\0';
91011+ }
91012
91013 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
91014 BUG();
91015diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91016index ac78024..161a80c 100644
91017--- a/net/bridge/netfilter/ebtables.c
91018+++ b/net/bridge/netfilter/ebtables.c
91019@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91020 tmp.valid_hooks = t->table->valid_hooks;
91021 }
91022 mutex_unlock(&ebt_mutex);
91023- if (copy_to_user(user, &tmp, *len) != 0){
91024+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91025 BUGPRINT("c2u Didn't work\n");
91026 ret = -EFAULT;
91027 break;
91028@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91029 goto out;
91030 tmp.valid_hooks = t->valid_hooks;
91031
91032- if (copy_to_user(user, &tmp, *len) != 0) {
91033+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91034 ret = -EFAULT;
91035 break;
91036 }
91037@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91038 tmp.entries_size = t->table->entries_size;
91039 tmp.valid_hooks = t->table->valid_hooks;
91040
91041- if (copy_to_user(user, &tmp, *len) != 0) {
91042+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91043 ret = -EFAULT;
91044 break;
91045 }
91046diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91047index 0f45522..dab651f 100644
91048--- a/net/caif/cfctrl.c
91049+++ b/net/caif/cfctrl.c
91050@@ -10,6 +10,7 @@
91051 #include <linux/spinlock.h>
91052 #include <linux/slab.h>
91053 #include <linux/pkt_sched.h>
91054+#include <linux/sched.h>
91055 #include <net/caif/caif_layer.h>
91056 #include <net/caif/cfpkt.h>
91057 #include <net/caif/cfctrl.h>
91058@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91059 memset(&dev_info, 0, sizeof(dev_info));
91060 dev_info.id = 0xff;
91061 cfsrvl_init(&this->serv, 0, &dev_info, false);
91062- atomic_set(&this->req_seq_no, 1);
91063- atomic_set(&this->rsp_seq_no, 1);
91064+ atomic_set_unchecked(&this->req_seq_no, 1);
91065+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91066 this->serv.layer.receive = cfctrl_recv;
91067 sprintf(this->serv.layer.name, "ctrl");
91068 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91069@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91070 struct cfctrl_request_info *req)
91071 {
91072 spin_lock_bh(&ctrl->info_list_lock);
91073- atomic_inc(&ctrl->req_seq_no);
91074- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91075+ atomic_inc_unchecked(&ctrl->req_seq_no);
91076+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91077 list_add_tail(&req->list, &ctrl->list);
91078 spin_unlock_bh(&ctrl->info_list_lock);
91079 }
91080@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91081 if (p != first)
91082 pr_warn("Requests are not received in order\n");
91083
91084- atomic_set(&ctrl->rsp_seq_no,
91085+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91086 p->sequence_no);
91087 list_del(&p->list);
91088 goto out;
91089diff --git a/net/can/af_can.c b/net/can/af_can.c
91090index 3ab8dd2..b9aef13 100644
91091--- a/net/can/af_can.c
91092+++ b/net/can/af_can.c
91093@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91094 };
91095
91096 /* notifier block for netdevice event */
91097-static struct notifier_block can_netdev_notifier __read_mostly = {
91098+static struct notifier_block can_netdev_notifier = {
91099 .notifier_call = can_notifier,
91100 };
91101
91102diff --git a/net/can/gw.c b/net/can/gw.c
91103index 2f291f9..98c986a 100644
91104--- a/net/can/gw.c
91105+++ b/net/can/gw.c
91106@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91107 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91108
91109 static HLIST_HEAD(cgw_list);
91110-static struct notifier_block notifier;
91111
91112 static struct kmem_cache *cgw_cache __read_mostly;
91113
91114@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91115 return err;
91116 }
91117
91118+static struct notifier_block notifier = {
91119+ .notifier_call = cgw_notifier
91120+};
91121+
91122 static __init int cgw_module_init(void)
91123 {
91124 /* sanitize given module parameter */
91125@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91126 return -ENOMEM;
91127
91128 /* set notifier */
91129- notifier.notifier_call = cgw_notifier;
91130 register_netdevice_notifier(&notifier);
91131
91132 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91133diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91134index eb0a46a..5f3bae8 100644
91135--- a/net/ceph/messenger.c
91136+++ b/net/ceph/messenger.c
91137@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91138 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91139
91140 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91141-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91142+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91143
91144 static struct page *zero_page; /* used in certain error cases */
91145
91146@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91147 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91148 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91149
91150- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91151+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91152 s = addr_str[i];
91153
91154 switch (ss->ss_family) {
91155diff --git a/net/compat.c b/net/compat.c
91156index f0a1ba6..0541331 100644
91157--- a/net/compat.c
91158+++ b/net/compat.c
91159@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91160 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91161 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91162 return -EFAULT;
91163- kmsg->msg_name = compat_ptr(tmp1);
91164- kmsg->msg_iov = compat_ptr(tmp2);
91165- kmsg->msg_control = compat_ptr(tmp3);
91166+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91167+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91168+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91169 return 0;
91170 }
91171
91172@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91173
91174 if (kern_msg->msg_namelen) {
91175 if (mode == VERIFY_READ) {
91176- int err = move_addr_to_kernel(kern_msg->msg_name,
91177+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91178 kern_msg->msg_namelen,
91179 kern_address);
91180 if (err < 0)
91181@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91182 kern_msg->msg_name = NULL;
91183
91184 tot_len = iov_from_user_compat_to_kern(kern_iov,
91185- (struct compat_iovec __user *)kern_msg->msg_iov,
91186+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91187 kern_msg->msg_iovlen);
91188 if (tot_len >= 0)
91189 kern_msg->msg_iov = kern_iov;
91190@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91191
91192 #define CMSG_COMPAT_FIRSTHDR(msg) \
91193 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91194- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91195+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91196 (struct compat_cmsghdr __user *)NULL)
91197
91198 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91199 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91200 (ucmlen) <= (unsigned long) \
91201 ((mhdr)->msg_controllen - \
91202- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91203+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91204
91205 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91206 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91207 {
91208 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91209- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91210+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91211 msg->msg_controllen)
91212 return NULL;
91213 return (struct compat_cmsghdr __user *)ptr;
91214@@ -219,7 +219,7 @@ Efault:
91215
91216 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91217 {
91218- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91219+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91220 struct compat_cmsghdr cmhdr;
91221 struct compat_timeval ctv;
91222 struct compat_timespec cts[3];
91223@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91224
91225 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91226 {
91227- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91228+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91229 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91230 int fdnum = scm->fp->count;
91231 struct file **fp = scm->fp->fp;
91232@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91233 return -EFAULT;
91234 old_fs = get_fs();
91235 set_fs(KERNEL_DS);
91236- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91237+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91238 set_fs(old_fs);
91239
91240 return err;
91241@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91242 len = sizeof(ktime);
91243 old_fs = get_fs();
91244 set_fs(KERNEL_DS);
91245- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91246+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91247 set_fs(old_fs);
91248
91249 if (!err) {
91250@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91251 case MCAST_JOIN_GROUP:
91252 case MCAST_LEAVE_GROUP:
91253 {
91254- struct compat_group_req __user *gr32 = (void *)optval;
91255+ struct compat_group_req __user *gr32 = (void __user *)optval;
91256 struct group_req __user *kgr =
91257 compat_alloc_user_space(sizeof(struct group_req));
91258 u32 interface;
91259@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91260 case MCAST_BLOCK_SOURCE:
91261 case MCAST_UNBLOCK_SOURCE:
91262 {
91263- struct compat_group_source_req __user *gsr32 = (void *)optval;
91264+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91265 struct group_source_req __user *kgsr = compat_alloc_user_space(
91266 sizeof(struct group_source_req));
91267 u32 interface;
91268@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91269 }
91270 case MCAST_MSFILTER:
91271 {
91272- struct compat_group_filter __user *gf32 = (void *)optval;
91273+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91274 struct group_filter __user *kgf;
91275 u32 interface, fmode, numsrc;
91276
91277@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91278 char __user *optval, int __user *optlen,
91279 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91280 {
91281- struct compat_group_filter __user *gf32 = (void *)optval;
91282+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91283 struct group_filter __user *kgf;
91284 int __user *koptlen;
91285 u32 interface, fmode, numsrc;
91286@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91287
91288 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91289 return -EINVAL;
91290- if (copy_from_user(a, args, nas[call]))
91291+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91292 return -EFAULT;
91293 a0 = a[0];
91294 a1 = a[1];
91295diff --git a/net/core/datagram.c b/net/core/datagram.c
91296index 8ab48cd..57b1a80 100644
91297--- a/net/core/datagram.c
91298+++ b/net/core/datagram.c
91299@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91300 }
91301
91302 kfree_skb(skb);
91303- atomic_inc(&sk->sk_drops);
91304+ atomic_inc_unchecked(&sk->sk_drops);
91305 sk_mem_reclaim_partial(sk);
91306
91307 return err;
91308diff --git a/net/core/dev.c b/net/core/dev.c
91309index 26755dd..2a232de 100644
91310--- a/net/core/dev.c
91311+++ b/net/core/dev.c
91312@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91313 {
91314 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91315 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91316- atomic_long_inc(&dev->rx_dropped);
91317+ atomic_long_inc_unchecked(&dev->rx_dropped);
91318 kfree_skb(skb);
91319 return NET_RX_DROP;
91320 }
91321 }
91322
91323 if (unlikely(!is_skb_forwardable(dev, skb))) {
91324- atomic_long_inc(&dev->rx_dropped);
91325+ atomic_long_inc_unchecked(&dev->rx_dropped);
91326 kfree_skb(skb);
91327 return NET_RX_DROP;
91328 }
91329@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91330
91331 struct dev_gso_cb {
91332 void (*destructor)(struct sk_buff *skb);
91333-};
91334+} __no_const;
91335
91336 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91337
91338@@ -3206,7 +3206,7 @@ enqueue:
91339
91340 local_irq_restore(flags);
91341
91342- atomic_long_inc(&skb->dev->rx_dropped);
91343+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91344 kfree_skb(skb);
91345 return NET_RX_DROP;
91346 }
91347@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91348 }
91349 EXPORT_SYMBOL(netif_rx_ni);
91350
91351-static void net_tx_action(struct softirq_action *h)
91352+static __latent_entropy void net_tx_action(void)
91353 {
91354 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91355
91356@@ -3612,7 +3612,7 @@ ncls:
91357 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91358 } else {
91359 drop:
91360- atomic_long_inc(&skb->dev->rx_dropped);
91361+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91362 kfree_skb(skb);
91363 /* Jamal, now you will not able to escape explaining
91364 * me how you were going to use this. :-)
91365@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91366 }
91367 EXPORT_SYMBOL(netif_napi_del);
91368
91369-static void net_rx_action(struct softirq_action *h)
91370+static __latent_entropy void net_rx_action(void)
91371 {
91372 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91373 unsigned long time_limit = jiffies + 2;
91374@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91375 } else {
91376 netdev_stats_to_stats64(storage, &dev->stats);
91377 }
91378- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91379+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91380 return storage;
91381 }
91382 EXPORT_SYMBOL(dev_get_stats);
91383diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91384index 5b7d0e1..cb960fc 100644
91385--- a/net/core/dev_ioctl.c
91386+++ b/net/core/dev_ioctl.c
91387@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91388 if (no_module && capable(CAP_NET_ADMIN))
91389 no_module = request_module("netdev-%s", name);
91390 if (no_module && capable(CAP_SYS_MODULE)) {
91391+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91392+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91393+#else
91394 if (!request_module("%s", name))
91395 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91396 name);
91397+#endif
91398 }
91399 }
91400 EXPORT_SYMBOL(dev_load);
91401diff --git a/net/core/flow.c b/net/core/flow.c
91402index dfa602c..3103d88 100644
91403--- a/net/core/flow.c
91404+++ b/net/core/flow.c
91405@@ -61,7 +61,7 @@ struct flow_cache {
91406 struct timer_list rnd_timer;
91407 };
91408
91409-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91410+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91411 EXPORT_SYMBOL(flow_cache_genid);
91412 static struct flow_cache flow_cache_global;
91413 static struct kmem_cache *flow_cachep __read_mostly;
91414@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91415
91416 static int flow_entry_valid(struct flow_cache_entry *fle)
91417 {
91418- if (atomic_read(&flow_cache_genid) != fle->genid)
91419+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91420 return 0;
91421 if (fle->object && !fle->object->ops->check(fle->object))
91422 return 0;
91423@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91424 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91425 fcp->hash_count++;
91426 }
91427- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91428+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91429 flo = fle->object;
91430 if (!flo)
91431 goto ret_object;
91432@@ -279,7 +279,7 @@ nocache:
91433 }
91434 flo = resolver(net, key, family, dir, flo, ctx);
91435 if (fle) {
91436- fle->genid = atomic_read(&flow_cache_genid);
91437+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91438 if (!IS_ERR(flo))
91439 fle->object = flo;
91440 else
91441diff --git a/net/core/iovec.c b/net/core/iovec.c
91442index de178e4..1dabd8b 100644
91443--- a/net/core/iovec.c
91444+++ b/net/core/iovec.c
91445@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91446 if (m->msg_namelen) {
91447 if (mode == VERIFY_READ) {
91448 void __user *namep;
91449- namep = (void __user __force *) m->msg_name;
91450+ namep = (void __force_user *) m->msg_name;
91451 err = move_addr_to_kernel(namep, m->msg_namelen,
91452 address);
91453 if (err < 0)
91454@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91455 }
91456
91457 size = m->msg_iovlen * sizeof(struct iovec);
91458- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91459+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91460 return -EFAULT;
91461
91462 m->msg_iov = iov;
91463diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91464index 60533db..14842cc 100644
91465--- a/net/core/neighbour.c
91466+++ b/net/core/neighbour.c
91467@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91468 void __user *buffer, size_t *lenp, loff_t *ppos)
91469 {
91470 int size, ret;
91471- struct ctl_table tmp = *ctl;
91472+ ctl_table_no_const tmp = *ctl;
91473
91474 tmp.extra1 = &zero;
91475 tmp.extra2 = &unres_qlen_max;
91476diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91477index 2bf8329..7960607 100644
91478--- a/net/core/net-procfs.c
91479+++ b/net/core/net-procfs.c
91480@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91481 else
91482 seq_printf(seq, "%04x", ntohs(pt->type));
91483
91484+#ifdef CONFIG_GRKERNSEC_HIDESYM
91485+ seq_printf(seq, " %-8s %pf\n",
91486+ pt->dev ? pt->dev->name : "", NULL);
91487+#else
91488 seq_printf(seq, " %-8s %pf\n",
91489 pt->dev ? pt->dev->name : "", pt->func);
91490+#endif
91491 }
91492
91493 return 0;
91494diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91495index 981fed3..536af34 100644
91496--- a/net/core/net-sysfs.c
91497+++ b/net/core/net-sysfs.c
91498@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91499 }
91500 EXPORT_SYMBOL(netdev_class_remove_file);
91501
91502-int netdev_kobject_init(void)
91503+int __init netdev_kobject_init(void)
91504 {
91505 kobj_ns_type_register(&net_ns_type_operations);
91506 return class_register(&net_class);
91507diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91508index f9765203..9feaef8 100644
91509--- a/net/core/net_namespace.c
91510+++ b/net/core/net_namespace.c
91511@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91512 int error;
91513 LIST_HEAD(net_exit_list);
91514
91515- list_add_tail(&ops->list, list);
91516+ pax_list_add_tail((struct list_head *)&ops->list, list);
91517 if (ops->init || (ops->id && ops->size)) {
91518 for_each_net(net) {
91519 error = ops_init(ops, net);
91520@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91521
91522 out_undo:
91523 /* If I have an error cleanup all namespaces I initialized */
91524- list_del(&ops->list);
91525+ pax_list_del((struct list_head *)&ops->list);
91526 ops_exit_list(ops, &net_exit_list);
91527 ops_free_list(ops, &net_exit_list);
91528 return error;
91529@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91530 struct net *net;
91531 LIST_HEAD(net_exit_list);
91532
91533- list_del(&ops->list);
91534+ pax_list_del((struct list_head *)&ops->list);
91535 for_each_net(net)
91536 list_add_tail(&net->exit_list, &net_exit_list);
91537 ops_exit_list(ops, &net_exit_list);
91538@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91539 mutex_lock(&net_mutex);
91540 error = register_pernet_operations(&pernet_list, ops);
91541 if (!error && (first_device == &pernet_list))
91542- first_device = &ops->list;
91543+ first_device = (struct list_head *)&ops->list;
91544 mutex_unlock(&net_mutex);
91545 return error;
91546 }
91547diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91548index fc75c9e..8c8e9be 100644
91549--- a/net/core/netpoll.c
91550+++ b/net/core/netpoll.c
91551@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91552 struct udphdr *udph;
91553 struct iphdr *iph;
91554 struct ethhdr *eth;
91555- static atomic_t ip_ident;
91556+ static atomic_unchecked_t ip_ident;
91557 struct ipv6hdr *ip6h;
91558
91559 udp_len = len + sizeof(*udph);
91560@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91561 put_unaligned(0x45, (unsigned char *)iph);
91562 iph->tos = 0;
91563 put_unaligned(htons(ip_len), &(iph->tot_len));
91564- iph->id = htons(atomic_inc_return(&ip_ident));
91565+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91566 iph->frag_off = 0;
91567 iph->ttl = 64;
91568 iph->protocol = IPPROTO_UDP;
91569diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91570index ca198c1d1..125372f 100644
91571--- a/net/core/rtnetlink.c
91572+++ b/net/core/rtnetlink.c
91573@@ -58,7 +58,7 @@ struct rtnl_link {
91574 rtnl_doit_func doit;
91575 rtnl_dumpit_func dumpit;
91576 rtnl_calcit_func calcit;
91577-};
91578+} __no_const;
91579
91580 static DEFINE_MUTEX(rtnl_mutex);
91581
91582@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91583 if (rtnl_link_ops_get(ops->kind))
91584 return -EEXIST;
91585
91586- if (!ops->dellink)
91587- ops->dellink = unregister_netdevice_queue;
91588+ if (!ops->dellink) {
91589+ pax_open_kernel();
91590+ *(void **)&ops->dellink = unregister_netdevice_queue;
91591+ pax_close_kernel();
91592+ }
91593
91594- list_add_tail(&ops->list, &link_ops);
91595+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91596 return 0;
91597 }
91598 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91599@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91600 for_each_net(net) {
91601 __rtnl_kill_links(net, ops);
91602 }
91603- list_del(&ops->list);
91604+ pax_list_del((struct list_head *)&ops->list);
91605 }
91606 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91607
91608diff --git a/net/core/scm.c b/net/core/scm.c
91609index b4da80b..98d6bdb 100644
91610--- a/net/core/scm.c
91611+++ b/net/core/scm.c
91612@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91613 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91614 {
91615 struct cmsghdr __user *cm
91616- = (__force struct cmsghdr __user *)msg->msg_control;
91617+ = (struct cmsghdr __force_user *)msg->msg_control;
91618 struct cmsghdr cmhdr;
91619 int cmlen = CMSG_LEN(len);
91620 int err;
91621@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91622 err = -EFAULT;
91623 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91624 goto out;
91625- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91626+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91627 goto out;
91628 cmlen = CMSG_SPACE(len);
91629 if (msg->msg_controllen < cmlen)
91630@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91631 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91632 {
91633 struct cmsghdr __user *cm
91634- = (__force struct cmsghdr __user*)msg->msg_control;
91635+ = (struct cmsghdr __force_user *)msg->msg_control;
91636
91637 int fdmax = 0;
91638 int fdnum = scm->fp->count;
91639@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91640 if (fdnum < fdmax)
91641 fdmax = fdnum;
91642
91643- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91644+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91645 i++, cmfptr++)
91646 {
91647 struct socket *sock;
91648diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91649index 2c3d0f5..f5a326f 100644
91650--- a/net/core/skbuff.c
91651+++ b/net/core/skbuff.c
91652@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91653 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91654 sizeof(struct sk_buff),
91655 0,
91656- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91657+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91658+ SLAB_NO_SANITIZE,
91659 NULL);
91660 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91661 (2*sizeof(struct sk_buff)) +
91662 sizeof(atomic_t),
91663 0,
91664- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91665+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91666+ SLAB_NO_SANITIZE,
91667 NULL);
91668 }
91669
91670diff --git a/net/core/sock.c b/net/core/sock.c
91671index 2c097c5..bf72858 100644
91672--- a/net/core/sock.c
91673+++ b/net/core/sock.c
91674@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91675 struct sk_buff_head *list = &sk->sk_receive_queue;
91676
91677 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91678- atomic_inc(&sk->sk_drops);
91679+ atomic_inc_unchecked(&sk->sk_drops);
91680 trace_sock_rcvqueue_full(sk, skb);
91681 return -ENOMEM;
91682 }
91683@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91684 return err;
91685
91686 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91687- atomic_inc(&sk->sk_drops);
91688+ atomic_inc_unchecked(&sk->sk_drops);
91689 return -ENOBUFS;
91690 }
91691
91692@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91693 skb_dst_force(skb);
91694
91695 spin_lock_irqsave(&list->lock, flags);
91696- skb->dropcount = atomic_read(&sk->sk_drops);
91697+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91698 __skb_queue_tail(list, skb);
91699 spin_unlock_irqrestore(&list->lock, flags);
91700
91701@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91702 skb->dev = NULL;
91703
91704 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91705- atomic_inc(&sk->sk_drops);
91706+ atomic_inc_unchecked(&sk->sk_drops);
91707 goto discard_and_relse;
91708 }
91709 if (nested)
91710@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91711 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91712 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91713 bh_unlock_sock(sk);
91714- atomic_inc(&sk->sk_drops);
91715+ atomic_inc_unchecked(&sk->sk_drops);
91716 goto discard_and_relse;
91717 }
91718
91719@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91720 struct timeval tm;
91721 } v;
91722
91723- int lv = sizeof(int);
91724- int len;
91725+ unsigned int lv = sizeof(int);
91726+ unsigned int len;
91727
91728 if (get_user(len, optlen))
91729 return -EFAULT;
91730- if (len < 0)
91731+ if (len > INT_MAX)
91732 return -EINVAL;
91733
91734 memset(&v, 0, sizeof(v));
91735@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91736
91737 case SO_PEERNAME:
91738 {
91739- char address[128];
91740+ char address[_K_SS_MAXSIZE];
91741
91742 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91743 return -ENOTCONN;
91744- if (lv < len)
91745+ if (lv < len || sizeof address < len)
91746 return -EINVAL;
91747 if (copy_to_user(optval, address, len))
91748 return -EFAULT;
91749@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91750
91751 if (len > lv)
91752 len = lv;
91753- if (copy_to_user(optval, &v, len))
91754+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91755 return -EFAULT;
91756 lenout:
91757 if (put_user(len, optlen))
91758@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91759 */
91760 smp_wmb();
91761 atomic_set(&sk->sk_refcnt, 1);
91762- atomic_set(&sk->sk_drops, 0);
91763+ atomic_set_unchecked(&sk->sk_drops, 0);
91764 }
91765 EXPORT_SYMBOL(sock_init_data);
91766
91767diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91768index a0e9cf6..ef7f9ed 100644
91769--- a/net/core/sock_diag.c
91770+++ b/net/core/sock_diag.c
91771@@ -9,26 +9,33 @@
91772 #include <linux/inet_diag.h>
91773 #include <linux/sock_diag.h>
91774
91775-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91776+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91777 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91778 static DEFINE_MUTEX(sock_diag_table_mutex);
91779
91780 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91781 {
91782+#ifndef CONFIG_GRKERNSEC_HIDESYM
91783 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91784 cookie[1] != INET_DIAG_NOCOOKIE) &&
91785 ((u32)(unsigned long)sk != cookie[0] ||
91786 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91787 return -ESTALE;
91788 else
91789+#endif
91790 return 0;
91791 }
91792 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91793
91794 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91795 {
91796+#ifdef CONFIG_GRKERNSEC_HIDESYM
91797+ cookie[0] = 0;
91798+ cookie[1] = 0;
91799+#else
91800 cookie[0] = (u32)(unsigned long)sk;
91801 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91802+#endif
91803 }
91804 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91805
91806@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91807 mutex_lock(&sock_diag_table_mutex);
91808 if (sock_diag_handlers[hndl->family])
91809 err = -EBUSY;
91810- else
91811+ else {
91812+ pax_open_kernel();
91813 sock_diag_handlers[hndl->family] = hndl;
91814+ pax_close_kernel();
91815+ }
91816 mutex_unlock(&sock_diag_table_mutex);
91817
91818 return err;
91819@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91820
91821 mutex_lock(&sock_diag_table_mutex);
91822 BUG_ON(sock_diag_handlers[family] != hnld);
91823+ pax_open_kernel();
91824 sock_diag_handlers[family] = NULL;
91825+ pax_close_kernel();
91826 mutex_unlock(&sock_diag_table_mutex);
91827 }
91828 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91829diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91830index 31107ab..ae03d5a 100644
91831--- a/net/core/sysctl_net_core.c
91832+++ b/net/core/sysctl_net_core.c
91833@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91834 {
91835 unsigned int orig_size, size;
91836 int ret, i;
91837- struct ctl_table tmp = {
91838+ ctl_table_no_const tmp = {
91839 .data = &size,
91840 .maxlen = sizeof(size),
91841 .mode = table->mode
91842@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91843
91844 static __net_init int sysctl_core_net_init(struct net *net)
91845 {
91846- struct ctl_table *tbl;
91847+ ctl_table_no_const *tbl = NULL;
91848
91849 net->core.sysctl_somaxconn = SOMAXCONN;
91850
91851- tbl = netns_core_table;
91852 if (!net_eq(net, &init_net)) {
91853- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91854+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91855 if (tbl == NULL)
91856 goto err_dup;
91857
91858@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91859 if (net->user_ns != &init_user_ns) {
91860 tbl[0].procname = NULL;
91861 }
91862- }
91863-
91864- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91865+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91866+ } else
91867+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91868 if (net->core.sysctl_hdr == NULL)
91869 goto err_reg;
91870
91871 return 0;
91872
91873 err_reg:
91874- if (tbl != netns_core_table)
91875- kfree(tbl);
91876+ kfree(tbl);
91877 err_dup:
91878 return -ENOMEM;
91879 }
91880@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91881 kfree(tbl);
91882 }
91883
91884-static __net_initdata struct pernet_operations sysctl_core_ops = {
91885+static __net_initconst struct pernet_operations sysctl_core_ops = {
91886 .init = sysctl_core_net_init,
91887 .exit = sysctl_core_net_exit,
91888 };
91889diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91890index dd4d506..fb2fb87 100644
91891--- a/net/decnet/af_decnet.c
91892+++ b/net/decnet/af_decnet.c
91893@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91894 .sysctl_rmem = sysctl_decnet_rmem,
91895 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91896 .obj_size = sizeof(struct dn_sock),
91897+ .slab_flags = SLAB_USERCOPY,
91898 };
91899
91900 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91901diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91902index 5325b54..a0d4d69 100644
91903--- a/net/decnet/sysctl_net_decnet.c
91904+++ b/net/decnet/sysctl_net_decnet.c
91905@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91906
91907 if (len > *lenp) len = *lenp;
91908
91909- if (copy_to_user(buffer, addr, len))
91910+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91911 return -EFAULT;
91912
91913 *lenp = len;
91914@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91915
91916 if (len > *lenp) len = *lenp;
91917
91918- if (copy_to_user(buffer, devname, len))
91919+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91920 return -EFAULT;
91921
91922 *lenp = len;
91923diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91924index 3b9d5f2..d7015c6 100644
91925--- a/net/ieee802154/6lowpan.c
91926+++ b/net/ieee802154/6lowpan.c
91927@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91928 hc06_ptr += 3;
91929 } else {
91930 /* compress nothing */
91931- memcpy(hc06_ptr, &hdr, 4);
91932+ memcpy(hc06_ptr, hdr, 4);
91933 /* replace the top byte with new ECN | DSCP format */
91934 *hc06_ptr = tmp;
91935 hc06_ptr += 4;
91936diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91937index dd6b523..dfe558f 100644
91938--- a/net/ipv4/af_inet.c
91939+++ b/net/ipv4/af_inet.c
91940@@ -1687,13 +1687,9 @@ static int __init inet_init(void)
91941
91942 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91943
91944- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91945- if (!sysctl_local_reserved_ports)
91946- goto out;
91947-
91948 rc = proto_register(&tcp_prot, 1);
91949 if (rc)
91950- goto out_free_reserved_ports;
91951+ goto out;
91952
91953 rc = proto_register(&udp_prot, 1);
91954 if (rc)
91955@@ -1802,8 +1798,6 @@ out_unregister_udp_proto:
91956 proto_unregister(&udp_prot);
91957 out_unregister_tcp_proto:
91958 proto_unregister(&tcp_prot);
91959-out_free_reserved_ports:
91960- kfree(sysctl_local_reserved_ports);
91961 goto out;
91962 }
91963
91964diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
91965index 34ca6d5..b6421e8 100644
91966--- a/net/ipv4/devinet.c
91967+++ b/net/ipv4/devinet.c
91968@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
91969 idx = 0;
91970 head = &net->dev_index_head[h];
91971 rcu_read_lock();
91972- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91973+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91974 net->dev_base_seq;
91975 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91976 if (idx < s_idx)
91977@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
91978 idx = 0;
91979 head = &net->dev_index_head[h];
91980 rcu_read_lock();
91981- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91982+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91983 net->dev_base_seq;
91984 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91985 if (idx < s_idx)
91986@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
91987 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
91988 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
91989
91990-static struct devinet_sysctl_table {
91991+static const struct devinet_sysctl_table {
91992 struct ctl_table_header *sysctl_header;
91993 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
91994 } devinet_sysctl = {
91995@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
91996 int err;
91997 struct ipv4_devconf *all, *dflt;
91998 #ifdef CONFIG_SYSCTL
91999- struct ctl_table *tbl = ctl_forward_entry;
92000+ ctl_table_no_const *tbl = NULL;
92001 struct ctl_table_header *forw_hdr;
92002 #endif
92003
92004@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92005 goto err_alloc_dflt;
92006
92007 #ifdef CONFIG_SYSCTL
92008- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92009+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92010 if (tbl == NULL)
92011 goto err_alloc_ctl;
92012
92013@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92014 goto err_reg_dflt;
92015
92016 err = -ENOMEM;
92017- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92018+ if (!net_eq(net, &init_net))
92019+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92020+ else
92021+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92022 if (forw_hdr == NULL)
92023 goto err_reg_ctl;
92024 net->ipv4.forw_hdr = forw_hdr;
92025@@ -2240,8 +2243,7 @@ err_reg_ctl:
92026 err_reg_dflt:
92027 __devinet_sysctl_unregister(all);
92028 err_reg_all:
92029- if (tbl != ctl_forward_entry)
92030- kfree(tbl);
92031+ kfree(tbl);
92032 err_alloc_ctl:
92033 #endif
92034 if (dflt != &ipv4_devconf_dflt)
92035diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92036index b3f627a..b0f3e99 100644
92037--- a/net/ipv4/fib_frontend.c
92038+++ b/net/ipv4/fib_frontend.c
92039@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92040 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92041 fib_sync_up(dev);
92042 #endif
92043- atomic_inc(&net->ipv4.dev_addr_genid);
92044+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92045 rt_cache_flush(dev_net(dev));
92046 break;
92047 case NETDEV_DOWN:
92048 fib_del_ifaddr(ifa, NULL);
92049- atomic_inc(&net->ipv4.dev_addr_genid);
92050+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92051 if (ifa->ifa_dev->ifa_list == NULL) {
92052 /* Last address was deleted from this interface.
92053 * Disable IP.
92054@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92055 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92056 fib_sync_up(dev);
92057 #endif
92058- atomic_inc(&net->ipv4.dev_addr_genid);
92059+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92060 rt_cache_flush(net);
92061 break;
92062 case NETDEV_DOWN:
92063diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92064index d5dbca5..6251d5f 100644
92065--- a/net/ipv4/fib_semantics.c
92066+++ b/net/ipv4/fib_semantics.c
92067@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92068 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92069 nh->nh_gw,
92070 nh->nh_parent->fib_scope);
92071- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92072+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92073
92074 return nh->nh_saddr;
92075 }
92076diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92077index 6acb541..9ea617d 100644
92078--- a/net/ipv4/inet_connection_sock.c
92079+++ b/net/ipv4/inet_connection_sock.c
92080@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92081 .range = { 32768, 61000 },
92082 };
92083
92084-unsigned long *sysctl_local_reserved_ports;
92085+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92086 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92087
92088 void inet_get_local_port_range(int *low, int *high)
92089diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92090index 7bd8983..3abdcf6 100644
92091--- a/net/ipv4/inet_hashtables.c
92092+++ b/net/ipv4/inet_hashtables.c
92093@@ -18,12 +18,15 @@
92094 #include <linux/sched.h>
92095 #include <linux/slab.h>
92096 #include <linux/wait.h>
92097+#include <linux/security.h>
92098
92099 #include <net/inet_connection_sock.h>
92100 #include <net/inet_hashtables.h>
92101 #include <net/secure_seq.h>
92102 #include <net/ip.h>
92103
92104+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92105+
92106 /*
92107 * Allocate and initialize a new local port bind bucket.
92108 * The bindhash mutex for snum's hash chain must be held here.
92109@@ -554,6 +557,8 @@ ok:
92110 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92111 spin_unlock(&head->lock);
92112
92113+ gr_update_task_in_ip_table(current, inet_sk(sk));
92114+
92115 if (tw) {
92116 inet_twsk_deschedule(tw, death_row);
92117 while (twrefcnt) {
92118diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92119index 33d5537..da337a4 100644
92120--- a/net/ipv4/inetpeer.c
92121+++ b/net/ipv4/inetpeer.c
92122@@ -503,8 +503,8 @@ relookup:
92123 if (p) {
92124 p->daddr = *daddr;
92125 atomic_set(&p->refcnt, 1);
92126- atomic_set(&p->rid, 0);
92127- atomic_set(&p->ip_id_count,
92128+ atomic_set_unchecked(&p->rid, 0);
92129+ atomic_set_unchecked(&p->ip_id_count,
92130 (daddr->family == AF_INET) ?
92131 secure_ip_id(daddr->addr.a4) :
92132 secure_ipv6_id(daddr->addr.a6));
92133diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92134index b66910a..cfe416e 100644
92135--- a/net/ipv4/ip_fragment.c
92136+++ b/net/ipv4/ip_fragment.c
92137@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92138 return 0;
92139
92140 start = qp->rid;
92141- end = atomic_inc_return(&peer->rid);
92142+ end = atomic_inc_return_unchecked(&peer->rid);
92143 qp->rid = end;
92144
92145 rc = qp->q.fragments && (end - start) > max;
92146@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92147
92148 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92149 {
92150- struct ctl_table *table;
92151+ ctl_table_no_const *table = NULL;
92152 struct ctl_table_header *hdr;
92153
92154- table = ip4_frags_ns_ctl_table;
92155 if (!net_eq(net, &init_net)) {
92156- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92157+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92158 if (table == NULL)
92159 goto err_alloc;
92160
92161@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92162 /* Don't export sysctls to unprivileged users */
92163 if (net->user_ns != &init_user_ns)
92164 table[0].procname = NULL;
92165- }
92166+ hdr = register_net_sysctl(net, "net/ipv4", table);
92167+ } else
92168+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92169
92170- hdr = register_net_sysctl(net, "net/ipv4", table);
92171 if (hdr == NULL)
92172 goto err_reg;
92173
92174@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92175 return 0;
92176
92177 err_reg:
92178- if (!net_eq(net, &init_net))
92179- kfree(table);
92180+ kfree(table);
92181 err_alloc:
92182 return -ENOMEM;
92183 }
92184diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92185index 8d6939e..19d0a95 100644
92186--- a/net/ipv4/ip_gre.c
92187+++ b/net/ipv4/ip_gre.c
92188@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92189 module_param(log_ecn_error, bool, 0644);
92190 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92191
92192-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92193+static struct rtnl_link_ops ipgre_link_ops;
92194 static int ipgre_tunnel_init(struct net_device *dev);
92195
92196 static int ipgre_net_id __read_mostly;
92197@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92198 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92199 };
92200
92201-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92202+static struct rtnl_link_ops ipgre_link_ops = {
92203 .kind = "gre",
92204 .maxtype = IFLA_GRE_MAX,
92205 .policy = ipgre_policy,
92206@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92207 .fill_info = ipgre_fill_info,
92208 };
92209
92210-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92211+static struct rtnl_link_ops ipgre_tap_ops = {
92212 .kind = "gretap",
92213 .maxtype = IFLA_GRE_MAX,
92214 .policy = ipgre_policy,
92215diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92216index d9c4f11..02b82dbc 100644
92217--- a/net/ipv4/ip_sockglue.c
92218+++ b/net/ipv4/ip_sockglue.c
92219@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92220 len = min_t(unsigned int, len, opt->optlen);
92221 if (put_user(len, optlen))
92222 return -EFAULT;
92223- if (copy_to_user(optval, opt->__data, len))
92224+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92225+ copy_to_user(optval, opt->__data, len))
92226 return -EFAULT;
92227 return 0;
92228 }
92229@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92230 if (sk->sk_type != SOCK_STREAM)
92231 return -ENOPROTOOPT;
92232
92233- msg.msg_control = optval;
92234+ msg.msg_control = (void __force_kernel *)optval;
92235 msg.msg_controllen = len;
92236 msg.msg_flags = flags;
92237
92238diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92239index 17cc0ff..63856c4 100644
92240--- a/net/ipv4/ip_vti.c
92241+++ b/net/ipv4/ip_vti.c
92242@@ -47,7 +47,7 @@
92243 #define HASH_SIZE 16
92244 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92245
92246-static struct rtnl_link_ops vti_link_ops __read_mostly;
92247+static struct rtnl_link_ops vti_link_ops;
92248
92249 static int vti_net_id __read_mostly;
92250 struct vti_net {
92251@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92252 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92253 };
92254
92255-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92256+static struct rtnl_link_ops vti_link_ops = {
92257 .kind = "vti",
92258 .maxtype = IFLA_VTI_MAX,
92259 .policy = vti_policy,
92260diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92261index efa1138..20dbba0 100644
92262--- a/net/ipv4/ipconfig.c
92263+++ b/net/ipv4/ipconfig.c
92264@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92265
92266 mm_segment_t oldfs = get_fs();
92267 set_fs(get_ds());
92268- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92269+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92270 set_fs(oldfs);
92271 return res;
92272 }
92273@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92274
92275 mm_segment_t oldfs = get_fs();
92276 set_fs(get_ds());
92277- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92278+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92279 set_fs(oldfs);
92280 return res;
92281 }
92282@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92283
92284 mm_segment_t oldfs = get_fs();
92285 set_fs(get_ds());
92286- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92287+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92288 set_fs(oldfs);
92289 return res;
92290 }
92291diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92292index b3ac3c3..ec6bd95 100644
92293--- a/net/ipv4/ipip.c
92294+++ b/net/ipv4/ipip.c
92295@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92296 static int ipip_net_id __read_mostly;
92297
92298 static int ipip_tunnel_init(struct net_device *dev);
92299-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92300+static struct rtnl_link_ops ipip_link_ops;
92301
92302 static int ipip_err(struct sk_buff *skb, u32 info)
92303 {
92304@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92305 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92306 };
92307
92308-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92309+static struct rtnl_link_ops ipip_link_ops = {
92310 .kind = "ipip",
92311 .maxtype = IFLA_IPTUN_MAX,
92312 .policy = ipip_policy,
92313diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92314index 85a4f21..1beb1f5 100644
92315--- a/net/ipv4/netfilter/arp_tables.c
92316+++ b/net/ipv4/netfilter/arp_tables.c
92317@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92318 #endif
92319
92320 static int get_info(struct net *net, void __user *user,
92321- const int *len, int compat)
92322+ int len, int compat)
92323 {
92324 char name[XT_TABLE_MAXNAMELEN];
92325 struct xt_table *t;
92326 int ret;
92327
92328- if (*len != sizeof(struct arpt_getinfo)) {
92329- duprintf("length %u != %Zu\n", *len,
92330+ if (len != sizeof(struct arpt_getinfo)) {
92331+ duprintf("length %u != %Zu\n", len,
92332 sizeof(struct arpt_getinfo));
92333 return -EINVAL;
92334 }
92335@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92336 info.size = private->size;
92337 strcpy(info.name, name);
92338
92339- if (copy_to_user(user, &info, *len) != 0)
92340+ if (copy_to_user(user, &info, len) != 0)
92341 ret = -EFAULT;
92342 else
92343 ret = 0;
92344@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92345
92346 switch (cmd) {
92347 case ARPT_SO_GET_INFO:
92348- ret = get_info(sock_net(sk), user, len, 1);
92349+ ret = get_info(sock_net(sk), user, *len, 1);
92350 break;
92351 case ARPT_SO_GET_ENTRIES:
92352 ret = compat_get_entries(sock_net(sk), user, len);
92353@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92354
92355 switch (cmd) {
92356 case ARPT_SO_GET_INFO:
92357- ret = get_info(sock_net(sk), user, len, 0);
92358+ ret = get_info(sock_net(sk), user, *len, 0);
92359 break;
92360
92361 case ARPT_SO_GET_ENTRIES:
92362diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92363index d23118d..6ad7277 100644
92364--- a/net/ipv4/netfilter/ip_tables.c
92365+++ b/net/ipv4/netfilter/ip_tables.c
92366@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92367 #endif
92368
92369 static int get_info(struct net *net, void __user *user,
92370- const int *len, int compat)
92371+ int len, int compat)
92372 {
92373 char name[XT_TABLE_MAXNAMELEN];
92374 struct xt_table *t;
92375 int ret;
92376
92377- if (*len != sizeof(struct ipt_getinfo)) {
92378- duprintf("length %u != %zu\n", *len,
92379+ if (len != sizeof(struct ipt_getinfo)) {
92380+ duprintf("length %u != %zu\n", len,
92381 sizeof(struct ipt_getinfo));
92382 return -EINVAL;
92383 }
92384@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92385 info.size = private->size;
92386 strcpy(info.name, name);
92387
92388- if (copy_to_user(user, &info, *len) != 0)
92389+ if (copy_to_user(user, &info, len) != 0)
92390 ret = -EFAULT;
92391 else
92392 ret = 0;
92393@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92394
92395 switch (cmd) {
92396 case IPT_SO_GET_INFO:
92397- ret = get_info(sock_net(sk), user, len, 1);
92398+ ret = get_info(sock_net(sk), user, *len, 1);
92399 break;
92400 case IPT_SO_GET_ENTRIES:
92401 ret = compat_get_entries(sock_net(sk), user, len);
92402@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92403
92404 switch (cmd) {
92405 case IPT_SO_GET_INFO:
92406- ret = get_info(sock_net(sk), user, len, 0);
92407+ ret = get_info(sock_net(sk), user, *len, 0);
92408 break;
92409
92410 case IPT_SO_GET_ENTRIES:
92411diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
92412index cbc2215..9cb993c 100644
92413--- a/net/ipv4/netfilter/ipt_ULOG.c
92414+++ b/net/ipv4/netfilter/ipt_ULOG.c
92415@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
92416 ub->qlen++;
92417
92418 pm = nlmsg_data(nlh);
92419+ memset(pm, 0, sizeof(*pm));
92420
92421 /* We might not have a timestamp, get one */
92422 if (skb->tstamp.tv64 == 0)
92423@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
92424 }
92425 else if (loginfo->prefix[0] != '\0')
92426 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
92427- else
92428- *(pm->prefix) = '\0';
92429
92430 if (in && in->hard_header_len > 0 &&
92431 skb->mac_header != skb->network_header &&
92432@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
92433
92434 if (in)
92435 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
92436- else
92437- pm->indev_name[0] = '\0';
92438
92439 if (out)
92440 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
92441- else
92442- pm->outdev_name[0] = '\0';
92443
92444 /* copy_len <= skb->len, so can't fail. */
92445 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
92446diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92447index 746427c..80eab72 100644
92448--- a/net/ipv4/ping.c
92449+++ b/net/ipv4/ping.c
92450@@ -55,7 +55,7 @@
92451
92452
92453 struct ping_table ping_table;
92454-struct pingv6_ops pingv6_ops;
92455+struct pingv6_ops *pingv6_ops;
92456 EXPORT_SYMBOL_GPL(pingv6_ops);
92457
92458 static u16 ping_port_rover;
92459@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92460 return -ENODEV;
92461 }
92462 }
92463- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92464+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92465 scoped);
92466 rcu_read_unlock();
92467
92468@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92469 }
92470 #if IS_ENABLED(CONFIG_IPV6)
92471 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92472- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92473+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92474 #endif
92475 }
92476
92477@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92478 info, (u8 *)icmph);
92479 #if IS_ENABLED(CONFIG_IPV6)
92480 } else if (family == AF_INET6) {
92481- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92482+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92483 info, (u8 *)icmph);
92484 #endif
92485 }
92486@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92487 return ip_recv_error(sk, msg, len);
92488 #if IS_ENABLED(CONFIG_IPV6)
92489 } else if (family == AF_INET6) {
92490- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92491+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92492 #endif
92493 }
92494 }
92495@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92496 IP6CB(skb)->iif);
92497
92498 if (inet6_sk(sk)->rxopt.all)
92499- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92500+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92501 #endif
92502 } else {
92503 BUG();
92504@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92505 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92506 0, sock_i_ino(sp),
92507 atomic_read(&sp->sk_refcnt), sp,
92508- atomic_read(&sp->sk_drops), len);
92509+ atomic_read_unchecked(&sp->sk_drops), len);
92510 }
92511
92512 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92513diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92514index 6fb2337..9cd6b20 100644
92515--- a/net/ipv4/raw.c
92516+++ b/net/ipv4/raw.c
92517@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92518 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92519 {
92520 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92521- atomic_inc(&sk->sk_drops);
92522+ atomic_inc_unchecked(&sk->sk_drops);
92523 kfree_skb(skb);
92524 return NET_RX_DROP;
92525 }
92526@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92527
92528 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92529 {
92530+ struct icmp_filter filter;
92531+
92532 if (optlen > sizeof(struct icmp_filter))
92533 optlen = sizeof(struct icmp_filter);
92534- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92535+ if (copy_from_user(&filter, optval, optlen))
92536 return -EFAULT;
92537+ raw_sk(sk)->filter = filter;
92538 return 0;
92539 }
92540
92541 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92542 {
92543 int len, ret = -EFAULT;
92544+ struct icmp_filter filter;
92545
92546 if (get_user(len, optlen))
92547 goto out;
92548@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92549 if (len > sizeof(struct icmp_filter))
92550 len = sizeof(struct icmp_filter);
92551 ret = -EFAULT;
92552- if (put_user(len, optlen) ||
92553- copy_to_user(optval, &raw_sk(sk)->filter, len))
92554+ filter = raw_sk(sk)->filter;
92555+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92556 goto out;
92557 ret = 0;
92558 out: return ret;
92559@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92560 0, 0L, 0,
92561 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92562 0, sock_i_ino(sp),
92563- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92564+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92565 }
92566
92567 static int raw_seq_show(struct seq_file *seq, void *v)
92568diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92569index a9a54a2..647316e 100644
92570--- a/net/ipv4/route.c
92571+++ b/net/ipv4/route.c
92572@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92573 .maxlen = sizeof(int),
92574 .mode = 0200,
92575 .proc_handler = ipv4_sysctl_rtcache_flush,
92576+ .extra1 = &init_net,
92577 },
92578 { },
92579 };
92580
92581 static __net_init int sysctl_route_net_init(struct net *net)
92582 {
92583- struct ctl_table *tbl;
92584+ ctl_table_no_const *tbl = NULL;
92585
92586- tbl = ipv4_route_flush_table;
92587 if (!net_eq(net, &init_net)) {
92588- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92589+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92590 if (tbl == NULL)
92591 goto err_dup;
92592
92593 /* Don't export sysctls to unprivileged users */
92594 if (net->user_ns != &init_user_ns)
92595 tbl[0].procname = NULL;
92596- }
92597- tbl[0].extra1 = net;
92598+ tbl[0].extra1 = net;
92599+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92600+ } else
92601+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92602
92603- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92604 if (net->ipv4.route_hdr == NULL)
92605 goto err_reg;
92606 return 0;
92607
92608 err_reg:
92609- if (tbl != ipv4_route_flush_table)
92610- kfree(tbl);
92611+ kfree(tbl);
92612 err_dup:
92613 return -ENOMEM;
92614 }
92615@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92616
92617 static __net_init int rt_genid_init(struct net *net)
92618 {
92619- atomic_set(&net->rt_genid, 0);
92620- atomic_set(&net->fnhe_genid, 0);
92621+ atomic_set_unchecked(&net->rt_genid, 0);
92622+ atomic_set_unchecked(&net->fnhe_genid, 0);
92623 get_random_bytes(&net->ipv4.dev_addr_genid,
92624 sizeof(net->ipv4.dev_addr_genid));
92625 return 0;
92626diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92627index 610e324..fd42e75 100644
92628--- a/net/ipv4/sysctl_net_ipv4.c
92629+++ b/net/ipv4/sysctl_net_ipv4.c
92630@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92631 {
92632 int ret;
92633 int range[2];
92634- struct ctl_table tmp = {
92635+ ctl_table_no_const tmp = {
92636 .data = &range,
92637 .maxlen = sizeof(range),
92638 .mode = table->mode,
92639@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92640 int ret;
92641 gid_t urange[2];
92642 kgid_t low, high;
92643- struct ctl_table tmp = {
92644+ ctl_table_no_const tmp = {
92645 .data = &urange,
92646 .maxlen = sizeof(urange),
92647 .mode = table->mode,
92648@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92649 void __user *buffer, size_t *lenp, loff_t *ppos)
92650 {
92651 char val[TCP_CA_NAME_MAX];
92652- struct ctl_table tbl = {
92653+ ctl_table_no_const tbl = {
92654 .data = val,
92655 .maxlen = TCP_CA_NAME_MAX,
92656 };
92657@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92658 void __user *buffer, size_t *lenp,
92659 loff_t *ppos)
92660 {
92661- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92662+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92663 int ret;
92664
92665 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92666@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92667 void __user *buffer, size_t *lenp,
92668 loff_t *ppos)
92669 {
92670- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92671+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92672 int ret;
92673
92674 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92675@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92676 struct mem_cgroup *memcg;
92677 #endif
92678
92679- struct ctl_table tmp = {
92680+ ctl_table_no_const tmp = {
92681 .data = &vec,
92682 .maxlen = sizeof(vec),
92683 .mode = ctl->mode,
92684 };
92685
92686 if (!write) {
92687- ctl->data = &net->ipv4.sysctl_tcp_mem;
92688- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92689+ ctl_table_no_const tcp_mem = *ctl;
92690+
92691+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92692+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92693 }
92694
92695 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92696@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92697 void __user *buffer, size_t *lenp,
92698 loff_t *ppos)
92699 {
92700- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92701+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92702 struct tcp_fastopen_context *ctxt;
92703 int ret;
92704 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92705@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92706 },
92707 {
92708 .procname = "ip_local_reserved_ports",
92709- .data = NULL, /* initialized in sysctl_ipv4_init */
92710+ .data = sysctl_local_reserved_ports,
92711 .maxlen = 65536,
92712 .mode = 0644,
92713 .proc_handler = proc_do_large_bitmap,
92714@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92715
92716 static __net_init int ipv4_sysctl_init_net(struct net *net)
92717 {
92718- struct ctl_table *table;
92719+ ctl_table_no_const *table = NULL;
92720
92721- table = ipv4_net_table;
92722 if (!net_eq(net, &init_net)) {
92723- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92724+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92725 if (table == NULL)
92726 goto err_alloc;
92727
92728@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92729
92730 tcp_init_mem(net);
92731
92732- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92733+ if (!net_eq(net, &init_net))
92734+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92735+ else
92736+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92737 if (net->ipv4.ipv4_hdr == NULL)
92738 goto err_reg;
92739
92740 return 0;
92741
92742 err_reg:
92743- if (!net_eq(net, &init_net))
92744- kfree(table);
92745+ kfree(table);
92746 err_alloc:
92747 return -ENOMEM;
92748 }
92749@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92750 static __init int sysctl_ipv4_init(void)
92751 {
92752 struct ctl_table_header *hdr;
92753- struct ctl_table *i;
92754-
92755- for (i = ipv4_table; i->procname; i++) {
92756- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92757- i->data = sysctl_local_reserved_ports;
92758- break;
92759- }
92760- }
92761- if (!i->procname)
92762- return -EINVAL;
92763
92764 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92765 if (hdr == NULL)
92766diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92767index 3ca2139..c4cc060 100644
92768--- a/net/ipv4/tcp_input.c
92769+++ b/net/ipv4/tcp_input.c
92770@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92771 * simplifies code)
92772 */
92773 static void
92774-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92775+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92776 struct sk_buff *head, struct sk_buff *tail,
92777 u32 start, u32 end)
92778 {
92779@@ -5465,6 +5465,7 @@ discard:
92780 tcp_paws_reject(&tp->rx_opt, 0))
92781 goto discard_and_undo;
92782
92783+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92784 if (th->syn) {
92785 /* We see SYN without ACK. It is attempt of
92786 * simultaneous connect with crossed SYNs.
92787@@ -5515,6 +5516,7 @@ discard:
92788 goto discard;
92789 #endif
92790 }
92791+#endif
92792 /* "fifth, if neither of the SYN or RST bits is set then
92793 * drop the segment and return."
92794 */
92795@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92796 goto discard;
92797
92798 if (th->syn) {
92799- if (th->fin)
92800+ if (th->fin || th->urg || th->psh)
92801 goto discard;
92802 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92803 return 1;
92804diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92805index b299da5..097db06 100644
92806--- a/net/ipv4/tcp_ipv4.c
92807+++ b/net/ipv4/tcp_ipv4.c
92808@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92809 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92810
92811
92812+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92813+extern int grsec_enable_blackhole;
92814+#endif
92815+
92816 #ifdef CONFIG_TCP_MD5SIG
92817 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92818 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92819@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92820 return 0;
92821
92822 reset:
92823+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92824+ if (!grsec_enable_blackhole)
92825+#endif
92826 tcp_v4_send_reset(rsk, skb);
92827 discard:
92828 kfree_skb(skb);
92829@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92830 TCP_SKB_CB(skb)->sacked = 0;
92831
92832 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92833- if (!sk)
92834+ if (!sk) {
92835+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92836+ ret = 1;
92837+#endif
92838 goto no_tcp_socket;
92839-
92840+ }
92841 process:
92842- if (sk->sk_state == TCP_TIME_WAIT)
92843+ if (sk->sk_state == TCP_TIME_WAIT) {
92844+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92845+ ret = 2;
92846+#endif
92847 goto do_time_wait;
92848+ }
92849
92850 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92851 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92852@@ -2034,6 +2048,10 @@ csum_error:
92853 bad_packet:
92854 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92855 } else {
92856+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92857+ if (!grsec_enable_blackhole || (ret == 1 &&
92858+ (skb->dev->flags & IFF_LOOPBACK)))
92859+#endif
92860 tcp_v4_send_reset(NULL, skb);
92861 }
92862
92863diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92864index ab1c086..2a8d76b 100644
92865--- a/net/ipv4/tcp_minisocks.c
92866+++ b/net/ipv4/tcp_minisocks.c
92867@@ -27,6 +27,10 @@
92868 #include <net/inet_common.h>
92869 #include <net/xfrm.h>
92870
92871+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92872+extern int grsec_enable_blackhole;
92873+#endif
92874+
92875 int sysctl_tcp_syncookies __read_mostly = 1;
92876 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92877
92878@@ -715,7 +719,10 @@ embryonic_reset:
92879 * avoid becoming vulnerable to outside attack aiming at
92880 * resetting legit local connections.
92881 */
92882- req->rsk_ops->send_reset(sk, skb);
92883+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92884+ if (!grsec_enable_blackhole)
92885+#endif
92886+ req->rsk_ops->send_reset(sk, skb);
92887 } else if (fastopen) { /* received a valid RST pkt */
92888 reqsk_fastopen_remove(sk, req, true);
92889 tcp_reset(sk);
92890diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
92891index 170737a..75cbd26 100644
92892--- a/net/ipv4/tcp_output.c
92893+++ b/net/ipv4/tcp_output.c
92894@@ -982,6 +982,9 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
92895 static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb,
92896 unsigned int mss_now)
92897 {
92898+ /* Make sure we own this skb before messing gso_size/gso_segs */
92899+ WARN_ON_ONCE(skb_cloned(skb));
92900+
92901 if (skb->len <= mss_now || !sk_can_gso(sk) ||
92902 skb->ip_summed == CHECKSUM_NONE) {
92903 /* Avoid the costly divide in the normal
92904@@ -1063,9 +1066,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
92905 if (nsize < 0)
92906 nsize = 0;
92907
92908- if (skb_cloned(skb) &&
92909- skb_is_nonlinear(skb) &&
92910- pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
92911+ if (skb_unclone(skb, GFP_ATOMIC))
92912 return -ENOMEM;
92913
92914 /* Get a new skb... force flag on. */
92915@@ -2334,6 +2335,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
92916 int oldpcount = tcp_skb_pcount(skb);
92917
92918 if (unlikely(oldpcount > 1)) {
92919+ if (skb_unclone(skb, GFP_ATOMIC))
92920+ return -ENOMEM;
92921 tcp_init_tso_segs(sk, skb, cur_mss);
92922 tcp_adjust_pcount(sk, skb, oldpcount - tcp_skb_pcount(skb));
92923 }
92924diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92925index d4943f6..e7a74a5 100644
92926--- a/net/ipv4/tcp_probe.c
92927+++ b/net/ipv4/tcp_probe.c
92928@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92929 if (cnt + width >= len)
92930 break;
92931
92932- if (copy_to_user(buf + cnt, tbuf, width))
92933+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92934 return -EFAULT;
92935 cnt += width;
92936 }
92937diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92938index 4b85e6f..22f9ac9 100644
92939--- a/net/ipv4/tcp_timer.c
92940+++ b/net/ipv4/tcp_timer.c
92941@@ -22,6 +22,10 @@
92942 #include <linux/gfp.h>
92943 #include <net/tcp.h>
92944
92945+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92946+extern int grsec_lastack_retries;
92947+#endif
92948+
92949 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92950 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92951 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92952@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92953 }
92954 }
92955
92956+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92957+ if ((sk->sk_state == TCP_LAST_ACK) &&
92958+ (grsec_lastack_retries > 0) &&
92959+ (grsec_lastack_retries < retry_until))
92960+ retry_until = grsec_lastack_retries;
92961+#endif
92962+
92963 if (retransmits_timed_out(sk, retry_until,
92964 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92965 /* Has it gone just too far? */
92966diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92967index 766e6ba..aff2f8d 100644
92968--- a/net/ipv4/udp.c
92969+++ b/net/ipv4/udp.c
92970@@ -87,6 +87,7 @@
92971 #include <linux/types.h>
92972 #include <linux/fcntl.h>
92973 #include <linux/module.h>
92974+#include <linux/security.h>
92975 #include <linux/socket.h>
92976 #include <linux/sockios.h>
92977 #include <linux/igmp.h>
92978@@ -112,6 +113,10 @@
92979 #include <net/busy_poll.h>
92980 #include "udp_impl.h"
92981
92982+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92983+extern int grsec_enable_blackhole;
92984+#endif
92985+
92986 struct udp_table udp_table __read_mostly;
92987 EXPORT_SYMBOL(udp_table);
92988
92989@@ -595,6 +600,9 @@ found:
92990 return s;
92991 }
92992
92993+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
92994+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
92995+
92996 /*
92997 * This routine is called by the ICMP module when it gets some
92998 * sort of error condition. If err < 0 then the socket should
92999@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93000 dport = usin->sin_port;
93001 if (dport == 0)
93002 return -EINVAL;
93003+
93004+ err = gr_search_udp_sendmsg(sk, usin);
93005+ if (err)
93006+ return err;
93007 } else {
93008 if (sk->sk_state != TCP_ESTABLISHED)
93009 return -EDESTADDRREQ;
93010+
93011+ err = gr_search_udp_sendmsg(sk, NULL);
93012+ if (err)
93013+ return err;
93014+
93015 daddr = inet->inet_daddr;
93016 dport = inet->inet_dport;
93017 /* Open fast path for connected socket.
93018@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93019 IS_UDPLITE(sk));
93020 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93021 IS_UDPLITE(sk));
93022- atomic_inc(&sk->sk_drops);
93023+ atomic_inc_unchecked(&sk->sk_drops);
93024 __skb_unlink(skb, rcvq);
93025 __skb_queue_tail(&list_kill, skb);
93026 }
93027@@ -1223,6 +1240,10 @@ try_again:
93028 if (!skb)
93029 goto out;
93030
93031+ err = gr_search_udp_recvmsg(sk, skb);
93032+ if (err)
93033+ goto out_free;
93034+
93035 ulen = skb->len - sizeof(struct udphdr);
93036 copied = len;
93037 if (copied > ulen)
93038@@ -1256,7 +1277,7 @@ try_again:
93039 if (unlikely(err)) {
93040 trace_kfree_skb(skb, udp_recvmsg);
93041 if (!peeked) {
93042- atomic_inc(&sk->sk_drops);
93043+ atomic_inc_unchecked(&sk->sk_drops);
93044 UDP_INC_STATS_USER(sock_net(sk),
93045 UDP_MIB_INERRORS, is_udplite);
93046 }
93047@@ -1543,7 +1564,7 @@ csum_error:
93048 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93049 drop:
93050 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93051- atomic_inc(&sk->sk_drops);
93052+ atomic_inc_unchecked(&sk->sk_drops);
93053 kfree_skb(skb);
93054 return -1;
93055 }
93056@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93057 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93058
93059 if (!skb1) {
93060- atomic_inc(&sk->sk_drops);
93061+ atomic_inc_unchecked(&sk->sk_drops);
93062 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93063 IS_UDPLITE(sk));
93064 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93065@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93066 goto csum_error;
93067
93068 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93069+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93070+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93071+#endif
93072 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93073
93074 /*
93075@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93076 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93077 0, sock_i_ino(sp),
93078 atomic_read(&sp->sk_refcnt), sp,
93079- atomic_read(&sp->sk_drops), len);
93080+ atomic_read_unchecked(&sp->sk_drops), len);
93081 }
93082
93083 int udp4_seq_show(struct seq_file *seq, void *v)
93084diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93085index 9a459be..c7bc04c 100644
93086--- a/net/ipv4/xfrm4_policy.c
93087+++ b/net/ipv4/xfrm4_policy.c
93088@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93089 fl4->flowi4_tos = iph->tos;
93090 }
93091
93092-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93093+static int xfrm4_garbage_collect(struct dst_ops *ops)
93094 {
93095 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93096
93097- xfrm4_policy_afinfo.garbage_collect(net);
93098+ xfrm_garbage_collect_deferred(net);
93099 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93100 }
93101
93102@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93103
93104 static int __net_init xfrm4_net_init(struct net *net)
93105 {
93106- struct ctl_table *table;
93107+ ctl_table_no_const *table = NULL;
93108 struct ctl_table_header *hdr;
93109
93110- table = xfrm4_policy_table;
93111 if (!net_eq(net, &init_net)) {
93112- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93113+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93114 if (!table)
93115 goto err_alloc;
93116
93117 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93118- }
93119-
93120- hdr = register_net_sysctl(net, "net/ipv4", table);
93121+ hdr = register_net_sysctl(net, "net/ipv4", table);
93122+ } else
93123+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93124 if (!hdr)
93125 goto err_reg;
93126
93127@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93128 return 0;
93129
93130 err_reg:
93131- if (!net_eq(net, &init_net))
93132- kfree(table);
93133+ kfree(table);
93134 err_alloc:
93135 return -ENOMEM;
93136 }
93137diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93138index 0f99f7b..9375cf5 100644
93139--- a/net/ipv6/addrconf.c
93140+++ b/net/ipv6/addrconf.c
93141@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93142 idx = 0;
93143 head = &net->dev_index_head[h];
93144 rcu_read_lock();
93145- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93146+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93147 net->dev_base_seq;
93148 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93149 if (idx < s_idx)
93150@@ -2408,7 +2408,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93151 p.iph.ihl = 5;
93152 p.iph.protocol = IPPROTO_IPV6;
93153 p.iph.ttl = 64;
93154- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93155+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93156
93157 if (ops->ndo_do_ioctl) {
93158 mm_segment_t oldfs = get_fs();
93159@@ -4057,7 +4057,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93160 s_ip_idx = ip_idx = cb->args[2];
93161
93162 rcu_read_lock();
93163- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93164+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93165 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93166 idx = 0;
93167 head = &net->dev_index_head[h];
93168@@ -4678,7 +4678,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93169 dst_free(&ifp->rt->dst);
93170 break;
93171 }
93172- atomic_inc(&net->ipv6.dev_addr_genid);
93173+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93174 }
93175
93176 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93177@@ -4698,7 +4698,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93178 int *valp = ctl->data;
93179 int val = *valp;
93180 loff_t pos = *ppos;
93181- struct ctl_table lctl;
93182+ ctl_table_no_const lctl;
93183 int ret;
93184
93185 /*
93186@@ -4783,7 +4783,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93187 int *valp = ctl->data;
93188 int val = *valp;
93189 loff_t pos = *ppos;
93190- struct ctl_table lctl;
93191+ ctl_table_no_const lctl;
93192 int ret;
93193
93194 /*
93195diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93196index 197e6f4..16d8396 100644
93197--- a/net/ipv6/datagram.c
93198+++ b/net/ipv6/datagram.c
93199@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93200 0,
93201 sock_i_ino(sp),
93202 atomic_read(&sp->sk_refcnt), sp,
93203- atomic_read(&sp->sk_drops));
93204+ atomic_read_unchecked(&sp->sk_drops));
93205 }
93206diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93207index 7cfc8d2..c5394b6 100644
93208--- a/net/ipv6/icmp.c
93209+++ b/net/ipv6/icmp.c
93210@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93211
93212 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93213 {
93214- struct ctl_table *table;
93215+ ctl_table_no_const *table;
93216
93217 table = kmemdup(ipv6_icmp_table_template,
93218 sizeof(ipv6_icmp_table_template),
93219diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93220index 8bc717b..76fbb5d 100644
93221--- a/net/ipv6/ip6_gre.c
93222+++ b/net/ipv6/ip6_gre.c
93223@@ -74,7 +74,7 @@ struct ip6gre_net {
93224 struct net_device *fb_tunnel_dev;
93225 };
93226
93227-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93228+static struct rtnl_link_ops ip6gre_link_ops;
93229 static int ip6gre_tunnel_init(struct net_device *dev);
93230 static void ip6gre_tunnel_setup(struct net_device *dev);
93231 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93232@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93233 }
93234
93235
93236-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93237+static struct inet6_protocol ip6gre_protocol = {
93238 .handler = ip6gre_rcv,
93239 .err_handler = ip6gre_err,
93240 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93241@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93242 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93243 };
93244
93245-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93246+static struct rtnl_link_ops ip6gre_link_ops = {
93247 .kind = "ip6gre",
93248 .maxtype = IFLA_GRE_MAX,
93249 .policy = ip6gre_policy,
93250@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93251 .fill_info = ip6gre_fill_info,
93252 };
93253
93254-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93255+static struct rtnl_link_ops ip6gre_tap_ops = {
93256 .kind = "ip6gretap",
93257 .maxtype = IFLA_GRE_MAX,
93258 .policy = ip6gre_policy,
93259diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93260index cf5d490..30946f0 100644
93261--- a/net/ipv6/ip6_tunnel.c
93262+++ b/net/ipv6/ip6_tunnel.c
93263@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93264
93265 static int ip6_tnl_dev_init(struct net_device *dev);
93266 static void ip6_tnl_dev_setup(struct net_device *dev);
93267-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93268+static struct rtnl_link_ops ip6_link_ops;
93269
93270 static int ip6_tnl_net_id __read_mostly;
93271 struct ip6_tnl_net {
93272@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93273 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93274 };
93275
93276-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93277+static struct rtnl_link_ops ip6_link_ops = {
93278 .kind = "ip6tnl",
93279 .maxtype = IFLA_IPTUN_MAX,
93280 .policy = ip6_tnl_policy,
93281diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93282index d1e2e8e..51c19ae 100644
93283--- a/net/ipv6/ipv6_sockglue.c
93284+++ b/net/ipv6/ipv6_sockglue.c
93285@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93286 if (sk->sk_type != SOCK_STREAM)
93287 return -ENOPROTOOPT;
93288
93289- msg.msg_control = optval;
93290+ msg.msg_control = (void __force_kernel *)optval;
93291 msg.msg_controllen = len;
93292 msg.msg_flags = flags;
93293
93294diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93295index 44400c2..8e11f52 100644
93296--- a/net/ipv6/netfilter/ip6_tables.c
93297+++ b/net/ipv6/netfilter/ip6_tables.c
93298@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93299 #endif
93300
93301 static int get_info(struct net *net, void __user *user,
93302- const int *len, int compat)
93303+ int len, int compat)
93304 {
93305 char name[XT_TABLE_MAXNAMELEN];
93306 struct xt_table *t;
93307 int ret;
93308
93309- if (*len != sizeof(struct ip6t_getinfo)) {
93310- duprintf("length %u != %zu\n", *len,
93311+ if (len != sizeof(struct ip6t_getinfo)) {
93312+ duprintf("length %u != %zu\n", len,
93313 sizeof(struct ip6t_getinfo));
93314 return -EINVAL;
93315 }
93316@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93317 info.size = private->size;
93318 strcpy(info.name, name);
93319
93320- if (copy_to_user(user, &info, *len) != 0)
93321+ if (copy_to_user(user, &info, len) != 0)
93322 ret = -EFAULT;
93323 else
93324 ret = 0;
93325@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93326
93327 switch (cmd) {
93328 case IP6T_SO_GET_INFO:
93329- ret = get_info(sock_net(sk), user, len, 1);
93330+ ret = get_info(sock_net(sk), user, *len, 1);
93331 break;
93332 case IP6T_SO_GET_ENTRIES:
93333 ret = compat_get_entries(sock_net(sk), user, len);
93334@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93335
93336 switch (cmd) {
93337 case IP6T_SO_GET_INFO:
93338- ret = get_info(sock_net(sk), user, len, 0);
93339+ ret = get_info(sock_net(sk), user, *len, 0);
93340 break;
93341
93342 case IP6T_SO_GET_ENTRIES:
93343diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93344index dffdc1a..ccc6678 100644
93345--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93346+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93347@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93348
93349 static int nf_ct_frag6_sysctl_register(struct net *net)
93350 {
93351- struct ctl_table *table;
93352+ ctl_table_no_const *table = NULL;
93353 struct ctl_table_header *hdr;
93354
93355- table = nf_ct_frag6_sysctl_table;
93356 if (!net_eq(net, &init_net)) {
93357- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93358+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93359 GFP_KERNEL);
93360 if (table == NULL)
93361 goto err_alloc;
93362@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93363 table[0].data = &net->nf_frag.frags.timeout;
93364 table[1].data = &net->nf_frag.frags.low_thresh;
93365 table[2].data = &net->nf_frag.frags.high_thresh;
93366- }
93367-
93368- hdr = register_net_sysctl(net, "net/netfilter", table);
93369+ hdr = register_net_sysctl(net, "net/netfilter", table);
93370+ } else
93371+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93372 if (hdr == NULL)
93373 goto err_reg;
93374
93375@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93376 return 0;
93377
93378 err_reg:
93379- if (!net_eq(net, &init_net))
93380- kfree(table);
93381+ kfree(table);
93382 err_alloc:
93383 return -ENOMEM;
93384 }
93385diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93386index ab92a36..bb4a528 100644
93387--- a/net/ipv6/output_core.c
93388+++ b/net/ipv6/output_core.c
93389@@ -8,8 +8,8 @@
93390
93391 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93392 {
93393- static atomic_t ipv6_fragmentation_id;
93394- int old, new;
93395+ static atomic_unchecked_t ipv6_fragmentation_id;
93396+ int id;
93397
93398 #if IS_ENABLED(CONFIG_IPV6)
93399 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93400@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93401 }
93402 }
93403 #endif
93404- do {
93405- old = atomic_read(&ipv6_fragmentation_id);
93406- new = old + 1;
93407- if (!new)
93408- new = 1;
93409- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93410- fhdr->identification = htonl(new);
93411+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93412+ if (!id)
93413+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93414+ fhdr->identification = htonl(id);
93415 }
93416 EXPORT_SYMBOL(ipv6_select_ident);
93417
93418diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93419index 18f19df..b46ada1 100644
93420--- a/net/ipv6/ping.c
93421+++ b/net/ipv6/ping.c
93422@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93423 };
93424 #endif
93425
93426+static struct pingv6_ops real_pingv6_ops = {
93427+ .ipv6_recv_error = ipv6_recv_error,
93428+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93429+ .icmpv6_err_convert = icmpv6_err_convert,
93430+ .ipv6_icmp_error = ipv6_icmp_error,
93431+ .ipv6_chk_addr = ipv6_chk_addr,
93432+};
93433+
93434+static struct pingv6_ops dummy_pingv6_ops = {
93435+ .ipv6_recv_error = dummy_ipv6_recv_error,
93436+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93437+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93438+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93439+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93440+};
93441+
93442 int __init pingv6_init(void)
93443 {
93444 #ifdef CONFIG_PROC_FS
93445@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93446 if (ret)
93447 return ret;
93448 #endif
93449- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93450- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93451- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93452- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93453- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93454+ pingv6_ops = &real_pingv6_ops;
93455 return inet6_register_protosw(&pingv6_protosw);
93456 }
93457
93458@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93459 */
93460 void pingv6_exit(void)
93461 {
93462- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93463- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93464- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93465- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93466- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93467+ pingv6_ops = &dummy_pingv6_ops;
93468 #ifdef CONFIG_PROC_FS
93469 unregister_pernet_subsys(&ping_v6_net_ops);
93470 #endif
93471diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93472index cdaed47..515edde9 100644
93473--- a/net/ipv6/raw.c
93474+++ b/net/ipv6/raw.c
93475@@ -108,7 +108,7 @@ found:
93476 */
93477 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93478 {
93479- struct icmp6hdr *_hdr;
93480+ struct icmp6hdr _hdr;
93481 const struct icmp6hdr *hdr;
93482
93483 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93484@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93485 {
93486 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93487 skb_checksum_complete(skb)) {
93488- atomic_inc(&sk->sk_drops);
93489+ atomic_inc_unchecked(&sk->sk_drops);
93490 kfree_skb(skb);
93491 return NET_RX_DROP;
93492 }
93493@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93494 struct raw6_sock *rp = raw6_sk(sk);
93495
93496 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93497- atomic_inc(&sk->sk_drops);
93498+ atomic_inc_unchecked(&sk->sk_drops);
93499 kfree_skb(skb);
93500 return NET_RX_DROP;
93501 }
93502@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93503
93504 if (inet->hdrincl) {
93505 if (skb_checksum_complete(skb)) {
93506- atomic_inc(&sk->sk_drops);
93507+ atomic_inc_unchecked(&sk->sk_drops);
93508 kfree_skb(skb);
93509 return NET_RX_DROP;
93510 }
93511@@ -602,7 +602,7 @@ out:
93512 return err;
93513 }
93514
93515-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93516+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93517 struct flowi6 *fl6, struct dst_entry **dstp,
93518 unsigned int flags)
93519 {
93520@@ -915,12 +915,15 @@ do_confirm:
93521 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93522 char __user *optval, int optlen)
93523 {
93524+ struct icmp6_filter filter;
93525+
93526 switch (optname) {
93527 case ICMPV6_FILTER:
93528 if (optlen > sizeof(struct icmp6_filter))
93529 optlen = sizeof(struct icmp6_filter);
93530- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93531+ if (copy_from_user(&filter, optval, optlen))
93532 return -EFAULT;
93533+ raw6_sk(sk)->filter = filter;
93534 return 0;
93535 default:
93536 return -ENOPROTOOPT;
93537@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93538 char __user *optval, int __user *optlen)
93539 {
93540 int len;
93541+ struct icmp6_filter filter;
93542
93543 switch (optname) {
93544 case ICMPV6_FILTER:
93545@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93546 len = sizeof(struct icmp6_filter);
93547 if (put_user(len, optlen))
93548 return -EFAULT;
93549- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93550+ filter = raw6_sk(sk)->filter;
93551+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93552 return -EFAULT;
93553 return 0;
93554 default:
93555diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93556index 1aeb473..bea761c 100644
93557--- a/net/ipv6/reassembly.c
93558+++ b/net/ipv6/reassembly.c
93559@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93560
93561 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93562 {
93563- struct ctl_table *table;
93564+ ctl_table_no_const *table = NULL;
93565 struct ctl_table_header *hdr;
93566
93567- table = ip6_frags_ns_ctl_table;
93568 if (!net_eq(net, &init_net)) {
93569- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93570+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93571 if (table == NULL)
93572 goto err_alloc;
93573
93574@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93575 /* Don't export sysctls to unprivileged users */
93576 if (net->user_ns != &init_user_ns)
93577 table[0].procname = NULL;
93578- }
93579+ hdr = register_net_sysctl(net, "net/ipv6", table);
93580+ } else
93581+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93582
93583- hdr = register_net_sysctl(net, "net/ipv6", table);
93584 if (hdr == NULL)
93585 goto err_reg;
93586
93587@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93588 return 0;
93589
93590 err_reg:
93591- if (!net_eq(net, &init_net))
93592- kfree(table);
93593+ kfree(table);
93594 err_alloc:
93595 return -ENOMEM;
93596 }
93597diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93598index 8d9a93ed..cd89616 100644
93599--- a/net/ipv6/route.c
93600+++ b/net/ipv6/route.c
93601@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93602
93603 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93604 {
93605- struct ctl_table *table;
93606+ ctl_table_no_const *table;
93607
93608 table = kmemdup(ipv6_route_table_template,
93609 sizeof(ipv6_route_table_template),
93610diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93611index 86f639b..71e355e 100644
93612--- a/net/ipv6/sit.c
93613+++ b/net/ipv6/sit.c
93614@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93615 static void ipip6_dev_free(struct net_device *dev);
93616 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93617 __be32 *v4dst);
93618-static struct rtnl_link_ops sit_link_ops __read_mostly;
93619+static struct rtnl_link_ops sit_link_ops;
93620
93621 static int sit_net_id __read_mostly;
93622 struct sit_net {
93623@@ -1601,7 +1601,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93624 #endif
93625 };
93626
93627-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93628+static struct rtnl_link_ops sit_link_ops = {
93629 .kind = "sit",
93630 .maxtype = IFLA_IPTUN_MAX,
93631 .policy = ipip6_policy,
93632diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93633index 107b2f1..72741a9 100644
93634--- a/net/ipv6/sysctl_net_ipv6.c
93635+++ b/net/ipv6/sysctl_net_ipv6.c
93636@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93637
93638 static int __net_init ipv6_sysctl_net_init(struct net *net)
93639 {
93640- struct ctl_table *ipv6_table;
93641+ ctl_table_no_const *ipv6_table;
93642 struct ctl_table *ipv6_route_table;
93643 struct ctl_table *ipv6_icmp_table;
93644 int err;
93645diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93646index 6e1649d..75ddb4c 100644
93647--- a/net/ipv6/tcp_ipv6.c
93648+++ b/net/ipv6/tcp_ipv6.c
93649@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93650 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93651 }
93652
93653+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93654+extern int grsec_enable_blackhole;
93655+#endif
93656+
93657 static void tcp_v6_hash(struct sock *sk)
93658 {
93659 if (sk->sk_state != TCP_CLOSE) {
93660@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93661 return 0;
93662
93663 reset:
93664+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93665+ if (!grsec_enable_blackhole)
93666+#endif
93667 tcp_v6_send_reset(sk, skb);
93668 discard:
93669 if (opt_skb)
93670@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93671 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93672 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93673 if (np->rxopt.bits.rxtclass)
93674- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93675+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93676 if (ipv6_opt_accepted(sk, opt_skb)) {
93677 skb_set_owner_r(opt_skb, sk);
93678 opt_skb = xchg(&np->pktoptions, opt_skb);
93679@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93680 TCP_SKB_CB(skb)->sacked = 0;
93681
93682 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93683- if (!sk)
93684+ if (!sk) {
93685+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93686+ ret = 1;
93687+#endif
93688 goto no_tcp_socket;
93689+ }
93690
93691 process:
93692- if (sk->sk_state == TCP_TIME_WAIT)
93693+ if (sk->sk_state == TCP_TIME_WAIT) {
93694+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93695+ ret = 2;
93696+#endif
93697 goto do_time_wait;
93698+ }
93699
93700 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93701 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93702@@ -1538,6 +1553,10 @@ csum_error:
93703 bad_packet:
93704 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93705 } else {
93706+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93707+ if (!grsec_enable_blackhole || (ret == 1 &&
93708+ (skb->dev->flags & IFF_LOOPBACK)))
93709+#endif
93710 tcp_v6_send_reset(NULL, skb);
93711 }
93712
93713diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93714index f405815..45a68a6 100644
93715--- a/net/ipv6/udp.c
93716+++ b/net/ipv6/udp.c
93717@@ -53,6 +53,10 @@
93718 #include <trace/events/skb.h>
93719 #include "udp_impl.h"
93720
93721+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93722+extern int grsec_enable_blackhole;
93723+#endif
93724+
93725 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93726 {
93727 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93728@@ -420,7 +424,7 @@ try_again:
93729 if (unlikely(err)) {
93730 trace_kfree_skb(skb, udpv6_recvmsg);
93731 if (!peeked) {
93732- atomic_inc(&sk->sk_drops);
93733+ atomic_inc_unchecked(&sk->sk_drops);
93734 if (is_udp4)
93735 UDP_INC_STATS_USER(sock_net(sk),
93736 UDP_MIB_INERRORS,
93737@@ -666,7 +670,7 @@ csum_error:
93738 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93739 drop:
93740 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93741- atomic_inc(&sk->sk_drops);
93742+ atomic_inc_unchecked(&sk->sk_drops);
93743 kfree_skb(skb);
93744 return -1;
93745 }
93746@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93747 if (likely(skb1 == NULL))
93748 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93749 if (!skb1) {
93750- atomic_inc(&sk->sk_drops);
93751+ atomic_inc_unchecked(&sk->sk_drops);
93752 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93753 IS_UDPLITE(sk));
93754 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93755@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93756 goto csum_error;
93757
93758 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93759+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93760+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93761+#endif
93762 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93763
93764 kfree_skb(skb);
93765diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93766index 23ed03d..6532e67 100644
93767--- a/net/ipv6/xfrm6_policy.c
93768+++ b/net/ipv6/xfrm6_policy.c
93769@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93770 }
93771 }
93772
93773-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93774+static int xfrm6_garbage_collect(struct dst_ops *ops)
93775 {
93776 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93777
93778- xfrm6_policy_afinfo.garbage_collect(net);
93779+ xfrm_garbage_collect_deferred(net);
93780 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93781 }
93782
93783@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93784
93785 static int __net_init xfrm6_net_init(struct net *net)
93786 {
93787- struct ctl_table *table;
93788+ ctl_table_no_const *table = NULL;
93789 struct ctl_table_header *hdr;
93790
93791- table = xfrm6_policy_table;
93792 if (!net_eq(net, &init_net)) {
93793- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93794+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93795 if (!table)
93796 goto err_alloc;
93797
93798 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93799- }
93800+ hdr = register_net_sysctl(net, "net/ipv6", table);
93801+ } else
93802+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93803
93804- hdr = register_net_sysctl(net, "net/ipv6", table);
93805 if (!hdr)
93806 goto err_reg;
93807
93808@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93809 return 0;
93810
93811 err_reg:
93812- if (!net_eq(net, &init_net))
93813- kfree(table);
93814+ kfree(table);
93815 err_alloc:
93816 return -ENOMEM;
93817 }
93818diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93819index 41ac7938..75e3bb1 100644
93820--- a/net/irda/ircomm/ircomm_tty.c
93821+++ b/net/irda/ircomm/ircomm_tty.c
93822@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93823 add_wait_queue(&port->open_wait, &wait);
93824
93825 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93826- __FILE__, __LINE__, tty->driver->name, port->count);
93827+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93828
93829 spin_lock_irqsave(&port->lock, flags);
93830 if (!tty_hung_up_p(filp))
93831- port->count--;
93832+ atomic_dec(&port->count);
93833 port->blocked_open++;
93834 spin_unlock_irqrestore(&port->lock, flags);
93835
93836@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93837 }
93838
93839 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93840- __FILE__, __LINE__, tty->driver->name, port->count);
93841+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93842
93843 schedule();
93844 }
93845@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93846
93847 spin_lock_irqsave(&port->lock, flags);
93848 if (!tty_hung_up_p(filp))
93849- port->count++;
93850+ atomic_inc(&port->count);
93851 port->blocked_open--;
93852 spin_unlock_irqrestore(&port->lock, flags);
93853
93854 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93855- __FILE__, __LINE__, tty->driver->name, port->count);
93856+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93857
93858 if (!retval)
93859 port->flags |= ASYNC_NORMAL_ACTIVE;
93860@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93861
93862 /* ++ is not atomic, so this should be protected - Jean II */
93863 spin_lock_irqsave(&self->port.lock, flags);
93864- self->port.count++;
93865+ atomic_inc(&self->port.count);
93866 spin_unlock_irqrestore(&self->port.lock, flags);
93867 tty_port_tty_set(&self->port, tty);
93868
93869 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93870- self->line, self->port.count);
93871+ self->line, atomic_read(&self->port.count));
93872
93873 /* Not really used by us, but lets do it anyway */
93874 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93875@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93876 tty_kref_put(port->tty);
93877 }
93878 port->tty = NULL;
93879- port->count = 0;
93880+ atomic_set(&port->count, 0);
93881 spin_unlock_irqrestore(&port->lock, flags);
93882
93883 wake_up_interruptible(&port->open_wait);
93884@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93885 seq_putc(m, '\n');
93886
93887 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93888- seq_printf(m, "Open count: %d\n", self->port.count);
93889+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93890 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93891 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93892
93893diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93894index 168aff5..9d43132 100644
93895--- a/net/iucv/af_iucv.c
93896+++ b/net/iucv/af_iucv.c
93897@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93898
93899 write_lock_bh(&iucv_sk_list.lock);
93900
93901- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93902+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93903 while (__iucv_get_sock_by_name(name)) {
93904 sprintf(name, "%08x",
93905- atomic_inc_return(&iucv_sk_list.autobind_name));
93906+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93907 }
93908
93909 write_unlock_bh(&iucv_sk_list.lock);
93910diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93911index cd5b8ec..f205e6b 100644
93912--- a/net/iucv/iucv.c
93913+++ b/net/iucv/iucv.c
93914@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93915 return NOTIFY_OK;
93916 }
93917
93918-static struct notifier_block __refdata iucv_cpu_notifier = {
93919+static struct notifier_block iucv_cpu_notifier = {
93920 .notifier_call = iucv_cpu_notify,
93921 };
93922
93923diff --git a/net/key/af_key.c b/net/key/af_key.c
93924index ab8bd2c..3a3eb81 100644
93925--- a/net/key/af_key.c
93926+++ b/net/key/af_key.c
93927@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
93928
93929 x->id.proto = proto;
93930 x->id.spi = sa->sadb_sa_spi;
93931- x->props.replay_window = sa->sadb_sa_replay;
93932+ x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
93933+ (sizeof(x->replay.bitmap) * 8));
93934 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
93935 x->props.flags |= XFRM_STATE_NOECN;
93936 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
93937@@ -3048,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93938 static u32 get_acqseq(void)
93939 {
93940 u32 res;
93941- static atomic_t acqseq;
93942+ static atomic_unchecked_t acqseq;
93943
93944 do {
93945- res = atomic_inc_return(&acqseq);
93946+ res = atomic_inc_return_unchecked(&acqseq);
93947 } while (!res);
93948 return res;
93949 }
93950diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
93951index feae495..aedaa2c 100644
93952--- a/net/l2tp/l2tp_core.c
93953+++ b/net/l2tp/l2tp_core.c
93954@@ -496,6 +496,7 @@ out:
93955 static inline int l2tp_verify_udp_checksum(struct sock *sk,
93956 struct sk_buff *skb)
93957 {
93958+ struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
93959 struct udphdr *uh = udp_hdr(skb);
93960 u16 ulen = ntohs(uh->len);
93961 __wsum psum;
93962@@ -504,7 +505,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
93963 return 0;
93964
93965 #if IS_ENABLED(CONFIG_IPV6)
93966- if (sk->sk_family == PF_INET6) {
93967+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) {
93968 if (!uh->check) {
93969 LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
93970 return 1;
93971@@ -1128,7 +1129,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
93972 /* Queue the packet to IP for output */
93973 skb->local_df = 1;
93974 #if IS_ENABLED(CONFIG_IPV6)
93975- if (skb->sk->sk_family == PF_INET6)
93976+ if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93977 error = inet6_csk_xmit(skb, NULL);
93978 else
93979 #endif
93980@@ -1255,7 +1256,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
93981
93982 /* Calculate UDP checksum if configured to do so */
93983 #if IS_ENABLED(CONFIG_IPV6)
93984- if (sk->sk_family == PF_INET6)
93985+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
93986 l2tp_xmit_ipv6_csum(sk, skb, udp_len);
93987 else
93988 #endif
93989@@ -1704,6 +1705,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
93990 if (cfg != NULL)
93991 tunnel->debug = cfg->debug;
93992
93993+#if IS_ENABLED(CONFIG_IPV6)
93994+ if (sk->sk_family == PF_INET6) {
93995+ struct ipv6_pinfo *np = inet6_sk(sk);
93996+
93997+ if (ipv6_addr_v4mapped(&np->saddr) &&
93998+ ipv6_addr_v4mapped(&np->daddr)) {
93999+ struct inet_sock *inet = inet_sk(sk);
94000+
94001+ tunnel->v4mapped = true;
94002+ inet->inet_saddr = np->saddr.s6_addr32[3];
94003+ inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
94004+ inet->inet_daddr = np->daddr.s6_addr32[3];
94005+ } else {
94006+ tunnel->v4mapped = false;
94007+ }
94008+ }
94009+#endif
94010+
94011 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
94012 tunnel->encap = encap;
94013 if (encap == L2TP_ENCAPTYPE_UDP) {
94014@@ -1712,7 +1731,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
94015 udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
94016 udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
94017 #if IS_ENABLED(CONFIG_IPV6)
94018- if (sk->sk_family == PF_INET6)
94019+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
94020 udpv6_encap_enable();
94021 else
94022 #endif
94023diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
94024index 66a559b..6f251cb 100644
94025--- a/net/l2tp/l2tp_core.h
94026+++ b/net/l2tp/l2tp_core.h
94027@@ -194,6 +194,9 @@ struct l2tp_tunnel {
94028 struct sock *sock; /* Parent socket */
94029 int fd; /* Parent fd, if tunnel socket
94030 * was created by userspace */
94031+#if IS_ENABLED(CONFIG_IPV6)
94032+ bool v4mapped;
94033+#endif
94034
94035 struct work_struct del_work;
94036
94037diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
94038index 43dd752..63a23bc 100644
94039--- a/net/mac80211/cfg.c
94040+++ b/net/mac80211/cfg.c
94041@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
94042 ret = ieee80211_vif_use_channel(sdata, chandef,
94043 IEEE80211_CHANCTX_EXCLUSIVE);
94044 }
94045- } else if (local->open_count == local->monitors) {
94046+ } else if (local_read(&local->open_count) == local->monitors) {
94047 local->_oper_chandef = *chandef;
94048 ieee80211_hw_config(local, 0);
94049 }
94050@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94051 else
94052 local->probe_req_reg--;
94053
94054- if (!local->open_count)
94055+ if (!local_read(&local->open_count))
94056 break;
94057
94058 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94059@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94060 if (chanctx_conf) {
94061 *chandef = chanctx_conf->def;
94062 ret = 0;
94063- } else if (local->open_count > 0 &&
94064- local->open_count == local->monitors &&
94065+ } else if (local_read(&local->open_count) > 0 &&
94066+ local_read(&local->open_count) == local->monitors &&
94067 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94068 if (local->use_chanctx)
94069 *chandef = local->monitor_chandef;
94070diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94071index 8412a30..6e00181 100644
94072--- a/net/mac80211/ieee80211_i.h
94073+++ b/net/mac80211/ieee80211_i.h
94074@@ -28,6 +28,7 @@
94075 #include <net/ieee80211_radiotap.h>
94076 #include <net/cfg80211.h>
94077 #include <net/mac80211.h>
94078+#include <asm/local.h>
94079 #include "key.h"
94080 #include "sta_info.h"
94081 #include "debug.h"
94082@@ -907,7 +908,7 @@ struct ieee80211_local {
94083 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94084 spinlock_t queue_stop_reason_lock;
94085
94086- int open_count;
94087+ local_t open_count;
94088 int monitors, cooked_mntrs;
94089 /* number of interfaces with corresponding FIF_ flags */
94090 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94091diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94092index cc11759..11d5541 100644
94093--- a/net/mac80211/iface.c
94094+++ b/net/mac80211/iface.c
94095@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94096 break;
94097 }
94098
94099- if (local->open_count == 0) {
94100+ if (local_read(&local->open_count) == 0) {
94101 res = drv_start(local);
94102 if (res)
94103 goto err_del_bss;
94104@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94105 res = drv_add_interface(local, sdata);
94106 if (res)
94107 goto err_stop;
94108- } else if (local->monitors == 0 && local->open_count == 0) {
94109+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94110 res = ieee80211_add_virtual_monitor(local);
94111 if (res)
94112 goto err_stop;
94113@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94114 atomic_inc(&local->iff_promiscs);
94115
94116 if (coming_up)
94117- local->open_count++;
94118+ local_inc(&local->open_count);
94119
94120 if (hw_reconf_flags)
94121 ieee80211_hw_config(local, hw_reconf_flags);
94122@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94123 err_del_interface:
94124 drv_remove_interface(local, sdata);
94125 err_stop:
94126- if (!local->open_count)
94127+ if (!local_read(&local->open_count))
94128 drv_stop(local);
94129 err_del_bss:
94130 sdata->bss = NULL;
94131@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94132 }
94133
94134 if (going_down)
94135- local->open_count--;
94136+ local_dec(&local->open_count);
94137
94138 switch (sdata->vif.type) {
94139 case NL80211_IFTYPE_AP_VLAN:
94140@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94141 }
94142 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94143
94144- if (local->open_count == 0)
94145+ if (local_read(&local->open_count) == 0)
94146 ieee80211_clear_tx_pending(local);
94147
94148 /*
94149@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94150
94151 ieee80211_recalc_ps(local, -1);
94152
94153- if (local->open_count == 0) {
94154+ if (local_read(&local->open_count) == 0) {
94155 ieee80211_stop_device(local);
94156
94157 /* no reconfiguring after stop! */
94158@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94159 ieee80211_configure_filter(local);
94160 ieee80211_hw_config(local, hw_reconf_flags);
94161
94162- if (local->monitors == local->open_count)
94163+ if (local->monitors == local_read(&local->open_count))
94164 ieee80211_add_virtual_monitor(local);
94165 }
94166
94167diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94168index 091088a..daf43c7 100644
94169--- a/net/mac80211/main.c
94170+++ b/net/mac80211/main.c
94171@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94172 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94173 IEEE80211_CONF_CHANGE_POWER);
94174
94175- if (changed && local->open_count) {
94176+ if (changed && local_read(&local->open_count)) {
94177 ret = drv_config(local, changed);
94178 /*
94179 * Goal:
94180diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94181index 3401262..d5cd68d 100644
94182--- a/net/mac80211/pm.c
94183+++ b/net/mac80211/pm.c
94184@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94185 struct ieee80211_sub_if_data *sdata;
94186 struct sta_info *sta;
94187
94188- if (!local->open_count)
94189+ if (!local_read(&local->open_count))
94190 goto suspend;
94191
94192 ieee80211_scan_cancel(local);
94193@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94194 cancel_work_sync(&local->dynamic_ps_enable_work);
94195 del_timer_sync(&local->dynamic_ps_timer);
94196
94197- local->wowlan = wowlan && local->open_count;
94198+ local->wowlan = wowlan && local_read(&local->open_count);
94199 if (local->wowlan) {
94200 int err = drv_suspend(local, wowlan);
94201 if (err < 0) {
94202@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94203 WARN_ON(!list_empty(&local->chanctx_list));
94204
94205 /* stop hardware - this must stop RX */
94206- if (local->open_count)
94207+ if (local_read(&local->open_count))
94208 ieee80211_stop_device(local);
94209
94210 suspend:
94211diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94212index 30d58d2..449ac8e 100644
94213--- a/net/mac80211/rate.c
94214+++ b/net/mac80211/rate.c
94215@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94216
94217 ASSERT_RTNL();
94218
94219- if (local->open_count)
94220+ if (local_read(&local->open_count))
94221 return -EBUSY;
94222
94223 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94224diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94225index c97a065..ff61928 100644
94226--- a/net/mac80211/rc80211_pid_debugfs.c
94227+++ b/net/mac80211/rc80211_pid_debugfs.c
94228@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94229
94230 spin_unlock_irqrestore(&events->lock, status);
94231
94232- if (copy_to_user(buf, pb, p))
94233+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94234 return -EFAULT;
94235
94236 return p;
94237diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94238index 2265445..ba14971 100644
94239--- a/net/mac80211/util.c
94240+++ b/net/mac80211/util.c
94241@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94242 }
94243 #endif
94244 /* everything else happens only if HW was up & running */
94245- if (!local->open_count)
94246+ if (!local_read(&local->open_count))
94247 goto wake_up;
94248
94249 /*
94250@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94251 local->in_reconfig = false;
94252 barrier();
94253
94254- if (local->monitors == local->open_count && local->monitors > 0)
94255+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94256 ieee80211_add_virtual_monitor(local);
94257
94258 /*
94259diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94260index 56d22ca..87c778f 100644
94261--- a/net/netfilter/Kconfig
94262+++ b/net/netfilter/Kconfig
94263@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94264
94265 To compile it as a module, choose M here. If unsure, say N.
94266
94267+config NETFILTER_XT_MATCH_GRADM
94268+ tristate '"gradm" match support'
94269+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94270+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94271+ ---help---
94272+ The gradm match allows to match on grsecurity RBAC being enabled.
94273+ It is useful when iptables rules are applied early on bootup to
94274+ prevent connections to the machine (except from a trusted host)
94275+ while the RBAC system is disabled.
94276+
94277 config NETFILTER_XT_MATCH_HASHLIMIT
94278 tristate '"hashlimit" match support'
94279 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94280diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94281index a1abf87..dbcb7ee 100644
94282--- a/net/netfilter/Makefile
94283+++ b/net/netfilter/Makefile
94284@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94285 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94286 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94287 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94288+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94289 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94290 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94291 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94292diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94293index f771390..145b765 100644
94294--- a/net/netfilter/ipset/ip_set_core.c
94295+++ b/net/netfilter/ipset/ip_set_core.c
94296@@ -1820,7 +1820,7 @@ done:
94297 return ret;
94298 }
94299
94300-static struct nf_sockopt_ops so_set __read_mostly = {
94301+static struct nf_sockopt_ops so_set = {
94302 .pf = PF_INET,
94303 .get_optmin = SO_IP_SET,
94304 .get_optmax = SO_IP_SET + 1,
94305diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94306index 4c8e5c0..5a79b4d 100644
94307--- a/net/netfilter/ipvs/ip_vs_conn.c
94308+++ b/net/netfilter/ipvs/ip_vs_conn.c
94309@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94310 /* Increase the refcnt counter of the dest */
94311 ip_vs_dest_hold(dest);
94312
94313- conn_flags = atomic_read(&dest->conn_flags);
94314+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94315 if (cp->protocol != IPPROTO_UDP)
94316 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94317 flags = cp->flags;
94318@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94319
94320 cp->control = NULL;
94321 atomic_set(&cp->n_control, 0);
94322- atomic_set(&cp->in_pkts, 0);
94323+ atomic_set_unchecked(&cp->in_pkts, 0);
94324
94325 cp->packet_xmit = NULL;
94326 cp->app = NULL;
94327@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94328
94329 /* Don't drop the entry if its number of incoming packets is not
94330 located in [0, 8] */
94331- i = atomic_read(&cp->in_pkts);
94332+ i = atomic_read_unchecked(&cp->in_pkts);
94333 if (i > 8 || i < 0) return 0;
94334
94335 if (!todrop_rate[i]) return 0;
94336diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94337index 4f69e83..da2d8bf 100644
94338--- a/net/netfilter/ipvs/ip_vs_core.c
94339+++ b/net/netfilter/ipvs/ip_vs_core.c
94340@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94341 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94342 /* do not touch skb anymore */
94343
94344- atomic_inc(&cp->in_pkts);
94345+ atomic_inc_unchecked(&cp->in_pkts);
94346 ip_vs_conn_put(cp);
94347 return ret;
94348 }
94349@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94350 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94351 pkts = sysctl_sync_threshold(ipvs);
94352 else
94353- pkts = atomic_add_return(1, &cp->in_pkts);
94354+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94355
94356 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94357 ip_vs_sync_conn(net, cp, pkts);
94358diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94359index c8148e4..eff604f 100644
94360--- a/net/netfilter/ipvs/ip_vs_ctl.c
94361+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94362@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94363 */
94364 ip_vs_rs_hash(ipvs, dest);
94365 }
94366- atomic_set(&dest->conn_flags, conn_flags);
94367+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94368
94369 /* bind the service */
94370 if (!dest->svc) {
94371@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94372 * align with netns init in ip_vs_control_net_init()
94373 */
94374
94375-static struct ctl_table vs_vars[] = {
94376+static ctl_table_no_const vs_vars[] __read_only = {
94377 {
94378 .procname = "amemthresh",
94379 .maxlen = sizeof(int),
94380@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94381 " %-7s %-6d %-10d %-10d\n",
94382 &dest->addr.in6,
94383 ntohs(dest->port),
94384- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94385+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94386 atomic_read(&dest->weight),
94387 atomic_read(&dest->activeconns),
94388 atomic_read(&dest->inactconns));
94389@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94390 "%-7s %-6d %-10d %-10d\n",
94391 ntohl(dest->addr.ip),
94392 ntohs(dest->port),
94393- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94394+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94395 atomic_read(&dest->weight),
94396 atomic_read(&dest->activeconns),
94397 atomic_read(&dest->inactconns));
94398@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94399
94400 entry.addr = dest->addr.ip;
94401 entry.port = dest->port;
94402- entry.conn_flags = atomic_read(&dest->conn_flags);
94403+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94404 entry.weight = atomic_read(&dest->weight);
94405 entry.u_threshold = dest->u_threshold;
94406 entry.l_threshold = dest->l_threshold;
94407@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94408 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94409 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94410 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94411- (atomic_read(&dest->conn_flags) &
94412+ (atomic_read_unchecked(&dest->conn_flags) &
94413 IP_VS_CONN_F_FWD_MASK)) ||
94414 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94415 atomic_read(&dest->weight)) ||
94416@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94417 {
94418 int idx;
94419 struct netns_ipvs *ipvs = net_ipvs(net);
94420- struct ctl_table *tbl;
94421+ ctl_table_no_const *tbl;
94422
94423 atomic_set(&ipvs->dropentry, 0);
94424 spin_lock_init(&ipvs->dropentry_lock);
94425diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94426index 1383b0e..a486da1 100644
94427--- a/net/netfilter/ipvs/ip_vs_lblc.c
94428+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94429@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94430 * IPVS LBLC sysctl table
94431 */
94432 #ifdef CONFIG_SYSCTL
94433-static struct ctl_table vs_vars_table[] = {
94434+static ctl_table_no_const vs_vars_table[] __read_only = {
94435 {
94436 .procname = "lblc_expiration",
94437 .data = NULL,
94438diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94439index 3cd85b2..dfab2b8 100644
94440--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94441+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94442@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94443 * IPVS LBLCR sysctl table
94444 */
94445
94446-static struct ctl_table vs_vars_table[] = {
94447+static ctl_table_no_const vs_vars_table[] __read_only = {
94448 {
94449 .procname = "lblcr_expiration",
94450 .data = NULL,
94451diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94452index f448471..995f131 100644
94453--- a/net/netfilter/ipvs/ip_vs_sync.c
94454+++ b/net/netfilter/ipvs/ip_vs_sync.c
94455@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94456 cp = cp->control;
94457 if (cp) {
94458 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94459- pkts = atomic_add_return(1, &cp->in_pkts);
94460+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94461 else
94462 pkts = sysctl_sync_threshold(ipvs);
94463 ip_vs_sync_conn(net, cp->control, pkts);
94464@@ -771,7 +771,7 @@ control:
94465 if (!cp)
94466 return;
94467 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94468- pkts = atomic_add_return(1, &cp->in_pkts);
94469+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94470 else
94471 pkts = sysctl_sync_threshold(ipvs);
94472 goto sloop;
94473@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94474
94475 if (opt)
94476 memcpy(&cp->in_seq, opt, sizeof(*opt));
94477- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94478+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94479 cp->state = state;
94480 cp->old_state = cp->state;
94481 /*
94482diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94483index c47444e..b0961c6 100644
94484--- a/net/netfilter/ipvs/ip_vs_xmit.c
94485+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94486@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94487 else
94488 rc = NF_ACCEPT;
94489 /* do not touch skb anymore */
94490- atomic_inc(&cp->in_pkts);
94491+ atomic_inc_unchecked(&cp->in_pkts);
94492 goto out;
94493 }
94494
94495@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94496 else
94497 rc = NF_ACCEPT;
94498 /* do not touch skb anymore */
94499- atomic_inc(&cp->in_pkts);
94500+ atomic_inc_unchecked(&cp->in_pkts);
94501 goto out;
94502 }
94503
94504diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94505index 2d3030a..7ba1c0a 100644
94506--- a/net/netfilter/nf_conntrack_acct.c
94507+++ b/net/netfilter/nf_conntrack_acct.c
94508@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94509 #ifdef CONFIG_SYSCTL
94510 static int nf_conntrack_acct_init_sysctl(struct net *net)
94511 {
94512- struct ctl_table *table;
94513+ ctl_table_no_const *table;
94514
94515 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94516 GFP_KERNEL);
94517diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94518index 0283bae..5febcb0 100644
94519--- a/net/netfilter/nf_conntrack_core.c
94520+++ b/net/netfilter/nf_conntrack_core.c
94521@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94522 #define DYING_NULLS_VAL ((1<<30)+1)
94523 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94524
94525+#ifdef CONFIG_GRKERNSEC_HIDESYM
94526+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94527+#endif
94528+
94529 int nf_conntrack_init_net(struct net *net)
94530 {
94531 int ret;
94532@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94533 goto err_stat;
94534 }
94535
94536+#ifdef CONFIG_GRKERNSEC_HIDESYM
94537+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94538+#else
94539 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94540+#endif
94541 if (!net->ct.slabname) {
94542 ret = -ENOMEM;
94543 goto err_slabname;
94544diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94545index 1df1761..ce8b88a 100644
94546--- a/net/netfilter/nf_conntrack_ecache.c
94547+++ b/net/netfilter/nf_conntrack_ecache.c
94548@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94549 #ifdef CONFIG_SYSCTL
94550 static int nf_conntrack_event_init_sysctl(struct net *net)
94551 {
94552- struct ctl_table *table;
94553+ ctl_table_no_const *table;
94554
94555 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94556 GFP_KERNEL);
94557diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94558index 974a2a4..52cc6ff 100644
94559--- a/net/netfilter/nf_conntrack_helper.c
94560+++ b/net/netfilter/nf_conntrack_helper.c
94561@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94562
94563 static int nf_conntrack_helper_init_sysctl(struct net *net)
94564 {
94565- struct ctl_table *table;
94566+ ctl_table_no_const *table;
94567
94568 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94569 GFP_KERNEL);
94570diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94571index 0ab9636..cea3c6a 100644
94572--- a/net/netfilter/nf_conntrack_proto.c
94573+++ b/net/netfilter/nf_conntrack_proto.c
94574@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94575
94576 static void
94577 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94578- struct ctl_table **table,
94579+ ctl_table_no_const **table,
94580 unsigned int users)
94581 {
94582 if (users > 0)
94583diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94584index a99b6c3..cb372f9 100644
94585--- a/net/netfilter/nf_conntrack_proto_dccp.c
94586+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94587@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94588 const char *msg;
94589 u_int8_t state;
94590
94591- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94592+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94593 BUG_ON(dh == NULL);
94594
94595 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94596@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94597 out_invalid:
94598 if (LOG_INVALID(net, IPPROTO_DCCP))
94599 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94600- NULL, msg);
94601+ NULL, "%s", msg);
94602 return false;
94603 }
94604
94605@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94606 u_int8_t type, old_state, new_state;
94607 enum ct_dccp_roles role;
94608
94609- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94610+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94611 BUG_ON(dh == NULL);
94612 type = dh->dccph_type;
94613
94614@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94615 unsigned int cscov;
94616 const char *msg;
94617
94618- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94619+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94620 if (dh == NULL) {
94621 msg = "nf_ct_dccp: short packet ";
94622 goto out_invalid;
94623@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94624
94625 out_invalid:
94626 if (LOG_INVALID(net, IPPROTO_DCCP))
94627- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94628+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94629 return -NF_ACCEPT;
94630 }
94631
94632diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94633index f641751..d3c5b51 100644
94634--- a/net/netfilter/nf_conntrack_standalone.c
94635+++ b/net/netfilter/nf_conntrack_standalone.c
94636@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94637
94638 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94639 {
94640- struct ctl_table *table;
94641+ ctl_table_no_const *table;
94642
94643 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94644 GFP_KERNEL);
94645diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94646index 902fb0a..87f7fdb 100644
94647--- a/net/netfilter/nf_conntrack_timestamp.c
94648+++ b/net/netfilter/nf_conntrack_timestamp.c
94649@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94650 #ifdef CONFIG_SYSCTL
94651 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94652 {
94653- struct ctl_table *table;
94654+ ctl_table_no_const *table;
94655
94656 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94657 GFP_KERNEL);
94658diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94659index 85296d4..8becdec 100644
94660--- a/net/netfilter/nf_log.c
94661+++ b/net/netfilter/nf_log.c
94662@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94663
94664 #ifdef CONFIG_SYSCTL
94665 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94666-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94667+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94668
94669 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94670 void __user *buffer, size_t *lenp, loff_t *ppos)
94671@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94672 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94673 mutex_unlock(&nf_log_mutex);
94674 } else {
94675+ ctl_table_no_const nf_log_table = *table;
94676+
94677 mutex_lock(&nf_log_mutex);
94678 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94679 lockdep_is_held(&nf_log_mutex));
94680 if (!logger)
94681- table->data = "NONE";
94682+ nf_log_table.data = "NONE";
94683 else
94684- table->data = logger->name;
94685- r = proc_dostring(table, write, buffer, lenp, ppos);
94686+ nf_log_table.data = logger->name;
94687+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94688 mutex_unlock(&nf_log_mutex);
94689 }
94690
94691diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94692index f042ae5..30ea486 100644
94693--- a/net/netfilter/nf_sockopt.c
94694+++ b/net/netfilter/nf_sockopt.c
94695@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94696 }
94697 }
94698
94699- list_add(&reg->list, &nf_sockopts);
94700+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94701 out:
94702 mutex_unlock(&nf_sockopt_mutex);
94703 return ret;
94704@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94705 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94706 {
94707 mutex_lock(&nf_sockopt_mutex);
94708- list_del(&reg->list);
94709+ pax_list_del((struct list_head *)&reg->list);
94710 mutex_unlock(&nf_sockopt_mutex);
94711 }
94712 EXPORT_SYMBOL(nf_unregister_sockopt);
94713diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94714index d92cc31..e46f350 100644
94715--- a/net/netfilter/nfnetlink_log.c
94716+++ b/net/netfilter/nfnetlink_log.c
94717@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94718 struct nfnl_log_net {
94719 spinlock_t instances_lock;
94720 struct hlist_head instance_table[INSTANCE_BUCKETS];
94721- atomic_t global_seq;
94722+ atomic_unchecked_t global_seq;
94723 };
94724
94725 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94726@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94727 /* global sequence number */
94728 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94729 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94730- htonl(atomic_inc_return(&log->global_seq))))
94731+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94732 goto nla_put_failure;
94733
94734 if (data_len) {
94735diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94736new file mode 100644
94737index 0000000..c566332
94738--- /dev/null
94739+++ b/net/netfilter/xt_gradm.c
94740@@ -0,0 +1,51 @@
94741+/*
94742+ * gradm match for netfilter
94743