]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.6-201310271552.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.6-201310271552.patch
CommitLineData
95a4865c
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..d3526c1 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,14 +20,14 @@
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-copy_user_generic(void *to, const void *from, unsigned len)
18388+static __always_inline __must_check __size_overflow(3) unsigned long
18389+copy_user_generic(void *to, const void *from, unsigned long len)
18390 {
18391 unsigned ret;
18392
18393@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
18394 return ret;
18395 }
18396
18397+static __always_inline __must_check unsigned long
18398+__copy_to_user(void __user *to, const void *from, unsigned long len);
18399+static __always_inline __must_check unsigned long
18400+__copy_from_user(void *to, const void __user *from, unsigned long len);
18401 __must_check unsigned long
18402-_copy_to_user(void __user *to, const void *from, unsigned len);
18403-__must_check unsigned long
18404-_copy_from_user(void *to, const void __user *from, unsigned len);
18405-__must_check unsigned long
18406-copy_in_user(void __user *to, const void __user *from, unsigned len);
18407+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18408+
18409+extern void copy_to_user_overflow(void)
18410+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18411+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18412+#else
18413+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18414+#endif
18415+;
18416+
18417+extern void copy_from_user_overflow(void)
18418+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18419+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18420+#else
18421+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18422+#endif
18423+;
18424
18425 static inline unsigned long __must_check copy_from_user(void *to,
18426 const void __user *from,
18427 unsigned long n)
18428 {
18429- int sz = __compiletime_object_size(to);
18430-
18431 might_fault();
18432- if (likely(sz == -1 || sz >= n))
18433- n = _copy_from_user(to, from, n);
18434-#ifdef CONFIG_DEBUG_VM
18435- else
18436- WARN(1, "Buffer overflow detected!\n");
18437-#endif
18438+
18439+ check_object_size(to, n, false);
18440+
18441+ if (access_ok(VERIFY_READ, from, n))
18442+ n = __copy_from_user(to, from, n);
18443+ else if (n < INT_MAX)
18444+ memset(to, 0, n);
18445 return n;
18446 }
18447
18448 static __always_inline __must_check
18449-int copy_to_user(void __user *dst, const void *src, unsigned size)
18450+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18451 {
18452 might_fault();
18453
18454- return _copy_to_user(dst, src, size);
18455+ if (access_ok(VERIFY_WRITE, dst, size))
18456+ size = __copy_to_user(dst, src, size);
18457+ return size;
18458 }
18459
18460 static __always_inline __must_check
18461-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18462+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18463 {
18464- int ret = 0;
18465+ size_t sz = __compiletime_object_size(dst);
18466+ unsigned ret = 0;
18467
18468 might_fault();
18469+
18470+ if (size > INT_MAX)
18471+ return size;
18472+
18473+ check_object_size(dst, size, false);
18474+
18475+#ifdef CONFIG_PAX_MEMORY_UDEREF
18476+ if (!__access_ok(VERIFY_READ, src, size))
18477+ return size;
18478+#endif
18479+
18480+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18481+ copy_from_user_overflow();
18482+ return size;
18483+ }
18484+
18485 if (!__builtin_constant_p(size))
18486- return copy_user_generic(dst, (__force void *)src, size);
18487+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18488 switch (size) {
18489- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18490+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18491 ret, "b", "b", "=q", 1);
18492 return ret;
18493- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18494+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18495 ret, "w", "w", "=r", 2);
18496 return ret;
18497- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18498+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18499 ret, "l", "k", "=r", 4);
18500 return ret;
18501- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18502+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18503 ret, "q", "", "=r", 8);
18504 return ret;
18505 case 10:
18506- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18507+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18508 ret, "q", "", "=r", 10);
18509 if (unlikely(ret))
18510 return ret;
18511 __get_user_asm(*(u16 *)(8 + (char *)dst),
18512- (u16 __user *)(8 + (char __user *)src),
18513+ (const u16 __user *)(8 + (const char __user *)src),
18514 ret, "w", "w", "=r", 2);
18515 return ret;
18516 case 16:
18517- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18518+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18519 ret, "q", "", "=r", 16);
18520 if (unlikely(ret))
18521 return ret;
18522 __get_user_asm(*(u64 *)(8 + (char *)dst),
18523- (u64 __user *)(8 + (char __user *)src),
18524+ (const u64 __user *)(8 + (const char __user *)src),
18525 ret, "q", "", "=r", 8);
18526 return ret;
18527 default:
18528- return copy_user_generic(dst, (__force void *)src, size);
18529+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18530 }
18531 }
18532
18533 static __always_inline __must_check
18534-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18535+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18536 {
18537- int ret = 0;
18538+ size_t sz = __compiletime_object_size(src);
18539+ unsigned ret = 0;
18540
18541 might_fault();
18542+
18543+ if (size > INT_MAX)
18544+ return size;
18545+
18546+ check_object_size(src, size, true);
18547+
18548+#ifdef CONFIG_PAX_MEMORY_UDEREF
18549+ if (!__access_ok(VERIFY_WRITE, dst, size))
18550+ return size;
18551+#endif
18552+
18553+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18554+ copy_to_user_overflow();
18555+ return size;
18556+ }
18557+
18558 if (!__builtin_constant_p(size))
18559- return copy_user_generic((__force void *)dst, src, size);
18560+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18561 switch (size) {
18562- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18563+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18564 ret, "b", "b", "iq", 1);
18565 return ret;
18566- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18567+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18568 ret, "w", "w", "ir", 2);
18569 return ret;
18570- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18571+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18572 ret, "l", "k", "ir", 4);
18573 return ret;
18574- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18575+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18576 ret, "q", "", "er", 8);
18577 return ret;
18578 case 10:
18579- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18580+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18581 ret, "q", "", "er", 10);
18582 if (unlikely(ret))
18583 return ret;
18584 asm("":::"memory");
18585- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18586+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18587 ret, "w", "w", "ir", 2);
18588 return ret;
18589 case 16:
18590- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18591+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18592 ret, "q", "", "er", 16);
18593 if (unlikely(ret))
18594 return ret;
18595 asm("":::"memory");
18596- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18597+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18598 ret, "q", "", "er", 8);
18599 return ret;
18600 default:
18601- return copy_user_generic((__force void *)dst, src, size);
18602+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18603 }
18604 }
18605
18606 static __always_inline __must_check
18607-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18608+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18609 {
18610- int ret = 0;
18611+ unsigned ret = 0;
18612
18613 might_fault();
18614+
18615+ if (size > INT_MAX)
18616+ return size;
18617+
18618+#ifdef CONFIG_PAX_MEMORY_UDEREF
18619+ if (!__access_ok(VERIFY_READ, src, size))
18620+ return size;
18621+ if (!__access_ok(VERIFY_WRITE, dst, size))
18622+ return size;
18623+#endif
18624+
18625 if (!__builtin_constant_p(size))
18626- return copy_user_generic((__force void *)dst,
18627- (__force void *)src, size);
18628+ return copy_user_generic((__force_kernel void *)____m(dst),
18629+ (__force_kernel const void *)____m(src), size);
18630 switch (size) {
18631 case 1: {
18632 u8 tmp;
18633- __get_user_asm(tmp, (u8 __user *)src,
18634+ __get_user_asm(tmp, (const u8 __user *)src,
18635 ret, "b", "b", "=q", 1);
18636 if (likely(!ret))
18637 __put_user_asm(tmp, (u8 __user *)dst,
18638@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18639 }
18640 case 2: {
18641 u16 tmp;
18642- __get_user_asm(tmp, (u16 __user *)src,
18643+ __get_user_asm(tmp, (const u16 __user *)src,
18644 ret, "w", "w", "=r", 2);
18645 if (likely(!ret))
18646 __put_user_asm(tmp, (u16 __user *)dst,
18647@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18648
18649 case 4: {
18650 u32 tmp;
18651- __get_user_asm(tmp, (u32 __user *)src,
18652+ __get_user_asm(tmp, (const u32 __user *)src,
18653 ret, "l", "k", "=r", 4);
18654 if (likely(!ret))
18655 __put_user_asm(tmp, (u32 __user *)dst,
18656@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18657 }
18658 case 8: {
18659 u64 tmp;
18660- __get_user_asm(tmp, (u64 __user *)src,
18661+ __get_user_asm(tmp, (const u64 __user *)src,
18662 ret, "q", "", "=r", 8);
18663 if (likely(!ret))
18664 __put_user_asm(tmp, (u64 __user *)dst,
18665@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18666 return ret;
18667 }
18668 default:
18669- return copy_user_generic((__force void *)dst,
18670- (__force void *)src, size);
18671+ return copy_user_generic((__force_kernel void *)____m(dst),
18672+ (__force_kernel const void *)____m(src), size);
18673 }
18674 }
18675
18676-static __must_check __always_inline int
18677-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18678+static __must_check __always_inline unsigned long
18679+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18680 {
18681- return copy_user_generic(dst, (__force const void *)src, size);
18682+ if (size > INT_MAX)
18683+ return size;
18684+
18685+#ifdef CONFIG_PAX_MEMORY_UDEREF
18686+ if (!__access_ok(VERIFY_READ, src, size))
18687+ return size;
18688+#endif
18689+
18690+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18691 }
18692
18693-static __must_check __always_inline int
18694-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18695+static __must_check __always_inline unsigned long
18696+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18697 {
18698- return copy_user_generic((__force void *)dst, src, size);
18699+ if (size > INT_MAX)
18700+ return size;
18701+
18702+#ifdef CONFIG_PAX_MEMORY_UDEREF
18703+ if (!__access_ok(VERIFY_WRITE, dst, size))
18704+ return size;
18705+#endif
18706+
18707+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18708 }
18709
18710-extern long __copy_user_nocache(void *dst, const void __user *src,
18711- unsigned size, int zerorest);
18712+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18713+ unsigned long size, int zerorest) __size_overflow(3);
18714
18715-static inline int
18716-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18717+static inline unsigned long
18718+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18719 {
18720 might_fault();
18721+
18722+ if (size > INT_MAX)
18723+ return size;
18724+
18725+#ifdef CONFIG_PAX_MEMORY_UDEREF
18726+ if (!__access_ok(VERIFY_READ, src, size))
18727+ return size;
18728+#endif
18729+
18730 return __copy_user_nocache(dst, src, size, 1);
18731 }
18732
18733-static inline int
18734+static inline unsigned long
18735 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18736- unsigned size)
18737+ unsigned long size)
18738 {
18739+ if (size > INT_MAX)
18740+ return size;
18741+
18742+#ifdef CONFIG_PAX_MEMORY_UDEREF
18743+ if (!__access_ok(VERIFY_READ, src, size))
18744+ return size;
18745+#endif
18746+
18747 return __copy_user_nocache(dst, src, size, 0);
18748 }
18749
18750 unsigned long
18751-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18752+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18753
18754 #endif /* _ASM_X86_UACCESS_64_H */
18755diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18756index 5b238981..77fdd78 100644
18757--- a/arch/x86/include/asm/word-at-a-time.h
18758+++ b/arch/x86/include/asm/word-at-a-time.h
18759@@ -11,7 +11,7 @@
18760 * and shift, for example.
18761 */
18762 struct word_at_a_time {
18763- const unsigned long one_bits, high_bits;
18764+ unsigned long one_bits, high_bits;
18765 };
18766
18767 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18768diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18769index 828a156..650e625 100644
18770--- a/arch/x86/include/asm/x86_init.h
18771+++ b/arch/x86/include/asm/x86_init.h
18772@@ -129,7 +129,7 @@ struct x86_init_ops {
18773 struct x86_init_timers timers;
18774 struct x86_init_iommu iommu;
18775 struct x86_init_pci pci;
18776-};
18777+} __no_const;
18778
18779 /**
18780 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18781@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18782 void (*setup_percpu_clockev)(void);
18783 void (*early_percpu_clock_init)(void);
18784 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18785-};
18786+} __no_const;
18787
18788 struct timespec;
18789
18790@@ -168,7 +168,7 @@ struct x86_platform_ops {
18791 void (*save_sched_clock_state)(void);
18792 void (*restore_sched_clock_state)(void);
18793 void (*apic_post_init)(void);
18794-};
18795+} __no_const;
18796
18797 struct pci_dev;
18798 struct msi_msg;
18799@@ -182,7 +182,7 @@ struct x86_msi_ops {
18800 void (*teardown_msi_irqs)(struct pci_dev *dev);
18801 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18802 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18803-};
18804+} __no_const;
18805
18806 struct IO_APIC_route_entry;
18807 struct io_apic_irq_attr;
18808@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18809 unsigned int destination, int vector,
18810 struct io_apic_irq_attr *attr);
18811 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18812-};
18813+} __no_const;
18814
18815 extern struct x86_init_ops x86_init;
18816 extern struct x86_cpuinit_ops x86_cpuinit;
18817diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18818index 0415cda..3b22adc 100644
18819--- a/arch/x86/include/asm/xsave.h
18820+++ b/arch/x86/include/asm/xsave.h
18821@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18822 if (unlikely(err))
18823 return -EFAULT;
18824
18825+ pax_open_userland();
18826 __asm__ __volatile__(ASM_STAC "\n"
18827- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18828+ "1:"
18829+ __copyuser_seg
18830+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18831 "2: " ASM_CLAC "\n"
18832 ".section .fixup,\"ax\"\n"
18833 "3: movl $-1,%[err]\n"
18834@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18835 : [err] "=r" (err)
18836 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18837 : "memory");
18838+ pax_close_userland();
18839 return err;
18840 }
18841
18842 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18843 {
18844 int err;
18845- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18846+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18847 u32 lmask = mask;
18848 u32 hmask = mask >> 32;
18849
18850+ pax_open_userland();
18851 __asm__ __volatile__(ASM_STAC "\n"
18852- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18853+ "1:"
18854+ __copyuser_seg
18855+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18856 "2: " ASM_CLAC "\n"
18857 ".section .fixup,\"ax\"\n"
18858 "3: movl $-1,%[err]\n"
18859@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18860 : [err] "=r" (err)
18861 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18862 : "memory"); /* memory required? */
18863+ pax_close_userland();
18864 return err;
18865 }
18866
18867diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18868index bbae024..e1528f9 100644
18869--- a/arch/x86/include/uapi/asm/e820.h
18870+++ b/arch/x86/include/uapi/asm/e820.h
18871@@ -63,7 +63,7 @@ struct e820map {
18872 #define ISA_START_ADDRESS 0xa0000
18873 #define ISA_END_ADDRESS 0x100000
18874
18875-#define BIOS_BEGIN 0x000a0000
18876+#define BIOS_BEGIN 0x000c0000
18877 #define BIOS_END 0x00100000
18878
18879 #define BIOS_ROM_BASE 0xffe00000
18880diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18881index 88d99ea..9fc7e17 100644
18882--- a/arch/x86/kernel/Makefile
18883+++ b/arch/x86/kernel/Makefile
18884@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18885 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18886 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18887 obj-y += probe_roms.o
18888-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18889+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18890 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18891 obj-y += syscall_$(BITS).o
18892 obj-$(CONFIG_X86_64) += vsyscall_64.o
18893diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18894index 2627a81..cd8325e 100644
18895--- a/arch/x86/kernel/acpi/boot.c
18896+++ b/arch/x86/kernel/acpi/boot.c
18897@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18898 * If your system is blacklisted here, but you find that acpi=force
18899 * works for you, please contact linux-acpi@vger.kernel.org
18900 */
18901-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18902+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18903 /*
18904 * Boxes that need ACPI disabled
18905 */
18906@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18907 };
18908
18909 /* second table for DMI checks that should run after early-quirks */
18910-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18911+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18912 /*
18913 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18914 * which includes some code which overrides all temperature
18915diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18916index 3312010..a65ca7b 100644
18917--- a/arch/x86/kernel/acpi/sleep.c
18918+++ b/arch/x86/kernel/acpi/sleep.c
18919@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18920 #else /* CONFIG_64BIT */
18921 #ifdef CONFIG_SMP
18922 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18923+
18924+ pax_open_kernel();
18925 early_gdt_descr.address =
18926 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18927+ pax_close_kernel();
18928+
18929 initial_gs = per_cpu_offset(smp_processor_id());
18930 #endif
18931 initial_code = (unsigned long)wakeup_long64;
18932diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18933index d1daa66..59fecba 100644
18934--- a/arch/x86/kernel/acpi/wakeup_32.S
18935+++ b/arch/x86/kernel/acpi/wakeup_32.S
18936@@ -29,13 +29,11 @@ wakeup_pmode_return:
18937 # and restore the stack ... but you need gdt for this to work
18938 movl saved_context_esp, %esp
18939
18940- movl %cs:saved_magic, %eax
18941- cmpl $0x12345678, %eax
18942+ cmpl $0x12345678, saved_magic
18943 jne bogus_magic
18944
18945 # jump to place where we left off
18946- movl saved_eip, %eax
18947- jmp *%eax
18948+ jmp *(saved_eip)
18949
18950 bogus_magic:
18951 jmp bogus_magic
18952diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18953index c15cf9a..0e63558 100644
18954--- a/arch/x86/kernel/alternative.c
18955+++ b/arch/x86/kernel/alternative.c
18956@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18957 */
18958 for (a = start; a < end; a++) {
18959 instr = (u8 *)&a->instr_offset + a->instr_offset;
18960+
18961+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18962+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18963+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18964+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18965+#endif
18966+
18967 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18968 BUG_ON(a->replacementlen > a->instrlen);
18969 BUG_ON(a->instrlen > sizeof(insnbuf));
18970@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18971 for (poff = start; poff < end; poff++) {
18972 u8 *ptr = (u8 *)poff + *poff;
18973
18974+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18975+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18976+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18977+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18978+#endif
18979+
18980 if (!*poff || ptr < text || ptr >= text_end)
18981 continue;
18982 /* turn DS segment override prefix into lock prefix */
18983- if (*ptr == 0x3e)
18984+ if (*ktla_ktva(ptr) == 0x3e)
18985 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18986 }
18987 mutex_unlock(&text_mutex);
18988@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18989 for (poff = start; poff < end; poff++) {
18990 u8 *ptr = (u8 *)poff + *poff;
18991
18992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18993+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18994+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18995+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18996+#endif
18997+
18998 if (!*poff || ptr < text || ptr >= text_end)
18999 continue;
19000 /* turn lock prefix into DS segment override prefix */
19001- if (*ptr == 0xf0)
19002+ if (*ktla_ktva(ptr) == 0xf0)
19003 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19004 }
19005 mutex_unlock(&text_mutex);
19006@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19007
19008 BUG_ON(p->len > MAX_PATCH_LEN);
19009 /* prep the buffer with the original instructions */
19010- memcpy(insnbuf, p->instr, p->len);
19011+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19012 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19013 (unsigned long)p->instr, p->len);
19014
19015@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19016 if (!uniproc_patched || num_possible_cpus() == 1)
19017 free_init_pages("SMP alternatives",
19018 (unsigned long)__smp_locks,
19019- (unsigned long)__smp_locks_end);
19020+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19021 #endif
19022
19023 apply_paravirt(__parainstructions, __parainstructions_end);
19024@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19025 * instructions. And on the local CPU you need to be protected again NMI or MCE
19026 * handlers seeing an inconsistent instruction while you patch.
19027 */
19028-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19029+void *__kprobes text_poke_early(void *addr, const void *opcode,
19030 size_t len)
19031 {
19032 unsigned long flags;
19033 local_irq_save(flags);
19034- memcpy(addr, opcode, len);
19035+
19036+ pax_open_kernel();
19037+ memcpy(ktla_ktva(addr), opcode, len);
19038 sync_core();
19039+ pax_close_kernel();
19040+
19041 local_irq_restore(flags);
19042 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19043 that causes hangs on some VIA CPUs. */
19044@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19045 */
19046 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19047 {
19048- unsigned long flags;
19049- char *vaddr;
19050+ unsigned char *vaddr = ktla_ktva(addr);
19051 struct page *pages[2];
19052- int i;
19053+ size_t i;
19054
19055 if (!core_kernel_text((unsigned long)addr)) {
19056- pages[0] = vmalloc_to_page(addr);
19057- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19058+ pages[0] = vmalloc_to_page(vaddr);
19059+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19060 } else {
19061- pages[0] = virt_to_page(addr);
19062+ pages[0] = virt_to_page(vaddr);
19063 WARN_ON(!PageReserved(pages[0]));
19064- pages[1] = virt_to_page(addr + PAGE_SIZE);
19065+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19066 }
19067 BUG_ON(!pages[0]);
19068- local_irq_save(flags);
19069- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19070- if (pages[1])
19071- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19072- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19073- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19074- clear_fixmap(FIX_TEXT_POKE0);
19075- if (pages[1])
19076- clear_fixmap(FIX_TEXT_POKE1);
19077- local_flush_tlb();
19078- sync_core();
19079- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19080- that causes hangs on some VIA CPUs. */
19081+ text_poke_early(addr, opcode, len);
19082 for (i = 0; i < len; i++)
19083- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19084- local_irq_restore(flags);
19085+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19086 return addr;
19087 }
19088
19089diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19090index eca89c5..d566b78 100644
19091--- a/arch/x86/kernel/apic/apic.c
19092+++ b/arch/x86/kernel/apic/apic.c
19093@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19094 /*
19095 * Debug level, exported for io_apic.c
19096 */
19097-unsigned int apic_verbosity;
19098+int apic_verbosity;
19099
19100 int pic_mode;
19101
19102@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19103 apic_write(APIC_ESR, 0);
19104 v1 = apic_read(APIC_ESR);
19105 ack_APIC_irq();
19106- atomic_inc(&irq_err_count);
19107+ atomic_inc_unchecked(&irq_err_count);
19108
19109 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19110 smp_processor_id(), v0 , v1);
19111diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19112index 00c77cf..2dc6a2d 100644
19113--- a/arch/x86/kernel/apic/apic_flat_64.c
19114+++ b/arch/x86/kernel/apic/apic_flat_64.c
19115@@ -157,7 +157,7 @@ static int flat_probe(void)
19116 return 1;
19117 }
19118
19119-static struct apic apic_flat = {
19120+static struct apic apic_flat __read_only = {
19121 .name = "flat",
19122 .probe = flat_probe,
19123 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19124@@ -271,7 +271,7 @@ static int physflat_probe(void)
19125 return 0;
19126 }
19127
19128-static struct apic apic_physflat = {
19129+static struct apic apic_physflat __read_only = {
19130
19131 .name = "physical flat",
19132 .probe = physflat_probe,
19133diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19134index e145f28..2752888 100644
19135--- a/arch/x86/kernel/apic/apic_noop.c
19136+++ b/arch/x86/kernel/apic/apic_noop.c
19137@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19138 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19139 }
19140
19141-struct apic apic_noop = {
19142+struct apic apic_noop __read_only = {
19143 .name = "noop",
19144 .probe = noop_probe,
19145 .acpi_madt_oem_check = NULL,
19146diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19147index d50e364..543bee3 100644
19148--- a/arch/x86/kernel/apic/bigsmp_32.c
19149+++ b/arch/x86/kernel/apic/bigsmp_32.c
19150@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19151 return dmi_bigsmp;
19152 }
19153
19154-static struct apic apic_bigsmp = {
19155+static struct apic apic_bigsmp __read_only = {
19156
19157 .name = "bigsmp",
19158 .probe = probe_bigsmp,
19159diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19160index c552247..587a316 100644
19161--- a/arch/x86/kernel/apic/es7000_32.c
19162+++ b/arch/x86/kernel/apic/es7000_32.c
19163@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19164 return ret && es7000_apic_is_cluster();
19165 }
19166
19167-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19168-static struct apic __refdata apic_es7000_cluster = {
19169+static struct apic apic_es7000_cluster __read_only = {
19170
19171 .name = "es7000",
19172 .probe = probe_es7000,
19173@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19174 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19175 };
19176
19177-static struct apic __refdata apic_es7000 = {
19178+static struct apic apic_es7000 __read_only = {
19179
19180 .name = "es7000",
19181 .probe = probe_es7000,
19182diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19183index 9ed796c..e930fe4 100644
19184--- a/arch/x86/kernel/apic/io_apic.c
19185+++ b/arch/x86/kernel/apic/io_apic.c
19186@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19187 }
19188 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19189
19190-void lock_vector_lock(void)
19191+void lock_vector_lock(void) __acquires(vector_lock)
19192 {
19193 /* Used to the online set of cpus does not change
19194 * during assign_irq_vector.
19195@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19196 raw_spin_lock(&vector_lock);
19197 }
19198
19199-void unlock_vector_lock(void)
19200+void unlock_vector_lock(void) __releases(vector_lock)
19201 {
19202 raw_spin_unlock(&vector_lock);
19203 }
19204@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19205 ack_APIC_irq();
19206 }
19207
19208-atomic_t irq_mis_count;
19209+atomic_unchecked_t irq_mis_count;
19210
19211 #ifdef CONFIG_GENERIC_PENDING_IRQ
19212 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19213@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19214 * at the cpu.
19215 */
19216 if (!(v & (1 << (i & 0x1f)))) {
19217- atomic_inc(&irq_mis_count);
19218+ atomic_inc_unchecked(&irq_mis_count);
19219
19220 eoi_ioapic_irq(irq, cfg);
19221 }
19222diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19223index 1e42e8f..daacf44 100644
19224--- a/arch/x86/kernel/apic/numaq_32.c
19225+++ b/arch/x86/kernel/apic/numaq_32.c
19226@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19227 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19228 }
19229
19230-/* Use __refdata to keep false positive warning calm. */
19231-static struct apic __refdata apic_numaq = {
19232+static struct apic apic_numaq __read_only = {
19233
19234 .name = "NUMAQ",
19235 .probe = probe_numaq,
19236diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19237index eb35ef9..f184a21 100644
19238--- a/arch/x86/kernel/apic/probe_32.c
19239+++ b/arch/x86/kernel/apic/probe_32.c
19240@@ -72,7 +72,7 @@ static int probe_default(void)
19241 return 1;
19242 }
19243
19244-static struct apic apic_default = {
19245+static struct apic apic_default __read_only = {
19246
19247 .name = "default",
19248 .probe = probe_default,
19249diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19250index 77c95c0..434f8a4 100644
19251--- a/arch/x86/kernel/apic/summit_32.c
19252+++ b/arch/x86/kernel/apic/summit_32.c
19253@@ -486,7 +486,7 @@ void setup_summit(void)
19254 }
19255 #endif
19256
19257-static struct apic apic_summit = {
19258+static struct apic apic_summit __read_only = {
19259
19260 .name = "summit",
19261 .probe = probe_summit,
19262diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19263index 140e29d..d88bc95 100644
19264--- a/arch/x86/kernel/apic/x2apic_cluster.c
19265+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19266@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19267 return notifier_from_errno(err);
19268 }
19269
19270-static struct notifier_block __refdata x2apic_cpu_notifier = {
19271+static struct notifier_block x2apic_cpu_notifier = {
19272 .notifier_call = update_clusterinfo,
19273 };
19274
19275@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19276 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19277 }
19278
19279-static struct apic apic_x2apic_cluster = {
19280+static struct apic apic_x2apic_cluster __read_only = {
19281
19282 .name = "cluster x2apic",
19283 .probe = x2apic_cluster_probe,
19284diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19285index 562a76d..a003c0f 100644
19286--- a/arch/x86/kernel/apic/x2apic_phys.c
19287+++ b/arch/x86/kernel/apic/x2apic_phys.c
19288@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19289 return apic == &apic_x2apic_phys;
19290 }
19291
19292-static struct apic apic_x2apic_phys = {
19293+static struct apic apic_x2apic_phys __read_only = {
19294
19295 .name = "physical x2apic",
19296 .probe = x2apic_phys_probe,
19297diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19298index 1191ac1..2335fa4 100644
19299--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19300+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19301@@ -357,7 +357,7 @@ static int uv_probe(void)
19302 return apic == &apic_x2apic_uv_x;
19303 }
19304
19305-static struct apic __refdata apic_x2apic_uv_x = {
19306+static struct apic apic_x2apic_uv_x __read_only = {
19307
19308 .name = "UV large system",
19309 .probe = uv_probe,
19310diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19311index 53a4e27..038760a 100644
19312--- a/arch/x86/kernel/apm_32.c
19313+++ b/arch/x86/kernel/apm_32.c
19314@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19315 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19316 * even though they are called in protected mode.
19317 */
19318-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19319+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19320 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19321
19322 static const char driver_version[] = "1.16ac"; /* no spaces */
19323@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19324 BUG_ON(cpu != 0);
19325 gdt = get_cpu_gdt_table(cpu);
19326 save_desc_40 = gdt[0x40 / 8];
19327+
19328+ pax_open_kernel();
19329 gdt[0x40 / 8] = bad_bios_desc;
19330+ pax_close_kernel();
19331
19332 apm_irq_save(flags);
19333 APM_DO_SAVE_SEGS;
19334@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19335 &call->esi);
19336 APM_DO_RESTORE_SEGS;
19337 apm_irq_restore(flags);
19338+
19339+ pax_open_kernel();
19340 gdt[0x40 / 8] = save_desc_40;
19341+ pax_close_kernel();
19342+
19343 put_cpu();
19344
19345 return call->eax & 0xff;
19346@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19347 BUG_ON(cpu != 0);
19348 gdt = get_cpu_gdt_table(cpu);
19349 save_desc_40 = gdt[0x40 / 8];
19350+
19351+ pax_open_kernel();
19352 gdt[0x40 / 8] = bad_bios_desc;
19353+ pax_close_kernel();
19354
19355 apm_irq_save(flags);
19356 APM_DO_SAVE_SEGS;
19357@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19358 &call->eax);
19359 APM_DO_RESTORE_SEGS;
19360 apm_irq_restore(flags);
19361+
19362+ pax_open_kernel();
19363 gdt[0x40 / 8] = save_desc_40;
19364+ pax_close_kernel();
19365+
19366 put_cpu();
19367 return error;
19368 }
19369@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19370 * code to that CPU.
19371 */
19372 gdt = get_cpu_gdt_table(0);
19373+
19374+ pax_open_kernel();
19375 set_desc_base(&gdt[APM_CS >> 3],
19376 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19377 set_desc_base(&gdt[APM_CS_16 >> 3],
19378 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19379 set_desc_base(&gdt[APM_DS >> 3],
19380 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19381+ pax_close_kernel();
19382
19383 proc_create("apm", 0, NULL, &apm_file_ops);
19384
19385diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19386index 2861082..6d4718e 100644
19387--- a/arch/x86/kernel/asm-offsets.c
19388+++ b/arch/x86/kernel/asm-offsets.c
19389@@ -33,6 +33,8 @@ void common(void) {
19390 OFFSET(TI_status, thread_info, status);
19391 OFFSET(TI_addr_limit, thread_info, addr_limit);
19392 OFFSET(TI_preempt_count, thread_info, preempt_count);
19393+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19394+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19395
19396 BLANK();
19397 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19398@@ -53,8 +55,26 @@ void common(void) {
19399 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19400 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19401 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19402+
19403+#ifdef CONFIG_PAX_KERNEXEC
19404+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19405 #endif
19406
19407+#ifdef CONFIG_PAX_MEMORY_UDEREF
19408+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19409+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19410+#ifdef CONFIG_X86_64
19411+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19412+#endif
19413+#endif
19414+
19415+#endif
19416+
19417+ BLANK();
19418+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19419+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19420+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19421+
19422 #ifdef CONFIG_XEN
19423 BLANK();
19424 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19425diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19426index e7c798b..2b2019b 100644
19427--- a/arch/x86/kernel/asm-offsets_64.c
19428+++ b/arch/x86/kernel/asm-offsets_64.c
19429@@ -77,6 +77,7 @@ int main(void)
19430 BLANK();
19431 #undef ENTRY
19432
19433+ DEFINE(TSS_size, sizeof(struct tss_struct));
19434 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19435 BLANK();
19436
19437diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19438index 47b56a7..efc2bc6 100644
19439--- a/arch/x86/kernel/cpu/Makefile
19440+++ b/arch/x86/kernel/cpu/Makefile
19441@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19442 CFLAGS_REMOVE_perf_event.o = -pg
19443 endif
19444
19445-# Make sure load_percpu_segment has no stackprotector
19446-nostackp := $(call cc-option, -fno-stack-protector)
19447-CFLAGS_common.o := $(nostackp)
19448-
19449 obj-y := intel_cacheinfo.o scattered.o topology.o
19450 obj-y += proc.o capflags.o powerflags.o common.o
19451 obj-y += rdrand.o
19452diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19453index 08a0890..e557865 100644
19454--- a/arch/x86/kernel/cpu/amd.c
19455+++ b/arch/x86/kernel/cpu/amd.c
19456@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19457 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19458 {
19459 /* AMD errata T13 (order #21922) */
19460- if ((c->x86 == 6)) {
19461+ if (c->x86 == 6) {
19462 /* Duron Rev A0 */
19463 if (c->x86_model == 3 && c->x86_mask == 0)
19464 size = 64;
19465diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19466index 25eb274..3a92d93 100644
19467--- a/arch/x86/kernel/cpu/common.c
19468+++ b/arch/x86/kernel/cpu/common.c
19469@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19470
19471 static const struct cpu_dev *this_cpu = &default_cpu;
19472
19473-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19474-#ifdef CONFIG_X86_64
19475- /*
19476- * We need valid kernel segments for data and code in long mode too
19477- * IRET will check the segment types kkeil 2000/10/28
19478- * Also sysret mandates a special GDT layout
19479- *
19480- * TLS descriptors are currently at a different place compared to i386.
19481- * Hopefully nobody expects them at a fixed place (Wine?)
19482- */
19483- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19484- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19485- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19486- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19487- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19488- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19489-#else
19490- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19491- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19492- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19493- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19494- /*
19495- * Segments used for calling PnP BIOS have byte granularity.
19496- * They code segments and data segments have fixed 64k limits,
19497- * the transfer segment sizes are set at run time.
19498- */
19499- /* 32-bit code */
19500- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19501- /* 16-bit code */
19502- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19503- /* 16-bit data */
19504- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19505- /* 16-bit data */
19506- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19507- /* 16-bit data */
19508- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19509- /*
19510- * The APM segments have byte granularity and their bases
19511- * are set at run time. All have 64k limits.
19512- */
19513- /* 32-bit code */
19514- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19515- /* 16-bit code */
19516- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19517- /* data */
19518- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19519-
19520- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19521- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19522- GDT_STACK_CANARY_INIT
19523-#endif
19524-} };
19525-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19526-
19527 static int __init x86_xsave_setup(char *s)
19528 {
19529 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19530@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19531 set_in_cr4(X86_CR4_SMAP);
19532 }
19533
19534+#ifdef CONFIG_X86_64
19535+static __init int setup_disable_pcid(char *arg)
19536+{
19537+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19538+
19539+#ifdef CONFIG_PAX_MEMORY_UDEREF
19540+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19541+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19542+#endif
19543+
19544+ return 1;
19545+}
19546+__setup("nopcid", setup_disable_pcid);
19547+
19548+static void setup_pcid(struct cpuinfo_x86 *c)
19549+{
19550+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19551+
19552+#ifdef CONFIG_PAX_MEMORY_UDEREF
19553+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19554+ pax_open_kernel();
19555+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19556+ pax_close_kernel();
19557+ printk("PAX: slow and weak UDEREF enabled\n");
19558+ } else
19559+ printk("PAX: UDEREF disabled\n");
19560+#endif
19561+
19562+ return;
19563+ }
19564+
19565+ printk("PAX: PCID detected\n");
19566+ set_in_cr4(X86_CR4_PCIDE);
19567+
19568+#ifdef CONFIG_PAX_MEMORY_UDEREF
19569+ pax_open_kernel();
19570+ clone_pgd_mask = ~(pgdval_t)0UL;
19571+ pax_close_kernel();
19572+ if (pax_user_shadow_base)
19573+ printk("PAX: weak UDEREF enabled\n");
19574+ else {
19575+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19576+ printk("PAX: strong UDEREF enabled\n");
19577+ }
19578+#endif
19579+
19580+ if (cpu_has(c, X86_FEATURE_INVPCID))
19581+ printk("PAX: INVPCID detected\n");
19582+}
19583+#endif
19584+
19585 /*
19586 * Some CPU features depend on higher CPUID levels, which may not always
19587 * be available due to CPUID level capping or broken virtualization
19588@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19589 {
19590 struct desc_ptr gdt_descr;
19591
19592- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19593+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19594 gdt_descr.size = GDT_SIZE - 1;
19595 load_gdt(&gdt_descr);
19596 /* Reload the per-cpu base */
19597@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19598 setup_smep(c);
19599 setup_smap(c);
19600
19601+#ifdef CONFIG_X86_64
19602+ setup_pcid(c);
19603+#endif
19604+
19605 /*
19606 * The vendor-specific functions might have changed features.
19607 * Now we do "generic changes."
19608@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19609 /* Filter out anything that depends on CPUID levels we don't have */
19610 filter_cpuid_features(c, true);
19611
19612+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19613+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19614+#endif
19615+
19616 /* If the model name is still unset, do table lookup. */
19617 if (!c->x86_model_id[0]) {
19618 const char *p;
19619@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19620 }
19621 __setup("clearcpuid=", setup_disablecpuid);
19622
19623+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19624+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19625+
19626 #ifdef CONFIG_X86_64
19627-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19628-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19629- (unsigned long) debug_idt_table };
19630+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19631+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19632
19633 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19634 irq_stack_union) __aligned(PAGE_SIZE);
19635@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19636 EXPORT_PER_CPU_SYMBOL(current_task);
19637
19638 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19639- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19640+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19641 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19642
19643 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19644@@ -1232,7 +1239,7 @@ void cpu_init(void)
19645 load_ucode_ap();
19646
19647 cpu = stack_smp_processor_id();
19648- t = &per_cpu(init_tss, cpu);
19649+ t = init_tss + cpu;
19650 oist = &per_cpu(orig_ist, cpu);
19651
19652 #ifdef CONFIG_NUMA
19653@@ -1267,7 +1274,6 @@ void cpu_init(void)
19654 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19655 barrier();
19656
19657- x86_configure_nx();
19658 enable_x2apic();
19659
19660 /*
19661@@ -1319,7 +1325,7 @@ void cpu_init(void)
19662 {
19663 int cpu = smp_processor_id();
19664 struct task_struct *curr = current;
19665- struct tss_struct *t = &per_cpu(init_tss, cpu);
19666+ struct tss_struct *t = init_tss + cpu;
19667 struct thread_struct *thread = &curr->thread;
19668
19669 show_ucode_info_early();
19670diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19671index 1414c90..1159406 100644
19672--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19673+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19674@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19675 };
19676
19677 #ifdef CONFIG_AMD_NB
19678+static struct attribute *default_attrs_amd_nb[] = {
19679+ &type.attr,
19680+ &level.attr,
19681+ &coherency_line_size.attr,
19682+ &physical_line_partition.attr,
19683+ &ways_of_associativity.attr,
19684+ &number_of_sets.attr,
19685+ &size.attr,
19686+ &shared_cpu_map.attr,
19687+ &shared_cpu_list.attr,
19688+ NULL,
19689+ NULL,
19690+ NULL,
19691+ NULL
19692+};
19693+
19694 static struct attribute **amd_l3_attrs(void)
19695 {
19696 static struct attribute **attrs;
19697@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19698
19699 n = ARRAY_SIZE(default_attrs);
19700
19701- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19702- n += 2;
19703-
19704- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19705- n += 1;
19706-
19707- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19708- if (attrs == NULL)
19709- return attrs = default_attrs;
19710-
19711- for (n = 0; default_attrs[n]; n++)
19712- attrs[n] = default_attrs[n];
19713+ attrs = default_attrs_amd_nb;
19714
19715 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19716 attrs[n++] = &cache_disable_0.attr;
19717@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19718 .default_attrs = default_attrs,
19719 };
19720
19721+#ifdef CONFIG_AMD_NB
19722+static struct kobj_type ktype_cache_amd_nb = {
19723+ .sysfs_ops = &sysfs_ops,
19724+ .default_attrs = default_attrs_amd_nb,
19725+};
19726+#endif
19727+
19728 static struct kobj_type ktype_percpu_entry = {
19729 .sysfs_ops = &sysfs_ops,
19730 };
19731@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19732 return retval;
19733 }
19734
19735+#ifdef CONFIG_AMD_NB
19736+ amd_l3_attrs();
19737+#endif
19738+
19739 for (i = 0; i < num_cache_leaves; i++) {
19740+ struct kobj_type *ktype;
19741+
19742 this_object = INDEX_KOBJECT_PTR(cpu, i);
19743 this_object->cpu = cpu;
19744 this_object->index = i;
19745
19746 this_leaf = CPUID4_INFO_IDX(cpu, i);
19747
19748- ktype_cache.default_attrs = default_attrs;
19749+ ktype = &ktype_cache;
19750 #ifdef CONFIG_AMD_NB
19751 if (this_leaf->base.nb)
19752- ktype_cache.default_attrs = amd_l3_attrs();
19753+ ktype = &ktype_cache_amd_nb;
19754 #endif
19755 retval = kobject_init_and_add(&(this_object->kobj),
19756- &ktype_cache,
19757+ ktype,
19758 per_cpu(ici_cache_kobject, cpu),
19759 "index%1lu", i);
19760 if (unlikely(retval)) {
19761diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19762index 87a65c9..92fcce6 100644
19763--- a/arch/x86/kernel/cpu/mcheck/mce.c
19764+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19765@@ -45,6 +45,7 @@
19766 #include <asm/processor.h>
19767 #include <asm/mce.h>
19768 #include <asm/msr.h>
19769+#include <asm/local.h>
19770
19771 #include "mce-internal.h"
19772
19773@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19774 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19775 m->cs, m->ip);
19776
19777- if (m->cs == __KERNEL_CS)
19778+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19779 print_symbol("{%s}", m->ip);
19780 pr_cont("\n");
19781 }
19782@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19783
19784 #define PANIC_TIMEOUT 5 /* 5 seconds */
19785
19786-static atomic_t mce_paniced;
19787+static atomic_unchecked_t mce_paniced;
19788
19789 static int fake_panic;
19790-static atomic_t mce_fake_paniced;
19791+static atomic_unchecked_t mce_fake_paniced;
19792
19793 /* Panic in progress. Enable interrupts and wait for final IPI */
19794 static void wait_for_panic(void)
19795@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19796 /*
19797 * Make sure only one CPU runs in machine check panic
19798 */
19799- if (atomic_inc_return(&mce_paniced) > 1)
19800+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19801 wait_for_panic();
19802 barrier();
19803
19804@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19805 console_verbose();
19806 } else {
19807 /* Don't log too much for fake panic */
19808- if (atomic_inc_return(&mce_fake_paniced) > 1)
19809+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19810 return;
19811 }
19812 /* First print corrected ones that are still unlogged */
19813@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19814 if (!fake_panic) {
19815 if (panic_timeout == 0)
19816 panic_timeout = mca_cfg.panic_timeout;
19817- panic(msg);
19818+ panic("%s", msg);
19819 } else
19820 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19821 }
19822@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19823 * might have been modified by someone else.
19824 */
19825 rmb();
19826- if (atomic_read(&mce_paniced))
19827+ if (atomic_read_unchecked(&mce_paniced))
19828 wait_for_panic();
19829 if (!mca_cfg.monarch_timeout)
19830 goto out;
19831@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19832 }
19833
19834 /* Call the installed machine check handler for this CPU setup. */
19835-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19836+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19837 unexpected_machine_check;
19838
19839 /*
19840@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19841 return;
19842 }
19843
19844+ pax_open_kernel();
19845 machine_check_vector = do_machine_check;
19846+ pax_close_kernel();
19847
19848 __mcheck_cpu_init_generic();
19849 __mcheck_cpu_init_vendor(c);
19850@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19851 */
19852
19853 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19854-static int mce_chrdev_open_count; /* #times opened */
19855+static local_t mce_chrdev_open_count; /* #times opened */
19856 static int mce_chrdev_open_exclu; /* already open exclusive? */
19857
19858 static int mce_chrdev_open(struct inode *inode, struct file *file)
19859@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19860 spin_lock(&mce_chrdev_state_lock);
19861
19862 if (mce_chrdev_open_exclu ||
19863- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19864+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19865 spin_unlock(&mce_chrdev_state_lock);
19866
19867 return -EBUSY;
19868@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19869
19870 if (file->f_flags & O_EXCL)
19871 mce_chrdev_open_exclu = 1;
19872- mce_chrdev_open_count++;
19873+ local_inc(&mce_chrdev_open_count);
19874
19875 spin_unlock(&mce_chrdev_state_lock);
19876
19877@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19878 {
19879 spin_lock(&mce_chrdev_state_lock);
19880
19881- mce_chrdev_open_count--;
19882+ local_dec(&mce_chrdev_open_count);
19883 mce_chrdev_open_exclu = 0;
19884
19885 spin_unlock(&mce_chrdev_state_lock);
19886@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19887
19888 for (i = 0; i < mca_cfg.banks; i++) {
19889 struct mce_bank *b = &mce_banks[i];
19890- struct device_attribute *a = &b->attr;
19891+ device_attribute_no_const *a = &b->attr;
19892
19893 sysfs_attr_init(&a->attr);
19894 a->attr.name = b->attrname;
19895@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19896 static void mce_reset(void)
19897 {
19898 cpu_missing = 0;
19899- atomic_set(&mce_fake_paniced, 0);
19900+ atomic_set_unchecked(&mce_fake_paniced, 0);
19901 atomic_set(&mce_executing, 0);
19902 atomic_set(&mce_callin, 0);
19903 atomic_set(&global_nwo, 0);
19904diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19905index 1c044b1..37a2a43 100644
19906--- a/arch/x86/kernel/cpu/mcheck/p5.c
19907+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19908@@ -11,6 +11,7 @@
19909 #include <asm/processor.h>
19910 #include <asm/mce.h>
19911 #include <asm/msr.h>
19912+#include <asm/pgtable.h>
19913
19914 /* By default disabled */
19915 int mce_p5_enabled __read_mostly;
19916@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19917 if (!cpu_has(c, X86_FEATURE_MCE))
19918 return;
19919
19920+ pax_open_kernel();
19921 machine_check_vector = pentium_machine_check;
19922+ pax_close_kernel();
19923 /* Make sure the vector pointer is visible before we enable MCEs: */
19924 wmb();
19925
19926diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19927index e9a701a..35317d6 100644
19928--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19929+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19930@@ -10,6 +10,7 @@
19931 #include <asm/processor.h>
19932 #include <asm/mce.h>
19933 #include <asm/msr.h>
19934+#include <asm/pgtable.h>
19935
19936 /* Machine check handler for WinChip C6: */
19937 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19938@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19939 {
19940 u32 lo, hi;
19941
19942+ pax_open_kernel();
19943 machine_check_vector = winchip_machine_check;
19944+ pax_close_kernel();
19945 /* Make sure the vector pointer is visible before we enable MCEs: */
19946 wmb();
19947
19948diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19949index f961de9..8a9d332 100644
19950--- a/arch/x86/kernel/cpu/mtrr/main.c
19951+++ b/arch/x86/kernel/cpu/mtrr/main.c
19952@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19953 u64 size_or_mask, size_and_mask;
19954 static bool mtrr_aps_delayed_init;
19955
19956-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19957+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19958
19959 const struct mtrr_ops *mtrr_if;
19960
19961diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19962index df5e41f..816c719 100644
19963--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19964+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19965@@ -25,7 +25,7 @@ struct mtrr_ops {
19966 int (*validate_add_page)(unsigned long base, unsigned long size,
19967 unsigned int type);
19968 int (*have_wrcomb)(void);
19969-};
19970+} __do_const;
19971
19972 extern int generic_get_free_region(unsigned long base, unsigned long size,
19973 int replace_reg);
19974diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19975index a7c7305..b9705ab 100644
19976--- a/arch/x86/kernel/cpu/perf_event.c
19977+++ b/arch/x86/kernel/cpu/perf_event.c
19978@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19979 pr_info("no hardware sampling interrupt available.\n");
19980 }
19981
19982-static struct attribute_group x86_pmu_format_group = {
19983+static attribute_group_no_const x86_pmu_format_group = {
19984 .name = "format",
19985 .attrs = NULL,
19986 };
19987@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19988 NULL,
19989 };
19990
19991-static struct attribute_group x86_pmu_events_group = {
19992+static attribute_group_no_const x86_pmu_events_group = {
19993 .name = "events",
19994 .attrs = events_attr,
19995 };
19996@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19997 if (idx > GDT_ENTRIES)
19998 return 0;
19999
20000- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20001+ desc = get_cpu_gdt_table(smp_processor_id());
20002 }
20003
20004 return get_desc_base(desc + idx);
20005@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20006 break;
20007
20008 perf_callchain_store(entry, frame.return_address);
20009- fp = frame.next_frame;
20010+ fp = (const void __force_user *)frame.next_frame;
20011 }
20012 }
20013
20014diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20015index 639d128..e92d7e5 100644
20016--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20017+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20018@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20019 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20020 {
20021 struct attribute **attrs;
20022- struct attribute_group *attr_group;
20023+ attribute_group_no_const *attr_group;
20024 int i = 0, j;
20025
20026 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20027diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20028index a45d8d4..8abd32c 100644
20029--- a/arch/x86/kernel/cpu/perf_event_intel.c
20030+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20031@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20032 * v2 and above have a perf capabilities MSR
20033 */
20034 if (version > 1) {
20035- u64 capabilities;
20036+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20037
20038- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20039- x86_pmu.intel_cap.capabilities = capabilities;
20040+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20041+ x86_pmu.intel_cap.capabilities = capabilities;
20042 }
20043
20044 intel_ds_init();
20045diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20046index 1fb6c72..f5fa2a3 100644
20047--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20048+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20049@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20050 static int __init uncore_type_init(struct intel_uncore_type *type)
20051 {
20052 struct intel_uncore_pmu *pmus;
20053- struct attribute_group *attr_group;
20054+ attribute_group_no_const *attr_group;
20055 struct attribute **attrs;
20056 int i, j;
20057
20058diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20059index 47b3d00c..2cf1751 100644
20060--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20061+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20062@@ -488,7 +488,7 @@ struct intel_uncore_box {
20063 struct uncore_event_desc {
20064 struct kobj_attribute attr;
20065 const char *config;
20066-};
20067+} __do_const;
20068
20069 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20070 { \
20071diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20072index 7d9481c..99c7e4b 100644
20073--- a/arch/x86/kernel/cpuid.c
20074+++ b/arch/x86/kernel/cpuid.c
20075@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20076 return notifier_from_errno(err);
20077 }
20078
20079-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20080+static struct notifier_block cpuid_class_cpu_notifier =
20081 {
20082 .notifier_call = cpuid_class_cpu_callback,
20083 };
20084diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20085index 74467fe..18793d5 100644
20086--- a/arch/x86/kernel/crash.c
20087+++ b/arch/x86/kernel/crash.c
20088@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20089 {
20090 #ifdef CONFIG_X86_32
20091 struct pt_regs fixed_regs;
20092-#endif
20093
20094-#ifdef CONFIG_X86_32
20095- if (!user_mode_vm(regs)) {
20096+ if (!user_mode(regs)) {
20097 crash_fixup_ss_esp(&fixed_regs, regs);
20098 regs = &fixed_regs;
20099 }
20100diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20101index afa64ad..dce67dd 100644
20102--- a/arch/x86/kernel/crash_dump_64.c
20103+++ b/arch/x86/kernel/crash_dump_64.c
20104@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20105 return -ENOMEM;
20106
20107 if (userbuf) {
20108- if (copy_to_user(buf, vaddr + offset, csize)) {
20109+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20110 iounmap(vaddr);
20111 return -EFAULT;
20112 }
20113diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20114index 5d3fe8d..02e1429 100644
20115--- a/arch/x86/kernel/doublefault.c
20116+++ b/arch/x86/kernel/doublefault.c
20117@@ -13,7 +13,7 @@
20118
20119 #define DOUBLEFAULT_STACKSIZE (1024)
20120 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20121-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20122+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20123
20124 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20125
20126@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20127 unsigned long gdt, tss;
20128
20129 native_store_gdt(&gdt_desc);
20130- gdt = gdt_desc.address;
20131+ gdt = (unsigned long)gdt_desc.address;
20132
20133 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20134
20135@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20136 /* 0x2 bit is always set */
20137 .flags = X86_EFLAGS_SF | 0x2,
20138 .sp = STACK_START,
20139- .es = __USER_DS,
20140+ .es = __KERNEL_DS,
20141 .cs = __KERNEL_CS,
20142 .ss = __KERNEL_DS,
20143- .ds = __USER_DS,
20144+ .ds = __KERNEL_DS,
20145 .fs = __KERNEL_PERCPU,
20146
20147 .__cr3 = __pa_nodebug(swapper_pg_dir),
20148diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20149index deb6421..76bbc12 100644
20150--- a/arch/x86/kernel/dumpstack.c
20151+++ b/arch/x86/kernel/dumpstack.c
20152@@ -2,6 +2,9 @@
20153 * Copyright (C) 1991, 1992 Linus Torvalds
20154 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20155 */
20156+#ifdef CONFIG_GRKERNSEC_HIDESYM
20157+#define __INCLUDED_BY_HIDESYM 1
20158+#endif
20159 #include <linux/kallsyms.h>
20160 #include <linux/kprobes.h>
20161 #include <linux/uaccess.h>
20162@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20163 static void
20164 print_ftrace_graph_addr(unsigned long addr, void *data,
20165 const struct stacktrace_ops *ops,
20166- struct thread_info *tinfo, int *graph)
20167+ struct task_struct *task, int *graph)
20168 {
20169- struct task_struct *task;
20170 unsigned long ret_addr;
20171 int index;
20172
20173 if (addr != (unsigned long)return_to_handler)
20174 return;
20175
20176- task = tinfo->task;
20177 index = task->curr_ret_stack;
20178
20179 if (!task->ret_stack || index < *graph)
20180@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20181 static inline void
20182 print_ftrace_graph_addr(unsigned long addr, void *data,
20183 const struct stacktrace_ops *ops,
20184- struct thread_info *tinfo, int *graph)
20185+ struct task_struct *task, int *graph)
20186 { }
20187 #endif
20188
20189@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20190 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20191 */
20192
20193-static inline int valid_stack_ptr(struct thread_info *tinfo,
20194- void *p, unsigned int size, void *end)
20195+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20196 {
20197- void *t = tinfo;
20198 if (end) {
20199 if (p < end && p >= (end-THREAD_SIZE))
20200 return 1;
20201@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20202 }
20203
20204 unsigned long
20205-print_context_stack(struct thread_info *tinfo,
20206+print_context_stack(struct task_struct *task, void *stack_start,
20207 unsigned long *stack, unsigned long bp,
20208 const struct stacktrace_ops *ops, void *data,
20209 unsigned long *end, int *graph)
20210 {
20211 struct stack_frame *frame = (struct stack_frame *)bp;
20212
20213- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20214+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20215 unsigned long addr;
20216
20217 addr = *stack;
20218@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20219 } else {
20220 ops->address(data, addr, 0);
20221 }
20222- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20223+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20224 }
20225 stack++;
20226 }
20227@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20228 EXPORT_SYMBOL_GPL(print_context_stack);
20229
20230 unsigned long
20231-print_context_stack_bp(struct thread_info *tinfo,
20232+print_context_stack_bp(struct task_struct *task, void *stack_start,
20233 unsigned long *stack, unsigned long bp,
20234 const struct stacktrace_ops *ops, void *data,
20235 unsigned long *end, int *graph)
20236@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20237 struct stack_frame *frame = (struct stack_frame *)bp;
20238 unsigned long *ret_addr = &frame->return_address;
20239
20240- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20241+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20242 unsigned long addr = *ret_addr;
20243
20244 if (!__kernel_text_address(addr))
20245@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20246 ops->address(data, addr, 1);
20247 frame = frame->next_frame;
20248 ret_addr = &frame->return_address;
20249- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20250+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20251 }
20252
20253 return (unsigned long)frame;
20254@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20255 static void print_trace_address(void *data, unsigned long addr, int reliable)
20256 {
20257 touch_nmi_watchdog();
20258- printk(data);
20259+ printk("%s", (char *)data);
20260 printk_address(addr, reliable);
20261 }
20262
20263@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20264 }
20265 EXPORT_SYMBOL_GPL(oops_begin);
20266
20267+extern void gr_handle_kernel_exploit(void);
20268+
20269 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20270 {
20271 if (regs && kexec_should_crash(current))
20272@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20273 panic("Fatal exception in interrupt");
20274 if (panic_on_oops)
20275 panic("Fatal exception");
20276- do_exit(signr);
20277+
20278+ gr_handle_kernel_exploit();
20279+
20280+ do_group_exit(signr);
20281 }
20282
20283 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20284@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20285 print_modules();
20286 show_regs(regs);
20287 #ifdef CONFIG_X86_32
20288- if (user_mode_vm(regs)) {
20289+ if (user_mode(regs)) {
20290 sp = regs->sp;
20291 ss = regs->ss & 0xffff;
20292 } else {
20293@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20294 unsigned long flags = oops_begin();
20295 int sig = SIGSEGV;
20296
20297- if (!user_mode_vm(regs))
20298+ if (!user_mode(regs))
20299 report_bug(regs->ip, regs);
20300
20301 if (__die(str, regs, err))
20302diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20303index f2a1770..540657f 100644
20304--- a/arch/x86/kernel/dumpstack_32.c
20305+++ b/arch/x86/kernel/dumpstack_32.c
20306@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20307 bp = stack_frame(task, regs);
20308
20309 for (;;) {
20310- struct thread_info *context;
20311+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20312
20313- context = (struct thread_info *)
20314- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20315- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20316+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20317
20318- stack = (unsigned long *)context->previous_esp;
20319- if (!stack)
20320+ if (stack_start == task_stack_page(task))
20321 break;
20322+ stack = *(unsigned long **)stack_start;
20323 if (ops->stack(data, "IRQ") < 0)
20324 break;
20325 touch_nmi_watchdog();
20326@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20327 int i;
20328
20329 show_regs_print_info(KERN_EMERG);
20330- __show_regs(regs, !user_mode_vm(regs));
20331+ __show_regs(regs, !user_mode(regs));
20332
20333 /*
20334 * When in-kernel, we also print out the stack and code at the
20335 * time of the fault..
20336 */
20337- if (!user_mode_vm(regs)) {
20338+ if (!user_mode(regs)) {
20339 unsigned int code_prologue = code_bytes * 43 / 64;
20340 unsigned int code_len = code_bytes;
20341 unsigned char c;
20342 u8 *ip;
20343+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20344
20345 pr_emerg("Stack:\n");
20346 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20347
20348 pr_emerg("Code:");
20349
20350- ip = (u8 *)regs->ip - code_prologue;
20351+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20352 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20353 /* try starting at IP */
20354- ip = (u8 *)regs->ip;
20355+ ip = (u8 *)regs->ip + cs_base;
20356 code_len = code_len - code_prologue + 1;
20357 }
20358 for (i = 0; i < code_len; i++, ip++) {
20359@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20360 pr_cont(" Bad EIP value.");
20361 break;
20362 }
20363- if (ip == (u8 *)regs->ip)
20364+ if (ip == (u8 *)regs->ip + cs_base)
20365 pr_cont(" <%02x>", c);
20366 else
20367 pr_cont(" %02x", c);
20368@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20369 {
20370 unsigned short ud2;
20371
20372+ ip = ktla_ktva(ip);
20373 if (ip < PAGE_OFFSET)
20374 return 0;
20375 if (probe_kernel_address((unsigned short *)ip, ud2))
20376@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20377
20378 return ud2 == 0x0b0f;
20379 }
20380+
20381+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20382+void pax_check_alloca(unsigned long size)
20383+{
20384+ unsigned long sp = (unsigned long)&sp, stack_left;
20385+
20386+ /* all kernel stacks are of the same size */
20387+ stack_left = sp & (THREAD_SIZE - 1);
20388+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20389+}
20390+EXPORT_SYMBOL(pax_check_alloca);
20391+#endif
20392diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20393index addb207..99635fa 100644
20394--- a/arch/x86/kernel/dumpstack_64.c
20395+++ b/arch/x86/kernel/dumpstack_64.c
20396@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20397 unsigned long *irq_stack_end =
20398 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20399 unsigned used = 0;
20400- struct thread_info *tinfo;
20401 int graph = 0;
20402 unsigned long dummy;
20403+ void *stack_start;
20404
20405 if (!task)
20406 task = current;
20407@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20408 * current stack address. If the stacks consist of nested
20409 * exceptions
20410 */
20411- tinfo = task_thread_info(task);
20412 for (;;) {
20413 char *id;
20414 unsigned long *estack_end;
20415+
20416 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20417 &used, &id);
20418
20419@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20420 if (ops->stack(data, id) < 0)
20421 break;
20422
20423- bp = ops->walk_stack(tinfo, stack, bp, ops,
20424+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20425 data, estack_end, &graph);
20426 ops->stack(data, "<EOE>");
20427 /*
20428@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20429 * second-to-last pointer (index -2 to end) in the
20430 * exception stack:
20431 */
20432+ if ((u16)estack_end[-1] != __KERNEL_DS)
20433+ goto out;
20434 stack = (unsigned long *) estack_end[-2];
20435 continue;
20436 }
20437@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20438 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20439 if (ops->stack(data, "IRQ") < 0)
20440 break;
20441- bp = ops->walk_stack(tinfo, stack, bp,
20442+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20443 ops, data, irq_stack_end, &graph);
20444 /*
20445 * We link to the next stack (which would be
20446@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20447 /*
20448 * This handles the process stack:
20449 */
20450- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20451+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20452+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20453+out:
20454 put_cpu();
20455 }
20456 EXPORT_SYMBOL(dump_trace);
20457@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20458
20459 return ud2 == 0x0b0f;
20460 }
20461+
20462+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20463+void pax_check_alloca(unsigned long size)
20464+{
20465+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20466+ unsigned cpu, used;
20467+ char *id;
20468+
20469+ /* check the process stack first */
20470+ stack_start = (unsigned long)task_stack_page(current);
20471+ stack_end = stack_start + THREAD_SIZE;
20472+ if (likely(stack_start <= sp && sp < stack_end)) {
20473+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20474+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20475+ return;
20476+ }
20477+
20478+ cpu = get_cpu();
20479+
20480+ /* check the irq stacks */
20481+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20482+ stack_start = stack_end - IRQ_STACK_SIZE;
20483+ if (stack_start <= sp && sp < stack_end) {
20484+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20485+ put_cpu();
20486+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20487+ return;
20488+ }
20489+
20490+ /* check the exception stacks */
20491+ used = 0;
20492+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20493+ stack_start = stack_end - EXCEPTION_STKSZ;
20494+ if (stack_end && stack_start <= sp && sp < stack_end) {
20495+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20496+ put_cpu();
20497+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20498+ return;
20499+ }
20500+
20501+ put_cpu();
20502+
20503+ /* unknown stack */
20504+ BUG();
20505+}
20506+EXPORT_SYMBOL(pax_check_alloca);
20507+#endif
20508diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20509index 174da5f..5e55606 100644
20510--- a/arch/x86/kernel/e820.c
20511+++ b/arch/x86/kernel/e820.c
20512@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20513
20514 static void early_panic(char *msg)
20515 {
20516- early_printk(msg);
20517- panic(msg);
20518+ early_printk("%s", msg);
20519+ panic("%s", msg);
20520 }
20521
20522 static int userdef __initdata;
20523diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20524index d15f575..d692043 100644
20525--- a/arch/x86/kernel/early_printk.c
20526+++ b/arch/x86/kernel/early_printk.c
20527@@ -7,6 +7,7 @@
20528 #include <linux/pci_regs.h>
20529 #include <linux/pci_ids.h>
20530 #include <linux/errno.h>
20531+#include <linux/sched.h>
20532 #include <asm/io.h>
20533 #include <asm/processor.h>
20534 #include <asm/fcntl.h>
20535diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20536index 2cfbc3a..b756682 100644
20537--- a/arch/x86/kernel/entry_32.S
20538+++ b/arch/x86/kernel/entry_32.S
20539@@ -177,13 +177,153 @@
20540 /*CFI_REL_OFFSET gs, PT_GS*/
20541 .endm
20542 .macro SET_KERNEL_GS reg
20543+
20544+#ifdef CONFIG_CC_STACKPROTECTOR
20545 movl $(__KERNEL_STACK_CANARY), \reg
20546+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20547+ movl $(__USER_DS), \reg
20548+#else
20549+ xorl \reg, \reg
20550+#endif
20551+
20552 movl \reg, %gs
20553 .endm
20554
20555 #endif /* CONFIG_X86_32_LAZY_GS */
20556
20557-.macro SAVE_ALL
20558+.macro pax_enter_kernel
20559+#ifdef CONFIG_PAX_KERNEXEC
20560+ call pax_enter_kernel
20561+#endif
20562+.endm
20563+
20564+.macro pax_exit_kernel
20565+#ifdef CONFIG_PAX_KERNEXEC
20566+ call pax_exit_kernel
20567+#endif
20568+.endm
20569+
20570+#ifdef CONFIG_PAX_KERNEXEC
20571+ENTRY(pax_enter_kernel)
20572+#ifdef CONFIG_PARAVIRT
20573+ pushl %eax
20574+ pushl %ecx
20575+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20576+ mov %eax, %esi
20577+#else
20578+ mov %cr0, %esi
20579+#endif
20580+ bts $16, %esi
20581+ jnc 1f
20582+ mov %cs, %esi
20583+ cmp $__KERNEL_CS, %esi
20584+ jz 3f
20585+ ljmp $__KERNEL_CS, $3f
20586+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20587+2:
20588+#ifdef CONFIG_PARAVIRT
20589+ mov %esi, %eax
20590+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20591+#else
20592+ mov %esi, %cr0
20593+#endif
20594+3:
20595+#ifdef CONFIG_PARAVIRT
20596+ popl %ecx
20597+ popl %eax
20598+#endif
20599+ ret
20600+ENDPROC(pax_enter_kernel)
20601+
20602+ENTRY(pax_exit_kernel)
20603+#ifdef CONFIG_PARAVIRT
20604+ pushl %eax
20605+ pushl %ecx
20606+#endif
20607+ mov %cs, %esi
20608+ cmp $__KERNEXEC_KERNEL_CS, %esi
20609+ jnz 2f
20610+#ifdef CONFIG_PARAVIRT
20611+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20612+ mov %eax, %esi
20613+#else
20614+ mov %cr0, %esi
20615+#endif
20616+ btr $16, %esi
20617+ ljmp $__KERNEL_CS, $1f
20618+1:
20619+#ifdef CONFIG_PARAVIRT
20620+ mov %esi, %eax
20621+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20622+#else
20623+ mov %esi, %cr0
20624+#endif
20625+2:
20626+#ifdef CONFIG_PARAVIRT
20627+ popl %ecx
20628+ popl %eax
20629+#endif
20630+ ret
20631+ENDPROC(pax_exit_kernel)
20632+#endif
20633+
20634+ .macro pax_erase_kstack
20635+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20636+ call pax_erase_kstack
20637+#endif
20638+ .endm
20639+
20640+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20641+/*
20642+ * ebp: thread_info
20643+ */
20644+ENTRY(pax_erase_kstack)
20645+ pushl %edi
20646+ pushl %ecx
20647+ pushl %eax
20648+
20649+ mov TI_lowest_stack(%ebp), %edi
20650+ mov $-0xBEEF, %eax
20651+ std
20652+
20653+1: mov %edi, %ecx
20654+ and $THREAD_SIZE_asm - 1, %ecx
20655+ shr $2, %ecx
20656+ repne scasl
20657+ jecxz 2f
20658+
20659+ cmp $2*16, %ecx
20660+ jc 2f
20661+
20662+ mov $2*16, %ecx
20663+ repe scasl
20664+ jecxz 2f
20665+ jne 1b
20666+
20667+2: cld
20668+ mov %esp, %ecx
20669+ sub %edi, %ecx
20670+
20671+ cmp $THREAD_SIZE_asm, %ecx
20672+ jb 3f
20673+ ud2
20674+3:
20675+
20676+ shr $2, %ecx
20677+ rep stosl
20678+
20679+ mov TI_task_thread_sp0(%ebp), %edi
20680+ sub $128, %edi
20681+ mov %edi, TI_lowest_stack(%ebp)
20682+
20683+ popl %eax
20684+ popl %ecx
20685+ popl %edi
20686+ ret
20687+ENDPROC(pax_erase_kstack)
20688+#endif
20689+
20690+.macro __SAVE_ALL _DS
20691 cld
20692 PUSH_GS
20693 pushl_cfi %fs
20694@@ -206,7 +346,7 @@
20695 CFI_REL_OFFSET ecx, 0
20696 pushl_cfi %ebx
20697 CFI_REL_OFFSET ebx, 0
20698- movl $(__USER_DS), %edx
20699+ movl $\_DS, %edx
20700 movl %edx, %ds
20701 movl %edx, %es
20702 movl $(__KERNEL_PERCPU), %edx
20703@@ -214,6 +354,15 @@
20704 SET_KERNEL_GS %edx
20705 .endm
20706
20707+.macro SAVE_ALL
20708+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20709+ __SAVE_ALL __KERNEL_DS
20710+ pax_enter_kernel
20711+#else
20712+ __SAVE_ALL __USER_DS
20713+#endif
20714+.endm
20715+
20716 .macro RESTORE_INT_REGS
20717 popl_cfi %ebx
20718 CFI_RESTORE ebx
20719@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20720 popfl_cfi
20721 jmp syscall_exit
20722 CFI_ENDPROC
20723-END(ret_from_fork)
20724+ENDPROC(ret_from_fork)
20725
20726 ENTRY(ret_from_kernel_thread)
20727 CFI_STARTPROC
20728@@ -344,7 +493,15 @@ ret_from_intr:
20729 andl $SEGMENT_RPL_MASK, %eax
20730 #endif
20731 cmpl $USER_RPL, %eax
20732+
20733+#ifdef CONFIG_PAX_KERNEXEC
20734+ jae resume_userspace
20735+
20736+ pax_exit_kernel
20737+ jmp resume_kernel
20738+#else
20739 jb resume_kernel # not returning to v8086 or userspace
20740+#endif
20741
20742 ENTRY(resume_userspace)
20743 LOCKDEP_SYS_EXIT
20744@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20745 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20746 # int/exception return?
20747 jne work_pending
20748- jmp restore_all
20749-END(ret_from_exception)
20750+ jmp restore_all_pax
20751+ENDPROC(ret_from_exception)
20752
20753 #ifdef CONFIG_PREEMPT
20754 ENTRY(resume_kernel)
20755@@ -372,7 +529,7 @@ need_resched:
20756 jz restore_all
20757 call preempt_schedule_irq
20758 jmp need_resched
20759-END(resume_kernel)
20760+ENDPROC(resume_kernel)
20761 #endif
20762 CFI_ENDPROC
20763 /*
20764@@ -406,30 +563,45 @@ sysenter_past_esp:
20765 /*CFI_REL_OFFSET cs, 0*/
20766 /*
20767 * Push current_thread_info()->sysenter_return to the stack.
20768- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20769- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20770 */
20771- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20772+ pushl_cfi $0
20773 CFI_REL_OFFSET eip, 0
20774
20775 pushl_cfi %eax
20776 SAVE_ALL
20777+ GET_THREAD_INFO(%ebp)
20778+ movl TI_sysenter_return(%ebp),%ebp
20779+ movl %ebp,PT_EIP(%esp)
20780 ENABLE_INTERRUPTS(CLBR_NONE)
20781
20782 /*
20783 * Load the potential sixth argument from user stack.
20784 * Careful about security.
20785 */
20786+ movl PT_OLDESP(%esp),%ebp
20787+
20788+#ifdef CONFIG_PAX_MEMORY_UDEREF
20789+ mov PT_OLDSS(%esp),%ds
20790+1: movl %ds:(%ebp),%ebp
20791+ push %ss
20792+ pop %ds
20793+#else
20794 cmpl $__PAGE_OFFSET-3,%ebp
20795 jae syscall_fault
20796 ASM_STAC
20797 1: movl (%ebp),%ebp
20798 ASM_CLAC
20799+#endif
20800+
20801 movl %ebp,PT_EBP(%esp)
20802 _ASM_EXTABLE(1b,syscall_fault)
20803
20804 GET_THREAD_INFO(%ebp)
20805
20806+#ifdef CONFIG_PAX_RANDKSTACK
20807+ pax_erase_kstack
20808+#endif
20809+
20810 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20811 jnz sysenter_audit
20812 sysenter_do_call:
20813@@ -444,12 +616,24 @@ sysenter_do_call:
20814 testl $_TIF_ALLWORK_MASK, %ecx
20815 jne sysexit_audit
20816 sysenter_exit:
20817+
20818+#ifdef CONFIG_PAX_RANDKSTACK
20819+ pushl_cfi %eax
20820+ movl %esp, %eax
20821+ call pax_randomize_kstack
20822+ popl_cfi %eax
20823+#endif
20824+
20825+ pax_erase_kstack
20826+
20827 /* if something modifies registers it must also disable sysexit */
20828 movl PT_EIP(%esp), %edx
20829 movl PT_OLDESP(%esp), %ecx
20830 xorl %ebp,%ebp
20831 TRACE_IRQS_ON
20832 1: mov PT_FS(%esp), %fs
20833+2: mov PT_DS(%esp), %ds
20834+3: mov PT_ES(%esp), %es
20835 PTGS_TO_GS
20836 ENABLE_INTERRUPTS_SYSEXIT
20837
20838@@ -466,6 +650,9 @@ sysenter_audit:
20839 movl %eax,%edx /* 2nd arg: syscall number */
20840 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20841 call __audit_syscall_entry
20842+
20843+ pax_erase_kstack
20844+
20845 pushl_cfi %ebx
20846 movl PT_EAX(%esp),%eax /* reload syscall number */
20847 jmp sysenter_do_call
20848@@ -491,10 +678,16 @@ sysexit_audit:
20849
20850 CFI_ENDPROC
20851 .pushsection .fixup,"ax"
20852-2: movl $0,PT_FS(%esp)
20853+4: movl $0,PT_FS(%esp)
20854+ jmp 1b
20855+5: movl $0,PT_DS(%esp)
20856+ jmp 1b
20857+6: movl $0,PT_ES(%esp)
20858 jmp 1b
20859 .popsection
20860- _ASM_EXTABLE(1b,2b)
20861+ _ASM_EXTABLE(1b,4b)
20862+ _ASM_EXTABLE(2b,5b)
20863+ _ASM_EXTABLE(3b,6b)
20864 PTGS_TO_GS_EX
20865 ENDPROC(ia32_sysenter_target)
20866
20867@@ -509,6 +702,11 @@ ENTRY(system_call)
20868 pushl_cfi %eax # save orig_eax
20869 SAVE_ALL
20870 GET_THREAD_INFO(%ebp)
20871+
20872+#ifdef CONFIG_PAX_RANDKSTACK
20873+ pax_erase_kstack
20874+#endif
20875+
20876 # system call tracing in operation / emulation
20877 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20878 jnz syscall_trace_entry
20879@@ -527,6 +725,15 @@ syscall_exit:
20880 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20881 jne syscall_exit_work
20882
20883+restore_all_pax:
20884+
20885+#ifdef CONFIG_PAX_RANDKSTACK
20886+ movl %esp, %eax
20887+ call pax_randomize_kstack
20888+#endif
20889+
20890+ pax_erase_kstack
20891+
20892 restore_all:
20893 TRACE_IRQS_IRET
20894 restore_all_notrace:
20895@@ -583,14 +790,34 @@ ldt_ss:
20896 * compensating for the offset by changing to the ESPFIX segment with
20897 * a base address that matches for the difference.
20898 */
20899-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20900+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20901 mov %esp, %edx /* load kernel esp */
20902 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20903 mov %dx, %ax /* eax: new kernel esp */
20904 sub %eax, %edx /* offset (low word is 0) */
20905+#ifdef CONFIG_SMP
20906+ movl PER_CPU_VAR(cpu_number), %ebx
20907+ shll $PAGE_SHIFT_asm, %ebx
20908+ addl $cpu_gdt_table, %ebx
20909+#else
20910+ movl $cpu_gdt_table, %ebx
20911+#endif
20912 shr $16, %edx
20913- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20914- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20915+
20916+#ifdef CONFIG_PAX_KERNEXEC
20917+ mov %cr0, %esi
20918+ btr $16, %esi
20919+ mov %esi, %cr0
20920+#endif
20921+
20922+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20923+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20924+
20925+#ifdef CONFIG_PAX_KERNEXEC
20926+ bts $16, %esi
20927+ mov %esi, %cr0
20928+#endif
20929+
20930 pushl_cfi $__ESPFIX_SS
20931 pushl_cfi %eax /* new kernel esp */
20932 /* Disable interrupts, but do not irqtrace this section: we
20933@@ -619,20 +846,18 @@ work_resched:
20934 movl TI_flags(%ebp), %ecx
20935 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20936 # than syscall tracing?
20937- jz restore_all
20938+ jz restore_all_pax
20939 testb $_TIF_NEED_RESCHED, %cl
20940 jnz work_resched
20941
20942 work_notifysig: # deal with pending signals and
20943 # notify-resume requests
20944+ movl %esp, %eax
20945 #ifdef CONFIG_VM86
20946 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20947- movl %esp, %eax
20948 jne work_notifysig_v86 # returning to kernel-space or
20949 # vm86-space
20950 1:
20951-#else
20952- movl %esp, %eax
20953 #endif
20954 TRACE_IRQS_ON
20955 ENABLE_INTERRUPTS(CLBR_NONE)
20956@@ -653,7 +878,7 @@ work_notifysig_v86:
20957 movl %eax, %esp
20958 jmp 1b
20959 #endif
20960-END(work_pending)
20961+ENDPROC(work_pending)
20962
20963 # perform syscall exit tracing
20964 ALIGN
20965@@ -661,11 +886,14 @@ syscall_trace_entry:
20966 movl $-ENOSYS,PT_EAX(%esp)
20967 movl %esp, %eax
20968 call syscall_trace_enter
20969+
20970+ pax_erase_kstack
20971+
20972 /* What it returned is what we'll actually use. */
20973 cmpl $(NR_syscalls), %eax
20974 jnae syscall_call
20975 jmp syscall_exit
20976-END(syscall_trace_entry)
20977+ENDPROC(syscall_trace_entry)
20978
20979 # perform syscall exit tracing
20980 ALIGN
20981@@ -678,21 +906,25 @@ syscall_exit_work:
20982 movl %esp, %eax
20983 call syscall_trace_leave
20984 jmp resume_userspace
20985-END(syscall_exit_work)
20986+ENDPROC(syscall_exit_work)
20987 CFI_ENDPROC
20988
20989 RING0_INT_FRAME # can't unwind into user space anyway
20990 syscall_fault:
20991+#ifdef CONFIG_PAX_MEMORY_UDEREF
20992+ push %ss
20993+ pop %ds
20994+#endif
20995 ASM_CLAC
20996 GET_THREAD_INFO(%ebp)
20997 movl $-EFAULT,PT_EAX(%esp)
20998 jmp resume_userspace
20999-END(syscall_fault)
21000+ENDPROC(syscall_fault)
21001
21002 syscall_badsys:
21003 movl $-ENOSYS,PT_EAX(%esp)
21004 jmp resume_userspace
21005-END(syscall_badsys)
21006+ENDPROC(syscall_badsys)
21007 CFI_ENDPROC
21008 /*
21009 * End of kprobes section
21010@@ -708,8 +940,15 @@ END(syscall_badsys)
21011 * normal stack and adjusts ESP with the matching offset.
21012 */
21013 /* fixup the stack */
21014- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21015- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21016+#ifdef CONFIG_SMP
21017+ movl PER_CPU_VAR(cpu_number), %ebx
21018+ shll $PAGE_SHIFT_asm, %ebx
21019+ addl $cpu_gdt_table, %ebx
21020+#else
21021+ movl $cpu_gdt_table, %ebx
21022+#endif
21023+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21024+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21025 shl $16, %eax
21026 addl %esp, %eax /* the adjusted stack pointer */
21027 pushl_cfi $__KERNEL_DS
21028@@ -762,7 +1001,7 @@ vector=vector+1
21029 .endr
21030 2: jmp common_interrupt
21031 .endr
21032-END(irq_entries_start)
21033+ENDPROC(irq_entries_start)
21034
21035 .previous
21036 END(interrupt)
21037@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21038 pushl_cfi $do_coprocessor_error
21039 jmp error_code
21040 CFI_ENDPROC
21041-END(coprocessor_error)
21042+ENDPROC(coprocessor_error)
21043
21044 ENTRY(simd_coprocessor_error)
21045 RING0_INT_FRAME
21046@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21047 .section .altinstructions,"a"
21048 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21049 .previous
21050-.section .altinstr_replacement,"ax"
21051+.section .altinstr_replacement,"a"
21052 663: pushl $do_simd_coprocessor_error
21053 664:
21054 .previous
21055@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21056 #endif
21057 jmp error_code
21058 CFI_ENDPROC
21059-END(simd_coprocessor_error)
21060+ENDPROC(simd_coprocessor_error)
21061
21062 ENTRY(device_not_available)
21063 RING0_INT_FRAME
21064@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21065 pushl_cfi $do_device_not_available
21066 jmp error_code
21067 CFI_ENDPROC
21068-END(device_not_available)
21069+ENDPROC(device_not_available)
21070
21071 #ifdef CONFIG_PARAVIRT
21072 ENTRY(native_iret)
21073 iret
21074 _ASM_EXTABLE(native_iret, iret_exc)
21075-END(native_iret)
21076+ENDPROC(native_iret)
21077
21078 ENTRY(native_irq_enable_sysexit)
21079 sti
21080 sysexit
21081-END(native_irq_enable_sysexit)
21082+ENDPROC(native_irq_enable_sysexit)
21083 #endif
21084
21085 ENTRY(overflow)
21086@@ -875,7 +1114,7 @@ ENTRY(overflow)
21087 pushl_cfi $do_overflow
21088 jmp error_code
21089 CFI_ENDPROC
21090-END(overflow)
21091+ENDPROC(overflow)
21092
21093 ENTRY(bounds)
21094 RING0_INT_FRAME
21095@@ -884,7 +1123,7 @@ ENTRY(bounds)
21096 pushl_cfi $do_bounds
21097 jmp error_code
21098 CFI_ENDPROC
21099-END(bounds)
21100+ENDPROC(bounds)
21101
21102 ENTRY(invalid_op)
21103 RING0_INT_FRAME
21104@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21105 pushl_cfi $do_invalid_op
21106 jmp error_code
21107 CFI_ENDPROC
21108-END(invalid_op)
21109+ENDPROC(invalid_op)
21110
21111 ENTRY(coprocessor_segment_overrun)
21112 RING0_INT_FRAME
21113@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21114 pushl_cfi $do_coprocessor_segment_overrun
21115 jmp error_code
21116 CFI_ENDPROC
21117-END(coprocessor_segment_overrun)
21118+ENDPROC(coprocessor_segment_overrun)
21119
21120 ENTRY(invalid_TSS)
21121 RING0_EC_FRAME
21122@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21123 pushl_cfi $do_invalid_TSS
21124 jmp error_code
21125 CFI_ENDPROC
21126-END(invalid_TSS)
21127+ENDPROC(invalid_TSS)
21128
21129 ENTRY(segment_not_present)
21130 RING0_EC_FRAME
21131@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21132 pushl_cfi $do_segment_not_present
21133 jmp error_code
21134 CFI_ENDPROC
21135-END(segment_not_present)
21136+ENDPROC(segment_not_present)
21137
21138 ENTRY(stack_segment)
21139 RING0_EC_FRAME
21140@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21141 pushl_cfi $do_stack_segment
21142 jmp error_code
21143 CFI_ENDPROC
21144-END(stack_segment)
21145+ENDPROC(stack_segment)
21146
21147 ENTRY(alignment_check)
21148 RING0_EC_FRAME
21149@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21150 pushl_cfi $do_alignment_check
21151 jmp error_code
21152 CFI_ENDPROC
21153-END(alignment_check)
21154+ENDPROC(alignment_check)
21155
21156 ENTRY(divide_error)
21157 RING0_INT_FRAME
21158@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21159 pushl_cfi $do_divide_error
21160 jmp error_code
21161 CFI_ENDPROC
21162-END(divide_error)
21163+ENDPROC(divide_error)
21164
21165 #ifdef CONFIG_X86_MCE
21166 ENTRY(machine_check)
21167@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21168 pushl_cfi machine_check_vector
21169 jmp error_code
21170 CFI_ENDPROC
21171-END(machine_check)
21172+ENDPROC(machine_check)
21173 #endif
21174
21175 ENTRY(spurious_interrupt_bug)
21176@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21177 pushl_cfi $do_spurious_interrupt_bug
21178 jmp error_code
21179 CFI_ENDPROC
21180-END(spurious_interrupt_bug)
21181+ENDPROC(spurious_interrupt_bug)
21182 /*
21183 * End of kprobes section
21184 */
21185@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21186
21187 ENTRY(mcount)
21188 ret
21189-END(mcount)
21190+ENDPROC(mcount)
21191
21192 ENTRY(ftrace_caller)
21193 cmpl $0, function_trace_stop
21194@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21195 .globl ftrace_stub
21196 ftrace_stub:
21197 ret
21198-END(ftrace_caller)
21199+ENDPROC(ftrace_caller)
21200
21201 ENTRY(ftrace_regs_caller)
21202 pushf /* push flags before compare (in cs location) */
21203@@ -1207,7 +1446,7 @@ trace:
21204 popl %ecx
21205 popl %eax
21206 jmp ftrace_stub
21207-END(mcount)
21208+ENDPROC(mcount)
21209 #endif /* CONFIG_DYNAMIC_FTRACE */
21210 #endif /* CONFIG_FUNCTION_TRACER */
21211
21212@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21213 popl %ecx
21214 popl %eax
21215 ret
21216-END(ftrace_graph_caller)
21217+ENDPROC(ftrace_graph_caller)
21218
21219 .globl return_to_handler
21220 return_to_handler:
21221@@ -1281,15 +1520,18 @@ error_code:
21222 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21223 REG_TO_PTGS %ecx
21224 SET_KERNEL_GS %ecx
21225- movl $(__USER_DS), %ecx
21226+ movl $(__KERNEL_DS), %ecx
21227 movl %ecx, %ds
21228 movl %ecx, %es
21229+
21230+ pax_enter_kernel
21231+
21232 TRACE_IRQS_OFF
21233 movl %esp,%eax # pt_regs pointer
21234 call *%edi
21235 jmp ret_from_exception
21236 CFI_ENDPROC
21237-END(page_fault)
21238+ENDPROC(page_fault)
21239
21240 /*
21241 * Debug traps and NMI can happen at the one SYSENTER instruction
21242@@ -1332,7 +1574,7 @@ debug_stack_correct:
21243 call do_debug
21244 jmp ret_from_exception
21245 CFI_ENDPROC
21246-END(debug)
21247+ENDPROC(debug)
21248
21249 /*
21250 * NMI is doubly nasty. It can happen _while_ we're handling
21251@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21252 xorl %edx,%edx # zero error code
21253 movl %esp,%eax # pt_regs pointer
21254 call do_nmi
21255+
21256+ pax_exit_kernel
21257+
21258 jmp restore_all_notrace
21259 CFI_ENDPROC
21260
21261@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21262 FIXUP_ESPFIX_STACK # %eax == %esp
21263 xorl %edx,%edx # zero error code
21264 call do_nmi
21265+
21266+ pax_exit_kernel
21267+
21268 RESTORE_REGS
21269 lss 12+4(%esp), %esp # back to espfix stack
21270 CFI_ADJUST_CFA_OFFSET -24
21271 jmp irq_return
21272 CFI_ENDPROC
21273-END(nmi)
21274+ENDPROC(nmi)
21275
21276 ENTRY(int3)
21277 RING0_INT_FRAME
21278@@ -1424,14 +1672,14 @@ ENTRY(int3)
21279 call do_int3
21280 jmp ret_from_exception
21281 CFI_ENDPROC
21282-END(int3)
21283+ENDPROC(int3)
21284
21285 ENTRY(general_protection)
21286 RING0_EC_FRAME
21287 pushl_cfi $do_general_protection
21288 jmp error_code
21289 CFI_ENDPROC
21290-END(general_protection)
21291+ENDPROC(general_protection)
21292
21293 #ifdef CONFIG_KVM_GUEST
21294 ENTRY(async_page_fault)
21295@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21296 pushl_cfi $do_async_page_fault
21297 jmp error_code
21298 CFI_ENDPROC
21299-END(async_page_fault)
21300+ENDPROC(async_page_fault)
21301 #endif
21302
21303 /*
21304diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21305index 1b69951..8430a6d 100644
21306--- a/arch/x86/kernel/entry_64.S
21307+++ b/arch/x86/kernel/entry_64.S
21308@@ -59,6 +59,8 @@
21309 #include <asm/context_tracking.h>
21310 #include <asm/smap.h>
21311 #include <linux/err.h>
21312+#include <asm/pgtable.h>
21313+#include <asm/alternative-asm.h>
21314
21315 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21316 #include <linux/elf-em.h>
21317@@ -80,8 +82,9 @@
21318 #ifdef CONFIG_DYNAMIC_FTRACE
21319
21320 ENTRY(function_hook)
21321+ pax_force_retaddr
21322 retq
21323-END(function_hook)
21324+ENDPROC(function_hook)
21325
21326 /* skip is set if stack has been adjusted */
21327 .macro ftrace_caller_setup skip=0
21328@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21329 #endif
21330
21331 GLOBAL(ftrace_stub)
21332+ pax_force_retaddr
21333 retq
21334-END(ftrace_caller)
21335+ENDPROC(ftrace_caller)
21336
21337 ENTRY(ftrace_regs_caller)
21338 /* Save the current flags before compare (in SS location)*/
21339@@ -191,7 +195,7 @@ ftrace_restore_flags:
21340 popfq
21341 jmp ftrace_stub
21342
21343-END(ftrace_regs_caller)
21344+ENDPROC(ftrace_regs_caller)
21345
21346
21347 #else /* ! CONFIG_DYNAMIC_FTRACE */
21348@@ -212,6 +216,7 @@ ENTRY(function_hook)
21349 #endif
21350
21351 GLOBAL(ftrace_stub)
21352+ pax_force_retaddr
21353 retq
21354
21355 trace:
21356@@ -225,12 +230,13 @@ trace:
21357 #endif
21358 subq $MCOUNT_INSN_SIZE, %rdi
21359
21360+ pax_force_fptr ftrace_trace_function
21361 call *ftrace_trace_function
21362
21363 MCOUNT_RESTORE_FRAME
21364
21365 jmp ftrace_stub
21366-END(function_hook)
21367+ENDPROC(function_hook)
21368 #endif /* CONFIG_DYNAMIC_FTRACE */
21369 #endif /* CONFIG_FUNCTION_TRACER */
21370
21371@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21372
21373 MCOUNT_RESTORE_FRAME
21374
21375+ pax_force_retaddr
21376 retq
21377-END(ftrace_graph_caller)
21378+ENDPROC(ftrace_graph_caller)
21379
21380 GLOBAL(return_to_handler)
21381 subq $24, %rsp
21382@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21383 movq 8(%rsp), %rdx
21384 movq (%rsp), %rax
21385 addq $24, %rsp
21386+ pax_force_fptr %rdi
21387 jmp *%rdi
21388+ENDPROC(return_to_handler)
21389 #endif
21390
21391
21392@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21393 ENDPROC(native_usergs_sysret64)
21394 #endif /* CONFIG_PARAVIRT */
21395
21396+ .macro ljmpq sel, off
21397+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21398+ .byte 0x48; ljmp *1234f(%rip)
21399+ .pushsection .rodata
21400+ .align 16
21401+ 1234: .quad \off; .word \sel
21402+ .popsection
21403+#else
21404+ pushq $\sel
21405+ pushq $\off
21406+ lretq
21407+#endif
21408+ .endm
21409+
21410+ .macro pax_enter_kernel
21411+ pax_set_fptr_mask
21412+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21413+ call pax_enter_kernel
21414+#endif
21415+ .endm
21416+
21417+ .macro pax_exit_kernel
21418+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21419+ call pax_exit_kernel
21420+#endif
21421+
21422+ .endm
21423+
21424+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21425+ENTRY(pax_enter_kernel)
21426+ pushq %rdi
21427+
21428+#ifdef CONFIG_PARAVIRT
21429+ PV_SAVE_REGS(CLBR_RDI)
21430+#endif
21431+
21432+#ifdef CONFIG_PAX_KERNEXEC
21433+ GET_CR0_INTO_RDI
21434+ bts $16,%rdi
21435+ jnc 3f
21436+ mov %cs,%edi
21437+ cmp $__KERNEL_CS,%edi
21438+ jnz 2f
21439+1:
21440+#endif
21441+
21442+#ifdef CONFIG_PAX_MEMORY_UDEREF
21443+ 661: jmp 111f
21444+ .pushsection .altinstr_replacement, "a"
21445+ 662: ASM_NOP2
21446+ .popsection
21447+ .pushsection .altinstructions, "a"
21448+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21449+ .popsection
21450+ GET_CR3_INTO_RDI
21451+ cmp $0,%dil
21452+ jnz 112f
21453+ mov $__KERNEL_DS,%edi
21454+ mov %edi,%ss
21455+ jmp 111f
21456+112: cmp $1,%dil
21457+ jz 113f
21458+ ud2
21459+113: sub $4097,%rdi
21460+ bts $63,%rdi
21461+ SET_RDI_INTO_CR3
21462+ mov $__UDEREF_KERNEL_DS,%edi
21463+ mov %edi,%ss
21464+111:
21465+#endif
21466+
21467+#ifdef CONFIG_PARAVIRT
21468+ PV_RESTORE_REGS(CLBR_RDI)
21469+#endif
21470+
21471+ popq %rdi
21472+ pax_force_retaddr
21473+ retq
21474+
21475+#ifdef CONFIG_PAX_KERNEXEC
21476+2: ljmpq __KERNEL_CS,1b
21477+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21478+4: SET_RDI_INTO_CR0
21479+ jmp 1b
21480+#endif
21481+ENDPROC(pax_enter_kernel)
21482+
21483+ENTRY(pax_exit_kernel)
21484+ pushq %rdi
21485+
21486+#ifdef CONFIG_PARAVIRT
21487+ PV_SAVE_REGS(CLBR_RDI)
21488+#endif
21489+
21490+#ifdef CONFIG_PAX_KERNEXEC
21491+ mov %cs,%rdi
21492+ cmp $__KERNEXEC_KERNEL_CS,%edi
21493+ jz 2f
21494+ GET_CR0_INTO_RDI
21495+ bts $16,%rdi
21496+ jnc 4f
21497+1:
21498+#endif
21499+
21500+#ifdef CONFIG_PAX_MEMORY_UDEREF
21501+ 661: jmp 111f
21502+ .pushsection .altinstr_replacement, "a"
21503+ 662: ASM_NOP2
21504+ .popsection
21505+ .pushsection .altinstructions, "a"
21506+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21507+ .popsection
21508+ mov %ss,%edi
21509+ cmp $__UDEREF_KERNEL_DS,%edi
21510+ jnz 111f
21511+ GET_CR3_INTO_RDI
21512+ cmp $0,%dil
21513+ jz 112f
21514+ ud2
21515+112: add $4097,%rdi
21516+ bts $63,%rdi
21517+ SET_RDI_INTO_CR3
21518+ mov $__KERNEL_DS,%edi
21519+ mov %edi,%ss
21520+111:
21521+#endif
21522+
21523+#ifdef CONFIG_PARAVIRT
21524+ PV_RESTORE_REGS(CLBR_RDI);
21525+#endif
21526+
21527+ popq %rdi
21528+ pax_force_retaddr
21529+ retq
21530+
21531+#ifdef CONFIG_PAX_KERNEXEC
21532+2: GET_CR0_INTO_RDI
21533+ btr $16,%rdi
21534+ jnc 4f
21535+ ljmpq __KERNEL_CS,3f
21536+3: SET_RDI_INTO_CR0
21537+ jmp 1b
21538+4: ud2
21539+ jmp 4b
21540+#endif
21541+ENDPROC(pax_exit_kernel)
21542+#endif
21543+
21544+ .macro pax_enter_kernel_user
21545+ pax_set_fptr_mask
21546+#ifdef CONFIG_PAX_MEMORY_UDEREF
21547+ call pax_enter_kernel_user
21548+#endif
21549+ .endm
21550+
21551+ .macro pax_exit_kernel_user
21552+#ifdef CONFIG_PAX_MEMORY_UDEREF
21553+ call pax_exit_kernel_user
21554+#endif
21555+#ifdef CONFIG_PAX_RANDKSTACK
21556+ pushq %rax
21557+ pushq %r11
21558+ call pax_randomize_kstack
21559+ popq %r11
21560+ popq %rax
21561+#endif
21562+ .endm
21563+
21564+#ifdef CONFIG_PAX_MEMORY_UDEREF
21565+ENTRY(pax_enter_kernel_user)
21566+ pushq %rdi
21567+ pushq %rbx
21568+
21569+#ifdef CONFIG_PARAVIRT
21570+ PV_SAVE_REGS(CLBR_RDI)
21571+#endif
21572+
21573+ 661: jmp 111f
21574+ .pushsection .altinstr_replacement, "a"
21575+ 662: ASM_NOP2
21576+ .popsection
21577+ .pushsection .altinstructions, "a"
21578+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21579+ .popsection
21580+ GET_CR3_INTO_RDI
21581+ cmp $1,%dil
21582+ jnz 4f
21583+ sub $4097,%rdi
21584+ bts $63,%rdi
21585+ SET_RDI_INTO_CR3
21586+ jmp 3f
21587+111:
21588+
21589+ GET_CR3_INTO_RDI
21590+ mov %rdi,%rbx
21591+ add $__START_KERNEL_map,%rbx
21592+ sub phys_base(%rip),%rbx
21593+
21594+#ifdef CONFIG_PARAVIRT
21595+ cmpl $0, pv_info+PARAVIRT_enabled
21596+ jz 1f
21597+ pushq %rdi
21598+ i = 0
21599+ .rept USER_PGD_PTRS
21600+ mov i*8(%rbx),%rsi
21601+ mov $0,%sil
21602+ lea i*8(%rbx),%rdi
21603+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21604+ i = i + 1
21605+ .endr
21606+ popq %rdi
21607+ jmp 2f
21608+1:
21609+#endif
21610+
21611+ i = 0
21612+ .rept USER_PGD_PTRS
21613+ movb $0,i*8(%rbx)
21614+ i = i + 1
21615+ .endr
21616+
21617+2: SET_RDI_INTO_CR3
21618+
21619+#ifdef CONFIG_PAX_KERNEXEC
21620+ GET_CR0_INTO_RDI
21621+ bts $16,%rdi
21622+ SET_RDI_INTO_CR0
21623+#endif
21624+
21625+3:
21626+
21627+#ifdef CONFIG_PARAVIRT
21628+ PV_RESTORE_REGS(CLBR_RDI)
21629+#endif
21630+
21631+ popq %rbx
21632+ popq %rdi
21633+ pax_force_retaddr
21634+ retq
21635+4: ud2
21636+ENDPROC(pax_enter_kernel_user)
21637+
21638+ENTRY(pax_exit_kernel_user)
21639+ pushq %rdi
21640+ pushq %rbx
21641+
21642+#ifdef CONFIG_PARAVIRT
21643+ PV_SAVE_REGS(CLBR_RDI)
21644+#endif
21645+
21646+ GET_CR3_INTO_RDI
21647+ 661: jmp 1f
21648+ .pushsection .altinstr_replacement, "a"
21649+ 662: ASM_NOP2
21650+ .popsection
21651+ .pushsection .altinstructions, "a"
21652+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21653+ .popsection
21654+ cmp $0,%dil
21655+ jnz 3f
21656+ add $4097,%rdi
21657+ bts $63,%rdi
21658+ SET_RDI_INTO_CR3
21659+ jmp 2f
21660+1:
21661+
21662+ mov %rdi,%rbx
21663+
21664+#ifdef CONFIG_PAX_KERNEXEC
21665+ GET_CR0_INTO_RDI
21666+ btr $16,%rdi
21667+ jnc 3f
21668+ SET_RDI_INTO_CR0
21669+#endif
21670+
21671+ add $__START_KERNEL_map,%rbx
21672+ sub phys_base(%rip),%rbx
21673+
21674+#ifdef CONFIG_PARAVIRT
21675+ cmpl $0, pv_info+PARAVIRT_enabled
21676+ jz 1f
21677+ i = 0
21678+ .rept USER_PGD_PTRS
21679+ mov i*8(%rbx),%rsi
21680+ mov $0x67,%sil
21681+ lea i*8(%rbx),%rdi
21682+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21683+ i = i + 1
21684+ .endr
21685+ jmp 2f
21686+1:
21687+#endif
21688+
21689+ i = 0
21690+ .rept USER_PGD_PTRS
21691+ movb $0x67,i*8(%rbx)
21692+ i = i + 1
21693+ .endr
21694+2:
21695+
21696+#ifdef CONFIG_PARAVIRT
21697+ PV_RESTORE_REGS(CLBR_RDI)
21698+#endif
21699+
21700+ popq %rbx
21701+ popq %rdi
21702+ pax_force_retaddr
21703+ retq
21704+3: ud2
21705+ENDPROC(pax_exit_kernel_user)
21706+#endif
21707+
21708+ .macro pax_enter_kernel_nmi
21709+ pax_set_fptr_mask
21710+
21711+#ifdef CONFIG_PAX_KERNEXEC
21712+ GET_CR0_INTO_RDI
21713+ bts $16,%rdi
21714+ jc 110f
21715+ SET_RDI_INTO_CR0
21716+ or $2,%ebx
21717+110:
21718+#endif
21719+
21720+#ifdef CONFIG_PAX_MEMORY_UDEREF
21721+ 661: jmp 111f
21722+ .pushsection .altinstr_replacement, "a"
21723+ 662: ASM_NOP2
21724+ .popsection
21725+ .pushsection .altinstructions, "a"
21726+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21727+ .popsection
21728+ GET_CR3_INTO_RDI
21729+ cmp $0,%dil
21730+ jz 111f
21731+ sub $4097,%rdi
21732+ or $4,%ebx
21733+ bts $63,%rdi
21734+ SET_RDI_INTO_CR3
21735+ mov $__UDEREF_KERNEL_DS,%edi
21736+ mov %edi,%ss
21737+111:
21738+#endif
21739+ .endm
21740+
21741+ .macro pax_exit_kernel_nmi
21742+#ifdef CONFIG_PAX_KERNEXEC
21743+ btr $1,%ebx
21744+ jnc 110f
21745+ GET_CR0_INTO_RDI
21746+ btr $16,%rdi
21747+ SET_RDI_INTO_CR0
21748+110:
21749+#endif
21750+
21751+#ifdef CONFIG_PAX_MEMORY_UDEREF
21752+ btr $2,%ebx
21753+ jnc 111f
21754+ GET_CR3_INTO_RDI
21755+ add $4097,%rdi
21756+ bts $63,%rdi
21757+ SET_RDI_INTO_CR3
21758+ mov $__KERNEL_DS,%edi
21759+ mov %edi,%ss
21760+111:
21761+#endif
21762+ .endm
21763+
21764+ .macro pax_erase_kstack
21765+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21766+ call pax_erase_kstack
21767+#endif
21768+ .endm
21769+
21770+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21771+ENTRY(pax_erase_kstack)
21772+ pushq %rdi
21773+ pushq %rcx
21774+ pushq %rax
21775+ pushq %r11
21776+
21777+ GET_THREAD_INFO(%r11)
21778+ mov TI_lowest_stack(%r11), %rdi
21779+ mov $-0xBEEF, %rax
21780+ std
21781+
21782+1: mov %edi, %ecx
21783+ and $THREAD_SIZE_asm - 1, %ecx
21784+ shr $3, %ecx
21785+ repne scasq
21786+ jecxz 2f
21787+
21788+ cmp $2*8, %ecx
21789+ jc 2f
21790+
21791+ mov $2*8, %ecx
21792+ repe scasq
21793+ jecxz 2f
21794+ jne 1b
21795+
21796+2: cld
21797+ mov %esp, %ecx
21798+ sub %edi, %ecx
21799+
21800+ cmp $THREAD_SIZE_asm, %rcx
21801+ jb 3f
21802+ ud2
21803+3:
21804+
21805+ shr $3, %ecx
21806+ rep stosq
21807+
21808+ mov TI_task_thread_sp0(%r11), %rdi
21809+ sub $256, %rdi
21810+ mov %rdi, TI_lowest_stack(%r11)
21811+
21812+ popq %r11
21813+ popq %rax
21814+ popq %rcx
21815+ popq %rdi
21816+ pax_force_retaddr
21817+ ret
21818+ENDPROC(pax_erase_kstack)
21819+#endif
21820
21821 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21822 #ifdef CONFIG_TRACE_IRQFLAGS
21823@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21824 .endm
21825
21826 .macro UNFAKE_STACK_FRAME
21827- addq $8*6, %rsp
21828- CFI_ADJUST_CFA_OFFSET -(6*8)
21829+ addq $8*6 + ARG_SKIP, %rsp
21830+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21831 .endm
21832
21833 /*
21834@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21835 movq %rsp, %rsi
21836
21837 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21838- testl $3, CS-RBP(%rsi)
21839+ testb $3, CS-RBP(%rsi)
21840 je 1f
21841 SWAPGS
21842 /*
21843@@ -498,9 +931,10 @@ ENTRY(save_rest)
21844 movq_cfi r15, R15+16
21845 movq %r11, 8(%rsp) /* return address */
21846 FIXUP_TOP_OF_STACK %r11, 16
21847+ pax_force_retaddr
21848 ret
21849 CFI_ENDPROC
21850-END(save_rest)
21851+ENDPROC(save_rest)
21852
21853 /* save complete stack frame */
21854 .pushsection .kprobes.text, "ax"
21855@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21856 js 1f /* negative -> in kernel */
21857 SWAPGS
21858 xorl %ebx,%ebx
21859-1: ret
21860+1: pax_force_retaddr_bts
21861+ ret
21862 CFI_ENDPROC
21863-END(save_paranoid)
21864+ENDPROC(save_paranoid)
21865 .popsection
21866
21867 /*
21868@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21869
21870 RESTORE_REST
21871
21872- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21873+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21874 jz 1f
21875
21876 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21877@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21878 RESTORE_REST
21879 jmp int_ret_from_sys_call
21880 CFI_ENDPROC
21881-END(ret_from_fork)
21882+ENDPROC(ret_from_fork)
21883
21884 /*
21885 * System call entry. Up to 6 arguments in registers are supported.
21886@@ -608,7 +1043,7 @@ END(ret_from_fork)
21887 ENTRY(system_call)
21888 CFI_STARTPROC simple
21889 CFI_SIGNAL_FRAME
21890- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21891+ CFI_DEF_CFA rsp,0
21892 CFI_REGISTER rip,rcx
21893 /*CFI_REGISTER rflags,r11*/
21894 SWAPGS_UNSAFE_STACK
21895@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21896
21897 movq %rsp,PER_CPU_VAR(old_rsp)
21898 movq PER_CPU_VAR(kernel_stack),%rsp
21899+ SAVE_ARGS 8*6,0
21900+ pax_enter_kernel_user
21901+
21902+#ifdef CONFIG_PAX_RANDKSTACK
21903+ pax_erase_kstack
21904+#endif
21905+
21906 /*
21907 * No need to follow this irqs off/on section - it's straight
21908 * and short:
21909 */
21910 ENABLE_INTERRUPTS(CLBR_NONE)
21911- SAVE_ARGS 8,0
21912 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21913 movq %rcx,RIP-ARGOFFSET(%rsp)
21914 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21915- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21916+ GET_THREAD_INFO(%rcx)
21917+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21918 jnz tracesys
21919 system_call_fastpath:
21920 #if __SYSCALL_MASK == ~0
21921@@ -640,7 +1082,7 @@ system_call_fastpath:
21922 cmpl $__NR_syscall_max,%eax
21923 #endif
21924 ja badsys
21925- movq %r10,%rcx
21926+ movq R10-ARGOFFSET(%rsp),%rcx
21927 call *sys_call_table(,%rax,8) # XXX: rip relative
21928 movq %rax,RAX-ARGOFFSET(%rsp)
21929 /*
21930@@ -654,10 +1096,13 @@ sysret_check:
21931 LOCKDEP_SYS_EXIT
21932 DISABLE_INTERRUPTS(CLBR_NONE)
21933 TRACE_IRQS_OFF
21934- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21935+ GET_THREAD_INFO(%rcx)
21936+ movl TI_flags(%rcx),%edx
21937 andl %edi,%edx
21938 jnz sysret_careful
21939 CFI_REMEMBER_STATE
21940+ pax_exit_kernel_user
21941+ pax_erase_kstack
21942 /*
21943 * sysretq will re-enable interrupts:
21944 */
21945@@ -709,14 +1154,18 @@ badsys:
21946 * jump back to the normal fast path.
21947 */
21948 auditsys:
21949- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21950+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21951 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21952 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21953 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21954 movq %rax,%rsi /* 2nd arg: syscall number */
21955 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21956 call __audit_syscall_entry
21957+
21958+ pax_erase_kstack
21959+
21960 LOAD_ARGS 0 /* reload call-clobbered registers */
21961+ pax_set_fptr_mask
21962 jmp system_call_fastpath
21963
21964 /*
21965@@ -737,7 +1186,7 @@ sysret_audit:
21966 /* Do syscall tracing */
21967 tracesys:
21968 #ifdef CONFIG_AUDITSYSCALL
21969- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21970+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21971 jz auditsys
21972 #endif
21973 SAVE_REST
21974@@ -745,12 +1194,16 @@ tracesys:
21975 FIXUP_TOP_OF_STACK %rdi
21976 movq %rsp,%rdi
21977 call syscall_trace_enter
21978+
21979+ pax_erase_kstack
21980+
21981 /*
21982 * Reload arg registers from stack in case ptrace changed them.
21983 * We don't reload %rax because syscall_trace_enter() returned
21984 * the value it wants us to use in the table lookup.
21985 */
21986 LOAD_ARGS ARGOFFSET, 1
21987+ pax_set_fptr_mask
21988 RESTORE_REST
21989 #if __SYSCALL_MASK == ~0
21990 cmpq $__NR_syscall_max,%rax
21991@@ -759,7 +1212,7 @@ tracesys:
21992 cmpl $__NR_syscall_max,%eax
21993 #endif
21994 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21995- movq %r10,%rcx /* fixup for C */
21996+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21997 call *sys_call_table(,%rax,8)
21998 movq %rax,RAX-ARGOFFSET(%rsp)
21999 /* Use IRET because user could have changed frame */
22000@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
22001 andl %edi,%edx
22002 jnz int_careful
22003 andl $~TS_COMPAT,TI_status(%rcx)
22004- jmp retint_swapgs
22005+ pax_exit_kernel_user
22006+ pax_erase_kstack
22007+ jmp retint_swapgs_pax
22008
22009 /* Either reschedule or signal or syscall exit tracking needed. */
22010 /* First do a reschedule test. */
22011@@ -826,7 +1281,7 @@ int_restore_rest:
22012 TRACE_IRQS_OFF
22013 jmp int_with_check
22014 CFI_ENDPROC
22015-END(system_call)
22016+ENDPROC(system_call)
22017
22018 .macro FORK_LIKE func
22019 ENTRY(stub_\func)
22020@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22021 DEFAULT_FRAME 0 8 /* offset 8: return address */
22022 call sys_\func
22023 RESTORE_TOP_OF_STACK %r11, 8
22024+ pax_force_retaddr
22025 ret $REST_SKIP /* pop extended registers */
22026 CFI_ENDPROC
22027-END(stub_\func)
22028+ENDPROC(stub_\func)
22029 .endm
22030
22031 .macro FIXED_FRAME label,func
22032@@ -851,9 +1307,10 @@ ENTRY(\label)
22033 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22034 call \func
22035 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22036+ pax_force_retaddr
22037 ret
22038 CFI_ENDPROC
22039-END(\label)
22040+ENDPROC(\label)
22041 .endm
22042
22043 FORK_LIKE clone
22044@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22045 movq_cfi_restore R12+8, r12
22046 movq_cfi_restore RBP+8, rbp
22047 movq_cfi_restore RBX+8, rbx
22048+ pax_force_retaddr
22049 ret $REST_SKIP /* pop extended registers */
22050 CFI_ENDPROC
22051-END(ptregscall_common)
22052+ENDPROC(ptregscall_common)
22053
22054 ENTRY(stub_execve)
22055 CFI_STARTPROC
22056@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22057 RESTORE_REST
22058 jmp int_ret_from_sys_call
22059 CFI_ENDPROC
22060-END(stub_execve)
22061+ENDPROC(stub_execve)
22062
22063 /*
22064 * sigreturn is special because it needs to restore all registers on return.
22065@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22066 RESTORE_REST
22067 jmp int_ret_from_sys_call
22068 CFI_ENDPROC
22069-END(stub_rt_sigreturn)
22070+ENDPROC(stub_rt_sigreturn)
22071
22072 #ifdef CONFIG_X86_X32_ABI
22073 ENTRY(stub_x32_rt_sigreturn)
22074@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22075 RESTORE_REST
22076 jmp int_ret_from_sys_call
22077 CFI_ENDPROC
22078-END(stub_x32_rt_sigreturn)
22079+ENDPROC(stub_x32_rt_sigreturn)
22080
22081 ENTRY(stub_x32_execve)
22082 CFI_STARTPROC
22083@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22084 RESTORE_REST
22085 jmp int_ret_from_sys_call
22086 CFI_ENDPROC
22087-END(stub_x32_execve)
22088+ENDPROC(stub_x32_execve)
22089
22090 #endif
22091
22092@@ -967,7 +1425,7 @@ vector=vector+1
22093 2: jmp common_interrupt
22094 .endr
22095 CFI_ENDPROC
22096-END(irq_entries_start)
22097+ENDPROC(irq_entries_start)
22098
22099 .previous
22100 END(interrupt)
22101@@ -987,6 +1445,16 @@ END(interrupt)
22102 subq $ORIG_RAX-RBP, %rsp
22103 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22104 SAVE_ARGS_IRQ
22105+#ifdef CONFIG_PAX_MEMORY_UDEREF
22106+ testb $3, CS(%rdi)
22107+ jnz 1f
22108+ pax_enter_kernel
22109+ jmp 2f
22110+1: pax_enter_kernel_user
22111+2:
22112+#else
22113+ pax_enter_kernel
22114+#endif
22115 call \func
22116 .endm
22117
22118@@ -1019,7 +1487,7 @@ ret_from_intr:
22119
22120 exit_intr:
22121 GET_THREAD_INFO(%rcx)
22122- testl $3,CS-ARGOFFSET(%rsp)
22123+ testb $3,CS-ARGOFFSET(%rsp)
22124 je retint_kernel
22125
22126 /* Interrupt came from user space */
22127@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22128 * The iretq could re-enable interrupts:
22129 */
22130 DISABLE_INTERRUPTS(CLBR_ANY)
22131+ pax_exit_kernel_user
22132+retint_swapgs_pax:
22133 TRACE_IRQS_IRETQ
22134 SWAPGS
22135 jmp restore_args
22136
22137 retint_restore_args: /* return to kernel space */
22138 DISABLE_INTERRUPTS(CLBR_ANY)
22139+ pax_exit_kernel
22140+ pax_force_retaddr (RIP-ARGOFFSET)
22141 /*
22142 * The iretq could re-enable interrupts:
22143 */
22144@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22145 #endif
22146
22147 CFI_ENDPROC
22148-END(common_interrupt)
22149+ENDPROC(common_interrupt)
22150 /*
22151 * End of kprobes section
22152 */
22153@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22154 interrupt \do_sym
22155 jmp ret_from_intr
22156 CFI_ENDPROC
22157-END(\sym)
22158+ENDPROC(\sym)
22159 .endm
22160
22161 #ifdef CONFIG_TRACING
22162@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22163 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22164 call error_entry
22165 DEFAULT_FRAME 0
22166+#ifdef CONFIG_PAX_MEMORY_UDEREF
22167+ testb $3, CS(%rsp)
22168+ jnz 1f
22169+ pax_enter_kernel
22170+ jmp 2f
22171+1: pax_enter_kernel_user
22172+2:
22173+#else
22174+ pax_enter_kernel
22175+#endif
22176 movq %rsp,%rdi /* pt_regs pointer */
22177 xorl %esi,%esi /* no error code */
22178 call \do_sym
22179 jmp error_exit /* %ebx: no swapgs flag */
22180 CFI_ENDPROC
22181-END(\sym)
22182+ENDPROC(\sym)
22183 .endm
22184
22185 .macro paranoidzeroentry sym do_sym
22186@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22187 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22188 call save_paranoid
22189 TRACE_IRQS_OFF
22190+#ifdef CONFIG_PAX_MEMORY_UDEREF
22191+ testb $3, CS(%rsp)
22192+ jnz 1f
22193+ pax_enter_kernel
22194+ jmp 2f
22195+1: pax_enter_kernel_user
22196+2:
22197+#else
22198+ pax_enter_kernel
22199+#endif
22200 movq %rsp,%rdi /* pt_regs pointer */
22201 xorl %esi,%esi /* no error code */
22202 call \do_sym
22203 jmp paranoid_exit /* %ebx: no swapgs flag */
22204 CFI_ENDPROC
22205-END(\sym)
22206+ENDPROC(\sym)
22207 .endm
22208
22209-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22210+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22211 .macro paranoidzeroentry_ist sym do_sym ist
22212 ENTRY(\sym)
22213 INTR_FRAME
22214@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22215 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22216 call save_paranoid
22217 TRACE_IRQS_OFF_DEBUG
22218+#ifdef CONFIG_PAX_MEMORY_UDEREF
22219+ testb $3, CS(%rsp)
22220+ jnz 1f
22221+ pax_enter_kernel
22222+ jmp 2f
22223+1: pax_enter_kernel_user
22224+2:
22225+#else
22226+ pax_enter_kernel
22227+#endif
22228 movq %rsp,%rdi /* pt_regs pointer */
22229 xorl %esi,%esi /* no error code */
22230+#ifdef CONFIG_SMP
22231+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22232+ lea init_tss(%r12), %r12
22233+#else
22234+ lea init_tss(%rip), %r12
22235+#endif
22236 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22237 call \do_sym
22238 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22239 jmp paranoid_exit /* %ebx: no swapgs flag */
22240 CFI_ENDPROC
22241-END(\sym)
22242+ENDPROC(\sym)
22243 .endm
22244
22245 .macro errorentry sym do_sym
22246@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22247 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22248 call error_entry
22249 DEFAULT_FRAME 0
22250+#ifdef CONFIG_PAX_MEMORY_UDEREF
22251+ testb $3, CS(%rsp)
22252+ jnz 1f
22253+ pax_enter_kernel
22254+ jmp 2f
22255+1: pax_enter_kernel_user
22256+2:
22257+#else
22258+ pax_enter_kernel
22259+#endif
22260 movq %rsp,%rdi /* pt_regs pointer */
22261 movq ORIG_RAX(%rsp),%rsi /* get error code */
22262 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22263 call \do_sym
22264 jmp error_exit /* %ebx: no swapgs flag */
22265 CFI_ENDPROC
22266-END(\sym)
22267+ENDPROC(\sym)
22268 .endm
22269
22270 /* error code is on the stack already */
22271@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22272 call save_paranoid
22273 DEFAULT_FRAME 0
22274 TRACE_IRQS_OFF
22275+#ifdef CONFIG_PAX_MEMORY_UDEREF
22276+ testb $3, CS(%rsp)
22277+ jnz 1f
22278+ pax_enter_kernel
22279+ jmp 2f
22280+1: pax_enter_kernel_user
22281+2:
22282+#else
22283+ pax_enter_kernel
22284+#endif
22285 movq %rsp,%rdi /* pt_regs pointer */
22286 movq ORIG_RAX(%rsp),%rsi /* get error code */
22287 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22288 call \do_sym
22289 jmp paranoid_exit /* %ebx: no swapgs flag */
22290 CFI_ENDPROC
22291-END(\sym)
22292+ENDPROC(\sym)
22293 .endm
22294
22295 zeroentry divide_error do_divide_error
22296@@ -1342,9 +1870,10 @@ gs_change:
22297 2: mfence /* workaround */
22298 SWAPGS
22299 popfq_cfi
22300+ pax_force_retaddr
22301 ret
22302 CFI_ENDPROC
22303-END(native_load_gs_index)
22304+ENDPROC(native_load_gs_index)
22305
22306 _ASM_EXTABLE(gs_change,bad_gs)
22307 .section .fixup,"ax"
22308@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22309 CFI_DEF_CFA_REGISTER rsp
22310 CFI_ADJUST_CFA_OFFSET -8
22311 decl PER_CPU_VAR(irq_count)
22312+ pax_force_retaddr
22313 ret
22314 CFI_ENDPROC
22315-END(call_softirq)
22316+ENDPROC(call_softirq)
22317
22318 #ifdef CONFIG_XEN
22319 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22320@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22321 decl PER_CPU_VAR(irq_count)
22322 jmp error_exit
22323 CFI_ENDPROC
22324-END(xen_do_hypervisor_callback)
22325+ENDPROC(xen_do_hypervisor_callback)
22326
22327 /*
22328 * Hypervisor uses this for application faults while it executes.
22329@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22330 SAVE_ALL
22331 jmp error_exit
22332 CFI_ENDPROC
22333-END(xen_failsafe_callback)
22334+ENDPROC(xen_failsafe_callback)
22335
22336 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22337 xen_hvm_callback_vector xen_evtchn_do_upcall
22338@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22339 DEFAULT_FRAME
22340 DISABLE_INTERRUPTS(CLBR_NONE)
22341 TRACE_IRQS_OFF_DEBUG
22342- testl %ebx,%ebx /* swapgs needed? */
22343+ testl $1,%ebx /* swapgs needed? */
22344 jnz paranoid_restore
22345- testl $3,CS(%rsp)
22346+ testb $3,CS(%rsp)
22347 jnz paranoid_userspace
22348+#ifdef CONFIG_PAX_MEMORY_UDEREF
22349+ pax_exit_kernel
22350+ TRACE_IRQS_IRETQ 0
22351+ SWAPGS_UNSAFE_STACK
22352+ RESTORE_ALL 8
22353+ pax_force_retaddr_bts
22354+ jmp irq_return
22355+#endif
22356 paranoid_swapgs:
22357+#ifdef CONFIG_PAX_MEMORY_UDEREF
22358+ pax_exit_kernel_user
22359+#else
22360+ pax_exit_kernel
22361+#endif
22362 TRACE_IRQS_IRETQ 0
22363 SWAPGS_UNSAFE_STACK
22364 RESTORE_ALL 8
22365 jmp irq_return
22366 paranoid_restore:
22367+ pax_exit_kernel
22368 TRACE_IRQS_IRETQ_DEBUG 0
22369 RESTORE_ALL 8
22370+ pax_force_retaddr_bts
22371 jmp irq_return
22372 paranoid_userspace:
22373 GET_THREAD_INFO(%rcx)
22374@@ -1563,7 +2108,7 @@ paranoid_schedule:
22375 TRACE_IRQS_OFF
22376 jmp paranoid_userspace
22377 CFI_ENDPROC
22378-END(paranoid_exit)
22379+ENDPROC(paranoid_exit)
22380
22381 /*
22382 * Exception entry point. This expects an error code/orig_rax on the stack.
22383@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22384 movq_cfi r14, R14+8
22385 movq_cfi r15, R15+8
22386 xorl %ebx,%ebx
22387- testl $3,CS+8(%rsp)
22388+ testb $3,CS+8(%rsp)
22389 je error_kernelspace
22390 error_swapgs:
22391 SWAPGS
22392 error_sti:
22393 TRACE_IRQS_OFF
22394+ pax_force_retaddr_bts
22395 ret
22396
22397 /*
22398@@ -1622,7 +2168,7 @@ bstep_iret:
22399 movq %rcx,RIP+8(%rsp)
22400 jmp error_swapgs
22401 CFI_ENDPROC
22402-END(error_entry)
22403+ENDPROC(error_entry)
22404
22405
22406 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22407@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22408 DISABLE_INTERRUPTS(CLBR_NONE)
22409 TRACE_IRQS_OFF
22410 GET_THREAD_INFO(%rcx)
22411- testl %eax,%eax
22412+ testl $1,%eax
22413 jne retint_kernel
22414 LOCKDEP_SYS_EXIT_IRQ
22415 movl TI_flags(%rcx),%edx
22416@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22417 jnz retint_careful
22418 jmp retint_swapgs
22419 CFI_ENDPROC
22420-END(error_exit)
22421+ENDPROC(error_exit)
22422
22423 /*
22424 * Test if a given stack is an NMI stack or not.
22425@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22426 * If %cs was not the kernel segment, then the NMI triggered in user
22427 * space, which means it is definitely not nested.
22428 */
22429+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22430+ je 1f
22431 cmpl $__KERNEL_CS, 16(%rsp)
22432 jne first_nmi
22433-
22434+1:
22435 /*
22436 * Check the special variable on the stack to see if NMIs are
22437 * executing.
22438@@ -1736,8 +2284,7 @@ nested_nmi:
22439
22440 1:
22441 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22442- leaq -1*8(%rsp), %rdx
22443- movq %rdx, %rsp
22444+ subq $8, %rsp
22445 CFI_ADJUST_CFA_OFFSET 1*8
22446 leaq -10*8(%rsp), %rdx
22447 pushq_cfi $__KERNEL_DS
22448@@ -1755,6 +2302,7 @@ nested_nmi_out:
22449 CFI_RESTORE rdx
22450
22451 /* No need to check faults here */
22452+# pax_force_retaddr_bts
22453 INTERRUPT_RETURN
22454
22455 CFI_RESTORE_STATE
22456@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22457 */
22458 movq %cr2, %r12
22459
22460+ pax_enter_kernel_nmi
22461+
22462 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22463 movq %rsp,%rdi
22464 movq $-1,%rsi
22465@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22466 movq %r12, %cr2
22467 1:
22468
22469- testl %ebx,%ebx /* swapgs needed? */
22470+ testl $1,%ebx /* swapgs needed? */
22471 jnz nmi_restore
22472 nmi_swapgs:
22473 SWAPGS_UNSAFE_STACK
22474 nmi_restore:
22475+ pax_exit_kernel_nmi
22476 /* Pop the extra iret frame at once */
22477 RESTORE_ALL 6*8
22478+ testb $3, 8(%rsp)
22479+ jnz 1f
22480+ pax_force_retaddr_bts
22481+1:
22482
22483 /* Clear the NMI executing stack variable */
22484 movq $0, 5*8(%rsp)
22485 jmp irq_return
22486 CFI_ENDPROC
22487-END(nmi)
22488+ENDPROC(nmi)
22489
22490 ENTRY(ignore_sysret)
22491 CFI_STARTPROC
22492 mov $-ENOSYS,%eax
22493 sysret
22494 CFI_ENDPROC
22495-END(ignore_sysret)
22496+ENDPROC(ignore_sysret)
22497
22498 /*
22499 * End of kprobes section
22500diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22501index 42a392a..fbbd930 100644
22502--- a/arch/x86/kernel/ftrace.c
22503+++ b/arch/x86/kernel/ftrace.c
22504@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22505 {
22506 unsigned char replaced[MCOUNT_INSN_SIZE];
22507
22508+ ip = ktla_ktva(ip);
22509+
22510 /*
22511 * Note: Due to modules and __init, code can
22512 * disappear and change, we need to protect against faulting
22513@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22514 unsigned char old[MCOUNT_INSN_SIZE], *new;
22515 int ret;
22516
22517- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22518+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22519 new = ftrace_call_replace(ip, (unsigned long)func);
22520
22521 /* See comment above by declaration of modifying_ftrace_code */
22522@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22523 /* Also update the regs callback function */
22524 if (!ret) {
22525 ip = (unsigned long)(&ftrace_regs_call);
22526- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22527+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22528 new = ftrace_call_replace(ip, (unsigned long)func);
22529 ret = ftrace_modify_code(ip, old, new);
22530 }
22531@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22532 * kernel identity mapping to modify code.
22533 */
22534 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22535- ip = (unsigned long)__va(__pa_symbol(ip));
22536+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22537
22538 return probe_kernel_write((void *)ip, val, size);
22539 }
22540@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22541 unsigned char replaced[MCOUNT_INSN_SIZE];
22542 unsigned char brk = BREAKPOINT_INSTRUCTION;
22543
22544- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22545+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22546 return -EFAULT;
22547
22548 /* Make sure it is what we expect it to be */
22549@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22550 return ret;
22551
22552 fail_update:
22553- probe_kernel_write((void *)ip, &old_code[0], 1);
22554+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22555 goto out;
22556 }
22557
22558@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22559 {
22560 unsigned char code[MCOUNT_INSN_SIZE];
22561
22562+ ip = ktla_ktva(ip);
22563+
22564 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22565 return -EFAULT;
22566
22567diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22568index 55b6761..a6456fc 100644
22569--- a/arch/x86/kernel/head64.c
22570+++ b/arch/x86/kernel/head64.c
22571@@ -67,12 +67,12 @@ again:
22572 pgd = *pgd_p;
22573
22574 /*
22575- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22576- * critical -- __PAGE_OFFSET would point us back into the dynamic
22577+ * The use of __early_va rather than __va here is critical:
22578+ * __va would point us back into the dynamic
22579 * range and we might end up looping forever...
22580 */
22581 if (pgd)
22582- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22583+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22584 else {
22585 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22586 reset_early_page_tables();
22587@@ -82,13 +82,13 @@ again:
22588 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22589 for (i = 0; i < PTRS_PER_PUD; i++)
22590 pud_p[i] = 0;
22591- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22592+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22593 }
22594 pud_p += pud_index(address);
22595 pud = *pud_p;
22596
22597 if (pud)
22598- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22599+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22600 else {
22601 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22602 reset_early_page_tables();
22603@@ -98,7 +98,7 @@ again:
22604 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22605 for (i = 0; i < PTRS_PER_PMD; i++)
22606 pmd_p[i] = 0;
22607- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22608+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22609 }
22610 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22611 pmd_p[pmd_index(address)] = pmd;
22612@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22613 if (console_loglevel == 10)
22614 early_printk("Kernel alive\n");
22615
22616- clear_page(init_level4_pgt);
22617 /* set init_level4_pgt kernel high mapping*/
22618 init_level4_pgt[511] = early_level4_pgt[511];
22619
22620diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22621index 5dd87a8..d68b3f4 100644
22622--- a/arch/x86/kernel/head_32.S
22623+++ b/arch/x86/kernel/head_32.S
22624@@ -26,6 +26,12 @@
22625 /* Physical address */
22626 #define pa(X) ((X) - __PAGE_OFFSET)
22627
22628+#ifdef CONFIG_PAX_KERNEXEC
22629+#define ta(X) (X)
22630+#else
22631+#define ta(X) ((X) - __PAGE_OFFSET)
22632+#endif
22633+
22634 /*
22635 * References to members of the new_cpu_data structure.
22636 */
22637@@ -55,11 +61,7 @@
22638 * and small than max_low_pfn, otherwise will waste some page table entries
22639 */
22640
22641-#if PTRS_PER_PMD > 1
22642-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22643-#else
22644-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22645-#endif
22646+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22647
22648 /* Number of possible pages in the lowmem region */
22649 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22650@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22651 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22652
22653 /*
22654+ * Real beginning of normal "text" segment
22655+ */
22656+ENTRY(stext)
22657+ENTRY(_stext)
22658+
22659+/*
22660 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22661 * %esi points to the real-mode code as a 32-bit pointer.
22662 * CS and DS must be 4 GB flat segments, but we don't depend on
22663@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22664 * can.
22665 */
22666 __HEAD
22667+
22668+#ifdef CONFIG_PAX_KERNEXEC
22669+ jmp startup_32
22670+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22671+.fill PAGE_SIZE-5,1,0xcc
22672+#endif
22673+
22674 ENTRY(startup_32)
22675 movl pa(stack_start),%ecx
22676
22677@@ -106,6 +121,59 @@ ENTRY(startup_32)
22678 2:
22679 leal -__PAGE_OFFSET(%ecx),%esp
22680
22681+#ifdef CONFIG_SMP
22682+ movl $pa(cpu_gdt_table),%edi
22683+ movl $__per_cpu_load,%eax
22684+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22685+ rorl $16,%eax
22686+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22687+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22688+ movl $__per_cpu_end - 1,%eax
22689+ subl $__per_cpu_start,%eax
22690+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22691+#endif
22692+
22693+#ifdef CONFIG_PAX_MEMORY_UDEREF
22694+ movl $NR_CPUS,%ecx
22695+ movl $pa(cpu_gdt_table),%edi
22696+1:
22697+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22698+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22699+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22700+ addl $PAGE_SIZE_asm,%edi
22701+ loop 1b
22702+#endif
22703+
22704+#ifdef CONFIG_PAX_KERNEXEC
22705+ movl $pa(boot_gdt),%edi
22706+ movl $__LOAD_PHYSICAL_ADDR,%eax
22707+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22708+ rorl $16,%eax
22709+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22710+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22711+ rorl $16,%eax
22712+
22713+ ljmp $(__BOOT_CS),$1f
22714+1:
22715+
22716+ movl $NR_CPUS,%ecx
22717+ movl $pa(cpu_gdt_table),%edi
22718+ addl $__PAGE_OFFSET,%eax
22719+1:
22720+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22721+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22722+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22723+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22724+ rorl $16,%eax
22725+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22726+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22727+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22728+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22729+ rorl $16,%eax
22730+ addl $PAGE_SIZE_asm,%edi
22731+ loop 1b
22732+#endif
22733+
22734 /*
22735 * Clear BSS first so that there are no surprises...
22736 */
22737@@ -201,8 +269,11 @@ ENTRY(startup_32)
22738 movl %eax, pa(max_pfn_mapped)
22739
22740 /* Do early initialization of the fixmap area */
22741- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22742- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22743+#ifdef CONFIG_COMPAT_VDSO
22744+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22745+#else
22746+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22747+#endif
22748 #else /* Not PAE */
22749
22750 page_pde_offset = (__PAGE_OFFSET >> 20);
22751@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22752 movl %eax, pa(max_pfn_mapped)
22753
22754 /* Do early initialization of the fixmap area */
22755- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22756- movl %eax,pa(initial_page_table+0xffc)
22757+#ifdef CONFIG_COMPAT_VDSO
22758+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22759+#else
22760+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22761+#endif
22762 #endif
22763
22764 #ifdef CONFIG_PARAVIRT
22765@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22766 cmpl $num_subarch_entries, %eax
22767 jae bad_subarch
22768
22769- movl pa(subarch_entries)(,%eax,4), %eax
22770- subl $__PAGE_OFFSET, %eax
22771- jmp *%eax
22772+ jmp *pa(subarch_entries)(,%eax,4)
22773
22774 bad_subarch:
22775 WEAK(lguest_entry)
22776@@ -261,10 +333,10 @@ WEAK(xen_entry)
22777 __INITDATA
22778
22779 subarch_entries:
22780- .long default_entry /* normal x86/PC */
22781- .long lguest_entry /* lguest hypervisor */
22782- .long xen_entry /* Xen hypervisor */
22783- .long default_entry /* Moorestown MID */
22784+ .long ta(default_entry) /* normal x86/PC */
22785+ .long ta(lguest_entry) /* lguest hypervisor */
22786+ .long ta(xen_entry) /* Xen hypervisor */
22787+ .long ta(default_entry) /* Moorestown MID */
22788 num_subarch_entries = (. - subarch_entries) / 4
22789 .previous
22790 #else
22791@@ -354,6 +426,7 @@ default_entry:
22792 movl pa(mmu_cr4_features),%eax
22793 movl %eax,%cr4
22794
22795+#ifdef CONFIG_X86_PAE
22796 testb $X86_CR4_PAE, %al # check if PAE is enabled
22797 jz enable_paging
22798
22799@@ -382,6 +455,9 @@ default_entry:
22800 /* Make changes effective */
22801 wrmsr
22802
22803+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22804+#endif
22805+
22806 enable_paging:
22807
22808 /*
22809@@ -449,14 +525,20 @@ is486:
22810 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22811 movl %eax,%ss # after changing gdt.
22812
22813- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22814+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22815 movl %eax,%ds
22816 movl %eax,%es
22817
22818 movl $(__KERNEL_PERCPU), %eax
22819 movl %eax,%fs # set this cpu's percpu
22820
22821+#ifdef CONFIG_CC_STACKPROTECTOR
22822 movl $(__KERNEL_STACK_CANARY),%eax
22823+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22824+ movl $(__USER_DS),%eax
22825+#else
22826+ xorl %eax,%eax
22827+#endif
22828 movl %eax,%gs
22829
22830 xorl %eax,%eax # Clear LDT
22831@@ -512,8 +594,11 @@ setup_once:
22832 * relocation. Manually set base address in stack canary
22833 * segment descriptor.
22834 */
22835- movl $gdt_page,%eax
22836+ movl $cpu_gdt_table,%eax
22837 movl $stack_canary,%ecx
22838+#ifdef CONFIG_SMP
22839+ addl $__per_cpu_load,%ecx
22840+#endif
22841 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22842 shrl $16, %ecx
22843 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22844@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22845 /* This is global to keep gas from relaxing the jumps */
22846 ENTRY(early_idt_handler)
22847 cld
22848- cmpl $2,%ss:early_recursion_flag
22849+ cmpl $1,%ss:early_recursion_flag
22850 je hlt_loop
22851 incl %ss:early_recursion_flag
22852
22853@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22854 pushl (20+6*4)(%esp) /* trapno */
22855 pushl $fault_msg
22856 call printk
22857-#endif
22858 call dump_stack
22859+#endif
22860 hlt_loop:
22861 hlt
22862 jmp hlt_loop
22863@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22864 /* This is the default interrupt "handler" :-) */
22865 ALIGN
22866 ignore_int:
22867- cld
22868 #ifdef CONFIG_PRINTK
22869+ cmpl $2,%ss:early_recursion_flag
22870+ je hlt_loop
22871+ incl %ss:early_recursion_flag
22872+ cld
22873 pushl %eax
22874 pushl %ecx
22875 pushl %edx
22876@@ -612,9 +700,6 @@ ignore_int:
22877 movl $(__KERNEL_DS),%eax
22878 movl %eax,%ds
22879 movl %eax,%es
22880- cmpl $2,early_recursion_flag
22881- je hlt_loop
22882- incl early_recursion_flag
22883 pushl 16(%esp)
22884 pushl 24(%esp)
22885 pushl 32(%esp)
22886@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22887 /*
22888 * BSS section
22889 */
22890-__PAGE_ALIGNED_BSS
22891- .align PAGE_SIZE
22892 #ifdef CONFIG_X86_PAE
22893+.section .initial_pg_pmd,"a",@progbits
22894 initial_pg_pmd:
22895 .fill 1024*KPMDS,4,0
22896 #else
22897+.section .initial_page_table,"a",@progbits
22898 ENTRY(initial_page_table)
22899 .fill 1024,4,0
22900 #endif
22901+.section .initial_pg_fixmap,"a",@progbits
22902 initial_pg_fixmap:
22903 .fill 1024,4,0
22904+.section .empty_zero_page,"a",@progbits
22905 ENTRY(empty_zero_page)
22906 .fill 4096,1,0
22907+.section .swapper_pg_dir,"a",@progbits
22908 ENTRY(swapper_pg_dir)
22909+#ifdef CONFIG_X86_PAE
22910+ .fill 4,8,0
22911+#else
22912 .fill 1024,4,0
22913+#endif
22914
22915 /*
22916 * This starts the data section.
22917 */
22918 #ifdef CONFIG_X86_PAE
22919-__PAGE_ALIGNED_DATA
22920- /* Page-aligned for the benefit of paravirt? */
22921- .align PAGE_SIZE
22922+.section .initial_page_table,"a",@progbits
22923 ENTRY(initial_page_table)
22924 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22925 # if KPMDS == 3
22926@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22927 # error "Kernel PMDs should be 1, 2 or 3"
22928 # endif
22929 .align PAGE_SIZE /* needs to be page-sized too */
22930+
22931+#ifdef CONFIG_PAX_PER_CPU_PGD
22932+ENTRY(cpu_pgd)
22933+ .rept 2*NR_CPUS
22934+ .fill 4,8,0
22935+ .endr
22936+#endif
22937+
22938 #endif
22939
22940 .data
22941 .balign 4
22942 ENTRY(stack_start)
22943- .long init_thread_union+THREAD_SIZE
22944+ .long init_thread_union+THREAD_SIZE-8
22945
22946 __INITRODATA
22947 int_msg:
22948@@ -722,7 +820,7 @@ fault_msg:
22949 * segment size, and 32-bit linear address value:
22950 */
22951
22952- .data
22953+.section .rodata,"a",@progbits
22954 .globl boot_gdt_descr
22955 .globl idt_descr
22956
22957@@ -731,7 +829,7 @@ fault_msg:
22958 .word 0 # 32 bit align gdt_desc.address
22959 boot_gdt_descr:
22960 .word __BOOT_DS+7
22961- .long boot_gdt - __PAGE_OFFSET
22962+ .long pa(boot_gdt)
22963
22964 .word 0 # 32-bit align idt_desc.address
22965 idt_descr:
22966@@ -742,7 +840,7 @@ idt_descr:
22967 .word 0 # 32 bit align gdt_desc.address
22968 ENTRY(early_gdt_descr)
22969 .word GDT_ENTRIES*8-1
22970- .long gdt_page /* Overwritten for secondary CPUs */
22971+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22972
22973 /*
22974 * The boot_gdt must mirror the equivalent in setup.S and is
22975@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22976 .align L1_CACHE_BYTES
22977 ENTRY(boot_gdt)
22978 .fill GDT_ENTRY_BOOT_CS,8,0
22979- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22980- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22981+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22982+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22983+
22984+ .align PAGE_SIZE_asm
22985+ENTRY(cpu_gdt_table)
22986+ .rept NR_CPUS
22987+ .quad 0x0000000000000000 /* NULL descriptor */
22988+ .quad 0x0000000000000000 /* 0x0b reserved */
22989+ .quad 0x0000000000000000 /* 0x13 reserved */
22990+ .quad 0x0000000000000000 /* 0x1b reserved */
22991+
22992+#ifdef CONFIG_PAX_KERNEXEC
22993+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22994+#else
22995+ .quad 0x0000000000000000 /* 0x20 unused */
22996+#endif
22997+
22998+ .quad 0x0000000000000000 /* 0x28 unused */
22999+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23000+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23001+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23002+ .quad 0x0000000000000000 /* 0x4b reserved */
23003+ .quad 0x0000000000000000 /* 0x53 reserved */
23004+ .quad 0x0000000000000000 /* 0x5b reserved */
23005+
23006+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23007+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23008+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23009+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23010+
23011+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23012+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23013+
23014+ /*
23015+ * Segments used for calling PnP BIOS have byte granularity.
23016+ * The code segments and data segments have fixed 64k limits,
23017+ * the transfer segment sizes are set at run time.
23018+ */
23019+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23020+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23021+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23022+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23023+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23024+
23025+ /*
23026+ * The APM segments have byte granularity and their bases
23027+ * are set at run time. All have 64k limits.
23028+ */
23029+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23030+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23031+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23032+
23033+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23034+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23035+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23036+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23037+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23038+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23039+
23040+ /* Be sure this is zeroed to avoid false validations in Xen */
23041+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23042+ .endr
23043diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23044index e1aabdb..73dcad8 100644
23045--- a/arch/x86/kernel/head_64.S
23046+++ b/arch/x86/kernel/head_64.S
23047@@ -20,6 +20,8 @@
23048 #include <asm/processor-flags.h>
23049 #include <asm/percpu.h>
23050 #include <asm/nops.h>
23051+#include <asm/cpufeature.h>
23052+#include <asm/alternative-asm.h>
23053
23054 #ifdef CONFIG_PARAVIRT
23055 #include <asm/asm-offsets.h>
23056@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23057 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23058 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23059 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23060+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23061+L3_VMALLOC_START = pud_index(VMALLOC_START)
23062+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23063+L3_VMALLOC_END = pud_index(VMALLOC_END)
23064+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23065+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23066
23067 .text
23068 __HEAD
23069@@ -89,11 +97,23 @@ startup_64:
23070 * Fixup the physical addresses in the page table
23071 */
23072 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23073+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23074+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23075+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23076+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23077+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23078
23079- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23080- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23081+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23082+#ifndef CONFIG_XEN
23083+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23084+#endif
23085
23086- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23087+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23088+
23089+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23090+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23091+
23092+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23093
23094 /*
23095 * Set up the identity mapping for the switchover. These
23096@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23097 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23098 1:
23099
23100- /* Enable PAE mode and PGE */
23101- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23102+ /* Enable PAE mode and PSE/PGE */
23103+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23104 movq %rcx, %cr4
23105
23106 /* Setup early boot stage 4 level pagetables. */
23107@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23108 movl $MSR_EFER, %ecx
23109 rdmsr
23110 btsl $_EFER_SCE, %eax /* Enable System Call */
23111- btl $20,%edi /* No Execute supported? */
23112+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23113 jnc 1f
23114 btsl $_EFER_NX, %eax
23115 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23116+ leaq init_level4_pgt(%rip), %rdi
23117+#ifndef CONFIG_EFI
23118+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23119+#endif
23120+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23121+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23122+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23123+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23124 1: wrmsr /* Make changes effective */
23125
23126 /* Setup cr0 */
23127@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23128 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23129 * address given in m16:64.
23130 */
23131+ pax_set_fptr_mask
23132 movq initial_code(%rip),%rax
23133 pushq $0 # fake return address to stop unwinder
23134 pushq $__KERNEL_CS # set correct cs
23135@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23136 call dump_stack
23137 #ifdef CONFIG_KALLSYMS
23138 leaq early_idt_ripmsg(%rip),%rdi
23139- movq 40(%rsp),%rsi # %rip again
23140+ movq 88(%rsp),%rsi # %rip again
23141 call __print_symbol
23142 #endif
23143 #endif /* EARLY_PRINTK */
23144@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23145 early_recursion_flag:
23146 .long 0
23147
23148+ .section .rodata,"a",@progbits
23149 #ifdef CONFIG_EARLY_PRINTK
23150 early_idt_msg:
23151 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23152@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23153 NEXT_PAGE(early_dynamic_pgts)
23154 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23155
23156- .data
23157+ .section .rodata,"a",@progbits
23158
23159-#ifndef CONFIG_XEN
23160 NEXT_PAGE(init_level4_pgt)
23161- .fill 512,8,0
23162-#else
23163-NEXT_PAGE(init_level4_pgt)
23164- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23165 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23166 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23167+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23168+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23169+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23170+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23171+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23172+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23173 .org init_level4_pgt + L4_START_KERNEL*8, 0
23174 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23175 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23176
23177+#ifdef CONFIG_PAX_PER_CPU_PGD
23178+NEXT_PAGE(cpu_pgd)
23179+ .rept 2*NR_CPUS
23180+ .fill 512,8,0
23181+ .endr
23182+#endif
23183+
23184 NEXT_PAGE(level3_ident_pgt)
23185 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23186+#ifdef CONFIG_XEN
23187 .fill 511, 8, 0
23188+#else
23189+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23190+ .fill 510,8,0
23191+#endif
23192+
23193+NEXT_PAGE(level3_vmalloc_start_pgt)
23194+ .fill 512,8,0
23195+
23196+NEXT_PAGE(level3_vmalloc_end_pgt)
23197+ .fill 512,8,0
23198+
23199+NEXT_PAGE(level3_vmemmap_pgt)
23200+ .fill L3_VMEMMAP_START,8,0
23201+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23202+
23203 NEXT_PAGE(level2_ident_pgt)
23204- /* Since I easily can, map the first 1G.
23205+ /* Since I easily can, map the first 2G.
23206 * Don't set NX because code runs from these pages.
23207 */
23208- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23209-#endif
23210+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23211
23212 NEXT_PAGE(level3_kernel_pgt)
23213 .fill L3_START_KERNEL,8,0
23214@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23215 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23216 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23217
23218+NEXT_PAGE(level2_vmemmap_pgt)
23219+ .fill 512,8,0
23220+
23221 NEXT_PAGE(level2_kernel_pgt)
23222 /*
23223 * 512 MB kernel mapping. We spend a full page on this pagetable
23224@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23225 KERNEL_IMAGE_SIZE/PMD_SIZE)
23226
23227 NEXT_PAGE(level2_fixmap_pgt)
23228- .fill 506,8,0
23229- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23230- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23231- .fill 5,8,0
23232+ .fill 507,8,0
23233+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23234+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23235+ .fill 4,8,0
23236
23237-NEXT_PAGE(level1_fixmap_pgt)
23238+NEXT_PAGE(level1_vsyscall_pgt)
23239 .fill 512,8,0
23240
23241 #undef PMDS
23242
23243- .data
23244+ .align PAGE_SIZE
23245+ENTRY(cpu_gdt_table)
23246+ .rept NR_CPUS
23247+ .quad 0x0000000000000000 /* NULL descriptor */
23248+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23249+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23250+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23251+ .quad 0x00cffb000000ffff /* __USER32_CS */
23252+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23253+ .quad 0x00affb000000ffff /* __USER_CS */
23254+
23255+#ifdef CONFIG_PAX_KERNEXEC
23256+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23257+#else
23258+ .quad 0x0 /* unused */
23259+#endif
23260+
23261+ .quad 0,0 /* TSS */
23262+ .quad 0,0 /* LDT */
23263+ .quad 0,0,0 /* three TLS descriptors */
23264+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23265+ /* asm/segment.h:GDT_ENTRIES must match this */
23266+
23267+#ifdef CONFIG_PAX_MEMORY_UDEREF
23268+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23269+#else
23270+ .quad 0x0 /* unused */
23271+#endif
23272+
23273+ /* zero the remaining page */
23274+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23275+ .endr
23276+
23277 .align 16
23278 .globl early_gdt_descr
23279 early_gdt_descr:
23280 .word GDT_ENTRIES*8-1
23281 early_gdt_descr_base:
23282- .quad INIT_PER_CPU_VAR(gdt_page)
23283+ .quad cpu_gdt_table
23284
23285 ENTRY(phys_base)
23286 /* This must match the first entry in level2_kernel_pgt */
23287 .quad 0x0000000000000000
23288
23289 #include "../../x86/xen/xen-head.S"
23290-
23291- __PAGE_ALIGNED_BSS
23292+
23293+ .section .rodata,"a",@progbits
23294 NEXT_PAGE(empty_zero_page)
23295 .skip PAGE_SIZE
23296diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23297index 0fa6912..b37438b 100644
23298--- a/arch/x86/kernel/i386_ksyms_32.c
23299+++ b/arch/x86/kernel/i386_ksyms_32.c
23300@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23301 EXPORT_SYMBOL(cmpxchg8b_emu);
23302 #endif
23303
23304+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23305+
23306 /* Networking helper routines. */
23307 EXPORT_SYMBOL(csum_partial_copy_generic);
23308+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23309+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23310
23311 EXPORT_SYMBOL(__get_user_1);
23312 EXPORT_SYMBOL(__get_user_2);
23313@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23314
23315 EXPORT_SYMBOL(csum_partial);
23316 EXPORT_SYMBOL(empty_zero_page);
23317+
23318+#ifdef CONFIG_PAX_KERNEXEC
23319+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23320+#endif
23321+
23322+#ifdef CONFIG_PAX_PER_CPU_PGD
23323+EXPORT_SYMBOL(cpu_pgd);
23324+#endif
23325diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23326index 5d576ab..1403a03 100644
23327--- a/arch/x86/kernel/i387.c
23328+++ b/arch/x86/kernel/i387.c
23329@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23330 static inline bool interrupted_user_mode(void)
23331 {
23332 struct pt_regs *regs = get_irq_regs();
23333- return regs && user_mode_vm(regs);
23334+ return regs && user_mode(regs);
23335 }
23336
23337 /*
23338diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23339index 9a5c460..84868423 100644
23340--- a/arch/x86/kernel/i8259.c
23341+++ b/arch/x86/kernel/i8259.c
23342@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23343 static void make_8259A_irq(unsigned int irq)
23344 {
23345 disable_irq_nosync(irq);
23346- io_apic_irqs &= ~(1<<irq);
23347+ io_apic_irqs &= ~(1UL<<irq);
23348 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23349 i8259A_chip.name);
23350 enable_irq(irq);
23351@@ -209,7 +209,7 @@ spurious_8259A_irq:
23352 "spurious 8259A interrupt: IRQ%d.\n", irq);
23353 spurious_irq_mask |= irqmask;
23354 }
23355- atomic_inc(&irq_err_count);
23356+ atomic_inc_unchecked(&irq_err_count);
23357 /*
23358 * Theoretically we do not have to handle this IRQ,
23359 * but in Linux this does not cause problems and is
23360@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23361 /* (slave's support for AEOI in flat mode is to be investigated) */
23362 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23363
23364+ pax_open_kernel();
23365 if (auto_eoi)
23366 /*
23367 * In AEOI mode we just have to mask the interrupt
23368 * when acking.
23369 */
23370- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23371+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23372 else
23373- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23374+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23375+ pax_close_kernel();
23376
23377 udelay(100); /* wait for 8259A to initialize */
23378
23379diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23380index a979b5b..1d6db75 100644
23381--- a/arch/x86/kernel/io_delay.c
23382+++ b/arch/x86/kernel/io_delay.c
23383@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23384 * Quirk table for systems that misbehave (lock up, etc.) if port
23385 * 0x80 is used:
23386 */
23387-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23388+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23389 {
23390 .callback = dmi_io_delay_0xed_port,
23391 .ident = "Compaq Presario V6000",
23392diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23393index 4ddaf66..6292f4e 100644
23394--- a/arch/x86/kernel/ioport.c
23395+++ b/arch/x86/kernel/ioport.c
23396@@ -6,6 +6,7 @@
23397 #include <linux/sched.h>
23398 #include <linux/kernel.h>
23399 #include <linux/capability.h>
23400+#include <linux/security.h>
23401 #include <linux/errno.h>
23402 #include <linux/types.h>
23403 #include <linux/ioport.h>
23404@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23405
23406 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23407 return -EINVAL;
23408+#ifdef CONFIG_GRKERNSEC_IO
23409+ if (turn_on && grsec_disable_privio) {
23410+ gr_handle_ioperm();
23411+ return -EPERM;
23412+ }
23413+#endif
23414 if (turn_on && !capable(CAP_SYS_RAWIO))
23415 return -EPERM;
23416
23417@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23418 * because the ->io_bitmap_max value must match the bitmap
23419 * contents:
23420 */
23421- tss = &per_cpu(init_tss, get_cpu());
23422+ tss = init_tss + get_cpu();
23423
23424 if (turn_on)
23425 bitmap_clear(t->io_bitmap_ptr, from, num);
23426@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23427 return -EINVAL;
23428 /* Trying to gain more privileges? */
23429 if (level > old) {
23430+#ifdef CONFIG_GRKERNSEC_IO
23431+ if (grsec_disable_privio) {
23432+ gr_handle_iopl();
23433+ return -EPERM;
23434+ }
23435+#endif
23436 if (!capable(CAP_SYS_RAWIO))
23437 return -EPERM;
23438 }
23439diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23440index 3a8185c..3c042ee 100644
23441--- a/arch/x86/kernel/irq.c
23442+++ b/arch/x86/kernel/irq.c
23443@@ -21,7 +21,7 @@
23444 #define CREATE_TRACE_POINTS
23445 #include <asm/trace/irq_vectors.h>
23446
23447-atomic_t irq_err_count;
23448+atomic_unchecked_t irq_err_count;
23449
23450 /* Function pointer for generic interrupt vector handling */
23451 void (*x86_platform_ipi_callback)(void) = NULL;
23452@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23453 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23454 seq_printf(p, " Machine check polls\n");
23455 #endif
23456- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23457+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23458 #if defined(CONFIG_X86_IO_APIC)
23459- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23460+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23461 #endif
23462 return 0;
23463 }
23464@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23465
23466 u64 arch_irq_stat(void)
23467 {
23468- u64 sum = atomic_read(&irq_err_count);
23469+ u64 sum = atomic_read_unchecked(&irq_err_count);
23470 return sum;
23471 }
23472
23473diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23474index 4186755..784efa0 100644
23475--- a/arch/x86/kernel/irq_32.c
23476+++ b/arch/x86/kernel/irq_32.c
23477@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23478 __asm__ __volatile__("andl %%esp,%0" :
23479 "=r" (sp) : "0" (THREAD_SIZE - 1));
23480
23481- return sp < (sizeof(struct thread_info) + STACK_WARN);
23482+ return sp < STACK_WARN;
23483 }
23484
23485 static void print_stack_overflow(void)
23486@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23487 * per-CPU IRQ handling contexts (thread information and stack)
23488 */
23489 union irq_ctx {
23490- struct thread_info tinfo;
23491- u32 stack[THREAD_SIZE/sizeof(u32)];
23492+ unsigned long previous_esp;
23493+ u32 stack[THREAD_SIZE/sizeof(u32)];
23494 } __attribute__((aligned(THREAD_SIZE)));
23495
23496 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23497@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23498 static inline int
23499 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23500 {
23501- union irq_ctx *curctx, *irqctx;
23502+ union irq_ctx *irqctx;
23503 u32 *isp, arg1, arg2;
23504
23505- curctx = (union irq_ctx *) current_thread_info();
23506 irqctx = __this_cpu_read(hardirq_ctx);
23507
23508 /*
23509@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23510 * handler) we can't do that and just have to keep using the
23511 * current stack (which is the irq stack already after all)
23512 */
23513- if (unlikely(curctx == irqctx))
23514+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23515 return 0;
23516
23517 /* build the stack frame on the IRQ stack */
23518- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23519- irqctx->tinfo.task = curctx->tinfo.task;
23520- irqctx->tinfo.previous_esp = current_stack_pointer;
23521+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23522+ irqctx->previous_esp = current_stack_pointer;
23523
23524- /* Copy the preempt_count so that the [soft]irq checks work. */
23525- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23526+#ifdef CONFIG_PAX_MEMORY_UDEREF
23527+ __set_fs(MAKE_MM_SEG(0));
23528+#endif
23529
23530 if (unlikely(overflow))
23531 call_on_stack(print_stack_overflow, isp);
23532@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23533 : "0" (irq), "1" (desc), "2" (isp),
23534 "D" (desc->handle_irq)
23535 : "memory", "cc", "ecx");
23536+
23537+#ifdef CONFIG_PAX_MEMORY_UDEREF
23538+ __set_fs(current_thread_info()->addr_limit);
23539+#endif
23540+
23541 return 1;
23542 }
23543
23544@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23545 */
23546 void irq_ctx_init(int cpu)
23547 {
23548- union irq_ctx *irqctx;
23549-
23550 if (per_cpu(hardirq_ctx, cpu))
23551 return;
23552
23553- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23554- THREADINFO_GFP,
23555- THREAD_SIZE_ORDER));
23556- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23557- irqctx->tinfo.cpu = cpu;
23558- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23559- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23560+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23561+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23562
23563- per_cpu(hardirq_ctx, cpu) = irqctx;
23564-
23565- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23566- THREADINFO_GFP,
23567- THREAD_SIZE_ORDER));
23568- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23569- irqctx->tinfo.cpu = cpu;
23570- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23571-
23572- per_cpu(softirq_ctx, cpu) = irqctx;
23573+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23574+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23575
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@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23579 asmlinkage void do_softirq(void)
23580 {
23581 unsigned long flags;
23582- struct thread_info *curctx;
23583 union irq_ctx *irqctx;
23584 u32 *isp;
23585
23586@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23587 local_irq_save(flags);
23588
23589 if (local_softirq_pending()) {
23590- curctx = current_thread_info();
23591 irqctx = __this_cpu_read(softirq_ctx);
23592- irqctx->tinfo.task = curctx->task;
23593- irqctx->tinfo.previous_esp = current_stack_pointer;
23594+ irqctx->previous_esp = current_stack_pointer;
23595
23596 /* build the stack frame on the softirq stack */
23597- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23598+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23599+
23600+#ifdef CONFIG_PAX_MEMORY_UDEREF
23601+ __set_fs(MAKE_MM_SEG(0));
23602+#endif
23603
23604 call_on_stack(__do_softirq, isp);
23605+
23606+#ifdef CONFIG_PAX_MEMORY_UDEREF
23607+ __set_fs(current_thread_info()->addr_limit);
23608+#endif
23609+
23610 /*
23611 * Shouldn't happen, we returned above if in_interrupt():
23612 */
23613@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23614 if (unlikely(!desc))
23615 return false;
23616
23617- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23618+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23619 if (unlikely(overflow))
23620 print_stack_overflow();
23621 desc->handle_irq(irq, desc);
23622diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23623index d04d3ec..ea4b374 100644
23624--- a/arch/x86/kernel/irq_64.c
23625+++ b/arch/x86/kernel/irq_64.c
23626@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23627 u64 estack_top, estack_bottom;
23628 u64 curbase = (u64)task_stack_page(current);
23629
23630- if (user_mode_vm(regs))
23631+ if (user_mode(regs))
23632 return;
23633
23634 if (regs->sp >= curbase + sizeof(struct thread_info) +
23635diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23636index dc1404b..bbc43e7 100644
23637--- a/arch/x86/kernel/kdebugfs.c
23638+++ b/arch/x86/kernel/kdebugfs.c
23639@@ -27,7 +27,7 @@ struct setup_data_node {
23640 u32 len;
23641 };
23642
23643-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23644+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23645 size_t count, loff_t *ppos)
23646 {
23647 struct setup_data_node *node = file->private_data;
23648diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23649index 836f832..a8bda67 100644
23650--- a/arch/x86/kernel/kgdb.c
23651+++ b/arch/x86/kernel/kgdb.c
23652@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23653 #ifdef CONFIG_X86_32
23654 switch (regno) {
23655 case GDB_SS:
23656- if (!user_mode_vm(regs))
23657+ if (!user_mode(regs))
23658 *(unsigned long *)mem = __KERNEL_DS;
23659 break;
23660 case GDB_SP:
23661- if (!user_mode_vm(regs))
23662+ if (!user_mode(regs))
23663 *(unsigned long *)mem = kernel_stack_pointer(regs);
23664 break;
23665 case GDB_GS:
23666@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23667 bp->attr.bp_addr = breakinfo[breakno].addr;
23668 bp->attr.bp_len = breakinfo[breakno].len;
23669 bp->attr.bp_type = breakinfo[breakno].type;
23670- info->address = breakinfo[breakno].addr;
23671+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23672+ info->address = ktla_ktva(breakinfo[breakno].addr);
23673+ else
23674+ info->address = breakinfo[breakno].addr;
23675 info->len = breakinfo[breakno].len;
23676 info->type = breakinfo[breakno].type;
23677 val = arch_install_hw_breakpoint(bp);
23678@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23679 case 'k':
23680 /* clear the trace bit */
23681 linux_regs->flags &= ~X86_EFLAGS_TF;
23682- atomic_set(&kgdb_cpu_doing_single_step, -1);
23683+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23684
23685 /* set the trace bit if we're stepping */
23686 if (remcomInBuffer[0] == 's') {
23687 linux_regs->flags |= X86_EFLAGS_TF;
23688- atomic_set(&kgdb_cpu_doing_single_step,
23689+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23690 raw_smp_processor_id());
23691 }
23692
23693@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23694
23695 switch (cmd) {
23696 case DIE_DEBUG:
23697- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23698+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23699 if (user_mode(regs))
23700 return single_step_cont(regs, args);
23701 break;
23702@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23703 #endif /* CONFIG_DEBUG_RODATA */
23704
23705 bpt->type = BP_BREAKPOINT;
23706- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23707+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23708 BREAK_INSTR_SIZE);
23709 if (err)
23710 return err;
23711- err = probe_kernel_write((char *)bpt->bpt_addr,
23712+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23713 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23714 #ifdef CONFIG_DEBUG_RODATA
23715 if (!err)
23716@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23717 return -EBUSY;
23718 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23719 BREAK_INSTR_SIZE);
23720- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23721+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23722 if (err)
23723 return err;
23724 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23725@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23726 if (mutex_is_locked(&text_mutex))
23727 goto knl_write;
23728 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23729- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23730+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23731 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23732 goto knl_write;
23733 return err;
23734 knl_write:
23735 #endif /* CONFIG_DEBUG_RODATA */
23736- return probe_kernel_write((char *)bpt->bpt_addr,
23737+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23738 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23739 }
23740
23741diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23742index 211bce4..6e2580a 100644
23743--- a/arch/x86/kernel/kprobes/core.c
23744+++ b/arch/x86/kernel/kprobes/core.c
23745@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23746 s32 raddr;
23747 } __packed *insn;
23748
23749- insn = (struct __arch_relative_insn *)from;
23750+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23751+
23752+ pax_open_kernel();
23753 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23754 insn->op = op;
23755+ pax_close_kernel();
23756 }
23757
23758 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23759@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23760 kprobe_opcode_t opcode;
23761 kprobe_opcode_t *orig_opcodes = opcodes;
23762
23763- if (search_exception_tables((unsigned long)opcodes))
23764+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23765 return 0; /* Page fault may occur on this address. */
23766
23767 retry:
23768@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23769 * for the first byte, we can recover the original instruction
23770 * from it and kp->opcode.
23771 */
23772- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23773+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23774 buf[0] = kp->opcode;
23775- return (unsigned long)buf;
23776+ return ktva_ktla((unsigned long)buf);
23777 }
23778
23779 /*
23780@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23781 /* Another subsystem puts a breakpoint, failed to recover */
23782 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23783 return 0;
23784+ pax_open_kernel();
23785 memcpy(dest, insn.kaddr, insn.length);
23786+ pax_close_kernel();
23787
23788 #ifdef CONFIG_X86_64
23789 if (insn_rip_relative(&insn)) {
23790@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23791 return 0;
23792 }
23793 disp = (u8 *) dest + insn_offset_displacement(&insn);
23794+ pax_open_kernel();
23795 *(s32 *) disp = (s32) newdisp;
23796+ pax_close_kernel();
23797 }
23798 #endif
23799 return insn.length;
23800@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23801 * nor set current_kprobe, because it doesn't use single
23802 * stepping.
23803 */
23804- regs->ip = (unsigned long)p->ainsn.insn;
23805+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23806 preempt_enable_no_resched();
23807 return;
23808 }
23809@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23810 regs->flags &= ~X86_EFLAGS_IF;
23811 /* single step inline if the instruction is an int3 */
23812 if (p->opcode == BREAKPOINT_INSTRUCTION)
23813- regs->ip = (unsigned long)p->addr;
23814+ regs->ip = ktla_ktva((unsigned long)p->addr);
23815 else
23816- regs->ip = (unsigned long)p->ainsn.insn;
23817+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23818 }
23819
23820 /*
23821@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23822 setup_singlestep(p, regs, kcb, 0);
23823 return 1;
23824 }
23825- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23826+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23827 /*
23828 * The breakpoint instruction was removed right
23829 * after we hit it. Another cpu has removed
23830@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23831 " movq %rax, 152(%rsp)\n"
23832 RESTORE_REGS_STRING
23833 " popfq\n"
23834+#ifdef KERNEXEC_PLUGIN
23835+ " btsq $63,(%rsp)\n"
23836+#endif
23837 #else
23838 " pushf\n"
23839 SAVE_REGS_STRING
23840@@ -779,7 +789,7 @@ static void __kprobes
23841 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23842 {
23843 unsigned long *tos = stack_addr(regs);
23844- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23845+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23846 unsigned long orig_ip = (unsigned long)p->addr;
23847 kprobe_opcode_t *insn = p->ainsn.insn;
23848
23849@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23850 struct die_args *args = data;
23851 int ret = NOTIFY_DONE;
23852
23853- if (args->regs && user_mode_vm(args->regs))
23854+ if (args->regs && user_mode(args->regs))
23855 return ret;
23856
23857 switch (val) {
23858diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23859index 76dc6f0..66bdfc3 100644
23860--- a/arch/x86/kernel/kprobes/opt.c
23861+++ b/arch/x86/kernel/kprobes/opt.c
23862@@ -79,6 +79,7 @@ found:
23863 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23864 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23865 {
23866+ pax_open_kernel();
23867 #ifdef CONFIG_X86_64
23868 *addr++ = 0x48;
23869 *addr++ = 0xbf;
23870@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23871 *addr++ = 0xb8;
23872 #endif
23873 *(unsigned long *)addr = val;
23874+ pax_close_kernel();
23875 }
23876
23877 static void __used __kprobes kprobes_optinsn_template_holder(void)
23878@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23879 * Verify if the address gap is in 2GB range, because this uses
23880 * a relative jump.
23881 */
23882- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23883+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23884 if (abs(rel) > 0x7fffffff)
23885 return -ERANGE;
23886
23887@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23888 op->optinsn.size = ret;
23889
23890 /* Copy arch-dep-instance from template */
23891- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23892+ pax_open_kernel();
23893+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23894+ pax_close_kernel();
23895
23896 /* Set probe information */
23897 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23898
23899 /* Set probe function call */
23900- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23901+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23902
23903 /* Set returning jmp instruction at the tail of out-of-line buffer */
23904- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23905+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23906 (u8 *)op->kp.addr + op->optinsn.size);
23907
23908 flush_icache_range((unsigned long) buf,
23909@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23910 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23911
23912 /* Backup instructions which will be replaced by jump address */
23913- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23914+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23915 RELATIVE_ADDR_SIZE);
23916
23917 insn_buf[0] = RELATIVEJUMP_OPCODE;
23918@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23919 /* This kprobe is really able to run optimized path. */
23920 op = container_of(p, struct optimized_kprobe, kp);
23921 /* Detour through copied instructions */
23922- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23923+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23924 if (!reenter)
23925 reset_current_kprobe();
23926 preempt_enable_no_resched();
23927diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23928index ebc9873..1b9724b 100644
23929--- a/arch/x86/kernel/ldt.c
23930+++ b/arch/x86/kernel/ldt.c
23931@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23932 if (reload) {
23933 #ifdef CONFIG_SMP
23934 preempt_disable();
23935- load_LDT(pc);
23936+ load_LDT_nolock(pc);
23937 if (!cpumask_equal(mm_cpumask(current->mm),
23938 cpumask_of(smp_processor_id())))
23939 smp_call_function(flush_ldt, current->mm, 1);
23940 preempt_enable();
23941 #else
23942- load_LDT(pc);
23943+ load_LDT_nolock(pc);
23944 #endif
23945 }
23946 if (oldsize) {
23947@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23948 return err;
23949
23950 for (i = 0; i < old->size; i++)
23951- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23952+ write_ldt_entry(new->ldt, i, old->ldt + i);
23953 return 0;
23954 }
23955
23956@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23957 retval = copy_ldt(&mm->context, &old_mm->context);
23958 mutex_unlock(&old_mm->context.lock);
23959 }
23960+
23961+ if (tsk == current) {
23962+ mm->context.vdso = 0;
23963+
23964+#ifdef CONFIG_X86_32
23965+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23966+ mm->context.user_cs_base = 0UL;
23967+ mm->context.user_cs_limit = ~0UL;
23968+
23969+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23970+ cpus_clear(mm->context.cpu_user_cs_mask);
23971+#endif
23972+
23973+#endif
23974+#endif
23975+
23976+ }
23977+
23978 return retval;
23979 }
23980
23981@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23982 }
23983 }
23984
23985+#ifdef CONFIG_PAX_SEGMEXEC
23986+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23987+ error = -EINVAL;
23988+ goto out_unlock;
23989+ }
23990+#endif
23991+
23992 fill_ldt(&ldt, &ldt_info);
23993 if (oldmode)
23994 ldt.avl = 0;
23995diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23996index 5b19e4d..6476a76 100644
23997--- a/arch/x86/kernel/machine_kexec_32.c
23998+++ b/arch/x86/kernel/machine_kexec_32.c
23999@@ -26,7 +26,7 @@
24000 #include <asm/cacheflush.h>
24001 #include <asm/debugreg.h>
24002
24003-static void set_idt(void *newidt, __u16 limit)
24004+static void set_idt(struct desc_struct *newidt, __u16 limit)
24005 {
24006 struct desc_ptr curidt;
24007
24008@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24009 }
24010
24011
24012-static void set_gdt(void *newgdt, __u16 limit)
24013+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24014 {
24015 struct desc_ptr curgdt;
24016
24017@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24018 }
24019
24020 control_page = page_address(image->control_code_page);
24021- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24022+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24023
24024 relocate_kernel_ptr = control_page;
24025 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24026diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24027index 15c9876..0a43909 100644
24028--- a/arch/x86/kernel/microcode_core.c
24029+++ b/arch/x86/kernel/microcode_core.c
24030@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24031 return NOTIFY_OK;
24032 }
24033
24034-static struct notifier_block __refdata mc_cpu_notifier = {
24035+static struct notifier_block mc_cpu_notifier = {
24036 .notifier_call = mc_cpu_callback,
24037 };
24038
24039diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24040index 5fb2ceb..3ae90bb 100644
24041--- a/arch/x86/kernel/microcode_intel.c
24042+++ b/arch/x86/kernel/microcode_intel.c
24043@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24044
24045 static int get_ucode_user(void *to, const void *from, size_t n)
24046 {
24047- return copy_from_user(to, from, n);
24048+ return copy_from_user(to, (const void __force_user *)from, n);
24049 }
24050
24051 static enum ucode_state
24052 request_microcode_user(int cpu, const void __user *buf, size_t size)
24053 {
24054- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24055+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24056 }
24057
24058 static void microcode_fini_cpu(int cpu)
24059diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24060index 216a4d7..228255a 100644
24061--- a/arch/x86/kernel/module.c
24062+++ b/arch/x86/kernel/module.c
24063@@ -43,15 +43,60 @@ do { \
24064 } while (0)
24065 #endif
24066
24067-void *module_alloc(unsigned long size)
24068+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24069 {
24070- if (PAGE_ALIGN(size) > MODULES_LEN)
24071+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24072 return NULL;
24073 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24074- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24075+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24076 -1, __builtin_return_address(0));
24077 }
24078
24079+void *module_alloc(unsigned long size)
24080+{
24081+
24082+#ifdef CONFIG_PAX_KERNEXEC
24083+ return __module_alloc(size, PAGE_KERNEL);
24084+#else
24085+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24086+#endif
24087+
24088+}
24089+
24090+#ifdef CONFIG_PAX_KERNEXEC
24091+#ifdef CONFIG_X86_32
24092+void *module_alloc_exec(unsigned long size)
24093+{
24094+ struct vm_struct *area;
24095+
24096+ if (size == 0)
24097+ return NULL;
24098+
24099+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24100+ return area ? area->addr : NULL;
24101+}
24102+EXPORT_SYMBOL(module_alloc_exec);
24103+
24104+void module_free_exec(struct module *mod, void *module_region)
24105+{
24106+ vunmap(module_region);
24107+}
24108+EXPORT_SYMBOL(module_free_exec);
24109+#else
24110+void module_free_exec(struct module *mod, void *module_region)
24111+{
24112+ module_free(mod, module_region);
24113+}
24114+EXPORT_SYMBOL(module_free_exec);
24115+
24116+void *module_alloc_exec(unsigned long size)
24117+{
24118+ return __module_alloc(size, PAGE_KERNEL_RX);
24119+}
24120+EXPORT_SYMBOL(module_alloc_exec);
24121+#endif
24122+#endif
24123+
24124 #ifdef CONFIG_X86_32
24125 int apply_relocate(Elf32_Shdr *sechdrs,
24126 const char *strtab,
24127@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24128 unsigned int i;
24129 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24130 Elf32_Sym *sym;
24131- uint32_t *location;
24132+ uint32_t *plocation, location;
24133
24134 DEBUGP("Applying relocate section %u to %u\n",
24135 relsec, sechdrs[relsec].sh_info);
24136 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24137 /* This is where to make the change */
24138- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24139- + rel[i].r_offset;
24140+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24141+ location = (uint32_t)plocation;
24142+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24143+ plocation = ktla_ktva((void *)plocation);
24144 /* This is the symbol it is referring to. Note that all
24145 undefined symbols have been resolved. */
24146 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24147@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24148 switch (ELF32_R_TYPE(rel[i].r_info)) {
24149 case R_386_32:
24150 /* We add the value into the location given */
24151- *location += sym->st_value;
24152+ pax_open_kernel();
24153+ *plocation += sym->st_value;
24154+ pax_close_kernel();
24155 break;
24156 case R_386_PC32:
24157 /* Add the value, subtract its position */
24158- *location += sym->st_value - (uint32_t)location;
24159+ pax_open_kernel();
24160+ *plocation += sym->st_value - location;
24161+ pax_close_kernel();
24162 break;
24163 default:
24164 pr_err("%s: Unknown relocation: %u\n",
24165@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24166 case R_X86_64_NONE:
24167 break;
24168 case R_X86_64_64:
24169+ pax_open_kernel();
24170 *(u64 *)loc = val;
24171+ pax_close_kernel();
24172 break;
24173 case R_X86_64_32:
24174+ pax_open_kernel();
24175 *(u32 *)loc = val;
24176+ pax_close_kernel();
24177 if (val != *(u32 *)loc)
24178 goto overflow;
24179 break;
24180 case R_X86_64_32S:
24181+ pax_open_kernel();
24182 *(s32 *)loc = val;
24183+ pax_close_kernel();
24184 if ((s64)val != *(s32 *)loc)
24185 goto overflow;
24186 break;
24187 case R_X86_64_PC32:
24188 val -= (u64)loc;
24189+ pax_open_kernel();
24190 *(u32 *)loc = val;
24191+ pax_close_kernel();
24192+
24193 #if 0
24194 if ((s64)val != *(s32 *)loc)
24195 goto overflow;
24196diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24197index 88458fa..349f7a4 100644
24198--- a/arch/x86/kernel/msr.c
24199+++ b/arch/x86/kernel/msr.c
24200@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24201 return notifier_from_errno(err);
24202 }
24203
24204-static struct notifier_block __refdata msr_class_cpu_notifier = {
24205+static struct notifier_block msr_class_cpu_notifier = {
24206 .notifier_call = msr_class_cpu_callback,
24207 };
24208
24209diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24210index ba77ebc..65da999 100644
24211--- a/arch/x86/kernel/nmi.c
24212+++ b/arch/x86/kernel/nmi.c
24213@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24214 return handled;
24215 }
24216
24217-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24218+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24219 {
24220 struct nmi_desc *desc = nmi_to_desc(type);
24221 unsigned long flags;
24222@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24223 * event confuses some handlers (kdump uses this flag)
24224 */
24225 if (action->flags & NMI_FLAG_FIRST)
24226- list_add_rcu(&action->list, &desc->head);
24227+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24228 else
24229- list_add_tail_rcu(&action->list, &desc->head);
24230+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24231
24232 spin_unlock_irqrestore(&desc->lock, flags);
24233 return 0;
24234@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24235 if (!strcmp(n->name, name)) {
24236 WARN(in_nmi(),
24237 "Trying to free NMI (%s) from NMI context!\n", n->name);
24238- list_del_rcu(&n->list);
24239+ pax_list_del_rcu((struct list_head *)&n->list);
24240 break;
24241 }
24242 }
24243@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24244 dotraplinkage notrace __kprobes void
24245 do_nmi(struct pt_regs *regs, long error_code)
24246 {
24247+
24248+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24249+ if (!user_mode(regs)) {
24250+ unsigned long cs = regs->cs & 0xFFFF;
24251+ unsigned long ip = ktva_ktla(regs->ip);
24252+
24253+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24254+ regs->ip = ip;
24255+ }
24256+#endif
24257+
24258 nmi_nesting_preprocess(regs);
24259
24260 nmi_enter();
24261diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24262index 6d9582e..f746287 100644
24263--- a/arch/x86/kernel/nmi_selftest.c
24264+++ b/arch/x86/kernel/nmi_selftest.c
24265@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24266 {
24267 /* trap all the unknown NMIs we may generate */
24268 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24269- __initdata);
24270+ __initconst);
24271 }
24272
24273 static void __init cleanup_nmi_testsuite(void)
24274@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24275 unsigned long timeout;
24276
24277 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24278- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24279+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24280 nmi_fail = FAILURE;
24281 return;
24282 }
24283diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24284index 676b8c7..870ba04 100644
24285--- a/arch/x86/kernel/paravirt-spinlocks.c
24286+++ b/arch/x86/kernel/paravirt-spinlocks.c
24287@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24288 arch_spin_lock(lock);
24289 }
24290
24291-struct pv_lock_ops pv_lock_ops = {
24292+struct pv_lock_ops pv_lock_ops __read_only = {
24293 #ifdef CONFIG_SMP
24294 .spin_is_locked = __ticket_spin_is_locked,
24295 .spin_is_contended = __ticket_spin_is_contended,
24296diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24297index cd6de64..27c6af0 100644
24298--- a/arch/x86/kernel/paravirt.c
24299+++ b/arch/x86/kernel/paravirt.c
24300@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24301 {
24302 return x;
24303 }
24304+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24305+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24306+#endif
24307
24308 void __init default_banner(void)
24309 {
24310@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24311 if (opfunc == NULL)
24312 /* If there's no function, patch it with a ud2a (BUG) */
24313 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24314- else if (opfunc == _paravirt_nop)
24315+ else if (opfunc == (void *)_paravirt_nop)
24316 /* If the operation is a nop, then nop the callsite */
24317 ret = paravirt_patch_nop();
24318
24319 /* identity functions just return their single argument */
24320- else if (opfunc == _paravirt_ident_32)
24321+ else if (opfunc == (void *)_paravirt_ident_32)
24322 ret = paravirt_patch_ident_32(insnbuf, len);
24323- else if (opfunc == _paravirt_ident_64)
24324+ else if (opfunc == (void *)_paravirt_ident_64)
24325 ret = paravirt_patch_ident_64(insnbuf, len);
24326+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24327+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24328+ ret = paravirt_patch_ident_64(insnbuf, len);
24329+#endif
24330
24331 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24332 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24333@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24334 if (insn_len > len || start == NULL)
24335 insn_len = len;
24336 else
24337- memcpy(insnbuf, start, insn_len);
24338+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24339
24340 return insn_len;
24341 }
24342@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24343 return this_cpu_read(paravirt_lazy_mode);
24344 }
24345
24346-struct pv_info pv_info = {
24347+struct pv_info pv_info __read_only = {
24348 .name = "bare hardware",
24349 .paravirt_enabled = 0,
24350 .kernel_rpl = 0,
24351@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24352 #endif
24353 };
24354
24355-struct pv_init_ops pv_init_ops = {
24356+struct pv_init_ops pv_init_ops __read_only = {
24357 .patch = native_patch,
24358 };
24359
24360-struct pv_time_ops pv_time_ops = {
24361+struct pv_time_ops pv_time_ops __read_only = {
24362 .sched_clock = native_sched_clock,
24363 .steal_clock = native_steal_clock,
24364 };
24365
24366-struct pv_irq_ops pv_irq_ops = {
24367+struct pv_irq_ops pv_irq_ops __read_only = {
24368 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24369 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24370 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24371@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24372 #endif
24373 };
24374
24375-struct pv_cpu_ops pv_cpu_ops = {
24376+struct pv_cpu_ops pv_cpu_ops __read_only = {
24377 .cpuid = native_cpuid,
24378 .get_debugreg = native_get_debugreg,
24379 .set_debugreg = native_set_debugreg,
24380@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24381 .end_context_switch = paravirt_nop,
24382 };
24383
24384-struct pv_apic_ops pv_apic_ops = {
24385+struct pv_apic_ops pv_apic_ops __read_only= {
24386 #ifdef CONFIG_X86_LOCAL_APIC
24387 .startup_ipi_hook = paravirt_nop,
24388 #endif
24389 };
24390
24391-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24392+#ifdef CONFIG_X86_32
24393+#ifdef CONFIG_X86_PAE
24394+/* 64-bit pagetable entries */
24395+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24396+#else
24397 /* 32-bit pagetable entries */
24398 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24399+#endif
24400 #else
24401 /* 64-bit pagetable entries */
24402 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24403 #endif
24404
24405-struct pv_mmu_ops pv_mmu_ops = {
24406+struct pv_mmu_ops pv_mmu_ops __read_only = {
24407
24408 .read_cr2 = native_read_cr2,
24409 .write_cr2 = native_write_cr2,
24410@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24411 .make_pud = PTE_IDENT,
24412
24413 .set_pgd = native_set_pgd,
24414+ .set_pgd_batched = native_set_pgd_batched,
24415 #endif
24416 #endif /* PAGETABLE_LEVELS >= 3 */
24417
24418@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24419 },
24420
24421 .set_fixmap = native_set_fixmap,
24422+
24423+#ifdef CONFIG_PAX_KERNEXEC
24424+ .pax_open_kernel = native_pax_open_kernel,
24425+ .pax_close_kernel = native_pax_close_kernel,
24426+#endif
24427+
24428 };
24429
24430 EXPORT_SYMBOL_GPL(pv_time_ops);
24431diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24432index 299d493..2ccb0ee 100644
24433--- a/arch/x86/kernel/pci-calgary_64.c
24434+++ b/arch/x86/kernel/pci-calgary_64.c
24435@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24436 tce_space = be64_to_cpu(readq(target));
24437 tce_space = tce_space & TAR_SW_BITS;
24438
24439- tce_space = tce_space & (~specified_table_size);
24440+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24441 info->tce_space = (u64 *)__va(tce_space);
24442 }
24443 }
24444diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24445index 35ccf75..7a15747 100644
24446--- a/arch/x86/kernel/pci-iommu_table.c
24447+++ b/arch/x86/kernel/pci-iommu_table.c
24448@@ -2,7 +2,7 @@
24449 #include <asm/iommu_table.h>
24450 #include <linux/string.h>
24451 #include <linux/kallsyms.h>
24452-
24453+#include <linux/sched.h>
24454
24455 #define DEBUG 1
24456
24457diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24458index 6c483ba..d10ce2f 100644
24459--- a/arch/x86/kernel/pci-swiotlb.c
24460+++ b/arch/x86/kernel/pci-swiotlb.c
24461@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24462 void *vaddr, dma_addr_t dma_addr,
24463 struct dma_attrs *attrs)
24464 {
24465- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24466+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24467 }
24468
24469 static struct dma_map_ops swiotlb_dma_ops = {
24470diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24471index 83369e5..52b93f0 100644
24472--- a/arch/x86/kernel/process.c
24473+++ b/arch/x86/kernel/process.c
24474@@ -36,7 +36,8 @@
24475 * section. Since TSS's are completely CPU-local, we want them
24476 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24477 */
24478-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24479+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24480+EXPORT_SYMBOL(init_tss);
24481
24482 #ifdef CONFIG_X86_64
24483 static DEFINE_PER_CPU(unsigned char, is_idle);
24484@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24485 task_xstate_cachep =
24486 kmem_cache_create("task_xstate", xstate_size,
24487 __alignof__(union thread_xstate),
24488- SLAB_PANIC | SLAB_NOTRACK, NULL);
24489+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24490 }
24491
24492 /*
24493@@ -105,7 +106,7 @@ void exit_thread(void)
24494 unsigned long *bp = t->io_bitmap_ptr;
24495
24496 if (bp) {
24497- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24498+ struct tss_struct *tss = init_tss + get_cpu();
24499
24500 t->io_bitmap_ptr = NULL;
24501 clear_thread_flag(TIF_IO_BITMAP);
24502@@ -125,6 +126,9 @@ void flush_thread(void)
24503 {
24504 struct task_struct *tsk = current;
24505
24506+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24507+ loadsegment(gs, 0);
24508+#endif
24509 flush_ptrace_hw_breakpoint(tsk);
24510 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24511 drop_init_fpu(tsk);
24512@@ -271,7 +275,7 @@ static void __exit_idle(void)
24513 void exit_idle(void)
24514 {
24515 /* idle loop has pid 0 */
24516- if (current->pid)
24517+ if (task_pid_nr(current))
24518 return;
24519 __exit_idle();
24520 }
24521@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24522 return ret;
24523 }
24524 #endif
24525-void stop_this_cpu(void *dummy)
24526+__noreturn void stop_this_cpu(void *dummy)
24527 {
24528 local_irq_disable();
24529 /*
24530@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24531 }
24532 early_param("idle", idle_setup);
24533
24534-unsigned long arch_align_stack(unsigned long sp)
24535+#ifdef CONFIG_PAX_RANDKSTACK
24536+void pax_randomize_kstack(struct pt_regs *regs)
24537 {
24538- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24539- sp -= get_random_int() % 8192;
24540- return sp & ~0xf;
24541-}
24542+ struct thread_struct *thread = &current->thread;
24543+ unsigned long time;
24544
24545-unsigned long arch_randomize_brk(struct mm_struct *mm)
24546-{
24547- unsigned long range_end = mm->brk + 0x02000000;
24548- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24549-}
24550+ if (!randomize_va_space)
24551+ return;
24552+
24553+ if (v8086_mode(regs))
24554+ return;
24555
24556+ rdtscl(time);
24557+
24558+ /* P4 seems to return a 0 LSB, ignore it */
24559+#ifdef CONFIG_MPENTIUM4
24560+ time &= 0x3EUL;
24561+ time <<= 2;
24562+#elif defined(CONFIG_X86_64)
24563+ time &= 0xFUL;
24564+ time <<= 4;
24565+#else
24566+ time &= 0x1FUL;
24567+ time <<= 3;
24568+#endif
24569+
24570+ thread->sp0 ^= time;
24571+ load_sp0(init_tss + smp_processor_id(), thread);
24572+
24573+#ifdef CONFIG_X86_64
24574+ this_cpu_write(kernel_stack, thread->sp0);
24575+#endif
24576+}
24577+#endif
24578diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24579index f8adefc..4bce3d6 100644
24580--- a/arch/x86/kernel/process_32.c
24581+++ b/arch/x86/kernel/process_32.c
24582@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24583 unsigned long thread_saved_pc(struct task_struct *tsk)
24584 {
24585 return ((unsigned long *)tsk->thread.sp)[3];
24586+//XXX return tsk->thread.eip;
24587 }
24588
24589 void __show_regs(struct pt_regs *regs, int all)
24590@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24591 unsigned long sp;
24592 unsigned short ss, gs;
24593
24594- if (user_mode_vm(regs)) {
24595+ if (user_mode(regs)) {
24596 sp = regs->sp;
24597 ss = regs->ss & 0xffff;
24598- gs = get_user_gs(regs);
24599 } else {
24600 sp = kernel_stack_pointer(regs);
24601 savesegment(ss, ss);
24602- savesegment(gs, gs);
24603 }
24604+ gs = get_user_gs(regs);
24605
24606 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24607 (u16)regs->cs, regs->ip, regs->flags,
24608- smp_processor_id());
24609+ raw_smp_processor_id());
24610 print_symbol("EIP is at %s\n", regs->ip);
24611
24612 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24613@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24614 int copy_thread(unsigned long clone_flags, unsigned long sp,
24615 unsigned long arg, struct task_struct *p)
24616 {
24617- struct pt_regs *childregs = task_pt_regs(p);
24618+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24619 struct task_struct *tsk;
24620 int err;
24621
24622 p->thread.sp = (unsigned long) childregs;
24623 p->thread.sp0 = (unsigned long) (childregs+1);
24624+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24625
24626 if (unlikely(p->flags & PF_KTHREAD)) {
24627 /* kernel thread */
24628 memset(childregs, 0, sizeof(struct pt_regs));
24629 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24630- task_user_gs(p) = __KERNEL_STACK_CANARY;
24631- childregs->ds = __USER_DS;
24632- childregs->es = __USER_DS;
24633+ savesegment(gs, childregs->gs);
24634+ childregs->ds = __KERNEL_DS;
24635+ childregs->es = __KERNEL_DS;
24636 childregs->fs = __KERNEL_PERCPU;
24637 childregs->bx = sp; /* function */
24638 childregs->bp = arg;
24639@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24640 struct thread_struct *prev = &prev_p->thread,
24641 *next = &next_p->thread;
24642 int cpu = smp_processor_id();
24643- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24644+ struct tss_struct *tss = init_tss + cpu;
24645 fpu_switch_t fpu;
24646
24647 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24648@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24649 */
24650 lazy_save_gs(prev->gs);
24651
24652+#ifdef CONFIG_PAX_MEMORY_UDEREF
24653+ __set_fs(task_thread_info(next_p)->addr_limit);
24654+#endif
24655+
24656 /*
24657 * Load the per-thread Thread-Local Storage descriptor.
24658 */
24659@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24660 */
24661 arch_end_context_switch(next_p);
24662
24663+ this_cpu_write(current_task, next_p);
24664+ this_cpu_write(current_tinfo, &next_p->tinfo);
24665+
24666 /*
24667 * Restore %gs if needed (which is common)
24668 */
24669@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24670
24671 switch_fpu_finish(next_p, fpu);
24672
24673- this_cpu_write(current_task, next_p);
24674-
24675 return prev_p;
24676 }
24677
24678@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24679 } while (count++ < 16);
24680 return 0;
24681 }
24682-
24683diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24684index 05646ba..0c2906d 100644
24685--- a/arch/x86/kernel/process_64.c
24686+++ b/arch/x86/kernel/process_64.c
24687@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24688 struct pt_regs *childregs;
24689 struct task_struct *me = current;
24690
24691- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24692+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24693 childregs = task_pt_regs(p);
24694 p->thread.sp = (unsigned long) childregs;
24695 p->thread.usersp = me->thread.usersp;
24696+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24697 set_tsk_thread_flag(p, TIF_FORK);
24698 p->fpu_counter = 0;
24699 p->thread.io_bitmap_ptr = NULL;
24700@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24701 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24702 savesegment(es, p->thread.es);
24703 savesegment(ds, p->thread.ds);
24704+ savesegment(ss, p->thread.ss);
24705+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24706 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24707
24708 if (unlikely(p->flags & PF_KTHREAD)) {
24709@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24710 struct thread_struct *prev = &prev_p->thread;
24711 struct thread_struct *next = &next_p->thread;
24712 int cpu = smp_processor_id();
24713- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24714+ struct tss_struct *tss = init_tss + cpu;
24715 unsigned fsindex, gsindex;
24716 fpu_switch_t fpu;
24717
24718@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24719 if (unlikely(next->ds | prev->ds))
24720 loadsegment(ds, next->ds);
24721
24722+ savesegment(ss, prev->ss);
24723+ if (unlikely(next->ss != prev->ss))
24724+ loadsegment(ss, next->ss);
24725
24726 /* We must save %fs and %gs before load_TLS() because
24727 * %fs and %gs may be cleared by load_TLS().
24728@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24729 prev->usersp = this_cpu_read(old_rsp);
24730 this_cpu_write(old_rsp, next->usersp);
24731 this_cpu_write(current_task, next_p);
24732+ this_cpu_write(current_tinfo, &next_p->tinfo);
24733
24734- this_cpu_write(kernel_stack,
24735- (unsigned long)task_stack_page(next_p) +
24736- THREAD_SIZE - KERNEL_STACK_OFFSET);
24737+ this_cpu_write(kernel_stack, next->sp0);
24738
24739 /*
24740 * Now maybe reload the debug registers and handle I/O bitmaps
24741@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24742 if (!p || p == current || p->state == TASK_RUNNING)
24743 return 0;
24744 stack = (unsigned long)task_stack_page(p);
24745- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24746+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24747 return 0;
24748 fp = *(u64 *)(p->thread.sp);
24749 do {
24750- if (fp < (unsigned long)stack ||
24751- fp >= (unsigned long)stack+THREAD_SIZE)
24752+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24753 return 0;
24754 ip = *(u64 *)(fp+8);
24755 if (!in_sched_functions(ip))
24756diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24757index 7461f50..1334029 100644
24758--- a/arch/x86/kernel/ptrace.c
24759+++ b/arch/x86/kernel/ptrace.c
24760@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24761 {
24762 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24763 unsigned long sp = (unsigned long)&regs->sp;
24764- struct thread_info *tinfo;
24765
24766- if (context == (sp & ~(THREAD_SIZE - 1)))
24767+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24768 return sp;
24769
24770- tinfo = (struct thread_info *)context;
24771- if (tinfo->previous_esp)
24772- return tinfo->previous_esp;
24773+ sp = *(unsigned long *)context;
24774+ if (sp)
24775+ return sp;
24776
24777 return (unsigned long)regs;
24778 }
24779@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24780 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24781 {
24782 int i;
24783- int dr7 = 0;
24784+ unsigned long dr7 = 0;
24785 struct arch_hw_breakpoint *info;
24786
24787 for (i = 0; i < HBP_NUM; i++) {
24788@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24789 unsigned long addr, unsigned long data)
24790 {
24791 int ret;
24792- unsigned long __user *datap = (unsigned long __user *)data;
24793+ unsigned long __user *datap = (__force unsigned long __user *)data;
24794
24795 switch (request) {
24796 /* read the word at location addr in the USER area. */
24797@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24798 if ((int) addr < 0)
24799 return -EIO;
24800 ret = do_get_thread_area(child, addr,
24801- (struct user_desc __user *)data);
24802+ (__force struct user_desc __user *) data);
24803 break;
24804
24805 case PTRACE_SET_THREAD_AREA:
24806 if ((int) addr < 0)
24807 return -EIO;
24808 ret = do_set_thread_area(child, addr,
24809- (struct user_desc __user *)data, 0);
24810+ (__force struct user_desc __user *) data, 0);
24811 break;
24812 #endif
24813
24814@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24815
24816 #ifdef CONFIG_X86_64
24817
24818-static struct user_regset x86_64_regsets[] __read_mostly = {
24819+static user_regset_no_const x86_64_regsets[] __read_only = {
24820 [REGSET_GENERAL] = {
24821 .core_note_type = NT_PRSTATUS,
24822 .n = sizeof(struct user_regs_struct) / sizeof(long),
24823@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24824 #endif /* CONFIG_X86_64 */
24825
24826 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24827-static struct user_regset x86_32_regsets[] __read_mostly = {
24828+static user_regset_no_const x86_32_regsets[] __read_only = {
24829 [REGSET_GENERAL] = {
24830 .core_note_type = NT_PRSTATUS,
24831 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24832@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24833 */
24834 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24835
24836-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24837+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24838 {
24839 #ifdef CONFIG_X86_64
24840 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24841@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24842 memset(info, 0, sizeof(*info));
24843 info->si_signo = SIGTRAP;
24844 info->si_code = si_code;
24845- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24846+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24847 }
24848
24849 void user_single_step_siginfo(struct task_struct *tsk,
24850@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24851 # define IS_IA32 0
24852 #endif
24853
24854+#ifdef CONFIG_GRKERNSEC_SETXID
24855+extern void gr_delayed_cred_worker(void);
24856+#endif
24857+
24858 /*
24859 * We must return the syscall number to actually look up in the table.
24860 * This can be -1L to skip running any syscall at all.
24861@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24862
24863 user_exit();
24864
24865+#ifdef CONFIG_GRKERNSEC_SETXID
24866+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24867+ gr_delayed_cred_worker();
24868+#endif
24869+
24870 /*
24871 * If we stepped into a sysenter/syscall insn, it trapped in
24872 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24873@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24874 */
24875 user_exit();
24876
24877+#ifdef CONFIG_GRKERNSEC_SETXID
24878+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24879+ gr_delayed_cred_worker();
24880+#endif
24881+
24882 audit_syscall_exit(regs);
24883
24884 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24885diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24886index 2cb9470..ff1fd80 100644
24887--- a/arch/x86/kernel/pvclock.c
24888+++ b/arch/x86/kernel/pvclock.c
24889@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24890 return pv_tsc_khz;
24891 }
24892
24893-static atomic64_t last_value = ATOMIC64_INIT(0);
24894+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24895
24896 void pvclock_resume(void)
24897 {
24898- atomic64_set(&last_value, 0);
24899+ atomic64_set_unchecked(&last_value, 0);
24900 }
24901
24902 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24903@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24904 * updating at the same time, and one of them could be slightly behind,
24905 * making the assumption that last_value always go forward fail to hold.
24906 */
24907- last = atomic64_read(&last_value);
24908+ last = atomic64_read_unchecked(&last_value);
24909 do {
24910 if (ret < last)
24911 return last;
24912- last = atomic64_cmpxchg(&last_value, last, ret);
24913+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24914 } while (unlikely(last != ret));
24915
24916 return ret;
24917diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24918index 5f4ad27..9d96c99 100644
24919--- a/arch/x86/kernel/reboot.c
24920+++ b/arch/x86/kernel/reboot.c
24921@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24922
24923 void __noreturn machine_real_restart(unsigned int type)
24924 {
24925+
24926+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24927+ struct desc_struct *gdt;
24928+#endif
24929+
24930 local_irq_disable();
24931
24932 /*
24933@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24934
24935 /* Jump to the identity-mapped low memory code */
24936 #ifdef CONFIG_X86_32
24937- asm volatile("jmpl *%0" : :
24938+
24939+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24940+ gdt = get_cpu_gdt_table(smp_processor_id());
24941+ pax_open_kernel();
24942+#ifdef CONFIG_PAX_MEMORY_UDEREF
24943+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24944+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24945+ loadsegment(ds, __KERNEL_DS);
24946+ loadsegment(es, __KERNEL_DS);
24947+ loadsegment(ss, __KERNEL_DS);
24948+#endif
24949+#ifdef CONFIG_PAX_KERNEXEC
24950+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24951+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24952+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24953+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24954+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24955+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24956+#endif
24957+ pax_close_kernel();
24958+#endif
24959+
24960+ asm volatile("ljmpl *%0" : :
24961 "rm" (real_mode_header->machine_real_restart_asm),
24962 "a" (type));
24963 #else
24964@@ -458,7 +485,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24965 * try to force a triple fault and then cycle between hitting the keyboard
24966 * controller and doing that
24967 */
24968-static void native_machine_emergency_restart(void)
24969+static void __noreturn native_machine_emergency_restart(void)
24970 {
24971 int i;
24972 int attempt = 0;
24973@@ -567,13 +594,13 @@ void native_machine_shutdown(void)
24974 #endif
24975 }
24976
24977-static void __machine_emergency_restart(int emergency)
24978+static void __noreturn __machine_emergency_restart(int emergency)
24979 {
24980 reboot_emergency = emergency;
24981 machine_ops.emergency_restart();
24982 }
24983
24984-static void native_machine_restart(char *__unused)
24985+static void __noreturn native_machine_restart(char *__unused)
24986 {
24987 pr_notice("machine restart\n");
24988
24989@@ -582,7 +609,7 @@ static void native_machine_restart(char *__unused)
24990 __machine_emergency_restart(0);
24991 }
24992
24993-static void native_machine_halt(void)
24994+static void __noreturn native_machine_halt(void)
24995 {
24996 /* Stop other cpus and apics */
24997 machine_shutdown();
24998@@ -592,7 +619,7 @@ static void native_machine_halt(void)
24999 stop_this_cpu(NULL);
25000 }
25001
25002-static void native_machine_power_off(void)
25003+static void __noreturn native_machine_power_off(void)
25004 {
25005 if (pm_power_off) {
25006 if (!reboot_force)
25007@@ -601,9 +628,10 @@ static void native_machine_power_off(void)
25008 }
25009 /* A fallback in case there is no PM info available */
25010 tboot_shutdown(TB_SHUTDOWN_HALT);
25011+ unreachable();
25012 }
25013
25014-struct machine_ops machine_ops = {
25015+struct machine_ops machine_ops __read_only = {
25016 .power_off = native_machine_power_off,
25017 .shutdown = native_machine_shutdown,
25018 .emergency_restart = native_machine_emergency_restart,
25019diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25020index c8e41e9..64049ef 100644
25021--- a/arch/x86/kernel/reboot_fixups_32.c
25022+++ b/arch/x86/kernel/reboot_fixups_32.c
25023@@ -57,7 +57,7 @@ struct device_fixup {
25024 unsigned int vendor;
25025 unsigned int device;
25026 void (*reboot_fixup)(struct pci_dev *);
25027-};
25028+} __do_const;
25029
25030 /*
25031 * PCI ids solely used for fixups_table go here
25032diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25033index 3fd2c69..16ef367 100644
25034--- a/arch/x86/kernel/relocate_kernel_64.S
25035+++ b/arch/x86/kernel/relocate_kernel_64.S
25036@@ -11,6 +11,7 @@
25037 #include <asm/kexec.h>
25038 #include <asm/processor-flags.h>
25039 #include <asm/pgtable_types.h>
25040+#include <asm/alternative-asm.h>
25041
25042 /*
25043 * Must be relocatable PIC code callable as a C function
25044@@ -96,8 +97,7 @@ relocate_kernel:
25045
25046 /* jump to identity mapped page */
25047 addq $(identity_mapped - relocate_kernel), %r8
25048- pushq %r8
25049- ret
25050+ jmp *%r8
25051
25052 identity_mapped:
25053 /* set return address to 0 if not preserving context */
25054@@ -167,6 +167,7 @@ identity_mapped:
25055 xorl %r14d, %r14d
25056 xorl %r15d, %r15d
25057
25058+ pax_force_retaddr 0, 1
25059 ret
25060
25061 1:
25062diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25063index 234e1e3..1246d05 100644
25064--- a/arch/x86/kernel/setup.c
25065+++ b/arch/x86/kernel/setup.c
25066@@ -110,6 +110,7 @@
25067 #include <asm/mce.h>
25068 #include <asm/alternative.h>
25069 #include <asm/prom.h>
25070+#include <asm/boot.h>
25071
25072 /*
25073 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25074@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25075 #endif
25076
25077
25078-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25079-unsigned long mmu_cr4_features;
25080+#ifdef CONFIG_X86_64
25081+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25082+#elif defined(CONFIG_X86_PAE)
25083+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25084 #else
25085-unsigned long mmu_cr4_features = X86_CR4_PAE;
25086+unsigned long mmu_cr4_features __read_only;
25087 #endif
25088
25089+void set_in_cr4(unsigned long mask)
25090+{
25091+ unsigned long cr4 = read_cr4();
25092+
25093+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25094+ return;
25095+
25096+ pax_open_kernel();
25097+ mmu_cr4_features |= mask;
25098+ pax_close_kernel();
25099+
25100+ if (trampoline_cr4_features)
25101+ *trampoline_cr4_features = mmu_cr4_features;
25102+ cr4 |= mask;
25103+ write_cr4(cr4);
25104+}
25105+EXPORT_SYMBOL(set_in_cr4);
25106+
25107+void clear_in_cr4(unsigned long mask)
25108+{
25109+ unsigned long cr4 = read_cr4();
25110+
25111+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25112+ return;
25113+
25114+ pax_open_kernel();
25115+ mmu_cr4_features &= ~mask;
25116+ pax_close_kernel();
25117+
25118+ if (trampoline_cr4_features)
25119+ *trampoline_cr4_features = mmu_cr4_features;
25120+ cr4 &= ~mask;
25121+ write_cr4(cr4);
25122+}
25123+EXPORT_SYMBOL(clear_in_cr4);
25124+
25125 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25126 int bootloader_type, bootloader_version;
25127
25128@@ -442,7 +481,7 @@ static void __init parse_setup_data(void)
25129
25130 switch (data_type) {
25131 case SETUP_E820_EXT:
25132- parse_e820_ext(pa_data, data_len);
25133+ parse_e820_ext((struct setup_data __force_kernel *)pa_data, data_len);
25134 break;
25135 case SETUP_DTB:
25136 add_dtb(pa_data);
25137@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25138 * area (640->1Mb) as ram even though it is not.
25139 * take them out.
25140 */
25141- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25142+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25143
25144 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25145 }
25146@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25147 /* called before trim_bios_range() to spare extra sanitize */
25148 static void __init e820_add_kernel_range(void)
25149 {
25150- u64 start = __pa_symbol(_text);
25151+ u64 start = __pa_symbol(ktla_ktva(_text));
25152 u64 size = __pa_symbol(_end) - start;
25153
25154 /*
25155@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25156
25157 void __init setup_arch(char **cmdline_p)
25158 {
25159+#ifdef CONFIG_X86_32
25160+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25161+#else
25162 memblock_reserve(__pa_symbol(_text),
25163 (unsigned long)__bss_stop - (unsigned long)_text);
25164+#endif
25165
25166 early_reserve_initrd();
25167
25168@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25169
25170 if (!boot_params.hdr.root_flags)
25171 root_mountflags &= ~MS_RDONLY;
25172- init_mm.start_code = (unsigned long) _text;
25173- init_mm.end_code = (unsigned long) _etext;
25174+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25175+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25176 init_mm.end_data = (unsigned long) _edata;
25177 init_mm.brk = _brk_end;
25178
25179- code_resource.start = __pa_symbol(_text);
25180- code_resource.end = __pa_symbol(_etext)-1;
25181- data_resource.start = __pa_symbol(_etext);
25182+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25183+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25184+ data_resource.start = __pa_symbol(_sdata);
25185 data_resource.end = __pa_symbol(_edata)-1;
25186 bss_resource.start = __pa_symbol(__bss_start);
25187 bss_resource.end = __pa_symbol(__bss_stop)-1;
25188diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25189index 5cdff03..80fa283 100644
25190--- a/arch/x86/kernel/setup_percpu.c
25191+++ b/arch/x86/kernel/setup_percpu.c
25192@@ -21,19 +21,17 @@
25193 #include <asm/cpu.h>
25194 #include <asm/stackprotector.h>
25195
25196-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25197+#ifdef CONFIG_SMP
25198+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25199 EXPORT_PER_CPU_SYMBOL(cpu_number);
25200+#endif
25201
25202-#ifdef CONFIG_X86_64
25203 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25204-#else
25205-#define BOOT_PERCPU_OFFSET 0
25206-#endif
25207
25208 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25209 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25210
25211-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25212+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25213 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25214 };
25215 EXPORT_SYMBOL(__per_cpu_offset);
25216@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25217 {
25218 #ifdef CONFIG_NEED_MULTIPLE_NODES
25219 pg_data_t *last = NULL;
25220- unsigned int cpu;
25221+ int cpu;
25222
25223 for_each_possible_cpu(cpu) {
25224 int node = early_cpu_to_node(cpu);
25225@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25226 {
25227 #ifdef CONFIG_X86_32
25228 struct desc_struct gdt;
25229+ unsigned long base = per_cpu_offset(cpu);
25230
25231- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25232- 0x2 | DESCTYPE_S, 0x8);
25233- gdt.s = 1;
25234+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25235+ 0x83 | DESCTYPE_S, 0xC);
25236 write_gdt_entry(get_cpu_gdt_table(cpu),
25237 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25238 #endif
25239@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25240 /* alrighty, percpu areas up and running */
25241 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25242 for_each_possible_cpu(cpu) {
25243+#ifdef CONFIG_CC_STACKPROTECTOR
25244+#ifdef CONFIG_X86_32
25245+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25246+#endif
25247+#endif
25248 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25249 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25250 per_cpu(cpu_number, cpu) = cpu;
25251@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25252 */
25253 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25254 #endif
25255+#ifdef CONFIG_CC_STACKPROTECTOR
25256+#ifdef CONFIG_X86_32
25257+ if (!cpu)
25258+ per_cpu(stack_canary.canary, cpu) = canary;
25259+#endif
25260+#endif
25261 /*
25262 * Up to this point, the boot CPU has been using .init.data
25263 * area. Reload any changed state for the boot CPU.
25264diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25265index d859eea..44e17c4 100644
25266--- a/arch/x86/kernel/signal.c
25267+++ b/arch/x86/kernel/signal.c
25268@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25269 * Align the stack pointer according to the i386 ABI,
25270 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25271 */
25272- sp = ((sp + 4) & -16ul) - 4;
25273+ sp = ((sp - 12) & -16ul) - 4;
25274 #else /* !CONFIG_X86_32 */
25275 sp = round_down(sp, 16) - 8;
25276 #endif
25277@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25278 }
25279
25280 if (current->mm->context.vdso)
25281- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25282+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25283 else
25284- restorer = &frame->retcode;
25285+ restorer = (void __user *)&frame->retcode;
25286 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25287 restorer = ksig->ka.sa.sa_restorer;
25288
25289@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25290 * reasons and because gdb uses it as a signature to notice
25291 * signal handler stack frames.
25292 */
25293- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25294+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25295
25296 if (err)
25297 return -EFAULT;
25298@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25299 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25300
25301 /* Set up to return from userspace. */
25302- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25303+ if (current->mm->context.vdso)
25304+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25305+ else
25306+ restorer = (void __user *)&frame->retcode;
25307 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25308 restorer = ksig->ka.sa.sa_restorer;
25309 put_user_ex(restorer, &frame->pretcode);
25310@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25311 * reasons and because gdb uses it as a signature to notice
25312 * signal handler stack frames.
25313 */
25314- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25315+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25316 } put_user_catch(err);
25317
25318 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25319@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25320 {
25321 int usig = signr_convert(ksig->sig);
25322 sigset_t *set = sigmask_to_save();
25323- compat_sigset_t *cset = (compat_sigset_t *) set;
25324+ sigset_t sigcopy;
25325+ compat_sigset_t *cset;
25326+
25327+ sigcopy = *set;
25328+
25329+ cset = (compat_sigset_t *) &sigcopy;
25330
25331 /* Set up the stack frame */
25332 if (is_ia32_frame()) {
25333@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25334 } else if (is_x32_frame()) {
25335 return x32_setup_rt_frame(ksig, cset, regs);
25336 } else {
25337- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25338+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25339 }
25340 }
25341
25342diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25343index cdaa347..f5af55d 100644
25344--- a/arch/x86/kernel/smp.c
25345+++ b/arch/x86/kernel/smp.c
25346@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25347
25348 __setup("nonmi_ipi", nonmi_ipi_setup);
25349
25350-struct smp_ops smp_ops = {
25351+struct smp_ops smp_ops __read_only = {
25352 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25353 .smp_prepare_cpus = native_smp_prepare_cpus,
25354 .smp_cpus_done = native_smp_cpus_done,
25355diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25356index aecc98a..0244a53 100644
25357--- a/arch/x86/kernel/smpboot.c
25358+++ b/arch/x86/kernel/smpboot.c
25359@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25360
25361 enable_start_cpu0 = 0;
25362
25363-#ifdef CONFIG_X86_32
25364- /* switch away from the initial page table */
25365- load_cr3(swapper_pg_dir);
25366- __flush_tlb_all();
25367-#endif
25368-
25369 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25370 barrier();
25371+
25372+ /* switch away from the initial page table */
25373+#ifdef CONFIG_PAX_PER_CPU_PGD
25374+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25375+ __flush_tlb_all();
25376+#elif defined(CONFIG_X86_32)
25377+ load_cr3(swapper_pg_dir);
25378+ __flush_tlb_all();
25379+#endif
25380+
25381 /*
25382 * Check TSC synchronization with the BP:
25383 */
25384@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25385 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25386 (THREAD_SIZE + task_stack_page(idle))) - 1);
25387 per_cpu(current_task, cpu) = idle;
25388+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25389
25390 #ifdef CONFIG_X86_32
25391 /* Stack for startup_32 can be just as for start_secondary onwards */
25392@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25393 #else
25394 clear_tsk_thread_flag(idle, TIF_FORK);
25395 initial_gs = per_cpu_offset(cpu);
25396- per_cpu(kernel_stack, cpu) =
25397- (unsigned long)task_stack_page(idle) -
25398- KERNEL_STACK_OFFSET + THREAD_SIZE;
25399+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25400 #endif
25401+
25402+ pax_open_kernel();
25403 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25404+ pax_close_kernel();
25405+
25406 initial_code = (unsigned long)start_secondary;
25407 stack_start = idle->thread.sp;
25408
25409@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25410 /* the FPU context is blank, nobody can own it */
25411 __cpu_disable_lazy_restore(cpu);
25412
25413+#ifdef CONFIG_PAX_PER_CPU_PGD
25414+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25415+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25416+ KERNEL_PGD_PTRS);
25417+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25418+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25419+ KERNEL_PGD_PTRS);
25420+#endif
25421+
25422 err = do_boot_cpu(apicid, cpu, tidle);
25423 if (err) {
25424 pr_debug("do_boot_cpu failed %d\n", err);
25425diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25426index 9b4d51d..5d28b58 100644
25427--- a/arch/x86/kernel/step.c
25428+++ b/arch/x86/kernel/step.c
25429@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25430 struct desc_struct *desc;
25431 unsigned long base;
25432
25433- seg &= ~7UL;
25434+ seg >>= 3;
25435
25436 mutex_lock(&child->mm->context.lock);
25437- if (unlikely((seg >> 3) >= child->mm->context.size))
25438+ if (unlikely(seg >= child->mm->context.size))
25439 addr = -1L; /* bogus selector, access would fault */
25440 else {
25441 desc = child->mm->context.ldt + seg;
25442@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25443 addr += base;
25444 }
25445 mutex_unlock(&child->mm->context.lock);
25446- }
25447+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25448+ addr = ktla_ktva(addr);
25449
25450 return addr;
25451 }
25452@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25453 unsigned char opcode[15];
25454 unsigned long addr = convert_ip_to_linear(child, regs);
25455
25456+ if (addr == -EINVAL)
25457+ return 0;
25458+
25459 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25460 for (i = 0; i < copied; i++) {
25461 switch (opcode[i]) {
25462diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25463new file mode 100644
25464index 0000000..5877189
25465--- /dev/null
25466+++ b/arch/x86/kernel/sys_i386_32.c
25467@@ -0,0 +1,189 @@
25468+/*
25469+ * This file contains various random system calls that
25470+ * have a non-standard calling sequence on the Linux/i386
25471+ * platform.
25472+ */
25473+
25474+#include <linux/errno.h>
25475+#include <linux/sched.h>
25476+#include <linux/mm.h>
25477+#include <linux/fs.h>
25478+#include <linux/smp.h>
25479+#include <linux/sem.h>
25480+#include <linux/msg.h>
25481+#include <linux/shm.h>
25482+#include <linux/stat.h>
25483+#include <linux/syscalls.h>
25484+#include <linux/mman.h>
25485+#include <linux/file.h>
25486+#include <linux/utsname.h>
25487+#include <linux/ipc.h>
25488+#include <linux/elf.h>
25489+
25490+#include <linux/uaccess.h>
25491+#include <linux/unistd.h>
25492+
25493+#include <asm/syscalls.h>
25494+
25495+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25496+{
25497+ unsigned long pax_task_size = TASK_SIZE;
25498+
25499+#ifdef CONFIG_PAX_SEGMEXEC
25500+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25501+ pax_task_size = SEGMEXEC_TASK_SIZE;
25502+#endif
25503+
25504+ if (flags & MAP_FIXED)
25505+ if (len > pax_task_size || addr > pax_task_size - len)
25506+ return -EINVAL;
25507+
25508+ return 0;
25509+}
25510+
25511+/*
25512+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25513+ */
25514+static unsigned long get_align_mask(void)
25515+{
25516+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25517+ return 0;
25518+
25519+ if (!(current->flags & PF_RANDOMIZE))
25520+ return 0;
25521+
25522+ return va_align.mask;
25523+}
25524+
25525+unsigned long
25526+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25527+ unsigned long len, unsigned long pgoff, unsigned long flags)
25528+{
25529+ struct mm_struct *mm = current->mm;
25530+ struct vm_area_struct *vma;
25531+ unsigned long pax_task_size = TASK_SIZE;
25532+ struct vm_unmapped_area_info info;
25533+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25534+
25535+#ifdef CONFIG_PAX_SEGMEXEC
25536+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25537+ pax_task_size = SEGMEXEC_TASK_SIZE;
25538+#endif
25539+
25540+ pax_task_size -= PAGE_SIZE;
25541+
25542+ if (len > pax_task_size)
25543+ return -ENOMEM;
25544+
25545+ if (flags & MAP_FIXED)
25546+ return addr;
25547+
25548+#ifdef CONFIG_PAX_RANDMMAP
25549+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25550+#endif
25551+
25552+ if (addr) {
25553+ addr = PAGE_ALIGN(addr);
25554+ if (pax_task_size - len >= addr) {
25555+ vma = find_vma(mm, addr);
25556+ if (check_heap_stack_gap(vma, addr, len, offset))
25557+ return addr;
25558+ }
25559+ }
25560+
25561+ info.flags = 0;
25562+ info.length = len;
25563+ info.align_mask = filp ? get_align_mask() : 0;
25564+ info.align_offset = pgoff << PAGE_SHIFT;
25565+ info.threadstack_offset = offset;
25566+
25567+#ifdef CONFIG_PAX_PAGEEXEC
25568+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25569+ info.low_limit = 0x00110000UL;
25570+ info.high_limit = mm->start_code;
25571+
25572+#ifdef CONFIG_PAX_RANDMMAP
25573+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25574+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25575+#endif
25576+
25577+ if (info.low_limit < info.high_limit) {
25578+ addr = vm_unmapped_area(&info);
25579+ if (!IS_ERR_VALUE(addr))
25580+ return addr;
25581+ }
25582+ } else
25583+#endif
25584+
25585+ info.low_limit = mm->mmap_base;
25586+ info.high_limit = pax_task_size;
25587+
25588+ return vm_unmapped_area(&info);
25589+}
25590+
25591+unsigned long
25592+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25593+ const unsigned long len, const unsigned long pgoff,
25594+ const unsigned long flags)
25595+{
25596+ struct vm_area_struct *vma;
25597+ struct mm_struct *mm = current->mm;
25598+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25599+ struct vm_unmapped_area_info info;
25600+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25601+
25602+#ifdef CONFIG_PAX_SEGMEXEC
25603+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25604+ pax_task_size = SEGMEXEC_TASK_SIZE;
25605+#endif
25606+
25607+ pax_task_size -= PAGE_SIZE;
25608+
25609+ /* requested length too big for entire address space */
25610+ if (len > pax_task_size)
25611+ return -ENOMEM;
25612+
25613+ if (flags & MAP_FIXED)
25614+ return addr;
25615+
25616+#ifdef CONFIG_PAX_PAGEEXEC
25617+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25618+ goto bottomup;
25619+#endif
25620+
25621+#ifdef CONFIG_PAX_RANDMMAP
25622+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25623+#endif
25624+
25625+ /* requesting a specific address */
25626+ if (addr) {
25627+ addr = PAGE_ALIGN(addr);
25628+ if (pax_task_size - len >= addr) {
25629+ vma = find_vma(mm, addr);
25630+ if (check_heap_stack_gap(vma, addr, len, offset))
25631+ return addr;
25632+ }
25633+ }
25634+
25635+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25636+ info.length = len;
25637+ info.low_limit = PAGE_SIZE;
25638+ info.high_limit = mm->mmap_base;
25639+ info.align_mask = filp ? get_align_mask() : 0;
25640+ info.align_offset = pgoff << PAGE_SHIFT;
25641+ info.threadstack_offset = offset;
25642+
25643+ addr = vm_unmapped_area(&info);
25644+ if (!(addr & ~PAGE_MASK))
25645+ return addr;
25646+ VM_BUG_ON(addr != -ENOMEM);
25647+
25648+bottomup:
25649+ /*
25650+ * A failed mmap() very likely causes application failure,
25651+ * so fall back to the bottom-up function here. This scenario
25652+ * can happen with large stack limits and large mmap()
25653+ * allocations.
25654+ */
25655+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25656+}
25657diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25658index 30277e2..5664a29 100644
25659--- a/arch/x86/kernel/sys_x86_64.c
25660+++ b/arch/x86/kernel/sys_x86_64.c
25661@@ -81,8 +81,8 @@ out:
25662 return error;
25663 }
25664
25665-static void find_start_end(unsigned long flags, unsigned long *begin,
25666- unsigned long *end)
25667+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25668+ unsigned long *begin, unsigned long *end)
25669 {
25670 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25671 unsigned long new_begin;
25672@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25673 *begin = new_begin;
25674 }
25675 } else {
25676- *begin = current->mm->mmap_legacy_base;
25677+ *begin = mm->mmap_legacy_base;
25678 *end = TASK_SIZE;
25679 }
25680 }
25681@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25682 struct vm_area_struct *vma;
25683 struct vm_unmapped_area_info info;
25684 unsigned long begin, end;
25685+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25686
25687 if (flags & MAP_FIXED)
25688 return addr;
25689
25690- find_start_end(flags, &begin, &end);
25691+ find_start_end(mm, flags, &begin, &end);
25692
25693 if (len > end)
25694 return -ENOMEM;
25695
25696+#ifdef CONFIG_PAX_RANDMMAP
25697+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25698+#endif
25699+
25700 if (addr) {
25701 addr = PAGE_ALIGN(addr);
25702 vma = find_vma(mm, addr);
25703- if (end - len >= addr &&
25704- (!vma || addr + len <= vma->vm_start))
25705+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25706 return addr;
25707 }
25708
25709@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25710 info.high_limit = end;
25711 info.align_mask = filp ? get_align_mask() : 0;
25712 info.align_offset = pgoff << PAGE_SHIFT;
25713+ info.threadstack_offset = offset;
25714 return vm_unmapped_area(&info);
25715 }
25716
25717@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25718 struct mm_struct *mm = current->mm;
25719 unsigned long addr = addr0;
25720 struct vm_unmapped_area_info info;
25721+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25722
25723 /* requested length too big for entire address space */
25724 if (len > TASK_SIZE)
25725@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25726 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25727 goto bottomup;
25728
25729+#ifdef CONFIG_PAX_RANDMMAP
25730+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25731+#endif
25732+
25733 /* requesting a specific address */
25734 if (addr) {
25735 addr = PAGE_ALIGN(addr);
25736 vma = find_vma(mm, addr);
25737- if (TASK_SIZE - len >= addr &&
25738- (!vma || addr + len <= vma->vm_start))
25739+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25740 return addr;
25741 }
25742
25743@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25744 info.high_limit = mm->mmap_base;
25745 info.align_mask = filp ? get_align_mask() : 0;
25746 info.align_offset = pgoff << PAGE_SHIFT;
25747+ info.threadstack_offset = offset;
25748 addr = vm_unmapped_area(&info);
25749 if (!(addr & ~PAGE_MASK))
25750 return addr;
25751diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25752index addf7b5..f960685 100644
25753--- a/arch/x86/kernel/tboot.c
25754+++ b/arch/x86/kernel/tboot.c
25755@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25756
25757 void tboot_shutdown(u32 shutdown_type)
25758 {
25759- void (*shutdown)(void);
25760+ void (* __noreturn shutdown)(void);
25761
25762 if (!tboot_enabled())
25763 return;
25764@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25765
25766 switch_to_tboot_pt();
25767
25768- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25769+ shutdown = (void *)tboot->shutdown_entry;
25770 shutdown();
25771
25772 /* should not reach here */
25773@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25774 return 0;
25775 }
25776
25777-static atomic_t ap_wfs_count;
25778+static atomic_unchecked_t ap_wfs_count;
25779
25780 static int tboot_wait_for_aps(int num_aps)
25781 {
25782@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25783 {
25784 switch (action) {
25785 case CPU_DYING:
25786- atomic_inc(&ap_wfs_count);
25787+ atomic_inc_unchecked(&ap_wfs_count);
25788 if (num_online_cpus() == 1)
25789- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25790+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25791 return NOTIFY_BAD;
25792 break;
25793 }
25794@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25795
25796 tboot_create_trampoline();
25797
25798- atomic_set(&ap_wfs_count, 0);
25799+ atomic_set_unchecked(&ap_wfs_count, 0);
25800 register_hotcpu_notifier(&tboot_cpu_notifier);
25801
25802 #ifdef CONFIG_DEBUG_FS
25803diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25804index 24d3c91..d06b473 100644
25805--- a/arch/x86/kernel/time.c
25806+++ b/arch/x86/kernel/time.c
25807@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25808 {
25809 unsigned long pc = instruction_pointer(regs);
25810
25811- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25812+ if (!user_mode(regs) && in_lock_functions(pc)) {
25813 #ifdef CONFIG_FRAME_POINTER
25814- return *(unsigned long *)(regs->bp + sizeof(long));
25815+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25816 #else
25817 unsigned long *sp =
25818 (unsigned long *)kernel_stack_pointer(regs);
25819@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25820 * or above a saved flags. Eflags has bits 22-31 zero,
25821 * kernel addresses don't.
25822 */
25823+
25824+#ifdef CONFIG_PAX_KERNEXEC
25825+ return ktla_ktva(sp[0]);
25826+#else
25827 if (sp[0] >> 22)
25828 return sp[0];
25829 if (sp[1] >> 22)
25830 return sp[1];
25831 #endif
25832+
25833+#endif
25834 }
25835 return pc;
25836 }
25837diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25838index f7fec09..9991981 100644
25839--- a/arch/x86/kernel/tls.c
25840+++ b/arch/x86/kernel/tls.c
25841@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25842 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25843 return -EINVAL;
25844
25845+#ifdef CONFIG_PAX_SEGMEXEC
25846+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25847+ return -EINVAL;
25848+#endif
25849+
25850 set_tls_desc(p, idx, &info, 1);
25851
25852 return 0;
25853@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25854
25855 if (kbuf)
25856 info = kbuf;
25857- else if (__copy_from_user(infobuf, ubuf, count))
25858+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25859 return -EFAULT;
25860 else
25861 info = infobuf;
25862diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25863index 1c113db..287b42e 100644
25864--- a/arch/x86/kernel/tracepoint.c
25865+++ b/arch/x86/kernel/tracepoint.c
25866@@ -9,11 +9,11 @@
25867 #include <linux/atomic.h>
25868
25869 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25870-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25871+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25872 (unsigned long) trace_idt_table };
25873
25874 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25875-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25876+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25877
25878 static int trace_irq_vector_refcount;
25879 static DEFINE_MUTEX(irq_vector_mutex);
25880diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25881index 1b23a1c..910de0d 100644
25882--- a/arch/x86/kernel/traps.c
25883+++ b/arch/x86/kernel/traps.c
25884@@ -65,7 +65,7 @@
25885 #include <asm/proto.h>
25886
25887 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25888-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25889+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25890 #else
25891 #include <asm/processor-flags.h>
25892 #include <asm/setup.h>
25893@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25894 #endif
25895
25896 /* Must be page-aligned because the real IDT is used in a fixmap. */
25897-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25898+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25899
25900 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25901 EXPORT_SYMBOL_GPL(used_vectors);
25902@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25903 }
25904
25905 static int __kprobes
25906-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25907+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25908 struct pt_regs *regs, long error_code)
25909 {
25910 #ifdef CONFIG_X86_32
25911- if (regs->flags & X86_VM_MASK) {
25912+ if (v8086_mode(regs)) {
25913 /*
25914 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25915 * On nmi (interrupt 2), do_trap should not be called.
25916@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25917 return -1;
25918 }
25919 #endif
25920- if (!user_mode(regs)) {
25921+ if (!user_mode_novm(regs)) {
25922 if (!fixup_exception(regs)) {
25923 tsk->thread.error_code = error_code;
25924 tsk->thread.trap_nr = trapnr;
25925+
25926+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25927+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25928+ str = "PAX: suspicious stack segment fault";
25929+#endif
25930+
25931 die(str, regs, error_code);
25932 }
25933+
25934+#ifdef CONFIG_PAX_REFCOUNT
25935+ if (trapnr == 4)
25936+ pax_report_refcount_overflow(regs);
25937+#endif
25938+
25939 return 0;
25940 }
25941
25942@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25943 }
25944
25945 static void __kprobes
25946-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25947+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25948 long error_code, siginfo_t *info)
25949 {
25950 struct task_struct *tsk = current;
25951@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25952 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25953 printk_ratelimit()) {
25954 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25955- tsk->comm, tsk->pid, str,
25956+ tsk->comm, task_pid_nr(tsk), str,
25957 regs->ip, regs->sp, error_code);
25958 print_vma_addr(" in ", regs->ip);
25959 pr_cont("\n");
25960@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25961 conditional_sti(regs);
25962
25963 #ifdef CONFIG_X86_32
25964- if (regs->flags & X86_VM_MASK) {
25965+ if (v8086_mode(regs)) {
25966 local_irq_enable();
25967 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25968 goto exit;
25969@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25970 #endif
25971
25972 tsk = current;
25973- if (!user_mode(regs)) {
25974+ if (!user_mode_novm(regs)) {
25975 if (fixup_exception(regs))
25976 goto exit;
25977
25978 tsk->thread.error_code = error_code;
25979 tsk->thread.trap_nr = X86_TRAP_GP;
25980 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25981- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25982+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25983+
25984+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25985+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25986+ die("PAX: suspicious general protection fault", regs, error_code);
25987+ else
25988+#endif
25989+
25990 die("general protection fault", regs, error_code);
25991+ }
25992 goto exit;
25993 }
25994
25995+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25996+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25997+ struct mm_struct *mm = tsk->mm;
25998+ unsigned long limit;
25999+
26000+ down_write(&mm->mmap_sem);
26001+ limit = mm->context.user_cs_limit;
26002+ if (limit < TASK_SIZE) {
26003+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26004+ up_write(&mm->mmap_sem);
26005+ return;
26006+ }
26007+ up_write(&mm->mmap_sem);
26008+ }
26009+#endif
26010+
26011 tsk->thread.error_code = error_code;
26012 tsk->thread.trap_nr = X86_TRAP_GP;
26013
26014@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26015 /* It's safe to allow irq's after DR6 has been saved */
26016 preempt_conditional_sti(regs);
26017
26018- if (regs->flags & X86_VM_MASK) {
26019+ if (v8086_mode(regs)) {
26020 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26021 X86_TRAP_DB);
26022 preempt_conditional_cli(regs);
26023@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26024 * We already checked v86 mode above, so we can check for kernel mode
26025 * by just checking the CPL of CS.
26026 */
26027- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26028+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26029 tsk->thread.debugreg6 &= ~DR_STEP;
26030 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26031 regs->flags &= ~X86_EFLAGS_TF;
26032@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26033 return;
26034 conditional_sti(regs);
26035
26036- if (!user_mode_vm(regs))
26037+ if (!user_mode(regs))
26038 {
26039 if (!fixup_exception(regs)) {
26040 task->thread.error_code = error_code;
26041diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26042index 2ed8459..7cf329f 100644
26043--- a/arch/x86/kernel/uprobes.c
26044+++ b/arch/x86/kernel/uprobes.c
26045@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26046 int ret = NOTIFY_DONE;
26047
26048 /* We are only interested in userspace traps */
26049- if (regs && !user_mode_vm(regs))
26050+ if (regs && !user_mode(regs))
26051 return NOTIFY_DONE;
26052
26053 switch (val) {
26054@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26055
26056 if (ncopied != rasize) {
26057 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26058- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26059+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26060
26061 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26062 }
26063diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26064index b9242ba..50c5edd 100644
26065--- a/arch/x86/kernel/verify_cpu.S
26066+++ b/arch/x86/kernel/verify_cpu.S
26067@@ -20,6 +20,7 @@
26068 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26069 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26070 * arch/x86/kernel/head_32.S: processor startup
26071+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26072 *
26073 * verify_cpu, returns the status of longmode and SSE in register %eax.
26074 * 0: Success 1: Failure
26075diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26076index e8edcf5..27f9344 100644
26077--- a/arch/x86/kernel/vm86_32.c
26078+++ b/arch/x86/kernel/vm86_32.c
26079@@ -44,6 +44,7 @@
26080 #include <linux/ptrace.h>
26081 #include <linux/audit.h>
26082 #include <linux/stddef.h>
26083+#include <linux/grsecurity.h>
26084
26085 #include <asm/uaccess.h>
26086 #include <asm/io.h>
26087@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26088 do_exit(SIGSEGV);
26089 }
26090
26091- tss = &per_cpu(init_tss, get_cpu());
26092+ tss = init_tss + get_cpu();
26093 current->thread.sp0 = current->thread.saved_sp0;
26094 current->thread.sysenter_cs = __KERNEL_CS;
26095 load_sp0(tss, &current->thread);
26096@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26097
26098 if (tsk->thread.saved_sp0)
26099 return -EPERM;
26100+
26101+#ifdef CONFIG_GRKERNSEC_VM86
26102+ if (!capable(CAP_SYS_RAWIO)) {
26103+ gr_handle_vm86();
26104+ return -EPERM;
26105+ }
26106+#endif
26107+
26108 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26109 offsetof(struct kernel_vm86_struct, vm86plus) -
26110 sizeof(info.regs));
26111@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26112 int tmp;
26113 struct vm86plus_struct __user *v86;
26114
26115+#ifdef CONFIG_GRKERNSEC_VM86
26116+ if (!capable(CAP_SYS_RAWIO)) {
26117+ gr_handle_vm86();
26118+ return -EPERM;
26119+ }
26120+#endif
26121+
26122 tsk = current;
26123 switch (cmd) {
26124 case VM86_REQUEST_IRQ:
26125@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26126 tsk->thread.saved_fs = info->regs32->fs;
26127 tsk->thread.saved_gs = get_user_gs(info->regs32);
26128
26129- tss = &per_cpu(init_tss, get_cpu());
26130+ tss = init_tss + get_cpu();
26131 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26132 if (cpu_has_sep)
26133 tsk->thread.sysenter_cs = 0;
26134@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26135 goto cannot_handle;
26136 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26137 goto cannot_handle;
26138- intr_ptr = (unsigned long __user *) (i << 2);
26139+ intr_ptr = (__force unsigned long __user *) (i << 2);
26140 if (get_user(segoffs, intr_ptr))
26141 goto cannot_handle;
26142 if ((segoffs >> 16) == BIOSSEG)
26143diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26144index 10c4f30..65408b9 100644
26145--- a/arch/x86/kernel/vmlinux.lds.S
26146+++ b/arch/x86/kernel/vmlinux.lds.S
26147@@ -26,6 +26,13 @@
26148 #include <asm/page_types.h>
26149 #include <asm/cache.h>
26150 #include <asm/boot.h>
26151+#include <asm/segment.h>
26152+
26153+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26154+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26155+#else
26156+#define __KERNEL_TEXT_OFFSET 0
26157+#endif
26158
26159 #undef i386 /* in case the preprocessor is a 32bit one */
26160
26161@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26162
26163 PHDRS {
26164 text PT_LOAD FLAGS(5); /* R_E */
26165+#ifdef CONFIG_X86_32
26166+ module PT_LOAD FLAGS(5); /* R_E */
26167+#endif
26168+#ifdef CONFIG_XEN
26169+ rodata PT_LOAD FLAGS(5); /* R_E */
26170+#else
26171+ rodata PT_LOAD FLAGS(4); /* R__ */
26172+#endif
26173 data PT_LOAD FLAGS(6); /* RW_ */
26174-#ifdef CONFIG_X86_64
26175+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26176 #ifdef CONFIG_SMP
26177 percpu PT_LOAD FLAGS(6); /* RW_ */
26178 #endif
26179+ text.init PT_LOAD FLAGS(5); /* R_E */
26180+ text.exit PT_LOAD FLAGS(5); /* R_E */
26181 init PT_LOAD FLAGS(7); /* RWE */
26182-#endif
26183 note PT_NOTE FLAGS(0); /* ___ */
26184 }
26185
26186 SECTIONS
26187 {
26188 #ifdef CONFIG_X86_32
26189- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26190- phys_startup_32 = startup_32 - LOAD_OFFSET;
26191+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26192 #else
26193- . = __START_KERNEL;
26194- phys_startup_64 = startup_64 - LOAD_OFFSET;
26195+ . = __START_KERNEL;
26196 #endif
26197
26198 /* Text and read-only data */
26199- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26200- _text = .;
26201+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26202 /* bootstrapping code */
26203+#ifdef CONFIG_X86_32
26204+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26205+#else
26206+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26207+#endif
26208+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26209+ _text = .;
26210 HEAD_TEXT
26211 . = ALIGN(8);
26212 _stext = .;
26213@@ -104,13 +124,47 @@ SECTIONS
26214 IRQENTRY_TEXT
26215 *(.fixup)
26216 *(.gnu.warning)
26217- /* End of text section */
26218- _etext = .;
26219 } :text = 0x9090
26220
26221- NOTES :text :note
26222+ . += __KERNEL_TEXT_OFFSET;
26223
26224- EXCEPTION_TABLE(16) :text = 0x9090
26225+#ifdef CONFIG_X86_32
26226+ . = ALIGN(PAGE_SIZE);
26227+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26228+
26229+#ifdef CONFIG_PAX_KERNEXEC
26230+ MODULES_EXEC_VADDR = .;
26231+ BYTE(0)
26232+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26233+ . = ALIGN(HPAGE_SIZE) - 1;
26234+ MODULES_EXEC_END = .;
26235+#endif
26236+
26237+ } :module
26238+#endif
26239+
26240+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26241+ /* End of text section */
26242+ BYTE(0)
26243+ _etext = . - __KERNEL_TEXT_OFFSET;
26244+ }
26245+
26246+#ifdef CONFIG_X86_32
26247+ . = ALIGN(PAGE_SIZE);
26248+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26249+ . = ALIGN(PAGE_SIZE);
26250+ *(.empty_zero_page)
26251+ *(.initial_pg_fixmap)
26252+ *(.initial_pg_pmd)
26253+ *(.initial_page_table)
26254+ *(.swapper_pg_dir)
26255+ } :rodata
26256+#endif
26257+
26258+ . = ALIGN(PAGE_SIZE);
26259+ NOTES :rodata :note
26260+
26261+ EXCEPTION_TABLE(16) :rodata
26262
26263 #if defined(CONFIG_DEBUG_RODATA)
26264 /* .text should occupy whole number of pages */
26265@@ -122,16 +176,20 @@ SECTIONS
26266
26267 /* Data */
26268 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26269+
26270+#ifdef CONFIG_PAX_KERNEXEC
26271+ . = ALIGN(HPAGE_SIZE);
26272+#else
26273+ . = ALIGN(PAGE_SIZE);
26274+#endif
26275+
26276 /* Start of data section */
26277 _sdata = .;
26278
26279 /* init_task */
26280 INIT_TASK_DATA(THREAD_SIZE)
26281
26282-#ifdef CONFIG_X86_32
26283- /* 32 bit has nosave before _edata */
26284 NOSAVE_DATA
26285-#endif
26286
26287 PAGE_ALIGNED_DATA(PAGE_SIZE)
26288
26289@@ -172,12 +230,19 @@ SECTIONS
26290 #endif /* CONFIG_X86_64 */
26291
26292 /* Init code and data - will be freed after init */
26293- . = ALIGN(PAGE_SIZE);
26294 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26295+ BYTE(0)
26296+
26297+#ifdef CONFIG_PAX_KERNEXEC
26298+ . = ALIGN(HPAGE_SIZE);
26299+#else
26300+ . = ALIGN(PAGE_SIZE);
26301+#endif
26302+
26303 __init_begin = .; /* paired with __init_end */
26304- }
26305+ } :init.begin
26306
26307-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26308+#ifdef CONFIG_SMP
26309 /*
26310 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26311 * output PHDR, so the next output section - .init.text - should
26312@@ -186,12 +251,27 @@ SECTIONS
26313 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26314 #endif
26315
26316- INIT_TEXT_SECTION(PAGE_SIZE)
26317-#ifdef CONFIG_X86_64
26318- :init
26319-#endif
26320+ . = ALIGN(PAGE_SIZE);
26321+ init_begin = .;
26322+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26323+ VMLINUX_SYMBOL(_sinittext) = .;
26324+ INIT_TEXT
26325+ VMLINUX_SYMBOL(_einittext) = .;
26326+ . = ALIGN(PAGE_SIZE);
26327+ } :text.init
26328
26329- INIT_DATA_SECTION(16)
26330+ /*
26331+ * .exit.text is discard at runtime, not link time, to deal with
26332+ * references from .altinstructions and .eh_frame
26333+ */
26334+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26335+ EXIT_TEXT
26336+ . = ALIGN(16);
26337+ } :text.exit
26338+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26339+
26340+ . = ALIGN(PAGE_SIZE);
26341+ INIT_DATA_SECTION(16) :init
26342
26343 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26344 __x86_cpu_dev_start = .;
26345@@ -253,19 +333,12 @@ SECTIONS
26346 }
26347
26348 . = ALIGN(8);
26349- /*
26350- * .exit.text is discard at runtime, not link time, to deal with
26351- * references from .altinstructions and .eh_frame
26352- */
26353- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26354- EXIT_TEXT
26355- }
26356
26357 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26358 EXIT_DATA
26359 }
26360
26361-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26362+#ifndef CONFIG_SMP
26363 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26364 #endif
26365
26366@@ -284,16 +357,10 @@ SECTIONS
26367 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26368 __smp_locks = .;
26369 *(.smp_locks)
26370- . = ALIGN(PAGE_SIZE);
26371 __smp_locks_end = .;
26372+ . = ALIGN(PAGE_SIZE);
26373 }
26374
26375-#ifdef CONFIG_X86_64
26376- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26377- NOSAVE_DATA
26378- }
26379-#endif
26380-
26381 /* BSS */
26382 . = ALIGN(PAGE_SIZE);
26383 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26384@@ -309,6 +376,7 @@ SECTIONS
26385 __brk_base = .;
26386 . += 64 * 1024; /* 64k alignment slop space */
26387 *(.brk_reservation) /* areas brk users have reserved */
26388+ . = ALIGN(HPAGE_SIZE);
26389 __brk_limit = .;
26390 }
26391
26392@@ -335,13 +403,12 @@ SECTIONS
26393 * for the boot processor.
26394 */
26395 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26396-INIT_PER_CPU(gdt_page);
26397 INIT_PER_CPU(irq_stack_union);
26398
26399 /*
26400 * Build-time check on the image size:
26401 */
26402-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26403+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26404 "kernel image bigger than KERNEL_IMAGE_SIZE");
26405
26406 #ifdef CONFIG_SMP
26407diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26408index 1f96f93..d5c8f7a 100644
26409--- a/arch/x86/kernel/vsyscall_64.c
26410+++ b/arch/x86/kernel/vsyscall_64.c
26411@@ -56,15 +56,13 @@
26412 DEFINE_VVAR(int, vgetcpu_mode);
26413 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26414
26415-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26416+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26417
26418 static int __init vsyscall_setup(char *str)
26419 {
26420 if (str) {
26421 if (!strcmp("emulate", str))
26422 vsyscall_mode = EMULATE;
26423- else if (!strcmp("native", str))
26424- vsyscall_mode = NATIVE;
26425 else if (!strcmp("none", str))
26426 vsyscall_mode = NONE;
26427 else
26428@@ -323,8 +321,7 @@ do_ret:
26429 return true;
26430
26431 sigsegv:
26432- force_sig(SIGSEGV, current);
26433- return true;
26434+ do_group_exit(SIGKILL);
26435 }
26436
26437 /*
26438@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26439 extern char __vvar_page;
26440 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26441
26442- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26443- vsyscall_mode == NATIVE
26444- ? PAGE_KERNEL_VSYSCALL
26445- : PAGE_KERNEL_VVAR);
26446+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26447 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26448 (unsigned long)VSYSCALL_START);
26449
26450diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26451index b014d94..e775258 100644
26452--- a/arch/x86/kernel/x8664_ksyms_64.c
26453+++ b/arch/x86/kernel/x8664_ksyms_64.c
26454@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26455 EXPORT_SYMBOL(copy_user_generic_unrolled);
26456 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26457 EXPORT_SYMBOL(__copy_user_nocache);
26458-EXPORT_SYMBOL(_copy_from_user);
26459-EXPORT_SYMBOL(_copy_to_user);
26460
26461 EXPORT_SYMBOL(copy_page);
26462 EXPORT_SYMBOL(clear_page);
26463@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26464 #ifndef CONFIG_PARAVIRT
26465 EXPORT_SYMBOL(native_load_gs_index);
26466 #endif
26467+
26468+#ifdef CONFIG_PAX_PER_CPU_PGD
26469+EXPORT_SYMBOL(cpu_pgd);
26470+#endif
26471diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26472index 5f24c71..1dadf09 100644
26473--- a/arch/x86/kernel/x86_init.c
26474+++ b/arch/x86/kernel/x86_init.c
26475@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26476 static void default_nmi_init(void) { };
26477 static int default_i8042_detect(void) { return 1; };
26478
26479-struct x86_platform_ops x86_platform = {
26480+struct x86_platform_ops x86_platform __read_only = {
26481 .calibrate_tsc = native_calibrate_tsc,
26482 .get_wallclock = mach_get_cmos_time,
26483 .set_wallclock = mach_set_rtc_mmss,
26484@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26485 };
26486
26487 EXPORT_SYMBOL_GPL(x86_platform);
26488-struct x86_msi_ops x86_msi = {
26489+struct x86_msi_ops x86_msi __read_only = {
26490 .setup_msi_irqs = native_setup_msi_irqs,
26491 .compose_msi_msg = native_compose_msi_msg,
26492 .teardown_msi_irq = native_teardown_msi_irq,
26493@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26494 .setup_hpet_msi = default_setup_hpet_msi,
26495 };
26496
26497-struct x86_io_apic_ops x86_io_apic_ops = {
26498+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26499 .init = native_io_apic_init_mappings,
26500 .read = native_io_apic_read,
26501 .write = native_io_apic_write,
26502diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26503index 422fd82..c3687ca 100644
26504--- a/arch/x86/kernel/xsave.c
26505+++ b/arch/x86/kernel/xsave.c
26506@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26507 {
26508 int err;
26509
26510+ buf = (struct xsave_struct __user *)____m(buf);
26511 if (use_xsave())
26512 err = xsave_user(buf);
26513 else if (use_fxsr())
26514@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26515 */
26516 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26517 {
26518+ buf = (void __user *)____m(buf);
26519 if (use_xsave()) {
26520 if ((unsigned long)buf % 64 || fx_only) {
26521 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26522diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26523index a20ecb5..d0e2194 100644
26524--- a/arch/x86/kvm/cpuid.c
26525+++ b/arch/x86/kvm/cpuid.c
26526@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26527 struct kvm_cpuid2 *cpuid,
26528 struct kvm_cpuid_entry2 __user *entries)
26529 {
26530- int r;
26531+ int r, i;
26532
26533 r = -E2BIG;
26534 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26535 goto out;
26536 r = -EFAULT;
26537- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26538- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26539+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26540 goto out;
26541+ for (i = 0; i < cpuid->nent; ++i) {
26542+ struct kvm_cpuid_entry2 cpuid_entry;
26543+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26544+ goto out;
26545+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26546+ }
26547 vcpu->arch.cpuid_nent = cpuid->nent;
26548 kvm_apic_set_version(vcpu);
26549 kvm_x86_ops->cpuid_update(vcpu);
26550@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26551 struct kvm_cpuid2 *cpuid,
26552 struct kvm_cpuid_entry2 __user *entries)
26553 {
26554- int r;
26555+ int r, i;
26556
26557 r = -E2BIG;
26558 if (cpuid->nent < vcpu->arch.cpuid_nent)
26559 goto out;
26560 r = -EFAULT;
26561- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26562- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26563+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26564 goto out;
26565+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26566+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26567+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26568+ goto out;
26569+ }
26570 return 0;
26571
26572 out:
26573diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26574index afc1124..3e431f2 100644
26575--- a/arch/x86/kvm/lapic.c
26576+++ b/arch/x86/kvm/lapic.c
26577@@ -55,7 +55,7 @@
26578 #define APIC_BUS_CYCLE_NS 1
26579
26580 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26581-#define apic_debug(fmt, arg...)
26582+#define apic_debug(fmt, arg...) do {} while (0)
26583
26584 #define APIC_LVT_NUM 6
26585 /* 14 is the version for Xeon and Pentium 8.4.8*/
26586diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26587index 7769699..c8aca4a7f 100644
26588--- a/arch/x86/kvm/paging_tmpl.h
26589+++ b/arch/x86/kvm/paging_tmpl.h
26590@@ -208,7 +208,7 @@ retry_walk:
26591 if (unlikely(kvm_is_error_hva(host_addr)))
26592 goto error;
26593
26594- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26595+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26596 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26597 goto error;
26598 walker->ptep_user[walker->level - 1] = ptep_user;
26599diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26600index c0bc803..6837a50 100644
26601--- a/arch/x86/kvm/svm.c
26602+++ b/arch/x86/kvm/svm.c
26603@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26604 int cpu = raw_smp_processor_id();
26605
26606 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26607+
26608+ pax_open_kernel();
26609 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26610+ pax_close_kernel();
26611+
26612 load_TR_desc();
26613 }
26614
26615@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26616 #endif
26617 #endif
26618
26619+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26620+ __set_fs(current_thread_info()->addr_limit);
26621+#endif
26622+
26623 reload_tss(vcpu);
26624
26625 local_irq_disable();
26626diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26627index 064d0be..f5f758e 100644
26628--- a/arch/x86/kvm/vmx.c
26629+++ b/arch/x86/kvm/vmx.c
26630@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26631 #endif
26632 }
26633
26634-static void vmcs_clear_bits(unsigned long field, u32 mask)
26635+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26636 {
26637 vmcs_writel(field, vmcs_readl(field) & ~mask);
26638 }
26639
26640-static void vmcs_set_bits(unsigned long field, u32 mask)
26641+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26642 {
26643 vmcs_writel(field, vmcs_readl(field) | mask);
26644 }
26645@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26646 struct desc_struct *descs;
26647
26648 descs = (void *)gdt->address;
26649+
26650+ pax_open_kernel();
26651 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26652+ pax_close_kernel();
26653+
26654 load_TR_desc();
26655 }
26656
26657@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26658 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26659 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26660
26661+#ifdef CONFIG_PAX_PER_CPU_PGD
26662+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26663+#endif
26664+
26665 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26666 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26667 vmx->loaded_vmcs->cpu = cpu;
26668@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26669 if (!cpu_has_vmx_flexpriority())
26670 flexpriority_enabled = 0;
26671
26672- if (!cpu_has_vmx_tpr_shadow())
26673- kvm_x86_ops->update_cr8_intercept = NULL;
26674+ if (!cpu_has_vmx_tpr_shadow()) {
26675+ pax_open_kernel();
26676+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26677+ pax_close_kernel();
26678+ }
26679
26680 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26681 kvm_disable_largepages();
26682@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26683 if (!cpu_has_vmx_apicv())
26684 enable_apicv = 0;
26685
26686+ pax_open_kernel();
26687 if (enable_apicv)
26688- kvm_x86_ops->update_cr8_intercept = NULL;
26689+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26690 else {
26691- kvm_x86_ops->hwapic_irr_update = NULL;
26692- kvm_x86_ops->deliver_posted_interrupt = NULL;
26693- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26694+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26695+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26696+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26697 }
26698+ pax_close_kernel();
26699
26700 if (nested)
26701 nested_vmx_setup_ctls_msrs();
26702@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26703
26704 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26705 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26706+
26707+#ifndef CONFIG_PAX_PER_CPU_PGD
26708 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26709+#endif
26710
26711 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26712 #ifdef CONFIG_X86_64
26713@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26714 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26715 vmx->host_idt_base = dt.address;
26716
26717- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26718+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26719
26720 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26721 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26722@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26723 "jmp 2f \n\t"
26724 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26725 "2: "
26726+
26727+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26728+ "ljmp %[cs],$3f\n\t"
26729+ "3: "
26730+#endif
26731+
26732 /* Save guest registers, load host registers, keep flags */
26733 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26734 "pop %0 \n\t"
26735@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26736 #endif
26737 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26738 [wordsize]"i"(sizeof(ulong))
26739+
26740+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26741+ ,[cs]"i"(__KERNEL_CS)
26742+#endif
26743+
26744 : "cc", "memory"
26745 #ifdef CONFIG_X86_64
26746 , "rax", "rbx", "rdi", "rsi"
26747@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26748 if (debugctlmsr)
26749 update_debugctlmsr(debugctlmsr);
26750
26751-#ifndef CONFIG_X86_64
26752+#ifdef CONFIG_X86_32
26753 /*
26754 * The sysexit path does not restore ds/es, so we must set them to
26755 * a reasonable value ourselves.
26756@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26757 * may be executed in interrupt context, which saves and restore segments
26758 * around it, nullifying its effect.
26759 */
26760- loadsegment(ds, __USER_DS);
26761- loadsegment(es, __USER_DS);
26762+ loadsegment(ds, __KERNEL_DS);
26763+ loadsegment(es, __KERNEL_DS);
26764+ loadsegment(ss, __KERNEL_DS);
26765+
26766+#ifdef CONFIG_PAX_KERNEXEC
26767+ loadsegment(fs, __KERNEL_PERCPU);
26768+#endif
26769+
26770+#ifdef CONFIG_PAX_MEMORY_UDEREF
26771+ __set_fs(current_thread_info()->addr_limit);
26772+#endif
26773+
26774 #endif
26775
26776 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26777diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26778index d21bce5..fdae9f1 100644
26779--- a/arch/x86/kvm/x86.c
26780+++ b/arch/x86/kvm/x86.c
26781@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26782 {
26783 struct kvm *kvm = vcpu->kvm;
26784 int lm = is_long_mode(vcpu);
26785- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26786- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26787+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26788+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26789 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26790 : kvm->arch.xen_hvm_config.blob_size_32;
26791 u32 page_num = data & ~PAGE_MASK;
26792@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26793 if (n < msr_list.nmsrs)
26794 goto out;
26795 r = -EFAULT;
26796+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26797+ goto out;
26798 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26799 num_msrs_to_save * sizeof(u32)))
26800 goto out;
26801@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26802 };
26803 #endif
26804
26805-int kvm_arch_init(void *opaque)
26806+int kvm_arch_init(const void *opaque)
26807 {
26808 int r;
26809 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26810diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26811index 6a22c19..1763f04 100644
26812--- a/arch/x86/lguest/boot.c
26813+++ b/arch/x86/lguest/boot.c
26814@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26815 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26816 * Launcher to reboot us.
26817 */
26818-static void lguest_restart(char *reason)
26819+static __noreturn void lguest_restart(char *reason)
26820 {
26821 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26822+ BUG();
26823 }
26824
26825 /*G:050
26826diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26827index 00933d5..3a64af9 100644
26828--- a/arch/x86/lib/atomic64_386_32.S
26829+++ b/arch/x86/lib/atomic64_386_32.S
26830@@ -48,6 +48,10 @@ BEGIN(read)
26831 movl (v), %eax
26832 movl 4(v), %edx
26833 RET_ENDP
26834+BEGIN(read_unchecked)
26835+ movl (v), %eax
26836+ movl 4(v), %edx
26837+RET_ENDP
26838 #undef v
26839
26840 #define v %esi
26841@@ -55,6 +59,10 @@ BEGIN(set)
26842 movl %ebx, (v)
26843 movl %ecx, 4(v)
26844 RET_ENDP
26845+BEGIN(set_unchecked)
26846+ movl %ebx, (v)
26847+ movl %ecx, 4(v)
26848+RET_ENDP
26849 #undef v
26850
26851 #define v %esi
26852@@ -70,6 +78,20 @@ RET_ENDP
26853 BEGIN(add)
26854 addl %eax, (v)
26855 adcl %edx, 4(v)
26856+
26857+#ifdef CONFIG_PAX_REFCOUNT
26858+ jno 0f
26859+ subl %eax, (v)
26860+ sbbl %edx, 4(v)
26861+ int $4
26862+0:
26863+ _ASM_EXTABLE(0b, 0b)
26864+#endif
26865+
26866+RET_ENDP
26867+BEGIN(add_unchecked)
26868+ addl %eax, (v)
26869+ adcl %edx, 4(v)
26870 RET_ENDP
26871 #undef v
26872
26873@@ -77,6 +99,24 @@ RET_ENDP
26874 BEGIN(add_return)
26875 addl (v), %eax
26876 adcl 4(v), %edx
26877+
26878+#ifdef CONFIG_PAX_REFCOUNT
26879+ into
26880+1234:
26881+ _ASM_EXTABLE(1234b, 2f)
26882+#endif
26883+
26884+ movl %eax, (v)
26885+ movl %edx, 4(v)
26886+
26887+#ifdef CONFIG_PAX_REFCOUNT
26888+2:
26889+#endif
26890+
26891+RET_ENDP
26892+BEGIN(add_return_unchecked)
26893+ addl (v), %eax
26894+ adcl 4(v), %edx
26895 movl %eax, (v)
26896 movl %edx, 4(v)
26897 RET_ENDP
26898@@ -86,6 +126,20 @@ RET_ENDP
26899 BEGIN(sub)
26900 subl %eax, (v)
26901 sbbl %edx, 4(v)
26902+
26903+#ifdef CONFIG_PAX_REFCOUNT
26904+ jno 0f
26905+ addl %eax, (v)
26906+ adcl %edx, 4(v)
26907+ int $4
26908+0:
26909+ _ASM_EXTABLE(0b, 0b)
26910+#endif
26911+
26912+RET_ENDP
26913+BEGIN(sub_unchecked)
26914+ subl %eax, (v)
26915+ sbbl %edx, 4(v)
26916 RET_ENDP
26917 #undef v
26918
26919@@ -96,6 +150,27 @@ BEGIN(sub_return)
26920 sbbl $0, %edx
26921 addl (v), %eax
26922 adcl 4(v), %edx
26923+
26924+#ifdef CONFIG_PAX_REFCOUNT
26925+ into
26926+1234:
26927+ _ASM_EXTABLE(1234b, 2f)
26928+#endif
26929+
26930+ movl %eax, (v)
26931+ movl %edx, 4(v)
26932+
26933+#ifdef CONFIG_PAX_REFCOUNT
26934+2:
26935+#endif
26936+
26937+RET_ENDP
26938+BEGIN(sub_return_unchecked)
26939+ negl %edx
26940+ negl %eax
26941+ sbbl $0, %edx
26942+ addl (v), %eax
26943+ adcl 4(v), %edx
26944 movl %eax, (v)
26945 movl %edx, 4(v)
26946 RET_ENDP
26947@@ -105,6 +180,20 @@ RET_ENDP
26948 BEGIN(inc)
26949 addl $1, (v)
26950 adcl $0, 4(v)
26951+
26952+#ifdef CONFIG_PAX_REFCOUNT
26953+ jno 0f
26954+ subl $1, (v)
26955+ sbbl $0, 4(v)
26956+ int $4
26957+0:
26958+ _ASM_EXTABLE(0b, 0b)
26959+#endif
26960+
26961+RET_ENDP
26962+BEGIN(inc_unchecked)
26963+ addl $1, (v)
26964+ adcl $0, 4(v)
26965 RET_ENDP
26966 #undef v
26967
26968@@ -114,6 +203,26 @@ BEGIN(inc_return)
26969 movl 4(v), %edx
26970 addl $1, %eax
26971 adcl $0, %edx
26972+
26973+#ifdef CONFIG_PAX_REFCOUNT
26974+ into
26975+1234:
26976+ _ASM_EXTABLE(1234b, 2f)
26977+#endif
26978+
26979+ movl %eax, (v)
26980+ movl %edx, 4(v)
26981+
26982+#ifdef CONFIG_PAX_REFCOUNT
26983+2:
26984+#endif
26985+
26986+RET_ENDP
26987+BEGIN(inc_return_unchecked)
26988+ movl (v), %eax
26989+ movl 4(v), %edx
26990+ addl $1, %eax
26991+ adcl $0, %edx
26992 movl %eax, (v)
26993 movl %edx, 4(v)
26994 RET_ENDP
26995@@ -123,6 +232,20 @@ RET_ENDP
26996 BEGIN(dec)
26997 subl $1, (v)
26998 sbbl $0, 4(v)
26999+
27000+#ifdef CONFIG_PAX_REFCOUNT
27001+ jno 0f
27002+ addl $1, (v)
27003+ adcl $0, 4(v)
27004+ int $4
27005+0:
27006+ _ASM_EXTABLE(0b, 0b)
27007+#endif
27008+
27009+RET_ENDP
27010+BEGIN(dec_unchecked)
27011+ subl $1, (v)
27012+ sbbl $0, 4(v)
27013 RET_ENDP
27014 #undef v
27015
27016@@ -132,6 +255,26 @@ BEGIN(dec_return)
27017 movl 4(v), %edx
27018 subl $1, %eax
27019 sbbl $0, %edx
27020+
27021+#ifdef CONFIG_PAX_REFCOUNT
27022+ into
27023+1234:
27024+ _ASM_EXTABLE(1234b, 2f)
27025+#endif
27026+
27027+ movl %eax, (v)
27028+ movl %edx, 4(v)
27029+
27030+#ifdef CONFIG_PAX_REFCOUNT
27031+2:
27032+#endif
27033+
27034+RET_ENDP
27035+BEGIN(dec_return_unchecked)
27036+ movl (v), %eax
27037+ movl 4(v), %edx
27038+ subl $1, %eax
27039+ sbbl $0, %edx
27040 movl %eax, (v)
27041 movl %edx, 4(v)
27042 RET_ENDP
27043@@ -143,6 +286,13 @@ BEGIN(add_unless)
27044 adcl %edx, %edi
27045 addl (v), %eax
27046 adcl 4(v), %edx
27047+
27048+#ifdef CONFIG_PAX_REFCOUNT
27049+ into
27050+1234:
27051+ _ASM_EXTABLE(1234b, 2f)
27052+#endif
27053+
27054 cmpl %eax, %ecx
27055 je 3f
27056 1:
27057@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27058 1:
27059 addl $1, %eax
27060 adcl $0, %edx
27061+
27062+#ifdef CONFIG_PAX_REFCOUNT
27063+ into
27064+1234:
27065+ _ASM_EXTABLE(1234b, 2f)
27066+#endif
27067+
27068 movl %eax, (v)
27069 movl %edx, 4(v)
27070 movl $1, %eax
27071@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27072 movl 4(v), %edx
27073 subl $1, %eax
27074 sbbl $0, %edx
27075+
27076+#ifdef CONFIG_PAX_REFCOUNT
27077+ into
27078+1234:
27079+ _ASM_EXTABLE(1234b, 1f)
27080+#endif
27081+
27082 js 1f
27083 movl %eax, (v)
27084 movl %edx, 4(v)
27085diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27086index f5cc9eb..51fa319 100644
27087--- a/arch/x86/lib/atomic64_cx8_32.S
27088+++ b/arch/x86/lib/atomic64_cx8_32.S
27089@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27090 CFI_STARTPROC
27091
27092 read64 %ecx
27093+ pax_force_retaddr
27094 ret
27095 CFI_ENDPROC
27096 ENDPROC(atomic64_read_cx8)
27097
27098+ENTRY(atomic64_read_unchecked_cx8)
27099+ CFI_STARTPROC
27100+
27101+ read64 %ecx
27102+ pax_force_retaddr
27103+ ret
27104+ CFI_ENDPROC
27105+ENDPROC(atomic64_read_unchecked_cx8)
27106+
27107 ENTRY(atomic64_set_cx8)
27108 CFI_STARTPROC
27109
27110@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27111 cmpxchg8b (%esi)
27112 jne 1b
27113
27114+ pax_force_retaddr
27115 ret
27116 CFI_ENDPROC
27117 ENDPROC(atomic64_set_cx8)
27118
27119+ENTRY(atomic64_set_unchecked_cx8)
27120+ CFI_STARTPROC
27121+
27122+1:
27123+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27124+ * are atomic on 586 and newer */
27125+ cmpxchg8b (%esi)
27126+ jne 1b
27127+
27128+ pax_force_retaddr
27129+ ret
27130+ CFI_ENDPROC
27131+ENDPROC(atomic64_set_unchecked_cx8)
27132+
27133 ENTRY(atomic64_xchg_cx8)
27134 CFI_STARTPROC
27135
27136@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27137 cmpxchg8b (%esi)
27138 jne 1b
27139
27140+ pax_force_retaddr
27141 ret
27142 CFI_ENDPROC
27143 ENDPROC(atomic64_xchg_cx8)
27144
27145-.macro addsub_return func ins insc
27146-ENTRY(atomic64_\func\()_return_cx8)
27147+.macro addsub_return func ins insc unchecked=""
27148+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27149 CFI_STARTPROC
27150 SAVE ebp
27151 SAVE ebx
27152@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27153 movl %edx, %ecx
27154 \ins\()l %esi, %ebx
27155 \insc\()l %edi, %ecx
27156+
27157+.ifb \unchecked
27158+#ifdef CONFIG_PAX_REFCOUNT
27159+ into
27160+2:
27161+ _ASM_EXTABLE(2b, 3f)
27162+#endif
27163+.endif
27164+
27165 LOCK_PREFIX
27166 cmpxchg8b (%ebp)
27167 jne 1b
27168-
27169-10:
27170 movl %ebx, %eax
27171 movl %ecx, %edx
27172+
27173+.ifb \unchecked
27174+#ifdef CONFIG_PAX_REFCOUNT
27175+3:
27176+#endif
27177+.endif
27178+
27179 RESTORE edi
27180 RESTORE esi
27181 RESTORE ebx
27182 RESTORE ebp
27183+ pax_force_retaddr
27184 ret
27185 CFI_ENDPROC
27186-ENDPROC(atomic64_\func\()_return_cx8)
27187+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27188 .endm
27189
27190 addsub_return add add adc
27191 addsub_return sub sub sbb
27192+addsub_return add add adc _unchecked
27193+addsub_return sub sub sbb _unchecked
27194
27195-.macro incdec_return func ins insc
27196-ENTRY(atomic64_\func\()_return_cx8)
27197+.macro incdec_return func ins insc unchecked=""
27198+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27199 CFI_STARTPROC
27200 SAVE ebx
27201
27202@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27203 movl %edx, %ecx
27204 \ins\()l $1, %ebx
27205 \insc\()l $0, %ecx
27206+
27207+.ifb \unchecked
27208+#ifdef CONFIG_PAX_REFCOUNT
27209+ into
27210+2:
27211+ _ASM_EXTABLE(2b, 3f)
27212+#endif
27213+.endif
27214+
27215 LOCK_PREFIX
27216 cmpxchg8b (%esi)
27217 jne 1b
27218
27219-10:
27220 movl %ebx, %eax
27221 movl %ecx, %edx
27222+
27223+.ifb \unchecked
27224+#ifdef CONFIG_PAX_REFCOUNT
27225+3:
27226+#endif
27227+.endif
27228+
27229 RESTORE ebx
27230+ pax_force_retaddr
27231 ret
27232 CFI_ENDPROC
27233-ENDPROC(atomic64_\func\()_return_cx8)
27234+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27235 .endm
27236
27237 incdec_return inc add adc
27238 incdec_return dec sub sbb
27239+incdec_return inc add adc _unchecked
27240+incdec_return dec sub sbb _unchecked
27241
27242 ENTRY(atomic64_dec_if_positive_cx8)
27243 CFI_STARTPROC
27244@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27245 movl %edx, %ecx
27246 subl $1, %ebx
27247 sbb $0, %ecx
27248+
27249+#ifdef CONFIG_PAX_REFCOUNT
27250+ into
27251+1234:
27252+ _ASM_EXTABLE(1234b, 2f)
27253+#endif
27254+
27255 js 2f
27256 LOCK_PREFIX
27257 cmpxchg8b (%esi)
27258@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27259 movl %ebx, %eax
27260 movl %ecx, %edx
27261 RESTORE ebx
27262+ pax_force_retaddr
27263 ret
27264 CFI_ENDPROC
27265 ENDPROC(atomic64_dec_if_positive_cx8)
27266@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27267 movl %edx, %ecx
27268 addl %ebp, %ebx
27269 adcl %edi, %ecx
27270+
27271+#ifdef CONFIG_PAX_REFCOUNT
27272+ into
27273+1234:
27274+ _ASM_EXTABLE(1234b, 3f)
27275+#endif
27276+
27277 LOCK_PREFIX
27278 cmpxchg8b (%esi)
27279 jne 1b
27280@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27281 CFI_ADJUST_CFA_OFFSET -8
27282 RESTORE ebx
27283 RESTORE ebp
27284+ pax_force_retaddr
27285 ret
27286 4:
27287 cmpl %edx, 4(%esp)
27288@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27289 xorl %ecx, %ecx
27290 addl $1, %ebx
27291 adcl %edx, %ecx
27292+
27293+#ifdef CONFIG_PAX_REFCOUNT
27294+ into
27295+1234:
27296+ _ASM_EXTABLE(1234b, 3f)
27297+#endif
27298+
27299 LOCK_PREFIX
27300 cmpxchg8b (%esi)
27301 jne 1b
27302@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27303 movl $1, %eax
27304 3:
27305 RESTORE ebx
27306+ pax_force_retaddr
27307 ret
27308 CFI_ENDPROC
27309 ENDPROC(atomic64_inc_not_zero_cx8)
27310diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27311index e78b8ee..7e173a8 100644
27312--- a/arch/x86/lib/checksum_32.S
27313+++ b/arch/x86/lib/checksum_32.S
27314@@ -29,7 +29,8 @@
27315 #include <asm/dwarf2.h>
27316 #include <asm/errno.h>
27317 #include <asm/asm.h>
27318-
27319+#include <asm/segment.h>
27320+
27321 /*
27322 * computes a partial checksum, e.g. for TCP/UDP fragments
27323 */
27324@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27325
27326 #define ARGBASE 16
27327 #define FP 12
27328-
27329-ENTRY(csum_partial_copy_generic)
27330+
27331+ENTRY(csum_partial_copy_generic_to_user)
27332 CFI_STARTPROC
27333+
27334+#ifdef CONFIG_PAX_MEMORY_UDEREF
27335+ pushl_cfi %gs
27336+ popl_cfi %es
27337+ jmp csum_partial_copy_generic
27338+#endif
27339+
27340+ENTRY(csum_partial_copy_generic_from_user)
27341+
27342+#ifdef CONFIG_PAX_MEMORY_UDEREF
27343+ pushl_cfi %gs
27344+ popl_cfi %ds
27345+#endif
27346+
27347+ENTRY(csum_partial_copy_generic)
27348 subl $4,%esp
27349 CFI_ADJUST_CFA_OFFSET 4
27350 pushl_cfi %edi
27351@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27352 jmp 4f
27353 SRC(1: movw (%esi), %bx )
27354 addl $2, %esi
27355-DST( movw %bx, (%edi) )
27356+DST( movw %bx, %es:(%edi) )
27357 addl $2, %edi
27358 addw %bx, %ax
27359 adcl $0, %eax
27360@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27361 SRC(1: movl (%esi), %ebx )
27362 SRC( movl 4(%esi), %edx )
27363 adcl %ebx, %eax
27364-DST( movl %ebx, (%edi) )
27365+DST( movl %ebx, %es:(%edi) )
27366 adcl %edx, %eax
27367-DST( movl %edx, 4(%edi) )
27368+DST( movl %edx, %es:4(%edi) )
27369
27370 SRC( movl 8(%esi), %ebx )
27371 SRC( movl 12(%esi), %edx )
27372 adcl %ebx, %eax
27373-DST( movl %ebx, 8(%edi) )
27374+DST( movl %ebx, %es:8(%edi) )
27375 adcl %edx, %eax
27376-DST( movl %edx, 12(%edi) )
27377+DST( movl %edx, %es:12(%edi) )
27378
27379 SRC( movl 16(%esi), %ebx )
27380 SRC( movl 20(%esi), %edx )
27381 adcl %ebx, %eax
27382-DST( movl %ebx, 16(%edi) )
27383+DST( movl %ebx, %es:16(%edi) )
27384 adcl %edx, %eax
27385-DST( movl %edx, 20(%edi) )
27386+DST( movl %edx, %es:20(%edi) )
27387
27388 SRC( movl 24(%esi), %ebx )
27389 SRC( movl 28(%esi), %edx )
27390 adcl %ebx, %eax
27391-DST( movl %ebx, 24(%edi) )
27392+DST( movl %ebx, %es:24(%edi) )
27393 adcl %edx, %eax
27394-DST( movl %edx, 28(%edi) )
27395+DST( movl %edx, %es:28(%edi) )
27396
27397 lea 32(%esi), %esi
27398 lea 32(%edi), %edi
27399@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27400 shrl $2, %edx # This clears CF
27401 SRC(3: movl (%esi), %ebx )
27402 adcl %ebx, %eax
27403-DST( movl %ebx, (%edi) )
27404+DST( movl %ebx, %es:(%edi) )
27405 lea 4(%esi), %esi
27406 lea 4(%edi), %edi
27407 dec %edx
27408@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27409 jb 5f
27410 SRC( movw (%esi), %cx )
27411 leal 2(%esi), %esi
27412-DST( movw %cx, (%edi) )
27413+DST( movw %cx, %es:(%edi) )
27414 leal 2(%edi), %edi
27415 je 6f
27416 shll $16,%ecx
27417 SRC(5: movb (%esi), %cl )
27418-DST( movb %cl, (%edi) )
27419+DST( movb %cl, %es:(%edi) )
27420 6: addl %ecx, %eax
27421 adcl $0, %eax
27422 7:
27423@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27424
27425 6001:
27426 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27427- movl $-EFAULT, (%ebx)
27428+ movl $-EFAULT, %ss:(%ebx)
27429
27430 # zero the complete destination - computing the rest
27431 # is too much work
27432@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27433
27434 6002:
27435 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27436- movl $-EFAULT,(%ebx)
27437+ movl $-EFAULT,%ss:(%ebx)
27438 jmp 5000b
27439
27440 .previous
27441
27442+ pushl_cfi %ss
27443+ popl_cfi %ds
27444+ pushl_cfi %ss
27445+ popl_cfi %es
27446 popl_cfi %ebx
27447 CFI_RESTORE ebx
27448 popl_cfi %esi
27449@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27450 popl_cfi %ecx # equivalent to addl $4,%esp
27451 ret
27452 CFI_ENDPROC
27453-ENDPROC(csum_partial_copy_generic)
27454+ENDPROC(csum_partial_copy_generic_to_user)
27455
27456 #else
27457
27458 /* Version for PentiumII/PPro */
27459
27460 #define ROUND1(x) \
27461+ nop; nop; nop; \
27462 SRC(movl x(%esi), %ebx ) ; \
27463 addl %ebx, %eax ; \
27464- DST(movl %ebx, x(%edi) ) ;
27465+ DST(movl %ebx, %es:x(%edi)) ;
27466
27467 #define ROUND(x) \
27468+ nop; nop; nop; \
27469 SRC(movl x(%esi), %ebx ) ; \
27470 adcl %ebx, %eax ; \
27471- DST(movl %ebx, x(%edi) ) ;
27472+ DST(movl %ebx, %es:x(%edi)) ;
27473
27474 #define ARGBASE 12
27475-
27476-ENTRY(csum_partial_copy_generic)
27477+
27478+ENTRY(csum_partial_copy_generic_to_user)
27479 CFI_STARTPROC
27480+
27481+#ifdef CONFIG_PAX_MEMORY_UDEREF
27482+ pushl_cfi %gs
27483+ popl_cfi %es
27484+ jmp csum_partial_copy_generic
27485+#endif
27486+
27487+ENTRY(csum_partial_copy_generic_from_user)
27488+
27489+#ifdef CONFIG_PAX_MEMORY_UDEREF
27490+ pushl_cfi %gs
27491+ popl_cfi %ds
27492+#endif
27493+
27494+ENTRY(csum_partial_copy_generic)
27495 pushl_cfi %ebx
27496 CFI_REL_OFFSET ebx, 0
27497 pushl_cfi %edi
27498@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27499 subl %ebx, %edi
27500 lea -1(%esi),%edx
27501 andl $-32,%edx
27502- lea 3f(%ebx,%ebx), %ebx
27503+ lea 3f(%ebx,%ebx,2), %ebx
27504 testl %esi, %esi
27505 jmp *%ebx
27506 1: addl $64,%esi
27507@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27508 jb 5f
27509 SRC( movw (%esi), %dx )
27510 leal 2(%esi), %esi
27511-DST( movw %dx, (%edi) )
27512+DST( movw %dx, %es:(%edi) )
27513 leal 2(%edi), %edi
27514 je 6f
27515 shll $16,%edx
27516 5:
27517 SRC( movb (%esi), %dl )
27518-DST( movb %dl, (%edi) )
27519+DST( movb %dl, %es:(%edi) )
27520 6: addl %edx, %eax
27521 adcl $0, %eax
27522 7:
27523 .section .fixup, "ax"
27524 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27525- movl $-EFAULT, (%ebx)
27526+ movl $-EFAULT, %ss:(%ebx)
27527 # zero the complete destination (computing the rest is too much work)
27528 movl ARGBASE+8(%esp),%edi # dst
27529 movl ARGBASE+12(%esp),%ecx # len
27530@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27531 rep; stosb
27532 jmp 7b
27533 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27534- movl $-EFAULT, (%ebx)
27535+ movl $-EFAULT, %ss:(%ebx)
27536 jmp 7b
27537 .previous
27538
27539+#ifdef CONFIG_PAX_MEMORY_UDEREF
27540+ pushl_cfi %ss
27541+ popl_cfi %ds
27542+ pushl_cfi %ss
27543+ popl_cfi %es
27544+#endif
27545+
27546 popl_cfi %esi
27547 CFI_RESTORE esi
27548 popl_cfi %edi
27549@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27550 CFI_RESTORE ebx
27551 ret
27552 CFI_ENDPROC
27553-ENDPROC(csum_partial_copy_generic)
27554+ENDPROC(csum_partial_copy_generic_to_user)
27555
27556 #undef ROUND
27557 #undef ROUND1
27558diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27559index f2145cf..cea889d 100644
27560--- a/arch/x86/lib/clear_page_64.S
27561+++ b/arch/x86/lib/clear_page_64.S
27562@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27563 movl $4096/8,%ecx
27564 xorl %eax,%eax
27565 rep stosq
27566+ pax_force_retaddr
27567 ret
27568 CFI_ENDPROC
27569 ENDPROC(clear_page_c)
27570@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27571 movl $4096,%ecx
27572 xorl %eax,%eax
27573 rep stosb
27574+ pax_force_retaddr
27575 ret
27576 CFI_ENDPROC
27577 ENDPROC(clear_page_c_e)
27578@@ -43,6 +45,7 @@ ENTRY(clear_page)
27579 leaq 64(%rdi),%rdi
27580 jnz .Lloop
27581 nop
27582+ pax_force_retaddr
27583 ret
27584 CFI_ENDPROC
27585 .Lclear_page_end:
27586@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27587
27588 #include <asm/cpufeature.h>
27589
27590- .section .altinstr_replacement,"ax"
27591+ .section .altinstr_replacement,"a"
27592 1: .byte 0xeb /* jmp <disp8> */
27593 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27594 2: .byte 0xeb /* jmp <disp8> */
27595diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27596index 1e572c5..2a162cd 100644
27597--- a/arch/x86/lib/cmpxchg16b_emu.S
27598+++ b/arch/x86/lib/cmpxchg16b_emu.S
27599@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27600
27601 popf
27602 mov $1, %al
27603+ pax_force_retaddr
27604 ret
27605
27606 not_same:
27607 popf
27608 xor %al,%al
27609+ pax_force_retaddr
27610 ret
27611
27612 CFI_ENDPROC
27613diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27614index 176cca6..1166c50 100644
27615--- a/arch/x86/lib/copy_page_64.S
27616+++ b/arch/x86/lib/copy_page_64.S
27617@@ -9,6 +9,7 @@ copy_page_rep:
27618 CFI_STARTPROC
27619 movl $4096/8, %ecx
27620 rep movsq
27621+ pax_force_retaddr
27622 ret
27623 CFI_ENDPROC
27624 ENDPROC(copy_page_rep)
27625@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27626
27627 ENTRY(copy_page)
27628 CFI_STARTPROC
27629- subq $2*8, %rsp
27630- CFI_ADJUST_CFA_OFFSET 2*8
27631+ subq $3*8, %rsp
27632+ CFI_ADJUST_CFA_OFFSET 3*8
27633 movq %rbx, (%rsp)
27634 CFI_REL_OFFSET rbx, 0
27635 movq %r12, 1*8(%rsp)
27636 CFI_REL_OFFSET r12, 1*8
27637+ movq %r13, 2*8(%rsp)
27638+ CFI_REL_OFFSET r13, 2*8
27639
27640 movl $(4096/64)-5, %ecx
27641 .p2align 4
27642@@ -36,7 +39,7 @@ ENTRY(copy_page)
27643 movq 0x8*2(%rsi), %rdx
27644 movq 0x8*3(%rsi), %r8
27645 movq 0x8*4(%rsi), %r9
27646- movq 0x8*5(%rsi), %r10
27647+ movq 0x8*5(%rsi), %r13
27648 movq 0x8*6(%rsi), %r11
27649 movq 0x8*7(%rsi), %r12
27650
27651@@ -47,7 +50,7 @@ ENTRY(copy_page)
27652 movq %rdx, 0x8*2(%rdi)
27653 movq %r8, 0x8*3(%rdi)
27654 movq %r9, 0x8*4(%rdi)
27655- movq %r10, 0x8*5(%rdi)
27656+ movq %r13, 0x8*5(%rdi)
27657 movq %r11, 0x8*6(%rdi)
27658 movq %r12, 0x8*7(%rdi)
27659
27660@@ -66,7 +69,7 @@ ENTRY(copy_page)
27661 movq 0x8*2(%rsi), %rdx
27662 movq 0x8*3(%rsi), %r8
27663 movq 0x8*4(%rsi), %r9
27664- movq 0x8*5(%rsi), %r10
27665+ movq 0x8*5(%rsi), %r13
27666 movq 0x8*6(%rsi), %r11
27667 movq 0x8*7(%rsi), %r12
27668
27669@@ -75,7 +78,7 @@ ENTRY(copy_page)
27670 movq %rdx, 0x8*2(%rdi)
27671 movq %r8, 0x8*3(%rdi)
27672 movq %r9, 0x8*4(%rdi)
27673- movq %r10, 0x8*5(%rdi)
27674+ movq %r13, 0x8*5(%rdi)
27675 movq %r11, 0x8*6(%rdi)
27676 movq %r12, 0x8*7(%rdi)
27677
27678@@ -87,8 +90,11 @@ ENTRY(copy_page)
27679 CFI_RESTORE rbx
27680 movq 1*8(%rsp), %r12
27681 CFI_RESTORE r12
27682- addq $2*8, %rsp
27683- CFI_ADJUST_CFA_OFFSET -2*8
27684+ movq 2*8(%rsp), %r13
27685+ CFI_RESTORE r13
27686+ addq $3*8, %rsp
27687+ CFI_ADJUST_CFA_OFFSET -3*8
27688+ pax_force_retaddr
27689 ret
27690 .Lcopy_page_end:
27691 CFI_ENDPROC
27692@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27693
27694 #include <asm/cpufeature.h>
27695
27696- .section .altinstr_replacement,"ax"
27697+ .section .altinstr_replacement,"a"
27698 1: .byte 0xeb /* jmp <disp8> */
27699 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27700 2:
27701diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27702index a30ca15..6b3f4e1 100644
27703--- a/arch/x86/lib/copy_user_64.S
27704+++ b/arch/x86/lib/copy_user_64.S
27705@@ -18,31 +18,7 @@
27706 #include <asm/alternative-asm.h>
27707 #include <asm/asm.h>
27708 #include <asm/smap.h>
27709-
27710-/*
27711- * By placing feature2 after feature1 in altinstructions section, we logically
27712- * implement:
27713- * If CPU has feature2, jmp to alt2 is used
27714- * else if CPU has feature1, jmp to alt1 is used
27715- * else jmp to orig is used.
27716- */
27717- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27718-0:
27719- .byte 0xe9 /* 32bit jump */
27720- .long \orig-1f /* by default jump to orig */
27721-1:
27722- .section .altinstr_replacement,"ax"
27723-2: .byte 0xe9 /* near jump with 32bit immediate */
27724- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27725-3: .byte 0xe9 /* near jump with 32bit immediate */
27726- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27727- .previous
27728-
27729- .section .altinstructions,"a"
27730- altinstruction_entry 0b,2b,\feature1,5,5
27731- altinstruction_entry 0b,3b,\feature2,5,5
27732- .previous
27733- .endm
27734+#include <asm/pgtable.h>
27735
27736 .macro ALIGN_DESTINATION
27737 #ifdef FIX_ALIGNMENT
27738@@ -70,52 +46,6 @@
27739 #endif
27740 .endm
27741
27742-/* Standard copy_to_user with segment limit checking */
27743-ENTRY(_copy_to_user)
27744- CFI_STARTPROC
27745- GET_THREAD_INFO(%rax)
27746- movq %rdi,%rcx
27747- addq %rdx,%rcx
27748- jc bad_to_user
27749- cmpq TI_addr_limit(%rax),%rcx
27750- ja bad_to_user
27751- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27752- copy_user_generic_unrolled,copy_user_generic_string, \
27753- copy_user_enhanced_fast_string
27754- CFI_ENDPROC
27755-ENDPROC(_copy_to_user)
27756-
27757-/* Standard copy_from_user with segment limit checking */
27758-ENTRY(_copy_from_user)
27759- CFI_STARTPROC
27760- GET_THREAD_INFO(%rax)
27761- movq %rsi,%rcx
27762- addq %rdx,%rcx
27763- jc bad_from_user
27764- cmpq TI_addr_limit(%rax),%rcx
27765- ja bad_from_user
27766- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27767- copy_user_generic_unrolled,copy_user_generic_string, \
27768- copy_user_enhanced_fast_string
27769- CFI_ENDPROC
27770-ENDPROC(_copy_from_user)
27771-
27772- .section .fixup,"ax"
27773- /* must zero dest */
27774-ENTRY(bad_from_user)
27775-bad_from_user:
27776- CFI_STARTPROC
27777- movl %edx,%ecx
27778- xorl %eax,%eax
27779- rep
27780- stosb
27781-bad_to_user:
27782- movl %edx,%eax
27783- ret
27784- CFI_ENDPROC
27785-ENDPROC(bad_from_user)
27786- .previous
27787-
27788 /*
27789 * copy_user_generic_unrolled - memory copy with exception handling.
27790 * This version is for CPUs like P4 that don't have efficient micro
27791@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27792 */
27793 ENTRY(copy_user_generic_unrolled)
27794 CFI_STARTPROC
27795+ ASM_PAX_OPEN_USERLAND
27796 ASM_STAC
27797 cmpl $8,%edx
27798 jb 20f /* less then 8 bytes, go to byte copy loop */
27799@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27800 jz 17f
27801 1: movq (%rsi),%r8
27802 2: movq 1*8(%rsi),%r9
27803-3: movq 2*8(%rsi),%r10
27804+3: movq 2*8(%rsi),%rax
27805 4: movq 3*8(%rsi),%r11
27806 5: movq %r8,(%rdi)
27807 6: movq %r9,1*8(%rdi)
27808-7: movq %r10,2*8(%rdi)
27809+7: movq %rax,2*8(%rdi)
27810 8: movq %r11,3*8(%rdi)
27811 9: movq 4*8(%rsi),%r8
27812 10: movq 5*8(%rsi),%r9
27813-11: movq 6*8(%rsi),%r10
27814+11: movq 6*8(%rsi),%rax
27815 12: movq 7*8(%rsi),%r11
27816 13: movq %r8,4*8(%rdi)
27817 14: movq %r9,5*8(%rdi)
27818-15: movq %r10,6*8(%rdi)
27819+15: movq %rax,6*8(%rdi)
27820 16: movq %r11,7*8(%rdi)
27821 leaq 64(%rsi),%rsi
27822 leaq 64(%rdi),%rdi
27823@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27824 jnz 21b
27825 23: xor %eax,%eax
27826 ASM_CLAC
27827+ ASM_PAX_CLOSE_USERLAND
27828+ pax_force_retaddr
27829 ret
27830
27831 .section .fixup,"ax"
27832@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27833 */
27834 ENTRY(copy_user_generic_string)
27835 CFI_STARTPROC
27836+ ASM_PAX_OPEN_USERLAND
27837 ASM_STAC
27838 andl %edx,%edx
27839 jz 4f
27840@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27841 movsb
27842 4: xorl %eax,%eax
27843 ASM_CLAC
27844+ ASM_PAX_CLOSE_USERLAND
27845+ pax_force_retaddr
27846 ret
27847
27848 .section .fixup,"ax"
27849@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27850 */
27851 ENTRY(copy_user_enhanced_fast_string)
27852 CFI_STARTPROC
27853+ ASM_PAX_OPEN_USERLAND
27854 ASM_STAC
27855 andl %edx,%edx
27856 jz 2f
27857@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27858 movsb
27859 2: xorl %eax,%eax
27860 ASM_CLAC
27861+ ASM_PAX_CLOSE_USERLAND
27862+ pax_force_retaddr
27863 ret
27864
27865 .section .fixup,"ax"
27866diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27867index 6a4f43c..55d26f2 100644
27868--- a/arch/x86/lib/copy_user_nocache_64.S
27869+++ b/arch/x86/lib/copy_user_nocache_64.S
27870@@ -8,6 +8,7 @@
27871
27872 #include <linux/linkage.h>
27873 #include <asm/dwarf2.h>
27874+#include <asm/alternative-asm.h>
27875
27876 #define FIX_ALIGNMENT 1
27877
27878@@ -16,6 +17,7 @@
27879 #include <asm/thread_info.h>
27880 #include <asm/asm.h>
27881 #include <asm/smap.h>
27882+#include <asm/pgtable.h>
27883
27884 .macro ALIGN_DESTINATION
27885 #ifdef FIX_ALIGNMENT
27886@@ -49,6 +51,16 @@
27887 */
27888 ENTRY(__copy_user_nocache)
27889 CFI_STARTPROC
27890+
27891+#ifdef CONFIG_PAX_MEMORY_UDEREF
27892+ mov pax_user_shadow_base,%rcx
27893+ cmp %rcx,%rsi
27894+ jae 1f
27895+ add %rcx,%rsi
27896+1:
27897+#endif
27898+
27899+ ASM_PAX_OPEN_USERLAND
27900 ASM_STAC
27901 cmpl $8,%edx
27902 jb 20f /* less then 8 bytes, go to byte copy loop */
27903@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27904 jz 17f
27905 1: movq (%rsi),%r8
27906 2: movq 1*8(%rsi),%r9
27907-3: movq 2*8(%rsi),%r10
27908+3: movq 2*8(%rsi),%rax
27909 4: movq 3*8(%rsi),%r11
27910 5: movnti %r8,(%rdi)
27911 6: movnti %r9,1*8(%rdi)
27912-7: movnti %r10,2*8(%rdi)
27913+7: movnti %rax,2*8(%rdi)
27914 8: movnti %r11,3*8(%rdi)
27915 9: movq 4*8(%rsi),%r8
27916 10: movq 5*8(%rsi),%r9
27917-11: movq 6*8(%rsi),%r10
27918+11: movq 6*8(%rsi),%rax
27919 12: movq 7*8(%rsi),%r11
27920 13: movnti %r8,4*8(%rdi)
27921 14: movnti %r9,5*8(%rdi)
27922-15: movnti %r10,6*8(%rdi)
27923+15: movnti %rax,6*8(%rdi)
27924 16: movnti %r11,7*8(%rdi)
27925 leaq 64(%rsi),%rsi
27926 leaq 64(%rdi),%rdi
27927@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27928 jnz 21b
27929 23: xorl %eax,%eax
27930 ASM_CLAC
27931+ ASM_PAX_CLOSE_USERLAND
27932 sfence
27933+ pax_force_retaddr
27934 ret
27935
27936 .section .fixup,"ax"
27937diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27938index 2419d5f..953ee51 100644
27939--- a/arch/x86/lib/csum-copy_64.S
27940+++ b/arch/x86/lib/csum-copy_64.S
27941@@ -9,6 +9,7 @@
27942 #include <asm/dwarf2.h>
27943 #include <asm/errno.h>
27944 #include <asm/asm.h>
27945+#include <asm/alternative-asm.h>
27946
27947 /*
27948 * Checksum copy with exception handling.
27949@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27950 CFI_RESTORE rbp
27951 addq $7*8, %rsp
27952 CFI_ADJUST_CFA_OFFSET -7*8
27953+ pax_force_retaddr 0, 1
27954 ret
27955 CFI_RESTORE_STATE
27956
27957diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27958index 7609e0e..b449b98 100644
27959--- a/arch/x86/lib/csum-wrappers_64.c
27960+++ b/arch/x86/lib/csum-wrappers_64.c
27961@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27962 len -= 2;
27963 }
27964 }
27965+ pax_open_userland();
27966 stac();
27967- isum = csum_partial_copy_generic((__force const void *)src,
27968+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27969 dst, len, isum, errp, NULL);
27970 clac();
27971+ pax_close_userland();
27972 if (unlikely(*errp))
27973 goto out_err;
27974
27975@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27976 }
27977
27978 *errp = 0;
27979+ pax_open_userland();
27980 stac();
27981- ret = csum_partial_copy_generic(src, (void __force *)dst,
27982+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27983 len, isum, NULL, errp);
27984 clac();
27985+ pax_close_userland();
27986 return ret;
27987 }
27988 EXPORT_SYMBOL(csum_partial_copy_to_user);
27989diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27990index a451235..1daa956 100644
27991--- a/arch/x86/lib/getuser.S
27992+++ b/arch/x86/lib/getuser.S
27993@@ -33,17 +33,40 @@
27994 #include <asm/thread_info.h>
27995 #include <asm/asm.h>
27996 #include <asm/smap.h>
27997+#include <asm/segment.h>
27998+#include <asm/pgtable.h>
27999+#include <asm/alternative-asm.h>
28000+
28001+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28002+#define __copyuser_seg gs;
28003+#else
28004+#define __copyuser_seg
28005+#endif
28006
28007 .text
28008 ENTRY(__get_user_1)
28009 CFI_STARTPROC
28010+
28011+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28012 GET_THREAD_INFO(%_ASM_DX)
28013 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28014 jae bad_get_user
28015 ASM_STAC
28016-1: movzbl (%_ASM_AX),%edx
28017+
28018+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28019+ mov pax_user_shadow_base,%_ASM_DX
28020+ cmp %_ASM_DX,%_ASM_AX
28021+ jae 1234f
28022+ add %_ASM_DX,%_ASM_AX
28023+1234:
28024+#endif
28025+
28026+#endif
28027+
28028+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28029 xor %eax,%eax
28030 ASM_CLAC
28031+ pax_force_retaddr
28032 ret
28033 CFI_ENDPROC
28034 ENDPROC(__get_user_1)
28035@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28036 ENTRY(__get_user_2)
28037 CFI_STARTPROC
28038 add $1,%_ASM_AX
28039+
28040+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28041 jc bad_get_user
28042 GET_THREAD_INFO(%_ASM_DX)
28043 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28044 jae bad_get_user
28045 ASM_STAC
28046-2: movzwl -1(%_ASM_AX),%edx
28047+
28048+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28049+ mov pax_user_shadow_base,%_ASM_DX
28050+ cmp %_ASM_DX,%_ASM_AX
28051+ jae 1234f
28052+ add %_ASM_DX,%_ASM_AX
28053+1234:
28054+#endif
28055+
28056+#endif
28057+
28058+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28059 xor %eax,%eax
28060 ASM_CLAC
28061+ pax_force_retaddr
28062 ret
28063 CFI_ENDPROC
28064 ENDPROC(__get_user_2)
28065@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28066 ENTRY(__get_user_4)
28067 CFI_STARTPROC
28068 add $3,%_ASM_AX
28069+
28070+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28071 jc bad_get_user
28072 GET_THREAD_INFO(%_ASM_DX)
28073 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28074 jae bad_get_user
28075 ASM_STAC
28076-3: movl -3(%_ASM_AX),%edx
28077+
28078+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28079+ mov pax_user_shadow_base,%_ASM_DX
28080+ cmp %_ASM_DX,%_ASM_AX
28081+ jae 1234f
28082+ add %_ASM_DX,%_ASM_AX
28083+1234:
28084+#endif
28085+
28086+#endif
28087+
28088+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28089 xor %eax,%eax
28090 ASM_CLAC
28091+ pax_force_retaddr
28092 ret
28093 CFI_ENDPROC
28094 ENDPROC(__get_user_4)
28095@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28096 GET_THREAD_INFO(%_ASM_DX)
28097 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28098 jae bad_get_user
28099+
28100+#ifdef CONFIG_PAX_MEMORY_UDEREF
28101+ mov pax_user_shadow_base,%_ASM_DX
28102+ cmp %_ASM_DX,%_ASM_AX
28103+ jae 1234f
28104+ add %_ASM_DX,%_ASM_AX
28105+1234:
28106+#endif
28107+
28108 ASM_STAC
28109 4: movq -7(%_ASM_AX),%rdx
28110 xor %eax,%eax
28111 ASM_CLAC
28112+ pax_force_retaddr
28113 ret
28114 #else
28115 add $7,%_ASM_AX
28116@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28117 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28118 jae bad_get_user_8
28119 ASM_STAC
28120-4: movl -7(%_ASM_AX),%edx
28121-5: movl -3(%_ASM_AX),%ecx
28122+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28123+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28124 xor %eax,%eax
28125 ASM_CLAC
28126+ pax_force_retaddr
28127 ret
28128 #endif
28129 CFI_ENDPROC
28130@@ -113,6 +175,7 @@ bad_get_user:
28131 xor %edx,%edx
28132 mov $(-EFAULT),%_ASM_AX
28133 ASM_CLAC
28134+ pax_force_retaddr
28135 ret
28136 CFI_ENDPROC
28137 END(bad_get_user)
28138@@ -124,6 +187,7 @@ bad_get_user_8:
28139 xor %ecx,%ecx
28140 mov $(-EFAULT),%_ASM_AX
28141 ASM_CLAC
28142+ pax_force_retaddr
28143 ret
28144 CFI_ENDPROC
28145 END(bad_get_user_8)
28146diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28147index 54fcffe..7be149e 100644
28148--- a/arch/x86/lib/insn.c
28149+++ b/arch/x86/lib/insn.c
28150@@ -20,8 +20,10 @@
28151
28152 #ifdef __KERNEL__
28153 #include <linux/string.h>
28154+#include <asm/pgtable_types.h>
28155 #else
28156 #include <string.h>
28157+#define ktla_ktva(addr) addr
28158 #endif
28159 #include <asm/inat.h>
28160 #include <asm/insn.h>
28161@@ -53,8 +55,8 @@
28162 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28163 {
28164 memset(insn, 0, sizeof(*insn));
28165- insn->kaddr = kaddr;
28166- insn->next_byte = kaddr;
28167+ insn->kaddr = ktla_ktva(kaddr);
28168+ insn->next_byte = ktla_ktva(kaddr);
28169 insn->x86_64 = x86_64 ? 1 : 0;
28170 insn->opnd_bytes = 4;
28171 if (x86_64)
28172diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28173index 05a95e7..326f2fa 100644
28174--- a/arch/x86/lib/iomap_copy_64.S
28175+++ b/arch/x86/lib/iomap_copy_64.S
28176@@ -17,6 +17,7 @@
28177
28178 #include <linux/linkage.h>
28179 #include <asm/dwarf2.h>
28180+#include <asm/alternative-asm.h>
28181
28182 /*
28183 * override generic version in lib/iomap_copy.c
28184@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28185 CFI_STARTPROC
28186 movl %edx,%ecx
28187 rep movsd
28188+ pax_force_retaddr
28189 ret
28190 CFI_ENDPROC
28191 ENDPROC(__iowrite32_copy)
28192diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28193index 56313a3..9b59269 100644
28194--- a/arch/x86/lib/memcpy_64.S
28195+++ b/arch/x86/lib/memcpy_64.S
28196@@ -24,7 +24,7 @@
28197 * This gets patched over the unrolled variant (below) via the
28198 * alternative instructions framework:
28199 */
28200- .section .altinstr_replacement, "ax", @progbits
28201+ .section .altinstr_replacement, "a", @progbits
28202 .Lmemcpy_c:
28203 movq %rdi, %rax
28204 movq %rdx, %rcx
28205@@ -33,6 +33,7 @@
28206 rep movsq
28207 movl %edx, %ecx
28208 rep movsb
28209+ pax_force_retaddr
28210 ret
28211 .Lmemcpy_e:
28212 .previous
28213@@ -44,11 +45,12 @@
28214 * This gets patched over the unrolled variant (below) via the
28215 * alternative instructions framework:
28216 */
28217- .section .altinstr_replacement, "ax", @progbits
28218+ .section .altinstr_replacement, "a", @progbits
28219 .Lmemcpy_c_e:
28220 movq %rdi, %rax
28221 movq %rdx, %rcx
28222 rep movsb
28223+ pax_force_retaddr
28224 ret
28225 .Lmemcpy_e_e:
28226 .previous
28227@@ -76,13 +78,13 @@ ENTRY(memcpy)
28228 */
28229 movq 0*8(%rsi), %r8
28230 movq 1*8(%rsi), %r9
28231- movq 2*8(%rsi), %r10
28232+ movq 2*8(%rsi), %rcx
28233 movq 3*8(%rsi), %r11
28234 leaq 4*8(%rsi), %rsi
28235
28236 movq %r8, 0*8(%rdi)
28237 movq %r9, 1*8(%rdi)
28238- movq %r10, 2*8(%rdi)
28239+ movq %rcx, 2*8(%rdi)
28240 movq %r11, 3*8(%rdi)
28241 leaq 4*8(%rdi), %rdi
28242 jae .Lcopy_forward_loop
28243@@ -105,12 +107,12 @@ ENTRY(memcpy)
28244 subq $0x20, %rdx
28245 movq -1*8(%rsi), %r8
28246 movq -2*8(%rsi), %r9
28247- movq -3*8(%rsi), %r10
28248+ movq -3*8(%rsi), %rcx
28249 movq -4*8(%rsi), %r11
28250 leaq -4*8(%rsi), %rsi
28251 movq %r8, -1*8(%rdi)
28252 movq %r9, -2*8(%rdi)
28253- movq %r10, -3*8(%rdi)
28254+ movq %rcx, -3*8(%rdi)
28255 movq %r11, -4*8(%rdi)
28256 leaq -4*8(%rdi), %rdi
28257 jae .Lcopy_backward_loop
28258@@ -130,12 +132,13 @@ ENTRY(memcpy)
28259 */
28260 movq 0*8(%rsi), %r8
28261 movq 1*8(%rsi), %r9
28262- movq -2*8(%rsi, %rdx), %r10
28263+ movq -2*8(%rsi, %rdx), %rcx
28264 movq -1*8(%rsi, %rdx), %r11
28265 movq %r8, 0*8(%rdi)
28266 movq %r9, 1*8(%rdi)
28267- movq %r10, -2*8(%rdi, %rdx)
28268+ movq %rcx, -2*8(%rdi, %rdx)
28269 movq %r11, -1*8(%rdi, %rdx)
28270+ pax_force_retaddr
28271 retq
28272 .p2align 4
28273 .Lless_16bytes:
28274@@ -148,6 +151,7 @@ ENTRY(memcpy)
28275 movq -1*8(%rsi, %rdx), %r9
28276 movq %r8, 0*8(%rdi)
28277 movq %r9, -1*8(%rdi, %rdx)
28278+ pax_force_retaddr
28279 retq
28280 .p2align 4
28281 .Lless_8bytes:
28282@@ -161,6 +165,7 @@ ENTRY(memcpy)
28283 movl -4(%rsi, %rdx), %r8d
28284 movl %ecx, (%rdi)
28285 movl %r8d, -4(%rdi, %rdx)
28286+ pax_force_retaddr
28287 retq
28288 .p2align 4
28289 .Lless_3bytes:
28290@@ -179,6 +184,7 @@ ENTRY(memcpy)
28291 movb %cl, (%rdi)
28292
28293 .Lend:
28294+ pax_force_retaddr
28295 retq
28296 CFI_ENDPROC
28297 ENDPROC(memcpy)
28298diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28299index 65268a6..5aa7815 100644
28300--- a/arch/x86/lib/memmove_64.S
28301+++ b/arch/x86/lib/memmove_64.S
28302@@ -61,13 +61,13 @@ ENTRY(memmove)
28303 5:
28304 sub $0x20, %rdx
28305 movq 0*8(%rsi), %r11
28306- movq 1*8(%rsi), %r10
28307+ movq 1*8(%rsi), %rcx
28308 movq 2*8(%rsi), %r9
28309 movq 3*8(%rsi), %r8
28310 leaq 4*8(%rsi), %rsi
28311
28312 movq %r11, 0*8(%rdi)
28313- movq %r10, 1*8(%rdi)
28314+ movq %rcx, 1*8(%rdi)
28315 movq %r9, 2*8(%rdi)
28316 movq %r8, 3*8(%rdi)
28317 leaq 4*8(%rdi), %rdi
28318@@ -81,10 +81,10 @@ ENTRY(memmove)
28319 4:
28320 movq %rdx, %rcx
28321 movq -8(%rsi, %rdx), %r11
28322- lea -8(%rdi, %rdx), %r10
28323+ lea -8(%rdi, %rdx), %r9
28324 shrq $3, %rcx
28325 rep movsq
28326- movq %r11, (%r10)
28327+ movq %r11, (%r9)
28328 jmp 13f
28329 .Lmemmove_end_forward:
28330
28331@@ -95,14 +95,14 @@ ENTRY(memmove)
28332 7:
28333 movq %rdx, %rcx
28334 movq (%rsi), %r11
28335- movq %rdi, %r10
28336+ movq %rdi, %r9
28337 leaq -8(%rsi, %rdx), %rsi
28338 leaq -8(%rdi, %rdx), %rdi
28339 shrq $3, %rcx
28340 std
28341 rep movsq
28342 cld
28343- movq %r11, (%r10)
28344+ movq %r11, (%r9)
28345 jmp 13f
28346
28347 /*
28348@@ -127,13 +127,13 @@ ENTRY(memmove)
28349 8:
28350 subq $0x20, %rdx
28351 movq -1*8(%rsi), %r11
28352- movq -2*8(%rsi), %r10
28353+ movq -2*8(%rsi), %rcx
28354 movq -3*8(%rsi), %r9
28355 movq -4*8(%rsi), %r8
28356 leaq -4*8(%rsi), %rsi
28357
28358 movq %r11, -1*8(%rdi)
28359- movq %r10, -2*8(%rdi)
28360+ movq %rcx, -2*8(%rdi)
28361 movq %r9, -3*8(%rdi)
28362 movq %r8, -4*8(%rdi)
28363 leaq -4*8(%rdi), %rdi
28364@@ -151,11 +151,11 @@ ENTRY(memmove)
28365 * Move data from 16 bytes to 31 bytes.
28366 */
28367 movq 0*8(%rsi), %r11
28368- movq 1*8(%rsi), %r10
28369+ movq 1*8(%rsi), %rcx
28370 movq -2*8(%rsi, %rdx), %r9
28371 movq -1*8(%rsi, %rdx), %r8
28372 movq %r11, 0*8(%rdi)
28373- movq %r10, 1*8(%rdi)
28374+ movq %rcx, 1*8(%rdi)
28375 movq %r9, -2*8(%rdi, %rdx)
28376 movq %r8, -1*8(%rdi, %rdx)
28377 jmp 13f
28378@@ -167,9 +167,9 @@ ENTRY(memmove)
28379 * Move data from 8 bytes to 15 bytes.
28380 */
28381 movq 0*8(%rsi), %r11
28382- movq -1*8(%rsi, %rdx), %r10
28383+ movq -1*8(%rsi, %rdx), %r9
28384 movq %r11, 0*8(%rdi)
28385- movq %r10, -1*8(%rdi, %rdx)
28386+ movq %r9, -1*8(%rdi, %rdx)
28387 jmp 13f
28388 10:
28389 cmpq $4, %rdx
28390@@ -178,9 +178,9 @@ ENTRY(memmove)
28391 * Move data from 4 bytes to 7 bytes.
28392 */
28393 movl (%rsi), %r11d
28394- movl -4(%rsi, %rdx), %r10d
28395+ movl -4(%rsi, %rdx), %r9d
28396 movl %r11d, (%rdi)
28397- movl %r10d, -4(%rdi, %rdx)
28398+ movl %r9d, -4(%rdi, %rdx)
28399 jmp 13f
28400 11:
28401 cmp $2, %rdx
28402@@ -189,9 +189,9 @@ ENTRY(memmove)
28403 * Move data from 2 bytes to 3 bytes.
28404 */
28405 movw (%rsi), %r11w
28406- movw -2(%rsi, %rdx), %r10w
28407+ movw -2(%rsi, %rdx), %r9w
28408 movw %r11w, (%rdi)
28409- movw %r10w, -2(%rdi, %rdx)
28410+ movw %r9w, -2(%rdi, %rdx)
28411 jmp 13f
28412 12:
28413 cmp $1, %rdx
28414@@ -202,14 +202,16 @@ ENTRY(memmove)
28415 movb (%rsi), %r11b
28416 movb %r11b, (%rdi)
28417 13:
28418+ pax_force_retaddr
28419 retq
28420 CFI_ENDPROC
28421
28422- .section .altinstr_replacement,"ax"
28423+ .section .altinstr_replacement,"a"
28424 .Lmemmove_begin_forward_efs:
28425 /* Forward moving data. */
28426 movq %rdx, %rcx
28427 rep movsb
28428+ pax_force_retaddr
28429 retq
28430 .Lmemmove_end_forward_efs:
28431 .previous
28432diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28433index 2dcb380..50a78bc 100644
28434--- a/arch/x86/lib/memset_64.S
28435+++ b/arch/x86/lib/memset_64.S
28436@@ -16,7 +16,7 @@
28437 *
28438 * rax original destination
28439 */
28440- .section .altinstr_replacement, "ax", @progbits
28441+ .section .altinstr_replacement, "a", @progbits
28442 .Lmemset_c:
28443 movq %rdi,%r9
28444 movq %rdx,%rcx
28445@@ -30,6 +30,7 @@
28446 movl %edx,%ecx
28447 rep stosb
28448 movq %r9,%rax
28449+ pax_force_retaddr
28450 ret
28451 .Lmemset_e:
28452 .previous
28453@@ -45,13 +46,14 @@
28454 *
28455 * rax original destination
28456 */
28457- .section .altinstr_replacement, "ax", @progbits
28458+ .section .altinstr_replacement, "a", @progbits
28459 .Lmemset_c_e:
28460 movq %rdi,%r9
28461 movb %sil,%al
28462 movq %rdx,%rcx
28463 rep stosb
28464 movq %r9,%rax
28465+ pax_force_retaddr
28466 ret
28467 .Lmemset_e_e:
28468 .previous
28469@@ -59,7 +61,7 @@
28470 ENTRY(memset)
28471 ENTRY(__memset)
28472 CFI_STARTPROC
28473- movq %rdi,%r10
28474+ movq %rdi,%r11
28475
28476 /* expand byte value */
28477 movzbl %sil,%ecx
28478@@ -117,7 +119,8 @@ ENTRY(__memset)
28479 jnz .Lloop_1
28480
28481 .Lende:
28482- movq %r10,%rax
28483+ movq %r11,%rax
28484+ pax_force_retaddr
28485 ret
28486
28487 CFI_RESTORE_STATE
28488diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28489index c9f2d9b..e7fd2c0 100644
28490--- a/arch/x86/lib/mmx_32.c
28491+++ b/arch/x86/lib/mmx_32.c
28492@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28493 {
28494 void *p;
28495 int i;
28496+ unsigned long cr0;
28497
28498 if (unlikely(in_interrupt()))
28499 return __memcpy(to, from, len);
28500@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28501 kernel_fpu_begin();
28502
28503 __asm__ __volatile__ (
28504- "1: prefetch (%0)\n" /* This set is 28 bytes */
28505- " prefetch 64(%0)\n"
28506- " prefetch 128(%0)\n"
28507- " prefetch 192(%0)\n"
28508- " prefetch 256(%0)\n"
28509+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28510+ " prefetch 64(%1)\n"
28511+ " prefetch 128(%1)\n"
28512+ " prefetch 192(%1)\n"
28513+ " prefetch 256(%1)\n"
28514 "2: \n"
28515 ".section .fixup, \"ax\"\n"
28516- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28517+ "3: \n"
28518+
28519+#ifdef CONFIG_PAX_KERNEXEC
28520+ " movl %%cr0, %0\n"
28521+ " movl %0, %%eax\n"
28522+ " andl $0xFFFEFFFF, %%eax\n"
28523+ " movl %%eax, %%cr0\n"
28524+#endif
28525+
28526+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28527+
28528+#ifdef CONFIG_PAX_KERNEXEC
28529+ " movl %0, %%cr0\n"
28530+#endif
28531+
28532 " jmp 2b\n"
28533 ".previous\n"
28534 _ASM_EXTABLE(1b, 3b)
28535- : : "r" (from));
28536+ : "=&r" (cr0) : "r" (from) : "ax");
28537
28538 for ( ; i > 5; i--) {
28539 __asm__ __volatile__ (
28540- "1: prefetch 320(%0)\n"
28541- "2: movq (%0), %%mm0\n"
28542- " movq 8(%0), %%mm1\n"
28543- " movq 16(%0), %%mm2\n"
28544- " movq 24(%0), %%mm3\n"
28545- " movq %%mm0, (%1)\n"
28546- " movq %%mm1, 8(%1)\n"
28547- " movq %%mm2, 16(%1)\n"
28548- " movq %%mm3, 24(%1)\n"
28549- " movq 32(%0), %%mm0\n"
28550- " movq 40(%0), %%mm1\n"
28551- " movq 48(%0), %%mm2\n"
28552- " movq 56(%0), %%mm3\n"
28553- " movq %%mm0, 32(%1)\n"
28554- " movq %%mm1, 40(%1)\n"
28555- " movq %%mm2, 48(%1)\n"
28556- " movq %%mm3, 56(%1)\n"
28557+ "1: prefetch 320(%1)\n"
28558+ "2: movq (%1), %%mm0\n"
28559+ " movq 8(%1), %%mm1\n"
28560+ " movq 16(%1), %%mm2\n"
28561+ " movq 24(%1), %%mm3\n"
28562+ " movq %%mm0, (%2)\n"
28563+ " movq %%mm1, 8(%2)\n"
28564+ " movq %%mm2, 16(%2)\n"
28565+ " movq %%mm3, 24(%2)\n"
28566+ " movq 32(%1), %%mm0\n"
28567+ " movq 40(%1), %%mm1\n"
28568+ " movq 48(%1), %%mm2\n"
28569+ " movq 56(%1), %%mm3\n"
28570+ " movq %%mm0, 32(%2)\n"
28571+ " movq %%mm1, 40(%2)\n"
28572+ " movq %%mm2, 48(%2)\n"
28573+ " movq %%mm3, 56(%2)\n"
28574 ".section .fixup, \"ax\"\n"
28575- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28576+ "3:\n"
28577+
28578+#ifdef CONFIG_PAX_KERNEXEC
28579+ " movl %%cr0, %0\n"
28580+ " movl %0, %%eax\n"
28581+ " andl $0xFFFEFFFF, %%eax\n"
28582+ " movl %%eax, %%cr0\n"
28583+#endif
28584+
28585+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28586+
28587+#ifdef CONFIG_PAX_KERNEXEC
28588+ " movl %0, %%cr0\n"
28589+#endif
28590+
28591 " jmp 2b\n"
28592 ".previous\n"
28593 _ASM_EXTABLE(1b, 3b)
28594- : : "r" (from), "r" (to) : "memory");
28595+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28596
28597 from += 64;
28598 to += 64;
28599@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28600 static void fast_copy_page(void *to, void *from)
28601 {
28602 int i;
28603+ unsigned long cr0;
28604
28605 kernel_fpu_begin();
28606
28607@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28608 * but that is for later. -AV
28609 */
28610 __asm__ __volatile__(
28611- "1: prefetch (%0)\n"
28612- " prefetch 64(%0)\n"
28613- " prefetch 128(%0)\n"
28614- " prefetch 192(%0)\n"
28615- " prefetch 256(%0)\n"
28616+ "1: prefetch (%1)\n"
28617+ " prefetch 64(%1)\n"
28618+ " prefetch 128(%1)\n"
28619+ " prefetch 192(%1)\n"
28620+ " prefetch 256(%1)\n"
28621 "2: \n"
28622 ".section .fixup, \"ax\"\n"
28623- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28624+ "3: \n"
28625+
28626+#ifdef CONFIG_PAX_KERNEXEC
28627+ " movl %%cr0, %0\n"
28628+ " movl %0, %%eax\n"
28629+ " andl $0xFFFEFFFF, %%eax\n"
28630+ " movl %%eax, %%cr0\n"
28631+#endif
28632+
28633+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28634+
28635+#ifdef CONFIG_PAX_KERNEXEC
28636+ " movl %0, %%cr0\n"
28637+#endif
28638+
28639 " jmp 2b\n"
28640 ".previous\n"
28641- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28642+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28643
28644 for (i = 0; i < (4096-320)/64; i++) {
28645 __asm__ __volatile__ (
28646- "1: prefetch 320(%0)\n"
28647- "2: movq (%0), %%mm0\n"
28648- " movntq %%mm0, (%1)\n"
28649- " movq 8(%0), %%mm1\n"
28650- " movntq %%mm1, 8(%1)\n"
28651- " movq 16(%0), %%mm2\n"
28652- " movntq %%mm2, 16(%1)\n"
28653- " movq 24(%0), %%mm3\n"
28654- " movntq %%mm3, 24(%1)\n"
28655- " movq 32(%0), %%mm4\n"
28656- " movntq %%mm4, 32(%1)\n"
28657- " movq 40(%0), %%mm5\n"
28658- " movntq %%mm5, 40(%1)\n"
28659- " movq 48(%0), %%mm6\n"
28660- " movntq %%mm6, 48(%1)\n"
28661- " movq 56(%0), %%mm7\n"
28662- " movntq %%mm7, 56(%1)\n"
28663+ "1: prefetch 320(%1)\n"
28664+ "2: movq (%1), %%mm0\n"
28665+ " movntq %%mm0, (%2)\n"
28666+ " movq 8(%1), %%mm1\n"
28667+ " movntq %%mm1, 8(%2)\n"
28668+ " movq 16(%1), %%mm2\n"
28669+ " movntq %%mm2, 16(%2)\n"
28670+ " movq 24(%1), %%mm3\n"
28671+ " movntq %%mm3, 24(%2)\n"
28672+ " movq 32(%1), %%mm4\n"
28673+ " movntq %%mm4, 32(%2)\n"
28674+ " movq 40(%1), %%mm5\n"
28675+ " movntq %%mm5, 40(%2)\n"
28676+ " movq 48(%1), %%mm6\n"
28677+ " movntq %%mm6, 48(%2)\n"
28678+ " movq 56(%1), %%mm7\n"
28679+ " movntq %%mm7, 56(%2)\n"
28680 ".section .fixup, \"ax\"\n"
28681- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28682+ "3:\n"
28683+
28684+#ifdef CONFIG_PAX_KERNEXEC
28685+ " movl %%cr0, %0\n"
28686+ " movl %0, %%eax\n"
28687+ " andl $0xFFFEFFFF, %%eax\n"
28688+ " movl %%eax, %%cr0\n"
28689+#endif
28690+
28691+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28692+
28693+#ifdef CONFIG_PAX_KERNEXEC
28694+ " movl %0, %%cr0\n"
28695+#endif
28696+
28697 " jmp 2b\n"
28698 ".previous\n"
28699- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28700+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28701
28702 from += 64;
28703 to += 64;
28704@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28705 static void fast_copy_page(void *to, void *from)
28706 {
28707 int i;
28708+ unsigned long cr0;
28709
28710 kernel_fpu_begin();
28711
28712 __asm__ __volatile__ (
28713- "1: prefetch (%0)\n"
28714- " prefetch 64(%0)\n"
28715- " prefetch 128(%0)\n"
28716- " prefetch 192(%0)\n"
28717- " prefetch 256(%0)\n"
28718+ "1: prefetch (%1)\n"
28719+ " prefetch 64(%1)\n"
28720+ " prefetch 128(%1)\n"
28721+ " prefetch 192(%1)\n"
28722+ " prefetch 256(%1)\n"
28723 "2: \n"
28724 ".section .fixup, \"ax\"\n"
28725- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28726+ "3: \n"
28727+
28728+#ifdef CONFIG_PAX_KERNEXEC
28729+ " movl %%cr0, %0\n"
28730+ " movl %0, %%eax\n"
28731+ " andl $0xFFFEFFFF, %%eax\n"
28732+ " movl %%eax, %%cr0\n"
28733+#endif
28734+
28735+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28736+
28737+#ifdef CONFIG_PAX_KERNEXEC
28738+ " movl %0, %%cr0\n"
28739+#endif
28740+
28741 " jmp 2b\n"
28742 ".previous\n"
28743- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28744+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28745
28746 for (i = 0; i < 4096/64; i++) {
28747 __asm__ __volatile__ (
28748- "1: prefetch 320(%0)\n"
28749- "2: movq (%0), %%mm0\n"
28750- " movq 8(%0), %%mm1\n"
28751- " movq 16(%0), %%mm2\n"
28752- " movq 24(%0), %%mm3\n"
28753- " movq %%mm0, (%1)\n"
28754- " movq %%mm1, 8(%1)\n"
28755- " movq %%mm2, 16(%1)\n"
28756- " movq %%mm3, 24(%1)\n"
28757- " movq 32(%0), %%mm0\n"
28758- " movq 40(%0), %%mm1\n"
28759- " movq 48(%0), %%mm2\n"
28760- " movq 56(%0), %%mm3\n"
28761- " movq %%mm0, 32(%1)\n"
28762- " movq %%mm1, 40(%1)\n"
28763- " movq %%mm2, 48(%1)\n"
28764- " movq %%mm3, 56(%1)\n"
28765+ "1: prefetch 320(%1)\n"
28766+ "2: movq (%1), %%mm0\n"
28767+ " movq 8(%1), %%mm1\n"
28768+ " movq 16(%1), %%mm2\n"
28769+ " movq 24(%1), %%mm3\n"
28770+ " movq %%mm0, (%2)\n"
28771+ " movq %%mm1, 8(%2)\n"
28772+ " movq %%mm2, 16(%2)\n"
28773+ " movq %%mm3, 24(%2)\n"
28774+ " movq 32(%1), %%mm0\n"
28775+ " movq 40(%1), %%mm1\n"
28776+ " movq 48(%1), %%mm2\n"
28777+ " movq 56(%1), %%mm3\n"
28778+ " movq %%mm0, 32(%2)\n"
28779+ " movq %%mm1, 40(%2)\n"
28780+ " movq %%mm2, 48(%2)\n"
28781+ " movq %%mm3, 56(%2)\n"
28782 ".section .fixup, \"ax\"\n"
28783- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28784+ "3:\n"
28785+
28786+#ifdef CONFIG_PAX_KERNEXEC
28787+ " movl %%cr0, %0\n"
28788+ " movl %0, %%eax\n"
28789+ " andl $0xFFFEFFFF, %%eax\n"
28790+ " movl %%eax, %%cr0\n"
28791+#endif
28792+
28793+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28794+
28795+#ifdef CONFIG_PAX_KERNEXEC
28796+ " movl %0, %%cr0\n"
28797+#endif
28798+
28799 " jmp 2b\n"
28800 ".previous\n"
28801 _ASM_EXTABLE(1b, 3b)
28802- : : "r" (from), "r" (to) : "memory");
28803+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28804
28805 from += 64;
28806 to += 64;
28807diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28808index f6d13ee..aca5f0b 100644
28809--- a/arch/x86/lib/msr-reg.S
28810+++ b/arch/x86/lib/msr-reg.S
28811@@ -3,6 +3,7 @@
28812 #include <asm/dwarf2.h>
28813 #include <asm/asm.h>
28814 #include <asm/msr.h>
28815+#include <asm/alternative-asm.h>
28816
28817 #ifdef CONFIG_X86_64
28818 /*
28819@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28820 CFI_STARTPROC
28821 pushq_cfi %rbx
28822 pushq_cfi %rbp
28823- movq %rdi, %r10 /* Save pointer */
28824+ movq %rdi, %r9 /* Save pointer */
28825 xorl %r11d, %r11d /* Return value */
28826 movl (%rdi), %eax
28827 movl 4(%rdi), %ecx
28828@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28829 movl 28(%rdi), %edi
28830 CFI_REMEMBER_STATE
28831 1: \op
28832-2: movl %eax, (%r10)
28833+2: movl %eax, (%r9)
28834 movl %r11d, %eax /* Return value */
28835- movl %ecx, 4(%r10)
28836- movl %edx, 8(%r10)
28837- movl %ebx, 12(%r10)
28838- movl %ebp, 20(%r10)
28839- movl %esi, 24(%r10)
28840- movl %edi, 28(%r10)
28841+ movl %ecx, 4(%r9)
28842+ movl %edx, 8(%r9)
28843+ movl %ebx, 12(%r9)
28844+ movl %ebp, 20(%r9)
28845+ movl %esi, 24(%r9)
28846+ movl %edi, 28(%r9)
28847 popq_cfi %rbp
28848 popq_cfi %rbx
28849+ pax_force_retaddr
28850 ret
28851 3:
28852 CFI_RESTORE_STATE
28853diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28854index fc6ba17..d4d989d 100644
28855--- a/arch/x86/lib/putuser.S
28856+++ b/arch/x86/lib/putuser.S
28857@@ -16,7 +16,9 @@
28858 #include <asm/errno.h>
28859 #include <asm/asm.h>
28860 #include <asm/smap.h>
28861-
28862+#include <asm/segment.h>
28863+#include <asm/pgtable.h>
28864+#include <asm/alternative-asm.h>
28865
28866 /*
28867 * __put_user_X
28868@@ -30,57 +32,125 @@
28869 * as they get called from within inline assembly.
28870 */
28871
28872-#define ENTER CFI_STARTPROC ; \
28873- GET_THREAD_INFO(%_ASM_BX)
28874-#define EXIT ASM_CLAC ; \
28875- ret ; \
28876+#define ENTER CFI_STARTPROC
28877+#define EXIT ASM_CLAC ; \
28878+ pax_force_retaddr ; \
28879+ ret ; \
28880 CFI_ENDPROC
28881
28882+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28883+#define _DEST %_ASM_CX,%_ASM_BX
28884+#else
28885+#define _DEST %_ASM_CX
28886+#endif
28887+
28888+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28889+#define __copyuser_seg gs;
28890+#else
28891+#define __copyuser_seg
28892+#endif
28893+
28894 .text
28895 ENTRY(__put_user_1)
28896 ENTER
28897+
28898+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28899+ GET_THREAD_INFO(%_ASM_BX)
28900 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28901 jae bad_put_user
28902 ASM_STAC
28903-1: movb %al,(%_ASM_CX)
28904+
28905+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28906+ mov pax_user_shadow_base,%_ASM_BX
28907+ cmp %_ASM_BX,%_ASM_CX
28908+ jb 1234f
28909+ xor %ebx,%ebx
28910+1234:
28911+#endif
28912+
28913+#endif
28914+
28915+1: __copyuser_seg movb %al,(_DEST)
28916 xor %eax,%eax
28917 EXIT
28918 ENDPROC(__put_user_1)
28919
28920 ENTRY(__put_user_2)
28921 ENTER
28922+
28923+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28924+ GET_THREAD_INFO(%_ASM_BX)
28925 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28926 sub $1,%_ASM_BX
28927 cmp %_ASM_BX,%_ASM_CX
28928 jae bad_put_user
28929 ASM_STAC
28930-2: movw %ax,(%_ASM_CX)
28931+
28932+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28933+ mov pax_user_shadow_base,%_ASM_BX
28934+ cmp %_ASM_BX,%_ASM_CX
28935+ jb 1234f
28936+ xor %ebx,%ebx
28937+1234:
28938+#endif
28939+
28940+#endif
28941+
28942+2: __copyuser_seg movw %ax,(_DEST)
28943 xor %eax,%eax
28944 EXIT
28945 ENDPROC(__put_user_2)
28946
28947 ENTRY(__put_user_4)
28948 ENTER
28949+
28950+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28951+ GET_THREAD_INFO(%_ASM_BX)
28952 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28953 sub $3,%_ASM_BX
28954 cmp %_ASM_BX,%_ASM_CX
28955 jae bad_put_user
28956 ASM_STAC
28957-3: movl %eax,(%_ASM_CX)
28958+
28959+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28960+ mov pax_user_shadow_base,%_ASM_BX
28961+ cmp %_ASM_BX,%_ASM_CX
28962+ jb 1234f
28963+ xor %ebx,%ebx
28964+1234:
28965+#endif
28966+
28967+#endif
28968+
28969+3: __copyuser_seg movl %eax,(_DEST)
28970 xor %eax,%eax
28971 EXIT
28972 ENDPROC(__put_user_4)
28973
28974 ENTRY(__put_user_8)
28975 ENTER
28976+
28977+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28978+ GET_THREAD_INFO(%_ASM_BX)
28979 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28980 sub $7,%_ASM_BX
28981 cmp %_ASM_BX,%_ASM_CX
28982 jae bad_put_user
28983 ASM_STAC
28984-4: mov %_ASM_AX,(%_ASM_CX)
28985+
28986+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28987+ mov pax_user_shadow_base,%_ASM_BX
28988+ cmp %_ASM_BX,%_ASM_CX
28989+ jb 1234f
28990+ xor %ebx,%ebx
28991+1234:
28992+#endif
28993+
28994+#endif
28995+
28996+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28997 #ifdef CONFIG_X86_32
28998-5: movl %edx,4(%_ASM_CX)
28999+5: __copyuser_seg movl %edx,4(_DEST)
29000 #endif
29001 xor %eax,%eax
29002 EXIT
29003diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29004index 1cad221..de671ee 100644
29005--- a/arch/x86/lib/rwlock.S
29006+++ b/arch/x86/lib/rwlock.S
29007@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29008 FRAME
29009 0: LOCK_PREFIX
29010 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29011+
29012+#ifdef CONFIG_PAX_REFCOUNT
29013+ jno 1234f
29014+ LOCK_PREFIX
29015+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29016+ int $4
29017+1234:
29018+ _ASM_EXTABLE(1234b, 1234b)
29019+#endif
29020+
29021 1: rep; nop
29022 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29023 jne 1b
29024 LOCK_PREFIX
29025 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29026+
29027+#ifdef CONFIG_PAX_REFCOUNT
29028+ jno 1234f
29029+ LOCK_PREFIX
29030+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29031+ int $4
29032+1234:
29033+ _ASM_EXTABLE(1234b, 1234b)
29034+#endif
29035+
29036 jnz 0b
29037 ENDFRAME
29038+ pax_force_retaddr
29039 ret
29040 CFI_ENDPROC
29041 END(__write_lock_failed)
29042@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29043 FRAME
29044 0: LOCK_PREFIX
29045 READ_LOCK_SIZE(inc) (%__lock_ptr)
29046+
29047+#ifdef CONFIG_PAX_REFCOUNT
29048+ jno 1234f
29049+ LOCK_PREFIX
29050+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29051+ int $4
29052+1234:
29053+ _ASM_EXTABLE(1234b, 1234b)
29054+#endif
29055+
29056 1: rep; nop
29057 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29058 js 1b
29059 LOCK_PREFIX
29060 READ_LOCK_SIZE(dec) (%__lock_ptr)
29061+
29062+#ifdef CONFIG_PAX_REFCOUNT
29063+ jno 1234f
29064+ LOCK_PREFIX
29065+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29066+ int $4
29067+1234:
29068+ _ASM_EXTABLE(1234b, 1234b)
29069+#endif
29070+
29071 js 0b
29072 ENDFRAME
29073+ pax_force_retaddr
29074 ret
29075 CFI_ENDPROC
29076 END(__read_lock_failed)
29077diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29078index 5dff5f0..cadebf4 100644
29079--- a/arch/x86/lib/rwsem.S
29080+++ b/arch/x86/lib/rwsem.S
29081@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29082 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29083 CFI_RESTORE __ASM_REG(dx)
29084 restore_common_regs
29085+ pax_force_retaddr
29086 ret
29087 CFI_ENDPROC
29088 ENDPROC(call_rwsem_down_read_failed)
29089@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29090 movq %rax,%rdi
29091 call rwsem_down_write_failed
29092 restore_common_regs
29093+ pax_force_retaddr
29094 ret
29095 CFI_ENDPROC
29096 ENDPROC(call_rwsem_down_write_failed)
29097@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29098 movq %rax,%rdi
29099 call rwsem_wake
29100 restore_common_regs
29101-1: ret
29102+1: pax_force_retaddr
29103+ ret
29104 CFI_ENDPROC
29105 ENDPROC(call_rwsem_wake)
29106
29107@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29108 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29109 CFI_RESTORE __ASM_REG(dx)
29110 restore_common_regs
29111+ pax_force_retaddr
29112 ret
29113 CFI_ENDPROC
29114 ENDPROC(call_rwsem_downgrade_wake)
29115diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29116index a63efd6..ccecad8 100644
29117--- a/arch/x86/lib/thunk_64.S
29118+++ b/arch/x86/lib/thunk_64.S
29119@@ -8,6 +8,7 @@
29120 #include <linux/linkage.h>
29121 #include <asm/dwarf2.h>
29122 #include <asm/calling.h>
29123+#include <asm/alternative-asm.h>
29124
29125 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29126 .macro THUNK name, func, put_ret_addr_in_rdi=0
29127@@ -41,5 +42,6 @@
29128 SAVE_ARGS
29129 restore:
29130 RESTORE_ARGS
29131+ pax_force_retaddr
29132 ret
29133 CFI_ENDPROC
29134diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29135index 3eb18ac..6890bc3 100644
29136--- a/arch/x86/lib/usercopy_32.c
29137+++ b/arch/x86/lib/usercopy_32.c
29138@@ -42,11 +42,13 @@ do { \
29139 int __d0; \
29140 might_fault(); \
29141 __asm__ __volatile__( \
29142+ __COPYUSER_SET_ES \
29143 ASM_STAC "\n" \
29144 "0: rep; stosl\n" \
29145 " movl %2,%0\n" \
29146 "1: rep; stosb\n" \
29147 "2: " ASM_CLAC "\n" \
29148+ __COPYUSER_RESTORE_ES \
29149 ".section .fixup,\"ax\"\n" \
29150 "3: lea 0(%2,%0,4),%0\n" \
29151 " jmp 2b\n" \
29152@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29153
29154 #ifdef CONFIG_X86_INTEL_USERCOPY
29155 static unsigned long
29156-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29157+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29158 {
29159 int d0, d1;
29160 __asm__ __volatile__(
29161@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29162 " .align 2,0x90\n"
29163 "3: movl 0(%4), %%eax\n"
29164 "4: movl 4(%4), %%edx\n"
29165- "5: movl %%eax, 0(%3)\n"
29166- "6: movl %%edx, 4(%3)\n"
29167+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29168+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29169 "7: movl 8(%4), %%eax\n"
29170 "8: movl 12(%4),%%edx\n"
29171- "9: movl %%eax, 8(%3)\n"
29172- "10: movl %%edx, 12(%3)\n"
29173+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29174+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29175 "11: movl 16(%4), %%eax\n"
29176 "12: movl 20(%4), %%edx\n"
29177- "13: movl %%eax, 16(%3)\n"
29178- "14: movl %%edx, 20(%3)\n"
29179+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29180+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29181 "15: movl 24(%4), %%eax\n"
29182 "16: movl 28(%4), %%edx\n"
29183- "17: movl %%eax, 24(%3)\n"
29184- "18: movl %%edx, 28(%3)\n"
29185+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29186+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29187 "19: movl 32(%4), %%eax\n"
29188 "20: movl 36(%4), %%edx\n"
29189- "21: movl %%eax, 32(%3)\n"
29190- "22: movl %%edx, 36(%3)\n"
29191+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29192+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29193 "23: movl 40(%4), %%eax\n"
29194 "24: movl 44(%4), %%edx\n"
29195- "25: movl %%eax, 40(%3)\n"
29196- "26: movl %%edx, 44(%3)\n"
29197+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29198+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29199 "27: movl 48(%4), %%eax\n"
29200 "28: movl 52(%4), %%edx\n"
29201- "29: movl %%eax, 48(%3)\n"
29202- "30: movl %%edx, 52(%3)\n"
29203+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29204+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29205 "31: movl 56(%4), %%eax\n"
29206 "32: movl 60(%4), %%edx\n"
29207- "33: movl %%eax, 56(%3)\n"
29208- "34: movl %%edx, 60(%3)\n"
29209+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29210+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29211 " addl $-64, %0\n"
29212 " addl $64, %4\n"
29213 " addl $64, %3\n"
29214@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29215 " shrl $2, %0\n"
29216 " andl $3, %%eax\n"
29217 " cld\n"
29218+ __COPYUSER_SET_ES
29219 "99: rep; movsl\n"
29220 "36: movl %%eax, %0\n"
29221 "37: rep; movsb\n"
29222 "100:\n"
29223+ __COPYUSER_RESTORE_ES
29224 ".section .fixup,\"ax\"\n"
29225 "101: lea 0(%%eax,%0,4),%0\n"
29226 " jmp 100b\n"
29227@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29228 }
29229
29230 static unsigned long
29231+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29232+{
29233+ int d0, d1;
29234+ __asm__ __volatile__(
29235+ " .align 2,0x90\n"
29236+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29237+ " cmpl $67, %0\n"
29238+ " jbe 3f\n"
29239+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29240+ " .align 2,0x90\n"
29241+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29242+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29243+ "5: movl %%eax, 0(%3)\n"
29244+ "6: movl %%edx, 4(%3)\n"
29245+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29246+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29247+ "9: movl %%eax, 8(%3)\n"
29248+ "10: movl %%edx, 12(%3)\n"
29249+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29250+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29251+ "13: movl %%eax, 16(%3)\n"
29252+ "14: movl %%edx, 20(%3)\n"
29253+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29254+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29255+ "17: movl %%eax, 24(%3)\n"
29256+ "18: movl %%edx, 28(%3)\n"
29257+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29258+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29259+ "21: movl %%eax, 32(%3)\n"
29260+ "22: movl %%edx, 36(%3)\n"
29261+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29262+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29263+ "25: movl %%eax, 40(%3)\n"
29264+ "26: movl %%edx, 44(%3)\n"
29265+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29266+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29267+ "29: movl %%eax, 48(%3)\n"
29268+ "30: movl %%edx, 52(%3)\n"
29269+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29270+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29271+ "33: movl %%eax, 56(%3)\n"
29272+ "34: movl %%edx, 60(%3)\n"
29273+ " addl $-64, %0\n"
29274+ " addl $64, %4\n"
29275+ " addl $64, %3\n"
29276+ " cmpl $63, %0\n"
29277+ " ja 1b\n"
29278+ "35: movl %0, %%eax\n"
29279+ " shrl $2, %0\n"
29280+ " andl $3, %%eax\n"
29281+ " cld\n"
29282+ "99: rep; "__copyuser_seg" movsl\n"
29283+ "36: movl %%eax, %0\n"
29284+ "37: rep; "__copyuser_seg" movsb\n"
29285+ "100:\n"
29286+ ".section .fixup,\"ax\"\n"
29287+ "101: lea 0(%%eax,%0,4),%0\n"
29288+ " jmp 100b\n"
29289+ ".previous\n"
29290+ _ASM_EXTABLE(1b,100b)
29291+ _ASM_EXTABLE(2b,100b)
29292+ _ASM_EXTABLE(3b,100b)
29293+ _ASM_EXTABLE(4b,100b)
29294+ _ASM_EXTABLE(5b,100b)
29295+ _ASM_EXTABLE(6b,100b)
29296+ _ASM_EXTABLE(7b,100b)
29297+ _ASM_EXTABLE(8b,100b)
29298+ _ASM_EXTABLE(9b,100b)
29299+ _ASM_EXTABLE(10b,100b)
29300+ _ASM_EXTABLE(11b,100b)
29301+ _ASM_EXTABLE(12b,100b)
29302+ _ASM_EXTABLE(13b,100b)
29303+ _ASM_EXTABLE(14b,100b)
29304+ _ASM_EXTABLE(15b,100b)
29305+ _ASM_EXTABLE(16b,100b)
29306+ _ASM_EXTABLE(17b,100b)
29307+ _ASM_EXTABLE(18b,100b)
29308+ _ASM_EXTABLE(19b,100b)
29309+ _ASM_EXTABLE(20b,100b)
29310+ _ASM_EXTABLE(21b,100b)
29311+ _ASM_EXTABLE(22b,100b)
29312+ _ASM_EXTABLE(23b,100b)
29313+ _ASM_EXTABLE(24b,100b)
29314+ _ASM_EXTABLE(25b,100b)
29315+ _ASM_EXTABLE(26b,100b)
29316+ _ASM_EXTABLE(27b,100b)
29317+ _ASM_EXTABLE(28b,100b)
29318+ _ASM_EXTABLE(29b,100b)
29319+ _ASM_EXTABLE(30b,100b)
29320+ _ASM_EXTABLE(31b,100b)
29321+ _ASM_EXTABLE(32b,100b)
29322+ _ASM_EXTABLE(33b,100b)
29323+ _ASM_EXTABLE(34b,100b)
29324+ _ASM_EXTABLE(35b,100b)
29325+ _ASM_EXTABLE(36b,100b)
29326+ _ASM_EXTABLE(37b,100b)
29327+ _ASM_EXTABLE(99b,101b)
29328+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29329+ : "1"(to), "2"(from), "0"(size)
29330+ : "eax", "edx", "memory");
29331+ return size;
29332+}
29333+
29334+static unsigned long __size_overflow(3)
29335 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29336 {
29337 int d0, d1;
29338 __asm__ __volatile__(
29339 " .align 2,0x90\n"
29340- "0: movl 32(%4), %%eax\n"
29341+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29342 " cmpl $67, %0\n"
29343 " jbe 2f\n"
29344- "1: movl 64(%4), %%eax\n"
29345+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29346 " .align 2,0x90\n"
29347- "2: movl 0(%4), %%eax\n"
29348- "21: movl 4(%4), %%edx\n"
29349+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29350+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29351 " movl %%eax, 0(%3)\n"
29352 " movl %%edx, 4(%3)\n"
29353- "3: movl 8(%4), %%eax\n"
29354- "31: movl 12(%4),%%edx\n"
29355+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29356+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29357 " movl %%eax, 8(%3)\n"
29358 " movl %%edx, 12(%3)\n"
29359- "4: movl 16(%4), %%eax\n"
29360- "41: movl 20(%4), %%edx\n"
29361+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29362+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29363 " movl %%eax, 16(%3)\n"
29364 " movl %%edx, 20(%3)\n"
29365- "10: movl 24(%4), %%eax\n"
29366- "51: movl 28(%4), %%edx\n"
29367+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29368+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29369 " movl %%eax, 24(%3)\n"
29370 " movl %%edx, 28(%3)\n"
29371- "11: movl 32(%4), %%eax\n"
29372- "61: movl 36(%4), %%edx\n"
29373+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29374+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29375 " movl %%eax, 32(%3)\n"
29376 " movl %%edx, 36(%3)\n"
29377- "12: movl 40(%4), %%eax\n"
29378- "71: movl 44(%4), %%edx\n"
29379+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29380+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29381 " movl %%eax, 40(%3)\n"
29382 " movl %%edx, 44(%3)\n"
29383- "13: movl 48(%4), %%eax\n"
29384- "81: movl 52(%4), %%edx\n"
29385+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29386+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29387 " movl %%eax, 48(%3)\n"
29388 " movl %%edx, 52(%3)\n"
29389- "14: movl 56(%4), %%eax\n"
29390- "91: movl 60(%4), %%edx\n"
29391+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29392+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29393 " movl %%eax, 56(%3)\n"
29394 " movl %%edx, 60(%3)\n"
29395 " addl $-64, %0\n"
29396@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29397 " shrl $2, %0\n"
29398 " andl $3, %%eax\n"
29399 " cld\n"
29400- "6: rep; movsl\n"
29401+ "6: rep; "__copyuser_seg" movsl\n"
29402 " movl %%eax,%0\n"
29403- "7: rep; movsb\n"
29404+ "7: rep; "__copyuser_seg" movsb\n"
29405 "8:\n"
29406 ".section .fixup,\"ax\"\n"
29407 "9: lea 0(%%eax,%0,4),%0\n"
29408@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29409 * hyoshiok@miraclelinux.com
29410 */
29411
29412-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29413+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29414 const void __user *from, unsigned long size)
29415 {
29416 int d0, d1;
29417
29418 __asm__ __volatile__(
29419 " .align 2,0x90\n"
29420- "0: movl 32(%4), %%eax\n"
29421+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29422 " cmpl $67, %0\n"
29423 " jbe 2f\n"
29424- "1: movl 64(%4), %%eax\n"
29425+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29426 " .align 2,0x90\n"
29427- "2: movl 0(%4), %%eax\n"
29428- "21: movl 4(%4), %%edx\n"
29429+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29430+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29431 " movnti %%eax, 0(%3)\n"
29432 " movnti %%edx, 4(%3)\n"
29433- "3: movl 8(%4), %%eax\n"
29434- "31: movl 12(%4),%%edx\n"
29435+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29436+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29437 " movnti %%eax, 8(%3)\n"
29438 " movnti %%edx, 12(%3)\n"
29439- "4: movl 16(%4), %%eax\n"
29440- "41: movl 20(%4), %%edx\n"
29441+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29442+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29443 " movnti %%eax, 16(%3)\n"
29444 " movnti %%edx, 20(%3)\n"
29445- "10: movl 24(%4), %%eax\n"
29446- "51: movl 28(%4), %%edx\n"
29447+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29448+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29449 " movnti %%eax, 24(%3)\n"
29450 " movnti %%edx, 28(%3)\n"
29451- "11: movl 32(%4), %%eax\n"
29452- "61: movl 36(%4), %%edx\n"
29453+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29454+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29455 " movnti %%eax, 32(%3)\n"
29456 " movnti %%edx, 36(%3)\n"
29457- "12: movl 40(%4), %%eax\n"
29458- "71: movl 44(%4), %%edx\n"
29459+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29460+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29461 " movnti %%eax, 40(%3)\n"
29462 " movnti %%edx, 44(%3)\n"
29463- "13: movl 48(%4), %%eax\n"
29464- "81: movl 52(%4), %%edx\n"
29465+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29466+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29467 " movnti %%eax, 48(%3)\n"
29468 " movnti %%edx, 52(%3)\n"
29469- "14: movl 56(%4), %%eax\n"
29470- "91: movl 60(%4), %%edx\n"
29471+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29472+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29473 " movnti %%eax, 56(%3)\n"
29474 " movnti %%edx, 60(%3)\n"
29475 " addl $-64, %0\n"
29476@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29477 " shrl $2, %0\n"
29478 " andl $3, %%eax\n"
29479 " cld\n"
29480- "6: rep; movsl\n"
29481+ "6: rep; "__copyuser_seg" movsl\n"
29482 " movl %%eax,%0\n"
29483- "7: rep; movsb\n"
29484+ "7: rep; "__copyuser_seg" movsb\n"
29485 "8:\n"
29486 ".section .fixup,\"ax\"\n"
29487 "9: lea 0(%%eax,%0,4),%0\n"
29488@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29489 return size;
29490 }
29491
29492-static unsigned long __copy_user_intel_nocache(void *to,
29493+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29494 const void __user *from, unsigned long size)
29495 {
29496 int d0, d1;
29497
29498 __asm__ __volatile__(
29499 " .align 2,0x90\n"
29500- "0: movl 32(%4), %%eax\n"
29501+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29502 " cmpl $67, %0\n"
29503 " jbe 2f\n"
29504- "1: movl 64(%4), %%eax\n"
29505+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29506 " .align 2,0x90\n"
29507- "2: movl 0(%4), %%eax\n"
29508- "21: movl 4(%4), %%edx\n"
29509+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29510+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29511 " movnti %%eax, 0(%3)\n"
29512 " movnti %%edx, 4(%3)\n"
29513- "3: movl 8(%4), %%eax\n"
29514- "31: movl 12(%4),%%edx\n"
29515+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29516+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29517 " movnti %%eax, 8(%3)\n"
29518 " movnti %%edx, 12(%3)\n"
29519- "4: movl 16(%4), %%eax\n"
29520- "41: movl 20(%4), %%edx\n"
29521+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29522+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29523 " movnti %%eax, 16(%3)\n"
29524 " movnti %%edx, 20(%3)\n"
29525- "10: movl 24(%4), %%eax\n"
29526- "51: movl 28(%4), %%edx\n"
29527+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29528+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29529 " movnti %%eax, 24(%3)\n"
29530 " movnti %%edx, 28(%3)\n"
29531- "11: movl 32(%4), %%eax\n"
29532- "61: movl 36(%4), %%edx\n"
29533+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29534+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29535 " movnti %%eax, 32(%3)\n"
29536 " movnti %%edx, 36(%3)\n"
29537- "12: movl 40(%4), %%eax\n"
29538- "71: movl 44(%4), %%edx\n"
29539+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29540+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29541 " movnti %%eax, 40(%3)\n"
29542 " movnti %%edx, 44(%3)\n"
29543- "13: movl 48(%4), %%eax\n"
29544- "81: movl 52(%4), %%edx\n"
29545+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29546+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29547 " movnti %%eax, 48(%3)\n"
29548 " movnti %%edx, 52(%3)\n"
29549- "14: movl 56(%4), %%eax\n"
29550- "91: movl 60(%4), %%edx\n"
29551+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29552+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29553 " movnti %%eax, 56(%3)\n"
29554 " movnti %%edx, 60(%3)\n"
29555 " addl $-64, %0\n"
29556@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29557 " shrl $2, %0\n"
29558 " andl $3, %%eax\n"
29559 " cld\n"
29560- "6: rep; movsl\n"
29561+ "6: rep; "__copyuser_seg" movsl\n"
29562 " movl %%eax,%0\n"
29563- "7: rep; movsb\n"
29564+ "7: rep; "__copyuser_seg" movsb\n"
29565 "8:\n"
29566 ".section .fixup,\"ax\"\n"
29567 "9: lea 0(%%eax,%0,4),%0\n"
29568@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29569 */
29570 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29571 unsigned long size);
29572-unsigned long __copy_user_intel(void __user *to, const void *from,
29573+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29574+ unsigned long size);
29575+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29576 unsigned long size);
29577 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29578 const void __user *from, unsigned long size);
29579 #endif /* CONFIG_X86_INTEL_USERCOPY */
29580
29581 /* Generic arbitrary sized copy. */
29582-#define __copy_user(to, from, size) \
29583+#define __copy_user(to, from, size, prefix, set, restore) \
29584 do { \
29585 int __d0, __d1, __d2; \
29586 __asm__ __volatile__( \
29587+ set \
29588 " cmp $7,%0\n" \
29589 " jbe 1f\n" \
29590 " movl %1,%0\n" \
29591 " negl %0\n" \
29592 " andl $7,%0\n" \
29593 " subl %0,%3\n" \
29594- "4: rep; movsb\n" \
29595+ "4: rep; "prefix"movsb\n" \
29596 " movl %3,%0\n" \
29597 " shrl $2,%0\n" \
29598 " andl $3,%3\n" \
29599 " .align 2,0x90\n" \
29600- "0: rep; movsl\n" \
29601+ "0: rep; "prefix"movsl\n" \
29602 " movl %3,%0\n" \
29603- "1: rep; movsb\n" \
29604+ "1: rep; "prefix"movsb\n" \
29605 "2:\n" \
29606+ restore \
29607 ".section .fixup,\"ax\"\n" \
29608 "5: addl %3,%0\n" \
29609 " jmp 2b\n" \
29610@@ -538,14 +650,14 @@ do { \
29611 " negl %0\n" \
29612 " andl $7,%0\n" \
29613 " subl %0,%3\n" \
29614- "4: rep; movsb\n" \
29615+ "4: rep; "__copyuser_seg"movsb\n" \
29616 " movl %3,%0\n" \
29617 " shrl $2,%0\n" \
29618 " andl $3,%3\n" \
29619 " .align 2,0x90\n" \
29620- "0: rep; movsl\n" \
29621+ "0: rep; "__copyuser_seg"movsl\n" \
29622 " movl %3,%0\n" \
29623- "1: rep; movsb\n" \
29624+ "1: rep; "__copyuser_seg"movsb\n" \
29625 "2:\n" \
29626 ".section .fixup,\"ax\"\n" \
29627 "5: addl %3,%0\n" \
29628@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29629 {
29630 stac();
29631 if (movsl_is_ok(to, from, n))
29632- __copy_user(to, from, n);
29633+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29634 else
29635- n = __copy_user_intel(to, from, n);
29636+ n = __generic_copy_to_user_intel(to, from, n);
29637 clac();
29638 return n;
29639 }
29640@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29641 {
29642 stac();
29643 if (movsl_is_ok(to, from, n))
29644- __copy_user(to, from, n);
29645+ __copy_user(to, from, n, __copyuser_seg, "", "");
29646 else
29647- n = __copy_user_intel((void __user *)to,
29648- (const void *)from, n);
29649+ n = __generic_copy_from_user_intel(to, from, n);
29650 clac();
29651 return n;
29652 }
29653@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29654 if (n > 64 && cpu_has_xmm2)
29655 n = __copy_user_intel_nocache(to, from, n);
29656 else
29657- __copy_user(to, from, n);
29658+ __copy_user(to, from, n, __copyuser_seg, "", "");
29659 #else
29660- __copy_user(to, from, n);
29661+ __copy_user(to, from, n, __copyuser_seg, "", "");
29662 #endif
29663 clac();
29664 return n;
29665 }
29666 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29667
29668-/**
29669- * copy_to_user: - Copy a block of data into user space.
29670- * @to: Destination address, in user space.
29671- * @from: Source address, in kernel space.
29672- * @n: Number of bytes to copy.
29673- *
29674- * Context: User context only. This function may sleep.
29675- *
29676- * Copy data from kernel space to user space.
29677- *
29678- * Returns number of bytes that could not be copied.
29679- * On success, this will be zero.
29680- */
29681-unsigned long
29682-copy_to_user(void __user *to, const void *from, unsigned long n)
29683+#ifdef CONFIG_PAX_MEMORY_UDEREF
29684+void __set_fs(mm_segment_t x)
29685 {
29686- if (access_ok(VERIFY_WRITE, to, n))
29687- n = __copy_to_user(to, from, n);
29688- return n;
29689+ switch (x.seg) {
29690+ case 0:
29691+ loadsegment(gs, 0);
29692+ break;
29693+ case TASK_SIZE_MAX:
29694+ loadsegment(gs, __USER_DS);
29695+ break;
29696+ case -1UL:
29697+ loadsegment(gs, __KERNEL_DS);
29698+ break;
29699+ default:
29700+ BUG();
29701+ }
29702 }
29703-EXPORT_SYMBOL(copy_to_user);
29704+EXPORT_SYMBOL(__set_fs);
29705
29706-/**
29707- * copy_from_user: - Copy a block of data from user space.
29708- * @to: Destination address, in kernel space.
29709- * @from: Source address, in user space.
29710- * @n: Number of bytes to copy.
29711- *
29712- * Context: User context only. This function may sleep.
29713- *
29714- * Copy data from user space to kernel space.
29715- *
29716- * Returns number of bytes that could not be copied.
29717- * On success, this will be zero.
29718- *
29719- * If some data could not be copied, this function will pad the copied
29720- * data to the requested size using zero bytes.
29721- */
29722-unsigned long
29723-_copy_from_user(void *to, const void __user *from, unsigned long n)
29724+void set_fs(mm_segment_t x)
29725 {
29726- if (access_ok(VERIFY_READ, from, n))
29727- n = __copy_from_user(to, from, n);
29728- else
29729- memset(to, 0, n);
29730- return n;
29731+ current_thread_info()->addr_limit = x;
29732+ __set_fs(x);
29733 }
29734-EXPORT_SYMBOL(_copy_from_user);
29735+EXPORT_SYMBOL(set_fs);
29736+#endif
29737diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29738index 906fea3..0194a18 100644
29739--- a/arch/x86/lib/usercopy_64.c
29740+++ b/arch/x86/lib/usercopy_64.c
29741@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29742 might_fault();
29743 /* no memory constraint because it doesn't change any memory gcc knows
29744 about */
29745+ pax_open_userland();
29746 stac();
29747 asm volatile(
29748 " testq %[size8],%[size8]\n"
29749@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29750 _ASM_EXTABLE(0b,3b)
29751 _ASM_EXTABLE(1b,2b)
29752 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29753- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29754+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29755 [zero] "r" (0UL), [eight] "r" (8UL));
29756 clac();
29757+ pax_close_userland();
29758 return size;
29759 }
29760 EXPORT_SYMBOL(__clear_user);
29761@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29762 }
29763 EXPORT_SYMBOL(clear_user);
29764
29765-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29766+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29767 {
29768- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29769- return copy_user_generic((__force void *)to, (__force void *)from, len);
29770- }
29771- return len;
29772+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29773+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29774+ return len;
29775 }
29776 EXPORT_SYMBOL(copy_in_user);
29777
29778@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29779 * it is not necessary to optimize tail handling.
29780 */
29781 unsigned long
29782-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29783+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29784 {
29785 char c;
29786 unsigned zero_len;
29787
29788+ clac();
29789+ pax_close_userland();
29790 for (; len; --len, to++) {
29791 if (__get_user_nocheck(c, from++, sizeof(char)))
29792 break;
29793@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29794 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29795 if (__put_user_nocheck(c, to++, sizeof(char)))
29796 break;
29797- clac();
29798 return len;
29799 }
29800diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29801index 23d8e5f..9ccc13a 100644
29802--- a/arch/x86/mm/Makefile
29803+++ b/arch/x86/mm/Makefile
29804@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29805 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29806
29807 obj-$(CONFIG_MEMTEST) += memtest.o
29808+
29809+quote:="
29810+obj-$(CONFIG_X86_64) += uderef_64.o
29811+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29812diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29813index 903ec1e..c4166b2 100644
29814--- a/arch/x86/mm/extable.c
29815+++ b/arch/x86/mm/extable.c
29816@@ -6,12 +6,24 @@
29817 static inline unsigned long
29818 ex_insn_addr(const struct exception_table_entry *x)
29819 {
29820- return (unsigned long)&x->insn + x->insn;
29821+ unsigned long reloc = 0;
29822+
29823+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29824+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29825+#endif
29826+
29827+ return (unsigned long)&x->insn + x->insn + reloc;
29828 }
29829 static inline unsigned long
29830 ex_fixup_addr(const struct exception_table_entry *x)
29831 {
29832- return (unsigned long)&x->fixup + x->fixup;
29833+ unsigned long reloc = 0;
29834+
29835+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29836+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29837+#endif
29838+
29839+ return (unsigned long)&x->fixup + x->fixup + reloc;
29840 }
29841
29842 int fixup_exception(struct pt_regs *regs)
29843@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29844 unsigned long new_ip;
29845
29846 #ifdef CONFIG_PNPBIOS
29847- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29848+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29849 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29850 extern u32 pnp_bios_is_utter_crap;
29851 pnp_bios_is_utter_crap = 1;
29852@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29853 i += 4;
29854 p->fixup -= i;
29855 i += 4;
29856+
29857+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29858+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29859+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29860+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29861+#endif
29862+
29863 }
29864 }
29865
29866diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29867index 654be4a..a4a3da1 100644
29868--- a/arch/x86/mm/fault.c
29869+++ b/arch/x86/mm/fault.c
29870@@ -14,11 +14,18 @@
29871 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29872 #include <linux/prefetch.h> /* prefetchw */
29873 #include <linux/context_tracking.h> /* exception_enter(), ... */
29874+#include <linux/unistd.h>
29875+#include <linux/compiler.h>
29876
29877 #include <asm/traps.h> /* dotraplinkage, ... */
29878 #include <asm/pgalloc.h> /* pgd_*(), ... */
29879 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29880 #include <asm/fixmap.h> /* VSYSCALL_START */
29881+#include <asm/tlbflush.h>
29882+
29883+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29884+#include <asm/stacktrace.h>
29885+#endif
29886
29887 /*
29888 * Page fault error code bits:
29889@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29890 int ret = 0;
29891
29892 /* kprobe_running() needs smp_processor_id() */
29893- if (kprobes_built_in() && !user_mode_vm(regs)) {
29894+ if (kprobes_built_in() && !user_mode(regs)) {
29895 preempt_disable();
29896 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29897 ret = 1;
29898@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29899 return !instr_lo || (instr_lo>>1) == 1;
29900 case 0x00:
29901 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29902- if (probe_kernel_address(instr, opcode))
29903+ if (user_mode(regs)) {
29904+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29905+ return 0;
29906+ } else if (probe_kernel_address(instr, opcode))
29907 return 0;
29908
29909 *prefetch = (instr_lo == 0xF) &&
29910@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29911 while (instr < max_instr) {
29912 unsigned char opcode;
29913
29914- if (probe_kernel_address(instr, opcode))
29915+ if (user_mode(regs)) {
29916+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29917+ break;
29918+ } else if (probe_kernel_address(instr, opcode))
29919 break;
29920
29921 instr++;
29922@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29923 force_sig_info(si_signo, &info, tsk);
29924 }
29925
29926+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29927+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29928+#endif
29929+
29930+#ifdef CONFIG_PAX_EMUTRAMP
29931+static int pax_handle_fetch_fault(struct pt_regs *regs);
29932+#endif
29933+
29934+#ifdef CONFIG_PAX_PAGEEXEC
29935+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29936+{
29937+ pgd_t *pgd;
29938+ pud_t *pud;
29939+ pmd_t *pmd;
29940+
29941+ pgd = pgd_offset(mm, address);
29942+ if (!pgd_present(*pgd))
29943+ return NULL;
29944+ pud = pud_offset(pgd, address);
29945+ if (!pud_present(*pud))
29946+ return NULL;
29947+ pmd = pmd_offset(pud, address);
29948+ if (!pmd_present(*pmd))
29949+ return NULL;
29950+ return pmd;
29951+}
29952+#endif
29953+
29954 DEFINE_SPINLOCK(pgd_lock);
29955 LIST_HEAD(pgd_list);
29956
29957@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29958 for (address = VMALLOC_START & PMD_MASK;
29959 address >= TASK_SIZE && address < FIXADDR_TOP;
29960 address += PMD_SIZE) {
29961+
29962+#ifdef CONFIG_PAX_PER_CPU_PGD
29963+ unsigned long cpu;
29964+#else
29965 struct page *page;
29966+#endif
29967
29968 spin_lock(&pgd_lock);
29969+
29970+#ifdef CONFIG_PAX_PER_CPU_PGD
29971+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29972+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29973+ pmd_t *ret;
29974+
29975+ ret = vmalloc_sync_one(pgd, address);
29976+ if (!ret)
29977+ break;
29978+ pgd = get_cpu_pgd(cpu, kernel);
29979+#else
29980 list_for_each_entry(page, &pgd_list, lru) {
29981+ pgd_t *pgd;
29982 spinlock_t *pgt_lock;
29983 pmd_t *ret;
29984
29985@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29986 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29987
29988 spin_lock(pgt_lock);
29989- ret = vmalloc_sync_one(page_address(page), address);
29990+ pgd = page_address(page);
29991+#endif
29992+
29993+ ret = vmalloc_sync_one(pgd, address);
29994+
29995+#ifndef CONFIG_PAX_PER_CPU_PGD
29996 spin_unlock(pgt_lock);
29997+#endif
29998
29999 if (!ret)
30000 break;
30001@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30002 * an interrupt in the middle of a task switch..
30003 */
30004 pgd_paddr = read_cr3();
30005+
30006+#ifdef CONFIG_PAX_PER_CPU_PGD
30007+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30008+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30009+#endif
30010+
30011 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30012 if (!pmd_k)
30013 return -1;
30014@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30015 * happen within a race in page table update. In the later
30016 * case just flush:
30017 */
30018- pgd = pgd_offset(current->active_mm, address);
30019+
30020 pgd_ref = pgd_offset_k(address);
30021 if (pgd_none(*pgd_ref))
30022 return -1;
30023
30024+#ifdef CONFIG_PAX_PER_CPU_PGD
30025+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30026+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30027+ if (pgd_none(*pgd)) {
30028+ set_pgd(pgd, *pgd_ref);
30029+ arch_flush_lazy_mmu_mode();
30030+ } else {
30031+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30032+ }
30033+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30034+#else
30035+ pgd = pgd_offset(current->active_mm, address);
30036+#endif
30037+
30038 if (pgd_none(*pgd)) {
30039 set_pgd(pgd, *pgd_ref);
30040 arch_flush_lazy_mmu_mode();
30041@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30042 static int is_errata100(struct pt_regs *regs, unsigned long address)
30043 {
30044 #ifdef CONFIG_X86_64
30045- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30046+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30047 return 1;
30048 #endif
30049 return 0;
30050@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30051 }
30052
30053 static const char nx_warning[] = KERN_CRIT
30054-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30055+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30056
30057 static void
30058 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30059@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30060 if (!oops_may_print())
30061 return;
30062
30063- if (error_code & PF_INSTR) {
30064+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30065 unsigned int level;
30066
30067 pte_t *pte = lookup_address(address, &level);
30068
30069 if (pte && pte_present(*pte) && !pte_exec(*pte))
30070- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30071+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30072 }
30073
30074+#ifdef CONFIG_PAX_KERNEXEC
30075+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30076+ if (current->signal->curr_ip)
30077+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30078+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30079+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30080+ else
30081+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30082+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30083+ }
30084+#endif
30085+
30086 printk(KERN_ALERT "BUG: unable to handle kernel ");
30087 if (address < PAGE_SIZE)
30088 printk(KERN_CONT "NULL pointer dereference");
30089@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30090 return;
30091 }
30092 #endif
30093+
30094+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30095+ if (pax_is_fetch_fault(regs, error_code, address)) {
30096+
30097+#ifdef CONFIG_PAX_EMUTRAMP
30098+ switch (pax_handle_fetch_fault(regs)) {
30099+ case 2:
30100+ return;
30101+ }
30102+#endif
30103+
30104+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30105+ do_group_exit(SIGKILL);
30106+ }
30107+#endif
30108+
30109 /* Kernel addresses are always protection faults: */
30110 if (address >= TASK_SIZE)
30111 error_code |= PF_PROT;
30112@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30113 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30114 printk(KERN_ERR
30115 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30116- tsk->comm, tsk->pid, address);
30117+ tsk->comm, task_pid_nr(tsk), address);
30118 code = BUS_MCEERR_AR;
30119 }
30120 #endif
30121@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30122 return 1;
30123 }
30124
30125+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30126+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30127+{
30128+ pte_t *pte;
30129+ pmd_t *pmd;
30130+ spinlock_t *ptl;
30131+ unsigned char pte_mask;
30132+
30133+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30134+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30135+ return 0;
30136+
30137+ /* PaX: it's our fault, let's handle it if we can */
30138+
30139+ /* PaX: take a look at read faults before acquiring any locks */
30140+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30141+ /* instruction fetch attempt from a protected page in user mode */
30142+ up_read(&mm->mmap_sem);
30143+
30144+#ifdef CONFIG_PAX_EMUTRAMP
30145+ switch (pax_handle_fetch_fault(regs)) {
30146+ case 2:
30147+ return 1;
30148+ }
30149+#endif
30150+
30151+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30152+ do_group_exit(SIGKILL);
30153+ }
30154+
30155+ pmd = pax_get_pmd(mm, address);
30156+ if (unlikely(!pmd))
30157+ return 0;
30158+
30159+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30160+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30161+ pte_unmap_unlock(pte, ptl);
30162+ return 0;
30163+ }
30164+
30165+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30166+ /* write attempt to a protected page in user mode */
30167+ pte_unmap_unlock(pte, ptl);
30168+ return 0;
30169+ }
30170+
30171+#ifdef CONFIG_SMP
30172+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30173+#else
30174+ if (likely(address > get_limit(regs->cs)))
30175+#endif
30176+ {
30177+ set_pte(pte, pte_mkread(*pte));
30178+ __flush_tlb_one(address);
30179+ pte_unmap_unlock(pte, ptl);
30180+ up_read(&mm->mmap_sem);
30181+ return 1;
30182+ }
30183+
30184+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30185+
30186+ /*
30187+ * PaX: fill DTLB with user rights and retry
30188+ */
30189+ __asm__ __volatile__ (
30190+ "orb %2,(%1)\n"
30191+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30192+/*
30193+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30194+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30195+ * page fault when examined during a TLB load attempt. this is true not only
30196+ * for PTEs holding a non-present entry but also present entries that will
30197+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30198+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30199+ * for our target pages since their PTEs are simply not in the TLBs at all.
30200+
30201+ * the best thing in omitting it is that we gain around 15-20% speed in the
30202+ * fast path of the page fault handler and can get rid of tracing since we
30203+ * can no longer flush unintended entries.
30204+ */
30205+ "invlpg (%0)\n"
30206+#endif
30207+ __copyuser_seg"testb $0,(%0)\n"
30208+ "xorb %3,(%1)\n"
30209+ :
30210+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30211+ : "memory", "cc");
30212+ pte_unmap_unlock(pte, ptl);
30213+ up_read(&mm->mmap_sem);
30214+ return 1;
30215+}
30216+#endif
30217+
30218 /*
30219 * Handle a spurious fault caused by a stale TLB entry.
30220 *
30221@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30222 static inline int
30223 access_error(unsigned long error_code, struct vm_area_struct *vma)
30224 {
30225+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30226+ return 1;
30227+
30228 if (error_code & PF_WRITE) {
30229 /* write, present and write, not present: */
30230 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30231@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30232 if (error_code & PF_USER)
30233 return false;
30234
30235- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30236+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30237 return false;
30238
30239 return true;
30240@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30241 {
30242 struct vm_area_struct *vma;
30243 struct task_struct *tsk;
30244- unsigned long address;
30245 struct mm_struct *mm;
30246 int fault;
30247 int write = error_code & PF_WRITE;
30248 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30249 (write ? FAULT_FLAG_WRITE : 0);
30250
30251- tsk = current;
30252- mm = tsk->mm;
30253-
30254 /* Get the faulting address: */
30255- address = read_cr2();
30256+ unsigned long address = read_cr2();
30257+
30258+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30259+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30260+ if (!search_exception_tables(regs->ip)) {
30261+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30262+ bad_area_nosemaphore(regs, error_code, address);
30263+ return;
30264+ }
30265+ if (address < pax_user_shadow_base) {
30266+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30267+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30268+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30269+ } else
30270+ address -= pax_user_shadow_base;
30271+ }
30272+#endif
30273+
30274+ tsk = current;
30275+ mm = tsk->mm;
30276
30277 /*
30278 * Detect and handle instructions that would cause a page fault for
30279@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30280 * User-mode registers count as a user access even for any
30281 * potential system fault or CPU buglet:
30282 */
30283- if (user_mode_vm(regs)) {
30284+ if (user_mode(regs)) {
30285 local_irq_enable();
30286 error_code |= PF_USER;
30287 } else {
30288@@ -1142,6 +1365,11 @@ retry:
30289 might_sleep();
30290 }
30291
30292+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30293+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30294+ return;
30295+#endif
30296+
30297 vma = find_vma(mm, address);
30298 if (unlikely(!vma)) {
30299 bad_area(regs, error_code, address);
30300@@ -1153,18 +1381,24 @@ retry:
30301 bad_area(regs, error_code, address);
30302 return;
30303 }
30304- if (error_code & PF_USER) {
30305- /*
30306- * Accessing the stack below %sp is always a bug.
30307- * The large cushion allows instructions like enter
30308- * and pusha to work. ("enter $65535, $31" pushes
30309- * 32 pointers and then decrements %sp by 65535.)
30310- */
30311- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30312- bad_area(regs, error_code, address);
30313- return;
30314- }
30315+ /*
30316+ * Accessing the stack below %sp is always a bug.
30317+ * The large cushion allows instructions like enter
30318+ * and pusha to work. ("enter $65535, $31" pushes
30319+ * 32 pointers and then decrements %sp by 65535.)
30320+ */
30321+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30322+ bad_area(regs, error_code, address);
30323+ return;
30324 }
30325+
30326+#ifdef CONFIG_PAX_SEGMEXEC
30327+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30328+ bad_area(regs, error_code, address);
30329+ return;
30330+ }
30331+#endif
30332+
30333 if (unlikely(expand_stack(vma, address))) {
30334 bad_area(regs, error_code, address);
30335 return;
30336@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30337 __do_page_fault(regs, error_code);
30338 exception_exit(prev_state);
30339 }
30340+
30341+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30342+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30343+{
30344+ struct mm_struct *mm = current->mm;
30345+ unsigned long ip = regs->ip;
30346+
30347+ if (v8086_mode(regs))
30348+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30349+
30350+#ifdef CONFIG_PAX_PAGEEXEC
30351+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30352+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30353+ return true;
30354+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30355+ return true;
30356+ return false;
30357+ }
30358+#endif
30359+
30360+#ifdef CONFIG_PAX_SEGMEXEC
30361+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30362+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30363+ return true;
30364+ return false;
30365+ }
30366+#endif
30367+
30368+ return false;
30369+}
30370+#endif
30371+
30372+#ifdef CONFIG_PAX_EMUTRAMP
30373+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30374+{
30375+ int err;
30376+
30377+ do { /* PaX: libffi trampoline emulation */
30378+ unsigned char mov, jmp;
30379+ unsigned int addr1, addr2;
30380+
30381+#ifdef CONFIG_X86_64
30382+ if ((regs->ip + 9) >> 32)
30383+ break;
30384+#endif
30385+
30386+ err = get_user(mov, (unsigned char __user *)regs->ip);
30387+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30388+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30389+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30390+
30391+ if (err)
30392+ break;
30393+
30394+ if (mov == 0xB8 && jmp == 0xE9) {
30395+ regs->ax = addr1;
30396+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30397+ return 2;
30398+ }
30399+ } while (0);
30400+
30401+ do { /* PaX: gcc trampoline emulation #1 */
30402+ unsigned char mov1, mov2;
30403+ unsigned short jmp;
30404+ unsigned int addr1, addr2;
30405+
30406+#ifdef CONFIG_X86_64
30407+ if ((regs->ip + 11) >> 32)
30408+ break;
30409+#endif
30410+
30411+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30412+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30413+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30414+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30415+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30416+
30417+ if (err)
30418+ break;
30419+
30420+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30421+ regs->cx = addr1;
30422+ regs->ax = addr2;
30423+ regs->ip = addr2;
30424+ return 2;
30425+ }
30426+ } while (0);
30427+
30428+ do { /* PaX: gcc trampoline emulation #2 */
30429+ unsigned char mov, jmp;
30430+ unsigned int addr1, addr2;
30431+
30432+#ifdef CONFIG_X86_64
30433+ if ((regs->ip + 9) >> 32)
30434+ break;
30435+#endif
30436+
30437+ err = get_user(mov, (unsigned char __user *)regs->ip);
30438+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30439+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30440+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30441+
30442+ if (err)
30443+ break;
30444+
30445+ if (mov == 0xB9 && jmp == 0xE9) {
30446+ regs->cx = addr1;
30447+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30448+ return 2;
30449+ }
30450+ } while (0);
30451+
30452+ return 1; /* PaX in action */
30453+}
30454+
30455+#ifdef CONFIG_X86_64
30456+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30457+{
30458+ int err;
30459+
30460+ do { /* PaX: libffi trampoline emulation */
30461+ unsigned short mov1, mov2, jmp1;
30462+ unsigned char stcclc, jmp2;
30463+ unsigned long addr1, addr2;
30464+
30465+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30466+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30467+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30468+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30469+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30470+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30471+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30472+
30473+ if (err)
30474+ break;
30475+
30476+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30477+ regs->r11 = addr1;
30478+ regs->r10 = addr2;
30479+ if (stcclc == 0xF8)
30480+ regs->flags &= ~X86_EFLAGS_CF;
30481+ else
30482+ regs->flags |= X86_EFLAGS_CF;
30483+ regs->ip = addr1;
30484+ return 2;
30485+ }
30486+ } while (0);
30487+
30488+ do { /* PaX: gcc trampoline emulation #1 */
30489+ unsigned short mov1, mov2, jmp1;
30490+ unsigned char jmp2;
30491+ unsigned int addr1;
30492+ unsigned long addr2;
30493+
30494+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30495+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30496+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30497+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30498+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30499+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30500+
30501+ if (err)
30502+ break;
30503+
30504+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30505+ regs->r11 = addr1;
30506+ regs->r10 = addr2;
30507+ regs->ip = addr1;
30508+ return 2;
30509+ }
30510+ } while (0);
30511+
30512+ do { /* PaX: gcc trampoline emulation #2 */
30513+ unsigned short mov1, mov2, jmp1;
30514+ unsigned char jmp2;
30515+ unsigned long addr1, addr2;
30516+
30517+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30518+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30519+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30520+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30521+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30522+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30523+
30524+ if (err)
30525+ break;
30526+
30527+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30528+ regs->r11 = addr1;
30529+ regs->r10 = addr2;
30530+ regs->ip = addr1;
30531+ return 2;
30532+ }
30533+ } while (0);
30534+
30535+ return 1; /* PaX in action */
30536+}
30537+#endif
30538+
30539+/*
30540+ * PaX: decide what to do with offenders (regs->ip = fault address)
30541+ *
30542+ * returns 1 when task should be killed
30543+ * 2 when gcc trampoline was detected
30544+ */
30545+static int pax_handle_fetch_fault(struct pt_regs *regs)
30546+{
30547+ if (v8086_mode(regs))
30548+ return 1;
30549+
30550+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30551+ return 1;
30552+
30553+#ifdef CONFIG_X86_32
30554+ return pax_handle_fetch_fault_32(regs);
30555+#else
30556+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30557+ return pax_handle_fetch_fault_32(regs);
30558+ else
30559+ return pax_handle_fetch_fault_64(regs);
30560+#endif
30561+}
30562+#endif
30563+
30564+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30565+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30566+{
30567+ long i;
30568+
30569+ printk(KERN_ERR "PAX: bytes at PC: ");
30570+ for (i = 0; i < 20; i++) {
30571+ unsigned char c;
30572+ if (get_user(c, (unsigned char __force_user *)pc+i))
30573+ printk(KERN_CONT "?? ");
30574+ else
30575+ printk(KERN_CONT "%02x ", c);
30576+ }
30577+ printk("\n");
30578+
30579+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30580+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30581+ unsigned long c;
30582+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30583+#ifdef CONFIG_X86_32
30584+ printk(KERN_CONT "???????? ");
30585+#else
30586+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30587+ printk(KERN_CONT "???????? ???????? ");
30588+ else
30589+ printk(KERN_CONT "???????????????? ");
30590+#endif
30591+ } else {
30592+#ifdef CONFIG_X86_64
30593+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30594+ printk(KERN_CONT "%08x ", (unsigned int)c);
30595+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30596+ } else
30597+#endif
30598+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30599+ }
30600+ }
30601+ printk("\n");
30602+}
30603+#endif
30604+
30605+/**
30606+ * probe_kernel_write(): safely attempt to write to a location
30607+ * @dst: address to write to
30608+ * @src: pointer to the data that shall be written
30609+ * @size: size of the data chunk
30610+ *
30611+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30612+ * happens, handle that and return -EFAULT.
30613+ */
30614+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30615+{
30616+ long ret;
30617+ mm_segment_t old_fs = get_fs();
30618+
30619+ set_fs(KERNEL_DS);
30620+ pagefault_disable();
30621+ pax_open_kernel();
30622+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30623+ pax_close_kernel();
30624+ pagefault_enable();
30625+ set_fs(old_fs);
30626+
30627+ return ret ? -EFAULT : 0;
30628+}
30629diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30630index dd74e46..7d26398 100644
30631--- a/arch/x86/mm/gup.c
30632+++ b/arch/x86/mm/gup.c
30633@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30634 addr = start;
30635 len = (unsigned long) nr_pages << PAGE_SHIFT;
30636 end = start + len;
30637- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30638+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30639 (void __user *)start, len)))
30640 return 0;
30641
30642diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30643index 4500142..53a363c 100644
30644--- a/arch/x86/mm/highmem_32.c
30645+++ b/arch/x86/mm/highmem_32.c
30646@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30647 idx = type + KM_TYPE_NR*smp_processor_id();
30648 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30649 BUG_ON(!pte_none(*(kmap_pte-idx)));
30650+
30651+ pax_open_kernel();
30652 set_pte(kmap_pte-idx, mk_pte(page, prot));
30653+ pax_close_kernel();
30654+
30655 arch_flush_lazy_mmu_mode();
30656
30657 return (void *)vaddr;
30658diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30659index 7e73e8c..11d3b86 100644
30660--- a/arch/x86/mm/hugetlbpage.c
30661+++ b/arch/x86/mm/hugetlbpage.c
30662@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30663 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30664 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30665 unsigned long addr, unsigned long len,
30666- unsigned long pgoff, unsigned long flags)
30667+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30668 {
30669 struct hstate *h = hstate_file(file);
30670 struct vm_unmapped_area_info info;
30671-
30672+
30673 info.flags = 0;
30674 info.length = len;
30675 info.low_limit = TASK_UNMAPPED_BASE;
30676+
30677+#ifdef CONFIG_PAX_RANDMMAP
30678+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30679+ info.low_limit += current->mm->delta_mmap;
30680+#endif
30681+
30682 info.high_limit = TASK_SIZE;
30683 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30684 info.align_offset = 0;
30685+ info.threadstack_offset = offset;
30686 return vm_unmapped_area(&info);
30687 }
30688
30689 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30690 unsigned long addr0, unsigned long len,
30691- unsigned long pgoff, unsigned long flags)
30692+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30693 {
30694 struct hstate *h = hstate_file(file);
30695 struct vm_unmapped_area_info info;
30696@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30697 info.high_limit = current->mm->mmap_base;
30698 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30699 info.align_offset = 0;
30700+ info.threadstack_offset = offset;
30701 addr = vm_unmapped_area(&info);
30702
30703 /*
30704@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30705 VM_BUG_ON(addr != -ENOMEM);
30706 info.flags = 0;
30707 info.low_limit = TASK_UNMAPPED_BASE;
30708+
30709+#ifdef CONFIG_PAX_RANDMMAP
30710+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30711+ info.low_limit += current->mm->delta_mmap;
30712+#endif
30713+
30714 info.high_limit = TASK_SIZE;
30715 addr = vm_unmapped_area(&info);
30716 }
30717@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30718 struct hstate *h = hstate_file(file);
30719 struct mm_struct *mm = current->mm;
30720 struct vm_area_struct *vma;
30721+ unsigned long pax_task_size = TASK_SIZE;
30722+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30723
30724 if (len & ~huge_page_mask(h))
30725 return -EINVAL;
30726- if (len > TASK_SIZE)
30727+
30728+#ifdef CONFIG_PAX_SEGMEXEC
30729+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30730+ pax_task_size = SEGMEXEC_TASK_SIZE;
30731+#endif
30732+
30733+ pax_task_size -= PAGE_SIZE;
30734+
30735+ if (len > pax_task_size)
30736 return -ENOMEM;
30737
30738 if (flags & MAP_FIXED) {
30739@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30740 return addr;
30741 }
30742
30743+#ifdef CONFIG_PAX_RANDMMAP
30744+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30745+#endif
30746+
30747 if (addr) {
30748 addr = ALIGN(addr, huge_page_size(h));
30749 vma = find_vma(mm, addr);
30750- if (TASK_SIZE - len >= addr &&
30751- (!vma || addr + len <= vma->vm_start))
30752+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30753 return addr;
30754 }
30755 if (mm->get_unmapped_area == arch_get_unmapped_area)
30756 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30757- pgoff, flags);
30758+ pgoff, flags, offset);
30759 else
30760 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30761- pgoff, flags);
30762+ pgoff, flags, offset);
30763 }
30764
30765 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30766diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30767index 04664cd..dae6e5d 100644
30768--- a/arch/x86/mm/init.c
30769+++ b/arch/x86/mm/init.c
30770@@ -4,6 +4,7 @@
30771 #include <linux/swap.h>
30772 #include <linux/memblock.h>
30773 #include <linux/bootmem.h> /* for max_low_pfn */
30774+#include <linux/tboot.h>
30775
30776 #include <asm/cacheflush.h>
30777 #include <asm/e820.h>
30778@@ -17,6 +18,8 @@
30779 #include <asm/proto.h>
30780 #include <asm/dma.h> /* for MAX_DMA_PFN */
30781 #include <asm/microcode.h>
30782+#include <asm/desc.h>
30783+#include <asm/bios_ebda.h>
30784
30785 #include "mm_internal.h"
30786
30787@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30788 early_ioremap_page_table_range_init();
30789 #endif
30790
30791+#ifdef CONFIG_PAX_PER_CPU_PGD
30792+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30793+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30794+ KERNEL_PGD_PTRS);
30795+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30796+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30797+ KERNEL_PGD_PTRS);
30798+ load_cr3(get_cpu_pgd(0, kernel));
30799+#else
30800 load_cr3(swapper_pg_dir);
30801+#endif
30802+
30803 __flush_tlb_all();
30804
30805 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30806@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30807 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30808 * mmio resources as well as potential bios/acpi data regions.
30809 */
30810+
30811+#ifdef CONFIG_GRKERNSEC_KMEM
30812+static unsigned int ebda_start __read_only;
30813+static unsigned int ebda_end __read_only;
30814+#endif
30815+
30816 int devmem_is_allowed(unsigned long pagenr)
30817 {
30818- if (pagenr < 256)
30819+#ifdef CONFIG_GRKERNSEC_KMEM
30820+ /* allow BDA */
30821+ if (!pagenr)
30822 return 1;
30823+ /* allow EBDA */
30824+ if (pagenr >= ebda_start && pagenr < ebda_end)
30825+ return 1;
30826+ /* if tboot is in use, allow access to its hardcoded serial log range */
30827+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30828+ return 1;
30829+#else
30830+ if (!pagenr)
30831+ return 1;
30832+#ifdef CONFIG_VM86
30833+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30834+ return 1;
30835+#endif
30836+#endif
30837+
30838+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30839+ return 1;
30840+#ifdef CONFIG_GRKERNSEC_KMEM
30841+ /* throw out everything else below 1MB */
30842+ if (pagenr <= 256)
30843+ return 0;
30844+#endif
30845 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30846 return 0;
30847 if (!page_is_ram(pagenr))
30848@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30849 #endif
30850 }
30851
30852+#ifdef CONFIG_GRKERNSEC_KMEM
30853+static inline void gr_init_ebda(void)
30854+{
30855+ unsigned int ebda_addr;
30856+ unsigned int ebda_size = 0;
30857+
30858+ ebda_addr = get_bios_ebda();
30859+ if (ebda_addr) {
30860+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30861+ ebda_size <<= 10;
30862+ }
30863+ if (ebda_addr && ebda_size) {
30864+ ebda_start = ebda_addr >> PAGE_SHIFT;
30865+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30866+ } else {
30867+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30868+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30869+ }
30870+}
30871+#else
30872+static inline void gr_init_ebda(void) { }
30873+#endif
30874+
30875 void free_initmem(void)
30876 {
30877+#ifdef CONFIG_PAX_KERNEXEC
30878+#ifdef CONFIG_X86_32
30879+ /* PaX: limit KERNEL_CS to actual size */
30880+ unsigned long addr, limit;
30881+ struct desc_struct d;
30882+ int cpu;
30883+#else
30884+ pgd_t *pgd;
30885+ pud_t *pud;
30886+ pmd_t *pmd;
30887+ unsigned long addr, end;
30888+#endif
30889+#endif
30890+
30891+ gr_init_ebda();
30892+
30893+#ifdef CONFIG_PAX_KERNEXEC
30894+#ifdef CONFIG_X86_32
30895+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30896+ limit = (limit - 1UL) >> PAGE_SHIFT;
30897+
30898+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30899+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30900+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30901+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30902+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30903+ }
30904+
30905+ /* PaX: make KERNEL_CS read-only */
30906+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30907+ if (!paravirt_enabled())
30908+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30909+/*
30910+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30911+ pgd = pgd_offset_k(addr);
30912+ pud = pud_offset(pgd, addr);
30913+ pmd = pmd_offset(pud, addr);
30914+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30915+ }
30916+*/
30917+#ifdef CONFIG_X86_PAE
30918+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30919+/*
30920+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30921+ pgd = pgd_offset_k(addr);
30922+ pud = pud_offset(pgd, addr);
30923+ pmd = pmd_offset(pud, addr);
30924+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30925+ }
30926+*/
30927+#endif
30928+
30929+#ifdef CONFIG_MODULES
30930+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30931+#endif
30932+
30933+#else
30934+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30935+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30936+ pgd = pgd_offset_k(addr);
30937+ pud = pud_offset(pgd, addr);
30938+ pmd = pmd_offset(pud, addr);
30939+ if (!pmd_present(*pmd))
30940+ continue;
30941+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30942+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30943+ else
30944+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30945+ }
30946+
30947+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30948+ end = addr + KERNEL_IMAGE_SIZE;
30949+ for (; addr < end; addr += PMD_SIZE) {
30950+ pgd = pgd_offset_k(addr);
30951+ pud = pud_offset(pgd, addr);
30952+ pmd = pmd_offset(pud, addr);
30953+ if (!pmd_present(*pmd))
30954+ continue;
30955+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30956+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30957+ }
30958+#endif
30959+
30960+ flush_tlb_all();
30961+#endif
30962+
30963 free_init_pages("unused kernel",
30964 (unsigned long)(&__init_begin),
30965 (unsigned long)(&__init_end));
30966diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30967index 4287f1f..3b99c71 100644
30968--- a/arch/x86/mm/init_32.c
30969+++ b/arch/x86/mm/init_32.c
30970@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30971 bool __read_mostly __vmalloc_start_set = false;
30972
30973 /*
30974- * Creates a middle page table and puts a pointer to it in the
30975- * given global directory entry. This only returns the gd entry
30976- * in non-PAE compilation mode, since the middle layer is folded.
30977- */
30978-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30979-{
30980- pud_t *pud;
30981- pmd_t *pmd_table;
30982-
30983-#ifdef CONFIG_X86_PAE
30984- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30985- pmd_table = (pmd_t *)alloc_low_page();
30986- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30987- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30988- pud = pud_offset(pgd, 0);
30989- BUG_ON(pmd_table != pmd_offset(pud, 0));
30990-
30991- return pmd_table;
30992- }
30993-#endif
30994- pud = pud_offset(pgd, 0);
30995- pmd_table = pmd_offset(pud, 0);
30996-
30997- return pmd_table;
30998-}
30999-
31000-/*
31001 * Create a page table and place a pointer to it in a middle page
31002 * directory entry:
31003 */
31004@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31005 pte_t *page_table = (pte_t *)alloc_low_page();
31006
31007 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31008+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31009+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31010+#else
31011 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31012+#endif
31013 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31014 }
31015
31016 return pte_offset_kernel(pmd, 0);
31017 }
31018
31019+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31020+{
31021+ pud_t *pud;
31022+ pmd_t *pmd_table;
31023+
31024+ pud = pud_offset(pgd, 0);
31025+ pmd_table = pmd_offset(pud, 0);
31026+
31027+ return pmd_table;
31028+}
31029+
31030 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31031 {
31032 int pgd_idx = pgd_index(vaddr);
31033@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31034 int pgd_idx, pmd_idx;
31035 unsigned long vaddr;
31036 pgd_t *pgd;
31037+ pud_t *pud;
31038 pmd_t *pmd;
31039 pte_t *pte = NULL;
31040 unsigned long count = page_table_range_init_count(start, end);
31041@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31042 pgd = pgd_base + pgd_idx;
31043
31044 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31045- pmd = one_md_table_init(pgd);
31046- pmd = pmd + pmd_index(vaddr);
31047+ pud = pud_offset(pgd, vaddr);
31048+ pmd = pmd_offset(pud, vaddr);
31049+
31050+#ifdef CONFIG_X86_PAE
31051+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31052+#endif
31053+
31054 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31055 pmd++, pmd_idx++) {
31056 pte = page_table_kmap_check(one_page_table_init(pmd),
31057@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31058 }
31059 }
31060
31061-static inline int is_kernel_text(unsigned long addr)
31062+static inline int is_kernel_text(unsigned long start, unsigned long end)
31063 {
31064- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31065- return 1;
31066- return 0;
31067+ if ((start > ktla_ktva((unsigned long)_etext) ||
31068+ end <= ktla_ktva((unsigned long)_stext)) &&
31069+ (start > ktla_ktva((unsigned long)_einittext) ||
31070+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31071+
31072+#ifdef CONFIG_ACPI_SLEEP
31073+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31074+#endif
31075+
31076+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31077+ return 0;
31078+ return 1;
31079 }
31080
31081 /*
31082@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31083 unsigned long last_map_addr = end;
31084 unsigned long start_pfn, end_pfn;
31085 pgd_t *pgd_base = swapper_pg_dir;
31086- int pgd_idx, pmd_idx, pte_ofs;
31087+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31088 unsigned long pfn;
31089 pgd_t *pgd;
31090+ pud_t *pud;
31091 pmd_t *pmd;
31092 pte_t *pte;
31093 unsigned pages_2m, pages_4k;
31094@@ -291,8 +295,13 @@ repeat:
31095 pfn = start_pfn;
31096 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31097 pgd = pgd_base + pgd_idx;
31098- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31099- pmd = one_md_table_init(pgd);
31100+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31101+ pud = pud_offset(pgd, 0);
31102+ pmd = pmd_offset(pud, 0);
31103+
31104+#ifdef CONFIG_X86_PAE
31105+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31106+#endif
31107
31108 if (pfn >= end_pfn)
31109 continue;
31110@@ -304,14 +313,13 @@ repeat:
31111 #endif
31112 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31113 pmd++, pmd_idx++) {
31114- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31115+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31116
31117 /*
31118 * Map with big pages if possible, otherwise
31119 * create normal page tables:
31120 */
31121 if (use_pse) {
31122- unsigned int addr2;
31123 pgprot_t prot = PAGE_KERNEL_LARGE;
31124 /*
31125 * first pass will use the same initial
31126@@ -322,11 +330,7 @@ repeat:
31127 _PAGE_PSE);
31128
31129 pfn &= PMD_MASK >> PAGE_SHIFT;
31130- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31131- PAGE_OFFSET + PAGE_SIZE-1;
31132-
31133- if (is_kernel_text(addr) ||
31134- is_kernel_text(addr2))
31135+ if (is_kernel_text(address, address + PMD_SIZE))
31136 prot = PAGE_KERNEL_LARGE_EXEC;
31137
31138 pages_2m++;
31139@@ -343,7 +347,7 @@ repeat:
31140 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31141 pte += pte_ofs;
31142 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31143- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31144+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31145 pgprot_t prot = PAGE_KERNEL;
31146 /*
31147 * first pass will use the same initial
31148@@ -351,7 +355,7 @@ repeat:
31149 */
31150 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31151
31152- if (is_kernel_text(addr))
31153+ if (is_kernel_text(address, address + PAGE_SIZE))
31154 prot = PAGE_KERNEL_EXEC;
31155
31156 pages_4k++;
31157@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31158
31159 pud = pud_offset(pgd, va);
31160 pmd = pmd_offset(pud, va);
31161- if (!pmd_present(*pmd))
31162+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31163 break;
31164
31165 /* should not be large page here */
31166@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31167
31168 static void __init pagetable_init(void)
31169 {
31170- pgd_t *pgd_base = swapper_pg_dir;
31171-
31172- permanent_kmaps_init(pgd_base);
31173+ permanent_kmaps_init(swapper_pg_dir);
31174 }
31175
31176-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31177+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31178 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31179
31180 /* user-defined highmem size */
31181@@ -787,10 +789,10 @@ void __init mem_init(void)
31182 ((unsigned long)&__init_end -
31183 (unsigned long)&__init_begin) >> 10,
31184
31185- (unsigned long)&_etext, (unsigned long)&_edata,
31186- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31187+ (unsigned long)&_sdata, (unsigned long)&_edata,
31188+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31189
31190- (unsigned long)&_text, (unsigned long)&_etext,
31191+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31192 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31193
31194 /*
31195@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31196 if (!kernel_set_to_readonly)
31197 return;
31198
31199+ start = ktla_ktva(start);
31200 pr_debug("Set kernel text: %lx - %lx for read write\n",
31201 start, start+size);
31202
31203@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31204 if (!kernel_set_to_readonly)
31205 return;
31206
31207+ start = ktla_ktva(start);
31208 pr_debug("Set kernel text: %lx - %lx for read only\n",
31209 start, start+size);
31210
31211@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31212 unsigned long start = PFN_ALIGN(_text);
31213 unsigned long size = PFN_ALIGN(_etext) - start;
31214
31215+ start = ktla_ktva(start);
31216 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31217 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31218 size >> 10);
31219diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31220index 104d56a..62ba13f 100644
31221--- a/arch/x86/mm/init_64.c
31222+++ b/arch/x86/mm/init_64.c
31223@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31224 * around without checking the pgd every time.
31225 */
31226
31227-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31228+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31229 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31230
31231 int force_personality32;
31232@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31233
31234 for (address = start; address <= end; address += PGDIR_SIZE) {
31235 const pgd_t *pgd_ref = pgd_offset_k(address);
31236+
31237+#ifdef CONFIG_PAX_PER_CPU_PGD
31238+ unsigned long cpu;
31239+#else
31240 struct page *page;
31241+#endif
31242
31243 if (pgd_none(*pgd_ref))
31244 continue;
31245
31246 spin_lock(&pgd_lock);
31247+
31248+#ifdef CONFIG_PAX_PER_CPU_PGD
31249+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31250+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31251+
31252+ if (pgd_none(*pgd))
31253+ set_pgd(pgd, *pgd_ref);
31254+ else
31255+ BUG_ON(pgd_page_vaddr(*pgd)
31256+ != pgd_page_vaddr(*pgd_ref));
31257+ pgd = pgd_offset_cpu(cpu, kernel, address);
31258+#else
31259 list_for_each_entry(page, &pgd_list, lru) {
31260 pgd_t *pgd;
31261 spinlock_t *pgt_lock;
31262@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31263 /* the pgt_lock only for Xen */
31264 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31265 spin_lock(pgt_lock);
31266+#endif
31267
31268 if (pgd_none(*pgd))
31269 set_pgd(pgd, *pgd_ref);
31270@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31271 BUG_ON(pgd_page_vaddr(*pgd)
31272 != pgd_page_vaddr(*pgd_ref));
31273
31274+#ifndef CONFIG_PAX_PER_CPU_PGD
31275 spin_unlock(pgt_lock);
31276+#endif
31277+
31278 }
31279 spin_unlock(&pgd_lock);
31280 }
31281@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31282 {
31283 if (pgd_none(*pgd)) {
31284 pud_t *pud = (pud_t *)spp_getpage();
31285- pgd_populate(&init_mm, pgd, pud);
31286+ pgd_populate_kernel(&init_mm, pgd, pud);
31287 if (pud != pud_offset(pgd, 0))
31288 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31289 pud, pud_offset(pgd, 0));
31290@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31291 {
31292 if (pud_none(*pud)) {
31293 pmd_t *pmd = (pmd_t *) spp_getpage();
31294- pud_populate(&init_mm, pud, pmd);
31295+ pud_populate_kernel(&init_mm, pud, pmd);
31296 if (pmd != pmd_offset(pud, 0))
31297 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31298 pmd, pmd_offset(pud, 0));
31299@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31300 pmd = fill_pmd(pud, vaddr);
31301 pte = fill_pte(pmd, vaddr);
31302
31303+ pax_open_kernel();
31304 set_pte(pte, new_pte);
31305+ pax_close_kernel();
31306
31307 /*
31308 * It's enough to flush this one mapping.
31309@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31310 pgd = pgd_offset_k((unsigned long)__va(phys));
31311 if (pgd_none(*pgd)) {
31312 pud = (pud_t *) spp_getpage();
31313- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31314- _PAGE_USER));
31315+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31316 }
31317 pud = pud_offset(pgd, (unsigned long)__va(phys));
31318 if (pud_none(*pud)) {
31319 pmd = (pmd_t *) spp_getpage();
31320- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31321- _PAGE_USER));
31322+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31323 }
31324 pmd = pmd_offset(pud, phys);
31325 BUG_ON(!pmd_none(*pmd));
31326@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31327 prot);
31328
31329 spin_lock(&init_mm.page_table_lock);
31330- pud_populate(&init_mm, pud, pmd);
31331+ pud_populate_kernel(&init_mm, pud, pmd);
31332 spin_unlock(&init_mm.page_table_lock);
31333 }
31334 __flush_tlb_all();
31335@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31336 page_size_mask);
31337
31338 spin_lock(&init_mm.page_table_lock);
31339- pgd_populate(&init_mm, pgd, pud);
31340+ pgd_populate_kernel(&init_mm, pgd, pud);
31341 spin_unlock(&init_mm.page_table_lock);
31342 pgd_changed = true;
31343 }
31344@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31345 static struct vm_area_struct gate_vma = {
31346 .vm_start = VSYSCALL_START,
31347 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31348- .vm_page_prot = PAGE_READONLY_EXEC,
31349- .vm_flags = VM_READ | VM_EXEC
31350+ .vm_page_prot = PAGE_READONLY,
31351+ .vm_flags = VM_READ
31352 };
31353
31354 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31355@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31356
31357 const char *arch_vma_name(struct vm_area_struct *vma)
31358 {
31359- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31360+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31361 return "[vdso]";
31362 if (vma == &gate_vma)
31363 return "[vsyscall]";
31364diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31365index 7b179b4..6bd17777 100644
31366--- a/arch/x86/mm/iomap_32.c
31367+++ b/arch/x86/mm/iomap_32.c
31368@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31369 type = kmap_atomic_idx_push();
31370 idx = type + KM_TYPE_NR * smp_processor_id();
31371 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31372+
31373+ pax_open_kernel();
31374 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31375+ pax_close_kernel();
31376+
31377 arch_flush_lazy_mmu_mode();
31378
31379 return (void *)vaddr;
31380diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31381index 0215e2c..1c62dab 100644
31382--- a/arch/x86/mm/ioremap.c
31383+++ b/arch/x86/mm/ioremap.c
31384@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31385 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31386 int is_ram = page_is_ram(pfn);
31387
31388- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31389+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31390 return NULL;
31391 WARN_ON_ONCE(is_ram);
31392 }
31393@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31394 *
31395 * Caller must ensure there is only one unmapping for the same pointer.
31396 */
31397-void iounmap(volatile void __iomem *addr)
31398+void iounmap(const volatile void __iomem *addr)
31399 {
31400 struct vm_struct *p, *o;
31401
31402@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31403
31404 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31405 if (page_is_ram(start >> PAGE_SHIFT))
31406+#ifdef CONFIG_HIGHMEM
31407+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31408+#endif
31409 return __va(phys);
31410
31411 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31412@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31413 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31414 {
31415 if (page_is_ram(phys >> PAGE_SHIFT))
31416+#ifdef CONFIG_HIGHMEM
31417+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31418+#endif
31419 return;
31420
31421 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31422@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31423 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31424
31425 static __initdata int after_paging_init;
31426-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31427+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31428
31429 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31430 {
31431@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31432 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31433
31434 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31435- memset(bm_pte, 0, sizeof(bm_pte));
31436- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31437+ pmd_populate_user(&init_mm, pmd, bm_pte);
31438
31439 /*
31440 * The boot-ioremap range spans multiple pmds, for which
31441diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31442index d87dd6d..bf3fa66 100644
31443--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31444+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31445@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31446 * memory (e.g. tracked pages)? For now, we need this to avoid
31447 * invoking kmemcheck for PnP BIOS calls.
31448 */
31449- if (regs->flags & X86_VM_MASK)
31450+ if (v8086_mode(regs))
31451 return false;
31452- if (regs->cs != __KERNEL_CS)
31453+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31454 return false;
31455
31456 pte = kmemcheck_pte_lookup(address);
31457diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31458index 25e7e13..1964579 100644
31459--- a/arch/x86/mm/mmap.c
31460+++ b/arch/x86/mm/mmap.c
31461@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31462 * Leave an at least ~128 MB hole with possible stack randomization.
31463 */
31464 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31465-#define MAX_GAP (TASK_SIZE/6*5)
31466+#define MAX_GAP (pax_task_size/6*5)
31467
31468 static int mmap_is_legacy(void)
31469 {
31470@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31471 return rnd << PAGE_SHIFT;
31472 }
31473
31474-static unsigned long mmap_base(void)
31475+static unsigned long mmap_base(struct mm_struct *mm)
31476 {
31477 unsigned long gap = rlimit(RLIMIT_STACK);
31478+ unsigned long pax_task_size = TASK_SIZE;
31479+
31480+#ifdef CONFIG_PAX_SEGMEXEC
31481+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31482+ pax_task_size = SEGMEXEC_TASK_SIZE;
31483+#endif
31484
31485 if (gap < MIN_GAP)
31486 gap = MIN_GAP;
31487 else if (gap > MAX_GAP)
31488 gap = MAX_GAP;
31489
31490- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31491+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31492 }
31493
31494 /*
31495 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31496 * does, but not when emulating X86_32
31497 */
31498-static unsigned long mmap_legacy_base(void)
31499+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31500 {
31501- if (mmap_is_ia32())
31502+ if (mmap_is_ia32()) {
31503+
31504+#ifdef CONFIG_PAX_SEGMEXEC
31505+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31506+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31507+ else
31508+#endif
31509+
31510 return TASK_UNMAPPED_BASE;
31511- else
31512+ } else
31513 return TASK_UNMAPPED_BASE + mmap_rnd();
31514 }
31515
31516@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31517 */
31518 void arch_pick_mmap_layout(struct mm_struct *mm)
31519 {
31520- mm->mmap_legacy_base = mmap_legacy_base();
31521- mm->mmap_base = mmap_base();
31522+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31523+ mm->mmap_base = mmap_base(mm);
31524+
31525+#ifdef CONFIG_PAX_RANDMMAP
31526+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31527+ mm->mmap_legacy_base += mm->delta_mmap;
31528+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31529+ }
31530+#endif
31531
31532 if (mmap_is_legacy()) {
31533 mm->mmap_base = mm->mmap_legacy_base;
31534diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31535index 0057a7a..95c7edd 100644
31536--- a/arch/x86/mm/mmio-mod.c
31537+++ b/arch/x86/mm/mmio-mod.c
31538@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31539 break;
31540 default:
31541 {
31542- unsigned char *ip = (unsigned char *)instptr;
31543+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31544 my_trace->opcode = MMIO_UNKNOWN_OP;
31545 my_trace->width = 0;
31546 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31547@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31548 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31549 void __iomem *addr)
31550 {
31551- static atomic_t next_id;
31552+ static atomic_unchecked_t next_id;
31553 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31554 /* These are page-unaligned. */
31555 struct mmiotrace_map map = {
31556@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31557 .private = trace
31558 },
31559 .phys = offset,
31560- .id = atomic_inc_return(&next_id)
31561+ .id = atomic_inc_return_unchecked(&next_id)
31562 };
31563 map.map_id = trace->id;
31564
31565@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31566 ioremap_trace_core(offset, size, addr);
31567 }
31568
31569-static void iounmap_trace_core(volatile void __iomem *addr)
31570+static void iounmap_trace_core(const volatile void __iomem *addr)
31571 {
31572 struct mmiotrace_map map = {
31573 .phys = 0,
31574@@ -328,7 +328,7 @@ not_enabled:
31575 }
31576 }
31577
31578-void mmiotrace_iounmap(volatile void __iomem *addr)
31579+void mmiotrace_iounmap(const volatile void __iomem *addr)
31580 {
31581 might_sleep();
31582 if (is_enabled()) /* recheck and proper locking in *_core() */
31583diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31584index 8bf93ba..dbcd670 100644
31585--- a/arch/x86/mm/numa.c
31586+++ b/arch/x86/mm/numa.c
31587@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31588 return true;
31589 }
31590
31591-static int __init numa_register_memblks(struct numa_meminfo *mi)
31592+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31593 {
31594 unsigned long uninitialized_var(pfn_align);
31595 int i, nid;
31596diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31597index d0b1773..4c3327c 100644
31598--- a/arch/x86/mm/pageattr-test.c
31599+++ b/arch/x86/mm/pageattr-test.c
31600@@ -36,7 +36,7 @@ enum {
31601
31602 static int pte_testbit(pte_t pte)
31603 {
31604- return pte_flags(pte) & _PAGE_UNUSED1;
31605+ return pte_flags(pte) & _PAGE_CPA_TEST;
31606 }
31607
31608 struct split_state {
31609diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31610index bb32480..75f2f5e 100644
31611--- a/arch/x86/mm/pageattr.c
31612+++ b/arch/x86/mm/pageattr.c
31613@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31614 */
31615 #ifdef CONFIG_PCI_BIOS
31616 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31617- pgprot_val(forbidden) |= _PAGE_NX;
31618+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31619 #endif
31620
31621 /*
31622@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31623 * Does not cover __inittext since that is gone later on. On
31624 * 64bit we do not enforce !NX on the low mapping
31625 */
31626- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31627- pgprot_val(forbidden) |= _PAGE_NX;
31628+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31629+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31630
31631+#ifdef CONFIG_DEBUG_RODATA
31632 /*
31633 * The .rodata section needs to be read-only. Using the pfn
31634 * catches all aliases.
31635@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31636 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31637 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31638 pgprot_val(forbidden) |= _PAGE_RW;
31639+#endif
31640
31641 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31642 /*
31643@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31644 }
31645 #endif
31646
31647+#ifdef CONFIG_PAX_KERNEXEC
31648+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31649+ pgprot_val(forbidden) |= _PAGE_RW;
31650+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31651+ }
31652+#endif
31653+
31654 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31655
31656 return prot;
31657@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31658 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31659 {
31660 /* change init_mm */
31661+ pax_open_kernel();
31662 set_pte_atomic(kpte, pte);
31663+
31664 #ifdef CONFIG_X86_32
31665 if (!SHARED_KERNEL_PMD) {
31666+
31667+#ifdef CONFIG_PAX_PER_CPU_PGD
31668+ unsigned long cpu;
31669+#else
31670 struct page *page;
31671+#endif
31672
31673+#ifdef CONFIG_PAX_PER_CPU_PGD
31674+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31675+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31676+#else
31677 list_for_each_entry(page, &pgd_list, lru) {
31678- pgd_t *pgd;
31679+ pgd_t *pgd = (pgd_t *)page_address(page);
31680+#endif
31681+
31682 pud_t *pud;
31683 pmd_t *pmd;
31684
31685- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31686+ pgd += pgd_index(address);
31687 pud = pud_offset(pgd, address);
31688 pmd = pmd_offset(pud, address);
31689 set_pte_atomic((pte_t *)pmd, pte);
31690 }
31691 }
31692 #endif
31693+ pax_close_kernel();
31694 }
31695
31696 static int
31697diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31698index 6574388..87e9bef 100644
31699--- a/arch/x86/mm/pat.c
31700+++ b/arch/x86/mm/pat.c
31701@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31702
31703 if (!entry) {
31704 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31705- current->comm, current->pid, start, end - 1);
31706+ current->comm, task_pid_nr(current), start, end - 1);
31707 return -EINVAL;
31708 }
31709
31710@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31711
31712 while (cursor < to) {
31713 if (!devmem_is_allowed(pfn)) {
31714- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31715- current->comm, from, to - 1);
31716+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31717+ current->comm, from, to - 1, cursor);
31718 return 0;
31719 }
31720 cursor += PAGE_SIZE;
31721@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31722 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31723 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31724 "for [mem %#010Lx-%#010Lx]\n",
31725- current->comm, current->pid,
31726+ current->comm, task_pid_nr(current),
31727 cattr_name(flags),
31728 base, (unsigned long long)(base + size-1));
31729 return -EINVAL;
31730@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31731 flags = lookup_memtype(paddr);
31732 if (want_flags != flags) {
31733 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31734- current->comm, current->pid,
31735+ current->comm, task_pid_nr(current),
31736 cattr_name(want_flags),
31737 (unsigned long long)paddr,
31738 (unsigned long long)(paddr + size - 1),
31739@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31740 free_memtype(paddr, paddr + size);
31741 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31742 " for [mem %#010Lx-%#010Lx], got %s\n",
31743- current->comm, current->pid,
31744+ current->comm, task_pid_nr(current),
31745 cattr_name(want_flags),
31746 (unsigned long long)paddr,
31747 (unsigned long long)(paddr + size - 1),
31748diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31749index 415f6c4..d319983 100644
31750--- a/arch/x86/mm/pat_rbtree.c
31751+++ b/arch/x86/mm/pat_rbtree.c
31752@@ -160,7 +160,7 @@ success:
31753
31754 failure:
31755 printk(KERN_INFO "%s:%d conflicting memory types "
31756- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31757+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31758 end, cattr_name(found_type), cattr_name(match->type));
31759 return -EBUSY;
31760 }
31761diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31762index 9f0614d..92ae64a 100644
31763--- a/arch/x86/mm/pf_in.c
31764+++ b/arch/x86/mm/pf_in.c
31765@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31766 int i;
31767 enum reason_type rv = OTHERS;
31768
31769- p = (unsigned char *)ins_addr;
31770+ p = (unsigned char *)ktla_ktva(ins_addr);
31771 p += skip_prefix(p, &prf);
31772 p += get_opcode(p, &opcode);
31773
31774@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31775 struct prefix_bits prf;
31776 int i;
31777
31778- p = (unsigned char *)ins_addr;
31779+ p = (unsigned char *)ktla_ktva(ins_addr);
31780 p += skip_prefix(p, &prf);
31781 p += get_opcode(p, &opcode);
31782
31783@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31784 struct prefix_bits prf;
31785 int i;
31786
31787- p = (unsigned char *)ins_addr;
31788+ p = (unsigned char *)ktla_ktva(ins_addr);
31789 p += skip_prefix(p, &prf);
31790 p += get_opcode(p, &opcode);
31791
31792@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31793 struct prefix_bits prf;
31794 int i;
31795
31796- p = (unsigned char *)ins_addr;
31797+ p = (unsigned char *)ktla_ktva(ins_addr);
31798 p += skip_prefix(p, &prf);
31799 p += get_opcode(p, &opcode);
31800 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31801@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31802 struct prefix_bits prf;
31803 int i;
31804
31805- p = (unsigned char *)ins_addr;
31806+ p = (unsigned char *)ktla_ktva(ins_addr);
31807 p += skip_prefix(p, &prf);
31808 p += get_opcode(p, &opcode);
31809 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31810diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31811index dfa537a..fd45c64 100644
31812--- a/arch/x86/mm/pgtable.c
31813+++ b/arch/x86/mm/pgtable.c
31814@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31815 list_del(&page->lru);
31816 }
31817
31818-#define UNSHARED_PTRS_PER_PGD \
31819- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31821+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31822
31823+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31824+{
31825+ unsigned int count = USER_PGD_PTRS;
31826
31827+ if (!pax_user_shadow_base)
31828+ return;
31829+
31830+ while (count--)
31831+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31832+}
31833+#endif
31834+
31835+#ifdef CONFIG_PAX_PER_CPU_PGD
31836+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31837+{
31838+ unsigned int count = USER_PGD_PTRS;
31839+
31840+ while (count--) {
31841+ pgd_t pgd;
31842+
31843+#ifdef CONFIG_X86_64
31844+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31845+#else
31846+ pgd = *src++;
31847+#endif
31848+
31849+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31850+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31851+#endif
31852+
31853+ *dst++ = pgd;
31854+ }
31855+
31856+}
31857+#endif
31858+
31859+#ifdef CONFIG_X86_64
31860+#define pxd_t pud_t
31861+#define pyd_t pgd_t
31862+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31863+#define pxd_free(mm, pud) pud_free((mm), (pud))
31864+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31865+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31866+#define PYD_SIZE PGDIR_SIZE
31867+#else
31868+#define pxd_t pmd_t
31869+#define pyd_t pud_t
31870+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31871+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31872+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31873+#define pyd_offset(mm, address) pud_offset((mm), (address))
31874+#define PYD_SIZE PUD_SIZE
31875+#endif
31876+
31877+#ifdef CONFIG_PAX_PER_CPU_PGD
31878+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31879+static inline void pgd_dtor(pgd_t *pgd) {}
31880+#else
31881 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31882 {
31883 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31884@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31885 pgd_list_del(pgd);
31886 spin_unlock(&pgd_lock);
31887 }
31888+#endif
31889
31890 /*
31891 * List of all pgd's needed for non-PAE so it can invalidate entries
31892@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31893 * -- nyc
31894 */
31895
31896-#ifdef CONFIG_X86_PAE
31897+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31898 /*
31899 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31900 * updating the top-level pagetable entries to guarantee the
31901@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31902 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31903 * and initialize the kernel pmds here.
31904 */
31905-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31906+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31907
31908 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31909 {
31910@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31911 */
31912 flush_tlb_mm(mm);
31913 }
31914+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31915+#define PREALLOCATED_PXDS USER_PGD_PTRS
31916 #else /* !CONFIG_X86_PAE */
31917
31918 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31919-#define PREALLOCATED_PMDS 0
31920+#define PREALLOCATED_PXDS 0
31921
31922 #endif /* CONFIG_X86_PAE */
31923
31924-static void free_pmds(pmd_t *pmds[])
31925+static void free_pxds(pxd_t *pxds[])
31926 {
31927 int i;
31928
31929- for(i = 0; i < PREALLOCATED_PMDS; i++)
31930- if (pmds[i])
31931- free_page((unsigned long)pmds[i]);
31932+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31933+ if (pxds[i])
31934+ free_page((unsigned long)pxds[i]);
31935 }
31936
31937-static int preallocate_pmds(pmd_t *pmds[])
31938+static int preallocate_pxds(pxd_t *pxds[])
31939 {
31940 int i;
31941 bool failed = false;
31942
31943- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31944- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31945- if (pmd == NULL)
31946+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31947+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31948+ if (pxd == NULL)
31949 failed = true;
31950- pmds[i] = pmd;
31951+ pxds[i] = pxd;
31952 }
31953
31954 if (failed) {
31955- free_pmds(pmds);
31956+ free_pxds(pxds);
31957 return -ENOMEM;
31958 }
31959
31960@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31961 * preallocate which never got a corresponding vma will need to be
31962 * freed manually.
31963 */
31964-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31965+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31966 {
31967 int i;
31968
31969- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31970+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31971 pgd_t pgd = pgdp[i];
31972
31973 if (pgd_val(pgd) != 0) {
31974- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31975+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31976
31977- pgdp[i] = native_make_pgd(0);
31978+ set_pgd(pgdp + i, native_make_pgd(0));
31979
31980- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31981- pmd_free(mm, pmd);
31982+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31983+ pxd_free(mm, pxd);
31984 }
31985 }
31986 }
31987
31988-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31989+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31990 {
31991- pud_t *pud;
31992+ pyd_t *pyd;
31993 int i;
31994
31995- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31996+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31997 return;
31998
31999- pud = pud_offset(pgd, 0);
32000-
32001- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32002- pmd_t *pmd = pmds[i];
32003+#ifdef CONFIG_X86_64
32004+ pyd = pyd_offset(mm, 0L);
32005+#else
32006+ pyd = pyd_offset(pgd, 0L);
32007+#endif
32008
32009+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32010+ pxd_t *pxd = pxds[i];
32011 if (i >= KERNEL_PGD_BOUNDARY)
32012- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32013- sizeof(pmd_t) * PTRS_PER_PMD);
32014+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32015+ sizeof(pxd_t) * PTRS_PER_PMD);
32016
32017- pud_populate(mm, pud, pmd);
32018+ pyd_populate(mm, pyd, pxd);
32019 }
32020 }
32021
32022 pgd_t *pgd_alloc(struct mm_struct *mm)
32023 {
32024 pgd_t *pgd;
32025- pmd_t *pmds[PREALLOCATED_PMDS];
32026+ pxd_t *pxds[PREALLOCATED_PXDS];
32027
32028 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32029
32030@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32031
32032 mm->pgd = pgd;
32033
32034- if (preallocate_pmds(pmds) != 0)
32035+ if (preallocate_pxds(pxds) != 0)
32036 goto out_free_pgd;
32037
32038 if (paravirt_pgd_alloc(mm) != 0)
32039- goto out_free_pmds;
32040+ goto out_free_pxds;
32041
32042 /*
32043 * Make sure that pre-populating the pmds is atomic with
32044@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32045 spin_lock(&pgd_lock);
32046
32047 pgd_ctor(mm, pgd);
32048- pgd_prepopulate_pmd(mm, pgd, pmds);
32049+ pgd_prepopulate_pxd(mm, pgd, pxds);
32050
32051 spin_unlock(&pgd_lock);
32052
32053 return pgd;
32054
32055-out_free_pmds:
32056- free_pmds(pmds);
32057+out_free_pxds:
32058+ free_pxds(pxds);
32059 out_free_pgd:
32060 free_page((unsigned long)pgd);
32061 out:
32062@@ -300,7 +363,7 @@ out:
32063
32064 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32065 {
32066- pgd_mop_up_pmds(mm, pgd);
32067+ pgd_mop_up_pxds(mm, pgd);
32068 pgd_dtor(pgd);
32069 paravirt_pgd_free(mm, pgd);
32070 free_page((unsigned long)pgd);
32071diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32072index a69bcb8..19068ab 100644
32073--- a/arch/x86/mm/pgtable_32.c
32074+++ b/arch/x86/mm/pgtable_32.c
32075@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32076 return;
32077 }
32078 pte = pte_offset_kernel(pmd, vaddr);
32079+
32080+ pax_open_kernel();
32081 if (pte_val(pteval))
32082 set_pte_at(&init_mm, vaddr, pte, pteval);
32083 else
32084 pte_clear(&init_mm, vaddr, pte);
32085+ pax_close_kernel();
32086
32087 /*
32088 * It's enough to flush this one mapping.
32089diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32090index e666cbb..61788c45 100644
32091--- a/arch/x86/mm/physaddr.c
32092+++ b/arch/x86/mm/physaddr.c
32093@@ -10,7 +10,7 @@
32094 #ifdef CONFIG_X86_64
32095
32096 #ifdef CONFIG_DEBUG_VIRTUAL
32097-unsigned long __phys_addr(unsigned long x)
32098+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32099 {
32100 unsigned long y = x - __START_KERNEL_map;
32101
32102@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32103 #else
32104
32105 #ifdef CONFIG_DEBUG_VIRTUAL
32106-unsigned long __phys_addr(unsigned long x)
32107+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32108 {
32109 unsigned long phys_addr = x - PAGE_OFFSET;
32110 /* VMALLOC_* aren't constants */
32111diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32112index 90555bf..f5f1828 100644
32113--- a/arch/x86/mm/setup_nx.c
32114+++ b/arch/x86/mm/setup_nx.c
32115@@ -5,8 +5,10 @@
32116 #include <asm/pgtable.h>
32117 #include <asm/proto.h>
32118
32119+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32120 static int disable_nx;
32121
32122+#ifndef CONFIG_PAX_PAGEEXEC
32123 /*
32124 * noexec = on|off
32125 *
32126@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32127 return 0;
32128 }
32129 early_param("noexec", noexec_setup);
32130+#endif
32131+
32132+#endif
32133
32134 void x86_configure_nx(void)
32135 {
32136+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32137 if (cpu_has_nx && !disable_nx)
32138 __supported_pte_mask |= _PAGE_NX;
32139 else
32140+#endif
32141 __supported_pte_mask &= ~_PAGE_NX;
32142 }
32143
32144diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32145index 282375f..e03a98f 100644
32146--- a/arch/x86/mm/tlb.c
32147+++ b/arch/x86/mm/tlb.c
32148@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32149 BUG();
32150 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32151 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32152+
32153+#ifndef CONFIG_PAX_PER_CPU_PGD
32154 load_cr3(swapper_pg_dir);
32155+#endif
32156+
32157 }
32158 }
32159 EXPORT_SYMBOL_GPL(leave_mm);
32160diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32161new file mode 100644
32162index 0000000..dace51c
32163--- /dev/null
32164+++ b/arch/x86/mm/uderef_64.c
32165@@ -0,0 +1,37 @@
32166+#include <linux/mm.h>
32167+#include <asm/pgtable.h>
32168+#include <asm/uaccess.h>
32169+
32170+#ifdef CONFIG_PAX_MEMORY_UDEREF
32171+/* PaX: due to the special call convention these functions must
32172+ * - remain leaf functions under all configurations,
32173+ * - never be called directly, only dereferenced from the wrappers.
32174+ */
32175+void __pax_open_userland(void)
32176+{
32177+ unsigned int cpu;
32178+
32179+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32180+ return;
32181+
32182+ cpu = raw_get_cpu();
32183+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32184+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32185+ raw_put_cpu_no_resched();
32186+}
32187+EXPORT_SYMBOL(__pax_open_userland);
32188+
32189+void __pax_close_userland(void)
32190+{
32191+ unsigned int cpu;
32192+
32193+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32194+ return;
32195+
32196+ cpu = raw_get_cpu();
32197+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32198+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32199+ raw_put_cpu_no_resched();
32200+}
32201+EXPORT_SYMBOL(__pax_close_userland);
32202+#endif
32203diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32204index 877b9a1..a8ecf42 100644
32205--- a/arch/x86/net/bpf_jit.S
32206+++ b/arch/x86/net/bpf_jit.S
32207@@ -9,6 +9,7 @@
32208 */
32209 #include <linux/linkage.h>
32210 #include <asm/dwarf2.h>
32211+#include <asm/alternative-asm.h>
32212
32213 /*
32214 * Calling convention :
32215@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32216 jle bpf_slow_path_word
32217 mov (SKBDATA,%rsi),%eax
32218 bswap %eax /* ntohl() */
32219+ pax_force_retaddr
32220 ret
32221
32222 sk_load_half:
32223@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32224 jle bpf_slow_path_half
32225 movzwl (SKBDATA,%rsi),%eax
32226 rol $8,%ax # ntohs()
32227+ pax_force_retaddr
32228 ret
32229
32230 sk_load_byte:
32231@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32232 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32233 jle bpf_slow_path_byte
32234 movzbl (SKBDATA,%rsi),%eax
32235+ pax_force_retaddr
32236 ret
32237
32238 /**
32239@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32240 movzbl (SKBDATA,%rsi),%ebx
32241 and $15,%bl
32242 shl $2,%bl
32243+ pax_force_retaddr
32244 ret
32245
32246 /* rsi contains offset and can be scratched */
32247@@ -109,6 +114,7 @@ bpf_slow_path_word:
32248 js bpf_error
32249 mov -12(%rbp),%eax
32250 bswap %eax
32251+ pax_force_retaddr
32252 ret
32253
32254 bpf_slow_path_half:
32255@@ -117,12 +123,14 @@ bpf_slow_path_half:
32256 mov -12(%rbp),%ax
32257 rol $8,%ax
32258 movzwl %ax,%eax
32259+ pax_force_retaddr
32260 ret
32261
32262 bpf_slow_path_byte:
32263 bpf_slow_path_common(1)
32264 js bpf_error
32265 movzbl -12(%rbp),%eax
32266+ pax_force_retaddr
32267 ret
32268
32269 bpf_slow_path_byte_msh:
32270@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32271 and $15,%al
32272 shl $2,%al
32273 xchg %eax,%ebx
32274+ pax_force_retaddr
32275 ret
32276
32277 #define sk_negative_common(SIZE) \
32278@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32279 sk_negative_common(4)
32280 mov (%rax), %eax
32281 bswap %eax
32282+ pax_force_retaddr
32283 ret
32284
32285 bpf_slow_path_half_neg:
32286@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32287 mov (%rax),%ax
32288 rol $8,%ax
32289 movzwl %ax,%eax
32290+ pax_force_retaddr
32291 ret
32292
32293 bpf_slow_path_byte_neg:
32294@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32295 .globl sk_load_byte_negative_offset
32296 sk_negative_common(1)
32297 movzbl (%rax), %eax
32298+ pax_force_retaddr
32299 ret
32300
32301 bpf_slow_path_byte_msh_neg:
32302@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32303 and $15,%al
32304 shl $2,%al
32305 xchg %eax,%ebx
32306+ pax_force_retaddr
32307 ret
32308
32309 bpf_error:
32310@@ -197,4 +210,5 @@ bpf_error:
32311 xor %eax,%eax
32312 mov -8(%rbp),%rbx
32313 leaveq
32314+ pax_force_retaddr
32315 ret
32316diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32317index 79c216a..08d39cc 100644
32318--- a/arch/x86/net/bpf_jit_comp.c
32319+++ b/arch/x86/net/bpf_jit_comp.c
32320@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32321 return ptr + len;
32322 }
32323
32324+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32325+#define MAX_INSTR_CODE_SIZE 96
32326+#else
32327+#define MAX_INSTR_CODE_SIZE 64
32328+#endif
32329+
32330 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32331
32332 #define EMIT1(b1) EMIT(b1, 1)
32333 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32334 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32335 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32336+
32337+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32338+/* original constant will appear in ecx */
32339+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32340+do { \
32341+ /* mov ecx, randkey */ \
32342+ EMIT1(0xb9); \
32343+ EMIT(_key, 4); \
32344+ /* xor ecx, randkey ^ off */ \
32345+ EMIT2(0x81, 0xf1); \
32346+ EMIT((_key) ^ (_off), 4); \
32347+} while (0)
32348+
32349+#define EMIT1_off32(b1, _off) \
32350+do { \
32351+ switch (b1) { \
32352+ case 0x05: /* add eax, imm32 */ \
32353+ case 0x2d: /* sub eax, imm32 */ \
32354+ case 0x25: /* and eax, imm32 */ \
32355+ case 0x0d: /* or eax, imm32 */ \
32356+ case 0xb8: /* mov eax, imm32 */ \
32357+ case 0x35: /* xor eax, imm32 */ \
32358+ case 0x3d: /* cmp eax, imm32 */ \
32359+ case 0xa9: /* test eax, imm32 */ \
32360+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32361+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32362+ break; \
32363+ case 0xbb: /* mov ebx, imm32 */ \
32364+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32365+ /* mov ebx, ecx */ \
32366+ EMIT2(0x89, 0xcb); \
32367+ break; \
32368+ case 0xbe: /* mov esi, imm32 */ \
32369+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32370+ /* mov esi, ecx */ \
32371+ EMIT2(0x89, 0xce); \
32372+ break; \
32373+ case 0xe8: /* call rel imm32, always to known funcs */ \
32374+ EMIT1(b1); \
32375+ EMIT(_off, 4); \
32376+ break; \
32377+ case 0xe9: /* jmp rel imm32 */ \
32378+ EMIT1(b1); \
32379+ EMIT(_off, 4); \
32380+ /* prevent fall-through, we're not called if off = 0 */ \
32381+ EMIT(0xcccccccc, 4); \
32382+ EMIT(0xcccccccc, 4); \
32383+ break; \
32384+ default: \
32385+ BUILD_BUG(); \
32386+ } \
32387+} while (0)
32388+
32389+#define EMIT2_off32(b1, b2, _off) \
32390+do { \
32391+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32392+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32393+ EMIT(randkey, 4); \
32394+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32395+ EMIT((_off) - randkey, 4); \
32396+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32397+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32398+ /* imul eax, ecx */ \
32399+ EMIT3(0x0f, 0xaf, 0xc1); \
32400+ } else { \
32401+ BUILD_BUG(); \
32402+ } \
32403+} while (0)
32404+#else
32405 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32406+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32407+#endif
32408
32409 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32410 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32411@@ -91,6 +168,24 @@ do { \
32412 #define X86_JBE 0x76
32413 #define X86_JA 0x77
32414
32415+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32416+#define APPEND_FLOW_VERIFY() \
32417+do { \
32418+ /* mov ecx, randkey */ \
32419+ EMIT1(0xb9); \
32420+ EMIT(randkey, 4); \
32421+ /* cmp ecx, randkey */ \
32422+ EMIT2(0x81, 0xf9); \
32423+ EMIT(randkey, 4); \
32424+ /* jz after 8 int 3s */ \
32425+ EMIT2(0x74, 0x08); \
32426+ EMIT(0xcccccccc, 4); \
32427+ EMIT(0xcccccccc, 4); \
32428+} while (0)
32429+#else
32430+#define APPEND_FLOW_VERIFY() do { } while (0)
32431+#endif
32432+
32433 #define EMIT_COND_JMP(op, offset) \
32434 do { \
32435 if (is_near(offset)) \
32436@@ -98,6 +193,7 @@ do { \
32437 else { \
32438 EMIT2(0x0f, op + 0x10); \
32439 EMIT(offset, 4); /* jxx .+off32 */ \
32440+ APPEND_FLOW_VERIFY(); \
32441 } \
32442 } while (0)
32443
32444@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32445 return -1;
32446 }
32447
32448-struct bpf_binary_header {
32449- unsigned int pages;
32450- /* Note : for security reasons, bpf code will follow a randomly
32451- * sized amount of int3 instructions
32452- */
32453- u8 image[];
32454-};
32455-
32456-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32457+/* Note : for security reasons, bpf code will follow a randomly
32458+ * sized amount of int3 instructions
32459+ */
32460+static u8 *bpf_alloc_binary(unsigned int proglen,
32461 u8 **image_ptr)
32462 {
32463 unsigned int sz, hole;
32464- struct bpf_binary_header *header;
32465+ u8 *header;
32466
32467 /* Most of BPF filters are really small,
32468 * but if some of them fill a page, allow at least
32469 * 128 extra bytes to insert a random section of int3
32470 */
32471- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32472- header = module_alloc(sz);
32473+ sz = round_up(proglen + 128, PAGE_SIZE);
32474+ header = module_alloc_exec(sz);
32475 if (!header)
32476 return NULL;
32477
32478+ pax_open_kernel();
32479 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32480+ pax_close_kernel();
32481
32482- header->pages = sz / PAGE_SIZE;
32483- hole = sz - (proglen + sizeof(*header));
32484+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32485
32486 /* insert a random number of int3 instructions before BPF code */
32487- *image_ptr = &header->image[prandom_u32() % hole];
32488+ *image_ptr = &header[prandom_u32() % hole];
32489 return header;
32490 }
32491
32492 void bpf_jit_compile(struct sk_filter *fp)
32493 {
32494- u8 temp[64];
32495+ u8 temp[MAX_INSTR_CODE_SIZE];
32496 u8 *prog;
32497 unsigned int proglen, oldproglen = 0;
32498 int ilen, i;
32499 int t_offset, f_offset;
32500 u8 t_op, f_op, seen = 0, pass;
32501 u8 *image = NULL;
32502- struct bpf_binary_header *header = NULL;
32503+ u8 *header = NULL;
32504 u8 *func;
32505 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32506 unsigned int cleanup_addr; /* epilogue code offset */
32507 unsigned int *addrs;
32508 const struct sock_filter *filter = fp->insns;
32509 int flen = fp->len;
32510+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32511+ unsigned int randkey;
32512+#endif
32513
32514 if (!bpf_jit_enable)
32515 return;
32516@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32517 if (addrs == NULL)
32518 return;
32519
32520+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32521+ randkey = get_random_int();
32522+#endif
32523+
32524 /* Before first pass, make a rough estimation of addrs[]
32525- * each bpf instruction is translated to less than 64 bytes
32526+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32527 */
32528 for (proglen = 0, i = 0; i < flen; i++) {
32529- proglen += 64;
32530+ proglen += MAX_INSTR_CODE_SIZE;
32531 addrs[i] = proglen;
32532 }
32533 cleanup_addr = proglen; /* epilogue address */
32534@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32535 case BPF_S_ALU_MUL_K: /* A *= K */
32536 if (is_imm8(K))
32537 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32538- else {
32539- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32540- EMIT(K, 4);
32541- }
32542+ else
32543+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32544 break;
32545 case BPF_S_ALU_DIV_X: /* A /= X; */
32546 seen |= SEEN_XREG;
32547@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32548 break;
32549 case BPF_S_ALU_MOD_K: /* A %= K; */
32550 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32551+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32552+ DILUTE_CONST_SEQUENCE(K, randkey);
32553+#else
32554 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32555+#endif
32556 EMIT2(0xf7, 0xf1); /* div %ecx */
32557 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32558 break;
32559 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32560+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32561+ DILUTE_CONST_SEQUENCE(K, randkey);
32562+ // imul rax, rcx
32563+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32564+#else
32565 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32566 EMIT(K, 4);
32567+#endif
32568 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32569 break;
32570 case BPF_S_ALU_AND_X:
32571@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32572 if (is_imm8(K)) {
32573 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32574 } else {
32575- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32576- EMIT(K, 4);
32577+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32578 }
32579 } else {
32580 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32581@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32582 if (unlikely(proglen + ilen > oldproglen)) {
32583 pr_err("bpb_jit_compile fatal error\n");
32584 kfree(addrs);
32585- module_free(NULL, header);
32586+ module_free_exec(NULL, image);
32587 return;
32588 }
32589+ pax_open_kernel();
32590 memcpy(image + proglen, temp, ilen);
32591+ pax_close_kernel();
32592 }
32593 proglen += ilen;
32594 addrs[i] = proglen;
32595@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32596
32597 if (image) {
32598 bpf_flush_icache(header, image + proglen);
32599- set_memory_ro((unsigned long)header, header->pages);
32600 fp->bpf_func = (void *)image;
32601 }
32602 out:
32603@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32604 {
32605 if (fp->bpf_func != sk_run_filter) {
32606 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32607- struct bpf_binary_header *header = (void *)addr;
32608-
32609- set_memory_rw(addr, header->pages);
32610- module_free(NULL, header);
32611+ set_memory_rw(addr, 1);
32612+ module_free_exec(NULL, (void *)addr);
32613 }
32614 }
32615diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32616index d6aa6e8..266395a 100644
32617--- a/arch/x86/oprofile/backtrace.c
32618+++ b/arch/x86/oprofile/backtrace.c
32619@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32620 struct stack_frame_ia32 *fp;
32621 unsigned long bytes;
32622
32623- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32624+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32625 if (bytes != sizeof(bufhead))
32626 return NULL;
32627
32628- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32629+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32630
32631 oprofile_add_trace(bufhead[0].return_address);
32632
32633@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32634 struct stack_frame bufhead[2];
32635 unsigned long bytes;
32636
32637- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32638+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32639 if (bytes != sizeof(bufhead))
32640 return NULL;
32641
32642@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32643 {
32644 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32645
32646- if (!user_mode_vm(regs)) {
32647+ if (!user_mode(regs)) {
32648 unsigned long stack = kernel_stack_pointer(regs);
32649 if (depth)
32650 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32651diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32652index 48768df..ba9143c 100644
32653--- a/arch/x86/oprofile/nmi_int.c
32654+++ b/arch/x86/oprofile/nmi_int.c
32655@@ -23,6 +23,7 @@
32656 #include <asm/nmi.h>
32657 #include <asm/msr.h>
32658 #include <asm/apic.h>
32659+#include <asm/pgtable.h>
32660
32661 #include "op_counter.h"
32662 #include "op_x86_model.h"
32663@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32664 if (ret)
32665 return ret;
32666
32667- if (!model->num_virt_counters)
32668- model->num_virt_counters = model->num_counters;
32669+ if (!model->num_virt_counters) {
32670+ pax_open_kernel();
32671+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32672+ pax_close_kernel();
32673+ }
32674
32675 mux_init(ops);
32676
32677diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32678index b2b9443..be58856 100644
32679--- a/arch/x86/oprofile/op_model_amd.c
32680+++ b/arch/x86/oprofile/op_model_amd.c
32681@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32682 num_counters = AMD64_NUM_COUNTERS;
32683 }
32684
32685- op_amd_spec.num_counters = num_counters;
32686- op_amd_spec.num_controls = num_counters;
32687- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32688+ pax_open_kernel();
32689+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32690+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32691+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32692+ pax_close_kernel();
32693
32694 return 0;
32695 }
32696diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32697index d90528e..0127e2b 100644
32698--- a/arch/x86/oprofile/op_model_ppro.c
32699+++ b/arch/x86/oprofile/op_model_ppro.c
32700@@ -19,6 +19,7 @@
32701 #include <asm/msr.h>
32702 #include <asm/apic.h>
32703 #include <asm/nmi.h>
32704+#include <asm/pgtable.h>
32705
32706 #include "op_x86_model.h"
32707 #include "op_counter.h"
32708@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32709
32710 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32711
32712- op_arch_perfmon_spec.num_counters = num_counters;
32713- op_arch_perfmon_spec.num_controls = num_counters;
32714+ pax_open_kernel();
32715+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32716+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32717+ pax_close_kernel();
32718 }
32719
32720 static int arch_perfmon_init(struct oprofile_operations *ignore)
32721diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32722index 71e8a67..6a313bb 100644
32723--- a/arch/x86/oprofile/op_x86_model.h
32724+++ b/arch/x86/oprofile/op_x86_model.h
32725@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32726 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32727 struct op_msrs const * const msrs);
32728 #endif
32729-};
32730+} __do_const;
32731
32732 struct op_counter_config;
32733
32734diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32735index 372e9b8..e775a6c 100644
32736--- a/arch/x86/pci/irq.c
32737+++ b/arch/x86/pci/irq.c
32738@@ -50,7 +50,7 @@ struct irq_router {
32739 struct irq_router_handler {
32740 u16 vendor;
32741 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32742-};
32743+} __do_const;
32744
32745 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32746 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32747@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32748 return 0;
32749 }
32750
32751-static __initdata struct irq_router_handler pirq_routers[] = {
32752+static __initconst const struct irq_router_handler pirq_routers[] = {
32753 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32754 { PCI_VENDOR_ID_AL, ali_router_probe },
32755 { PCI_VENDOR_ID_ITE, ite_router_probe },
32756@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32757 static void __init pirq_find_router(struct irq_router *r)
32758 {
32759 struct irq_routing_table *rt = pirq_table;
32760- struct irq_router_handler *h;
32761+ const struct irq_router_handler *h;
32762
32763 #ifdef CONFIG_PCI_BIOS
32764 if (!rt->signature) {
32765@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32766 return 0;
32767 }
32768
32769-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32770+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32771 {
32772 .callback = fix_broken_hp_bios_irq9,
32773 .ident = "HP Pavilion N5400 Series Laptop",
32774diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32775index 6eb18c4..20d83de 100644
32776--- a/arch/x86/pci/mrst.c
32777+++ b/arch/x86/pci/mrst.c
32778@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32779 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32780 pci_mmcfg_late_init();
32781 pcibios_enable_irq = mrst_pci_irq_enable;
32782- pci_root_ops = pci_mrst_ops;
32783+ pax_open_kernel();
32784+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32785+ pax_close_kernel();
32786 pci_soc_mode = 1;
32787 /* Continue with standard init */
32788 return 1;
32789diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32790index c77b24a..c979855 100644
32791--- a/arch/x86/pci/pcbios.c
32792+++ b/arch/x86/pci/pcbios.c
32793@@ -79,7 +79,7 @@ union bios32 {
32794 static struct {
32795 unsigned long address;
32796 unsigned short segment;
32797-} bios32_indirect = { 0, __KERNEL_CS };
32798+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32799
32800 /*
32801 * Returns the entry point for the given service, NULL on error
32802@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32803 unsigned long length; /* %ecx */
32804 unsigned long entry; /* %edx */
32805 unsigned long flags;
32806+ struct desc_struct d, *gdt;
32807
32808 local_irq_save(flags);
32809- __asm__("lcall *(%%edi); cld"
32810+
32811+ gdt = get_cpu_gdt_table(smp_processor_id());
32812+
32813+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32814+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32815+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32816+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32817+
32818+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32819 : "=a" (return_code),
32820 "=b" (address),
32821 "=c" (length),
32822 "=d" (entry)
32823 : "0" (service),
32824 "1" (0),
32825- "D" (&bios32_indirect));
32826+ "D" (&bios32_indirect),
32827+ "r"(__PCIBIOS_DS)
32828+ : "memory");
32829+
32830+ pax_open_kernel();
32831+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32832+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32833+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32834+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32835+ pax_close_kernel();
32836+
32837 local_irq_restore(flags);
32838
32839 switch (return_code) {
32840- case 0:
32841- return address + entry;
32842- case 0x80: /* Not present */
32843- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32844- return 0;
32845- default: /* Shouldn't happen */
32846- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32847- service, return_code);
32848+ case 0: {
32849+ int cpu;
32850+ unsigned char flags;
32851+
32852+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32853+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32854+ printk(KERN_WARNING "bios32_service: not valid\n");
32855 return 0;
32856+ }
32857+ address = address + PAGE_OFFSET;
32858+ length += 16UL; /* some BIOSs underreport this... */
32859+ flags = 4;
32860+ if (length >= 64*1024*1024) {
32861+ length >>= PAGE_SHIFT;
32862+ flags |= 8;
32863+ }
32864+
32865+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32866+ gdt = get_cpu_gdt_table(cpu);
32867+ pack_descriptor(&d, address, length, 0x9b, flags);
32868+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32869+ pack_descriptor(&d, address, length, 0x93, flags);
32870+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32871+ }
32872+ return entry;
32873+ }
32874+ case 0x80: /* Not present */
32875+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32876+ return 0;
32877+ default: /* Shouldn't happen */
32878+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32879+ service, return_code);
32880+ return 0;
32881 }
32882 }
32883
32884 static struct {
32885 unsigned long address;
32886 unsigned short segment;
32887-} pci_indirect = { 0, __KERNEL_CS };
32888+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32889
32890-static int pci_bios_present;
32891+static int pci_bios_present __read_only;
32892
32893 static int check_pcibios(void)
32894 {
32895@@ -131,11 +174,13 @@ static int check_pcibios(void)
32896 unsigned long flags, pcibios_entry;
32897
32898 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32899- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32900+ pci_indirect.address = pcibios_entry;
32901
32902 local_irq_save(flags);
32903- __asm__(
32904- "lcall *(%%edi); cld\n\t"
32905+ __asm__("movw %w6, %%ds\n\t"
32906+ "lcall *%%ss:(%%edi); cld\n\t"
32907+ "push %%ss\n\t"
32908+ "pop %%ds\n\t"
32909 "jc 1f\n\t"
32910 "xor %%ah, %%ah\n"
32911 "1:"
32912@@ -144,7 +189,8 @@ static int check_pcibios(void)
32913 "=b" (ebx),
32914 "=c" (ecx)
32915 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32916- "D" (&pci_indirect)
32917+ "D" (&pci_indirect),
32918+ "r" (__PCIBIOS_DS)
32919 : "memory");
32920 local_irq_restore(flags);
32921
32922@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32923
32924 switch (len) {
32925 case 1:
32926- __asm__("lcall *(%%esi); cld\n\t"
32927+ __asm__("movw %w6, %%ds\n\t"
32928+ "lcall *%%ss:(%%esi); cld\n\t"
32929+ "push %%ss\n\t"
32930+ "pop %%ds\n\t"
32931 "jc 1f\n\t"
32932 "xor %%ah, %%ah\n"
32933 "1:"
32934@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32935 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32936 "b" (bx),
32937 "D" ((long)reg),
32938- "S" (&pci_indirect));
32939+ "S" (&pci_indirect),
32940+ "r" (__PCIBIOS_DS));
32941 /*
32942 * Zero-extend the result beyond 8 bits, do not trust the
32943 * BIOS having done it:
32944@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32945 *value &= 0xff;
32946 break;
32947 case 2:
32948- __asm__("lcall *(%%esi); cld\n\t"
32949+ __asm__("movw %w6, %%ds\n\t"
32950+ "lcall *%%ss:(%%esi); cld\n\t"
32951+ "push %%ss\n\t"
32952+ "pop %%ds\n\t"
32953 "jc 1f\n\t"
32954 "xor %%ah, %%ah\n"
32955 "1:"
32956@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32957 : "1" (PCIBIOS_READ_CONFIG_WORD),
32958 "b" (bx),
32959 "D" ((long)reg),
32960- "S" (&pci_indirect));
32961+ "S" (&pci_indirect),
32962+ "r" (__PCIBIOS_DS));
32963 /*
32964 * Zero-extend the result beyond 16 bits, do not trust the
32965 * BIOS having done it:
32966@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32967 *value &= 0xffff;
32968 break;
32969 case 4:
32970- __asm__("lcall *(%%esi); cld\n\t"
32971+ __asm__("movw %w6, %%ds\n\t"
32972+ "lcall *%%ss:(%%esi); cld\n\t"
32973+ "push %%ss\n\t"
32974+ "pop %%ds\n\t"
32975 "jc 1f\n\t"
32976 "xor %%ah, %%ah\n"
32977 "1:"
32978@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32979 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32980 "b" (bx),
32981 "D" ((long)reg),
32982- "S" (&pci_indirect));
32983+ "S" (&pci_indirect),
32984+ "r" (__PCIBIOS_DS));
32985 break;
32986 }
32987
32988@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32989
32990 switch (len) {
32991 case 1:
32992- __asm__("lcall *(%%esi); cld\n\t"
32993+ __asm__("movw %w6, %%ds\n\t"
32994+ "lcall *%%ss:(%%esi); cld\n\t"
32995+ "push %%ss\n\t"
32996+ "pop %%ds\n\t"
32997 "jc 1f\n\t"
32998 "xor %%ah, %%ah\n"
32999 "1:"
33000@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33001 "c" (value),
33002 "b" (bx),
33003 "D" ((long)reg),
33004- "S" (&pci_indirect));
33005+ "S" (&pci_indirect),
33006+ "r" (__PCIBIOS_DS));
33007 break;
33008 case 2:
33009- __asm__("lcall *(%%esi); cld\n\t"
33010+ __asm__("movw %w6, %%ds\n\t"
33011+ "lcall *%%ss:(%%esi); cld\n\t"
33012+ "push %%ss\n\t"
33013+ "pop %%ds\n\t"
33014 "jc 1f\n\t"
33015 "xor %%ah, %%ah\n"
33016 "1:"
33017@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33018 "c" (value),
33019 "b" (bx),
33020 "D" ((long)reg),
33021- "S" (&pci_indirect));
33022+ "S" (&pci_indirect),
33023+ "r" (__PCIBIOS_DS));
33024 break;
33025 case 4:
33026- __asm__("lcall *(%%esi); cld\n\t"
33027+ __asm__("movw %w6, %%ds\n\t"
33028+ "lcall *%%ss:(%%esi); cld\n\t"
33029+ "push %%ss\n\t"
33030+ "pop %%ds\n\t"
33031 "jc 1f\n\t"
33032 "xor %%ah, %%ah\n"
33033 "1:"
33034@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33035 "c" (value),
33036 "b" (bx),
33037 "D" ((long)reg),
33038- "S" (&pci_indirect));
33039+ "S" (&pci_indirect),
33040+ "r" (__PCIBIOS_DS));
33041 break;
33042 }
33043
33044@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33045
33046 DBG("PCI: Fetching IRQ routing table... ");
33047 __asm__("push %%es\n\t"
33048+ "movw %w8, %%ds\n\t"
33049 "push %%ds\n\t"
33050 "pop %%es\n\t"
33051- "lcall *(%%esi); cld\n\t"
33052+ "lcall *%%ss:(%%esi); cld\n\t"
33053 "pop %%es\n\t"
33054+ "push %%ss\n\t"
33055+ "pop %%ds\n"
33056 "jc 1f\n\t"
33057 "xor %%ah, %%ah\n"
33058 "1:"
33059@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33060 "1" (0),
33061 "D" ((long) &opt),
33062 "S" (&pci_indirect),
33063- "m" (opt)
33064+ "m" (opt),
33065+ "r" (__PCIBIOS_DS)
33066 : "memory");
33067 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33068 if (ret & 0xff00)
33069@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33070 {
33071 int ret;
33072
33073- __asm__("lcall *(%%esi); cld\n\t"
33074+ __asm__("movw %w5, %%ds\n\t"
33075+ "lcall *%%ss:(%%esi); cld\n\t"
33076+ "push %%ss\n\t"
33077+ "pop %%ds\n"
33078 "jc 1f\n\t"
33079 "xor %%ah, %%ah\n"
33080 "1:"
33081@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33082 : "0" (PCIBIOS_SET_PCI_HW_INT),
33083 "b" ((dev->bus->number << 8) | dev->devfn),
33084 "c" ((irq << 8) | (pin + 10)),
33085- "S" (&pci_indirect));
33086+ "S" (&pci_indirect),
33087+ "r" (__PCIBIOS_DS));
33088 return !(ret & 0xff00);
33089 }
33090 EXPORT_SYMBOL(pcibios_set_irq_routing);
33091diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33092index 40e4469..d915bf9 100644
33093--- a/arch/x86/platform/efi/efi_32.c
33094+++ b/arch/x86/platform/efi/efi_32.c
33095@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33096 {
33097 struct desc_ptr gdt_descr;
33098
33099+#ifdef CONFIG_PAX_KERNEXEC
33100+ struct desc_struct d;
33101+#endif
33102+
33103 local_irq_save(efi_rt_eflags);
33104
33105 load_cr3(initial_page_table);
33106 __flush_tlb_all();
33107
33108+#ifdef CONFIG_PAX_KERNEXEC
33109+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33110+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33111+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33112+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33113+#endif
33114+
33115 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33116 gdt_descr.size = GDT_SIZE - 1;
33117 load_gdt(&gdt_descr);
33118@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33119 {
33120 struct desc_ptr gdt_descr;
33121
33122+#ifdef CONFIG_PAX_KERNEXEC
33123+ struct desc_struct d;
33124+
33125+ memset(&d, 0, sizeof d);
33126+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33127+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33128+#endif
33129+
33130 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33131 gdt_descr.size = GDT_SIZE - 1;
33132 load_gdt(&gdt_descr);
33133
33134+#ifdef CONFIG_PAX_PER_CPU_PGD
33135+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33136+#else
33137 load_cr3(swapper_pg_dir);
33138+#endif
33139+
33140 __flush_tlb_all();
33141
33142 local_irq_restore(efi_rt_eflags);
33143diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33144index 39a0e7f1..872396e 100644
33145--- a/arch/x86/platform/efi/efi_64.c
33146+++ b/arch/x86/platform/efi/efi_64.c
33147@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33148 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33149 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33150 }
33151+
33152+#ifdef CONFIG_PAX_PER_CPU_PGD
33153+ load_cr3(swapper_pg_dir);
33154+#endif
33155+
33156 __flush_tlb_all();
33157 }
33158
33159@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33160 for (pgd = 0; pgd < n_pgds; pgd++)
33161 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33162 kfree(save_pgd);
33163+
33164+#ifdef CONFIG_PAX_PER_CPU_PGD
33165+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33166+#endif
33167+
33168 __flush_tlb_all();
33169 local_irq_restore(efi_flags);
33170 early_code_mapping_set_exec(0);
33171diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33172index fbe66e6..eae5e38 100644
33173--- a/arch/x86/platform/efi/efi_stub_32.S
33174+++ b/arch/x86/platform/efi/efi_stub_32.S
33175@@ -6,7 +6,9 @@
33176 */
33177
33178 #include <linux/linkage.h>
33179+#include <linux/init.h>
33180 #include <asm/page_types.h>
33181+#include <asm/segment.h>
33182
33183 /*
33184 * efi_call_phys(void *, ...) is a function with variable parameters.
33185@@ -20,7 +22,7 @@
33186 * service functions will comply with gcc calling convention, too.
33187 */
33188
33189-.text
33190+__INIT
33191 ENTRY(efi_call_phys)
33192 /*
33193 * 0. The function can only be called in Linux kernel. So CS has been
33194@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33195 * The mapping of lower virtual memory has been created in prelog and
33196 * epilog.
33197 */
33198- movl $1f, %edx
33199- subl $__PAGE_OFFSET, %edx
33200- jmp *%edx
33201+#ifdef CONFIG_PAX_KERNEXEC
33202+ movl $(__KERNEXEC_EFI_DS), %edx
33203+ mov %edx, %ds
33204+ mov %edx, %es
33205+ mov %edx, %ss
33206+ addl $2f,(1f)
33207+ ljmp *(1f)
33208+
33209+__INITDATA
33210+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33211+.previous
33212+
33213+2:
33214+ subl $2b,(1b)
33215+#else
33216+ jmp 1f-__PAGE_OFFSET
33217 1:
33218+#endif
33219
33220 /*
33221 * 2. Now on the top of stack is the return
33222@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33223 * parameter 2, ..., param n. To make things easy, we save the return
33224 * address of efi_call_phys in a global variable.
33225 */
33226- popl %edx
33227- movl %edx, saved_return_addr
33228- /* get the function pointer into ECX*/
33229- popl %ecx
33230- movl %ecx, efi_rt_function_ptr
33231- movl $2f, %edx
33232- subl $__PAGE_OFFSET, %edx
33233- pushl %edx
33234+ popl (saved_return_addr)
33235+ popl (efi_rt_function_ptr)
33236
33237 /*
33238 * 3. Clear PG bit in %CR0.
33239@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33240 /*
33241 * 5. Call the physical function.
33242 */
33243- jmp *%ecx
33244+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33245
33246-2:
33247 /*
33248 * 6. After EFI runtime service returns, control will return to
33249 * following instruction. We'd better readjust stack pointer first.
33250@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33251 movl %cr0, %edx
33252 orl $0x80000000, %edx
33253 movl %edx, %cr0
33254- jmp 1f
33255-1:
33256+
33257 /*
33258 * 8. Now restore the virtual mode from flat mode by
33259 * adding EIP with PAGE_OFFSET.
33260 */
33261- movl $1f, %edx
33262- jmp *%edx
33263+#ifdef CONFIG_PAX_KERNEXEC
33264+ movl $(__KERNEL_DS), %edx
33265+ mov %edx, %ds
33266+ mov %edx, %es
33267+ mov %edx, %ss
33268+ ljmp $(__KERNEL_CS),$1f
33269+#else
33270+ jmp 1f+__PAGE_OFFSET
33271+#endif
33272 1:
33273
33274 /*
33275 * 9. Balance the stack. And because EAX contain the return value,
33276 * we'd better not clobber it.
33277 */
33278- leal efi_rt_function_ptr, %edx
33279- movl (%edx), %ecx
33280- pushl %ecx
33281+ pushl (efi_rt_function_ptr)
33282
33283 /*
33284- * 10. Push the saved return address onto the stack and return.
33285+ * 10. Return to the saved return address.
33286 */
33287- leal saved_return_addr, %edx
33288- movl (%edx), %ecx
33289- pushl %ecx
33290- ret
33291+ jmpl *(saved_return_addr)
33292 ENDPROC(efi_call_phys)
33293 .previous
33294
33295-.data
33296+__INITDATA
33297 saved_return_addr:
33298 .long 0
33299 efi_rt_function_ptr:
33300diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33301index 4c07cca..2c8427d 100644
33302--- a/arch/x86/platform/efi/efi_stub_64.S
33303+++ b/arch/x86/platform/efi/efi_stub_64.S
33304@@ -7,6 +7,7 @@
33305 */
33306
33307 #include <linux/linkage.h>
33308+#include <asm/alternative-asm.h>
33309
33310 #define SAVE_XMM \
33311 mov %rsp, %rax; \
33312@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33313 call *%rdi
33314 addq $32, %rsp
33315 RESTORE_XMM
33316+ pax_force_retaddr 0, 1
33317 ret
33318 ENDPROC(efi_call0)
33319
33320@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33321 call *%rdi
33322 addq $32, %rsp
33323 RESTORE_XMM
33324+ pax_force_retaddr 0, 1
33325 ret
33326 ENDPROC(efi_call1)
33327
33328@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33329 call *%rdi
33330 addq $32, %rsp
33331 RESTORE_XMM
33332+ pax_force_retaddr 0, 1
33333 ret
33334 ENDPROC(efi_call2)
33335
33336@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33337 call *%rdi
33338 addq $32, %rsp
33339 RESTORE_XMM
33340+ pax_force_retaddr 0, 1
33341 ret
33342 ENDPROC(efi_call3)
33343
33344@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33345 call *%rdi
33346 addq $32, %rsp
33347 RESTORE_XMM
33348+ pax_force_retaddr 0, 1
33349 ret
33350 ENDPROC(efi_call4)
33351
33352@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33353 call *%rdi
33354 addq $48, %rsp
33355 RESTORE_XMM
33356+ pax_force_retaddr 0, 1
33357 ret
33358 ENDPROC(efi_call5)
33359
33360@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33361 call *%rdi
33362 addq $48, %rsp
33363 RESTORE_XMM
33364+ pax_force_retaddr 0, 1
33365 ret
33366 ENDPROC(efi_call6)
33367diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33368index 47fe66f..6206449 100644
33369--- a/arch/x86/platform/mrst/mrst.c
33370+++ b/arch/x86/platform/mrst/mrst.c
33371@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33372 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33373 int sfi_mrtc_num;
33374
33375-static void mrst_power_off(void)
33376+static __noreturn void mrst_power_off(void)
33377 {
33378+ BUG();
33379 }
33380
33381-static void mrst_reboot(void)
33382+static __noreturn void mrst_reboot(void)
33383 {
33384 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33385+ BUG();
33386 }
33387
33388 /* parse all the mtimer info to a static mtimer array */
33389diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33390index d6ee929..3637cb5 100644
33391--- a/arch/x86/platform/olpc/olpc_dt.c
33392+++ b/arch/x86/platform/olpc/olpc_dt.c
33393@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33394 return res;
33395 }
33396
33397-static struct of_pdt_ops prom_olpc_ops __initdata = {
33398+static struct of_pdt_ops prom_olpc_ops __initconst = {
33399 .nextprop = olpc_dt_nextprop,
33400 .getproplen = olpc_dt_getproplen,
33401 .getproperty = olpc_dt_getproperty,
33402diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33403index 1cf5b30..fd45732 100644
33404--- a/arch/x86/power/cpu.c
33405+++ b/arch/x86/power/cpu.c
33406@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33407 static void fix_processor_context(void)
33408 {
33409 int cpu = smp_processor_id();
33410- struct tss_struct *t = &per_cpu(init_tss, cpu);
33411-#ifdef CONFIG_X86_64
33412- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33413- tss_desc tss;
33414-#endif
33415+ struct tss_struct *t = init_tss + cpu;
33416+
33417 set_tss_desc(cpu, t); /*
33418 * This just modifies memory; should not be
33419 * necessary. But... This is necessary, because
33420@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33421 */
33422
33423 #ifdef CONFIG_X86_64
33424- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33425- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33426- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33427-
33428 syscall_init(); /* This sets MSR_*STAR and related */
33429 #endif
33430 load_TR_desc(); /* This does ltr */
33431diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33432index a44f457..9140171 100644
33433--- a/arch/x86/realmode/init.c
33434+++ b/arch/x86/realmode/init.c
33435@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33436 __va(real_mode_header->trampoline_header);
33437
33438 #ifdef CONFIG_X86_32
33439- trampoline_header->start = __pa_symbol(startup_32_smp);
33440+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33441+
33442+#ifdef CONFIG_PAX_KERNEXEC
33443+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33444+#endif
33445+
33446+ trampoline_header->boot_cs = __BOOT_CS;
33447 trampoline_header->gdt_limit = __BOOT_DS + 7;
33448 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33449 #else
33450@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33451 *trampoline_cr4_features = read_cr4();
33452
33453 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33454- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33455+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33456 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33457 #endif
33458 }
33459diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33460index 8869287..d577672 100644
33461--- a/arch/x86/realmode/rm/Makefile
33462+++ b/arch/x86/realmode/rm/Makefile
33463@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33464 $(call cc-option, -fno-unit-at-a-time)) \
33465 $(call cc-option, -fno-stack-protector) \
33466 $(call cc-option, -mpreferred-stack-boundary=2)
33467+ifdef CONSTIFY_PLUGIN
33468+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33469+endif
33470 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33471 GCOV_PROFILE := n
33472diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33473index a28221d..93c40f1 100644
33474--- a/arch/x86/realmode/rm/header.S
33475+++ b/arch/x86/realmode/rm/header.S
33476@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33477 #endif
33478 /* APM/BIOS reboot */
33479 .long pa_machine_real_restart_asm
33480-#ifdef CONFIG_X86_64
33481+#ifdef CONFIG_X86_32
33482+ .long __KERNEL_CS
33483+#else
33484 .long __KERNEL32_CS
33485 #endif
33486 END(real_mode_header)
33487diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33488index c1b2791..f9e31c7 100644
33489--- a/arch/x86/realmode/rm/trampoline_32.S
33490+++ b/arch/x86/realmode/rm/trampoline_32.S
33491@@ -25,6 +25,12 @@
33492 #include <asm/page_types.h>
33493 #include "realmode.h"
33494
33495+#ifdef CONFIG_PAX_KERNEXEC
33496+#define ta(X) (X)
33497+#else
33498+#define ta(X) (pa_ ## X)
33499+#endif
33500+
33501 .text
33502 .code16
33503
33504@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33505
33506 cli # We should be safe anyway
33507
33508- movl tr_start, %eax # where we need to go
33509-
33510 movl $0xA5A5A5A5, trampoline_status
33511 # write marker for master knows we're running
33512
33513@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33514 movw $1, %dx # protected mode (PE) bit
33515 lmsw %dx # into protected mode
33516
33517- ljmpl $__BOOT_CS, $pa_startup_32
33518+ ljmpl *(trampoline_header)
33519
33520 .section ".text32","ax"
33521 .code32
33522@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33523 .balign 8
33524 GLOBAL(trampoline_header)
33525 tr_start: .space 4
33526- tr_gdt_pad: .space 2
33527+ tr_boot_cs: .space 2
33528 tr_gdt: .space 6
33529 END(trampoline_header)
33530
33531diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33532index bb360dc..d0fd8f8 100644
33533--- a/arch/x86/realmode/rm/trampoline_64.S
33534+++ b/arch/x86/realmode/rm/trampoline_64.S
33535@@ -94,6 +94,7 @@ ENTRY(startup_32)
33536 movl %edx, %gs
33537
33538 movl pa_tr_cr4, %eax
33539+ andl $~X86_CR4_PCIDE, %eax
33540 movl %eax, %cr4 # Enable PAE mode
33541
33542 # Setup trampoline 4 level pagetables
33543@@ -107,7 +108,7 @@ ENTRY(startup_32)
33544 wrmsr
33545
33546 # Enable paging and in turn activate Long Mode
33547- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33548+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33549 movl %eax, %cr0
33550
33551 /*
33552diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33553index e812034..c747134 100644
33554--- a/arch/x86/tools/Makefile
33555+++ b/arch/x86/tools/Makefile
33556@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33557
33558 $(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
33559
33560-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33561+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33562 hostprogs-y += relocs
33563 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33564 relocs: $(obj)/relocs
33565diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33566index f7bab68..b6d9886 100644
33567--- a/arch/x86/tools/relocs.c
33568+++ b/arch/x86/tools/relocs.c
33569@@ -1,5 +1,7 @@
33570 /* This is included from relocs_32/64.c */
33571
33572+#include "../../../include/generated/autoconf.h"
33573+
33574 #define ElfW(type) _ElfW(ELF_BITS, type)
33575 #define _ElfW(bits, type) __ElfW(bits, type)
33576 #define __ElfW(bits, type) Elf##bits##_##type
33577@@ -11,6 +13,7 @@
33578 #define Elf_Sym ElfW(Sym)
33579
33580 static Elf_Ehdr ehdr;
33581+static Elf_Phdr *phdr;
33582
33583 struct relocs {
33584 uint32_t *offset;
33585@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33586 }
33587 }
33588
33589+static void read_phdrs(FILE *fp)
33590+{
33591+ unsigned int i;
33592+
33593+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33594+ if (!phdr) {
33595+ die("Unable to allocate %d program headers\n",
33596+ ehdr.e_phnum);
33597+ }
33598+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33599+ die("Seek to %d failed: %s\n",
33600+ ehdr.e_phoff, strerror(errno));
33601+ }
33602+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33603+ die("Cannot read ELF program headers: %s\n",
33604+ strerror(errno));
33605+ }
33606+ for(i = 0; i < ehdr.e_phnum; i++) {
33607+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33608+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33609+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33610+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33611+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33612+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33613+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33614+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33615+ }
33616+
33617+}
33618+
33619 static void read_shdrs(FILE *fp)
33620 {
33621- int i;
33622+ unsigned int i;
33623 Elf_Shdr shdr;
33624
33625 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33626@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33627
33628 static void read_strtabs(FILE *fp)
33629 {
33630- int i;
33631+ unsigned int i;
33632 for (i = 0; i < ehdr.e_shnum; i++) {
33633 struct section *sec = &secs[i];
33634 if (sec->shdr.sh_type != SHT_STRTAB) {
33635@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33636
33637 static void read_symtabs(FILE *fp)
33638 {
33639- int i,j;
33640+ unsigned int i,j;
33641 for (i = 0; i < ehdr.e_shnum; i++) {
33642 struct section *sec = &secs[i];
33643 if (sec->shdr.sh_type != SHT_SYMTAB) {
33644@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33645 }
33646
33647
33648-static void read_relocs(FILE *fp)
33649+static void read_relocs(FILE *fp, int use_real_mode)
33650 {
33651- int i,j;
33652+ unsigned int i,j;
33653+ uint32_t base;
33654+
33655 for (i = 0; i < ehdr.e_shnum; i++) {
33656 struct section *sec = &secs[i];
33657 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33658@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33659 die("Cannot read symbol table: %s\n",
33660 strerror(errno));
33661 }
33662+ base = 0;
33663+
33664+#ifdef CONFIG_X86_32
33665+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33666+ if (phdr[j].p_type != PT_LOAD )
33667+ continue;
33668+ 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)
33669+ continue;
33670+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33671+ break;
33672+ }
33673+#endif
33674+
33675 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33676 Elf_Rel *rel = &sec->reltab[j];
33677- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33678+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33679 rel->r_info = elf_xword_to_cpu(rel->r_info);
33680 #if (SHT_REL_TYPE == SHT_RELA)
33681 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33682@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33683
33684 static void print_absolute_symbols(void)
33685 {
33686- int i;
33687+ unsigned int i;
33688 const char *format;
33689
33690 if (ELF_BITS == 64)
33691@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33692 for (i = 0; i < ehdr.e_shnum; i++) {
33693 struct section *sec = &secs[i];
33694 char *sym_strtab;
33695- int j;
33696+ unsigned int j;
33697
33698 if (sec->shdr.sh_type != SHT_SYMTAB) {
33699 continue;
33700@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33701
33702 static void print_absolute_relocs(void)
33703 {
33704- int i, printed = 0;
33705+ unsigned int i, printed = 0;
33706 const char *format;
33707
33708 if (ELF_BITS == 64)
33709@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33710 struct section *sec_applies, *sec_symtab;
33711 char *sym_strtab;
33712 Elf_Sym *sh_symtab;
33713- int j;
33714+ unsigned int j;
33715 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33716 continue;
33717 }
33718@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33719 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33720 Elf_Sym *sym, const char *symname))
33721 {
33722- int i;
33723+ unsigned int i;
33724 /* Walk through the relocations */
33725 for (i = 0; i < ehdr.e_shnum; i++) {
33726 char *sym_strtab;
33727 Elf_Sym *sh_symtab;
33728 struct section *sec_applies, *sec_symtab;
33729- int j;
33730+ unsigned int j;
33731 struct section *sec = &secs[i];
33732
33733 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33734@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33735 {
33736 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33737 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33738+ char *sym_strtab = sec->link->link->strtab;
33739+
33740+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33741+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33742+ return 0;
33743+
33744+#ifdef CONFIG_PAX_KERNEXEC
33745+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33746+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33747+ return 0;
33748+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33749+ return 0;
33750+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33751+ return 0;
33752+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33753+ return 0;
33754+#endif
33755
33756 switch (r_type) {
33757 case R_386_NONE:
33758@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33759
33760 static void emit_relocs(int as_text, int use_real_mode)
33761 {
33762- int i;
33763+ unsigned int i;
33764 int (*write_reloc)(uint32_t, FILE *) = write32;
33765 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33766 const char *symname);
33767@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33768 {
33769 regex_init(use_real_mode);
33770 read_ehdr(fp);
33771+ read_phdrs(fp);
33772 read_shdrs(fp);
33773 read_strtabs(fp);
33774 read_symtabs(fp);
33775- read_relocs(fp);
33776+ read_relocs(fp, use_real_mode);
33777 if (ELF_BITS == 64)
33778 percpu_init();
33779 if (show_absolute_syms) {
33780diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33781index 80ffa5b..a33bd15 100644
33782--- a/arch/x86/um/tls_32.c
33783+++ b/arch/x86/um/tls_32.c
33784@@ -260,7 +260,7 @@ out:
33785 if (unlikely(task == current &&
33786 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33787 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33788- "without flushed TLS.", current->pid);
33789+ "without flushed TLS.", task_pid_nr(current));
33790 }
33791
33792 return 0;
33793diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33794index fd14be1..e3c79c0 100644
33795--- a/arch/x86/vdso/Makefile
33796+++ b/arch/x86/vdso/Makefile
33797@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33798 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33799 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33800
33801-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33802+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33803 GCOV_PROFILE := n
33804
33805 #
33806diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33807index d6bfb87..876ee18 100644
33808--- a/arch/x86/vdso/vdso32-setup.c
33809+++ b/arch/x86/vdso/vdso32-setup.c
33810@@ -25,6 +25,7 @@
33811 #include <asm/tlbflush.h>
33812 #include <asm/vdso.h>
33813 #include <asm/proto.h>
33814+#include <asm/mman.h>
33815
33816 enum {
33817 VDSO_DISABLED = 0,
33818@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33819 void enable_sep_cpu(void)
33820 {
33821 int cpu = get_cpu();
33822- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33823+ struct tss_struct *tss = init_tss + cpu;
33824
33825 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33826 put_cpu();
33827@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33828 gate_vma.vm_start = FIXADDR_USER_START;
33829 gate_vma.vm_end = FIXADDR_USER_END;
33830 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33831- gate_vma.vm_page_prot = __P101;
33832+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33833
33834 return 0;
33835 }
33836@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33837 if (compat)
33838 addr = VDSO_HIGH_BASE;
33839 else {
33840- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33841+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33842 if (IS_ERR_VALUE(addr)) {
33843 ret = addr;
33844 goto up_fail;
33845 }
33846 }
33847
33848- current->mm->context.vdso = (void *)addr;
33849+ current->mm->context.vdso = addr;
33850
33851 if (compat_uses_vma || !compat) {
33852 /*
33853@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33854 }
33855
33856 current_thread_info()->sysenter_return =
33857- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33858+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33859
33860 up_fail:
33861 if (ret)
33862- current->mm->context.vdso = NULL;
33863+ current->mm->context.vdso = 0;
33864
33865 up_write(&mm->mmap_sem);
33866
33867@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33868
33869 const char *arch_vma_name(struct vm_area_struct *vma)
33870 {
33871- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33872+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33873 return "[vdso]";
33874+
33875+#ifdef CONFIG_PAX_SEGMEXEC
33876+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33877+ return "[vdso]";
33878+#endif
33879+
33880 return NULL;
33881 }
33882
33883@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33884 * Check to see if the corresponding task was created in compat vdso
33885 * mode.
33886 */
33887- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33888+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33889 return &gate_vma;
33890 return NULL;
33891 }
33892diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33893index 431e875..cbb23f3 100644
33894--- a/arch/x86/vdso/vma.c
33895+++ b/arch/x86/vdso/vma.c
33896@@ -16,8 +16,6 @@
33897 #include <asm/vdso.h>
33898 #include <asm/page.h>
33899
33900-unsigned int __read_mostly vdso_enabled = 1;
33901-
33902 extern char vdso_start[], vdso_end[];
33903 extern unsigned short vdso_sync_cpuid;
33904
33905@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33906 * unaligned here as a result of stack start randomization.
33907 */
33908 addr = PAGE_ALIGN(addr);
33909- addr = align_vdso_addr(addr);
33910
33911 return addr;
33912 }
33913@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33914 unsigned size)
33915 {
33916 struct mm_struct *mm = current->mm;
33917- unsigned long addr;
33918+ unsigned long addr = 0;
33919 int ret;
33920
33921- if (!vdso_enabled)
33922- return 0;
33923-
33924 down_write(&mm->mmap_sem);
33925+
33926+#ifdef CONFIG_PAX_RANDMMAP
33927+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33928+#endif
33929+
33930 addr = vdso_addr(mm->start_stack, size);
33931+ addr = align_vdso_addr(addr);
33932 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33933 if (IS_ERR_VALUE(addr)) {
33934 ret = addr;
33935 goto up_fail;
33936 }
33937
33938- current->mm->context.vdso = (void *)addr;
33939+ mm->context.vdso = addr;
33940
33941 ret = install_special_mapping(mm, addr, size,
33942 VM_READ|VM_EXEC|
33943 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33944 pages);
33945- if (ret) {
33946- current->mm->context.vdso = NULL;
33947- goto up_fail;
33948- }
33949+ if (ret)
33950+ mm->context.vdso = 0;
33951
33952 up_fail:
33953 up_write(&mm->mmap_sem);
33954@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33955 vdsox32_size);
33956 }
33957 #endif
33958-
33959-static __init int vdso_setup(char *s)
33960-{
33961- vdso_enabled = simple_strtoul(s, NULL, 0);
33962- return 0;
33963-}
33964-__setup("vdso=", vdso_setup);
33965diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33966index 193097e..7590269 100644
33967--- a/arch/x86/xen/enlighten.c
33968+++ b/arch/x86/xen/enlighten.c
33969@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33970
33971 struct shared_info xen_dummy_shared_info;
33972
33973-void *xen_initial_gdt;
33974-
33975 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33976 __read_mostly int xen_have_vector_callback;
33977 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33978@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33979 {
33980 unsigned long va = dtr->address;
33981 unsigned int size = dtr->size + 1;
33982- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33983- unsigned long frames[pages];
33984+ unsigned long frames[65536 / PAGE_SIZE];
33985 int f;
33986
33987 /*
33988@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33989 {
33990 unsigned long va = dtr->address;
33991 unsigned int size = dtr->size + 1;
33992- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33993- unsigned long frames[pages];
33994+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33995 int f;
33996
33997 /*
33998@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33999 * 8-byte entries, or 16 4k pages..
34000 */
34001
34002- BUG_ON(size > 65536);
34003+ BUG_ON(size > GDT_SIZE);
34004 BUG_ON(va & ~PAGE_MASK);
34005
34006 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34007@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34008 return 0;
34009 }
34010
34011-static void set_xen_basic_apic_ops(void)
34012+static void __init set_xen_basic_apic_ops(void)
34013 {
34014 apic->read = xen_apic_read;
34015 apic->write = xen_apic_write;
34016@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34017 #endif
34018 };
34019
34020-static void xen_reboot(int reason)
34021+static __noreturn void xen_reboot(int reason)
34022 {
34023 struct sched_shutdown r = { .reason = reason };
34024
34025- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34026- BUG();
34027+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34028+ BUG();
34029 }
34030
34031-static void xen_restart(char *msg)
34032+static __noreturn void xen_restart(char *msg)
34033 {
34034 xen_reboot(SHUTDOWN_reboot);
34035 }
34036
34037-static void xen_emergency_restart(void)
34038+static __noreturn void xen_emergency_restart(void)
34039 {
34040 xen_reboot(SHUTDOWN_reboot);
34041 }
34042
34043-static void xen_machine_halt(void)
34044+static __noreturn void xen_machine_halt(void)
34045 {
34046 xen_reboot(SHUTDOWN_poweroff);
34047 }
34048
34049-static void xen_machine_power_off(void)
34050+static __noreturn void xen_machine_power_off(void)
34051 {
34052 if (pm_power_off)
34053 pm_power_off();
34054@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34055 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34056
34057 /* Work out if we support NX */
34058- x86_configure_nx();
34059+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34060+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34061+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34062+ unsigned l, h;
34063+
34064+ __supported_pte_mask |= _PAGE_NX;
34065+ rdmsr(MSR_EFER, l, h);
34066+ l |= EFER_NX;
34067+ wrmsr(MSR_EFER, l, h);
34068+ }
34069+#endif
34070
34071 xen_setup_features();
34072
34073@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34074
34075 machine_ops = xen_machine_ops;
34076
34077- /*
34078- * The only reliable way to retain the initial address of the
34079- * percpu gdt_page is to remember it here, so we can go and
34080- * mark it RW later, when the initial percpu area is freed.
34081- */
34082- xen_initial_gdt = &per_cpu(gdt_page, 0);
34083-
34084 xen_smp_init();
34085
34086 #ifdef CONFIG_ACPI_NUMA
34087diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34088index fdc3ba2..3daee39 100644
34089--- a/arch/x86/xen/mmu.c
34090+++ b/arch/x86/xen/mmu.c
34091@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34092 /* L3_k[510] -> level2_kernel_pgt
34093 * L3_i[511] -> level2_fixmap_pgt */
34094 convert_pfn_mfn(level3_kernel_pgt);
34095+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34096+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34097+ convert_pfn_mfn(level3_vmemmap_pgt);
34098
34099 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34100 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34101@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34102 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34103 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34104 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34105+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34106+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34107+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34108 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34109 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34110+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34111 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34112 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34113
34114@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34115 pv_mmu_ops.set_pud = xen_set_pud;
34116 #if PAGETABLE_LEVELS == 4
34117 pv_mmu_ops.set_pgd = xen_set_pgd;
34118+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34119 #endif
34120
34121 /* This will work as long as patching hasn't happened yet
34122@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34123 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34124 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34125 .set_pgd = xen_set_pgd_hyper,
34126+ .set_pgd_batched = xen_set_pgd_hyper,
34127
34128 .alloc_pud = xen_alloc_pmd_init,
34129 .release_pud = xen_release_pmd_init,
34130diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34131index b81c88e..2cbe7b8 100644
34132--- a/arch/x86/xen/smp.c
34133+++ b/arch/x86/xen/smp.c
34134@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34135 {
34136 BUG_ON(smp_processor_id() != 0);
34137 native_smp_prepare_boot_cpu();
34138-
34139- /* We've switched to the "real" per-cpu gdt, so make sure the
34140- old memory can be recycled */
34141- make_lowmem_page_readwrite(xen_initial_gdt);
34142-
34143 xen_filter_cpu_maps();
34144 xen_setup_vcpu_info_placement();
34145 }
34146@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34147 ctxt->user_regs.ss = __KERNEL_DS;
34148 #ifdef CONFIG_X86_32
34149 ctxt->user_regs.fs = __KERNEL_PERCPU;
34150- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34151+ savesegment(gs, ctxt->user_regs.gs);
34152 #else
34153 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34154 #endif
34155@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34156
34157 {
34158 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34159- ctxt->user_regs.ds = __USER_DS;
34160- ctxt->user_regs.es = __USER_DS;
34161+ ctxt->user_regs.ds = __KERNEL_DS;
34162+ ctxt->user_regs.es = __KERNEL_DS;
34163
34164 xen_copy_trap_info(ctxt->trap_ctxt);
34165
34166@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34167 int rc;
34168
34169 per_cpu(current_task, cpu) = idle;
34170+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34171 #ifdef CONFIG_X86_32
34172 irq_ctx_init(cpu);
34173 #else
34174 clear_tsk_thread_flag(idle, TIF_FORK);
34175- per_cpu(kernel_stack, cpu) =
34176- (unsigned long)task_stack_page(idle) -
34177- KERNEL_STACK_OFFSET + THREAD_SIZE;
34178+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34179 #endif
34180 xen_setup_runstate_info(cpu);
34181 xen_setup_timer(cpu);
34182@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34183
34184 void __init xen_smp_init(void)
34185 {
34186- smp_ops = xen_smp_ops;
34187+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34188 xen_fill_possible_map();
34189 xen_init_spinlocks();
34190 }
34191diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34192index 33ca6e4..0ded929 100644
34193--- a/arch/x86/xen/xen-asm_32.S
34194+++ b/arch/x86/xen/xen-asm_32.S
34195@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34196 ESP_OFFSET=4 # bytes pushed onto stack
34197
34198 /*
34199- * Store vcpu_info pointer for easy access. Do it this way to
34200- * avoid having to reload %fs
34201+ * Store vcpu_info pointer for easy access.
34202 */
34203 #ifdef CONFIG_SMP
34204- GET_THREAD_INFO(%eax)
34205- movl %ss:TI_cpu(%eax), %eax
34206- movl %ss:__per_cpu_offset(,%eax,4), %eax
34207- mov %ss:xen_vcpu(%eax), %eax
34208+ push %fs
34209+ mov $(__KERNEL_PERCPU), %eax
34210+ mov %eax, %fs
34211+ mov PER_CPU_VAR(xen_vcpu), %eax
34212+ pop %fs
34213 #else
34214 movl %ss:xen_vcpu, %eax
34215 #endif
34216diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34217index 7faed58..ba4427c 100644
34218--- a/arch/x86/xen/xen-head.S
34219+++ b/arch/x86/xen/xen-head.S
34220@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34221 #ifdef CONFIG_X86_32
34222 mov %esi,xen_start_info
34223 mov $init_thread_union+THREAD_SIZE,%esp
34224+#ifdef CONFIG_SMP
34225+ movl $cpu_gdt_table,%edi
34226+ movl $__per_cpu_load,%eax
34227+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34228+ rorl $16,%eax
34229+ movb %al,__KERNEL_PERCPU + 4(%edi)
34230+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34231+ movl $__per_cpu_end - 1,%eax
34232+ subl $__per_cpu_start,%eax
34233+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34234+#endif
34235 #else
34236 mov %rsi,xen_start_info
34237 mov $init_thread_union+THREAD_SIZE,%rsp
34238diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34239index 86782c5..fa272c8 100644
34240--- a/arch/x86/xen/xen-ops.h
34241+++ b/arch/x86/xen/xen-ops.h
34242@@ -10,8 +10,6 @@
34243 extern const char xen_hypervisor_callback[];
34244 extern const char xen_failsafe_callback[];
34245
34246-extern void *xen_initial_gdt;
34247-
34248 struct trap_info;
34249 void xen_copy_trap_info(struct trap_info *traps);
34250
34251diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34252index 525bd3d..ef888b1 100644
34253--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34254+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34255@@ -119,9 +119,9 @@
34256 ----------------------------------------------------------------------*/
34257
34258 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34259-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34260 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34261 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34262+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34263
34264 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34265 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34266diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34267index 2f33760..835e50a 100644
34268--- a/arch/xtensa/variants/fsf/include/variant/core.h
34269+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34270@@ -11,6 +11,7 @@
34271 #ifndef _XTENSA_CORE_H
34272 #define _XTENSA_CORE_H
34273
34274+#include <linux/const.h>
34275
34276 /****************************************************************************
34277 Parameters Useful for Any Code, USER or PRIVILEGED
34278@@ -112,9 +113,9 @@
34279 ----------------------------------------------------------------------*/
34280
34281 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34282-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34283 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34284 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34285+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34286
34287 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34288 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34289diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34290index af00795..2bb8105 100644
34291--- a/arch/xtensa/variants/s6000/include/variant/core.h
34292+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34293@@ -11,6 +11,7 @@
34294 #ifndef _XTENSA_CORE_CONFIGURATION_H
34295 #define _XTENSA_CORE_CONFIGURATION_H
34296
34297+#include <linux/const.h>
34298
34299 /****************************************************************************
34300 Parameters Useful for Any Code, USER or PRIVILEGED
34301@@ -118,9 +119,9 @@
34302 ----------------------------------------------------------------------*/
34303
34304 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34305-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34306 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34307 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34308+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34309
34310 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34311 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34312diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34313index 290792a..416f287 100644
34314--- a/block/blk-cgroup.c
34315+++ b/block/blk-cgroup.c
34316@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34317
34318 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34319 {
34320- static atomic64_t id_seq = ATOMIC64_INIT(0);
34321+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34322 struct blkcg *blkcg;
34323 struct cgroup *parent = cgroup->parent;
34324
34325@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34326
34327 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34328 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34329- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34330+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34331 done:
34332 spin_lock_init(&blkcg->lock);
34333 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34334diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34335index 4b8d9b54..a7178c0 100644
34336--- a/block/blk-iopoll.c
34337+++ b/block/blk-iopoll.c
34338@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34339 }
34340 EXPORT_SYMBOL(blk_iopoll_complete);
34341
34342-static void blk_iopoll_softirq(struct softirq_action *h)
34343+static __latent_entropy void blk_iopoll_softirq(void)
34344 {
34345 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34346 int rearm = 0, budget = blk_iopoll_budget;
34347diff --git a/block/blk-map.c b/block/blk-map.c
34348index 623e1cd..ca1e109 100644
34349--- a/block/blk-map.c
34350+++ b/block/blk-map.c
34351@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34352 if (!len || !kbuf)
34353 return -EINVAL;
34354
34355- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34356+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34357 if (do_copy)
34358 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34359 else
34360diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34361index ec9e606..3f38839 100644
34362--- a/block/blk-softirq.c
34363+++ b/block/blk-softirq.c
34364@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34365 * Softirq action handler - move entries to local list and loop over them
34366 * while passing them to the queue registered handler.
34367 */
34368-static void blk_done_softirq(struct softirq_action *h)
34369+static __latent_entropy void blk_done_softirq(void)
34370 {
34371 struct list_head *cpu_list, local_list;
34372
34373diff --git a/block/bsg.c b/block/bsg.c
34374index 420a5a9..23834aa 100644
34375--- a/block/bsg.c
34376+++ b/block/bsg.c
34377@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34378 struct sg_io_v4 *hdr, struct bsg_device *bd,
34379 fmode_t has_write_perm)
34380 {
34381+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34382+ unsigned char *cmdptr;
34383+
34384 if (hdr->request_len > BLK_MAX_CDB) {
34385 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34386 if (!rq->cmd)
34387 return -ENOMEM;
34388- }
34389+ cmdptr = rq->cmd;
34390+ } else
34391+ cmdptr = tmpcmd;
34392
34393- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34394+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34395 hdr->request_len))
34396 return -EFAULT;
34397
34398+ if (cmdptr != rq->cmd)
34399+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34400+
34401 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34402 if (blk_verify_command(rq->cmd, has_write_perm))
34403 return -EPERM;
34404diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34405index 7e5d474..0cf0017 100644
34406--- a/block/compat_ioctl.c
34407+++ b/block/compat_ioctl.c
34408@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34409 err |= __get_user(f->spec1, &uf->spec1);
34410 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34411 err |= __get_user(name, &uf->name);
34412- f->name = compat_ptr(name);
34413+ f->name = (void __force_kernel *)compat_ptr(name);
34414 if (err) {
34415 err = -EFAULT;
34416 goto out;
34417diff --git a/block/genhd.c b/block/genhd.c
34418index dadf42b..48dc887 100644
34419--- a/block/genhd.c
34420+++ b/block/genhd.c
34421@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34422
34423 /*
34424 * Register device numbers dev..(dev+range-1)
34425- * range must be nonzero
34426+ * Noop if @range is zero.
34427 * The hash chain is sorted on range, so that subranges can override.
34428 */
34429 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34430 struct kobject *(*probe)(dev_t, int *, void *),
34431 int (*lock)(dev_t, void *), void *data)
34432 {
34433- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34434+ if (range)
34435+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34436 }
34437
34438 EXPORT_SYMBOL(blk_register_region);
34439
34440+/* undo blk_register_region(), noop if @range is zero */
34441 void blk_unregister_region(dev_t devt, unsigned long range)
34442 {
34443- kobj_unmap(bdev_map, devt, range);
34444+ if (range)
34445+ kobj_unmap(bdev_map, devt, range);
34446 }
34447
34448 EXPORT_SYMBOL(blk_unregister_region);
34449diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34450index c85fc89..51e690b 100644
34451--- a/block/partitions/efi.c
34452+++ b/block/partitions/efi.c
34453@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34454 if (!gpt)
34455 return NULL;
34456
34457+ if (!le32_to_cpu(gpt->num_partition_entries))
34458+ return NULL;
34459+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34460+ if (!pte)
34461+ return NULL;
34462+
34463 count = le32_to_cpu(gpt->num_partition_entries) *
34464 le32_to_cpu(gpt->sizeof_partition_entry);
34465- if (!count)
34466- return NULL;
34467- pte = kmalloc(count, GFP_KERNEL);
34468- if (!pte)
34469- return NULL;
34470-
34471 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34472 (u8 *) pte,
34473 count) < count) {
34474diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34475index a5ffcc9..3cedc9c 100644
34476--- a/block/scsi_ioctl.c
34477+++ b/block/scsi_ioctl.c
34478@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34479 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34480 struct sg_io_hdr *hdr, fmode_t mode)
34481 {
34482- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34483+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34484+ unsigned char *cmdptr;
34485+
34486+ if (rq->cmd != rq->__cmd)
34487+ cmdptr = rq->cmd;
34488+ else
34489+ cmdptr = tmpcmd;
34490+
34491+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34492 return -EFAULT;
34493+
34494+ if (cmdptr != rq->cmd)
34495+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34496+
34497 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34498 return -EPERM;
34499
34500@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34501 int err;
34502 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34503 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34504+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34505+ unsigned char *cmdptr;
34506
34507 if (!sic)
34508 return -EINVAL;
34509@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34510 */
34511 err = -EFAULT;
34512 rq->cmd_len = cmdlen;
34513- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34514+
34515+ if (rq->cmd != rq->__cmd)
34516+ cmdptr = rq->cmd;
34517+ else
34518+ cmdptr = tmpcmd;
34519+
34520+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34521 goto error;
34522
34523+ if (rq->cmd != cmdptr)
34524+ memcpy(rq->cmd, cmdptr, cmdlen);
34525+
34526 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34527 goto error;
34528
34529diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34530index 7bdd61b..afec999 100644
34531--- a/crypto/cryptd.c
34532+++ b/crypto/cryptd.c
34533@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34534
34535 struct cryptd_blkcipher_request_ctx {
34536 crypto_completion_t complete;
34537-};
34538+} __no_const;
34539
34540 struct cryptd_hash_ctx {
34541 struct crypto_shash *child;
34542@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34543
34544 struct cryptd_aead_request_ctx {
34545 crypto_completion_t complete;
34546-};
34547+} __no_const;
34548
34549 static void cryptd_queue_worker(struct work_struct *work);
34550
34551diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34552index f8c920c..ab2cb5a 100644
34553--- a/crypto/pcrypt.c
34554+++ b/crypto/pcrypt.c
34555@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34556 int ret;
34557
34558 pinst->kobj.kset = pcrypt_kset;
34559- ret = kobject_add(&pinst->kobj, NULL, name);
34560+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34561 if (!ret)
34562 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34563
34564diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34565index f220d64..d359ad6 100644
34566--- a/drivers/acpi/apei/apei-internal.h
34567+++ b/drivers/acpi/apei/apei-internal.h
34568@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34569 struct apei_exec_ins_type {
34570 u32 flags;
34571 apei_exec_ins_func_t run;
34572-};
34573+} __do_const;
34574
34575 struct apei_exec_context {
34576 u32 ip;
34577diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34578index 33dc6a0..4b24b47 100644
34579--- a/drivers/acpi/apei/cper.c
34580+++ b/drivers/acpi/apei/cper.c
34581@@ -39,12 +39,12 @@
34582 */
34583 u64 cper_next_record_id(void)
34584 {
34585- static atomic64_t seq;
34586+ static atomic64_unchecked_t seq;
34587
34588- if (!atomic64_read(&seq))
34589- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34590+ if (!atomic64_read_unchecked(&seq))
34591+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34592
34593- return atomic64_inc_return(&seq);
34594+ return atomic64_inc_return_unchecked(&seq);
34595 }
34596 EXPORT_SYMBOL_GPL(cper_next_record_id);
34597
34598diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34599index ec9b57d..9682b3a 100644
34600--- a/drivers/acpi/apei/ghes.c
34601+++ b/drivers/acpi/apei/ghes.c
34602@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34603 const struct acpi_hest_generic *generic,
34604 const struct acpi_hest_generic_status *estatus)
34605 {
34606- static atomic_t seqno;
34607+ static atomic_unchecked_t seqno;
34608 unsigned int curr_seqno;
34609 char pfx_seq[64];
34610
34611@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34612 else
34613 pfx = KERN_ERR;
34614 }
34615- curr_seqno = atomic_inc_return(&seqno);
34616+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34617 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34618 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34619 pfx_seq, generic->header.source_id);
34620diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34621index be60399..778b33e8 100644
34622--- a/drivers/acpi/bgrt.c
34623+++ b/drivers/acpi/bgrt.c
34624@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34625 return -ENODEV;
34626
34627 sysfs_bin_attr_init(&image_attr);
34628- image_attr.private = bgrt_image;
34629- image_attr.size = bgrt_image_size;
34630+ pax_open_kernel();
34631+ *(void **)&image_attr.private = bgrt_image;
34632+ *(size_t *)&image_attr.size = bgrt_image_size;
34633+ pax_close_kernel();
34634
34635 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34636 if (!bgrt_kobj)
34637diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34638index cb96296..b81293b 100644
34639--- a/drivers/acpi/blacklist.c
34640+++ b/drivers/acpi/blacklist.c
34641@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34642 u32 is_critical_error;
34643 };
34644
34645-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34646+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34647
34648 /*
34649 * POLICY: If *anything* doesn't work, put it on the blacklist.
34650@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34651 return 0;
34652 }
34653
34654-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34655+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34656 {
34657 .callback = dmi_disable_osi_vista,
34658 .ident = "Fujitsu Siemens",
34659diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34660index f98dd00..7b69865 100644
34661--- a/drivers/acpi/processor_idle.c
34662+++ b/drivers/acpi/processor_idle.c
34663@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34664 {
34665 int i, count = CPUIDLE_DRIVER_STATE_START;
34666 struct acpi_processor_cx *cx;
34667- struct cpuidle_state *state;
34668+ cpuidle_state_no_const *state;
34669 struct cpuidle_driver *drv = &acpi_idle_driver;
34670
34671 if (!pr->flags.power_setup_done)
34672diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34673index 05306a5..733d1f0 100644
34674--- a/drivers/acpi/sysfs.c
34675+++ b/drivers/acpi/sysfs.c
34676@@ -423,11 +423,11 @@ static u32 num_counters;
34677 static struct attribute **all_attrs;
34678 static u32 acpi_gpe_count;
34679
34680-static struct attribute_group interrupt_stats_attr_group = {
34681+static attribute_group_no_const interrupt_stats_attr_group = {
34682 .name = "interrupts",
34683 };
34684
34685-static struct kobj_attribute *counter_attrs;
34686+static kobj_attribute_no_const *counter_attrs;
34687
34688 static void delete_gpe_attr_array(void)
34689 {
34690diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34691index acfd0f7..e5acb08 100644
34692--- a/drivers/ata/libahci.c
34693+++ b/drivers/ata/libahci.c
34694@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34695 }
34696 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34697
34698-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34699+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34700 struct ata_taskfile *tf, int is_cmd, u16 flags,
34701 unsigned long timeout_msec)
34702 {
34703diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34704index c24354d..335c975 100644
34705--- a/drivers/ata/libata-core.c
34706+++ b/drivers/ata/libata-core.c
34707@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34708 static void ata_dev_xfermask(struct ata_device *dev);
34709 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34710
34711-atomic_t ata_print_id = ATOMIC_INIT(0);
34712+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34713
34714 struct ata_force_param {
34715 const char *name;
34716@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34717 struct ata_port *ap;
34718 unsigned int tag;
34719
34720- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34721+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34722 ap = qc->ap;
34723
34724 qc->flags = 0;
34725@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34726 struct ata_port *ap;
34727 struct ata_link *link;
34728
34729- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34730+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34731 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34732 ap = qc->ap;
34733 link = qc->dev->link;
34734@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34735 return;
34736
34737 spin_lock(&lock);
34738+ pax_open_kernel();
34739
34740 for (cur = ops->inherits; cur; cur = cur->inherits) {
34741 void **inherit = (void **)cur;
34742@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34743 if (IS_ERR(*pp))
34744 *pp = NULL;
34745
34746- ops->inherits = NULL;
34747+ *(struct ata_port_operations **)&ops->inherits = NULL;
34748
34749+ pax_close_kernel();
34750 spin_unlock(&lock);
34751 }
34752
34753@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34754
34755 /* give ports names and add SCSI hosts */
34756 for (i = 0; i < host->n_ports; i++) {
34757- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34758+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34759 host->ports[i]->local_port_no = i + 1;
34760 }
34761
34762diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34763index b1e880a..8cf82e1 100644
34764--- a/drivers/ata/libata-scsi.c
34765+++ b/drivers/ata/libata-scsi.c
34766@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34767
34768 if (rc)
34769 return rc;
34770- ap->print_id = atomic_inc_return(&ata_print_id);
34771+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34772 return 0;
34773 }
34774 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34775diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34776index 577d902b..cb4781e 100644
34777--- a/drivers/ata/libata.h
34778+++ b/drivers/ata/libata.h
34779@@ -53,7 +53,7 @@ enum {
34780 ATA_DNXFER_QUIET = (1 << 31),
34781 };
34782
34783-extern atomic_t ata_print_id;
34784+extern atomic_unchecked_t ata_print_id;
34785 extern int atapi_passthru16;
34786 extern int libata_fua;
34787 extern int libata_noacpi;
34788diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34789index 848ed32..132f39d 100644
34790--- a/drivers/ata/pata_arasan_cf.c
34791+++ b/drivers/ata/pata_arasan_cf.c
34792@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34793 /* Handle platform specific quirks */
34794 if (quirk) {
34795 if (quirk & CF_BROKEN_PIO) {
34796- ap->ops->set_piomode = NULL;
34797+ pax_open_kernel();
34798+ *(void **)&ap->ops->set_piomode = NULL;
34799+ pax_close_kernel();
34800 ap->pio_mask = 0;
34801 }
34802 if (quirk & CF_BROKEN_MWDMA)
34803diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34804index f9b983a..887b9d8 100644
34805--- a/drivers/atm/adummy.c
34806+++ b/drivers/atm/adummy.c
34807@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34808 vcc->pop(vcc, skb);
34809 else
34810 dev_kfree_skb_any(skb);
34811- atomic_inc(&vcc->stats->tx);
34812+ atomic_inc_unchecked(&vcc->stats->tx);
34813
34814 return 0;
34815 }
34816diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34817index 62a7607..cc4be104 100644
34818--- a/drivers/atm/ambassador.c
34819+++ b/drivers/atm/ambassador.c
34820@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34821 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34822
34823 // VC layer stats
34824- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34825+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34826
34827 // free the descriptor
34828 kfree (tx_descr);
34829@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34830 dump_skb ("<<<", vc, skb);
34831
34832 // VC layer stats
34833- atomic_inc(&atm_vcc->stats->rx);
34834+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34835 __net_timestamp(skb);
34836 // end of our responsibility
34837 atm_vcc->push (atm_vcc, skb);
34838@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34839 } else {
34840 PRINTK (KERN_INFO, "dropped over-size frame");
34841 // should we count this?
34842- atomic_inc(&atm_vcc->stats->rx_drop);
34843+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34844 }
34845
34846 } else {
34847@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34848 }
34849
34850 if (check_area (skb->data, skb->len)) {
34851- atomic_inc(&atm_vcc->stats->tx_err);
34852+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34853 return -ENOMEM; // ?
34854 }
34855
34856diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34857index 0e3f8f9..765a7a5 100644
34858--- a/drivers/atm/atmtcp.c
34859+++ b/drivers/atm/atmtcp.c
34860@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34861 if (vcc->pop) vcc->pop(vcc,skb);
34862 else dev_kfree_skb(skb);
34863 if (dev_data) return 0;
34864- atomic_inc(&vcc->stats->tx_err);
34865+ atomic_inc_unchecked(&vcc->stats->tx_err);
34866 return -ENOLINK;
34867 }
34868 size = skb->len+sizeof(struct atmtcp_hdr);
34869@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34870 if (!new_skb) {
34871 if (vcc->pop) vcc->pop(vcc,skb);
34872 else dev_kfree_skb(skb);
34873- atomic_inc(&vcc->stats->tx_err);
34874+ atomic_inc_unchecked(&vcc->stats->tx_err);
34875 return -ENOBUFS;
34876 }
34877 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34878@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34879 if (vcc->pop) vcc->pop(vcc,skb);
34880 else dev_kfree_skb(skb);
34881 out_vcc->push(out_vcc,new_skb);
34882- atomic_inc(&vcc->stats->tx);
34883- atomic_inc(&out_vcc->stats->rx);
34884+ atomic_inc_unchecked(&vcc->stats->tx);
34885+ atomic_inc_unchecked(&out_vcc->stats->rx);
34886 return 0;
34887 }
34888
34889@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34890 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34891 read_unlock(&vcc_sklist_lock);
34892 if (!out_vcc) {
34893- atomic_inc(&vcc->stats->tx_err);
34894+ atomic_inc_unchecked(&vcc->stats->tx_err);
34895 goto done;
34896 }
34897 skb_pull(skb,sizeof(struct atmtcp_hdr));
34898@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34899 __net_timestamp(new_skb);
34900 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34901 out_vcc->push(out_vcc,new_skb);
34902- atomic_inc(&vcc->stats->tx);
34903- atomic_inc(&out_vcc->stats->rx);
34904+ atomic_inc_unchecked(&vcc->stats->tx);
34905+ atomic_inc_unchecked(&out_vcc->stats->rx);
34906 done:
34907 if (vcc->pop) vcc->pop(vcc,skb);
34908 else dev_kfree_skb(skb);
34909diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34910index b1955ba..b179940 100644
34911--- a/drivers/atm/eni.c
34912+++ b/drivers/atm/eni.c
34913@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34914 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34915 vcc->dev->number);
34916 length = 0;
34917- atomic_inc(&vcc->stats->rx_err);
34918+ atomic_inc_unchecked(&vcc->stats->rx_err);
34919 }
34920 else {
34921 length = ATM_CELL_SIZE-1; /* no HEC */
34922@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34923 size);
34924 }
34925 eff = length = 0;
34926- atomic_inc(&vcc->stats->rx_err);
34927+ atomic_inc_unchecked(&vcc->stats->rx_err);
34928 }
34929 else {
34930 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34931@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34932 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34933 vcc->dev->number,vcc->vci,length,size << 2,descr);
34934 length = eff = 0;
34935- atomic_inc(&vcc->stats->rx_err);
34936+ atomic_inc_unchecked(&vcc->stats->rx_err);
34937 }
34938 }
34939 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34940@@ -767,7 +767,7 @@ rx_dequeued++;
34941 vcc->push(vcc,skb);
34942 pushed++;
34943 }
34944- atomic_inc(&vcc->stats->rx);
34945+ atomic_inc_unchecked(&vcc->stats->rx);
34946 }
34947 wake_up(&eni_dev->rx_wait);
34948 }
34949@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34950 PCI_DMA_TODEVICE);
34951 if (vcc->pop) vcc->pop(vcc,skb);
34952 else dev_kfree_skb_irq(skb);
34953- atomic_inc(&vcc->stats->tx);
34954+ atomic_inc_unchecked(&vcc->stats->tx);
34955 wake_up(&eni_dev->tx_wait);
34956 dma_complete++;
34957 }
34958diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34959index b41c948..a002b17 100644
34960--- a/drivers/atm/firestream.c
34961+++ b/drivers/atm/firestream.c
34962@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34963 }
34964 }
34965
34966- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34967+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34968
34969 fs_dprintk (FS_DEBUG_TXMEM, "i");
34970 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34971@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34972 #endif
34973 skb_put (skb, qe->p1 & 0xffff);
34974 ATM_SKB(skb)->vcc = atm_vcc;
34975- atomic_inc(&atm_vcc->stats->rx);
34976+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34977 __net_timestamp(skb);
34978 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34979 atm_vcc->push (atm_vcc, skb);
34980@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34981 kfree (pe);
34982 }
34983 if (atm_vcc)
34984- atomic_inc(&atm_vcc->stats->rx_drop);
34985+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34986 break;
34987 case 0x1f: /* Reassembly abort: no buffers. */
34988 /* Silently increment error counter. */
34989 if (atm_vcc)
34990- atomic_inc(&atm_vcc->stats->rx_drop);
34991+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34992 break;
34993 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34994 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34995diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34996index 204814e..cede831 100644
34997--- a/drivers/atm/fore200e.c
34998+++ b/drivers/atm/fore200e.c
34999@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35000 #endif
35001 /* check error condition */
35002 if (*entry->status & STATUS_ERROR)
35003- atomic_inc(&vcc->stats->tx_err);
35004+ atomic_inc_unchecked(&vcc->stats->tx_err);
35005 else
35006- atomic_inc(&vcc->stats->tx);
35007+ atomic_inc_unchecked(&vcc->stats->tx);
35008 }
35009 }
35010
35011@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35012 if (skb == NULL) {
35013 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35014
35015- atomic_inc(&vcc->stats->rx_drop);
35016+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35017 return -ENOMEM;
35018 }
35019
35020@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35021
35022 dev_kfree_skb_any(skb);
35023
35024- atomic_inc(&vcc->stats->rx_drop);
35025+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35026 return -ENOMEM;
35027 }
35028
35029 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35030
35031 vcc->push(vcc, skb);
35032- atomic_inc(&vcc->stats->rx);
35033+ atomic_inc_unchecked(&vcc->stats->rx);
35034
35035 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35036
35037@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35038 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35039 fore200e->atm_dev->number,
35040 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35041- atomic_inc(&vcc->stats->rx_err);
35042+ atomic_inc_unchecked(&vcc->stats->rx_err);
35043 }
35044 }
35045
35046@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35047 goto retry_here;
35048 }
35049
35050- atomic_inc(&vcc->stats->tx_err);
35051+ atomic_inc_unchecked(&vcc->stats->tx_err);
35052
35053 fore200e->tx_sat++;
35054 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35055diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35056index 507362a..a845e57 100644
35057--- a/drivers/atm/he.c
35058+++ b/drivers/atm/he.c
35059@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35060
35061 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35062 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35063- atomic_inc(&vcc->stats->rx_drop);
35064+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35065 goto return_host_buffers;
35066 }
35067
35068@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35069 RBRQ_LEN_ERR(he_dev->rbrq_head)
35070 ? "LEN_ERR" : "",
35071 vcc->vpi, vcc->vci);
35072- atomic_inc(&vcc->stats->rx_err);
35073+ atomic_inc_unchecked(&vcc->stats->rx_err);
35074 goto return_host_buffers;
35075 }
35076
35077@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35078 vcc->push(vcc, skb);
35079 spin_lock(&he_dev->global_lock);
35080
35081- atomic_inc(&vcc->stats->rx);
35082+ atomic_inc_unchecked(&vcc->stats->rx);
35083
35084 return_host_buffers:
35085 ++pdus_assembled;
35086@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35087 tpd->vcc->pop(tpd->vcc, tpd->skb);
35088 else
35089 dev_kfree_skb_any(tpd->skb);
35090- atomic_inc(&tpd->vcc->stats->tx_err);
35091+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35092 }
35093 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35094 return;
35095@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35096 vcc->pop(vcc, skb);
35097 else
35098 dev_kfree_skb_any(skb);
35099- atomic_inc(&vcc->stats->tx_err);
35100+ atomic_inc_unchecked(&vcc->stats->tx_err);
35101 return -EINVAL;
35102 }
35103
35104@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35105 vcc->pop(vcc, skb);
35106 else
35107 dev_kfree_skb_any(skb);
35108- atomic_inc(&vcc->stats->tx_err);
35109+ atomic_inc_unchecked(&vcc->stats->tx_err);
35110 return -EINVAL;
35111 }
35112 #endif
35113@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35114 vcc->pop(vcc, skb);
35115 else
35116 dev_kfree_skb_any(skb);
35117- atomic_inc(&vcc->stats->tx_err);
35118+ atomic_inc_unchecked(&vcc->stats->tx_err);
35119 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35120 return -ENOMEM;
35121 }
35122@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35123 vcc->pop(vcc, skb);
35124 else
35125 dev_kfree_skb_any(skb);
35126- atomic_inc(&vcc->stats->tx_err);
35127+ atomic_inc_unchecked(&vcc->stats->tx_err);
35128 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35129 return -ENOMEM;
35130 }
35131@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35132 __enqueue_tpd(he_dev, tpd, cid);
35133 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35134
35135- atomic_inc(&vcc->stats->tx);
35136+ atomic_inc_unchecked(&vcc->stats->tx);
35137
35138 return 0;
35139 }
35140diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35141index 1dc0519..1aadaf7 100644
35142--- a/drivers/atm/horizon.c
35143+++ b/drivers/atm/horizon.c
35144@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35145 {
35146 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35147 // VC layer stats
35148- atomic_inc(&vcc->stats->rx);
35149+ atomic_inc_unchecked(&vcc->stats->rx);
35150 __net_timestamp(skb);
35151 // end of our responsibility
35152 vcc->push (vcc, skb);
35153@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35154 dev->tx_iovec = NULL;
35155
35156 // VC layer stats
35157- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35158+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35159
35160 // free the skb
35161 hrz_kfree_skb (skb);
35162diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35163index 272f009..a18ba55 100644
35164--- a/drivers/atm/idt77252.c
35165+++ b/drivers/atm/idt77252.c
35166@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35167 else
35168 dev_kfree_skb(skb);
35169
35170- atomic_inc(&vcc->stats->tx);
35171+ atomic_inc_unchecked(&vcc->stats->tx);
35172 }
35173
35174 atomic_dec(&scq->used);
35175@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35176 if ((sb = dev_alloc_skb(64)) == NULL) {
35177 printk("%s: Can't allocate buffers for aal0.\n",
35178 card->name);
35179- atomic_add(i, &vcc->stats->rx_drop);
35180+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35181 break;
35182 }
35183 if (!atm_charge(vcc, sb->truesize)) {
35184 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35185 card->name);
35186- atomic_add(i - 1, &vcc->stats->rx_drop);
35187+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35188 dev_kfree_skb(sb);
35189 break;
35190 }
35191@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35192 ATM_SKB(sb)->vcc = vcc;
35193 __net_timestamp(sb);
35194 vcc->push(vcc, sb);
35195- atomic_inc(&vcc->stats->rx);
35196+ atomic_inc_unchecked(&vcc->stats->rx);
35197
35198 cell += ATM_CELL_PAYLOAD;
35199 }
35200@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35201 "(CDC: %08x)\n",
35202 card->name, len, rpp->len, readl(SAR_REG_CDC));
35203 recycle_rx_pool_skb(card, rpp);
35204- atomic_inc(&vcc->stats->rx_err);
35205+ atomic_inc_unchecked(&vcc->stats->rx_err);
35206 return;
35207 }
35208 if (stat & SAR_RSQE_CRC) {
35209 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35210 recycle_rx_pool_skb(card, rpp);
35211- atomic_inc(&vcc->stats->rx_err);
35212+ atomic_inc_unchecked(&vcc->stats->rx_err);
35213 return;
35214 }
35215 if (skb_queue_len(&rpp->queue) > 1) {
35216@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35217 RXPRINTK("%s: Can't alloc RX skb.\n",
35218 card->name);
35219 recycle_rx_pool_skb(card, rpp);
35220- atomic_inc(&vcc->stats->rx_err);
35221+ atomic_inc_unchecked(&vcc->stats->rx_err);
35222 return;
35223 }
35224 if (!atm_charge(vcc, skb->truesize)) {
35225@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35226 __net_timestamp(skb);
35227
35228 vcc->push(vcc, skb);
35229- atomic_inc(&vcc->stats->rx);
35230+ atomic_inc_unchecked(&vcc->stats->rx);
35231
35232 return;
35233 }
35234@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35235 __net_timestamp(skb);
35236
35237 vcc->push(vcc, skb);
35238- atomic_inc(&vcc->stats->rx);
35239+ atomic_inc_unchecked(&vcc->stats->rx);
35240
35241 if (skb->truesize > SAR_FB_SIZE_3)
35242 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35243@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35244 if (vcc->qos.aal != ATM_AAL0) {
35245 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35246 card->name, vpi, vci);
35247- atomic_inc(&vcc->stats->rx_drop);
35248+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35249 goto drop;
35250 }
35251
35252 if ((sb = dev_alloc_skb(64)) == NULL) {
35253 printk("%s: Can't allocate buffers for AAL0.\n",
35254 card->name);
35255- atomic_inc(&vcc->stats->rx_err);
35256+ atomic_inc_unchecked(&vcc->stats->rx_err);
35257 goto drop;
35258 }
35259
35260@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35261 ATM_SKB(sb)->vcc = vcc;
35262 __net_timestamp(sb);
35263 vcc->push(vcc, sb);
35264- atomic_inc(&vcc->stats->rx);
35265+ atomic_inc_unchecked(&vcc->stats->rx);
35266
35267 drop:
35268 skb_pull(queue, 64);
35269@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35270
35271 if (vc == NULL) {
35272 printk("%s: NULL connection in send().\n", card->name);
35273- atomic_inc(&vcc->stats->tx_err);
35274+ atomic_inc_unchecked(&vcc->stats->tx_err);
35275 dev_kfree_skb(skb);
35276 return -EINVAL;
35277 }
35278 if (!test_bit(VCF_TX, &vc->flags)) {
35279 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35280- atomic_inc(&vcc->stats->tx_err);
35281+ atomic_inc_unchecked(&vcc->stats->tx_err);
35282 dev_kfree_skb(skb);
35283 return -EINVAL;
35284 }
35285@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35286 break;
35287 default:
35288 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35289- atomic_inc(&vcc->stats->tx_err);
35290+ atomic_inc_unchecked(&vcc->stats->tx_err);
35291 dev_kfree_skb(skb);
35292 return -EINVAL;
35293 }
35294
35295 if (skb_shinfo(skb)->nr_frags != 0) {
35296 printk("%s: No scatter-gather yet.\n", card->name);
35297- atomic_inc(&vcc->stats->tx_err);
35298+ atomic_inc_unchecked(&vcc->stats->tx_err);
35299 dev_kfree_skb(skb);
35300 return -EINVAL;
35301 }
35302@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35303
35304 err = queue_skb(card, vc, skb, oam);
35305 if (err) {
35306- atomic_inc(&vcc->stats->tx_err);
35307+ atomic_inc_unchecked(&vcc->stats->tx_err);
35308 dev_kfree_skb(skb);
35309 return err;
35310 }
35311@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35312 skb = dev_alloc_skb(64);
35313 if (!skb) {
35314 printk("%s: Out of memory in send_oam().\n", card->name);
35315- atomic_inc(&vcc->stats->tx_err);
35316+ atomic_inc_unchecked(&vcc->stats->tx_err);
35317 return -ENOMEM;
35318 }
35319 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35320diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35321index 4217f29..88f547a 100644
35322--- a/drivers/atm/iphase.c
35323+++ b/drivers/atm/iphase.c
35324@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35325 status = (u_short) (buf_desc_ptr->desc_mode);
35326 if (status & (RX_CER | RX_PTE | RX_OFL))
35327 {
35328- atomic_inc(&vcc->stats->rx_err);
35329+ atomic_inc_unchecked(&vcc->stats->rx_err);
35330 IF_ERR(printk("IA: bad packet, dropping it");)
35331 if (status & RX_CER) {
35332 IF_ERR(printk(" cause: packet CRC error\n");)
35333@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35334 len = dma_addr - buf_addr;
35335 if (len > iadev->rx_buf_sz) {
35336 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35337- atomic_inc(&vcc->stats->rx_err);
35338+ atomic_inc_unchecked(&vcc->stats->rx_err);
35339 goto out_free_desc;
35340 }
35341
35342@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35343 ia_vcc = INPH_IA_VCC(vcc);
35344 if (ia_vcc == NULL)
35345 {
35346- atomic_inc(&vcc->stats->rx_err);
35347+ atomic_inc_unchecked(&vcc->stats->rx_err);
35348 atm_return(vcc, skb->truesize);
35349 dev_kfree_skb_any(skb);
35350 goto INCR_DLE;
35351@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35352 if ((length > iadev->rx_buf_sz) || (length >
35353 (skb->len - sizeof(struct cpcs_trailer))))
35354 {
35355- atomic_inc(&vcc->stats->rx_err);
35356+ atomic_inc_unchecked(&vcc->stats->rx_err);
35357 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35358 length, skb->len);)
35359 atm_return(vcc, skb->truesize);
35360@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35361
35362 IF_RX(printk("rx_dle_intr: skb push");)
35363 vcc->push(vcc,skb);
35364- atomic_inc(&vcc->stats->rx);
35365+ atomic_inc_unchecked(&vcc->stats->rx);
35366 iadev->rx_pkt_cnt++;
35367 }
35368 INCR_DLE:
35369@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35370 {
35371 struct k_sonet_stats *stats;
35372 stats = &PRIV(_ia_dev[board])->sonet_stats;
35373- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35374- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35375- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35376- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35377- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35378- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35379- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35380- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35381- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35382+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35383+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35384+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35385+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35386+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35387+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35388+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35389+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35390+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35391 }
35392 ia_cmds.status = 0;
35393 break;
35394@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35395 if ((desc == 0) || (desc > iadev->num_tx_desc))
35396 {
35397 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35398- atomic_inc(&vcc->stats->tx);
35399+ atomic_inc_unchecked(&vcc->stats->tx);
35400 if (vcc->pop)
35401 vcc->pop(vcc, skb);
35402 else
35403@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35404 ATM_DESC(skb) = vcc->vci;
35405 skb_queue_tail(&iadev->tx_dma_q, skb);
35406
35407- atomic_inc(&vcc->stats->tx);
35408+ atomic_inc_unchecked(&vcc->stats->tx);
35409 iadev->tx_pkt_cnt++;
35410 /* Increment transaction counter */
35411 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35412
35413 #if 0
35414 /* add flow control logic */
35415- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35416+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35417 if (iavcc->vc_desc_cnt > 10) {
35418 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35419 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35420diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35421index fa7d701..1e404c7 100644
35422--- a/drivers/atm/lanai.c
35423+++ b/drivers/atm/lanai.c
35424@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35425 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35426 lanai_endtx(lanai, lvcc);
35427 lanai_free_skb(lvcc->tx.atmvcc, skb);
35428- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35429+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35430 }
35431
35432 /* Try to fill the buffer - don't call unless there is backlog */
35433@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35434 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35435 __net_timestamp(skb);
35436 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35437- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35438+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35439 out:
35440 lvcc->rx.buf.ptr = end;
35441 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35442@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35443 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35444 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35445 lanai->stats.service_rxnotaal5++;
35446- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35447+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35448 return 0;
35449 }
35450 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35451@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35452 int bytes;
35453 read_unlock(&vcc_sklist_lock);
35454 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35455- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35456+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35457 lvcc->stats.x.aal5.service_trash++;
35458 bytes = (SERVICE_GET_END(s) * 16) -
35459 (((unsigned long) lvcc->rx.buf.ptr) -
35460@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35461 }
35462 if (s & SERVICE_STREAM) {
35463 read_unlock(&vcc_sklist_lock);
35464- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35465+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35466 lvcc->stats.x.aal5.service_stream++;
35467 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35468 "PDU on VCI %d!\n", lanai->number, vci);
35469@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35470 return 0;
35471 }
35472 DPRINTK("got rx crc error on vci %d\n", vci);
35473- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35474+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35475 lvcc->stats.x.aal5.service_rxcrc++;
35476 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35477 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35478diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35479index 6587dc2..149833d 100644
35480--- a/drivers/atm/nicstar.c
35481+++ b/drivers/atm/nicstar.c
35482@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35483 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35484 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35485 card->index);
35486- atomic_inc(&vcc->stats->tx_err);
35487+ atomic_inc_unchecked(&vcc->stats->tx_err);
35488 dev_kfree_skb_any(skb);
35489 return -EINVAL;
35490 }
35491@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35492 if (!vc->tx) {
35493 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35494 card->index);
35495- atomic_inc(&vcc->stats->tx_err);
35496+ atomic_inc_unchecked(&vcc->stats->tx_err);
35497 dev_kfree_skb_any(skb);
35498 return -EINVAL;
35499 }
35500@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35501 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35502 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35503 card->index);
35504- atomic_inc(&vcc->stats->tx_err);
35505+ atomic_inc_unchecked(&vcc->stats->tx_err);
35506 dev_kfree_skb_any(skb);
35507 return -EINVAL;
35508 }
35509
35510 if (skb_shinfo(skb)->nr_frags != 0) {
35511 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35512- atomic_inc(&vcc->stats->tx_err);
35513+ atomic_inc_unchecked(&vcc->stats->tx_err);
35514 dev_kfree_skb_any(skb);
35515 return -EINVAL;
35516 }
35517@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35518 }
35519
35520 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35521- atomic_inc(&vcc->stats->tx_err);
35522+ atomic_inc_unchecked(&vcc->stats->tx_err);
35523 dev_kfree_skb_any(skb);
35524 return -EIO;
35525 }
35526- atomic_inc(&vcc->stats->tx);
35527+ atomic_inc_unchecked(&vcc->stats->tx);
35528
35529 return 0;
35530 }
35531@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35532 printk
35533 ("nicstar%d: Can't allocate buffers for aal0.\n",
35534 card->index);
35535- atomic_add(i, &vcc->stats->rx_drop);
35536+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35537 break;
35538 }
35539 if (!atm_charge(vcc, sb->truesize)) {
35540 RXPRINTK
35541 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35542 card->index);
35543- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35544+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35545 dev_kfree_skb_any(sb);
35546 break;
35547 }
35548@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35549 ATM_SKB(sb)->vcc = vcc;
35550 __net_timestamp(sb);
35551 vcc->push(vcc, sb);
35552- atomic_inc(&vcc->stats->rx);
35553+ atomic_inc_unchecked(&vcc->stats->rx);
35554 cell += ATM_CELL_PAYLOAD;
35555 }
35556
35557@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35558 if (iovb == NULL) {
35559 printk("nicstar%d: Out of iovec buffers.\n",
35560 card->index);
35561- atomic_inc(&vcc->stats->rx_drop);
35562+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35563 recycle_rx_buf(card, skb);
35564 return;
35565 }
35566@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35567 small or large buffer itself. */
35568 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35569 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35570- atomic_inc(&vcc->stats->rx_err);
35571+ atomic_inc_unchecked(&vcc->stats->rx_err);
35572 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35573 NS_MAX_IOVECS);
35574 NS_PRV_IOVCNT(iovb) = 0;
35575@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35576 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35577 card->index);
35578 which_list(card, skb);
35579- atomic_inc(&vcc->stats->rx_err);
35580+ atomic_inc_unchecked(&vcc->stats->rx_err);
35581 recycle_rx_buf(card, skb);
35582 vc->rx_iov = NULL;
35583 recycle_iov_buf(card, iovb);
35584@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35585 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35586 card->index);
35587 which_list(card, skb);
35588- atomic_inc(&vcc->stats->rx_err);
35589+ atomic_inc_unchecked(&vcc->stats->rx_err);
35590 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35591 NS_PRV_IOVCNT(iovb));
35592 vc->rx_iov = NULL;
35593@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35594 printk(" - PDU size mismatch.\n");
35595 else
35596 printk(".\n");
35597- atomic_inc(&vcc->stats->rx_err);
35598+ atomic_inc_unchecked(&vcc->stats->rx_err);
35599 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35600 NS_PRV_IOVCNT(iovb));
35601 vc->rx_iov = NULL;
35602@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35603 /* skb points to a small buffer */
35604 if (!atm_charge(vcc, skb->truesize)) {
35605 push_rxbufs(card, skb);
35606- atomic_inc(&vcc->stats->rx_drop);
35607+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35608 } else {
35609 skb_put(skb, len);
35610 dequeue_sm_buf(card, skb);
35611@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35612 ATM_SKB(skb)->vcc = vcc;
35613 __net_timestamp(skb);
35614 vcc->push(vcc, skb);
35615- atomic_inc(&vcc->stats->rx);
35616+ atomic_inc_unchecked(&vcc->stats->rx);
35617 }
35618 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35619 struct sk_buff *sb;
35620@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35621 if (len <= NS_SMBUFSIZE) {
35622 if (!atm_charge(vcc, sb->truesize)) {
35623 push_rxbufs(card, sb);
35624- atomic_inc(&vcc->stats->rx_drop);
35625+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35626 } else {
35627 skb_put(sb, len);
35628 dequeue_sm_buf(card, sb);
35629@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35630 ATM_SKB(sb)->vcc = vcc;
35631 __net_timestamp(sb);
35632 vcc->push(vcc, sb);
35633- atomic_inc(&vcc->stats->rx);
35634+ atomic_inc_unchecked(&vcc->stats->rx);
35635 }
35636
35637 push_rxbufs(card, skb);
35638@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35639
35640 if (!atm_charge(vcc, skb->truesize)) {
35641 push_rxbufs(card, skb);
35642- atomic_inc(&vcc->stats->rx_drop);
35643+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35644 } else {
35645 dequeue_lg_buf(card, skb);
35646 #ifdef NS_USE_DESTRUCTORS
35647@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35648 ATM_SKB(skb)->vcc = vcc;
35649 __net_timestamp(skb);
35650 vcc->push(vcc, skb);
35651- atomic_inc(&vcc->stats->rx);
35652+ atomic_inc_unchecked(&vcc->stats->rx);
35653 }
35654
35655 push_rxbufs(card, sb);
35656@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35657 printk
35658 ("nicstar%d: Out of huge buffers.\n",
35659 card->index);
35660- atomic_inc(&vcc->stats->rx_drop);
35661+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35662 recycle_iovec_rx_bufs(card,
35663 (struct iovec *)
35664 iovb->data,
35665@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35666 card->hbpool.count++;
35667 } else
35668 dev_kfree_skb_any(hb);
35669- atomic_inc(&vcc->stats->rx_drop);
35670+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35671 } else {
35672 /* Copy the small buffer to the huge buffer */
35673 sb = (struct sk_buff *)iov->iov_base;
35674@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35675 #endif /* NS_USE_DESTRUCTORS */
35676 __net_timestamp(hb);
35677 vcc->push(vcc, hb);
35678- atomic_inc(&vcc->stats->rx);
35679+ atomic_inc_unchecked(&vcc->stats->rx);
35680 }
35681 }
35682
35683diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35684index 32784d1..4a8434a 100644
35685--- a/drivers/atm/solos-pci.c
35686+++ b/drivers/atm/solos-pci.c
35687@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35688 }
35689 atm_charge(vcc, skb->truesize);
35690 vcc->push(vcc, skb);
35691- atomic_inc(&vcc->stats->rx);
35692+ atomic_inc_unchecked(&vcc->stats->rx);
35693 break;
35694
35695 case PKT_STATUS:
35696@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35697 vcc = SKB_CB(oldskb)->vcc;
35698
35699 if (vcc) {
35700- atomic_inc(&vcc->stats->tx);
35701+ atomic_inc_unchecked(&vcc->stats->tx);
35702 solos_pop(vcc, oldskb);
35703 } else {
35704 dev_kfree_skb_irq(oldskb);
35705diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35706index 0215934..ce9f5b1 100644
35707--- a/drivers/atm/suni.c
35708+++ b/drivers/atm/suni.c
35709@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35710
35711
35712 #define ADD_LIMITED(s,v) \
35713- atomic_add((v),&stats->s); \
35714- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35715+ atomic_add_unchecked((v),&stats->s); \
35716+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35717
35718
35719 static void suni_hz(unsigned long from_timer)
35720diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35721index 5120a96..e2572bd 100644
35722--- a/drivers/atm/uPD98402.c
35723+++ b/drivers/atm/uPD98402.c
35724@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35725 struct sonet_stats tmp;
35726 int error = 0;
35727
35728- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35729+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35730 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35731 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35732 if (zero && !error) {
35733@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35734
35735
35736 #define ADD_LIMITED(s,v) \
35737- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35738- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35739- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35740+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35741+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35742+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35743
35744
35745 static void stat_event(struct atm_dev *dev)
35746@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35747 if (reason & uPD98402_INT_PFM) stat_event(dev);
35748 if (reason & uPD98402_INT_PCO) {
35749 (void) GET(PCOCR); /* clear interrupt cause */
35750- atomic_add(GET(HECCT),
35751+ atomic_add_unchecked(GET(HECCT),
35752 &PRIV(dev)->sonet_stats.uncorr_hcs);
35753 }
35754 if ((reason & uPD98402_INT_RFO) &&
35755@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35756 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35757 uPD98402_INT_LOS),PIMR); /* enable them */
35758 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35759- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35760- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35761- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35762+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35763+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35764+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35765 return 0;
35766 }
35767
35768diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35769index 969c3c2..9b72956 100644
35770--- a/drivers/atm/zatm.c
35771+++ b/drivers/atm/zatm.c
35772@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35773 }
35774 if (!size) {
35775 dev_kfree_skb_irq(skb);
35776- if (vcc) atomic_inc(&vcc->stats->rx_err);
35777+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35778 continue;
35779 }
35780 if (!atm_charge(vcc,skb->truesize)) {
35781@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35782 skb->len = size;
35783 ATM_SKB(skb)->vcc = vcc;
35784 vcc->push(vcc,skb);
35785- atomic_inc(&vcc->stats->rx);
35786+ atomic_inc_unchecked(&vcc->stats->rx);
35787 }
35788 zout(pos & 0xffff,MTA(mbx));
35789 #if 0 /* probably a stupid idea */
35790@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35791 skb_queue_head(&zatm_vcc->backlog,skb);
35792 break;
35793 }
35794- atomic_inc(&vcc->stats->tx);
35795+ atomic_inc_unchecked(&vcc->stats->tx);
35796 wake_up(&zatm_vcc->tx_wait);
35797 }
35798
35799diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35800index d414331..b4dd4ba 100644
35801--- a/drivers/base/bus.c
35802+++ b/drivers/base/bus.c
35803@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35804 return -EINVAL;
35805
35806 mutex_lock(&subsys->p->mutex);
35807- list_add_tail(&sif->node, &subsys->p->interfaces);
35808+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35809 if (sif->add_dev) {
35810 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35811 while ((dev = subsys_dev_iter_next(&iter)))
35812@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35813 subsys = sif->subsys;
35814
35815 mutex_lock(&subsys->p->mutex);
35816- list_del_init(&sif->node);
35817+ pax_list_del_init((struct list_head *)&sif->node);
35818 if (sif->remove_dev) {
35819 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35820 while ((dev = subsys_dev_iter_next(&iter)))
35821diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35822index 7413d06..79155fa 100644
35823--- a/drivers/base/devtmpfs.c
35824+++ b/drivers/base/devtmpfs.c
35825@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35826 if (!thread)
35827 return 0;
35828
35829- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35830+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35831 if (err)
35832 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35833 else
35834@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35835 *err = sys_unshare(CLONE_NEWNS);
35836 if (*err)
35837 goto out;
35838- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35839+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35840 if (*err)
35841 goto out;
35842- sys_chdir("/.."); /* will traverse into overmounted root */
35843- sys_chroot(".");
35844+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35845+ sys_chroot((char __force_user *)".");
35846 complete(&setup_done);
35847 while (1) {
35848 spin_lock(&req_lock);
35849diff --git a/drivers/base/node.c b/drivers/base/node.c
35850index 7616a77c..8f57f51 100644
35851--- a/drivers/base/node.c
35852+++ b/drivers/base/node.c
35853@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35854 struct node_attr {
35855 struct device_attribute attr;
35856 enum node_states state;
35857-};
35858+} __do_const;
35859
35860 static ssize_t show_node_state(struct device *dev,
35861 struct device_attribute *attr, char *buf)
35862diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35863index bfb8955..42c9b9a 100644
35864--- a/drivers/base/power/domain.c
35865+++ b/drivers/base/power/domain.c
35866@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35867 {
35868 struct cpuidle_driver *cpuidle_drv;
35869 struct gpd_cpu_data *cpu_data;
35870- struct cpuidle_state *idle_state;
35871+ cpuidle_state_no_const *idle_state;
35872 int ret = 0;
35873
35874 if (IS_ERR_OR_NULL(genpd) || state < 0)
35875@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35876 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35877 {
35878 struct gpd_cpu_data *cpu_data;
35879- struct cpuidle_state *idle_state;
35880+ cpuidle_state_no_const *idle_state;
35881 int ret = 0;
35882
35883 if (IS_ERR_OR_NULL(genpd))
35884diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35885index a53ebd2..8f73eeb 100644
35886--- a/drivers/base/power/sysfs.c
35887+++ b/drivers/base/power/sysfs.c
35888@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35889 return -EIO;
35890 }
35891 }
35892- return sprintf(buf, p);
35893+ return sprintf(buf, "%s", p);
35894 }
35895
35896 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35897diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35898index 2d56f41..8830f19 100644
35899--- a/drivers/base/power/wakeup.c
35900+++ b/drivers/base/power/wakeup.c
35901@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35902 * They need to be modified together atomically, so it's better to use one
35903 * atomic variable to hold them both.
35904 */
35905-static atomic_t combined_event_count = ATOMIC_INIT(0);
35906+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35907
35908 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35909 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35910
35911 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35912 {
35913- unsigned int comb = atomic_read(&combined_event_count);
35914+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35915
35916 *cnt = (comb >> IN_PROGRESS_BITS);
35917 *inpr = comb & MAX_IN_PROGRESS;
35918@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35919 ws->start_prevent_time = ws->last_time;
35920
35921 /* Increment the counter of events in progress. */
35922- cec = atomic_inc_return(&combined_event_count);
35923+ cec = atomic_inc_return_unchecked(&combined_event_count);
35924
35925 trace_wakeup_source_activate(ws->name, cec);
35926 }
35927@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35928 * Increment the counter of registered wakeup events and decrement the
35929 * couter of wakeup events in progress simultaneously.
35930 */
35931- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35932+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35933 trace_wakeup_source_deactivate(ws->name, cec);
35934
35935 split_counters(&cnt, &inpr);
35936diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35937index e8d11b6..7b1b36f 100644
35938--- a/drivers/base/syscore.c
35939+++ b/drivers/base/syscore.c
35940@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35941 void register_syscore_ops(struct syscore_ops *ops)
35942 {
35943 mutex_lock(&syscore_ops_lock);
35944- list_add_tail(&ops->node, &syscore_ops_list);
35945+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35946 mutex_unlock(&syscore_ops_lock);
35947 }
35948 EXPORT_SYMBOL_GPL(register_syscore_ops);
35949@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35950 void unregister_syscore_ops(struct syscore_ops *ops)
35951 {
35952 mutex_lock(&syscore_ops_lock);
35953- list_del(&ops->node);
35954+ pax_list_del((struct list_head *)&ops->node);
35955 mutex_unlock(&syscore_ops_lock);
35956 }
35957 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35958diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35959index 90a4e6b..002d10f 100644
35960--- a/drivers/block/cciss.c
35961+++ b/drivers/block/cciss.c
35962@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
35963 while (!list_empty(&h->reqQ)) {
35964 c = list_entry(h->reqQ.next, CommandList_struct, list);
35965 /* can't do anything if fifo is full */
35966- if ((h->access.fifo_full(h))) {
35967+ if ((h->access->fifo_full(h))) {
35968 dev_warn(&h->pdev->dev, "fifo full\n");
35969 break;
35970 }
35971@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
35972 h->Qdepth--;
35973
35974 /* Tell the controller execute command */
35975- h->access.submit_command(h, c);
35976+ h->access->submit_command(h, c);
35977
35978 /* Put job onto the completed Q */
35979 addQ(&h->cmpQ, c);
35980@@ -3447,17 +3447,17 @@ startio:
35981
35982 static inline unsigned long get_next_completion(ctlr_info_t *h)
35983 {
35984- return h->access.command_completed(h);
35985+ return h->access->command_completed(h);
35986 }
35987
35988 static inline int interrupt_pending(ctlr_info_t *h)
35989 {
35990- return h->access.intr_pending(h);
35991+ return h->access->intr_pending(h);
35992 }
35993
35994 static inline long interrupt_not_for_us(ctlr_info_t *h)
35995 {
35996- return ((h->access.intr_pending(h) == 0) ||
35997+ return ((h->access->intr_pending(h) == 0) ||
35998 (h->interrupts_enabled == 0));
35999 }
36000
36001@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36002 u32 a;
36003
36004 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36005- return h->access.command_completed(h);
36006+ return h->access->command_completed(h);
36007
36008 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36009 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36010@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36011 trans_support & CFGTBL_Trans_use_short_tags);
36012
36013 /* Change the access methods to the performant access methods */
36014- h->access = SA5_performant_access;
36015+ h->access = &SA5_performant_access;
36016 h->transMethod = CFGTBL_Trans_Performant;
36017
36018 return;
36019@@ -4320,7 +4320,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36020 if (prod_index < 0)
36021 return -ENODEV;
36022 h->product_name = products[prod_index].product_name;
36023- h->access = *(products[prod_index].access);
36024+ h->access = products[prod_index].access;
36025
36026 if (cciss_board_disabled(h)) {
36027 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36028@@ -5052,7 +5052,7 @@ reinit_after_soft_reset:
36029 }
36030
36031 /* make sure the board interrupts are off */
36032- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36033+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36034 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36035 if (rc)
36036 goto clean2;
36037@@ -5102,7 +5102,7 @@ reinit_after_soft_reset:
36038 * fake ones to scoop up any residual completions.
36039 */
36040 spin_lock_irqsave(&h->lock, flags);
36041- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36042+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36043 spin_unlock_irqrestore(&h->lock, flags);
36044 free_irq(h->intr[h->intr_mode], h);
36045 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36046@@ -5122,9 +5122,9 @@ reinit_after_soft_reset:
36047 dev_info(&h->pdev->dev, "Board READY.\n");
36048 dev_info(&h->pdev->dev,
36049 "Waiting for stale completions to drain.\n");
36050- h->access.set_intr_mask(h, CCISS_INTR_ON);
36051+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36052 msleep(10000);
36053- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36054+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36055
36056 rc = controller_reset_failed(h->cfgtable);
36057 if (rc)
36058@@ -5147,7 +5147,7 @@ reinit_after_soft_reset:
36059 cciss_scsi_setup(h);
36060
36061 /* Turn the interrupts on so we can service requests */
36062- h->access.set_intr_mask(h, CCISS_INTR_ON);
36063+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36064
36065 /* Get the firmware version */
36066 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36067@@ -5219,7 +5219,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36068 kfree(flush_buf);
36069 if (return_code != IO_OK)
36070 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36071- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36072+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36073 free_irq(h->intr[h->intr_mode], h);
36074 }
36075
36076diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36077index 7fda30e..eb5dfe0 100644
36078--- a/drivers/block/cciss.h
36079+++ b/drivers/block/cciss.h
36080@@ -101,7 +101,7 @@ struct ctlr_info
36081 /* information about each logical volume */
36082 drive_info_struct *drv[CISS_MAX_LUN];
36083
36084- struct access_method access;
36085+ struct access_method *access;
36086
36087 /* queue and queue Info */
36088 struct list_head reqQ;
36089diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36090index 2b94403..fd6ad1f 100644
36091--- a/drivers/block/cpqarray.c
36092+++ b/drivers/block/cpqarray.c
36093@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36094 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36095 goto Enomem4;
36096 }
36097- hba[i]->access.set_intr_mask(hba[i], 0);
36098+ hba[i]->access->set_intr_mask(hba[i], 0);
36099 if (request_irq(hba[i]->intr, do_ida_intr,
36100 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36101 {
36102@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36103 add_timer(&hba[i]->timer);
36104
36105 /* Enable IRQ now that spinlock and rate limit timer are set up */
36106- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36107+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36108
36109 for(j=0; j<NWD; j++) {
36110 struct gendisk *disk = ida_gendisk[i][j];
36111@@ -694,7 +694,7 @@ DBGINFO(
36112 for(i=0; i<NR_PRODUCTS; i++) {
36113 if (board_id == products[i].board_id) {
36114 c->product_name = products[i].product_name;
36115- c->access = *(products[i].access);
36116+ c->access = products[i].access;
36117 break;
36118 }
36119 }
36120@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36121 hba[ctlr]->intr = intr;
36122 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36123 hba[ctlr]->product_name = products[j].product_name;
36124- hba[ctlr]->access = *(products[j].access);
36125+ hba[ctlr]->access = products[j].access;
36126 hba[ctlr]->ctlr = ctlr;
36127 hba[ctlr]->board_id = board_id;
36128 hba[ctlr]->pci_dev = NULL; /* not PCI */
36129@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36130
36131 while((c = h->reqQ) != NULL) {
36132 /* Can't do anything if we're busy */
36133- if (h->access.fifo_full(h) == 0)
36134+ if (h->access->fifo_full(h) == 0)
36135 return;
36136
36137 /* Get the first entry from the request Q */
36138@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36139 h->Qdepth--;
36140
36141 /* Tell the controller to do our bidding */
36142- h->access.submit_command(h, c);
36143+ h->access->submit_command(h, c);
36144
36145 /* Get onto the completion Q */
36146 addQ(&h->cmpQ, c);
36147@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36148 unsigned long flags;
36149 __u32 a,a1;
36150
36151- istat = h->access.intr_pending(h);
36152+ istat = h->access->intr_pending(h);
36153 /* Is this interrupt for us? */
36154 if (istat == 0)
36155 return IRQ_NONE;
36156@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36157 */
36158 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36159 if (istat & FIFO_NOT_EMPTY) {
36160- while((a = h->access.command_completed(h))) {
36161+ while((a = h->access->command_completed(h))) {
36162 a1 = a; a &= ~3;
36163 if ((c = h->cmpQ) == NULL)
36164 {
36165@@ -1448,11 +1448,11 @@ static int sendcmd(
36166 /*
36167 * Disable interrupt
36168 */
36169- info_p->access.set_intr_mask(info_p, 0);
36170+ info_p->access->set_intr_mask(info_p, 0);
36171 /* Make sure there is room in the command FIFO */
36172 /* Actually it should be completely empty at this time. */
36173 for (i = 200000; i > 0; i--) {
36174- temp = info_p->access.fifo_full(info_p);
36175+ temp = info_p->access->fifo_full(info_p);
36176 if (temp != 0) {
36177 break;
36178 }
36179@@ -1465,7 +1465,7 @@ DBG(
36180 /*
36181 * Send the cmd
36182 */
36183- info_p->access.submit_command(info_p, c);
36184+ info_p->access->submit_command(info_p, c);
36185 complete = pollcomplete(ctlr);
36186
36187 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36188@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36189 * we check the new geometry. Then turn interrupts back on when
36190 * we're done.
36191 */
36192- host->access.set_intr_mask(host, 0);
36193+ host->access->set_intr_mask(host, 0);
36194 getgeometry(ctlr);
36195- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36196+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36197
36198 for(i=0; i<NWD; i++) {
36199 struct gendisk *disk = ida_gendisk[ctlr][i];
36200@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36201 /* Wait (up to 2 seconds) for a command to complete */
36202
36203 for (i = 200000; i > 0; i--) {
36204- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36205+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36206 if (done == 0) {
36207 udelay(10); /* a short fixed delay */
36208 } else
36209diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36210index be73e9d..7fbf140 100644
36211--- a/drivers/block/cpqarray.h
36212+++ b/drivers/block/cpqarray.h
36213@@ -99,7 +99,7 @@ struct ctlr_info {
36214 drv_info_t drv[NWD];
36215 struct proc_dir_entry *proc;
36216
36217- struct access_method access;
36218+ struct access_method *access;
36219
36220 cmdlist_t *reqQ;
36221 cmdlist_t *cmpQ;
36222diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36223index 2d7f608..11245fe 100644
36224--- a/drivers/block/drbd/drbd_int.h
36225+++ b/drivers/block/drbd/drbd_int.h
36226@@ -582,7 +582,7 @@ struct drbd_epoch {
36227 struct drbd_tconn *tconn;
36228 struct list_head list;
36229 unsigned int barrier_nr;
36230- atomic_t epoch_size; /* increased on every request added. */
36231+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36232 atomic_t active; /* increased on every req. added, and dec on every finished. */
36233 unsigned long flags;
36234 };
36235@@ -1022,7 +1022,7 @@ struct drbd_conf {
36236 unsigned int al_tr_number;
36237 int al_tr_cycle;
36238 wait_queue_head_t seq_wait;
36239- atomic_t packet_seq;
36240+ atomic_unchecked_t packet_seq;
36241 unsigned int peer_seq;
36242 spinlock_t peer_seq_lock;
36243 unsigned int minor;
36244@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36245 char __user *uoptval;
36246 int err;
36247
36248- uoptval = (char __user __force *)optval;
36249+ uoptval = (char __force_user *)optval;
36250
36251 set_fs(KERNEL_DS);
36252 if (level == SOL_SOCKET)
36253diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36254index 55635ed..40e837c 100644
36255--- a/drivers/block/drbd/drbd_main.c
36256+++ b/drivers/block/drbd/drbd_main.c
36257@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36258 p->sector = sector;
36259 p->block_id = block_id;
36260 p->blksize = blksize;
36261- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36262+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36263 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36264 }
36265
36266@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36267 return -EIO;
36268 p->sector = cpu_to_be64(req->i.sector);
36269 p->block_id = (unsigned long)req;
36270- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36271+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36272 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36273 if (mdev->state.conn >= C_SYNC_SOURCE &&
36274 mdev->state.conn <= C_PAUSED_SYNC_T)
36275@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36276 {
36277 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36278
36279- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36280- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36281+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36282+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36283 kfree(tconn->current_epoch);
36284
36285 idr_destroy(&tconn->volumes);
36286diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36287index 8cc1e64..ba7ffa9 100644
36288--- a/drivers/block/drbd/drbd_nl.c
36289+++ b/drivers/block/drbd/drbd_nl.c
36290@@ -3440,7 +3440,7 @@ out:
36291
36292 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36293 {
36294- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36295+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36296 struct sk_buff *msg;
36297 struct drbd_genlmsghdr *d_out;
36298 unsigned seq;
36299@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36300 return;
36301 }
36302
36303- seq = atomic_inc_return(&drbd_genl_seq);
36304+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36305 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36306 if (!msg)
36307 goto failed;
36308diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36309index cc29cd3..d4b058b 100644
36310--- a/drivers/block/drbd/drbd_receiver.c
36311+++ b/drivers/block/drbd/drbd_receiver.c
36312@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36313 {
36314 int err;
36315
36316- atomic_set(&mdev->packet_seq, 0);
36317+ atomic_set_unchecked(&mdev->packet_seq, 0);
36318 mdev->peer_seq = 0;
36319
36320 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36321@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36322 do {
36323 next_epoch = NULL;
36324
36325- epoch_size = atomic_read(&epoch->epoch_size);
36326+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36327
36328 switch (ev & ~EV_CLEANUP) {
36329 case EV_PUT:
36330@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36331 rv = FE_DESTROYED;
36332 } else {
36333 epoch->flags = 0;
36334- atomic_set(&epoch->epoch_size, 0);
36335+ atomic_set_unchecked(&epoch->epoch_size, 0);
36336 /* atomic_set(&epoch->active, 0); is already zero */
36337 if (rv == FE_STILL_LIVE)
36338 rv = FE_RECYCLED;
36339@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36340 conn_wait_active_ee_empty(tconn);
36341 drbd_flush(tconn);
36342
36343- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36344+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36345 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36346 if (epoch)
36347 break;
36348@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36349 }
36350
36351 epoch->flags = 0;
36352- atomic_set(&epoch->epoch_size, 0);
36353+ atomic_set_unchecked(&epoch->epoch_size, 0);
36354 atomic_set(&epoch->active, 0);
36355
36356 spin_lock(&tconn->epoch_lock);
36357- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36358+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36359 list_add(&epoch->list, &tconn->current_epoch->list);
36360 tconn->current_epoch = epoch;
36361 tconn->epochs++;
36362@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36363
36364 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36365 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36366- atomic_inc(&tconn->current_epoch->epoch_size);
36367+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36368 err2 = drbd_drain_block(mdev, pi->size);
36369 if (!err)
36370 err = err2;
36371@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36372
36373 spin_lock(&tconn->epoch_lock);
36374 peer_req->epoch = tconn->current_epoch;
36375- atomic_inc(&peer_req->epoch->epoch_size);
36376+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36377 atomic_inc(&peer_req->epoch->active);
36378 spin_unlock(&tconn->epoch_lock);
36379
36380@@ -4347,7 +4347,7 @@ struct data_cmd {
36381 int expect_payload;
36382 size_t pkt_size;
36383 int (*fn)(struct drbd_tconn *, struct packet_info *);
36384-};
36385+} __do_const;
36386
36387 static struct data_cmd drbd_cmd_handler[] = {
36388 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36389@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36390 if (!list_empty(&tconn->current_epoch->list))
36391 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36392 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36393- atomic_set(&tconn->current_epoch->epoch_size, 0);
36394+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36395 tconn->send.seen_any_write_yet = false;
36396
36397 conn_info(tconn, "Connection closed\n");
36398@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36399 struct asender_cmd {
36400 size_t pkt_size;
36401 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36402-};
36403+} __do_const;
36404
36405 static struct asender_cmd asender_tbl[] = {
36406 [P_PING] = { 0, got_Ping },
36407diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36408index 40e7155..df5c79a 100644
36409--- a/drivers/block/loop.c
36410+++ b/drivers/block/loop.c
36411@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36412
36413 file_start_write(file);
36414 set_fs(get_ds());
36415- bw = file->f_op->write(file, buf, len, &pos);
36416+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36417 set_fs(old_fs);
36418 file_end_write(file);
36419 if (likely(bw == len))
36420diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36421index f5d0ea1..c62380a 100644
36422--- a/drivers/block/pktcdvd.c
36423+++ b/drivers/block/pktcdvd.c
36424@@ -84,7 +84,7 @@
36425 #define MAX_SPEED 0xffff
36426
36427 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36428- ~(sector_t)((pd)->settings.size - 1))
36429+ ~(sector_t)((pd)->settings.size - 1UL))
36430
36431 static DEFINE_MUTEX(pktcdvd_mutex);
36432 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36433diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36434index 7332889..9ece19e 100644
36435--- a/drivers/bus/arm-cci.c
36436+++ b/drivers/bus/arm-cci.c
36437@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36438
36439 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36440
36441- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36442+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36443 if (!ports)
36444 return -ENOMEM;
36445
36446diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36447index 8a3aff7..d7538c2 100644
36448--- a/drivers/cdrom/cdrom.c
36449+++ b/drivers/cdrom/cdrom.c
36450@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36451 ENSURE(reset, CDC_RESET);
36452 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36453 cdi->mc_flags = 0;
36454- cdo->n_minors = 0;
36455 cdi->options = CDO_USE_FFLAGS;
36456
36457 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36458@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36459 else
36460 cdi->cdda_method = CDDA_OLD;
36461
36462- if (!cdo->generic_packet)
36463- cdo->generic_packet = cdrom_dummy_generic_packet;
36464+ if (!cdo->generic_packet) {
36465+ pax_open_kernel();
36466+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36467+ pax_close_kernel();
36468+ }
36469
36470 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36471 mutex_lock(&cdrom_mutex);
36472@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36473 if (cdi->exit)
36474 cdi->exit(cdi);
36475
36476- cdi->ops->n_minors--;
36477 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36478 }
36479
36480@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36481 */
36482 nr = nframes;
36483 do {
36484- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36485+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36486 if (cgc.buffer)
36487 break;
36488
36489@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36490 struct cdrom_device_info *cdi;
36491 int ret;
36492
36493- ret = scnprintf(info + *pos, max_size - *pos, header);
36494+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36495 if (!ret)
36496 return 1;
36497
36498diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36499index 5980cb9..6d7bd7e 100644
36500--- a/drivers/cdrom/gdrom.c
36501+++ b/drivers/cdrom/gdrom.c
36502@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36503 .audio_ioctl = gdrom_audio_ioctl,
36504 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36505 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36506- .n_minors = 1,
36507 };
36508
36509 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36510diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36511index 1421997..33f5d6d 100644
36512--- a/drivers/char/Kconfig
36513+++ b/drivers/char/Kconfig
36514@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36515
36516 config DEVKMEM
36517 bool "/dev/kmem virtual device support"
36518- default y
36519+ default n
36520+ depends on !GRKERNSEC_KMEM
36521 help
36522 Say Y here if you want to support the /dev/kmem device. The
36523 /dev/kmem device is rarely used, but can be used for certain
36524@@ -570,6 +571,7 @@ config DEVPORT
36525 bool
36526 depends on !M68K
36527 depends on ISA || PCI
36528+ depends on !GRKERNSEC_KMEM
36529 default y
36530
36531 source "drivers/s390/char/Kconfig"
36532diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36533index a48e05b..6bac831 100644
36534--- a/drivers/char/agp/compat_ioctl.c
36535+++ b/drivers/char/agp/compat_ioctl.c
36536@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36537 return -ENOMEM;
36538 }
36539
36540- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36541+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36542 sizeof(*usegment) * ureserve.seg_count)) {
36543 kfree(usegment);
36544 kfree(ksegment);
36545diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36546index 1b19239..b87b143 100644
36547--- a/drivers/char/agp/frontend.c
36548+++ b/drivers/char/agp/frontend.c
36549@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36550 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36551 return -EFAULT;
36552
36553- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36554+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36555 return -EFAULT;
36556
36557 client = agp_find_client_by_pid(reserve.pid);
36558@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36559 if (segment == NULL)
36560 return -ENOMEM;
36561
36562- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36563+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36564 sizeof(struct agp_segment) * reserve.seg_count)) {
36565 kfree(segment);
36566 return -EFAULT;
36567diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36568index 4f94375..413694e 100644
36569--- a/drivers/char/genrtc.c
36570+++ b/drivers/char/genrtc.c
36571@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36572 switch (cmd) {
36573
36574 case RTC_PLL_GET:
36575+ memset(&pll, 0, sizeof(pll));
36576 if (get_rtc_pll(&pll))
36577 return -EINVAL;
36578 else
36579diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36580index 448ce5e..3a76625 100644
36581--- a/drivers/char/hpet.c
36582+++ b/drivers/char/hpet.c
36583@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36584 }
36585
36586 static int
36587-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36588+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36589 struct hpet_info *info)
36590 {
36591 struct hpet_timer __iomem *timer;
36592diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36593index 86fe45c..c0ea948 100644
36594--- a/drivers/char/hw_random/intel-rng.c
36595+++ b/drivers/char/hw_random/intel-rng.c
36596@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36597
36598 if (no_fwh_detect)
36599 return -ENODEV;
36600- printk(warning);
36601+ printk("%s", warning);
36602 return -EBUSY;
36603 }
36604
36605diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36606index 4445fa1..7c6de37 100644
36607--- a/drivers/char/ipmi/ipmi_msghandler.c
36608+++ b/drivers/char/ipmi/ipmi_msghandler.c
36609@@ -420,7 +420,7 @@ struct ipmi_smi {
36610 struct proc_dir_entry *proc_dir;
36611 char proc_dir_name[10];
36612
36613- atomic_t stats[IPMI_NUM_STATS];
36614+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36615
36616 /*
36617 * run_to_completion duplicate of smb_info, smi_info
36618@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36619
36620
36621 #define ipmi_inc_stat(intf, stat) \
36622- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36623+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36624 #define ipmi_get_stat(intf, stat) \
36625- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36626+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36627
36628 static int is_lan_addr(struct ipmi_addr *addr)
36629 {
36630@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36631 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36632 init_waitqueue_head(&intf->waitq);
36633 for (i = 0; i < IPMI_NUM_STATS; i++)
36634- atomic_set(&intf->stats[i], 0);
36635+ atomic_set_unchecked(&intf->stats[i], 0);
36636
36637 intf->proc_dir = NULL;
36638
36639diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36640index af4b23f..79806fc 100644
36641--- a/drivers/char/ipmi/ipmi_si_intf.c
36642+++ b/drivers/char/ipmi/ipmi_si_intf.c
36643@@ -275,7 +275,7 @@ struct smi_info {
36644 unsigned char slave_addr;
36645
36646 /* Counters and things for the proc filesystem. */
36647- atomic_t stats[SI_NUM_STATS];
36648+ atomic_unchecked_t stats[SI_NUM_STATS];
36649
36650 struct task_struct *thread;
36651
36652@@ -284,9 +284,9 @@ struct smi_info {
36653 };
36654
36655 #define smi_inc_stat(smi, stat) \
36656- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36657+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36658 #define smi_get_stat(smi, stat) \
36659- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36660+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36661
36662 #define SI_MAX_PARMS 4
36663
36664@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36665 atomic_set(&new_smi->req_events, 0);
36666 new_smi->run_to_completion = 0;
36667 for (i = 0; i < SI_NUM_STATS; i++)
36668- atomic_set(&new_smi->stats[i], 0);
36669+ atomic_set_unchecked(&new_smi->stats[i], 0);
36670
36671 new_smi->interrupt_disabled = 1;
36672 atomic_set(&new_smi->stop_operation, 0);
36673diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36674index f895a8c..2bc9147 100644
36675--- a/drivers/char/mem.c
36676+++ b/drivers/char/mem.c
36677@@ -18,6 +18,7 @@
36678 #include <linux/raw.h>
36679 #include <linux/tty.h>
36680 #include <linux/capability.h>
36681+#include <linux/security.h>
36682 #include <linux/ptrace.h>
36683 #include <linux/device.h>
36684 #include <linux/highmem.h>
36685@@ -37,6 +38,10 @@
36686
36687 #define DEVPORT_MINOR 4
36688
36689+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36690+extern const struct file_operations grsec_fops;
36691+#endif
36692+
36693 static inline unsigned long size_inside_page(unsigned long start,
36694 unsigned long size)
36695 {
36696@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36697
36698 while (cursor < to) {
36699 if (!devmem_is_allowed(pfn)) {
36700+#ifdef CONFIG_GRKERNSEC_KMEM
36701+ gr_handle_mem_readwrite(from, to);
36702+#else
36703 printk(KERN_INFO
36704 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36705 current->comm, from, to);
36706+#endif
36707 return 0;
36708 }
36709 cursor += PAGE_SIZE;
36710@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36711 }
36712 return 1;
36713 }
36714+#elif defined(CONFIG_GRKERNSEC_KMEM)
36715+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36716+{
36717+ return 0;
36718+}
36719 #else
36720 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36721 {
36722@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36723
36724 while (count > 0) {
36725 unsigned long remaining;
36726+ char *temp;
36727
36728 sz = size_inside_page(p, count);
36729
36730@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36731 if (!ptr)
36732 return -EFAULT;
36733
36734- remaining = copy_to_user(buf, ptr, sz);
36735+#ifdef CONFIG_PAX_USERCOPY
36736+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36737+ if (!temp) {
36738+ unxlate_dev_mem_ptr(p, ptr);
36739+ return -ENOMEM;
36740+ }
36741+ memcpy(temp, ptr, sz);
36742+#else
36743+ temp = ptr;
36744+#endif
36745+
36746+ remaining = copy_to_user(buf, temp, sz);
36747+
36748+#ifdef CONFIG_PAX_USERCOPY
36749+ kfree(temp);
36750+#endif
36751+
36752 unxlate_dev_mem_ptr(p, ptr);
36753 if (remaining)
36754 return -EFAULT;
36755@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36756 size_t count, loff_t *ppos)
36757 {
36758 unsigned long p = *ppos;
36759- ssize_t low_count, read, sz;
36760+ ssize_t low_count, read, sz, err = 0;
36761 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36762- int err = 0;
36763
36764 read = 0;
36765 if (p < (unsigned long) high_memory) {
36766@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36767 }
36768 #endif
36769 while (low_count > 0) {
36770+ char *temp;
36771+
36772 sz = size_inside_page(p, low_count);
36773
36774 /*
36775@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36776 */
36777 kbuf = xlate_dev_kmem_ptr((char *)p);
36778
36779- if (copy_to_user(buf, kbuf, sz))
36780+#ifdef CONFIG_PAX_USERCOPY
36781+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36782+ if (!temp)
36783+ return -ENOMEM;
36784+ memcpy(temp, kbuf, sz);
36785+#else
36786+ temp = kbuf;
36787+#endif
36788+
36789+ err = copy_to_user(buf, temp, sz);
36790+
36791+#ifdef CONFIG_PAX_USERCOPY
36792+ kfree(temp);
36793+#endif
36794+
36795+ if (err)
36796 return -EFAULT;
36797 buf += sz;
36798 p += sz;
36799@@ -822,6 +869,9 @@ static const struct memdev {
36800 #ifdef CONFIG_PRINTK
36801 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36802 #endif
36803+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36804+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36805+#endif
36806 };
36807
36808 static int memory_open(struct inode *inode, struct file *filp)
36809@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36810 continue;
36811
36812 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36813- NULL, devlist[minor].name);
36814+ NULL, "%s", devlist[minor].name);
36815 }
36816
36817 return tty_init();
36818diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36819index 9df78e2..01ba9ae 100644
36820--- a/drivers/char/nvram.c
36821+++ b/drivers/char/nvram.c
36822@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36823
36824 spin_unlock_irq(&rtc_lock);
36825
36826- if (copy_to_user(buf, contents, tmp - contents))
36827+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36828 return -EFAULT;
36829
36830 *ppos = i;
36831diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36832index 5c5cc00..ac9edb7 100644
36833--- a/drivers/char/pcmcia/synclink_cs.c
36834+++ b/drivers/char/pcmcia/synclink_cs.c
36835@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36836
36837 if (debug_level >= DEBUG_LEVEL_INFO)
36838 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36839- __FILE__, __LINE__, info->device_name, port->count);
36840+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36841
36842- WARN_ON(!port->count);
36843+ WARN_ON(!atomic_read(&port->count));
36844
36845 if (tty_port_close_start(port, tty, filp) == 0)
36846 goto cleanup;
36847@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36848 cleanup:
36849 if (debug_level >= DEBUG_LEVEL_INFO)
36850 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36851- tty->driver->name, port->count);
36852+ tty->driver->name, atomic_read(&port->count));
36853 }
36854
36855 /* Wait until the transmitter is empty.
36856@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36857
36858 if (debug_level >= DEBUG_LEVEL_INFO)
36859 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36860- __FILE__, __LINE__, tty->driver->name, port->count);
36861+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36862
36863 /* If port is closing, signal caller to try again */
36864 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36865@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36866 goto cleanup;
36867 }
36868 spin_lock(&port->lock);
36869- port->count++;
36870+ atomic_inc(&port->count);
36871 spin_unlock(&port->lock);
36872 spin_unlock_irqrestore(&info->netlock, flags);
36873
36874- if (port->count == 1) {
36875+ if (atomic_read(&port->count) == 1) {
36876 /* 1st open on this device, init hardware */
36877 retval = startup(info, tty);
36878 if (retval < 0)
36879@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36880 unsigned short new_crctype;
36881
36882 /* return error if TTY interface open */
36883- if (info->port.count)
36884+ if (atomic_read(&info->port.count))
36885 return -EBUSY;
36886
36887 switch (encoding)
36888@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36889
36890 /* arbitrate between network and tty opens */
36891 spin_lock_irqsave(&info->netlock, flags);
36892- if (info->port.count != 0 || info->netcount != 0) {
36893+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36894 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36895 spin_unlock_irqrestore(&info->netlock, flags);
36896 return -EBUSY;
36897@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36898 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36899
36900 /* return error if TTY interface open */
36901- if (info->port.count)
36902+ if (atomic_read(&info->port.count))
36903 return -EBUSY;
36904
36905 if (cmd != SIOCWANDEV)
36906diff --git a/drivers/char/random.c b/drivers/char/random.c
36907index 92e6c67..c640ec3 100644
36908--- a/drivers/char/random.c
36909+++ b/drivers/char/random.c
36910@@ -272,8 +272,13 @@
36911 /*
36912 * Configuration information
36913 */
36914+#ifdef CONFIG_GRKERNSEC_RANDNET
36915+#define INPUT_POOL_WORDS 512
36916+#define OUTPUT_POOL_WORDS 128
36917+#else
36918 #define INPUT_POOL_WORDS 128
36919 #define OUTPUT_POOL_WORDS 32
36920+#endif
36921 #define SEC_XFER_SIZE 512
36922 #define EXTRACT_SIZE 10
36923
36924@@ -313,10 +318,17 @@ static struct poolinfo {
36925 int poolwords;
36926 int tap1, tap2, tap3, tap4, tap5;
36927 } poolinfo_table[] = {
36928+#ifdef CONFIG_GRKERNSEC_RANDNET
36929+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36930+ { 512, 411, 308, 208, 104, 1 },
36931+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36932+ { 128, 103, 76, 51, 25, 1 },
36933+#else
36934 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36935 { 128, 103, 76, 51, 25, 1 },
36936 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36937 { 32, 26, 20, 14, 7, 1 },
36938+#endif
36939 #if 0
36940 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36941 { 2048, 1638, 1231, 819, 411, 1 },
36942@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36943 input_rotate += i ? 7 : 14;
36944 }
36945
36946- ACCESS_ONCE(r->input_rotate) = input_rotate;
36947- ACCESS_ONCE(r->add_ptr) = i;
36948+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36949+ ACCESS_ONCE_RW(r->add_ptr) = i;
36950 smp_wmb();
36951
36952 if (out)
36953@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36954
36955 extract_buf(r, tmp);
36956 i = min_t(int, nbytes, EXTRACT_SIZE);
36957- if (copy_to_user(buf, tmp, i)) {
36958+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36959 ret = -EFAULT;
36960 break;
36961 }
36962@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36963 #include <linux/sysctl.h>
36964
36965 static int min_read_thresh = 8, min_write_thresh;
36966-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36967+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36968 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36969 static char sysctl_bootid[16];
36970
36971@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36972 static int proc_do_uuid(struct ctl_table *table, int write,
36973 void __user *buffer, size_t *lenp, loff_t *ppos)
36974 {
36975- struct ctl_table fake_table;
36976+ ctl_table_no_const fake_table;
36977 unsigned char buf[64], tmp_uuid[16], *uuid;
36978
36979 uuid = table->data;
36980diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36981index bf2349db..5456d53 100644
36982--- a/drivers/char/sonypi.c
36983+++ b/drivers/char/sonypi.c
36984@@ -54,6 +54,7 @@
36985
36986 #include <asm/uaccess.h>
36987 #include <asm/io.h>
36988+#include <asm/local.h>
36989
36990 #include <linux/sonypi.h>
36991
36992@@ -490,7 +491,7 @@ static struct sonypi_device {
36993 spinlock_t fifo_lock;
36994 wait_queue_head_t fifo_proc_list;
36995 struct fasync_struct *fifo_async;
36996- int open_count;
36997+ local_t open_count;
36998 int model;
36999 struct input_dev *input_jog_dev;
37000 struct input_dev *input_key_dev;
37001@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37002 static int sonypi_misc_release(struct inode *inode, struct file *file)
37003 {
37004 mutex_lock(&sonypi_device.lock);
37005- sonypi_device.open_count--;
37006+ local_dec(&sonypi_device.open_count);
37007 mutex_unlock(&sonypi_device.lock);
37008 return 0;
37009 }
37010@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37011 {
37012 mutex_lock(&sonypi_device.lock);
37013 /* Flush input queue on first open */
37014- if (!sonypi_device.open_count)
37015+ if (!local_read(&sonypi_device.open_count))
37016 kfifo_reset(&sonypi_device.fifo);
37017- sonypi_device.open_count++;
37018+ local_inc(&sonypi_device.open_count);
37019 mutex_unlock(&sonypi_device.lock);
37020
37021 return 0;
37022diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37023index 64420b3..5c40b56 100644
37024--- a/drivers/char/tpm/tpm_acpi.c
37025+++ b/drivers/char/tpm/tpm_acpi.c
37026@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37027 virt = acpi_os_map_memory(start, len);
37028 if (!virt) {
37029 kfree(log->bios_event_log);
37030+ log->bios_event_log = NULL;
37031 printk("%s: ERROR - Unable to map memory\n", __func__);
37032 return -EIO;
37033 }
37034
37035- memcpy_fromio(log->bios_event_log, virt, len);
37036+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37037
37038 acpi_os_unmap_memory(virt, len);
37039 return 0;
37040diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37041index 84ddc55..1d32f1e 100644
37042--- a/drivers/char/tpm/tpm_eventlog.c
37043+++ b/drivers/char/tpm/tpm_eventlog.c
37044@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37045 event = addr;
37046
37047 if ((event->event_type == 0 && event->event_size == 0) ||
37048- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37049+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37050 return NULL;
37051
37052 return addr;
37053@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37054 return NULL;
37055
37056 if ((event->event_type == 0 && event->event_size == 0) ||
37057- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37058+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37059 return NULL;
37060
37061 (*pos)++;
37062@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37063 int i;
37064
37065 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37066- seq_putc(m, data[i]);
37067+ if (!seq_putc(m, data[i]))
37068+ return -EFAULT;
37069
37070 return 0;
37071 }
37072diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37073index fc45567..fa2a590 100644
37074--- a/drivers/char/virtio_console.c
37075+++ b/drivers/char/virtio_console.c
37076@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37077 if (to_user) {
37078 ssize_t ret;
37079
37080- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37081+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37082 if (ret)
37083 return -EFAULT;
37084 } else {
37085@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37086 if (!port_has_data(port) && !port->host_connected)
37087 return 0;
37088
37089- return fill_readbuf(port, ubuf, count, true);
37090+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37091 }
37092
37093 static int wait_port_writable(struct port *port, bool nonblock)
37094diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37095index a33f46f..a720eed 100644
37096--- a/drivers/clk/clk-composite.c
37097+++ b/drivers/clk/clk-composite.c
37098@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37099 struct clk *clk;
37100 struct clk_init_data init;
37101 struct clk_composite *composite;
37102- struct clk_ops *clk_composite_ops;
37103+ clk_ops_no_const *clk_composite_ops;
37104
37105 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37106 if (!composite) {
37107diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37108index 5bb848c..f1d4fc9 100644
37109--- a/drivers/clk/socfpga/clk.c
37110+++ b/drivers/clk/socfpga/clk.c
37111@@ -22,6 +22,7 @@
37112 #include <linux/clk-provider.h>
37113 #include <linux/io.h>
37114 #include <linux/of.h>
37115+#include <asm/pgtable.h>
37116
37117 /* Clock Manager offsets */
37118 #define CLKMGR_CTRL 0x0
37119@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37120 streq(clk_name, "periph_pll") ||
37121 streq(clk_name, "sdram_pll")) {
37122 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37123- clk_pll_ops.enable = clk_gate_ops.enable;
37124- clk_pll_ops.disable = clk_gate_ops.disable;
37125+ pax_open_kernel();
37126+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37127+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37128+ pax_close_kernel();
37129 }
37130
37131 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37132@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37133 return parent_rate / div;
37134 }
37135
37136-static struct clk_ops gateclk_ops = {
37137+static clk_ops_no_const gateclk_ops __read_only = {
37138 .recalc_rate = socfpga_clk_recalc_rate,
37139 .get_parent = socfpga_clk_get_parent,
37140 .set_parent = socfpga_clk_set_parent,
37141diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
37142index 08ae128..c73fc2b 100644
37143--- a/drivers/connector/cn_proc.c
37144+++ b/drivers/connector/cn_proc.c
37145@@ -65,6 +65,7 @@ void proc_fork_connector(struct task_struct *task)
37146
37147 msg = (struct cn_msg *)buffer;
37148 ev = (struct proc_event *)msg->data;
37149+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37150 get_seq(&msg->seq, &ev->cpu);
37151 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37152 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37153@@ -80,6 +81,7 @@ void proc_fork_connector(struct task_struct *task)
37154 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37155 msg->ack = 0; /* not used */
37156 msg->len = sizeof(*ev);
37157+ msg->flags = 0; /* not used */
37158 /* If cn_netlink_send() failed, the data is not sent */
37159 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37160 }
37161@@ -96,6 +98,7 @@ void proc_exec_connector(struct task_struct *task)
37162
37163 msg = (struct cn_msg *)buffer;
37164 ev = (struct proc_event *)msg->data;
37165+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37166 get_seq(&msg->seq, &ev->cpu);
37167 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37168 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37169@@ -106,6 +109,7 @@ void proc_exec_connector(struct task_struct *task)
37170 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37171 msg->ack = 0; /* not used */
37172 msg->len = sizeof(*ev);
37173+ msg->flags = 0; /* not used */
37174 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37175 }
37176
37177@@ -122,6 +126,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
37178
37179 msg = (struct cn_msg *)buffer;
37180 ev = (struct proc_event *)msg->data;
37181+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37182 ev->what = which_id;
37183 ev->event_data.id.process_pid = task->pid;
37184 ev->event_data.id.process_tgid = task->tgid;
37185@@ -145,6 +150,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
37186 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37187 msg->ack = 0; /* not used */
37188 msg->len = sizeof(*ev);
37189+ msg->flags = 0; /* not used */
37190 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37191 }
37192
37193@@ -160,6 +166,7 @@ void proc_sid_connector(struct task_struct *task)
37194
37195 msg = (struct cn_msg *)buffer;
37196 ev = (struct proc_event *)msg->data;
37197+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37198 get_seq(&msg->seq, &ev->cpu);
37199 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37200 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37201@@ -170,6 +177,7 @@ void proc_sid_connector(struct task_struct *task)
37202 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37203 msg->ack = 0; /* not used */
37204 msg->len = sizeof(*ev);
37205+ msg->flags = 0; /* not used */
37206 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37207 }
37208
37209@@ -185,6 +193,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
37210
37211 msg = (struct cn_msg *)buffer;
37212 ev = (struct proc_event *)msg->data;
37213+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37214 get_seq(&msg->seq, &ev->cpu);
37215 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37216 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37217@@ -203,6 +212,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
37218 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37219 msg->ack = 0; /* not used */
37220 msg->len = sizeof(*ev);
37221+ msg->flags = 0; /* not used */
37222 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37223 }
37224
37225@@ -218,6 +228,7 @@ void proc_comm_connector(struct task_struct *task)
37226
37227 msg = (struct cn_msg *)buffer;
37228 ev = (struct proc_event *)msg->data;
37229+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37230 get_seq(&msg->seq, &ev->cpu);
37231 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37232 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37233@@ -229,6 +240,7 @@ void proc_comm_connector(struct task_struct *task)
37234 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37235 msg->ack = 0; /* not used */
37236 msg->len = sizeof(*ev);
37237+ msg->flags = 0; /* not used */
37238 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37239 }
37240
37241@@ -244,6 +256,7 @@ void proc_coredump_connector(struct task_struct *task)
37242
37243 msg = (struct cn_msg *)buffer;
37244 ev = (struct proc_event *)msg->data;
37245+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37246 get_seq(&msg->seq, &ev->cpu);
37247 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37248 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37249@@ -254,6 +267,7 @@ void proc_coredump_connector(struct task_struct *task)
37250 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37251 msg->ack = 0; /* not used */
37252 msg->len = sizeof(*ev);
37253+ msg->flags = 0; /* not used */
37254 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37255 }
37256
37257@@ -269,6 +283,7 @@ void proc_exit_connector(struct task_struct *task)
37258
37259 msg = (struct cn_msg *)buffer;
37260 ev = (struct proc_event *)msg->data;
37261+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37262 get_seq(&msg->seq, &ev->cpu);
37263 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37264 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37265@@ -281,6 +296,7 @@ void proc_exit_connector(struct task_struct *task)
37266 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37267 msg->ack = 0; /* not used */
37268 msg->len = sizeof(*ev);
37269+ msg->flags = 0; /* not used */
37270 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37271 }
37272
37273@@ -304,6 +320,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
37274
37275 msg = (struct cn_msg *)buffer;
37276 ev = (struct proc_event *)msg->data;
37277+ memset(&ev->event_data, 0, sizeof(ev->event_data));
37278 msg->seq = rcvd_seq;
37279 ktime_get_ts(&ts); /* get high res monotonic timestamp */
37280 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
37281@@ -313,6 +330,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
37282 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
37283 msg->ack = rcvd_ack + 1;
37284 msg->len = sizeof(*ev);
37285+ msg->flags = 0; /* not used */
37286 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
37287 }
37288
37289diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
37290index 6ecfa75..0daa11e 100644
37291--- a/drivers/connector/connector.c
37292+++ b/drivers/connector/connector.c
37293@@ -157,17 +157,18 @@ static int cn_call_callback(struct sk_buff *skb)
37294 static void cn_rx_skb(struct sk_buff *__skb)
37295 {
37296 struct nlmsghdr *nlh;
37297- int err;
37298 struct sk_buff *skb;
37299+ int len, err;
37300
37301 skb = skb_get(__skb);
37302
37303 if (skb->len >= NLMSG_HDRLEN) {
37304 nlh = nlmsg_hdr(skb);
37305+ len = nlmsg_len(nlh);
37306
37307- if (nlh->nlmsg_len < sizeof(struct cn_msg) ||
37308+ if (len < (int)sizeof(struct cn_msg) ||
37309 skb->len < nlh->nlmsg_len ||
37310- nlh->nlmsg_len > CONNECTOR_MAX_MSG_SIZE) {
37311+ len > CONNECTOR_MAX_MSG_SIZE) {
37312 kfree_skb(skb);
37313 return;
37314 }
37315diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37316index 3926402..37b580d 100644
37317--- a/drivers/cpufreq/acpi-cpufreq.c
37318+++ b/drivers/cpufreq/acpi-cpufreq.c
37319@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37320 return sprintf(buf, "%u\n", boost_enabled);
37321 }
37322
37323-static struct global_attr global_boost = __ATTR(boost, 0644,
37324+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37325 show_global_boost,
37326 store_global_boost);
37327
37328@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37329 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37330 per_cpu(acfreq_data, cpu) = data;
37331
37332- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37333- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37334+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37335+ pax_open_kernel();
37336+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37337+ pax_close_kernel();
37338+ }
37339
37340 result = acpi_processor_register_performance(data->acpi_data, cpu);
37341 if (result)
37342@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37343 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37344 break;
37345 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37346- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37347+ pax_open_kernel();
37348+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37349+ pax_close_kernel();
37350 policy->cur = get_cur_freq_on_cpu(cpu);
37351 break;
37352 default:
37353@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37354 acpi_processor_notify_smm(THIS_MODULE);
37355
37356 /* Check for APERF/MPERF support in hardware */
37357- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37358- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37359+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37360+ pax_open_kernel();
37361+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37362+ pax_close_kernel();
37363+ }
37364
37365 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37366 for (i = 0; i < perf->state_count; i++)
37367diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37368index f0a5e2b..0a7ee46 100644
37369--- a/drivers/cpufreq/cpufreq.c
37370+++ b/drivers/cpufreq/cpufreq.c
37371@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37372 return NOTIFY_OK;
37373 }
37374
37375-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37376+static struct notifier_block cpufreq_cpu_notifier = {
37377 .notifier_call = cpufreq_cpu_callback,
37378 };
37379
37380@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37381
37382 pr_debug("trying to register driver %s\n", driver_data->name);
37383
37384- if (driver_data->setpolicy)
37385- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37386+ if (driver_data->setpolicy) {
37387+ pax_open_kernel();
37388+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37389+ pax_close_kernel();
37390+ }
37391
37392 write_lock_irqsave(&cpufreq_driver_lock, flags);
37393 if (cpufreq_driver) {
37394diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37395index e59afaa..a53a3ff 100644
37396--- a/drivers/cpufreq/cpufreq_governor.c
37397+++ b/drivers/cpufreq/cpufreq_governor.c
37398@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37399 struct dbs_data *dbs_data;
37400 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37401 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37402- struct od_ops *od_ops = NULL;
37403+ const struct od_ops *od_ops = NULL;
37404 struct od_dbs_tuners *od_tuners = NULL;
37405 struct cs_dbs_tuners *cs_tuners = NULL;
37406 struct cpu_dbs_common_info *cpu_cdbs;
37407@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37408
37409 if ((cdata->governor == GOV_CONSERVATIVE) &&
37410 (!policy->governor->initialized)) {
37411- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37412+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37413
37414 cpufreq_register_notifier(cs_ops->notifier_block,
37415 CPUFREQ_TRANSITION_NOTIFIER);
37416@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37417
37418 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37419 (policy->governor->initialized == 1)) {
37420- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37421+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37422
37423 cpufreq_unregister_notifier(cs_ops->notifier_block,
37424 CPUFREQ_TRANSITION_NOTIFIER);
37425diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37426index d5f12b4..eb30af1 100644
37427--- a/drivers/cpufreq/cpufreq_governor.h
37428+++ b/drivers/cpufreq/cpufreq_governor.h
37429@@ -204,7 +204,7 @@ struct common_dbs_data {
37430 void (*exit)(struct dbs_data *dbs_data);
37431
37432 /* Governor specific ops, see below */
37433- void *gov_ops;
37434+ const void *gov_ops;
37435 };
37436
37437 /* Governer Per policy data */
37438@@ -224,7 +224,7 @@ struct od_ops {
37439 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37440 unsigned int freq_next, unsigned int relation);
37441 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37442-};
37443+} __no_const;
37444
37445 struct cs_ops {
37446 struct notifier_block *notifier_block;
37447diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37448index c087347..989aa2e 100644
37449--- a/drivers/cpufreq/cpufreq_ondemand.c
37450+++ b/drivers/cpufreq/cpufreq_ondemand.c
37451@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37452
37453 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37454
37455-static struct od_ops od_ops = {
37456+static struct od_ops od_ops __read_only = {
37457 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37458 .powersave_bias_target = generic_powersave_bias_target,
37459 .freq_increase = dbs_freq_increase,
37460@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37461 (struct cpufreq_policy *, unsigned int, unsigned int),
37462 unsigned int powersave_bias)
37463 {
37464- od_ops.powersave_bias_target = f;
37465+ pax_open_kernel();
37466+ *(void **)&od_ops.powersave_bias_target = f;
37467+ pax_close_kernel();
37468 od_set_powersave_bias(powersave_bias);
37469 }
37470 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37471
37472 void od_unregister_powersave_bias_handler(void)
37473 {
37474- od_ops.powersave_bias_target = generic_powersave_bias_target;
37475+ pax_open_kernel();
37476+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37477+ pax_close_kernel();
37478 od_set_powersave_bias(0);
37479 }
37480 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37481diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37482index d37568c..fbb19a1 100644
37483--- a/drivers/cpufreq/cpufreq_stats.c
37484+++ b/drivers/cpufreq/cpufreq_stats.c
37485@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37486 }
37487
37488 /* priority=1 so this will get called before cpufreq_remove_dev */
37489-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37490+static struct notifier_block cpufreq_stat_cpu_notifier = {
37491 .notifier_call = cpufreq_stat_cpu_callback,
37492 .priority = 1,
37493 };
37494diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37495index 9ee7817..17b658e 100644
37496--- a/drivers/cpufreq/p4-clockmod.c
37497+++ b/drivers/cpufreq/p4-clockmod.c
37498@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37499 case 0x0F: /* Core Duo */
37500 case 0x16: /* Celeron Core */
37501 case 0x1C: /* Atom */
37502- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37503+ pax_open_kernel();
37504+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37505+ pax_close_kernel();
37506 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37507 case 0x0D: /* Pentium M (Dothan) */
37508- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37509+ pax_open_kernel();
37510+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37511+ pax_close_kernel();
37512 /* fall through */
37513 case 0x09: /* Pentium M (Banias) */
37514 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37515@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37516
37517 /* on P-4s, the TSC runs with constant frequency independent whether
37518 * throttling is active or not. */
37519- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37520+ pax_open_kernel();
37521+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37522+ pax_close_kernel();
37523
37524 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37525 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37526diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37527index 880ee29..2445bc6 100644
37528--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37529+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37530@@ -18,14 +18,12 @@
37531 #include <asm/head.h>
37532 #include <asm/timer.h>
37533
37534-static struct cpufreq_driver *cpufreq_us3_driver;
37535-
37536 struct us3_freq_percpu_info {
37537 struct cpufreq_frequency_table table[4];
37538 };
37539
37540 /* Indexed by cpu number. */
37541-static struct us3_freq_percpu_info *us3_freq_table;
37542+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37543
37544 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37545 * in the Safari config register.
37546@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37547
37548 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37549 {
37550- if (cpufreq_us3_driver)
37551- us3_set_cpu_divider_index(policy, 0);
37552+ us3_set_cpu_divider_index(policy->cpu, 0);
37553
37554 return 0;
37555 }
37556
37557+static int __init us3_freq_init(void);
37558+static void __exit us3_freq_exit(void);
37559+
37560+static struct cpufreq_driver cpufreq_us3_driver = {
37561+ .init = us3_freq_cpu_init,
37562+ .verify = us3_freq_verify,
37563+ .target = us3_freq_target,
37564+ .get = us3_freq_get,
37565+ .exit = us3_freq_cpu_exit,
37566+ .owner = THIS_MODULE,
37567+ .name = "UltraSPARC-III",
37568+
37569+};
37570+
37571 static int __init us3_freq_init(void)
37572 {
37573 unsigned long manuf, impl, ver;
37574@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37575 (impl == CHEETAH_IMPL ||
37576 impl == CHEETAH_PLUS_IMPL ||
37577 impl == JAGUAR_IMPL ||
37578- impl == PANTHER_IMPL)) {
37579- struct cpufreq_driver *driver;
37580-
37581- ret = -ENOMEM;
37582- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37583- if (!driver)
37584- goto err_out;
37585-
37586- us3_freq_table = kzalloc(
37587- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37588- GFP_KERNEL);
37589- if (!us3_freq_table)
37590- goto err_out;
37591-
37592- driver->init = us3_freq_cpu_init;
37593- driver->verify = us3_freq_verify;
37594- driver->target = us3_freq_target;
37595- driver->get = us3_freq_get;
37596- driver->exit = us3_freq_cpu_exit;
37597- driver->owner = THIS_MODULE,
37598- strcpy(driver->name, "UltraSPARC-III");
37599-
37600- cpufreq_us3_driver = driver;
37601- ret = cpufreq_register_driver(driver);
37602- if (ret)
37603- goto err_out;
37604-
37605- return 0;
37606-
37607-err_out:
37608- if (driver) {
37609- kfree(driver);
37610- cpufreq_us3_driver = NULL;
37611- }
37612- kfree(us3_freq_table);
37613- us3_freq_table = NULL;
37614- return ret;
37615- }
37616+ impl == PANTHER_IMPL))
37617+ return cpufreq_register_driver(&cpufreq_us3_driver);
37618
37619 return -ENODEV;
37620 }
37621
37622 static void __exit us3_freq_exit(void)
37623 {
37624- if (cpufreq_us3_driver) {
37625- cpufreq_unregister_driver(cpufreq_us3_driver);
37626- kfree(cpufreq_us3_driver);
37627- cpufreq_us3_driver = NULL;
37628- kfree(us3_freq_table);
37629- us3_freq_table = NULL;
37630- }
37631+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37632 }
37633
37634 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37635diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37636index 0915e71..53376ed 100644
37637--- a/drivers/cpufreq/speedstep-centrino.c
37638+++ b/drivers/cpufreq/speedstep-centrino.c
37639@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37640 !cpu_has(cpu, X86_FEATURE_EST))
37641 return -ENODEV;
37642
37643- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37644- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37645+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37646+ pax_open_kernel();
37647+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37648+ pax_close_kernel();
37649+ }
37650
37651 if (policy->cpu != 0)
37652 return -ENODEV;
37653diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37654index fdc432f..98e64e2 100644
37655--- a/drivers/cpuidle/cpuidle.c
37656+++ b/drivers/cpuidle/cpuidle.c
37657@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37658
37659 static void poll_idle_init(struct cpuidle_driver *drv)
37660 {
37661- struct cpuidle_state *state = &drv->states[0];
37662+ cpuidle_state_no_const *state = &drv->states[0];
37663
37664 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37665 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37666diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37667index ea2f8e7..70ac501 100644
37668--- a/drivers/cpuidle/governor.c
37669+++ b/drivers/cpuidle/governor.c
37670@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37671 mutex_lock(&cpuidle_lock);
37672 if (__cpuidle_find_governor(gov->name) == NULL) {
37673 ret = 0;
37674- list_add_tail(&gov->governor_list, &cpuidle_governors);
37675+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37676 if (!cpuidle_curr_governor ||
37677 cpuidle_curr_governor->rating < gov->rating)
37678 cpuidle_switch_governor(gov);
37679@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37680 new_gov = cpuidle_replace_governor(gov->rating);
37681 cpuidle_switch_governor(new_gov);
37682 }
37683- list_del(&gov->governor_list);
37684+ pax_list_del((struct list_head *)&gov->governor_list);
37685 mutex_unlock(&cpuidle_lock);
37686 }
37687
37688diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37689index 428754a..8bdf9cc 100644
37690--- a/drivers/cpuidle/sysfs.c
37691+++ b/drivers/cpuidle/sysfs.c
37692@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37693 NULL
37694 };
37695
37696-static struct attribute_group cpuidle_attr_group = {
37697+static attribute_group_no_const cpuidle_attr_group = {
37698 .attrs = cpuidle_default_attrs,
37699 .name = "cpuidle",
37700 };
37701diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37702index 12fea3e..1e28f47 100644
37703--- a/drivers/crypto/hifn_795x.c
37704+++ b/drivers/crypto/hifn_795x.c
37705@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37706 MODULE_PARM_DESC(hifn_pll_ref,
37707 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37708
37709-static atomic_t hifn_dev_number;
37710+static atomic_unchecked_t hifn_dev_number;
37711
37712 #define ACRYPTO_OP_DECRYPT 0
37713 #define ACRYPTO_OP_ENCRYPT 1
37714@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37715 goto err_out_disable_pci_device;
37716
37717 snprintf(name, sizeof(name), "hifn%d",
37718- atomic_inc_return(&hifn_dev_number)-1);
37719+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37720
37721 err = pci_request_regions(pdev, name);
37722 if (err)
37723diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37724index e94e619..f7e249c 100644
37725--- a/drivers/devfreq/devfreq.c
37726+++ b/drivers/devfreq/devfreq.c
37727@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37728 goto err_out;
37729 }
37730
37731- list_add(&governor->node, &devfreq_governor_list);
37732+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37733
37734 list_for_each_entry(devfreq, &devfreq_list, node) {
37735 int ret = 0;
37736@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37737 }
37738 }
37739
37740- list_del(&governor->node);
37741+ pax_list_del((struct list_head *)&governor->node);
37742 err_out:
37743 mutex_unlock(&devfreq_list_lock);
37744
37745diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37746index 5039fbc..841169f 100644
37747--- a/drivers/dma/sh/shdma.c
37748+++ b/drivers/dma/sh/shdma.c
37749@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37750 return ret;
37751 }
37752
37753-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37754+static struct notifier_block sh_dmae_nmi_notifier = {
37755 .notifier_call = sh_dmae_nmi_handler,
37756
37757 /* Run before NMI debug handler and KGDB */
37758diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37759index 211021d..201d47f 100644
37760--- a/drivers/edac/edac_device.c
37761+++ b/drivers/edac/edac_device.c
37762@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37763 */
37764 int edac_device_alloc_index(void)
37765 {
37766- static atomic_t device_indexes = ATOMIC_INIT(0);
37767+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37768
37769- return atomic_inc_return(&device_indexes) - 1;
37770+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37771 }
37772 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37773
37774diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37775index e7c32c4..6397af1 100644
37776--- a/drivers/edac/edac_mc_sysfs.c
37777+++ b/drivers/edac/edac_mc_sysfs.c
37778@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37779 struct dev_ch_attribute {
37780 struct device_attribute attr;
37781 int channel;
37782-};
37783+} __do_const;
37784
37785 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37786 struct dev_ch_attribute dev_attr_legacy_##_name = \
37787@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37788 }
37789
37790 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37791+ pax_open_kernel();
37792 if (mci->get_sdram_scrub_rate) {
37793- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37794- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37795+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37796+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37797 }
37798 if (mci->set_sdram_scrub_rate) {
37799- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37800- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37801+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37802+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37803 }
37804+ pax_close_kernel();
37805 err = device_create_file(&mci->dev,
37806 &dev_attr_sdram_scrub_rate);
37807 if (err) {
37808diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37809index dd370f9..0281629 100644
37810--- a/drivers/edac/edac_pci.c
37811+++ b/drivers/edac/edac_pci.c
37812@@ -29,7 +29,7 @@
37813
37814 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37815 static LIST_HEAD(edac_pci_list);
37816-static atomic_t pci_indexes = ATOMIC_INIT(0);
37817+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37818
37819 /*
37820 * edac_pci_alloc_ctl_info
37821@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37822 */
37823 int edac_pci_alloc_index(void)
37824 {
37825- return atomic_inc_return(&pci_indexes) - 1;
37826+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37827 }
37828 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37829
37830diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37831index e8658e4..22746d6 100644
37832--- a/drivers/edac/edac_pci_sysfs.c
37833+++ b/drivers/edac/edac_pci_sysfs.c
37834@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37835 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37836 static int edac_pci_poll_msec = 1000; /* one second workq period */
37837
37838-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37839-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37840+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37841+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37842
37843 static struct kobject *edac_pci_top_main_kobj;
37844 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37845@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37846 void *value;
37847 ssize_t(*show) (void *, char *);
37848 ssize_t(*store) (void *, const char *, size_t);
37849-};
37850+} __do_const;
37851
37852 /* Set of show/store abstract level functions for PCI Parity object */
37853 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37854@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37855 edac_printk(KERN_CRIT, EDAC_PCI,
37856 "Signaled System Error on %s\n",
37857 pci_name(dev));
37858- atomic_inc(&pci_nonparity_count);
37859+ atomic_inc_unchecked(&pci_nonparity_count);
37860 }
37861
37862 if (status & (PCI_STATUS_PARITY)) {
37863@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37864 "Master Data Parity Error on %s\n",
37865 pci_name(dev));
37866
37867- atomic_inc(&pci_parity_count);
37868+ atomic_inc_unchecked(&pci_parity_count);
37869 }
37870
37871 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37872@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37873 "Detected Parity Error on %s\n",
37874 pci_name(dev));
37875
37876- atomic_inc(&pci_parity_count);
37877+ atomic_inc_unchecked(&pci_parity_count);
37878 }
37879 }
37880
37881@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37882 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37883 "Signaled System Error on %s\n",
37884 pci_name(dev));
37885- atomic_inc(&pci_nonparity_count);
37886+ atomic_inc_unchecked(&pci_nonparity_count);
37887 }
37888
37889 if (status & (PCI_STATUS_PARITY)) {
37890@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37891 "Master Data Parity Error on "
37892 "%s\n", pci_name(dev));
37893
37894- atomic_inc(&pci_parity_count);
37895+ atomic_inc_unchecked(&pci_parity_count);
37896 }
37897
37898 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37899@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37900 "Detected Parity Error on %s\n",
37901 pci_name(dev));
37902
37903- atomic_inc(&pci_parity_count);
37904+ atomic_inc_unchecked(&pci_parity_count);
37905 }
37906 }
37907 }
37908@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37909 if (!check_pci_errors)
37910 return;
37911
37912- before_count = atomic_read(&pci_parity_count);
37913+ before_count = atomic_read_unchecked(&pci_parity_count);
37914
37915 /* scan all PCI devices looking for a Parity Error on devices and
37916 * bridges.
37917@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37918 /* Only if operator has selected panic on PCI Error */
37919 if (edac_pci_get_panic_on_pe()) {
37920 /* If the count is different 'after' from 'before' */
37921- if (before_count != atomic_read(&pci_parity_count))
37922+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37923 panic("EDAC: PCI Parity Error");
37924 }
37925 }
37926diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37927index 51b7e3a..aa8a3e8 100644
37928--- a/drivers/edac/mce_amd.h
37929+++ b/drivers/edac/mce_amd.h
37930@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37931 bool (*mc0_mce)(u16, u8);
37932 bool (*mc1_mce)(u16, u8);
37933 bool (*mc2_mce)(u16, u8);
37934-};
37935+} __no_const;
37936
37937 void amd_report_gart_errors(bool);
37938 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37939diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37940index 57ea7f4..af06b76 100644
37941--- a/drivers/firewire/core-card.c
37942+++ b/drivers/firewire/core-card.c
37943@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37944 const struct fw_card_driver *driver,
37945 struct device *device)
37946 {
37947- static atomic_t index = ATOMIC_INIT(-1);
37948+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37949
37950- card->index = atomic_inc_return(&index);
37951+ card->index = atomic_inc_return_unchecked(&index);
37952 card->driver = driver;
37953 card->device = device;
37954 card->current_tlabel = 0;
37955@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37956
37957 void fw_core_remove_card(struct fw_card *card)
37958 {
37959- struct fw_card_driver dummy_driver = dummy_driver_template;
37960+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37961
37962 card->driver->update_phy_reg(card, 4,
37963 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37964diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37965index de4aa40..49ab1f2 100644
37966--- a/drivers/firewire/core-device.c
37967+++ b/drivers/firewire/core-device.c
37968@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37969 struct config_rom_attribute {
37970 struct device_attribute attr;
37971 u32 key;
37972-};
37973+} __do_const;
37974
37975 static ssize_t show_immediate(struct device *dev,
37976 struct device_attribute *dattr, char *buf)
37977diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37978index 28a94c7..58da63a 100644
37979--- a/drivers/firewire/core-transaction.c
37980+++ b/drivers/firewire/core-transaction.c
37981@@ -38,6 +38,7 @@
37982 #include <linux/timer.h>
37983 #include <linux/types.h>
37984 #include <linux/workqueue.h>
37985+#include <linux/sched.h>
37986
37987 #include <asm/byteorder.h>
37988
37989diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37990index 515a42c..5ecf3ba 100644
37991--- a/drivers/firewire/core.h
37992+++ b/drivers/firewire/core.h
37993@@ -111,6 +111,7 @@ struct fw_card_driver {
37994
37995 int (*stop_iso)(struct fw_iso_context *ctx);
37996 };
37997+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37998
37999 void fw_card_initialize(struct fw_card *card,
38000 const struct fw_card_driver *driver, struct device *device);
38001diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38002index 94a58a0..f5eba42 100644
38003--- a/drivers/firmware/dmi-id.c
38004+++ b/drivers/firmware/dmi-id.c
38005@@ -16,7 +16,7 @@
38006 struct dmi_device_attribute{
38007 struct device_attribute dev_attr;
38008 int field;
38009-};
38010+} __do_const;
38011 #define to_dmi_dev_attr(_dev_attr) \
38012 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38013
38014diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38015index 232fa8f..386c255 100644
38016--- a/drivers/firmware/dmi_scan.c
38017+++ b/drivers/firmware/dmi_scan.c
38018@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
38019 }
38020 }
38021 else {
38022- /*
38023- * no iounmap() for that ioremap(); it would be a no-op, but
38024- * it's so early in setup that sucker gets confused into doing
38025- * what it shouldn't if we actually call it.
38026- */
38027 p = dmi_ioremap(0xF0000, 0x10000);
38028 if (p == NULL)
38029 goto error;
38030@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38031 if (buf == NULL)
38032 return -1;
38033
38034- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38035+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38036
38037 iounmap(buf);
38038 return 0;
38039diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38040index 5145fa3..0d3babd 100644
38041--- a/drivers/firmware/efi/efi.c
38042+++ b/drivers/firmware/efi/efi.c
38043@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38044 };
38045
38046 static struct efivars generic_efivars;
38047-static struct efivar_operations generic_ops;
38048+static efivar_operations_no_const generic_ops __read_only;
38049
38050 static int generic_ops_register(void)
38051 {
38052- generic_ops.get_variable = efi.get_variable;
38053- generic_ops.set_variable = efi.set_variable;
38054- generic_ops.get_next_variable = efi.get_next_variable;
38055- generic_ops.query_variable_store = efi_query_variable_store;
38056+ pax_open_kernel();
38057+ *(void **)&generic_ops.get_variable = efi.get_variable;
38058+ *(void **)&generic_ops.set_variable = efi.set_variable;
38059+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38060+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38061+ pax_close_kernel();
38062
38063 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38064 }
38065diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38066index 8a7432a..28fb839 100644
38067--- a/drivers/firmware/efi/efivars.c
38068+++ b/drivers/firmware/efi/efivars.c
38069@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38070 static int
38071 create_efivars_bin_attributes(void)
38072 {
38073- struct bin_attribute *attr;
38074+ bin_attribute_no_const *attr;
38075 int error;
38076
38077 /* new_var */
38078diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38079index 2a90ba6..07f3733 100644
38080--- a/drivers/firmware/google/memconsole.c
38081+++ b/drivers/firmware/google/memconsole.c
38082@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38083 if (!found_memconsole())
38084 return -ENODEV;
38085
38086- memconsole_bin_attr.size = memconsole_length;
38087+ pax_open_kernel();
38088+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38089+ pax_close_kernel();
38090
38091 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38092
38093diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38094index 2729e3d..f9deca1 100644
38095--- a/drivers/gpio/gpio-ich.c
38096+++ b/drivers/gpio/gpio-ich.c
38097@@ -71,7 +71,7 @@ struct ichx_desc {
38098 /* Some chipsets have quirks, let these use their own request/get */
38099 int (*request)(struct gpio_chip *chip, unsigned offset);
38100 int (*get)(struct gpio_chip *chip, unsigned offset);
38101-};
38102+} __do_const;
38103
38104 static struct {
38105 spinlock_t lock;
38106diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38107index 9902732..64b62dd 100644
38108--- a/drivers/gpio/gpio-vr41xx.c
38109+++ b/drivers/gpio/gpio-vr41xx.c
38110@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38111 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38112 maskl, pendl, maskh, pendh);
38113
38114- atomic_inc(&irq_err_count);
38115+ atomic_inc_unchecked(&irq_err_count);
38116
38117 return -EINVAL;
38118 }
38119diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38120index 6a64749..0767a9f 100644
38121--- a/drivers/gpu/drm/drm_crtc_helper.c
38122+++ b/drivers/gpu/drm/drm_crtc_helper.c
38123@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38124 struct drm_crtc *tmp;
38125 int crtc_mask = 1;
38126
38127- WARN(!crtc, "checking null crtc?\n");
38128+ BUG_ON(!crtc);
38129
38130 dev = crtc->dev;
38131
38132diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38133index 99fcd7c..13cf6c5 100644
38134--- a/drivers/gpu/drm/drm_drv.c
38135+++ b/drivers/gpu/drm/drm_drv.c
38136@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
38137 /**
38138 * Copy and IOCTL return string to user space
38139 */
38140-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38141+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38142 {
38143 int len;
38144
38145@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
38146 struct drm_file *file_priv = filp->private_data;
38147 struct drm_device *dev;
38148 const struct drm_ioctl_desc *ioctl = NULL;
38149- drm_ioctl_t *func;
38150+ drm_ioctl_no_const_t func;
38151 unsigned int nr = DRM_IOCTL_NR(cmd);
38152 int retcode = -EINVAL;
38153 char stack_kdata[128];
38154@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
38155 return -ENODEV;
38156
38157 atomic_inc(&dev->ioctl_count);
38158- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38159+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38160 ++file_priv->ioctl_count;
38161
38162 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38163diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38164index 3a24385..4e426e0 100644
38165--- a/drivers/gpu/drm/drm_fops.c
38166+++ b/drivers/gpu/drm/drm_fops.c
38167@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38168 }
38169
38170 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38171- atomic_set(&dev->counts[i], 0);
38172+ atomic_set_unchecked(&dev->counts[i], 0);
38173
38174 dev->sigdata.lock = NULL;
38175
38176@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38177 if (drm_device_is_unplugged(dev))
38178 return -ENODEV;
38179
38180- if (!dev->open_count++)
38181+ if (local_inc_return(&dev->open_count) == 1)
38182 need_setup = 1;
38183 mutex_lock(&dev->struct_mutex);
38184 old_imapping = inode->i_mapping;
38185@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38186 retcode = drm_open_helper(inode, filp, dev);
38187 if (retcode)
38188 goto err_undo;
38189- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38190+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38191 if (need_setup) {
38192 retcode = drm_setup(dev);
38193 if (retcode)
38194@@ -166,7 +166,7 @@ err_undo:
38195 iput(container_of(dev->dev_mapping, struct inode, i_data));
38196 dev->dev_mapping = old_mapping;
38197 mutex_unlock(&dev->struct_mutex);
38198- dev->open_count--;
38199+ local_dec(&dev->open_count);
38200 return retcode;
38201 }
38202 EXPORT_SYMBOL(drm_open);
38203@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38204
38205 mutex_lock(&drm_global_mutex);
38206
38207- DRM_DEBUG("open_count = %d\n", dev->open_count);
38208+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38209
38210 if (dev->driver->preclose)
38211 dev->driver->preclose(dev, file_priv);
38212@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38213 * Begin inline drm_release
38214 */
38215
38216- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38217+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38218 task_pid_nr(current),
38219 (long)old_encode_dev(file_priv->minor->device),
38220- dev->open_count);
38221+ local_read(&dev->open_count));
38222
38223 /* Release any auth tokens that might point to this file_priv,
38224 (do that under the drm_global_mutex) */
38225@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38226 * End inline drm_release
38227 */
38228
38229- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38230- if (!--dev->open_count) {
38231+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38232+ if (local_dec_and_test(&dev->open_count)) {
38233 if (atomic_read(&dev->ioctl_count)) {
38234 DRM_ERROR("Device busy: %d\n",
38235 atomic_read(&dev->ioctl_count));
38236diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38237index f731116..629842c 100644
38238--- a/drivers/gpu/drm/drm_global.c
38239+++ b/drivers/gpu/drm/drm_global.c
38240@@ -36,7 +36,7 @@
38241 struct drm_global_item {
38242 struct mutex mutex;
38243 void *object;
38244- int refcount;
38245+ atomic_t refcount;
38246 };
38247
38248 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38249@@ -49,7 +49,7 @@ void drm_global_init(void)
38250 struct drm_global_item *item = &glob[i];
38251 mutex_init(&item->mutex);
38252 item->object = NULL;
38253- item->refcount = 0;
38254+ atomic_set(&item->refcount, 0);
38255 }
38256 }
38257
38258@@ -59,7 +59,7 @@ void drm_global_release(void)
38259 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38260 struct drm_global_item *item = &glob[i];
38261 BUG_ON(item->object != NULL);
38262- BUG_ON(item->refcount != 0);
38263+ BUG_ON(atomic_read(&item->refcount) != 0);
38264 }
38265 }
38266
38267@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38268 void *object;
38269
38270 mutex_lock(&item->mutex);
38271- if (item->refcount == 0) {
38272+ if (atomic_read(&item->refcount) == 0) {
38273 item->object = kzalloc(ref->size, GFP_KERNEL);
38274 if (unlikely(item->object == NULL)) {
38275 ret = -ENOMEM;
38276@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38277 goto out_err;
38278
38279 }
38280- ++item->refcount;
38281+ atomic_inc(&item->refcount);
38282 ref->object = item->object;
38283 object = item->object;
38284 mutex_unlock(&item->mutex);
38285@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38286 struct drm_global_item *item = &glob[ref->global_type];
38287
38288 mutex_lock(&item->mutex);
38289- BUG_ON(item->refcount == 0);
38290+ BUG_ON(atomic_read(&item->refcount) == 0);
38291 BUG_ON(ref->object != item->object);
38292- if (--item->refcount == 0) {
38293+ if (atomic_dec_and_test(&item->refcount)) {
38294 ref->release(ref);
38295 item->object = NULL;
38296 }
38297diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38298index d4b20ce..77a8d41 100644
38299--- a/drivers/gpu/drm/drm_info.c
38300+++ b/drivers/gpu/drm/drm_info.c
38301@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38302 struct drm_local_map *map;
38303 struct drm_map_list *r_list;
38304
38305- /* Hardcoded from _DRM_FRAME_BUFFER,
38306- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38307- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38308- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38309+ static const char * const types[] = {
38310+ [_DRM_FRAME_BUFFER] = "FB",
38311+ [_DRM_REGISTERS] = "REG",
38312+ [_DRM_SHM] = "SHM",
38313+ [_DRM_AGP] = "AGP",
38314+ [_DRM_SCATTER_GATHER] = "SG",
38315+ [_DRM_CONSISTENT] = "PCI",
38316+ [_DRM_GEM] = "GEM" };
38317 const char *type;
38318 int i;
38319
38320@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38321 map = r_list->map;
38322 if (!map)
38323 continue;
38324- if (map->type < 0 || map->type > 5)
38325+ if (map->type >= ARRAY_SIZE(types))
38326 type = "??";
38327 else
38328 type = types[map->type];
38329@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38330 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38331 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38332 vma->vm_flags & VM_IO ? 'i' : '-',
38333+#ifdef CONFIG_GRKERNSEC_HIDESYM
38334+ 0);
38335+#else
38336 vma->vm_pgoff);
38337+#endif
38338
38339 #if defined(__i386__)
38340 pgprot = pgprot_val(vma->vm_page_prot);
38341diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38342index 2f4c434..dd12cd2 100644
38343--- a/drivers/gpu/drm/drm_ioc32.c
38344+++ b/drivers/gpu/drm/drm_ioc32.c
38345@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38346 request = compat_alloc_user_space(nbytes);
38347 if (!access_ok(VERIFY_WRITE, request, nbytes))
38348 return -EFAULT;
38349- list = (struct drm_buf_desc *) (request + 1);
38350+ list = (struct drm_buf_desc __user *) (request + 1);
38351
38352 if (__put_user(count, &request->count)
38353 || __put_user(list, &request->list))
38354@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38355 request = compat_alloc_user_space(nbytes);
38356 if (!access_ok(VERIFY_WRITE, request, nbytes))
38357 return -EFAULT;
38358- list = (struct drm_buf_pub *) (request + 1);
38359+ list = (struct drm_buf_pub __user *) (request + 1);
38360
38361 if (__put_user(count, &request->count)
38362 || __put_user(list, &request->list))
38363@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38364 return 0;
38365 }
38366
38367-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38368+drm_ioctl_compat_t drm_compat_ioctls[] = {
38369 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38370 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38371 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38372@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38373 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38374 {
38375 unsigned int nr = DRM_IOCTL_NR(cmd);
38376- drm_ioctl_compat_t *fn;
38377 int ret;
38378
38379 /* Assume that ioctls without an explicit compat routine will just
38380@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38381 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38382 return drm_ioctl(filp, cmd, arg);
38383
38384- fn = drm_compat_ioctls[nr];
38385-
38386- if (fn != NULL)
38387- ret = (*fn) (filp, cmd, arg);
38388+ if (drm_compat_ioctls[nr] != NULL)
38389+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38390 else
38391 ret = drm_ioctl(filp, cmd, arg);
38392
38393diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38394index ffd7a7b..a64643e 100644
38395--- a/drivers/gpu/drm/drm_ioctl.c
38396+++ b/drivers/gpu/drm/drm_ioctl.c
38397@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38398 stats->data[i].value =
38399 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38400 else
38401- stats->data[i].value = atomic_read(&dev->counts[i]);
38402+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38403 stats->data[i].type = dev->types[i];
38404 }
38405
38406diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38407index d752c96..fe08455 100644
38408--- a/drivers/gpu/drm/drm_lock.c
38409+++ b/drivers/gpu/drm/drm_lock.c
38410@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38411 if (drm_lock_take(&master->lock, lock->context)) {
38412 master->lock.file_priv = file_priv;
38413 master->lock.lock_time = jiffies;
38414- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38415+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38416 break; /* Got lock */
38417 }
38418
38419@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38420 return -EINVAL;
38421 }
38422
38423- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38424+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38425
38426 if (drm_lock_free(&master->lock, lock->context)) {
38427 /* FIXME: Should really bail out here. */
38428diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38429index 327ca19..684d3c0 100644
38430--- a/drivers/gpu/drm/drm_stub.c
38431+++ b/drivers/gpu/drm/drm_stub.c
38432@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38433
38434 drm_device_set_unplugged(dev);
38435
38436- if (dev->open_count == 0) {
38437+ if (local_read(&dev->open_count) == 0) {
38438 drm_put_dev(dev);
38439 }
38440 mutex_unlock(&drm_global_mutex);
38441diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38442index 2290b3b..22056a1 100644
38443--- a/drivers/gpu/drm/drm_sysfs.c
38444+++ b/drivers/gpu/drm/drm_sysfs.c
38445@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38446 int drm_sysfs_device_add(struct drm_minor *minor)
38447 {
38448 int err;
38449- char *minor_str;
38450+ const char *minor_str;
38451
38452 minor->kdev.parent = minor->dev->dev;
38453
38454diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38455index ada49ed..29275a0 100644
38456--- a/drivers/gpu/drm/i810/i810_dma.c
38457+++ b/drivers/gpu/drm/i810/i810_dma.c
38458@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38459 dma->buflist[vertex->idx],
38460 vertex->discard, vertex->used);
38461
38462- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38463- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38464+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38465+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38466 sarea_priv->last_enqueue = dev_priv->counter - 1;
38467 sarea_priv->last_dispatch = (int)hw_status[5];
38468
38469@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38470 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38471 mc->last_render);
38472
38473- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38474- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38475+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38476+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38477 sarea_priv->last_enqueue = dev_priv->counter - 1;
38478 sarea_priv->last_dispatch = (int)hw_status[5];
38479
38480diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38481index 6e0acad..93c8289 100644
38482--- a/drivers/gpu/drm/i810/i810_drv.h
38483+++ b/drivers/gpu/drm/i810/i810_drv.h
38484@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38485 int page_flipping;
38486
38487 wait_queue_head_t irq_queue;
38488- atomic_t irq_received;
38489- atomic_t irq_emitted;
38490+ atomic_unchecked_t irq_received;
38491+ atomic_unchecked_t irq_emitted;
38492
38493 int front_offset;
38494 } drm_i810_private_t;
38495diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38496index 47d6c74..279123f 100644
38497--- a/drivers/gpu/drm/i915/i915_debugfs.c
38498+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38499@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38500 I915_READ(GTIMR));
38501 }
38502 seq_printf(m, "Interrupts received: %d\n",
38503- atomic_read(&dev_priv->irq_received));
38504+ atomic_read_unchecked(&dev_priv->irq_received));
38505 for_each_ring(ring, dev_priv, i) {
38506 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38507 seq_printf(m,
38508diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38509index f466980..8f2883f 100644
38510--- a/drivers/gpu/drm/i915/i915_dma.c
38511+++ b/drivers/gpu/drm/i915/i915_dma.c
38512@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38513 bool can_switch;
38514
38515 spin_lock(&dev->count_lock);
38516- can_switch = (dev->open_count == 0);
38517+ can_switch = (local_read(&dev->open_count) == 0);
38518 spin_unlock(&dev->count_lock);
38519 return can_switch;
38520 }
38521diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38522index 2f09e80..077876d 100644
38523--- a/drivers/gpu/drm/i915/i915_drv.h
38524+++ b/drivers/gpu/drm/i915/i915_drv.h
38525@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38526 drm_dma_handle_t *status_page_dmah;
38527 struct resource mch_res;
38528
38529- atomic_t irq_received;
38530+ atomic_unchecked_t irq_received;
38531
38532 /* protects the irq masks */
38533 spinlock_t irq_lock;
38534diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38535index 87a3227..cd13d8f 100644
38536--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38537+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38538@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38539
38540 static int
38541 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38542- int count)
38543+ unsigned int count)
38544 {
38545- int i;
38546+ unsigned int i;
38547 int relocs_total = 0;
38548 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38549
38550diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38551index 3c59584..500f2e9 100644
38552--- a/drivers/gpu/drm/i915/i915_ioc32.c
38553+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38554@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38555 (unsigned long)request);
38556 }
38557
38558-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38559+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38560 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38561 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38562 [DRM_I915_GETPARAM] = compat_i915_getparam,
38563@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38564 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38565 {
38566 unsigned int nr = DRM_IOCTL_NR(cmd);
38567- drm_ioctl_compat_t *fn = NULL;
38568 int ret;
38569
38570 if (nr < DRM_COMMAND_BASE)
38571 return drm_compat_ioctl(filp, cmd, arg);
38572
38573- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38574- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38575-
38576- if (fn != NULL)
38577+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38578+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38579 ret = (*fn) (filp, cmd, arg);
38580- else
38581+ } else
38582 ret = drm_ioctl(filp, cmd, arg);
38583
38584 return ret;
38585diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38586index 46d46ba..6e49848 100644
38587--- a/drivers/gpu/drm/i915/i915_irq.c
38588+++ b/drivers/gpu/drm/i915/i915_irq.c
38589@@ -975,7 +975,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38590 int pipe;
38591 u32 pipe_stats[I915_MAX_PIPES];
38592
38593- atomic_inc(&dev_priv->irq_received);
38594+ atomic_inc_unchecked(&dev_priv->irq_received);
38595
38596 while (true) {
38597 iir = I915_READ(VLV_IIR);
38598@@ -1192,7 +1192,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38599 irqreturn_t ret = IRQ_NONE;
38600 int i;
38601
38602- atomic_inc(&dev_priv->irq_received);
38603+ atomic_inc_unchecked(&dev_priv->irq_received);
38604
38605 /* We get interrupts on unclaimed registers, so check for this before we
38606 * do any I915_{READ,WRITE}. */
38607@@ -1312,7 +1312,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38608 int ret = IRQ_NONE;
38609 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38610
38611- atomic_inc(&dev_priv->irq_received);
38612+ atomic_inc_unchecked(&dev_priv->irq_received);
38613
38614 /* disable master interrupt before clearing iir */
38615 de_ier = I915_READ(DEIER);
38616@@ -2617,7 +2617,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38617 {
38618 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38619
38620- atomic_set(&dev_priv->irq_received, 0);
38621+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38622
38623 I915_WRITE(HWSTAM, 0xeffe);
38624
38625@@ -2639,7 +2639,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38626 {
38627 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38628
38629- atomic_set(&dev_priv->irq_received, 0);
38630+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38631
38632 I915_WRITE(HWSTAM, 0xeffe);
38633
38634@@ -2667,7 +2667,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38635 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38636 int pipe;
38637
38638- atomic_set(&dev_priv->irq_received, 0);
38639+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38640
38641 /* VLV magic */
38642 I915_WRITE(VLV_IMR, 0);
38643@@ -2979,7 +2979,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38644 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38645 int pipe;
38646
38647- atomic_set(&dev_priv->irq_received, 0);
38648+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38649
38650 for_each_pipe(pipe)
38651 I915_WRITE(PIPESTAT(pipe), 0);
38652@@ -3058,7 +3058,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38653 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38654 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38655
38656- atomic_inc(&dev_priv->irq_received);
38657+ atomic_inc_unchecked(&dev_priv->irq_received);
38658
38659 iir = I915_READ16(IIR);
38660 if (iir == 0)
38661@@ -3133,7 +3133,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38662 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38663 int pipe;
38664
38665- atomic_set(&dev_priv->irq_received, 0);
38666+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38667
38668 if (I915_HAS_HOTPLUG(dev)) {
38669 I915_WRITE(PORT_HOTPLUG_EN, 0);
38670@@ -3232,7 +3232,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38671 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38672 int pipe, ret = IRQ_NONE;
38673
38674- atomic_inc(&dev_priv->irq_received);
38675+ atomic_inc_unchecked(&dev_priv->irq_received);
38676
38677 iir = I915_READ(IIR);
38678 do {
38679@@ -3356,7 +3356,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38680 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38681 int pipe;
38682
38683- atomic_set(&dev_priv->irq_received, 0);
38684+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38685
38686 I915_WRITE(PORT_HOTPLUG_EN, 0);
38687 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38688@@ -3465,7 +3465,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38689 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38690 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38691
38692- atomic_inc(&dev_priv->irq_received);
38693+ atomic_inc_unchecked(&dev_priv->irq_received);
38694
38695 iir = I915_READ(IIR);
38696
38697diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38698index 90a7c17..ecedc6a 100644
38699--- a/drivers/gpu/drm/i915/intel_display.c
38700+++ b/drivers/gpu/drm/i915/intel_display.c
38701@@ -9424,13 +9424,13 @@ struct intel_quirk {
38702 int subsystem_vendor;
38703 int subsystem_device;
38704 void (*hook)(struct drm_device *dev);
38705-};
38706+} __do_const;
38707
38708 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38709 struct intel_dmi_quirk {
38710 void (*hook)(struct drm_device *dev);
38711 const struct dmi_system_id (*dmi_id_list)[];
38712-};
38713+} __do_const;
38714
38715 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38716 {
38717@@ -9438,18 +9438,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38718 return 1;
38719 }
38720
38721-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38722+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38723 {
38724- .dmi_id_list = &(const struct dmi_system_id[]) {
38725- {
38726- .callback = intel_dmi_reverse_brightness,
38727- .ident = "NCR Corporation",
38728- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38729- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38730- },
38731- },
38732- { } /* terminating entry */
38733+ .callback = intel_dmi_reverse_brightness,
38734+ .ident = "NCR Corporation",
38735+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38736+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38737 },
38738+ },
38739+ { } /* terminating entry */
38740+};
38741+
38742+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38743+ {
38744+ .dmi_id_list = &intel_dmi_quirks_table,
38745 .hook = quirk_invert_brightness,
38746 },
38747 };
38748diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38749index 54558a0..2d97005 100644
38750--- a/drivers/gpu/drm/mga/mga_drv.h
38751+++ b/drivers/gpu/drm/mga/mga_drv.h
38752@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38753 u32 clear_cmd;
38754 u32 maccess;
38755
38756- atomic_t vbl_received; /**< Number of vblanks received. */
38757+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38758 wait_queue_head_t fence_queue;
38759- atomic_t last_fence_retired;
38760+ atomic_unchecked_t last_fence_retired;
38761 u32 next_fence_to_post;
38762
38763 unsigned int fb_cpp;
38764diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38765index 709e90d..89a1c0d 100644
38766--- a/drivers/gpu/drm/mga/mga_ioc32.c
38767+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38768@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38769 return 0;
38770 }
38771
38772-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38773+drm_ioctl_compat_t mga_compat_ioctls[] = {
38774 [DRM_MGA_INIT] = compat_mga_init,
38775 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38776 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38777@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38778 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38779 {
38780 unsigned int nr = DRM_IOCTL_NR(cmd);
38781- drm_ioctl_compat_t *fn = NULL;
38782 int ret;
38783
38784 if (nr < DRM_COMMAND_BASE)
38785 return drm_compat_ioctl(filp, cmd, arg);
38786
38787- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38788- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38789-
38790- if (fn != NULL)
38791+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38792+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38793 ret = (*fn) (filp, cmd, arg);
38794- else
38795+ } else
38796 ret = drm_ioctl(filp, cmd, arg);
38797
38798 return ret;
38799diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38800index 598c281..60d590e 100644
38801--- a/drivers/gpu/drm/mga/mga_irq.c
38802+++ b/drivers/gpu/drm/mga/mga_irq.c
38803@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38804 if (crtc != 0)
38805 return 0;
38806
38807- return atomic_read(&dev_priv->vbl_received);
38808+ return atomic_read_unchecked(&dev_priv->vbl_received);
38809 }
38810
38811
38812@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38813 /* VBLANK interrupt */
38814 if (status & MGA_VLINEPEN) {
38815 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38816- atomic_inc(&dev_priv->vbl_received);
38817+ atomic_inc_unchecked(&dev_priv->vbl_received);
38818 drm_handle_vblank(dev, 0);
38819 handled = 1;
38820 }
38821@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38822 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38823 MGA_WRITE(MGA_PRIMEND, prim_end);
38824
38825- atomic_inc(&dev_priv->last_fence_retired);
38826+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38827 DRM_WAKEUP(&dev_priv->fence_queue);
38828 handled = 1;
38829 }
38830@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38831 * using fences.
38832 */
38833 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38834- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38835+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38836 - *sequence) <= (1 << 23)));
38837
38838 *sequence = cur_fence;
38839diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38840index 3e72876..d1c15ad 100644
38841--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38842+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38843@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38844 struct bit_table {
38845 const char id;
38846 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38847-};
38848+} __no_const;
38849
38850 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38851
38852diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38853index 41ff7e0..fa854ef 100644
38854--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38855+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38856@@ -92,7 +92,6 @@ struct nouveau_drm {
38857 struct drm_global_reference mem_global_ref;
38858 struct ttm_bo_global_ref bo_global_ref;
38859 struct ttm_bo_device bdev;
38860- atomic_t validate_sequence;
38861 int (*move)(struct nouveau_channel *,
38862 struct ttm_buffer_object *,
38863 struct ttm_mem_reg *, struct ttm_mem_reg *);
38864diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38865index 08214bc..9208577 100644
38866--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38867+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38868@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38869 unsigned long arg)
38870 {
38871 unsigned int nr = DRM_IOCTL_NR(cmd);
38872- drm_ioctl_compat_t *fn = NULL;
38873+ drm_ioctl_compat_t fn = NULL;
38874 int ret;
38875
38876 if (nr < DRM_COMMAND_BASE)
38877diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38878index 25d3495..d81aaf6 100644
38879--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38880+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38881@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38882 bool can_switch;
38883
38884 spin_lock(&dev->count_lock);
38885- can_switch = (dev->open_count == 0);
38886+ can_switch = (local_read(&dev->open_count) == 0);
38887 spin_unlock(&dev->count_lock);
38888 return can_switch;
38889 }
38890diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38891index 1dfd84c..104896c 100644
38892--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38893+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38894@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38895 }
38896 }
38897
38898-static struct vm_operations_struct qxl_ttm_vm_ops;
38899+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38900 static const struct vm_operations_struct *ttm_vm_ops;
38901
38902 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38903@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38904 return r;
38905 if (unlikely(ttm_vm_ops == NULL)) {
38906 ttm_vm_ops = vma->vm_ops;
38907+ pax_open_kernel();
38908 qxl_ttm_vm_ops = *ttm_vm_ops;
38909 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38910+ pax_close_kernel();
38911 }
38912 vma->vm_ops = &qxl_ttm_vm_ops;
38913 return 0;
38914@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38915 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38916 {
38917 #if defined(CONFIG_DEBUG_FS)
38918- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38919- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38920- unsigned i;
38921+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38922+ {
38923+ .name = "qxl_mem_mm",
38924+ .show = &qxl_mm_dump_table,
38925+ },
38926+ {
38927+ .name = "qxl_surf_mm",
38928+ .show = &qxl_mm_dump_table,
38929+ }
38930+ };
38931
38932- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38933- if (i == 0)
38934- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38935- else
38936- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38937- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38938- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38939- qxl_mem_types_list[i].driver_features = 0;
38940- if (i == 0)
38941- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38942- else
38943- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38944+ pax_open_kernel();
38945+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38946+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38947+ pax_close_kernel();
38948
38949- }
38950- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38951+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38952 #else
38953 return 0;
38954 #endif
38955diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38956index d4660cf..70dbe65 100644
38957--- a/drivers/gpu/drm/r128/r128_cce.c
38958+++ b/drivers/gpu/drm/r128/r128_cce.c
38959@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38960
38961 /* GH: Simple idle check.
38962 */
38963- atomic_set(&dev_priv->idle_count, 0);
38964+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38965
38966 /* We don't support anything other than bus-mastering ring mode,
38967 * but the ring can be in either AGP or PCI space for the ring
38968diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38969index 930c71b..499aded 100644
38970--- a/drivers/gpu/drm/r128/r128_drv.h
38971+++ b/drivers/gpu/drm/r128/r128_drv.h
38972@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38973 int is_pci;
38974 unsigned long cce_buffers_offset;
38975
38976- atomic_t idle_count;
38977+ atomic_unchecked_t idle_count;
38978
38979 int page_flipping;
38980 int current_page;
38981 u32 crtc_offset;
38982 u32 crtc_offset_cntl;
38983
38984- atomic_t vbl_received;
38985+ atomic_unchecked_t vbl_received;
38986
38987 u32 color_fmt;
38988 unsigned int front_offset;
38989diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38990index a954c54..9cc595c 100644
38991--- a/drivers/gpu/drm/r128/r128_ioc32.c
38992+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38993@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38994 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38995 }
38996
38997-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38998+drm_ioctl_compat_t r128_compat_ioctls[] = {
38999 [DRM_R128_INIT] = compat_r128_init,
39000 [DRM_R128_DEPTH] = compat_r128_depth,
39001 [DRM_R128_STIPPLE] = compat_r128_stipple,
39002@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39003 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39004 {
39005 unsigned int nr = DRM_IOCTL_NR(cmd);
39006- drm_ioctl_compat_t *fn = NULL;
39007 int ret;
39008
39009 if (nr < DRM_COMMAND_BASE)
39010 return drm_compat_ioctl(filp, cmd, arg);
39011
39012- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39013- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39014-
39015- if (fn != NULL)
39016+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39017+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39018 ret = (*fn) (filp, cmd, arg);
39019- else
39020+ } else
39021 ret = drm_ioctl(filp, cmd, arg);
39022
39023 return ret;
39024diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39025index 2ea4f09..d391371 100644
39026--- a/drivers/gpu/drm/r128/r128_irq.c
39027+++ b/drivers/gpu/drm/r128/r128_irq.c
39028@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39029 if (crtc != 0)
39030 return 0;
39031
39032- return atomic_read(&dev_priv->vbl_received);
39033+ return atomic_read_unchecked(&dev_priv->vbl_received);
39034 }
39035
39036 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39037@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39038 /* VBLANK interrupt */
39039 if (status & R128_CRTC_VBLANK_INT) {
39040 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39041- atomic_inc(&dev_priv->vbl_received);
39042+ atomic_inc_unchecked(&dev_priv->vbl_received);
39043 drm_handle_vblank(dev, 0);
39044 return IRQ_HANDLED;
39045 }
39046diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39047index 19bb7e6..de7e2a2 100644
39048--- a/drivers/gpu/drm/r128/r128_state.c
39049+++ b/drivers/gpu/drm/r128/r128_state.c
39050@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39051
39052 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39053 {
39054- if (atomic_read(&dev_priv->idle_count) == 0)
39055+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39056 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39057 else
39058- atomic_set(&dev_priv->idle_count, 0);
39059+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39060 }
39061
39062 #endif
39063diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39064index af85299..ed9ac8d 100644
39065--- a/drivers/gpu/drm/radeon/mkregtable.c
39066+++ b/drivers/gpu/drm/radeon/mkregtable.c
39067@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
39068 regex_t mask_rex;
39069 regmatch_t match[4];
39070 char buf[1024];
39071- size_t end;
39072+ long end;
39073 int len;
39074 int done = 0;
39075 int r;
39076 unsigned o;
39077 struct offset *offset;
39078 char last_reg_s[10];
39079- int last_reg;
39080+ unsigned long last_reg;
39081
39082 if (regcomp
39083 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39084diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39085index d15f27e..ef11ffc 100644
39086--- a/drivers/gpu/drm/radeon/radeon_device.c
39087+++ b/drivers/gpu/drm/radeon/radeon_device.c
39088@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39089 bool can_switch;
39090
39091 spin_lock(&dev->count_lock);
39092- can_switch = (dev->open_count == 0);
39093+ can_switch = (local_read(&dev->open_count) == 0);
39094 spin_unlock(&dev->count_lock);
39095 return can_switch;
39096 }
39097diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39098index b369d42..8dd04eb 100644
39099--- a/drivers/gpu/drm/radeon/radeon_drv.h
39100+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39101@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39102
39103 /* SW interrupt */
39104 wait_queue_head_t swi_queue;
39105- atomic_t swi_emitted;
39106+ atomic_unchecked_t swi_emitted;
39107 int vblank_crtc;
39108 uint32_t irq_enable_reg;
39109 uint32_t r500_disp_irq_reg;
39110diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39111index c180df8..5fd8186 100644
39112--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39113+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39114@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39115 request = compat_alloc_user_space(sizeof(*request));
39116 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39117 || __put_user(req32.param, &request->param)
39118- || __put_user((void __user *)(unsigned long)req32.value,
39119+ || __put_user((unsigned long)req32.value,
39120 &request->value))
39121 return -EFAULT;
39122
39123@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39124 #define compat_radeon_cp_setparam NULL
39125 #endif /* X86_64 || IA64 */
39126
39127-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39128+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39129 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39130 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39131 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39132@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39133 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39134 {
39135 unsigned int nr = DRM_IOCTL_NR(cmd);
39136- drm_ioctl_compat_t *fn = NULL;
39137 int ret;
39138
39139 if (nr < DRM_COMMAND_BASE)
39140 return drm_compat_ioctl(filp, cmd, arg);
39141
39142- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39143- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39144-
39145- if (fn != NULL)
39146+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39147+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39148 ret = (*fn) (filp, cmd, arg);
39149- else
39150+ } else
39151 ret = drm_ioctl(filp, cmd, arg);
39152
39153 return ret;
39154diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39155index 8d68e97..9dcfed8 100644
39156--- a/drivers/gpu/drm/radeon/radeon_irq.c
39157+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39158@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39159 unsigned int ret;
39160 RING_LOCALS;
39161
39162- atomic_inc(&dev_priv->swi_emitted);
39163- ret = atomic_read(&dev_priv->swi_emitted);
39164+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39165+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39166
39167 BEGIN_RING(4);
39168 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39169@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39170 drm_radeon_private_t *dev_priv =
39171 (drm_radeon_private_t *) dev->dev_private;
39172
39173- atomic_set(&dev_priv->swi_emitted, 0);
39174+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39175 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39176
39177 dev->max_vblank_count = 0x001fffff;
39178diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39179index 4d20910..6726b6d 100644
39180--- a/drivers/gpu/drm/radeon/radeon_state.c
39181+++ b/drivers/gpu/drm/radeon/radeon_state.c
39182@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39183 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39184 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39185
39186- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39187+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39188 sarea_priv->nbox * sizeof(depth_boxes[0])))
39189 return -EFAULT;
39190
39191@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39192 {
39193 drm_radeon_private_t *dev_priv = dev->dev_private;
39194 drm_radeon_getparam_t *param = data;
39195- int value;
39196+ int value = 0;
39197
39198 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39199
39200diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39201index 6c0ce89..57a2529 100644
39202--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39203+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39204@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39205 man->size = size >> PAGE_SHIFT;
39206 }
39207
39208-static struct vm_operations_struct radeon_ttm_vm_ops;
39209+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39210 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39211
39212 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39213@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39214 }
39215 if (unlikely(ttm_vm_ops == NULL)) {
39216 ttm_vm_ops = vma->vm_ops;
39217+ pax_open_kernel();
39218 radeon_ttm_vm_ops = *ttm_vm_ops;
39219 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39220+ pax_close_kernel();
39221 }
39222 vma->vm_ops = &radeon_ttm_vm_ops;
39223 return 0;
39224@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39225 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39226 {
39227 #if defined(CONFIG_DEBUG_FS)
39228- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39229- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39230+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39231+ {
39232+ .name = "radeon_vram_mm",
39233+ .show = &radeon_mm_dump_table,
39234+ },
39235+ {
39236+ .name = "radeon_gtt_mm",
39237+ .show = &radeon_mm_dump_table,
39238+ },
39239+ {
39240+ .name = "ttm_page_pool",
39241+ .show = &ttm_page_alloc_debugfs,
39242+ },
39243+ {
39244+ .name = "ttm_dma_page_pool",
39245+ .show = &ttm_dma_page_alloc_debugfs,
39246+ },
39247+ };
39248 unsigned i;
39249
39250- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39251- if (i == 0)
39252- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39253- else
39254- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39255- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39256- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39257- radeon_mem_types_list[i].driver_features = 0;
39258- if (i == 0)
39259- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39260- else
39261- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39262-
39263- }
39264- /* Add ttm page pool to debugfs */
39265- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39266- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39267- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39268- radeon_mem_types_list[i].driver_features = 0;
39269- radeon_mem_types_list[i++].data = NULL;
39270+ pax_open_kernel();
39271+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39272+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39273+ pax_close_kernel();
39274 #ifdef CONFIG_SWIOTLB
39275- if (swiotlb_nr_tbl()) {
39276- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39277- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39278- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39279- radeon_mem_types_list[i].driver_features = 0;
39280- radeon_mem_types_list[i++].data = NULL;
39281- }
39282+ if (swiotlb_nr_tbl())
39283+ i++;
39284 #endif
39285 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39286
39287diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39288index d8ddfb3..609de1d 100644
39289--- a/drivers/gpu/drm/radeon/rs690.c
39290+++ b/drivers/gpu/drm/radeon/rs690.c
39291@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39292 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39293 rdev->pm.sideport_bandwidth.full)
39294 max_bandwidth = rdev->pm.sideport_bandwidth;
39295- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39296+ read_delay_latency.full = dfixed_const(800 * 1000);
39297 read_delay_latency.full = dfixed_div(read_delay_latency,
39298 rdev->pm.igp_sideport_mclk);
39299+ a.full = dfixed_const(370);
39300+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39301 } else {
39302 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39303 rdev->pm.k8_bandwidth.full)
39304diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39305index dbc2def..0a9f710 100644
39306--- a/drivers/gpu/drm/ttm/ttm_memory.c
39307+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39308@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39309 zone->glob = glob;
39310 glob->zone_kernel = zone;
39311 ret = kobject_init_and_add(
39312- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39313+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39314 if (unlikely(ret != 0)) {
39315 kobject_put(&zone->kobj);
39316 return ret;
39317@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39318 zone->glob = glob;
39319 glob->zone_dma32 = zone;
39320 ret = kobject_init_and_add(
39321- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39322+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39323 if (unlikely(ret != 0)) {
39324 kobject_put(&zone->kobj);
39325 return ret;
39326diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39327index bd2a3b4..122d9ad 100644
39328--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39329+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39330@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39331 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39332 struct shrink_control *sc)
39333 {
39334- static atomic_t start_pool = ATOMIC_INIT(0);
39335+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39336 unsigned i;
39337- unsigned pool_offset = atomic_add_return(1, &start_pool);
39338+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39339 struct ttm_page_pool *pool;
39340 int shrink_pages = sc->nr_to_scan;
39341
39342diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39343index 97e9d61..bf23c461 100644
39344--- a/drivers/gpu/drm/udl/udl_fb.c
39345+++ b/drivers/gpu/drm/udl/udl_fb.c
39346@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39347 fb_deferred_io_cleanup(info);
39348 kfree(info->fbdefio);
39349 info->fbdefio = NULL;
39350- info->fbops->fb_mmap = udl_fb_mmap;
39351 }
39352
39353 pr_warn("released /dev/fb%d user=%d count=%d\n",
39354diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39355index 893a650..6190d3b 100644
39356--- a/drivers/gpu/drm/via/via_drv.h
39357+++ b/drivers/gpu/drm/via/via_drv.h
39358@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39359 typedef uint32_t maskarray_t[5];
39360
39361 typedef struct drm_via_irq {
39362- atomic_t irq_received;
39363+ atomic_unchecked_t irq_received;
39364 uint32_t pending_mask;
39365 uint32_t enable_mask;
39366 wait_queue_head_t irq_queue;
39367@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39368 struct timeval last_vblank;
39369 int last_vblank_valid;
39370 unsigned usec_per_vblank;
39371- atomic_t vbl_received;
39372+ atomic_unchecked_t vbl_received;
39373 drm_via_state_t hc_state;
39374 char pci_buf[VIA_PCI_BUF_SIZE];
39375 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39376diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39377index ac98964..5dbf512 100644
39378--- a/drivers/gpu/drm/via/via_irq.c
39379+++ b/drivers/gpu/drm/via/via_irq.c
39380@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39381 if (crtc != 0)
39382 return 0;
39383
39384- return atomic_read(&dev_priv->vbl_received);
39385+ return atomic_read_unchecked(&dev_priv->vbl_received);
39386 }
39387
39388 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39389@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39390
39391 status = VIA_READ(VIA_REG_INTERRUPT);
39392 if (status & VIA_IRQ_VBLANK_PENDING) {
39393- atomic_inc(&dev_priv->vbl_received);
39394- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39395+ atomic_inc_unchecked(&dev_priv->vbl_received);
39396+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39397 do_gettimeofday(&cur_vblank);
39398 if (dev_priv->last_vblank_valid) {
39399 dev_priv->usec_per_vblank =
39400@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39401 dev_priv->last_vblank = cur_vblank;
39402 dev_priv->last_vblank_valid = 1;
39403 }
39404- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39405+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39406 DRM_DEBUG("US per vblank is: %u\n",
39407 dev_priv->usec_per_vblank);
39408 }
39409@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39410
39411 for (i = 0; i < dev_priv->num_irqs; ++i) {
39412 if (status & cur_irq->pending_mask) {
39413- atomic_inc(&cur_irq->irq_received);
39414+ atomic_inc_unchecked(&cur_irq->irq_received);
39415 DRM_WAKEUP(&cur_irq->irq_queue);
39416 handled = 1;
39417 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39418@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39419 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39420 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39421 masks[irq][4]));
39422- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39423+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39424 } else {
39425 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39426 (((cur_irq_sequence =
39427- atomic_read(&cur_irq->irq_received)) -
39428+ atomic_read_unchecked(&cur_irq->irq_received)) -
39429 *sequence) <= (1 << 23)));
39430 }
39431 *sequence = cur_irq_sequence;
39432@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39433 }
39434
39435 for (i = 0; i < dev_priv->num_irqs; ++i) {
39436- atomic_set(&cur_irq->irq_received, 0);
39437+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39438 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39439 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39440 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39441@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39442 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39443 case VIA_IRQ_RELATIVE:
39444 irqwait->request.sequence +=
39445- atomic_read(&cur_irq->irq_received);
39446+ atomic_read_unchecked(&cur_irq->irq_received);
39447 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39448 case VIA_IRQ_ABSOLUTE:
39449 break;
39450diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39451index 13aeda7..4a952d1 100644
39452--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39453+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39454@@ -290,7 +290,7 @@ struct vmw_private {
39455 * Fencing and IRQs.
39456 */
39457
39458- atomic_t marker_seq;
39459+ atomic_unchecked_t marker_seq;
39460 wait_queue_head_t fence_queue;
39461 wait_queue_head_t fifo_queue;
39462 int fence_queue_waiters; /* Protected by hw_mutex */
39463diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39464index 3eb1486..0a47ee9 100644
39465--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39466+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39467@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39468 (unsigned int) min,
39469 (unsigned int) fifo->capabilities);
39470
39471- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39472+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39473 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39474 vmw_marker_queue_init(&fifo->marker_queue);
39475 return vmw_fifo_send_fence(dev_priv, &dummy);
39476@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39477 if (reserveable)
39478 iowrite32(bytes, fifo_mem +
39479 SVGA_FIFO_RESERVED);
39480- return fifo_mem + (next_cmd >> 2);
39481+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39482 } else {
39483 need_bounce = true;
39484 }
39485@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39486
39487 fm = vmw_fifo_reserve(dev_priv, bytes);
39488 if (unlikely(fm == NULL)) {
39489- *seqno = atomic_read(&dev_priv->marker_seq);
39490+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39491 ret = -ENOMEM;
39492 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39493 false, 3*HZ);
39494@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39495 }
39496
39497 do {
39498- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39499+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39500 } while (*seqno == 0);
39501
39502 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39503diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39504index c509d40..3b640c3 100644
39505--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39506+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39507@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39508 int ret;
39509
39510 num_clips = arg->num_clips;
39511- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39512+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39513
39514 if (unlikely(num_clips == 0))
39515 return 0;
39516@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39517 int ret;
39518
39519 num_clips = arg->num_clips;
39520- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39521+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39522
39523 if (unlikely(num_clips == 0))
39524 return 0;
39525diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39526index 4640adb..e1384ed 100644
39527--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39528+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39529@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39530 * emitted. Then the fence is stale and signaled.
39531 */
39532
39533- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39534+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39535 > VMW_FENCE_WRAP);
39536
39537 return ret;
39538@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39539
39540 if (fifo_idle)
39541 down_read(&fifo_state->rwsem);
39542- signal_seq = atomic_read(&dev_priv->marker_seq);
39543+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39544 ret = 0;
39545
39546 for (;;) {
39547diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39548index 8a8725c2..afed796 100644
39549--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39550+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39551@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39552 while (!vmw_lag_lt(queue, us)) {
39553 spin_lock(&queue->lock);
39554 if (list_empty(&queue->head))
39555- seqno = atomic_read(&dev_priv->marker_seq);
39556+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39557 else {
39558 marker = list_first_entry(&queue->head,
39559 struct vmw_marker, head);
39560diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39561index 5360e5a..c2c0d26 100644
39562--- a/drivers/gpu/host1x/drm/dc.c
39563+++ b/drivers/gpu/host1x/drm/dc.c
39564@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39565 }
39566
39567 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39568- dc->debugfs_files[i].data = dc;
39569+ *(void **)&dc->debugfs_files[i].data = dc;
39570
39571 err = drm_debugfs_create_files(dc->debugfs_files,
39572 ARRAY_SIZE(debugfs_files),
39573diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39574index 9f60d63..c89e0b7 100644
39575--- a/drivers/hid/hid-core.c
39576+++ b/drivers/hid/hid-core.c
39577@@ -2370,7 +2370,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39578
39579 int hid_add_device(struct hid_device *hdev)
39580 {
39581- static atomic_t id = ATOMIC_INIT(0);
39582+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39583 int ret;
39584
39585 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39586@@ -2404,7 +2404,7 @@ int hid_add_device(struct hid_device *hdev)
39587 /* XXX hack, any other cleaner solution after the driver core
39588 * is converted to allow more than 20 bytes as the device name? */
39589 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39590- hdev->vendor, hdev->product, atomic_inc_return(&id));
39591+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39592
39593 hid_debug_register(hdev, dev_name(&hdev->dev));
39594 ret = device_add(&hdev->dev);
39595diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39596index c13fb5b..55a3802 100644
39597--- a/drivers/hid/hid-wiimote-debug.c
39598+++ b/drivers/hid/hid-wiimote-debug.c
39599@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39600 else if (size == 0)
39601 return -EIO;
39602
39603- if (copy_to_user(u, buf, size))
39604+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39605 return -EFAULT;
39606
39607 *off += size;
39608diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39609index 145a4cb..2353a3e 100644
39610--- a/drivers/hid/uhid.c
39611+++ b/drivers/hid/uhid.c
39612@@ -47,7 +47,7 @@ struct uhid_device {
39613 struct mutex report_lock;
39614 wait_queue_head_t report_wait;
39615 atomic_t report_done;
39616- atomic_t report_id;
39617+ atomic_unchecked_t report_id;
39618 struct uhid_event report_buf;
39619 };
39620
39621@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39622
39623 spin_lock_irqsave(&uhid->qlock, flags);
39624 ev->type = UHID_FEATURE;
39625- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39626+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39627 ev->u.feature.rnum = rnum;
39628 ev->u.feature.rtype = report_type;
39629
39630@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39631 spin_lock_irqsave(&uhid->qlock, flags);
39632
39633 /* id for old report; drop it silently */
39634- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39635+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39636 goto unlock;
39637 if (atomic_read(&uhid->report_done))
39638 goto unlock;
39639diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39640index 6de6c98..18319e9 100644
39641--- a/drivers/hv/channel.c
39642+++ b/drivers/hv/channel.c
39643@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39644 int ret = 0;
39645 int t;
39646
39647- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39648- atomic_inc(&vmbus_connection.next_gpadl_handle);
39649+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39650+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39651
39652 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39653 if (ret)
39654diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39655index 88f4096..e50452e 100644
39656--- a/drivers/hv/hv.c
39657+++ b/drivers/hv/hv.c
39658@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39659 u64 output_address = (output) ? virt_to_phys(output) : 0;
39660 u32 output_address_hi = output_address >> 32;
39661 u32 output_address_lo = output_address & 0xFFFFFFFF;
39662- void *hypercall_page = hv_context.hypercall_page;
39663+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39664
39665 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39666 "=a"(hv_status_lo) : "d" (control_hi),
39667diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39668index deb5c25..ed2d4fd 100644
39669--- a/drivers/hv/hv_balloon.c
39670+++ b/drivers/hv/hv_balloon.c
39671@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39672
39673 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39674 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39675-static atomic_t trans_id = ATOMIC_INIT(0);
39676+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39677
39678 static int dm_ring_size = (5 * PAGE_SIZE);
39679
39680@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39681 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39682 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39683 resp.hdr.size = sizeof(struct dm_hot_add_response);
39684- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39685+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39686
39687 #ifdef CONFIG_MEMORY_HOTPLUG
39688 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39689@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39690 memset(&status, 0, sizeof(struct dm_status));
39691 status.hdr.type = DM_STATUS_REPORT;
39692 status.hdr.size = sizeof(struct dm_status);
39693- status.hdr.trans_id = atomic_inc_return(&trans_id);
39694+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39695
39696 /*
39697 * The host expects the guest to report free memory.
39698@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39699 * send the status. This can happen if we were interrupted
39700 * after we picked our transaction ID.
39701 */
39702- if (status.hdr.trans_id != atomic_read(&trans_id))
39703+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39704 return;
39705
39706 vmbus_sendpacket(dm->dev->channel, &status,
39707@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39708 bl_resp = (struct dm_balloon_response *)send_buffer;
39709 memset(send_buffer, 0, PAGE_SIZE);
39710 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39711- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39712+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39713 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39714 bl_resp->more_pages = 1;
39715
39716@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39717
39718 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39719 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39720- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39721+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39722 resp.hdr.size = sizeof(struct dm_unballoon_response);
39723
39724 vmbus_sendpacket(dm_device.dev->channel, &resp,
39725@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39726 memset(&version_req, 0, sizeof(struct dm_version_request));
39727 version_req.hdr.type = DM_VERSION_REQUEST;
39728 version_req.hdr.size = sizeof(struct dm_version_request);
39729- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39730+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39731 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39732 version_req.is_last_attempt = 1;
39733
39734@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39735 memset(&version_req, 0, sizeof(struct dm_version_request));
39736 version_req.hdr.type = DM_VERSION_REQUEST;
39737 version_req.hdr.size = sizeof(struct dm_version_request);
39738- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39739+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39740 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39741 version_req.is_last_attempt = 0;
39742
39743@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39744 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39745 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39746 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39747- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39748+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39749
39750 cap_msg.caps.cap_bits.balloon = 1;
39751 cap_msg.caps.cap_bits.hot_add = 1;
39752diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39753index d84918f..7f38f9f 100644
39754--- a/drivers/hv/hyperv_vmbus.h
39755+++ b/drivers/hv/hyperv_vmbus.h
39756@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39757 struct vmbus_connection {
39758 enum vmbus_connect_state conn_state;
39759
39760- atomic_t next_gpadl_handle;
39761+ atomic_unchecked_t next_gpadl_handle;
39762
39763 /*
39764 * Represents channel interrupts. Each bit position represents a
39765diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39766index e8e071f..5b4b245 100644
39767--- a/drivers/hv/vmbus_drv.c
39768+++ b/drivers/hv/vmbus_drv.c
39769@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39770 {
39771 int ret = 0;
39772
39773- static atomic_t device_num = ATOMIC_INIT(0);
39774+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39775
39776 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39777- atomic_inc_return(&device_num));
39778+ atomic_inc_return_unchecked(&device_num));
39779
39780 child_device_obj->device.bus = &hv_bus;
39781 child_device_obj->device.parent = &hv_acpi_dev->dev;
39782diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39783index 6351aba..dc4aaf4 100644
39784--- a/drivers/hwmon/acpi_power_meter.c
39785+++ b/drivers/hwmon/acpi_power_meter.c
39786@@ -117,7 +117,7 @@ struct sensor_template {
39787 struct device_attribute *devattr,
39788 const char *buf, size_t count);
39789 int index;
39790-};
39791+} __do_const;
39792
39793 /* Averaging interval */
39794 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39795@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39796 struct sensor_template *attrs)
39797 {
39798 struct device *dev = &resource->acpi_dev->dev;
39799- struct sensor_device_attribute *sensors =
39800+ sensor_device_attribute_no_const *sensors =
39801 &resource->sensors[resource->num_sensors];
39802 int res = 0;
39803
39804diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39805index 3288f13..71cfb4e 100644
39806--- a/drivers/hwmon/applesmc.c
39807+++ b/drivers/hwmon/applesmc.c
39808@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39809 {
39810 struct applesmc_node_group *grp;
39811 struct applesmc_dev_attr *node;
39812- struct attribute *attr;
39813+ attribute_no_const *attr;
39814 int ret, i;
39815
39816 for (grp = groups; grp->format; grp++) {
39817diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39818index b25c643..a13460d 100644
39819--- a/drivers/hwmon/asus_atk0110.c
39820+++ b/drivers/hwmon/asus_atk0110.c
39821@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39822 struct atk_sensor_data {
39823 struct list_head list;
39824 struct atk_data *data;
39825- struct device_attribute label_attr;
39826- struct device_attribute input_attr;
39827- struct device_attribute limit1_attr;
39828- struct device_attribute limit2_attr;
39829+ device_attribute_no_const label_attr;
39830+ device_attribute_no_const input_attr;
39831+ device_attribute_no_const limit1_attr;
39832+ device_attribute_no_const limit2_attr;
39833 char label_attr_name[ATTR_NAME_SIZE];
39834 char input_attr_name[ATTR_NAME_SIZE];
39835 char limit1_attr_name[ATTR_NAME_SIZE];
39836@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39837 static struct device_attribute atk_name_attr =
39838 __ATTR(name, 0444, atk_name_show, NULL);
39839
39840-static void atk_init_attribute(struct device_attribute *attr, char *name,
39841+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39842 sysfs_show_func show)
39843 {
39844 sysfs_attr_init(&attr->attr);
39845diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39846index 2e5e2dc..5208b31 100644
39847--- a/drivers/hwmon/coretemp.c
39848+++ b/drivers/hwmon/coretemp.c
39849@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39850 return NOTIFY_OK;
39851 }
39852
39853-static struct notifier_block coretemp_cpu_notifier __refdata = {
39854+static struct notifier_block coretemp_cpu_notifier = {
39855 .notifier_call = coretemp_cpu_callback,
39856 };
39857
39858diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39859index 1429f6e..ee03d59 100644
39860--- a/drivers/hwmon/ibmaem.c
39861+++ b/drivers/hwmon/ibmaem.c
39862@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39863 struct aem_rw_sensor_template *rw)
39864 {
39865 struct device *dev = &data->pdev->dev;
39866- struct sensor_device_attribute *sensors = data->sensors;
39867+ sensor_device_attribute_no_const *sensors = data->sensors;
39868 int err;
39869
39870 /* Set up read-only sensors */
39871diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39872index 708081b..fe2d4ab 100644
39873--- a/drivers/hwmon/iio_hwmon.c
39874+++ b/drivers/hwmon/iio_hwmon.c
39875@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39876 {
39877 struct device *dev = &pdev->dev;
39878 struct iio_hwmon_state *st;
39879- struct sensor_device_attribute *a;
39880+ sensor_device_attribute_no_const *a;
39881 int ret, i;
39882 int in_i = 1, temp_i = 1, curr_i = 1;
39883 enum iio_chan_type type;
39884diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39885index 9add6092..ee7ba3f 100644
39886--- a/drivers/hwmon/pmbus/pmbus_core.c
39887+++ b/drivers/hwmon/pmbus/pmbus_core.c
39888@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39889 return 0;
39890 }
39891
39892-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39893+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39894 const char *name,
39895 umode_t mode,
39896 ssize_t (*show)(struct device *dev,
39897@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39898 dev_attr->store = store;
39899 }
39900
39901-static void pmbus_attr_init(struct sensor_device_attribute *a,
39902+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39903 const char *name,
39904 umode_t mode,
39905 ssize_t (*show)(struct device *dev,
39906@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39907 u16 reg, u8 mask)
39908 {
39909 struct pmbus_boolean *boolean;
39910- struct sensor_device_attribute *a;
39911+ sensor_device_attribute_no_const *a;
39912
39913 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39914 if (!boolean)
39915@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39916 bool update, bool readonly)
39917 {
39918 struct pmbus_sensor *sensor;
39919- struct device_attribute *a;
39920+ device_attribute_no_const *a;
39921
39922 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39923 if (!sensor)
39924@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39925 const char *lstring, int index)
39926 {
39927 struct pmbus_label *label;
39928- struct device_attribute *a;
39929+ device_attribute_no_const *a;
39930
39931 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39932 if (!label)
39933diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39934index 2507f90..1645765 100644
39935--- a/drivers/hwmon/sht15.c
39936+++ b/drivers/hwmon/sht15.c
39937@@ -169,7 +169,7 @@ struct sht15_data {
39938 int supply_uv;
39939 bool supply_uv_valid;
39940 struct work_struct update_supply_work;
39941- atomic_t interrupt_handled;
39942+ atomic_unchecked_t interrupt_handled;
39943 };
39944
39945 /**
39946@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39947 ret = gpio_direction_input(data->pdata->gpio_data);
39948 if (ret)
39949 return ret;
39950- atomic_set(&data->interrupt_handled, 0);
39951+ atomic_set_unchecked(&data->interrupt_handled, 0);
39952
39953 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39954 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39955 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39956 /* Only relevant if the interrupt hasn't occurred. */
39957- if (!atomic_read(&data->interrupt_handled))
39958+ if (!atomic_read_unchecked(&data->interrupt_handled))
39959 schedule_work(&data->read_work);
39960 }
39961 ret = wait_event_timeout(data->wait_queue,
39962@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
39963
39964 /* First disable the interrupt */
39965 disable_irq_nosync(irq);
39966- atomic_inc(&data->interrupt_handled);
39967+ atomic_inc_unchecked(&data->interrupt_handled);
39968 /* Then schedule a reading work struct */
39969 if (data->state != SHT15_READING_NOTHING)
39970 schedule_work(&data->read_work);
39971@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
39972 * If not, then start the interrupt again - care here as could
39973 * have gone low in meantime so verify it hasn't!
39974 */
39975- atomic_set(&data->interrupt_handled, 0);
39976+ atomic_set_unchecked(&data->interrupt_handled, 0);
39977 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39978 /* If still not occurred or another handler was scheduled */
39979 if (gpio_get_value(data->pdata->gpio_data)
39980- || atomic_read(&data->interrupt_handled))
39981+ || atomic_read_unchecked(&data->interrupt_handled))
39982 return;
39983 }
39984
39985diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
39986index 38944e9..ae9e5ed 100644
39987--- a/drivers/hwmon/via-cputemp.c
39988+++ b/drivers/hwmon/via-cputemp.c
39989@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
39990 return NOTIFY_OK;
39991 }
39992
39993-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
39994+static struct notifier_block via_cputemp_cpu_notifier = {
39995 .notifier_call = via_cputemp_cpu_callback,
39996 };
39997
39998diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
39999index 07f01ac..d79ad3d 100644
40000--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40001+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40002@@ -43,7 +43,7 @@
40003 extern struct i2c_adapter amd756_smbus;
40004
40005 static struct i2c_adapter *s4882_adapter;
40006-static struct i2c_algorithm *s4882_algo;
40007+static i2c_algorithm_no_const *s4882_algo;
40008
40009 /* Wrapper access functions for multiplexed SMBus */
40010 static DEFINE_MUTEX(amd756_lock);
40011diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40012index 2ca268d..c6acbdf 100644
40013--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40014+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40015@@ -41,7 +41,7 @@
40016 extern struct i2c_adapter *nforce2_smbus;
40017
40018 static struct i2c_adapter *s4985_adapter;
40019-static struct i2c_algorithm *s4985_algo;
40020+static i2c_algorithm_no_const *s4985_algo;
40021
40022 /* Wrapper access functions for multiplexed SMBus */
40023 static DEFINE_MUTEX(nforce2_lock);
40024diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40025index c3ccdea..5b3dc1a 100644
40026--- a/drivers/i2c/i2c-dev.c
40027+++ b/drivers/i2c/i2c-dev.c
40028@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40029 break;
40030 }
40031
40032- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40033+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40034 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40035 if (IS_ERR(rdwr_pa[i].buf)) {
40036 res = PTR_ERR(rdwr_pa[i].buf);
40037diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40038index 0b510ba..4fbb5085 100644
40039--- a/drivers/ide/ide-cd.c
40040+++ b/drivers/ide/ide-cd.c
40041@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40042 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40043 if ((unsigned long)buf & alignment
40044 || blk_rq_bytes(rq) & q->dma_pad_mask
40045- || object_is_on_stack(buf))
40046+ || object_starts_on_stack(buf))
40047 drive->dma = 0;
40048 }
40049 }
40050diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40051index e145931..08bfc59 100644
40052--- a/drivers/iio/industrialio-core.c
40053+++ b/drivers/iio/industrialio-core.c
40054@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40055 }
40056
40057 static
40058-int __iio_device_attr_init(struct device_attribute *dev_attr,
40059+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40060 const char *postfix,
40061 struct iio_chan_spec const *chan,
40062 ssize_t (*readfunc)(struct device *dev,
40063diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40064index 784b97c..c9ceadf 100644
40065--- a/drivers/infiniband/core/cm.c
40066+++ b/drivers/infiniband/core/cm.c
40067@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40068
40069 struct cm_counter_group {
40070 struct kobject obj;
40071- atomic_long_t counter[CM_ATTR_COUNT];
40072+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40073 };
40074
40075 struct cm_counter_attribute {
40076@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40077 struct ib_mad_send_buf *msg = NULL;
40078 int ret;
40079
40080- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40081+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40082 counter[CM_REQ_COUNTER]);
40083
40084 /* Quick state check to discard duplicate REQs. */
40085@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40086 if (!cm_id_priv)
40087 return;
40088
40089- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40090+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40091 counter[CM_REP_COUNTER]);
40092 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40093 if (ret)
40094@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40095 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40096 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40097 spin_unlock_irq(&cm_id_priv->lock);
40098- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40099+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40100 counter[CM_RTU_COUNTER]);
40101 goto out;
40102 }
40103@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40104 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40105 dreq_msg->local_comm_id);
40106 if (!cm_id_priv) {
40107- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40108+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40109 counter[CM_DREQ_COUNTER]);
40110 cm_issue_drep(work->port, work->mad_recv_wc);
40111 return -EINVAL;
40112@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40113 case IB_CM_MRA_REP_RCVD:
40114 break;
40115 case IB_CM_TIMEWAIT:
40116- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40117+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40118 counter[CM_DREQ_COUNTER]);
40119 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40120 goto unlock;
40121@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40122 cm_free_msg(msg);
40123 goto deref;
40124 case IB_CM_DREQ_RCVD:
40125- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40126+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40127 counter[CM_DREQ_COUNTER]);
40128 goto unlock;
40129 default:
40130@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40131 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40132 cm_id_priv->msg, timeout)) {
40133 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40134- atomic_long_inc(&work->port->
40135+ atomic_long_inc_unchecked(&work->port->
40136 counter_group[CM_RECV_DUPLICATES].
40137 counter[CM_MRA_COUNTER]);
40138 goto out;
40139@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40140 break;
40141 case IB_CM_MRA_REQ_RCVD:
40142 case IB_CM_MRA_REP_RCVD:
40143- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40144+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40145 counter[CM_MRA_COUNTER]);
40146 /* fall through */
40147 default:
40148@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40149 case IB_CM_LAP_IDLE:
40150 break;
40151 case IB_CM_MRA_LAP_SENT:
40152- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40153+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40154 counter[CM_LAP_COUNTER]);
40155 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40156 goto unlock;
40157@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40158 cm_free_msg(msg);
40159 goto deref;
40160 case IB_CM_LAP_RCVD:
40161- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40162+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40163 counter[CM_LAP_COUNTER]);
40164 goto unlock;
40165 default:
40166@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40167 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40168 if (cur_cm_id_priv) {
40169 spin_unlock_irq(&cm.lock);
40170- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40171+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40172 counter[CM_SIDR_REQ_COUNTER]);
40173 goto out; /* Duplicate message. */
40174 }
40175@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40176 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40177 msg->retries = 1;
40178
40179- atomic_long_add(1 + msg->retries,
40180+ atomic_long_add_unchecked(1 + msg->retries,
40181 &port->counter_group[CM_XMIT].counter[attr_index]);
40182 if (msg->retries)
40183- atomic_long_add(msg->retries,
40184+ atomic_long_add_unchecked(msg->retries,
40185 &port->counter_group[CM_XMIT_RETRIES].
40186 counter[attr_index]);
40187
40188@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40189 }
40190
40191 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40192- atomic_long_inc(&port->counter_group[CM_RECV].
40193+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40194 counter[attr_id - CM_ATTR_ID_OFFSET]);
40195
40196 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40197@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40198 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40199
40200 return sprintf(buf, "%ld\n",
40201- atomic_long_read(&group->counter[cm_attr->index]));
40202+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40203 }
40204
40205 static const struct sysfs_ops cm_counter_ops = {
40206diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40207index 9f5ad7c..588cd84 100644
40208--- a/drivers/infiniband/core/fmr_pool.c
40209+++ b/drivers/infiniband/core/fmr_pool.c
40210@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40211
40212 struct task_struct *thread;
40213
40214- atomic_t req_ser;
40215- atomic_t flush_ser;
40216+ atomic_unchecked_t req_ser;
40217+ atomic_unchecked_t flush_ser;
40218
40219 wait_queue_head_t force_wait;
40220 };
40221@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40222 struct ib_fmr_pool *pool = pool_ptr;
40223
40224 do {
40225- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40226+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40227 ib_fmr_batch_release(pool);
40228
40229- atomic_inc(&pool->flush_ser);
40230+ atomic_inc_unchecked(&pool->flush_ser);
40231 wake_up_interruptible(&pool->force_wait);
40232
40233 if (pool->flush_function)
40234@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40235 }
40236
40237 set_current_state(TASK_INTERRUPTIBLE);
40238- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40239+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40240 !kthread_should_stop())
40241 schedule();
40242 __set_current_state(TASK_RUNNING);
40243@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40244 pool->dirty_watermark = params->dirty_watermark;
40245 pool->dirty_len = 0;
40246 spin_lock_init(&pool->pool_lock);
40247- atomic_set(&pool->req_ser, 0);
40248- atomic_set(&pool->flush_ser, 0);
40249+ atomic_set_unchecked(&pool->req_ser, 0);
40250+ atomic_set_unchecked(&pool->flush_ser, 0);
40251 init_waitqueue_head(&pool->force_wait);
40252
40253 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40254@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40255 }
40256 spin_unlock_irq(&pool->pool_lock);
40257
40258- serial = atomic_inc_return(&pool->req_ser);
40259+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40260 wake_up_process(pool->thread);
40261
40262 if (wait_event_interruptible(pool->force_wait,
40263- atomic_read(&pool->flush_ser) - serial >= 0))
40264+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40265 return -EINTR;
40266
40267 return 0;
40268@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40269 } else {
40270 list_add_tail(&fmr->list, &pool->dirty_list);
40271 if (++pool->dirty_len >= pool->dirty_watermark) {
40272- atomic_inc(&pool->req_ser);
40273+ atomic_inc_unchecked(&pool->req_ser);
40274 wake_up_process(pool->thread);
40275 }
40276 }
40277diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40278index 4cb8eb2..146bf60 100644
40279--- a/drivers/infiniband/hw/cxgb4/mem.c
40280+++ b/drivers/infiniband/hw/cxgb4/mem.c
40281@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40282 int err;
40283 struct fw_ri_tpte tpt;
40284 u32 stag_idx;
40285- static atomic_t key;
40286+ static atomic_unchecked_t key;
40287
40288 if (c4iw_fatal_error(rdev))
40289 return -EIO;
40290@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40291 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40292 rdev->stats.stag.max = rdev->stats.stag.cur;
40293 mutex_unlock(&rdev->stats.lock);
40294- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40295+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40296 }
40297 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40298 __func__, stag_state, type, pdid, stag_idx);
40299diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40300index 79b3dbc..96e5fcc 100644
40301--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40302+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40303@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40304 struct ib_atomic_eth *ateth;
40305 struct ipath_ack_entry *e;
40306 u64 vaddr;
40307- atomic64_t *maddr;
40308+ atomic64_unchecked_t *maddr;
40309 u64 sdata;
40310 u32 rkey;
40311 u8 next;
40312@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40313 IB_ACCESS_REMOTE_ATOMIC)))
40314 goto nack_acc_unlck;
40315 /* Perform atomic OP and save result. */
40316- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40317+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40318 sdata = be64_to_cpu(ateth->swap_data);
40319 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40320 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40321- (u64) atomic64_add_return(sdata, maddr) - sdata :
40322+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40323 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40324 be64_to_cpu(ateth->compare_data),
40325 sdata);
40326diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40327index 1f95bba..9530f87 100644
40328--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40329+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40330@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40331 unsigned long flags;
40332 struct ib_wc wc;
40333 u64 sdata;
40334- atomic64_t *maddr;
40335+ atomic64_unchecked_t *maddr;
40336 enum ib_wc_status send_status;
40337
40338 /*
40339@@ -382,11 +382,11 @@ again:
40340 IB_ACCESS_REMOTE_ATOMIC)))
40341 goto acc_err;
40342 /* Perform atomic OP and save result. */
40343- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40344+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40345 sdata = wqe->wr.wr.atomic.compare_add;
40346 *(u64 *) sqp->s_sge.sge.vaddr =
40347 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40348- (u64) atomic64_add_return(sdata, maddr) - sdata :
40349+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40350 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40351 sdata, wqe->wr.wr.atomic.swap);
40352 goto send_comp;
40353diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40354index f2a3f48..673ec79 100644
40355--- a/drivers/infiniband/hw/mlx4/mad.c
40356+++ b/drivers/infiniband/hw/mlx4/mad.c
40357@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40358
40359 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40360 {
40361- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40362+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40363 cpu_to_be64(0xff00000000000000LL);
40364 }
40365
40366diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40367index 25b2cdf..099ff97 100644
40368--- a/drivers/infiniband/hw/mlx4/mcg.c
40369+++ b/drivers/infiniband/hw/mlx4/mcg.c
40370@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40371 {
40372 char name[20];
40373
40374- atomic_set(&ctx->tid, 0);
40375+ atomic_set_unchecked(&ctx->tid, 0);
40376 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40377 ctx->mcg_wq = create_singlethread_workqueue(name);
40378 if (!ctx->mcg_wq)
40379diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40380index f61ec26..ebf72cf 100644
40381--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40382+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40383@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40384 struct list_head mcg_mgid0_list;
40385 struct workqueue_struct *mcg_wq;
40386 struct mlx4_ib_demux_pv_ctx **tun;
40387- atomic_t tid;
40388+ atomic_unchecked_t tid;
40389 int flushing; /* flushing the work queue */
40390 };
40391
40392diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40393index 9d3e5c1..d9afe4a 100644
40394--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40395+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40396@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40397 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40398 }
40399
40400-int mthca_QUERY_FW(struct mthca_dev *dev)
40401+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40402 {
40403 struct mthca_mailbox *mailbox;
40404 u32 *outbox;
40405diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40406index ed9a989..e0c5871 100644
40407--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40408+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40409@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40410 return key;
40411 }
40412
40413-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40414+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40415 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40416 {
40417 struct mthca_mailbox *mailbox;
40418diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40419index 4291410..d2ab1fb 100644
40420--- a/drivers/infiniband/hw/nes/nes.c
40421+++ b/drivers/infiniband/hw/nes/nes.c
40422@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40423 LIST_HEAD(nes_adapter_list);
40424 static LIST_HEAD(nes_dev_list);
40425
40426-atomic_t qps_destroyed;
40427+atomic_unchecked_t qps_destroyed;
40428
40429 static unsigned int ee_flsh_adapter;
40430 static unsigned int sysfs_nonidx_addr;
40431@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40432 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40433 struct nes_adapter *nesadapter = nesdev->nesadapter;
40434
40435- atomic_inc(&qps_destroyed);
40436+ atomic_inc_unchecked(&qps_destroyed);
40437
40438 /* Free the control structures */
40439
40440diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40441index 33cc589..3bd6538 100644
40442--- a/drivers/infiniband/hw/nes/nes.h
40443+++ b/drivers/infiniband/hw/nes/nes.h
40444@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40445 extern unsigned int wqm_quanta;
40446 extern struct list_head nes_adapter_list;
40447
40448-extern atomic_t cm_connects;
40449-extern atomic_t cm_accepts;
40450-extern atomic_t cm_disconnects;
40451-extern atomic_t cm_closes;
40452-extern atomic_t cm_connecteds;
40453-extern atomic_t cm_connect_reqs;
40454-extern atomic_t cm_rejects;
40455-extern atomic_t mod_qp_timouts;
40456-extern atomic_t qps_created;
40457-extern atomic_t qps_destroyed;
40458-extern atomic_t sw_qps_destroyed;
40459+extern atomic_unchecked_t cm_connects;
40460+extern atomic_unchecked_t cm_accepts;
40461+extern atomic_unchecked_t cm_disconnects;
40462+extern atomic_unchecked_t cm_closes;
40463+extern atomic_unchecked_t cm_connecteds;
40464+extern atomic_unchecked_t cm_connect_reqs;
40465+extern atomic_unchecked_t cm_rejects;
40466+extern atomic_unchecked_t mod_qp_timouts;
40467+extern atomic_unchecked_t qps_created;
40468+extern atomic_unchecked_t qps_destroyed;
40469+extern atomic_unchecked_t sw_qps_destroyed;
40470 extern u32 mh_detected;
40471 extern u32 mh_pauses_sent;
40472 extern u32 cm_packets_sent;
40473@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40474 extern u32 cm_packets_received;
40475 extern u32 cm_packets_dropped;
40476 extern u32 cm_packets_retrans;
40477-extern atomic_t cm_listens_created;
40478-extern atomic_t cm_listens_destroyed;
40479+extern atomic_unchecked_t cm_listens_created;
40480+extern atomic_unchecked_t cm_listens_destroyed;
40481 extern u32 cm_backlog_drops;
40482-extern atomic_t cm_loopbacks;
40483-extern atomic_t cm_nodes_created;
40484-extern atomic_t cm_nodes_destroyed;
40485-extern atomic_t cm_accel_dropped_pkts;
40486-extern atomic_t cm_resets_recvd;
40487-extern atomic_t pau_qps_created;
40488-extern atomic_t pau_qps_destroyed;
40489+extern atomic_unchecked_t cm_loopbacks;
40490+extern atomic_unchecked_t cm_nodes_created;
40491+extern atomic_unchecked_t cm_nodes_destroyed;
40492+extern atomic_unchecked_t cm_accel_dropped_pkts;
40493+extern atomic_unchecked_t cm_resets_recvd;
40494+extern atomic_unchecked_t pau_qps_created;
40495+extern atomic_unchecked_t pau_qps_destroyed;
40496
40497 extern u32 int_mod_timer_init;
40498 extern u32 int_mod_cq_depth_256;
40499diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40500index 24b9f1a..00fd004 100644
40501--- a/drivers/infiniband/hw/nes/nes_cm.c
40502+++ b/drivers/infiniband/hw/nes/nes_cm.c
40503@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40504 u32 cm_packets_retrans;
40505 u32 cm_packets_created;
40506 u32 cm_packets_received;
40507-atomic_t cm_listens_created;
40508-atomic_t cm_listens_destroyed;
40509+atomic_unchecked_t cm_listens_created;
40510+atomic_unchecked_t cm_listens_destroyed;
40511 u32 cm_backlog_drops;
40512-atomic_t cm_loopbacks;
40513-atomic_t cm_nodes_created;
40514-atomic_t cm_nodes_destroyed;
40515-atomic_t cm_accel_dropped_pkts;
40516-atomic_t cm_resets_recvd;
40517+atomic_unchecked_t cm_loopbacks;
40518+atomic_unchecked_t cm_nodes_created;
40519+atomic_unchecked_t cm_nodes_destroyed;
40520+atomic_unchecked_t cm_accel_dropped_pkts;
40521+atomic_unchecked_t cm_resets_recvd;
40522
40523 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40524 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40525@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40526
40527 static struct nes_cm_core *g_cm_core;
40528
40529-atomic_t cm_connects;
40530-atomic_t cm_accepts;
40531-atomic_t cm_disconnects;
40532-atomic_t cm_closes;
40533-atomic_t cm_connecteds;
40534-atomic_t cm_connect_reqs;
40535-atomic_t cm_rejects;
40536+atomic_unchecked_t cm_connects;
40537+atomic_unchecked_t cm_accepts;
40538+atomic_unchecked_t cm_disconnects;
40539+atomic_unchecked_t cm_closes;
40540+atomic_unchecked_t cm_connecteds;
40541+atomic_unchecked_t cm_connect_reqs;
40542+atomic_unchecked_t cm_rejects;
40543
40544 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40545 {
40546@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40547 kfree(listener);
40548 listener = NULL;
40549 ret = 0;
40550- atomic_inc(&cm_listens_destroyed);
40551+ atomic_inc_unchecked(&cm_listens_destroyed);
40552 } else {
40553 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40554 }
40555@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40556 cm_node->rem_mac);
40557
40558 add_hte_node(cm_core, cm_node);
40559- atomic_inc(&cm_nodes_created);
40560+ atomic_inc_unchecked(&cm_nodes_created);
40561
40562 return cm_node;
40563 }
40564@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40565 }
40566
40567 atomic_dec(&cm_core->node_cnt);
40568- atomic_inc(&cm_nodes_destroyed);
40569+ atomic_inc_unchecked(&cm_nodes_destroyed);
40570 nesqp = cm_node->nesqp;
40571 if (nesqp) {
40572 nesqp->cm_node = NULL;
40573@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40574
40575 static void drop_packet(struct sk_buff *skb)
40576 {
40577- atomic_inc(&cm_accel_dropped_pkts);
40578+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40579 dev_kfree_skb_any(skb);
40580 }
40581
40582@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40583 {
40584
40585 int reset = 0; /* whether to send reset in case of err.. */
40586- atomic_inc(&cm_resets_recvd);
40587+ atomic_inc_unchecked(&cm_resets_recvd);
40588 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40589 " refcnt=%d\n", cm_node, cm_node->state,
40590 atomic_read(&cm_node->ref_count));
40591@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40592 rem_ref_cm_node(cm_node->cm_core, cm_node);
40593 return NULL;
40594 }
40595- atomic_inc(&cm_loopbacks);
40596+ atomic_inc_unchecked(&cm_loopbacks);
40597 loopbackremotenode->loopbackpartner = cm_node;
40598 loopbackremotenode->tcp_cntxt.rcv_wscale =
40599 NES_CM_DEFAULT_RCV_WND_SCALE;
40600@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40601 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40602 else {
40603 rem_ref_cm_node(cm_core, cm_node);
40604- atomic_inc(&cm_accel_dropped_pkts);
40605+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40606 dev_kfree_skb_any(skb);
40607 }
40608 break;
40609@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40610
40611 if ((cm_id) && (cm_id->event_handler)) {
40612 if (issue_disconn) {
40613- atomic_inc(&cm_disconnects);
40614+ atomic_inc_unchecked(&cm_disconnects);
40615 cm_event.event = IW_CM_EVENT_DISCONNECT;
40616 cm_event.status = disconn_status;
40617 cm_event.local_addr = cm_id->local_addr;
40618@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40619 }
40620
40621 if (issue_close) {
40622- atomic_inc(&cm_closes);
40623+ atomic_inc_unchecked(&cm_closes);
40624 nes_disconnect(nesqp, 1);
40625
40626 cm_id->provider_data = nesqp;
40627@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40628
40629 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40630 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40631- atomic_inc(&cm_accepts);
40632+ atomic_inc_unchecked(&cm_accepts);
40633
40634 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40635 netdev_refcnt_read(nesvnic->netdev));
40636@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40637 struct nes_cm_core *cm_core;
40638 u8 *start_buff;
40639
40640- atomic_inc(&cm_rejects);
40641+ atomic_inc_unchecked(&cm_rejects);
40642 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40643 loopback = cm_node->loopbackpartner;
40644 cm_core = cm_node->cm_core;
40645@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40646 ntohl(cm_id->local_addr.sin_addr.s_addr),
40647 ntohs(cm_id->local_addr.sin_port));
40648
40649- atomic_inc(&cm_connects);
40650+ atomic_inc_unchecked(&cm_connects);
40651 nesqp->active_conn = 1;
40652
40653 /* cache the cm_id in the qp */
40654@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40655 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40656 return err;
40657 }
40658- atomic_inc(&cm_listens_created);
40659+ atomic_inc_unchecked(&cm_listens_created);
40660 }
40661
40662 cm_id->add_ref(cm_id);
40663@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40664
40665 if (nesqp->destroyed)
40666 return;
40667- atomic_inc(&cm_connecteds);
40668+ atomic_inc_unchecked(&cm_connecteds);
40669 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40670 " local port 0x%04X. jiffies = %lu.\n",
40671 nesqp->hwqp.qp_id,
40672@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40673
40674 cm_id->add_ref(cm_id);
40675 ret = cm_id->event_handler(cm_id, &cm_event);
40676- atomic_inc(&cm_closes);
40677+ atomic_inc_unchecked(&cm_closes);
40678 cm_event.event = IW_CM_EVENT_CLOSE;
40679 cm_event.status = 0;
40680 cm_event.provider_data = cm_id->provider_data;
40681@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40682 return;
40683 cm_id = cm_node->cm_id;
40684
40685- atomic_inc(&cm_connect_reqs);
40686+ atomic_inc_unchecked(&cm_connect_reqs);
40687 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40688 cm_node, cm_id, jiffies);
40689
40690@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40691 return;
40692 cm_id = cm_node->cm_id;
40693
40694- atomic_inc(&cm_connect_reqs);
40695+ atomic_inc_unchecked(&cm_connect_reqs);
40696 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40697 cm_node, cm_id, jiffies);
40698
40699diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40700index 4166452..fc952c3 100644
40701--- a/drivers/infiniband/hw/nes/nes_mgt.c
40702+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40703@@ -40,8 +40,8 @@
40704 #include "nes.h"
40705 #include "nes_mgt.h"
40706
40707-atomic_t pau_qps_created;
40708-atomic_t pau_qps_destroyed;
40709+atomic_unchecked_t pau_qps_created;
40710+atomic_unchecked_t pau_qps_destroyed;
40711
40712 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40713 {
40714@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40715 {
40716 struct sk_buff *skb;
40717 unsigned long flags;
40718- atomic_inc(&pau_qps_destroyed);
40719+ atomic_inc_unchecked(&pau_qps_destroyed);
40720
40721 /* Free packets that have not yet been forwarded */
40722 /* Lock is acquired by skb_dequeue when removing the skb */
40723@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40724 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40725 skb_queue_head_init(&nesqp->pau_list);
40726 spin_lock_init(&nesqp->pau_lock);
40727- atomic_inc(&pau_qps_created);
40728+ atomic_inc_unchecked(&pau_qps_created);
40729 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40730 }
40731
40732diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40733index 49eb511..a774366 100644
40734--- a/drivers/infiniband/hw/nes/nes_nic.c
40735+++ b/drivers/infiniband/hw/nes/nes_nic.c
40736@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40737 target_stat_values[++index] = mh_detected;
40738 target_stat_values[++index] = mh_pauses_sent;
40739 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40740- target_stat_values[++index] = atomic_read(&cm_connects);
40741- target_stat_values[++index] = atomic_read(&cm_accepts);
40742- target_stat_values[++index] = atomic_read(&cm_disconnects);
40743- target_stat_values[++index] = atomic_read(&cm_connecteds);
40744- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40745- target_stat_values[++index] = atomic_read(&cm_rejects);
40746- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40747- target_stat_values[++index] = atomic_read(&qps_created);
40748- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40749- target_stat_values[++index] = atomic_read(&qps_destroyed);
40750- target_stat_values[++index] = atomic_read(&cm_closes);
40751+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40752+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40753+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40754+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40755+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40756+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40757+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40758+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40759+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40760+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40761+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40762 target_stat_values[++index] = cm_packets_sent;
40763 target_stat_values[++index] = cm_packets_bounced;
40764 target_stat_values[++index] = cm_packets_created;
40765 target_stat_values[++index] = cm_packets_received;
40766 target_stat_values[++index] = cm_packets_dropped;
40767 target_stat_values[++index] = cm_packets_retrans;
40768- target_stat_values[++index] = atomic_read(&cm_listens_created);
40769- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40770+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40771+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40772 target_stat_values[++index] = cm_backlog_drops;
40773- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40774- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40775- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40776- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40777- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40778+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40779+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40780+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40781+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40782+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40783 target_stat_values[++index] = nesadapter->free_4kpbl;
40784 target_stat_values[++index] = nesadapter->free_256pbl;
40785 target_stat_values[++index] = int_mod_timer_init;
40786 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40787 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40788 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40789- target_stat_values[++index] = atomic_read(&pau_qps_created);
40790- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40791+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40792+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40793 }
40794
40795 /**
40796diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40797index 5b53ca5..443da3c 100644
40798--- a/drivers/infiniband/hw/nes/nes_verbs.c
40799+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40800@@ -46,9 +46,9 @@
40801
40802 #include <rdma/ib_umem.h>
40803
40804-atomic_t mod_qp_timouts;
40805-atomic_t qps_created;
40806-atomic_t sw_qps_destroyed;
40807+atomic_unchecked_t mod_qp_timouts;
40808+atomic_unchecked_t qps_created;
40809+atomic_unchecked_t sw_qps_destroyed;
40810
40811 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40812
40813@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40814 if (init_attr->create_flags)
40815 return ERR_PTR(-EINVAL);
40816
40817- atomic_inc(&qps_created);
40818+ atomic_inc_unchecked(&qps_created);
40819 switch (init_attr->qp_type) {
40820 case IB_QPT_RC:
40821 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40822@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40823 struct iw_cm_event cm_event;
40824 int ret = 0;
40825
40826- atomic_inc(&sw_qps_destroyed);
40827+ atomic_inc_unchecked(&sw_qps_destroyed);
40828 nesqp->destroyed = 1;
40829
40830 /* Blow away the connection if it exists. */
40831diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40832index 4a9af79..b993f75 100644
40833--- a/drivers/infiniband/hw/qib/qib.h
40834+++ b/drivers/infiniband/hw/qib/qib.h
40835@@ -52,6 +52,7 @@
40836 #include <linux/kref.h>
40837 #include <linux/sched.h>
40838 #include <linux/kthread.h>
40839+#include <linux/slab.h>
40840
40841 #include "qib_common.h"
40842 #include "qib_verbs.h"
40843diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40844index da739d9..da1c7f4 100644
40845--- a/drivers/input/gameport/gameport.c
40846+++ b/drivers/input/gameport/gameport.c
40847@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40848 */
40849 static void gameport_init_port(struct gameport *gameport)
40850 {
40851- static atomic_t gameport_no = ATOMIC_INIT(0);
40852+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40853
40854 __module_get(THIS_MODULE);
40855
40856 mutex_init(&gameport->drv_mutex);
40857 device_initialize(&gameport->dev);
40858 dev_set_name(&gameport->dev, "gameport%lu",
40859- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40860+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40861 gameport->dev.bus = &gameport_bus;
40862 gameport->dev.release = gameport_release_port;
40863 if (gameport->parent)
40864diff --git a/drivers/input/input.c b/drivers/input/input.c
40865index c044699..174d71a 100644
40866--- a/drivers/input/input.c
40867+++ b/drivers/input/input.c
40868@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
40869 */
40870 int input_register_device(struct input_dev *dev)
40871 {
40872- static atomic_t input_no = ATOMIC_INIT(0);
40873+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40874 struct input_devres *devres = NULL;
40875 struct input_handler *handler;
40876 unsigned int packet_size;
40877@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
40878 dev->setkeycode = input_default_setkeycode;
40879
40880 dev_set_name(&dev->dev, "input%ld",
40881- (unsigned long) atomic_inc_return(&input_no) - 1);
40882+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40883
40884 error = device_add(&dev->dev);
40885 if (error)
40886diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40887index 04c69af..5f92d00 100644
40888--- a/drivers/input/joystick/sidewinder.c
40889+++ b/drivers/input/joystick/sidewinder.c
40890@@ -30,6 +30,7 @@
40891 #include <linux/kernel.h>
40892 #include <linux/module.h>
40893 #include <linux/slab.h>
40894+#include <linux/sched.h>
40895 #include <linux/init.h>
40896 #include <linux/input.h>
40897 #include <linux/gameport.h>
40898diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
40899index 75e3b10..fb390fd 100644
40900--- a/drivers/input/joystick/xpad.c
40901+++ b/drivers/input/joystick/xpad.c
40902@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
40903
40904 static int xpad_led_probe(struct usb_xpad *xpad)
40905 {
40906- static atomic_t led_seq = ATOMIC_INIT(0);
40907+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
40908 long led_no;
40909 struct xpad_led *led;
40910 struct led_classdev *led_cdev;
40911@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
40912 if (!led)
40913 return -ENOMEM;
40914
40915- led_no = (long)atomic_inc_return(&led_seq) - 1;
40916+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
40917
40918 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
40919 led->xpad = xpad;
40920diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
40921index e204f26..8459f15 100644
40922--- a/drivers/input/misc/ims-pcu.c
40923+++ b/drivers/input/misc/ims-pcu.c
40924@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
40925
40926 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40927 {
40928- static atomic_t device_no = ATOMIC_INIT(0);
40929+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
40930
40931 const struct ims_pcu_device_info *info;
40932 u8 device_id;
40933@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40934 }
40935
40936 /* Device appears to be operable, complete initialization */
40937- pcu->device_no = atomic_inc_return(&device_no) - 1;
40938+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
40939
40940 error = ims_pcu_setup_backlight(pcu);
40941 if (error)
40942diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
40943index 2f0b39d..7370f13 100644
40944--- a/drivers/input/mouse/psmouse.h
40945+++ b/drivers/input/mouse/psmouse.h
40946@@ -116,7 +116,7 @@ struct psmouse_attribute {
40947 ssize_t (*set)(struct psmouse *psmouse, void *data,
40948 const char *buf, size_t count);
40949 bool protect;
40950-};
40951+} __do_const;
40952 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
40953
40954 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
40955diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
40956index 4c842c3..590b0bf 100644
40957--- a/drivers/input/mousedev.c
40958+++ b/drivers/input/mousedev.c
40959@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
40960
40961 spin_unlock_irq(&client->packet_lock);
40962
40963- if (copy_to_user(buffer, data, count))
40964+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
40965 return -EFAULT;
40966
40967 return count;
40968diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
40969index 25fc597..558bf3b3 100644
40970--- a/drivers/input/serio/serio.c
40971+++ b/drivers/input/serio/serio.c
40972@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
40973 */
40974 static void serio_init_port(struct serio *serio)
40975 {
40976- static atomic_t serio_no = ATOMIC_INIT(0);
40977+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
40978
40979 __module_get(THIS_MODULE);
40980
40981@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
40982 mutex_init(&serio->drv_mutex);
40983 device_initialize(&serio->dev);
40984 dev_set_name(&serio->dev, "serio%ld",
40985- (long)atomic_inc_return(&serio_no) - 1);
40986+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
40987 serio->dev.bus = &serio_bus;
40988 serio->dev.release = serio_release_port;
40989 serio->dev.groups = serio_device_attr_groups;
40990diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
40991index 59df2e7..8f1cafb 100644
40992--- a/drivers/input/serio/serio_raw.c
40993+++ b/drivers/input/serio/serio_raw.c
40994@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
40995
40996 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
40997 {
40998- static atomic_t serio_raw_no = ATOMIC_INIT(0);
40999+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41000 struct serio_raw *serio_raw;
41001 int err;
41002
41003@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41004 }
41005
41006 snprintf(serio_raw->name, sizeof(serio_raw->name),
41007- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41008+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41009 kref_init(&serio_raw->kref);
41010 INIT_LIST_HEAD(&serio_raw->client_list);
41011 init_waitqueue_head(&serio_raw->wait);
41012diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41013index fbe9ca7..dbee61d 100644
41014--- a/drivers/iommu/iommu.c
41015+++ b/drivers/iommu/iommu.c
41016@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41017 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41018 {
41019 bus_register_notifier(bus, &iommu_bus_nb);
41020- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41021+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41022 }
41023
41024 /**
41025diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41026index 39f81ae..2660096 100644
41027--- a/drivers/iommu/irq_remapping.c
41028+++ b/drivers/iommu/irq_remapping.c
41029@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41030 void panic_if_irq_remap(const char *msg)
41031 {
41032 if (irq_remapping_enabled)
41033- panic(msg);
41034+ panic("%s", msg);
41035 }
41036
41037 static void ir_ack_apic_edge(struct irq_data *data)
41038@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41039
41040 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41041 {
41042- chip->irq_print_chip = ir_print_prefix;
41043- chip->irq_ack = ir_ack_apic_edge;
41044- chip->irq_eoi = ir_ack_apic_level;
41045- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41046+ pax_open_kernel();
41047+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41048+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41049+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41050+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41051+ pax_close_kernel();
41052 }
41053
41054 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41055diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41056index ee7c503..5d4ce08 100644
41057--- a/drivers/irqchip/irq-gic.c
41058+++ b/drivers/irqchip/irq-gic.c
41059@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41060 * Supported arch specific GIC irq extension.
41061 * Default make them NULL.
41062 */
41063-struct irq_chip gic_arch_extn = {
41064+irq_chip_no_const gic_arch_extn = {
41065 .irq_eoi = NULL,
41066 .irq_mask = NULL,
41067 .irq_unmask = NULL,
41068@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41069 chained_irq_exit(chip, desc);
41070 }
41071
41072-static struct irq_chip gic_chip = {
41073+static irq_chip_no_const gic_chip __read_only = {
41074 .name = "GIC",
41075 .irq_mask = gic_mask_irq,
41076 .irq_unmask = gic_unmask_irq,
41077diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41078index ac6f72b..81150f2 100644
41079--- a/drivers/isdn/capi/capi.c
41080+++ b/drivers/isdn/capi/capi.c
41081@@ -81,8 +81,8 @@ struct capiminor {
41082
41083 struct capi20_appl *ap;
41084 u32 ncci;
41085- atomic_t datahandle;
41086- atomic_t msgid;
41087+ atomic_unchecked_t datahandle;
41088+ atomic_unchecked_t msgid;
41089
41090 struct tty_port port;
41091 int ttyinstop;
41092@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41093 capimsg_setu16(s, 2, mp->ap->applid);
41094 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41095 capimsg_setu8 (s, 5, CAPI_RESP);
41096- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41097+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41098 capimsg_setu32(s, 8, mp->ncci);
41099 capimsg_setu16(s, 12, datahandle);
41100 }
41101@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41102 mp->outbytes -= len;
41103 spin_unlock_bh(&mp->outlock);
41104
41105- datahandle = atomic_inc_return(&mp->datahandle);
41106+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41107 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41108 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41109 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41110 capimsg_setu16(skb->data, 2, mp->ap->applid);
41111 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41112 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41113- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41114+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41115 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41116 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41117 capimsg_setu16(skb->data, 16, len); /* Data length */
41118diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41119index 600c79b..3752bab 100644
41120--- a/drivers/isdn/gigaset/interface.c
41121+++ b/drivers/isdn/gigaset/interface.c
41122@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41123 }
41124 tty->driver_data = cs;
41125
41126- ++cs->port.count;
41127+ atomic_inc(&cs->port.count);
41128
41129- if (cs->port.count == 1) {
41130+ if (atomic_read(&cs->port.count) == 1) {
41131 tty_port_tty_set(&cs->port, tty);
41132 cs->port.low_latency = 1;
41133 }
41134@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41135
41136 if (!cs->connected)
41137 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41138- else if (!cs->port.count)
41139+ else if (!atomic_read(&cs->port.count))
41140 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41141- else if (!--cs->port.count)
41142+ else if (!atomic_dec_return(&cs->port.count))
41143 tty_port_tty_set(&cs->port, NULL);
41144
41145 mutex_unlock(&cs->mutex);
41146diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41147index d0a41cb..f0cdb8c 100644
41148--- a/drivers/isdn/gigaset/usb-gigaset.c
41149+++ b/drivers/isdn/gigaset/usb-gigaset.c
41150@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41151 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41152 memcpy(cs->hw.usb->bchars, buf, 6);
41153 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41154- 0, 0, &buf, 6, 2000);
41155+ 0, 0, buf, 6, 2000);
41156 }
41157
41158 static void gigaset_freebcshw(struct bc_state *bcs)
41159diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41160index 4d9b195..455075c 100644
41161--- a/drivers/isdn/hardware/avm/b1.c
41162+++ b/drivers/isdn/hardware/avm/b1.c
41163@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41164 }
41165 if (left) {
41166 if (t4file->user) {
41167- if (copy_from_user(buf, dp, left))
41168+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41169 return -EFAULT;
41170 } else {
41171 memcpy(buf, dp, left);
41172@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41173 }
41174 if (left) {
41175 if (config->user) {
41176- if (copy_from_user(buf, dp, left))
41177+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41178 return -EFAULT;
41179 } else {
41180 memcpy(buf, dp, left);
41181diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41182index 1063bab..36817e0 100644
41183--- a/drivers/isdn/hisax/amd7930_fn.c
41184+++ b/drivers/isdn/hisax/amd7930_fn.c
41185@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41186
41187 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41188 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41189- debugl1(cs, cs->dlog);
41190+ debugl1(cs, "%s", cs->dlog);
41191 }
41192 /* moves received data in sk-buffer */
41193 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41194@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41195
41196 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41197 QuickHex(t, deb_ptr, count);
41198- debugl1(cs, cs->dlog);
41199+ debugl1(cs, "%s", cs->dlog);
41200 }
41201 /* AMD interrupts on */
41202 AmdIrqOn(cs);
41203diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41204index ee9b9a0..d1427bd 100644
41205--- a/drivers/isdn/hisax/avm_pci.c
41206+++ b/drivers/isdn/hisax/avm_pci.c
41207@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41208 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41209 bcs->channel ? 'B' : 'A', count);
41210 QuickHex(t, p, count);
41211- debugl1(cs, bcs->blog);
41212+ debugl1(cs, "%s", bcs->blog);
41213 }
41214 }
41215
41216@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41217 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41218 bcs->channel ? 'B' : 'A', count);
41219 QuickHex(t, p, count);
41220- debugl1(cs, bcs->blog);
41221+ debugl1(cs, "%s", bcs->blog);
41222 }
41223 }
41224
41225diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41226index bf04d2a..b33f53b 100644
41227--- a/drivers/isdn/hisax/config.c
41228+++ b/drivers/isdn/hisax/config.c
41229@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41230 ptr--;
41231 *ptr++ = '\n';
41232 *ptr = 0;
41233- HiSax_putstatus(cs, NULL, cs->dlog);
41234+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41235 } else
41236 HiSax_putstatus(cs, "LogEcho: ",
41237 "warning Frame too big (%d)",
41238diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41239index 8d0cf6e..4fc90de 100644
41240--- a/drivers/isdn/hisax/diva.c
41241+++ b/drivers/isdn/hisax/diva.c
41242@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41243 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41244 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41245 QuickHex(t, ptr, count);
41246- debugl1(cs, bcs->blog);
41247+ debugl1(cs, "%s", bcs->blog);
41248 }
41249 }
41250
41251@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41252 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41253 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41254 QuickHex(t, ptr, count);
41255- debugl1(cs, bcs->blog);
41256+ debugl1(cs, "%s", bcs->blog);
41257 }
41258 }
41259
41260diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41261index 1df6f9a..2be1c8a 100644
41262--- a/drivers/isdn/hisax/elsa.c
41263+++ b/drivers/isdn/hisax/elsa.c
41264@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41265 t = tmp;
41266 t += sprintf(tmp, "Arcofi data");
41267 QuickHex(t, p, cs->dc.isac.mon_rxp);
41268- debugl1(cs, tmp);
41269+ debugl1(cs, "%s", tmp);
41270 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41271 switch (cs->dc.isac.mon_rx[1]) {
41272 case 0x80:
41273diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41274index d4c98d3..3f84dd8 100644
41275--- a/drivers/isdn/hisax/elsa_ser.c
41276+++ b/drivers/isdn/hisax/elsa_ser.c
41277@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41278
41279 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41280 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41281- debugl1(cs, tmp);
41282+ debugl1(cs, "%s", tmp);
41283 }
41284 cs->hw.elsa.rcvcnt = 0;
41285 }
41286diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41287index 3ccd724..497bd02 100644
41288--- a/drivers/isdn/hisax/hfc_pci.c
41289+++ b/drivers/isdn/hisax/hfc_pci.c
41290@@ -901,7 +901,7 @@ Begin:
41291 ptr--;
41292 *ptr++ = '\n';
41293 *ptr = 0;
41294- HiSax_putstatus(cs, NULL, cs->dlog);
41295+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41296 } else
41297 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41298 }
41299diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41300index dc4574f..fa1fefd 100644
41301--- a/drivers/isdn/hisax/hfc_sx.c
41302+++ b/drivers/isdn/hisax/hfc_sx.c
41303@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41304 ptr--;
41305 *ptr++ = '\n';
41306 *ptr = 0;
41307- HiSax_putstatus(cs, NULL, cs->dlog);
41308+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41309 } else
41310 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41311 }
41312diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41313index f398d48..a8d6188 100644
41314--- a/drivers/isdn/hisax/hscx_irq.c
41315+++ b/drivers/isdn/hisax/hscx_irq.c
41316@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41317 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41318 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41319 QuickHex(t, ptr, count);
41320- debugl1(cs, bcs->blog);
41321+ debugl1(cs, "%s", bcs->blog);
41322 }
41323 }
41324
41325@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41326 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41327 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41328 QuickHex(t, ptr, count);
41329- debugl1(cs, bcs->blog);
41330+ debugl1(cs, "%s", bcs->blog);
41331 }
41332 }
41333
41334diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41335index db5321f..51dae91 100644
41336--- a/drivers/isdn/hisax/icc.c
41337+++ b/drivers/isdn/hisax/icc.c
41338@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41339
41340 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41341 QuickHex(t, ptr, count);
41342- debugl1(cs, cs->dlog);
41343+ debugl1(cs, "%s", cs->dlog);
41344 }
41345 }
41346
41347@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41348
41349 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41350 QuickHex(t, ptr, count);
41351- debugl1(cs, cs->dlog);
41352+ debugl1(cs, "%s", cs->dlog);
41353 }
41354 }
41355
41356diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41357index 74feb5c..5faa5de 100644
41358--- a/drivers/isdn/hisax/ipacx.c
41359+++ b/drivers/isdn/hisax/ipacx.c
41360@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41361
41362 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41363 QuickHex(t, ptr, count);
41364- debugl1(cs, cs->dlog);
41365+ debugl1(cs, "%s", cs->dlog);
41366 }
41367 }
41368
41369@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41370
41371 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41372 QuickHex(t, ptr, count);
41373- debugl1(cs, cs->dlog);
41374+ debugl1(cs, "%s", cs->dlog);
41375 }
41376 }
41377
41378@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41379
41380 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41381 QuickHex(t, ptr, count);
41382- debugl1(cs, bcs->blog);
41383+ debugl1(cs, "%s", bcs->blog);
41384 }
41385 }
41386
41387@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41388
41389 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41390 QuickHex(t, ptr, count);
41391- debugl1(cs, bcs->blog);
41392+ debugl1(cs, "%s", bcs->blog);
41393 }
41394 }
41395
41396diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41397index a365ccc..7fdf78f 100644
41398--- a/drivers/isdn/hisax/isac.c
41399+++ b/drivers/isdn/hisax/isac.c
41400@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41401
41402 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41403 QuickHex(t, ptr, count);
41404- debugl1(cs, cs->dlog);
41405+ debugl1(cs, "%s", cs->dlog);
41406 }
41407 }
41408
41409@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41410
41411 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41412 QuickHex(t, ptr, count);
41413- debugl1(cs, cs->dlog);
41414+ debugl1(cs, "%s", cs->dlog);
41415 }
41416 }
41417
41418diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41419index 7fdf347..f4956c7 100644
41420--- a/drivers/isdn/hisax/isar.c
41421+++ b/drivers/isdn/hisax/isar.c
41422@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41423 t = tmp;
41424 t += sprintf(t, "sendmbox cnt %d", len);
41425 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41426- debugl1(cs, tmp);
41427+ debugl1(cs, "%s", tmp);
41428 i -= 64;
41429 }
41430 }
41431@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41432 t = tmp;
41433 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41434 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41435- debugl1(cs, tmp);
41436+ debugl1(cs, "%s", tmp);
41437 i -= 64;
41438 }
41439 }
41440@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41441 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41442 ireg->iis, ireg->cmsb);
41443 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41444- debugl1(cs, debbuf);
41445+ debugl1(cs, "%s", debbuf);
41446 }
41447 break;
41448 case ISAR_IIS_INVMSG:
41449diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41450index f946c58..e2ae787 100644
41451--- a/drivers/isdn/hisax/jade.c
41452+++ b/drivers/isdn/hisax/jade.c
41453@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41454 int jade = bcs->hw.hscx.hscx;
41455
41456 if (cs->debug & L1_DEB_HSCX) {
41457- char tmp[40];
41458- sprintf(tmp, "jade %c mode %d ichan %d",
41459- 'A' + jade, mode, bc);
41460- debugl1(cs, tmp);
41461+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41462 }
41463 bcs->mode = mode;
41464 bcs->channel = bc;
41465@@ -257,23 +254,18 @@ void
41466 clear_pending_jade_ints(struct IsdnCardState *cs)
41467 {
41468 int val;
41469- char tmp[64];
41470
41471 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41472 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41473
41474 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41475- sprintf(tmp, "jade B ISTA %x", val);
41476- debugl1(cs, tmp);
41477+ debugl1(cs, "jade B ISTA %x", val);
41478 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41479- sprintf(tmp, "jade A ISTA %x", val);
41480- debugl1(cs, tmp);
41481+ debugl1(cs, "jade A ISTA %x", val);
41482 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41483- sprintf(tmp, "jade B STAR %x", val);
41484- debugl1(cs, tmp);
41485+ debugl1(cs, "jade B STAR %x", val);
41486 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41487- sprintf(tmp, "jade A STAR %x", val);
41488- debugl1(cs, tmp);
41489+ debugl1(cs, "jade A STAR %x", val);
41490 /* Unmask ints */
41491 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41492 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41493diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41494index f521fc8..b930da9 100644
41495--- a/drivers/isdn/hisax/jade_irq.c
41496+++ b/drivers/isdn/hisax/jade_irq.c
41497@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41498 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41499 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41500 QuickHex(t, ptr, count);
41501- debugl1(cs, bcs->blog);
41502+ debugl1(cs, "%s", bcs->blog);
41503 }
41504 }
41505
41506@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41507 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41508 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41509 QuickHex(t, ptr, count);
41510- debugl1(cs, bcs->blog);
41511+ debugl1(cs, "%s", bcs->blog);
41512 }
41513 }
41514
41515diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41516index 4c1bca5..875402e 100644
41517--- a/drivers/isdn/hisax/l3_1tr6.c
41518+++ b/drivers/isdn/hisax/l3_1tr6.c
41519@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41520 {
41521 dev_kfree_skb(skb);
41522 if (pc->st->l3.debug & L3_DEB_WARN)
41523- l3_debug(pc->st, msg);
41524+ l3_debug(pc->st, "%s", msg);
41525 l3_1tr6_release_req(pc, 0, NULL);
41526 }
41527
41528@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41529 {
41530 u_char *p;
41531 int bcfound = 0;
41532- char tmp[80];
41533 struct sk_buff *skb = arg;
41534
41535 /* Channel Identification */
41536@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41537 /* Signal all services, linklevel takes care of Service-Indicator */
41538 if (bcfound) {
41539 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41540- sprintf(tmp, "non-digital call: %s -> %s",
41541+ l3_debug(pc->st, "non-digital call: %s -> %s",
41542 pc->para.setup.phone,
41543 pc->para.setup.eazmsn);
41544- l3_debug(pc->st, tmp);
41545 }
41546 newl3state(pc, 6);
41547 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41548@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41549 {
41550 u_char *p;
41551 int i, tmpcharge = 0;
41552- char a_charge[8], tmp[32];
41553+ char a_charge[8];
41554 struct sk_buff *skb = arg;
41555
41556 p = skb->data;
41557@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41558 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41559 }
41560 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41561- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41562- l3_debug(pc->st, tmp);
41563+ l3_debug(pc->st, "charging info %d",
41564+ pc->para.chargeinfo);
41565 }
41566 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41567 l3_debug(pc->st, "charging info not found");
41568@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41569 struct sk_buff *skb = arg;
41570 u_char *p;
41571 int i, tmpcharge = 0;
41572- char a_charge[8], tmp[32];
41573+ char a_charge[8];
41574
41575 StopAllL3Timer(pc);
41576 p = skb->data;
41577@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41578 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41579 }
41580 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41581- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41582- l3_debug(pc->st, tmp);
41583+ l3_debug(pc->st, "charging info %d",
41584+ pc->para.chargeinfo);
41585 }
41586 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41587 l3_debug(pc->st, "charging info not found");
41588@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41589 int i, mt, cr;
41590 struct l3_process *proc;
41591 struct sk_buff *skb = arg;
41592- char tmp[80];
41593
41594 switch (pr) {
41595 case (DL_DATA | INDICATION):
41596@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41597 }
41598 if (skb->len < 4) {
41599 if (st->l3.debug & L3_DEB_PROTERR) {
41600- sprintf(tmp, "up1tr6 len only %d", skb->len);
41601- l3_debug(st, tmp);
41602+ l3_debug(st, "up1tr6 len only %d", skb->len);
41603 }
41604 dev_kfree_skb(skb);
41605 return;
41606 }
41607 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41608 if (st->l3.debug & L3_DEB_PROTERR) {
41609- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41610+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41611 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41612 skb->data[0], skb->len);
41613- l3_debug(st, tmp);
41614 }
41615 dev_kfree_skb(skb);
41616 return;
41617 }
41618 if (skb->data[1] != 1) {
41619 if (st->l3.debug & L3_DEB_PROTERR) {
41620- sprintf(tmp, "up1tr6 CR len not 1");
41621- l3_debug(st, tmp);
41622+ l3_debug(st, "up1tr6 CR len not 1");
41623 }
41624 dev_kfree_skb(skb);
41625 return;
41626@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41627 if (skb->data[0] == PROTO_DIS_N0) {
41628 dev_kfree_skb(skb);
41629 if (st->l3.debug & L3_DEB_STATE) {
41630- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41631+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41632 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41633- l3_debug(st, tmp);
41634 }
41635 } else if (skb->data[0] == PROTO_DIS_N1) {
41636 if (!(proc = getl3proc(st, cr))) {
41637@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41638 if (cr < 128) {
41639 if (!(proc = new_l3_process(st, cr))) {
41640 if (st->l3.debug & L3_DEB_PROTERR) {
41641- sprintf(tmp, "up1tr6 no roc mem");
41642- l3_debug(st, tmp);
41643+ l3_debug(st, "up1tr6 no roc mem");
41644 }
41645 dev_kfree_skb(skb);
41646 return;
41647@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41648 } else {
41649 if (!(proc = new_l3_process(st, cr))) {
41650 if (st->l3.debug & L3_DEB_PROTERR) {
41651- sprintf(tmp, "up1tr6 no roc mem");
41652- l3_debug(st, tmp);
41653+ l3_debug(st, "up1tr6 no roc mem");
41654 }
41655 dev_kfree_skb(skb);
41656 return;
41657@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41658 if (i == ARRAY_SIZE(datastln1)) {
41659 dev_kfree_skb(skb);
41660 if (st->l3.debug & L3_DEB_STATE) {
41661- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41662+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41663 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41664 proc->state, mt);
41665- l3_debug(st, tmp);
41666 }
41667 return;
41668 } else {
41669 if (st->l3.debug & L3_DEB_STATE) {
41670- sprintf(tmp, "up1tr6%sstate %d mt %x",
41671+ l3_debug(st, "up1tr6%sstate %d mt %x",
41672 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41673 proc->state, mt);
41674- l3_debug(st, tmp);
41675 }
41676 datastln1[i].rout(proc, pr, skb);
41677 }
41678@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41679 int i, cr;
41680 struct l3_process *proc;
41681 struct Channel *chan;
41682- char tmp[80];
41683
41684 if ((DL_ESTABLISH | REQUEST) == pr) {
41685 l3_msg(st, pr, NULL);
41686@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41687 break;
41688 if (i == ARRAY_SIZE(downstl)) {
41689 if (st->l3.debug & L3_DEB_STATE) {
41690- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41691+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41692 proc->state, pr);
41693- l3_debug(st, tmp);
41694 }
41695 } else {
41696 if (st->l3.debug & L3_DEB_STATE) {
41697- sprintf(tmp, "down1tr6 state %d prim %d",
41698+ l3_debug(st, "down1tr6 state %d prim %d",
41699 proc->state, pr);
41700- l3_debug(st, tmp);
41701 }
41702 downstl[i].rout(proc, pr, arg);
41703 }
41704diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41705index b646eed..233e432 100644
41706--- a/drivers/isdn/hisax/netjet.c
41707+++ b/drivers/isdn/hisax/netjet.c
41708@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41709 else
41710 j = i;
41711 QuickHex(t, p, j);
41712- debugl1(cs, tmp);
41713+ debugl1(cs, "%s", tmp);
41714 p += j;
41715 i -= j;
41716 t = tmp;
41717diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41718index 041bf52..af1b020 100644
41719--- a/drivers/isdn/hisax/q931.c
41720+++ b/drivers/isdn/hisax/q931.c
41721@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41722 dp--;
41723 *dp++ = '\n';
41724 *dp = 0;
41725- HiSax_putstatus(cs, NULL, cs->dlog);
41726+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41727 } else
41728 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41729 }
41730@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41731 }
41732 if (finish) {
41733 *dp = 0;
41734- HiSax_putstatus(cs, NULL, cs->dlog);
41735+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41736 return;
41737 }
41738 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41739@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41740 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41741 }
41742 *dp = 0;
41743- HiSax_putstatus(cs, NULL, cs->dlog);
41744+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41745 }
41746diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41747index d8cac69..a858955 100644
41748--- a/drivers/isdn/hisax/w6692.c
41749+++ b/drivers/isdn/hisax/w6692.c
41750@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41751
41752 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41753 QuickHex(t, ptr, count);
41754- debugl1(cs, cs->dlog);
41755+ debugl1(cs, "%s", cs->dlog);
41756 }
41757 }
41758
41759@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41760
41761 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41762 QuickHex(t, ptr, count);
41763- debugl1(cs, cs->dlog);
41764+ debugl1(cs, "%s", cs->dlog);
41765 }
41766 }
41767
41768@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
41769 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
41770 bcs->channel + '1', count);
41771 QuickHex(t, ptr, count);
41772- debugl1(cs, bcs->blog);
41773+ debugl1(cs, "%s", bcs->blog);
41774 }
41775 }
41776
41777@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
41778 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
41779 bcs->channel + '1', count);
41780 QuickHex(t, ptr, count);
41781- debugl1(cs, bcs->blog);
41782+ debugl1(cs, "%s", bcs->blog);
41783 }
41784 }
41785
41786diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41787index 9bb12ba..d4262f7 100644
41788--- a/drivers/isdn/i4l/isdn_common.c
41789+++ b/drivers/isdn/i4l/isdn_common.c
41790@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41791 } else
41792 return -EINVAL;
41793 case IIOCDBGVAR:
41794+ if (!capable(CAP_SYS_RAWIO))
41795+ return -EPERM;
41796 if (arg) {
41797 if (copy_to_user(argp, &dev, sizeof(ulong)))
41798 return -EFAULT;
41799diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41800index 3c5f249..5fac4d0 100644
41801--- a/drivers/isdn/i4l/isdn_tty.c
41802+++ b/drivers/isdn/i4l/isdn_tty.c
41803@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41804
41805 #ifdef ISDN_DEBUG_MODEM_OPEN
41806 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41807- port->count);
41808+ atomic_read(&port->count));
41809 #endif
41810- port->count++;
41811+ atomic_inc(&port->count);
41812 port->tty = tty;
41813 /*
41814 * Start up serial port
41815@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41816 #endif
41817 return;
41818 }
41819- if ((tty->count == 1) && (port->count != 1)) {
41820+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41821 /*
41822 * Uh, oh. tty->count is 1, which means that the tty
41823 * structure will be freed. Info->count should always
41824@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41825 * serial port won't be shutdown.
41826 */
41827 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41828- "info->count is %d\n", port->count);
41829- port->count = 1;
41830+ "info->count is %d\n", atomic_read(&port->count));
41831+ atomic_set(&port->count, 1);
41832 }
41833- if (--port->count < 0) {
41834+ if (atomic_dec_return(&port->count) < 0) {
41835 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41836- info->line, port->count);
41837- port->count = 0;
41838+ info->line, atomic_read(&port->count));
41839+ atomic_set(&port->count, 0);
41840 }
41841- if (port->count) {
41842+ if (atomic_read(&port->count)) {
41843 #ifdef ISDN_DEBUG_MODEM_OPEN
41844 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41845 #endif
41846@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41847 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41848 return;
41849 isdn_tty_shutdown(info);
41850- port->count = 0;
41851+ atomic_set(&port->count, 0);
41852 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41853 port->tty = NULL;
41854 wake_up_interruptible(&port->open_wait);
41855@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41856 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41857 modem_info *info = &dev->mdm.info[i];
41858
41859- if (info->port.count == 0)
41860+ if (atomic_read(&info->port.count) == 0)
41861 continue;
41862 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41863 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41864diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41865index e74df7c..03a03ba 100644
41866--- a/drivers/isdn/icn/icn.c
41867+++ b/drivers/isdn/icn/icn.c
41868@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41869 if (count > len)
41870 count = len;
41871 if (user) {
41872- if (copy_from_user(msg, buf, count))
41873+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41874 return -EFAULT;
41875 } else
41876 memcpy(msg, buf, count);
41877diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41878index 6a8405d..0bd1c7e 100644
41879--- a/drivers/leds/leds-clevo-mail.c
41880+++ b/drivers/leds/leds-clevo-mail.c
41881@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41882 * detected as working, but in reality it is not) as low as
41883 * possible.
41884 */
41885-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
41886+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
41887 {
41888 .callback = clevo_mail_led_dmi_callback,
41889 .ident = "Clevo D410J",
41890diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41891index 64e204e..c6bf189 100644
41892--- a/drivers/leds/leds-ss4200.c
41893+++ b/drivers/leds/leds-ss4200.c
41894@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41895 * detected as working, but in reality it is not) as low as
41896 * possible.
41897 */
41898-static struct dmi_system_id __initdata nas_led_whitelist[] = {
41899+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
41900 {
41901 .callback = ss4200_led_dmi_callback,
41902 .ident = "Intel SS4200-E",
41903diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41904index 0bf1e4e..b4bf44e 100644
41905--- a/drivers/lguest/core.c
41906+++ b/drivers/lguest/core.c
41907@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41908 * The end address needs +1 because __get_vm_area allocates an
41909 * extra guard page, so we need space for that.
41910 */
41911+
41912+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41913+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41914+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41915+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41916+#else
41917 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41918 VM_ALLOC, switcher_addr, switcher_addr
41919 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41920+#endif
41921+
41922 if (!switcher_vma) {
41923 err = -ENOMEM;
41924 printk("lguest: could not map switcher pages high\n");
41925@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41926 * Now the Switcher is mapped at the right address, we can't fail!
41927 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41928 */
41929- memcpy(switcher_vma->addr, start_switcher_text,
41930+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41931 end_switcher_text - start_switcher_text);
41932
41933 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41934diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41935index a35d8d1..59fb772 100644
41936--- a/drivers/lguest/page_tables.c
41937+++ b/drivers/lguest/page_tables.c
41938@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41939 /*:*/
41940
41941 #ifdef CONFIG_X86_PAE
41942-static void release_pmd(pmd_t *spmd)
41943+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41944 {
41945 /* If the entry's not present, there's nothing to release. */
41946 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41947diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41948index 5169239..47cb4db 100644
41949--- a/drivers/lguest/x86/core.c
41950+++ b/drivers/lguest/x86/core.c
41951@@ -59,7 +59,7 @@ static struct {
41952 /* Offset from where switcher.S was compiled to where we've copied it */
41953 static unsigned long switcher_offset(void)
41954 {
41955- return switcher_addr - (unsigned long)start_switcher_text;
41956+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41957 }
41958
41959 /* This cpu's struct lguest_pages (after the Switcher text page) */
41960@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
41961 * These copies are pretty cheap, so we do them unconditionally: */
41962 /* Save the current Host top-level page directory.
41963 */
41964+
41965+#ifdef CONFIG_PAX_PER_CPU_PGD
41966+ pages->state.host_cr3 = read_cr3();
41967+#else
41968 pages->state.host_cr3 = __pa(current->mm->pgd);
41969+#endif
41970+
41971 /*
41972 * Set up the Guest's page tables to see this CPU's pages (and no
41973 * other CPU's pages).
41974@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
41975 * compiled-in switcher code and the high-mapped copy we just made.
41976 */
41977 for (i = 0; i < IDT_ENTRIES; i++)
41978- default_idt_entries[i] += switcher_offset();
41979+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
41980
41981 /*
41982 * Set up the Switcher's per-cpu areas.
41983@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
41984 * it will be undisturbed when we switch. To change %cs and jump we
41985 * need this structure to feed to Intel's "lcall" instruction.
41986 */
41987- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
41988+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
41989 lguest_entry.segment = LGUEST_CS;
41990
41991 /*
41992diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
41993index 40634b0..4f5855e 100644
41994--- a/drivers/lguest/x86/switcher_32.S
41995+++ b/drivers/lguest/x86/switcher_32.S
41996@@ -87,6 +87,7 @@
41997 #include <asm/page.h>
41998 #include <asm/segment.h>
41999 #include <asm/lguest.h>
42000+#include <asm/processor-flags.h>
42001
42002 // We mark the start of the code to copy
42003 // It's placed in .text tho it's never run here
42004@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42005 // Changes type when we load it: damn Intel!
42006 // For after we switch over our page tables
42007 // That entry will be read-only: we'd crash.
42008+
42009+#ifdef CONFIG_PAX_KERNEXEC
42010+ mov %cr0, %edx
42011+ xor $X86_CR0_WP, %edx
42012+ mov %edx, %cr0
42013+#endif
42014+
42015 movl $(GDT_ENTRY_TSS*8), %edx
42016 ltr %dx
42017
42018@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42019 // Let's clear it again for our return.
42020 // The GDT descriptor of the Host
42021 // Points to the table after two "size" bytes
42022- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42023+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42024 // Clear "used" from type field (byte 5, bit 2)
42025- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42026+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42027+
42028+#ifdef CONFIG_PAX_KERNEXEC
42029+ mov %cr0, %eax
42030+ xor $X86_CR0_WP, %eax
42031+ mov %eax, %cr0
42032+#endif
42033
42034 // Once our page table's switched, the Guest is live!
42035 // The Host fades as we run this final step.
42036@@ -295,13 +309,12 @@ deliver_to_host:
42037 // I consulted gcc, and it gave
42038 // These instructions, which I gladly credit:
42039 leal (%edx,%ebx,8), %eax
42040- movzwl (%eax),%edx
42041- movl 4(%eax), %eax
42042- xorw %ax, %ax
42043- orl %eax, %edx
42044+ movl 4(%eax), %edx
42045+ movw (%eax), %dx
42046 // Now the address of the handler's in %edx
42047 // We call it now: its "iret" drops us home.
42048- jmp *%edx
42049+ ljmp $__KERNEL_CS, $1f
42050+1: jmp *%edx
42051
42052 // Every interrupt can come to us here
42053 // But we must truly tell each apart.
42054diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42055index 0003992..854bbce 100644
42056--- a/drivers/md/bcache/closure.h
42057+++ b/drivers/md/bcache/closure.h
42058@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42059 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42060 struct workqueue_struct *wq)
42061 {
42062- BUG_ON(object_is_on_stack(cl));
42063+ BUG_ON(object_starts_on_stack(cl));
42064 closure_set_ip(cl);
42065 cl->fn = fn;
42066 cl->wq = wq;
42067diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42068index 547c4c5..5be1de4 100644
42069--- a/drivers/md/bcache/super.c
42070+++ b/drivers/md/bcache/super.c
42071@@ -1644,7 +1644,7 @@ err_unlock_gc:
42072 err:
42073 closure_sync(&op.cl);
42074 /* XXX: test this, it's broken */
42075- bch_cache_set_error(c, err);
42076+ bch_cache_set_error(c, "%s", err);
42077 }
42078
42079 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42080diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42081index a7fd821..9dcf6c3 100644
42082--- a/drivers/md/bitmap.c
42083+++ b/drivers/md/bitmap.c
42084@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42085 chunk_kb ? "KB" : "B");
42086 if (bitmap->storage.file) {
42087 seq_printf(seq, ", file: ");
42088- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42089+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42090 }
42091
42092 seq_printf(seq, "\n");
42093diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42094index f1b7586..a49c4bd 100644
42095--- a/drivers/md/dm-ioctl.c
42096+++ b/drivers/md/dm-ioctl.c
42097@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42098 cmd == DM_LIST_VERSIONS_CMD)
42099 return 0;
42100
42101- if ((cmd == DM_DEV_CREATE_CMD)) {
42102+ if (cmd == DM_DEV_CREATE_CMD) {
42103 if (!*param->name) {
42104 DMWARN("name not supplied when creating device");
42105 return -EINVAL;
42106diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42107index 699b5be..eac0a15 100644
42108--- a/drivers/md/dm-raid1.c
42109+++ b/drivers/md/dm-raid1.c
42110@@ -40,7 +40,7 @@ enum dm_raid1_error {
42111
42112 struct mirror {
42113 struct mirror_set *ms;
42114- atomic_t error_count;
42115+ atomic_unchecked_t error_count;
42116 unsigned long error_type;
42117 struct dm_dev *dev;
42118 sector_t offset;
42119@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42120 struct mirror *m;
42121
42122 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42123- if (!atomic_read(&m->error_count))
42124+ if (!atomic_read_unchecked(&m->error_count))
42125 return m;
42126
42127 return NULL;
42128@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42129 * simple way to tell if a device has encountered
42130 * errors.
42131 */
42132- atomic_inc(&m->error_count);
42133+ atomic_inc_unchecked(&m->error_count);
42134
42135 if (test_and_set_bit(error_type, &m->error_type))
42136 return;
42137@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42138 struct mirror *m = get_default_mirror(ms);
42139
42140 do {
42141- if (likely(!atomic_read(&m->error_count)))
42142+ if (likely(!atomic_read_unchecked(&m->error_count)))
42143 return m;
42144
42145 if (m-- == ms->mirror)
42146@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42147 {
42148 struct mirror *default_mirror = get_default_mirror(m->ms);
42149
42150- return !atomic_read(&default_mirror->error_count);
42151+ return !atomic_read_unchecked(&default_mirror->error_count);
42152 }
42153
42154 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42155@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42156 */
42157 if (likely(region_in_sync(ms, region, 1)))
42158 m = choose_mirror(ms, bio->bi_sector);
42159- else if (m && atomic_read(&m->error_count))
42160+ else if (m && atomic_read_unchecked(&m->error_count))
42161 m = NULL;
42162
42163 if (likely(m))
42164@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42165 }
42166
42167 ms->mirror[mirror].ms = ms;
42168- atomic_set(&(ms->mirror[mirror].error_count), 0);
42169+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42170 ms->mirror[mirror].error_type = 0;
42171 ms->mirror[mirror].offset = offset;
42172
42173@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42174 */
42175 static char device_status_char(struct mirror *m)
42176 {
42177- if (!atomic_read(&(m->error_count)))
42178+ if (!atomic_read_unchecked(&(m->error_count)))
42179 return 'A';
42180
42181 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42182diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42183index d907ca6..cfb8384 100644
42184--- a/drivers/md/dm-stripe.c
42185+++ b/drivers/md/dm-stripe.c
42186@@ -20,7 +20,7 @@ struct stripe {
42187 struct dm_dev *dev;
42188 sector_t physical_start;
42189
42190- atomic_t error_count;
42191+ atomic_unchecked_t error_count;
42192 };
42193
42194 struct stripe_c {
42195@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42196 kfree(sc);
42197 return r;
42198 }
42199- atomic_set(&(sc->stripe[i].error_count), 0);
42200+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42201 }
42202
42203 ti->private = sc;
42204@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42205 DMEMIT("%d ", sc->stripes);
42206 for (i = 0; i < sc->stripes; i++) {
42207 DMEMIT("%s ", sc->stripe[i].dev->name);
42208- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42209+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42210 'D' : 'A';
42211 }
42212 buffer[i] = '\0';
42213@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42214 */
42215 for (i = 0; i < sc->stripes; i++)
42216 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42217- atomic_inc(&(sc->stripe[i].error_count));
42218- if (atomic_read(&(sc->stripe[i].error_count)) <
42219+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42220+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42221 DM_IO_ERROR_THRESHOLD)
42222 schedule_work(&sc->trigger_event);
42223 }
42224diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42225index f221812..aca962b 100644
42226--- a/drivers/md/dm-table.c
42227+++ b/drivers/md/dm-table.c
42228@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42229 if (!dev_size)
42230 return 0;
42231
42232- if ((start >= dev_size) || (start + len > dev_size)) {
42233+ if ((start >= dev_size) || (len > dev_size - start)) {
42234 DMWARN("%s: %s too small for target: "
42235 "start=%llu, len=%llu, dev_size=%llu",
42236 dm_device_name(ti->table->md), bdevname(bdev, b),
42237diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42238index 60bce43..9b997d0 100644
42239--- a/drivers/md/dm-thin-metadata.c
42240+++ b/drivers/md/dm-thin-metadata.c
42241@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42242 {
42243 pmd->info.tm = pmd->tm;
42244 pmd->info.levels = 2;
42245- pmd->info.value_type.context = pmd->data_sm;
42246+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42247 pmd->info.value_type.size = sizeof(__le64);
42248 pmd->info.value_type.inc = data_block_inc;
42249 pmd->info.value_type.dec = data_block_dec;
42250@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42251
42252 pmd->bl_info.tm = pmd->tm;
42253 pmd->bl_info.levels = 1;
42254- pmd->bl_info.value_type.context = pmd->data_sm;
42255+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42256 pmd->bl_info.value_type.size = sizeof(__le64);
42257 pmd->bl_info.value_type.inc = data_block_inc;
42258 pmd->bl_info.value_type.dec = data_block_dec;
42259diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42260index 995e1fc..2468cec 100644
42261--- a/drivers/md/dm.c
42262+++ b/drivers/md/dm.c
42263@@ -178,9 +178,9 @@ struct mapped_device {
42264 /*
42265 * Event handling.
42266 */
42267- atomic_t event_nr;
42268+ atomic_unchecked_t event_nr;
42269 wait_queue_head_t eventq;
42270- atomic_t uevent_seq;
42271+ atomic_unchecked_t uevent_seq;
42272 struct list_head uevent_list;
42273 spinlock_t uevent_lock; /* Protect access to uevent_list */
42274
42275@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42276 spin_lock_init(&md->deferred_lock);
42277 atomic_set(&md->holders, 1);
42278 atomic_set(&md->open_count, 0);
42279- atomic_set(&md->event_nr, 0);
42280- atomic_set(&md->uevent_seq, 0);
42281+ atomic_set_unchecked(&md->event_nr, 0);
42282+ atomic_set_unchecked(&md->uevent_seq, 0);
42283 INIT_LIST_HEAD(&md->uevent_list);
42284 spin_lock_init(&md->uevent_lock);
42285
42286@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42287
42288 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42289
42290- atomic_inc(&md->event_nr);
42291+ atomic_inc_unchecked(&md->event_nr);
42292 wake_up(&md->eventq);
42293 }
42294
42295@@ -2727,18 +2727,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42296
42297 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42298 {
42299- return atomic_add_return(1, &md->uevent_seq);
42300+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42301 }
42302
42303 uint32_t dm_get_event_nr(struct mapped_device *md)
42304 {
42305- return atomic_read(&md->event_nr);
42306+ return atomic_read_unchecked(&md->event_nr);
42307 }
42308
42309 int dm_wait_event(struct mapped_device *md, int event_nr)
42310 {
42311 return wait_event_interruptible(md->eventq,
42312- (event_nr != atomic_read(&md->event_nr)));
42313+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42314 }
42315
42316 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42317diff --git a/drivers/md/md.c b/drivers/md/md.c
42318index 9f13e13..411a5b8 100644
42319--- a/drivers/md/md.c
42320+++ b/drivers/md/md.c
42321@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42322 * start build, activate spare
42323 */
42324 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42325-static atomic_t md_event_count;
42326+static atomic_unchecked_t md_event_count;
42327 void md_new_event(struct mddev *mddev)
42328 {
42329- atomic_inc(&md_event_count);
42330+ atomic_inc_unchecked(&md_event_count);
42331 wake_up(&md_event_waiters);
42332 }
42333 EXPORT_SYMBOL_GPL(md_new_event);
42334@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42335 */
42336 static void md_new_event_inintr(struct mddev *mddev)
42337 {
42338- atomic_inc(&md_event_count);
42339+ atomic_inc_unchecked(&md_event_count);
42340 wake_up(&md_event_waiters);
42341 }
42342
42343@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42344 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42345 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42346 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42347- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42348+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42349
42350 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42351 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42352@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42353 else
42354 sb->resync_offset = cpu_to_le64(0);
42355
42356- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42357+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42358
42359 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42360 sb->size = cpu_to_le64(mddev->dev_sectors);
42361@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42362 static ssize_t
42363 errors_show(struct md_rdev *rdev, char *page)
42364 {
42365- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42366+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42367 }
42368
42369 static ssize_t
42370@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42371 char *e;
42372 unsigned long n = simple_strtoul(buf, &e, 10);
42373 if (*buf && (*e == 0 || *e == '\n')) {
42374- atomic_set(&rdev->corrected_errors, n);
42375+ atomic_set_unchecked(&rdev->corrected_errors, n);
42376 return len;
42377 }
42378 return -EINVAL;
42379@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42380 rdev->sb_loaded = 0;
42381 rdev->bb_page = NULL;
42382 atomic_set(&rdev->nr_pending, 0);
42383- atomic_set(&rdev->read_errors, 0);
42384- atomic_set(&rdev->corrected_errors, 0);
42385+ atomic_set_unchecked(&rdev->read_errors, 0);
42386+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42387
42388 INIT_LIST_HEAD(&rdev->same_set);
42389 init_waitqueue_head(&rdev->blocked_wait);
42390@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42391
42392 spin_unlock(&pers_lock);
42393 seq_printf(seq, "\n");
42394- seq->poll_event = atomic_read(&md_event_count);
42395+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42396 return 0;
42397 }
42398 if (v == (void*)2) {
42399@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42400 return error;
42401
42402 seq = file->private_data;
42403- seq->poll_event = atomic_read(&md_event_count);
42404+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42405 return error;
42406 }
42407
42408@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42409 /* always allow read */
42410 mask = POLLIN | POLLRDNORM;
42411
42412- if (seq->poll_event != atomic_read(&md_event_count))
42413+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42414 mask |= POLLERR | POLLPRI;
42415 return mask;
42416 }
42417@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42418 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42419 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42420 (int)part_stat_read(&disk->part0, sectors[1]) -
42421- atomic_read(&disk->sync_io);
42422+ atomic_read_unchecked(&disk->sync_io);
42423 /* sync IO will cause sync_io to increase before the disk_stats
42424 * as sync_io is counted when a request starts, and
42425 * disk_stats is counted when it completes.
42426diff --git a/drivers/md/md.h b/drivers/md/md.h
42427index 20f02c0..fd8c821 100644
42428--- a/drivers/md/md.h
42429+++ b/drivers/md/md.h
42430@@ -94,13 +94,13 @@ struct md_rdev {
42431 * only maintained for arrays that
42432 * support hot removal
42433 */
42434- atomic_t read_errors; /* number of consecutive read errors that
42435+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42436 * we have tried to ignore.
42437 */
42438 struct timespec last_read_error; /* monotonic time since our
42439 * last read error
42440 */
42441- atomic_t corrected_errors; /* number of corrected read errors,
42442+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42443 * for reporting to userspace and storing
42444 * in superblock.
42445 */
42446@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42447
42448 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42449 {
42450- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42451+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42452 }
42453
42454 struct md_personality
42455diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42456index 3e6d115..ffecdeb 100644
42457--- a/drivers/md/persistent-data/dm-space-map.h
42458+++ b/drivers/md/persistent-data/dm-space-map.h
42459@@ -71,6 +71,7 @@ struct dm_space_map {
42460 dm_sm_threshold_fn fn,
42461 void *context);
42462 };
42463+typedef struct dm_space_map __no_const dm_space_map_no_const;
42464
42465 /*----------------------------------------------------------------*/
42466
42467diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42468index d60412c..8d4c982 100644
42469--- a/drivers/md/raid1.c
42470+++ b/drivers/md/raid1.c
42471@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42472 if (r1_sync_page_io(rdev, sect, s,
42473 bio->bi_io_vec[idx].bv_page,
42474 READ) != 0)
42475- atomic_add(s, &rdev->corrected_errors);
42476+ atomic_add_unchecked(s, &rdev->corrected_errors);
42477 }
42478 sectors -= s;
42479 sect += s;
42480@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42481 test_bit(In_sync, &rdev->flags)) {
42482 if (r1_sync_page_io(rdev, sect, s,
42483 conf->tmppage, READ)) {
42484- atomic_add(s, &rdev->corrected_errors);
42485+ atomic_add_unchecked(s, &rdev->corrected_errors);
42486 printk(KERN_INFO
42487 "md/raid1:%s: read error corrected "
42488 "(%d sectors at %llu on %s)\n",
42489diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42490index df7b0a0..a257495 100644
42491--- a/drivers/md/raid10.c
42492+++ b/drivers/md/raid10.c
42493@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42494 /* The write handler will notice the lack of
42495 * R10BIO_Uptodate and record any errors etc
42496 */
42497- atomic_add(r10_bio->sectors,
42498+ atomic_add_unchecked(r10_bio->sectors,
42499 &conf->mirrors[d].rdev->corrected_errors);
42500
42501 /* for reconstruct, we always reschedule after a read.
42502@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42503 {
42504 struct timespec cur_time_mon;
42505 unsigned long hours_since_last;
42506- unsigned int read_errors = atomic_read(&rdev->read_errors);
42507+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42508
42509 ktime_get_ts(&cur_time_mon);
42510
42511@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42512 * overflowing the shift of read_errors by hours_since_last.
42513 */
42514 if (hours_since_last >= 8 * sizeof(read_errors))
42515- atomic_set(&rdev->read_errors, 0);
42516+ atomic_set_unchecked(&rdev->read_errors, 0);
42517 else
42518- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42519+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42520 }
42521
42522 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42523@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42524 return;
42525
42526 check_decay_read_errors(mddev, rdev);
42527- atomic_inc(&rdev->read_errors);
42528- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42529+ atomic_inc_unchecked(&rdev->read_errors);
42530+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42531 char b[BDEVNAME_SIZE];
42532 bdevname(rdev->bdev, b);
42533
42534@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42535 "md/raid10:%s: %s: Raid device exceeded "
42536 "read_error threshold [cur %d:max %d]\n",
42537 mdname(mddev), b,
42538- atomic_read(&rdev->read_errors), max_read_errors);
42539+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42540 printk(KERN_NOTICE
42541 "md/raid10:%s: %s: Failing raid device\n",
42542 mdname(mddev), b);
42543@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42544 sect +
42545 choose_data_offset(r10_bio, rdev)),
42546 bdevname(rdev->bdev, b));
42547- atomic_add(s, &rdev->corrected_errors);
42548+ atomic_add_unchecked(s, &rdev->corrected_errors);
42549 }
42550
42551 rdev_dec_pending(rdev, mddev);
42552diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42553index 78ea443..7d57513 100644
42554--- a/drivers/md/raid5.c
42555+++ b/drivers/md/raid5.c
42556@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42557 mdname(conf->mddev), STRIPE_SECTORS,
42558 (unsigned long long)s,
42559 bdevname(rdev->bdev, b));
42560- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42561+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42562 clear_bit(R5_ReadError, &sh->dev[i].flags);
42563 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42564 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42565 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42566
42567- if (atomic_read(&rdev->read_errors))
42568- atomic_set(&rdev->read_errors, 0);
42569+ if (atomic_read_unchecked(&rdev->read_errors))
42570+ atomic_set_unchecked(&rdev->read_errors, 0);
42571 } else {
42572 const char *bdn = bdevname(rdev->bdev, b);
42573 int retry = 0;
42574 int set_bad = 0;
42575
42576 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42577- atomic_inc(&rdev->read_errors);
42578+ atomic_inc_unchecked(&rdev->read_errors);
42579 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42580 printk_ratelimited(
42581 KERN_WARNING
42582@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42583 mdname(conf->mddev),
42584 (unsigned long long)s,
42585 bdn);
42586- } else if (atomic_read(&rdev->read_errors)
42587+ } else if (atomic_read_unchecked(&rdev->read_errors)
42588 > conf->max_nr_stripes)
42589 printk(KERN_WARNING
42590 "md/raid:%s: Too many read errors, failing device %s.\n",
42591diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42592index 401ef64..836e563 100644
42593--- a/drivers/media/dvb-core/dvbdev.c
42594+++ b/drivers/media/dvb-core/dvbdev.c
42595@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42596 const struct dvb_device *template, void *priv, int type)
42597 {
42598 struct dvb_device *dvbdev;
42599- struct file_operations *dvbdevfops;
42600+ file_operations_no_const *dvbdevfops;
42601 struct device *clsdev;
42602 int minor;
42603 int id;
42604diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42605index 9b6c3bb..baeb5c7 100644
42606--- a/drivers/media/dvb-frontends/dib3000.h
42607+++ b/drivers/media/dvb-frontends/dib3000.h
42608@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42609 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42610 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42611 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42612-};
42613+} __no_const;
42614
42615 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42616 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42617diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42618index ecf21d9..b992428d 100644
42619--- a/drivers/media/pci/cx88/cx88-video.c
42620+++ b/drivers/media/pci/cx88/cx88-video.c
42621@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42622
42623 /* ------------------------------------------------------------------ */
42624
42625-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42626-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42627-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42628+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42629+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42630+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42631
42632 module_param_array(video_nr, int, NULL, 0444);
42633 module_param_array(vbi_nr, int, NULL, 0444);
42634diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42635index c08ae3e..eb59af1 100644
42636--- a/drivers/media/pci/ivtv/ivtv-driver.c
42637+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42638@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42639 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42640
42641 /* ivtv instance counter */
42642-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42643+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42644
42645 /* Parameter declarations */
42646 static int cardtype[IVTV_MAX_CARDS];
42647diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42648index dfd0a21..6bbb465 100644
42649--- a/drivers/media/platform/omap/omap_vout.c
42650+++ b/drivers/media/platform/omap/omap_vout.c
42651@@ -63,7 +63,6 @@ enum omap_vout_channels {
42652 OMAP_VIDEO2,
42653 };
42654
42655-static struct videobuf_queue_ops video_vbq_ops;
42656 /* Variables configurable through module params*/
42657 static u32 video1_numbuffers = 3;
42658 static u32 video2_numbuffers = 3;
42659@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42660 {
42661 struct videobuf_queue *q;
42662 struct omap_vout_device *vout = NULL;
42663+ static struct videobuf_queue_ops video_vbq_ops = {
42664+ .buf_setup = omap_vout_buffer_setup,
42665+ .buf_prepare = omap_vout_buffer_prepare,
42666+ .buf_release = omap_vout_buffer_release,
42667+ .buf_queue = omap_vout_buffer_queue,
42668+ };
42669
42670 vout = video_drvdata(file);
42671 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42672@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42673 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42674
42675 q = &vout->vbq;
42676- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42677- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42678- video_vbq_ops.buf_release = omap_vout_buffer_release;
42679- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42680 spin_lock_init(&vout->vbq_lock);
42681
42682 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42683diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42684index 04e6490..2df65bf 100644
42685--- a/drivers/media/platform/s5p-tv/mixer.h
42686+++ b/drivers/media/platform/s5p-tv/mixer.h
42687@@ -156,7 +156,7 @@ struct mxr_layer {
42688 /** layer index (unique identifier) */
42689 int idx;
42690 /** callbacks for layer methods */
42691- struct mxr_layer_ops ops;
42692+ struct mxr_layer_ops *ops;
42693 /** format array */
42694 const struct mxr_format **fmt_array;
42695 /** size of format array */
42696diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42697index b93a21f..2535195 100644
42698--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42699+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42700@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42701 {
42702 struct mxr_layer *layer;
42703 int ret;
42704- struct mxr_layer_ops ops = {
42705+ static struct mxr_layer_ops ops = {
42706 .release = mxr_graph_layer_release,
42707 .buffer_set = mxr_graph_buffer_set,
42708 .stream_set = mxr_graph_stream_set,
42709diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42710index b713403..53cb5ad 100644
42711--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42712+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42713@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42714 layer->update_buf = next;
42715 }
42716
42717- layer->ops.buffer_set(layer, layer->update_buf);
42718+ layer->ops->buffer_set(layer, layer->update_buf);
42719
42720 if (done && done != layer->shadow_buf)
42721 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42722diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42723index 641b1f0..49cff30 100644
42724--- a/drivers/media/platform/s5p-tv/mixer_video.c
42725+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42726@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42727 layer->geo.src.height = layer->geo.src.full_height;
42728
42729 mxr_geometry_dump(mdev, &layer->geo);
42730- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42731+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42732 mxr_geometry_dump(mdev, &layer->geo);
42733 }
42734
42735@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42736 layer->geo.dst.full_width = mbus_fmt.width;
42737 layer->geo.dst.full_height = mbus_fmt.height;
42738 layer->geo.dst.field = mbus_fmt.field;
42739- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42740+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42741
42742 mxr_geometry_dump(mdev, &layer->geo);
42743 }
42744@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42745 /* set source size to highest accepted value */
42746 geo->src.full_width = max(geo->dst.full_width, pix->width);
42747 geo->src.full_height = max(geo->dst.full_height, pix->height);
42748- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42749+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42750 mxr_geometry_dump(mdev, &layer->geo);
42751 /* set cropping to total visible screen */
42752 geo->src.width = pix->width;
42753@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42754 geo->src.x_offset = 0;
42755 geo->src.y_offset = 0;
42756 /* assure consistency of geometry */
42757- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42758+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42759 mxr_geometry_dump(mdev, &layer->geo);
42760 /* set full size to lowest possible value */
42761 geo->src.full_width = 0;
42762 geo->src.full_height = 0;
42763- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42764+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42765 mxr_geometry_dump(mdev, &layer->geo);
42766
42767 /* returning results */
42768@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42769 target->width = s->r.width;
42770 target->height = s->r.height;
42771
42772- layer->ops.fix_geometry(layer, stage, s->flags);
42773+ layer->ops->fix_geometry(layer, stage, s->flags);
42774
42775 /* retrieve update selection rectangle */
42776 res.left = target->x_offset;
42777@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42778 mxr_output_get(mdev);
42779
42780 mxr_layer_update_output(layer);
42781- layer->ops.format_set(layer);
42782+ layer->ops->format_set(layer);
42783 /* enabling layer in hardware */
42784 spin_lock_irqsave(&layer->enq_slock, flags);
42785 layer->state = MXR_LAYER_STREAMING;
42786 spin_unlock_irqrestore(&layer->enq_slock, flags);
42787
42788- layer->ops.stream_set(layer, MXR_ENABLE);
42789+ layer->ops->stream_set(layer, MXR_ENABLE);
42790 mxr_streamer_get(mdev);
42791
42792 return 0;
42793@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42794 spin_unlock_irqrestore(&layer->enq_slock, flags);
42795
42796 /* disabling layer in hardware */
42797- layer->ops.stream_set(layer, MXR_DISABLE);
42798+ layer->ops->stream_set(layer, MXR_DISABLE);
42799 /* remove one streamer */
42800 mxr_streamer_put(mdev);
42801 /* allow changes in output configuration */
42802@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42803
42804 void mxr_layer_release(struct mxr_layer *layer)
42805 {
42806- if (layer->ops.release)
42807- layer->ops.release(layer);
42808+ if (layer->ops->release)
42809+ layer->ops->release(layer);
42810 }
42811
42812 void mxr_base_layer_release(struct mxr_layer *layer)
42813@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42814
42815 layer->mdev = mdev;
42816 layer->idx = idx;
42817- layer->ops = *ops;
42818+ layer->ops = ops;
42819
42820 spin_lock_init(&layer->enq_slock);
42821 INIT_LIST_HEAD(&layer->enq_list);
42822diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42823index 3d13a63..da31bf1 100644
42824--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42825+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42826@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42827 {
42828 struct mxr_layer *layer;
42829 int ret;
42830- struct mxr_layer_ops ops = {
42831+ static struct mxr_layer_ops ops = {
42832 .release = mxr_vp_layer_release,
42833 .buffer_set = mxr_vp_buffer_set,
42834 .stream_set = mxr_vp_stream_set,
42835diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42836index 545c04c..a14bded 100644
42837--- a/drivers/media/radio/radio-cadet.c
42838+++ b/drivers/media/radio/radio-cadet.c
42839@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42840 unsigned char readbuf[RDS_BUFFER];
42841 int i = 0;
42842
42843+ if (count > RDS_BUFFER)
42844+ return -EFAULT;
42845 mutex_lock(&dev->lock);
42846 if (dev->rdsstat == 0)
42847 cadet_start_rds(dev);
42848@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42849 while (i < count && dev->rdsin != dev->rdsout)
42850 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42851
42852- if (i && copy_to_user(data, readbuf, i))
42853+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42854 i = -EFAULT;
42855 unlock:
42856 mutex_unlock(&dev->lock);
42857diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42858index bd4d3a7..ffc0b9d 100644
42859--- a/drivers/media/radio/radio-maxiradio.c
42860+++ b/drivers/media/radio/radio-maxiradio.c
42861@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42862 /* TEA5757 pin mappings */
42863 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42864
42865-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42866+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42867
42868 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42869 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42870diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42871index 8fa18ab..caee70f 100644
42872--- a/drivers/media/radio/radio-shark.c
42873+++ b/drivers/media/radio/radio-shark.c
42874@@ -79,7 +79,7 @@ struct shark_device {
42875 u32 last_val;
42876 };
42877
42878-static atomic_t shark_instance = ATOMIC_INIT(0);
42879+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42880
42881 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42882 {
42883diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42884index 9fb6697..f167415 100644
42885--- a/drivers/media/radio/radio-shark2.c
42886+++ b/drivers/media/radio/radio-shark2.c
42887@@ -74,7 +74,7 @@ struct shark_device {
42888 u8 *transfer_buffer;
42889 };
42890
42891-static atomic_t shark_instance = ATOMIC_INIT(0);
42892+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42893
42894 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42895 {
42896diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42897index 9c9084c..a9e8dfb 100644
42898--- a/drivers/media/radio/radio-si476x.c
42899+++ b/drivers/media/radio/radio-si476x.c
42900@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42901 struct si476x_radio *radio;
42902 struct v4l2_ctrl *ctrl;
42903
42904- static atomic_t instance = ATOMIC_INIT(0);
42905+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42906
42907 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42908 if (!radio)
42909diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42910index 1cf382a..c22998c 100644
42911--- a/drivers/media/rc/rc-main.c
42912+++ b/drivers/media/rc/rc-main.c
42913@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42914 int rc_register_device(struct rc_dev *dev)
42915 {
42916 static bool raw_init = false; /* raw decoders loaded? */
42917- static atomic_t devno = ATOMIC_INIT(0);
42918+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42919 struct rc_map *rc_map;
42920 const char *path;
42921 int rc;
42922@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
42923 */
42924 mutex_lock(&dev->lock);
42925
42926- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42927+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42928 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42929 dev_set_drvdata(&dev->dev, dev);
42930 rc = device_add(&dev->dev);
42931diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42932index 3940bb0..fb3952a 100644
42933--- a/drivers/media/usb/dvb-usb/cxusb.c
42934+++ b/drivers/media/usb/dvb-usb/cxusb.c
42935@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42936
42937 struct dib0700_adapter_state {
42938 int (*set_param_save) (struct dvb_frontend *);
42939-};
42940+} __no_const;
42941
42942 static int dib7070_set_param_override(struct dvb_frontend *fe)
42943 {
42944diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42945index 6e237b6..dc25556 100644
42946--- a/drivers/media/usb/dvb-usb/dw2102.c
42947+++ b/drivers/media/usb/dvb-usb/dw2102.c
42948@@ -118,7 +118,7 @@ struct su3000_state {
42949
42950 struct s6x0_state {
42951 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42952-};
42953+} __no_const;
42954
42955 /* debug */
42956 static int dvb_usb_dw2102_debug;
42957diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42958index 8f7a6a4..59502dd 100644
42959--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42960+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42961@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
42962 __u32 reserved;
42963 };
42964
42965-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42966+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42967 enum v4l2_memory memory)
42968 {
42969 void __user *up_pln;
42970@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42971 return 0;
42972 }
42973
42974-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42975+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42976 enum v4l2_memory memory)
42977 {
42978 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
42979@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
42980 put_user(kp->start_block, &up->start_block) ||
42981 put_user(kp->blocks, &up->blocks) ||
42982 put_user(tmp, &up->edid) ||
42983- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
42984+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
42985 return -EFAULT;
42986 return 0;
42987 }
42988diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
42989index 02d1b63..5fd6b16 100644
42990--- a/drivers/media/v4l2-core/v4l2-device.c
42991+++ b/drivers/media/v4l2-core/v4l2-device.c
42992@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
42993 EXPORT_SYMBOL_GPL(v4l2_device_put);
42994
42995 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
42996- atomic_t *instance)
42997+ atomic_unchecked_t *instance)
42998 {
42999- int num = atomic_inc_return(instance) - 1;
43000+ int num = atomic_inc_return_unchecked(instance) - 1;
43001 int len = strlen(basename);
43002
43003 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43004diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43005index 68e6b5e..d8b923e 100644
43006--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43007+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43008@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43009 struct file *file, void *fh, void *p);
43010 } u;
43011 void (*debug)(const void *arg, bool write_only);
43012-};
43013+} __do_const;
43014+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43015
43016 /* This control needs a priority check */
43017 #define INFO_FL_PRIO (1 << 0)
43018@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43019 struct video_device *vfd = video_devdata(file);
43020 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43021 bool write_only = false;
43022- struct v4l2_ioctl_info default_info;
43023+ v4l2_ioctl_info_no_const default_info;
43024 const struct v4l2_ioctl_info *info;
43025 void *fh = file->private_data;
43026 struct v4l2_fh *vfh = NULL;
43027@@ -2194,7 +2195,7 @@ done:
43028 }
43029
43030 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43031- void * __user *user_ptr, void ***kernel_ptr)
43032+ void __user **user_ptr, void ***kernel_ptr)
43033 {
43034 int ret = 0;
43035
43036@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43037 ret = -EINVAL;
43038 break;
43039 }
43040- *user_ptr = (void __user *)buf->m.planes;
43041+ *user_ptr = (void __force_user *)buf->m.planes;
43042 *kernel_ptr = (void *)&buf->m.planes;
43043 *array_size = sizeof(struct v4l2_plane) * buf->length;
43044 ret = 1;
43045@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43046 ret = -EINVAL;
43047 break;
43048 }
43049- *user_ptr = (void __user *)ctrls->controls;
43050+ *user_ptr = (void __force_user *)ctrls->controls;
43051 *kernel_ptr = (void *)&ctrls->controls;
43052 *array_size = sizeof(struct v4l2_ext_control)
43053 * ctrls->count;
43054diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43055index 767ff4d..c69d259 100644
43056--- a/drivers/message/fusion/mptbase.c
43057+++ b/drivers/message/fusion/mptbase.c
43058@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43059 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43060 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43061
43062+#ifdef CONFIG_GRKERNSEC_HIDESYM
43063+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43064+#else
43065 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43066 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43067+#endif
43068+
43069 /*
43070 * Rounding UP to nearest 4-kB boundary here...
43071 */
43072@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43073 ioc->facts.GlobalCredits);
43074
43075 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43076+#ifdef CONFIG_GRKERNSEC_HIDESYM
43077+ NULL, NULL);
43078+#else
43079 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43080+#endif
43081 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43082 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43083 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43084diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43085index dd239bd..689c4f7 100644
43086--- a/drivers/message/fusion/mptsas.c
43087+++ b/drivers/message/fusion/mptsas.c
43088@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43089 return 0;
43090 }
43091
43092+static inline void
43093+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43094+{
43095+ if (phy_info->port_details) {
43096+ phy_info->port_details->rphy = rphy;
43097+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43098+ ioc->name, rphy));
43099+ }
43100+
43101+ if (rphy) {
43102+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43103+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43104+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43105+ ioc->name, rphy, rphy->dev.release));
43106+ }
43107+}
43108+
43109 /* no mutex */
43110 static void
43111 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43112@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43113 return NULL;
43114 }
43115
43116-static inline void
43117-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43118-{
43119- if (phy_info->port_details) {
43120- phy_info->port_details->rphy = rphy;
43121- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43122- ioc->name, rphy));
43123- }
43124-
43125- if (rphy) {
43126- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43127- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43128- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43129- ioc->name, rphy, rphy->dev.release));
43130- }
43131-}
43132-
43133 static inline struct sas_port *
43134 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43135 {
43136diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43137index 727819c..ad74694 100644
43138--- a/drivers/message/fusion/mptscsih.c
43139+++ b/drivers/message/fusion/mptscsih.c
43140@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43141
43142 h = shost_priv(SChost);
43143
43144- if (h) {
43145- if (h->info_kbuf == NULL)
43146- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43147- return h->info_kbuf;
43148- h->info_kbuf[0] = '\0';
43149+ if (!h)
43150+ return NULL;
43151
43152- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43153- h->info_kbuf[size-1] = '\0';
43154- }
43155+ if (h->info_kbuf == NULL)
43156+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43157+ return h->info_kbuf;
43158+ h->info_kbuf[0] = '\0';
43159+
43160+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43161+ h->info_kbuf[size-1] = '\0';
43162
43163 return h->info_kbuf;
43164 }
43165diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43166index b7d87cd..9890039 100644
43167--- a/drivers/message/i2o/i2o_proc.c
43168+++ b/drivers/message/i2o/i2o_proc.c
43169@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43170 "Array Controller Device"
43171 };
43172
43173-static char *chtostr(char *tmp, u8 *chars, int n)
43174-{
43175- tmp[0] = 0;
43176- return strncat(tmp, (char *)chars, n);
43177-}
43178-
43179 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43180 char *group)
43181 {
43182@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43183 } *result;
43184
43185 i2o_exec_execute_ddm_table ddm_table;
43186- char tmp[28 + 1];
43187
43188 result = kmalloc(sizeof(*result), GFP_KERNEL);
43189 if (!result)
43190@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43191
43192 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43193 seq_printf(seq, "%-#8x", ddm_table.module_id);
43194- seq_printf(seq, "%-29s",
43195- chtostr(tmp, ddm_table.module_name_version, 28));
43196+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43197 seq_printf(seq, "%9d ", ddm_table.data_size);
43198 seq_printf(seq, "%8d", ddm_table.code_size);
43199
43200@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43201
43202 i2o_driver_result_table *result;
43203 i2o_driver_store_table *dst;
43204- char tmp[28 + 1];
43205
43206 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43207 if (result == NULL)
43208@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43209
43210 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43211 seq_printf(seq, "%-#8x", dst->module_id);
43212- seq_printf(seq, "%-29s",
43213- chtostr(tmp, dst->module_name_version, 28));
43214- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43215+ seq_printf(seq, "%-.28s", dst->module_name_version);
43216+ seq_printf(seq, "%-.8s", dst->date);
43217 seq_printf(seq, "%8d ", dst->module_size);
43218 seq_printf(seq, "%8d ", dst->mpb_size);
43219 seq_printf(seq, "0x%04x", dst->module_flags);
43220@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43221 // == (allow) 512d bytes (max)
43222 static u16 *work16 = (u16 *) work32;
43223 int token;
43224- char tmp[16 + 1];
43225
43226 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43227
43228@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43229 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43230 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43231 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43232- seq_printf(seq, "Vendor info : %s\n",
43233- chtostr(tmp, (u8 *) (work32 + 2), 16));
43234- seq_printf(seq, "Product info : %s\n",
43235- chtostr(tmp, (u8 *) (work32 + 6), 16));
43236- seq_printf(seq, "Description : %s\n",
43237- chtostr(tmp, (u8 *) (work32 + 10), 16));
43238- seq_printf(seq, "Product rev. : %s\n",
43239- chtostr(tmp, (u8 *) (work32 + 14), 8));
43240+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43241+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43242+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43243+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43244
43245 seq_printf(seq, "Serial number : ");
43246 print_serial_number(seq, (u8 *) (work32 + 16),
43247@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43248 u8 pad[256]; // allow up to 256 byte (max) serial number
43249 } result;
43250
43251- char tmp[24 + 1];
43252-
43253 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43254
43255 if (token < 0) {
43256@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43257 }
43258
43259 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43260- seq_printf(seq, "Module name : %s\n",
43261- chtostr(tmp, result.module_name, 24));
43262- seq_printf(seq, "Module revision : %s\n",
43263- chtostr(tmp, result.module_rev, 8));
43264+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43265+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43266
43267 seq_printf(seq, "Serial number : ");
43268 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43269@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43270 u8 instance_number[4];
43271 } result;
43272
43273- char tmp[64 + 1];
43274-
43275 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43276
43277 if (token < 0) {
43278@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43279 return 0;
43280 }
43281
43282- seq_printf(seq, "Device name : %s\n",
43283- chtostr(tmp, result.device_name, 64));
43284- seq_printf(seq, "Service name : %s\n",
43285- chtostr(tmp, result.service_name, 64));
43286- seq_printf(seq, "Physical name : %s\n",
43287- chtostr(tmp, result.physical_location, 64));
43288- seq_printf(seq, "Instance number : %s\n",
43289- chtostr(tmp, result.instance_number, 4));
43290+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43291+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43292+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43293+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43294
43295 return 0;
43296 }
43297diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43298index a8c08f3..155fe3d 100644
43299--- a/drivers/message/i2o/iop.c
43300+++ b/drivers/message/i2o/iop.c
43301@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43302
43303 spin_lock_irqsave(&c->context_list_lock, flags);
43304
43305- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43306- atomic_inc(&c->context_list_counter);
43307+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43308+ atomic_inc_unchecked(&c->context_list_counter);
43309
43310- entry->context = atomic_read(&c->context_list_counter);
43311+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43312
43313 list_add(&entry->list, &c->context_list);
43314
43315@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43316
43317 #if BITS_PER_LONG == 64
43318 spin_lock_init(&c->context_list_lock);
43319- atomic_set(&c->context_list_counter, 0);
43320+ atomic_set_unchecked(&c->context_list_counter, 0);
43321 INIT_LIST_HEAD(&c->context_list);
43322 #endif
43323
43324diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43325index fcbb2e9..2635e11 100644
43326--- a/drivers/mfd/janz-cmodio.c
43327+++ b/drivers/mfd/janz-cmodio.c
43328@@ -13,6 +13,7 @@
43329
43330 #include <linux/kernel.h>
43331 #include <linux/module.h>
43332+#include <linux/slab.h>
43333 #include <linux/init.h>
43334 #include <linux/pci.h>
43335 #include <linux/interrupt.h>
43336diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43337index 9aa6d1e..1631bfc 100644
43338--- a/drivers/mfd/twl4030-irq.c
43339+++ b/drivers/mfd/twl4030-irq.c
43340@@ -35,6 +35,7 @@
43341 #include <linux/of.h>
43342 #include <linux/irqdomain.h>
43343 #include <linux/i2c/twl.h>
43344+#include <asm/pgtable.h>
43345
43346 #include "twl-core.h"
43347
43348@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43349 * Install an irq handler for each of the SIH modules;
43350 * clone dummy irq_chip since PIH can't *do* anything
43351 */
43352- twl4030_irq_chip = dummy_irq_chip;
43353- twl4030_irq_chip.name = "twl4030";
43354+ pax_open_kernel();
43355+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43356+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43357
43358- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43359+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43360+ pax_close_kernel();
43361
43362 for (i = irq_base; i < irq_end; i++) {
43363 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43364diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43365index 277a8db..0e0b754 100644
43366--- a/drivers/mfd/twl6030-irq.c
43367+++ b/drivers/mfd/twl6030-irq.c
43368@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43369 * install an irq handler for each of the modules;
43370 * clone dummy irq_chip since PIH can't *do* anything
43371 */
43372- twl6030_irq_chip = dummy_irq_chip;
43373- twl6030_irq_chip.name = "twl6030";
43374- twl6030_irq_chip.irq_set_type = NULL;
43375- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43376+ pax_open_kernel();
43377+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43378+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43379+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43380+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43381+ pax_close_kernel();
43382
43383 for (i = irq_base; i < irq_end; i++) {
43384 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43385diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43386index f32550a..e3e52a2 100644
43387--- a/drivers/misc/c2port/core.c
43388+++ b/drivers/misc/c2port/core.c
43389@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43390 mutex_init(&c2dev->mutex);
43391
43392 /* Create binary file */
43393- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43394+ pax_open_kernel();
43395+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43396+ pax_close_kernel();
43397 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43398 if (unlikely(ret))
43399 goto error_device_create_bin_file;
43400diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43401index 36f5d52..32311c3 100644
43402--- a/drivers/misc/kgdbts.c
43403+++ b/drivers/misc/kgdbts.c
43404@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43405 char before[BREAK_INSTR_SIZE];
43406 char after[BREAK_INSTR_SIZE];
43407
43408- probe_kernel_read(before, (char *)kgdbts_break_test,
43409+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43410 BREAK_INSTR_SIZE);
43411 init_simple_test();
43412 ts.tst = plant_and_detach_test;
43413@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43414 /* Activate test with initial breakpoint */
43415 if (!is_early)
43416 kgdb_breakpoint();
43417- probe_kernel_read(after, (char *)kgdbts_break_test,
43418+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43419 BREAK_INSTR_SIZE);
43420 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43421 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43422diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43423index 036effe..b3a6336 100644
43424--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43425+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43426@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43427 * the lid is closed. This leads to interrupts as soon as a little move
43428 * is done.
43429 */
43430- atomic_inc(&lis3->count);
43431+ atomic_inc_unchecked(&lis3->count);
43432
43433 wake_up_interruptible(&lis3->misc_wait);
43434 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43435@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43436 if (lis3->pm_dev)
43437 pm_runtime_get_sync(lis3->pm_dev);
43438
43439- atomic_set(&lis3->count, 0);
43440+ atomic_set_unchecked(&lis3->count, 0);
43441 return 0;
43442 }
43443
43444@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43445 add_wait_queue(&lis3->misc_wait, &wait);
43446 while (true) {
43447 set_current_state(TASK_INTERRUPTIBLE);
43448- data = atomic_xchg(&lis3->count, 0);
43449+ data = atomic_xchg_unchecked(&lis3->count, 0);
43450 if (data)
43451 break;
43452
43453@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43454 struct lis3lv02d, miscdev);
43455
43456 poll_wait(file, &lis3->misc_wait, wait);
43457- if (atomic_read(&lis3->count))
43458+ if (atomic_read_unchecked(&lis3->count))
43459 return POLLIN | POLLRDNORM;
43460 return 0;
43461 }
43462diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43463index c439c82..1f20f57 100644
43464--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43465+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43466@@ -297,7 +297,7 @@ struct lis3lv02d {
43467 struct input_polled_dev *idev; /* input device */
43468 struct platform_device *pdev; /* platform device */
43469 struct regulator_bulk_data regulators[2];
43470- atomic_t count; /* interrupt count after last read */
43471+ atomic_unchecked_t count; /* interrupt count after last read */
43472 union axis_conversion ac; /* hw -> logical axis */
43473 int mapped_btns[3];
43474
43475diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43476index 2f30bad..c4c13d0 100644
43477--- a/drivers/misc/sgi-gru/gruhandles.c
43478+++ b/drivers/misc/sgi-gru/gruhandles.c
43479@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43480 unsigned long nsec;
43481
43482 nsec = CLKS2NSEC(clks);
43483- atomic_long_inc(&mcs_op_statistics[op].count);
43484- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43485+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43486+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43487 if (mcs_op_statistics[op].max < nsec)
43488 mcs_op_statistics[op].max = nsec;
43489 }
43490diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43491index 4f76359..cdfcb2e 100644
43492--- a/drivers/misc/sgi-gru/gruprocfs.c
43493+++ b/drivers/misc/sgi-gru/gruprocfs.c
43494@@ -32,9 +32,9 @@
43495
43496 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43497
43498-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43499+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43500 {
43501- unsigned long val = atomic_long_read(v);
43502+ unsigned long val = atomic_long_read_unchecked(v);
43503
43504 seq_printf(s, "%16lu %s\n", val, id);
43505 }
43506@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43507
43508 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43509 for (op = 0; op < mcsop_last; op++) {
43510- count = atomic_long_read(&mcs_op_statistics[op].count);
43511- total = atomic_long_read(&mcs_op_statistics[op].total);
43512+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43513+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43514 max = mcs_op_statistics[op].max;
43515 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43516 count ? total / count : 0, max);
43517diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43518index 5c3ce24..4915ccb 100644
43519--- a/drivers/misc/sgi-gru/grutables.h
43520+++ b/drivers/misc/sgi-gru/grutables.h
43521@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43522 * GRU statistics.
43523 */
43524 struct gru_stats_s {
43525- atomic_long_t vdata_alloc;
43526- atomic_long_t vdata_free;
43527- atomic_long_t gts_alloc;
43528- atomic_long_t gts_free;
43529- atomic_long_t gms_alloc;
43530- atomic_long_t gms_free;
43531- atomic_long_t gts_double_allocate;
43532- atomic_long_t assign_context;
43533- atomic_long_t assign_context_failed;
43534- atomic_long_t free_context;
43535- atomic_long_t load_user_context;
43536- atomic_long_t load_kernel_context;
43537- atomic_long_t lock_kernel_context;
43538- atomic_long_t unlock_kernel_context;
43539- atomic_long_t steal_user_context;
43540- atomic_long_t steal_kernel_context;
43541- atomic_long_t steal_context_failed;
43542- atomic_long_t nopfn;
43543- atomic_long_t asid_new;
43544- atomic_long_t asid_next;
43545- atomic_long_t asid_wrap;
43546- atomic_long_t asid_reuse;
43547- atomic_long_t intr;
43548- atomic_long_t intr_cbr;
43549- atomic_long_t intr_tfh;
43550- atomic_long_t intr_spurious;
43551- atomic_long_t intr_mm_lock_failed;
43552- atomic_long_t call_os;
43553- atomic_long_t call_os_wait_queue;
43554- atomic_long_t user_flush_tlb;
43555- atomic_long_t user_unload_context;
43556- atomic_long_t user_exception;
43557- atomic_long_t set_context_option;
43558- atomic_long_t check_context_retarget_intr;
43559- atomic_long_t check_context_unload;
43560- atomic_long_t tlb_dropin;
43561- atomic_long_t tlb_preload_page;
43562- atomic_long_t tlb_dropin_fail_no_asid;
43563- atomic_long_t tlb_dropin_fail_upm;
43564- atomic_long_t tlb_dropin_fail_invalid;
43565- atomic_long_t tlb_dropin_fail_range_active;
43566- atomic_long_t tlb_dropin_fail_idle;
43567- atomic_long_t tlb_dropin_fail_fmm;
43568- atomic_long_t tlb_dropin_fail_no_exception;
43569- atomic_long_t tfh_stale_on_fault;
43570- atomic_long_t mmu_invalidate_range;
43571- atomic_long_t mmu_invalidate_page;
43572- atomic_long_t flush_tlb;
43573- atomic_long_t flush_tlb_gru;
43574- atomic_long_t flush_tlb_gru_tgh;
43575- atomic_long_t flush_tlb_gru_zero_asid;
43576+ atomic_long_unchecked_t vdata_alloc;
43577+ atomic_long_unchecked_t vdata_free;
43578+ atomic_long_unchecked_t gts_alloc;
43579+ atomic_long_unchecked_t gts_free;
43580+ atomic_long_unchecked_t gms_alloc;
43581+ atomic_long_unchecked_t gms_free;
43582+ atomic_long_unchecked_t gts_double_allocate;
43583+ atomic_long_unchecked_t assign_context;
43584+ atomic_long_unchecked_t assign_context_failed;
43585+ atomic_long_unchecked_t free_context;
43586+ atomic_long_unchecked_t load_user_context;
43587+ atomic_long_unchecked_t load_kernel_context;
43588+ atomic_long_unchecked_t lock_kernel_context;
43589+ atomic_long_unchecked_t unlock_kernel_context;
43590+ atomic_long_unchecked_t steal_user_context;
43591+ atomic_long_unchecked_t steal_kernel_context;
43592+ atomic_long_unchecked_t steal_context_failed;
43593+ atomic_long_unchecked_t nopfn;
43594+ atomic_long_unchecked_t asid_new;
43595+ atomic_long_unchecked_t asid_next;
43596+ atomic_long_unchecked_t asid_wrap;
43597+ atomic_long_unchecked_t asid_reuse;
43598+ atomic_long_unchecked_t intr;
43599+ atomic_long_unchecked_t intr_cbr;
43600+ atomic_long_unchecked_t intr_tfh;
43601+ atomic_long_unchecked_t intr_spurious;
43602+ atomic_long_unchecked_t intr_mm_lock_failed;
43603+ atomic_long_unchecked_t call_os;
43604+ atomic_long_unchecked_t call_os_wait_queue;
43605+ atomic_long_unchecked_t user_flush_tlb;
43606+ atomic_long_unchecked_t user_unload_context;
43607+ atomic_long_unchecked_t user_exception;
43608+ atomic_long_unchecked_t set_context_option;
43609+ atomic_long_unchecked_t check_context_retarget_intr;
43610+ atomic_long_unchecked_t check_context_unload;
43611+ atomic_long_unchecked_t tlb_dropin;
43612+ atomic_long_unchecked_t tlb_preload_page;
43613+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43614+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43615+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43616+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43617+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43618+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43619+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43620+ atomic_long_unchecked_t tfh_stale_on_fault;
43621+ atomic_long_unchecked_t mmu_invalidate_range;
43622+ atomic_long_unchecked_t mmu_invalidate_page;
43623+ atomic_long_unchecked_t flush_tlb;
43624+ atomic_long_unchecked_t flush_tlb_gru;
43625+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43626+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43627
43628- atomic_long_t copy_gpa;
43629- atomic_long_t read_gpa;
43630+ atomic_long_unchecked_t copy_gpa;
43631+ atomic_long_unchecked_t read_gpa;
43632
43633- atomic_long_t mesq_receive;
43634- atomic_long_t mesq_receive_none;
43635- atomic_long_t mesq_send;
43636- atomic_long_t mesq_send_failed;
43637- atomic_long_t mesq_noop;
43638- atomic_long_t mesq_send_unexpected_error;
43639- atomic_long_t mesq_send_lb_overflow;
43640- atomic_long_t mesq_send_qlimit_reached;
43641- atomic_long_t mesq_send_amo_nacked;
43642- atomic_long_t mesq_send_put_nacked;
43643- atomic_long_t mesq_page_overflow;
43644- atomic_long_t mesq_qf_locked;
43645- atomic_long_t mesq_qf_noop_not_full;
43646- atomic_long_t mesq_qf_switch_head_failed;
43647- atomic_long_t mesq_qf_unexpected_error;
43648- atomic_long_t mesq_noop_unexpected_error;
43649- atomic_long_t mesq_noop_lb_overflow;
43650- atomic_long_t mesq_noop_qlimit_reached;
43651- atomic_long_t mesq_noop_amo_nacked;
43652- atomic_long_t mesq_noop_put_nacked;
43653- atomic_long_t mesq_noop_page_overflow;
43654+ atomic_long_unchecked_t mesq_receive;
43655+ atomic_long_unchecked_t mesq_receive_none;
43656+ atomic_long_unchecked_t mesq_send;
43657+ atomic_long_unchecked_t mesq_send_failed;
43658+ atomic_long_unchecked_t mesq_noop;
43659+ atomic_long_unchecked_t mesq_send_unexpected_error;
43660+ atomic_long_unchecked_t mesq_send_lb_overflow;
43661+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43662+ atomic_long_unchecked_t mesq_send_amo_nacked;
43663+ atomic_long_unchecked_t mesq_send_put_nacked;
43664+ atomic_long_unchecked_t mesq_page_overflow;
43665+ atomic_long_unchecked_t mesq_qf_locked;
43666+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43667+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43668+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43669+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43670+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43671+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43672+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43673+ atomic_long_unchecked_t mesq_noop_put_nacked;
43674+ atomic_long_unchecked_t mesq_noop_page_overflow;
43675
43676 };
43677
43678@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43679 tghop_invalidate, mcsop_last};
43680
43681 struct mcs_op_statistic {
43682- atomic_long_t count;
43683- atomic_long_t total;
43684+ atomic_long_unchecked_t count;
43685+ atomic_long_unchecked_t total;
43686 unsigned long max;
43687 };
43688
43689@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43690
43691 #define STAT(id) do { \
43692 if (gru_options & OPT_STATS) \
43693- atomic_long_inc(&gru_stats.id); \
43694+ atomic_long_inc_unchecked(&gru_stats.id); \
43695 } while (0)
43696
43697 #ifdef CONFIG_SGI_GRU_DEBUG
43698diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43699index c862cd4..0d176fe 100644
43700--- a/drivers/misc/sgi-xp/xp.h
43701+++ b/drivers/misc/sgi-xp/xp.h
43702@@ -288,7 +288,7 @@ struct xpc_interface {
43703 xpc_notify_func, void *);
43704 void (*received) (short, int, void *);
43705 enum xp_retval (*partid_to_nasids) (short, void *);
43706-};
43707+} __no_const;
43708
43709 extern struct xpc_interface xpc_interface;
43710
43711diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43712index b94d5f7..7f494c5 100644
43713--- a/drivers/misc/sgi-xp/xpc.h
43714+++ b/drivers/misc/sgi-xp/xpc.h
43715@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43716 void (*received_payload) (struct xpc_channel *, void *);
43717 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43718 };
43719+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43720
43721 /* struct xpc_partition act_state values (for XPC HB) */
43722
43723@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43724 /* found in xpc_main.c */
43725 extern struct device *xpc_part;
43726 extern struct device *xpc_chan;
43727-extern struct xpc_arch_operations xpc_arch_ops;
43728+extern xpc_arch_operations_no_const xpc_arch_ops;
43729 extern int xpc_disengage_timelimit;
43730 extern int xpc_disengage_timedout;
43731 extern int xpc_activate_IRQ_rcvd;
43732diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43733index 82dc574..8539ab2 100644
43734--- a/drivers/misc/sgi-xp/xpc_main.c
43735+++ b/drivers/misc/sgi-xp/xpc_main.c
43736@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43737 .notifier_call = xpc_system_die,
43738 };
43739
43740-struct xpc_arch_operations xpc_arch_ops;
43741+xpc_arch_operations_no_const xpc_arch_ops;
43742
43743 /*
43744 * Timer function to enforce the timelimit on the partition disengage.
43745@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43746
43747 if (((die_args->trapnr == X86_TRAP_MF) ||
43748 (die_args->trapnr == X86_TRAP_XF)) &&
43749- !user_mode_vm(die_args->regs))
43750+ !user_mode(die_args->regs))
43751 xpc_die_deactivate();
43752
43753 break;
43754diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43755index 837fc73..acb5862 100644
43756--- a/drivers/mmc/core/mmc_ops.c
43757+++ b/drivers/mmc/core/mmc_ops.c
43758@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43759 void *data_buf;
43760 int is_on_stack;
43761
43762- is_on_stack = object_is_on_stack(buf);
43763+ is_on_stack = object_starts_on_stack(buf);
43764 if (is_on_stack) {
43765 /*
43766 * dma onto stack is unsafe/nonportable, but callers to this
43767diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43768index 81b2994..dce857e 100644
43769--- a/drivers/mmc/host/dw_mmc.h
43770+++ b/drivers/mmc/host/dw_mmc.h
43771@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43772 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43773 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43774 int (*parse_dt)(struct dw_mci *host);
43775-};
43776+} __do_const;
43777 #endif /* _DW_MMC_H_ */
43778diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43779index c3785ed..1984c44 100644
43780--- a/drivers/mmc/host/mmci.c
43781+++ b/drivers/mmc/host/mmci.c
43782@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43783 }
43784
43785 if (variant->busy_detect) {
43786- mmci_ops.card_busy = mmci_card_busy;
43787+ pax_open_kernel();
43788+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43789+ pax_close_kernel();
43790 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43791 }
43792
43793diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43794index 926aaf6..8e153e2 100644
43795--- a/drivers/mmc/host/sdhci-s3c.c
43796+++ b/drivers/mmc/host/sdhci-s3c.c
43797@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43798 * we can use overriding functions instead of default.
43799 */
43800 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43801- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43802- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43803- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43804+ pax_open_kernel();
43805+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43806+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43807+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43808+ pax_close_kernel();
43809 }
43810
43811 /* It supports additional host capabilities if needed */
43812diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43813index 0c8bb6b..6f35deb 100644
43814--- a/drivers/mtd/nand/denali.c
43815+++ b/drivers/mtd/nand/denali.c
43816@@ -24,6 +24,7 @@
43817 #include <linux/slab.h>
43818 #include <linux/mtd/mtd.h>
43819 #include <linux/module.h>
43820+#include <linux/slab.h>
43821
43822 #include "denali.h"
43823
43824diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43825index 51b9d6a..52af9a7 100644
43826--- a/drivers/mtd/nftlmount.c
43827+++ b/drivers/mtd/nftlmount.c
43828@@ -24,6 +24,7 @@
43829 #include <asm/errno.h>
43830 #include <linux/delay.h>
43831 #include <linux/slab.h>
43832+#include <linux/sched.h>
43833 #include <linux/mtd/mtd.h>
43834 #include <linux/mtd/nand.h>
43835 #include <linux/mtd/nftl.h>
43836diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43837index f9d5615..99dd95f 100644
43838--- a/drivers/mtd/sm_ftl.c
43839+++ b/drivers/mtd/sm_ftl.c
43840@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43841 #define SM_CIS_VENDOR_OFFSET 0x59
43842 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43843 {
43844- struct attribute_group *attr_group;
43845+ attribute_group_no_const *attr_group;
43846 struct attribute **attributes;
43847 struct sm_sysfs_attribute *vendor_attribute;
43848
43849diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43850index 5e31046..82f8ddc 100644
43851--- a/drivers/net/bonding/bond_main.c
43852+++ b/drivers/net/bonding/bond_main.c
43853@@ -4839,7 +4839,7 @@ static unsigned int bond_get_num_tx_queues(void)
43854 return tx_queues;
43855 }
43856
43857-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43858+static struct rtnl_link_ops bond_link_ops = {
43859 .kind = "bond",
43860 .priv_size = sizeof(struct bonding),
43861 .setup = bond_setup,
43862@@ -4964,8 +4964,8 @@ static void __exit bonding_exit(void)
43863
43864 bond_destroy_debugfs();
43865
43866- rtnl_link_unregister(&bond_link_ops);
43867 unregister_pernet_subsys(&bond_net_ops);
43868+ rtnl_link_unregister(&bond_link_ops);
43869
43870 #ifdef CONFIG_NET_POLL_CONTROLLER
43871 /*
43872diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43873index e1d2643..7f4133b 100644
43874--- a/drivers/net/ethernet/8390/ax88796.c
43875+++ b/drivers/net/ethernet/8390/ax88796.c
43876@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43877 if (ax->plat->reg_offsets)
43878 ei_local->reg_offset = ax->plat->reg_offsets;
43879 else {
43880+ resource_size_t _mem_size = mem_size;
43881+ do_div(_mem_size, 0x18);
43882 ei_local->reg_offset = ax->reg_offsets;
43883 for (ret = 0; ret < 0x18; ret++)
43884- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43885+ ax->reg_offsets[ret] = _mem_size * ret;
43886 }
43887
43888 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43889diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43890index c07a6d0..ca88c45 100644
43891--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43892+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43893@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43894 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43895 {
43896 /* RX_MODE controlling object */
43897- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43898+ bnx2x_init_rx_mode_obj(bp);
43899
43900 /* multicast configuration controlling object */
43901 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43902diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43903index 8f03c98..dd0ef10 100644
43904--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43905+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43906@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43907 return rc;
43908 }
43909
43910-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43911- struct bnx2x_rx_mode_obj *o)
43912+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43913 {
43914 if (CHIP_IS_E1x(bp)) {
43915- o->wait_comp = bnx2x_empty_rx_mode_wait;
43916- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43917+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43918+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43919 } else {
43920- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43921- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43922+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43923+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43924 }
43925 }
43926
43927diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43928index 798dfe9..05d0a44 100644
43929--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43930+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43931@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43932
43933 /********************* RX MODE ****************/
43934
43935-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43936- struct bnx2x_rx_mode_obj *o);
43937+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43938
43939 /**
43940 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43941diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43942index cd63d11..b67dd78 100644
43943--- a/drivers/net/ethernet/broadcom/tg3.h
43944+++ b/drivers/net/ethernet/broadcom/tg3.h
43945@@ -147,6 +147,7 @@
43946 #define CHIPREV_ID_5750_A0 0x4000
43947 #define CHIPREV_ID_5750_A1 0x4001
43948 #define CHIPREV_ID_5750_A3 0x4003
43949+#define CHIPREV_ID_5750_C1 0x4201
43950 #define CHIPREV_ID_5750_C2 0x4202
43951 #define CHIPREV_ID_5752_A0_HW 0x5000
43952 #define CHIPREV_ID_5752_A0 0x6000
43953diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43954index 8cffcdf..aadf043 100644
43955--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43956+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43957@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
43958 */
43959 struct l2t_skb_cb {
43960 arp_failure_handler_func arp_failure_handler;
43961-};
43962+} __no_const;
43963
43964 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
43965
43966diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43967index 9c89dc8..725ecc3 100644
43968--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
43969+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43970@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
43971 flits = skb_transport_offset(skb) / 8;
43972 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
43973 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
43974- skb->tail - skb->transport_header,
43975+ skb_tail_pointer(skb) - skb_transport_header(skb),
43976 adap->pdev);
43977 if (need_skb_unmap()) {
43978 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
43979diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
43980index 4c83003..2a2a5b9 100644
43981--- a/drivers/net/ethernet/dec/tulip/de4x5.c
43982+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
43983@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43984 for (i=0; i<ETH_ALEN; i++) {
43985 tmp.addr[i] = dev->dev_addr[i];
43986 }
43987- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43988+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43989 break;
43990
43991 case DE4X5_SET_HWADDR: /* Set the hardware address */
43992@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43993 spin_lock_irqsave(&lp->lock, flags);
43994 memcpy(&statbuf, &lp->pktStats, ioc->len);
43995 spin_unlock_irqrestore(&lp->lock, flags);
43996- if (copy_to_user(ioc->data, &statbuf, ioc->len))
43997+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
43998 return -EFAULT;
43999 break;
44000 }
44001diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44002index 3d91a5e..1014702 100644
44003--- a/drivers/net/ethernet/emulex/benet/be_main.c
44004+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44005@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44006
44007 if (wrapped)
44008 newacc += 65536;
44009- ACCESS_ONCE(*acc) = newacc;
44010+ ACCESS_ONCE_RW(*acc) = newacc;
44011 }
44012
44013 void populate_erx_stats(struct be_adapter *adapter,
44014diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44015index 934e1ae..b262e6b 100644
44016--- a/drivers/net/ethernet/faraday/ftgmac100.c
44017+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44018@@ -31,6 +31,8 @@
44019 #include <linux/netdevice.h>
44020 #include <linux/phy.h>
44021 #include <linux/platform_device.h>
44022+#include <linux/interrupt.h>
44023+#include <linux/irqreturn.h>
44024 #include <net/ip.h>
44025
44026 #include "ftgmac100.h"
44027diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44028index 4658f4c..407d155 100644
44029--- a/drivers/net/ethernet/faraday/ftmac100.c
44030+++ b/drivers/net/ethernet/faraday/ftmac100.c
44031@@ -31,6 +31,8 @@
44032 #include <linux/module.h>
44033 #include <linux/netdevice.h>
44034 #include <linux/platform_device.h>
44035+#include <linux/interrupt.h>
44036+#include <linux/irqreturn.h>
44037
44038 #include "ftmac100.h"
44039
44040diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
44041index 85fe7b5..e2da180 100644
44042--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
44043+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
44044@@ -2637,6 +2637,8 @@ static int igb_set_eee(struct net_device *netdev,
44045 (hw->phy.media_type != e1000_media_type_copper))
44046 return -EOPNOTSUPP;
44047
44048+ memset(&eee_curr, 0, sizeof(struct ethtool_eee));
44049+
44050 ret_val = igb_get_eee(netdev, &eee_curr);
44051 if (ret_val)
44052 return ret_val;
44053diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44054index 331987d..3be1135 100644
44055--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44056+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44057@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44058 }
44059
44060 /* update the base incval used to calculate frequency adjustment */
44061- ACCESS_ONCE(adapter->base_incval) = incval;
44062+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44063 smp_mb();
44064
44065 /* need lock to prevent incorrect read while modifying cyclecounter */
44066diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44067index fbe5363..266b4e3 100644
44068--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44069+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44070@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44071 struct __vxge_hw_fifo *fifo;
44072 struct vxge_hw_fifo_config *config;
44073 u32 txdl_size, txdl_per_memblock;
44074- struct vxge_hw_mempool_cbs fifo_mp_callback;
44075+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44076+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44077+ };
44078+
44079 struct __vxge_hw_virtualpath *vpath;
44080
44081 if ((vp == NULL) || (attr == NULL)) {
44082@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44083 goto exit;
44084 }
44085
44086- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44087-
44088 fifo->mempool =
44089 __vxge_hw_mempool_create(vpath->hldev,
44090 fifo->config->memblock_size,
44091diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44092index 345d987..af69721 100644
44093--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44094+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44095@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44096 op_mode = QLC_83XX_DEFAULT_OPMODE;
44097
44098 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44099- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44100+ pax_open_kernel();
44101+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44102+ pax_close_kernel();
44103 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44104 } else {
44105 return -EIO;
44106diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44107index 599d1fd..59868fe 100644
44108--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44109+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44110@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44111 case QLCNIC_NON_PRIV_FUNC:
44112 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44113 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44114- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44115+ pax_open_kernel();
44116+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44117+ pax_close_kernel();
44118 break;
44119 case QLCNIC_PRIV_FUNC:
44120 ahw->op_mode = QLCNIC_PRIV_FUNC;
44121 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44122- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44123+ pax_open_kernel();
44124+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44125+ pax_close_kernel();
44126 break;
44127 case QLCNIC_MGMT_FUNC:
44128 ahw->op_mode = QLCNIC_MGMT_FUNC;
44129 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44130- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44131+ pax_open_kernel();
44132+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44133+ pax_close_kernel();
44134 break;
44135 default:
44136 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44137diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44138index 7ba68e0..618c73d 100644
44139--- a/drivers/net/ethernet/realtek/r8169.c
44140+++ b/drivers/net/ethernet/realtek/r8169.c
44141@@ -759,22 +759,22 @@ struct rtl8169_private {
44142 struct mdio_ops {
44143 void (*write)(struct rtl8169_private *, int, int);
44144 int (*read)(struct rtl8169_private *, int);
44145- } mdio_ops;
44146+ } __no_const mdio_ops;
44147
44148 struct pll_power_ops {
44149 void (*down)(struct rtl8169_private *);
44150 void (*up)(struct rtl8169_private *);
44151- } pll_power_ops;
44152+ } __no_const pll_power_ops;
44153
44154 struct jumbo_ops {
44155 void (*enable)(struct rtl8169_private *);
44156 void (*disable)(struct rtl8169_private *);
44157- } jumbo_ops;
44158+ } __no_const jumbo_ops;
44159
44160 struct csi_ops {
44161 void (*write)(struct rtl8169_private *, int, int);
44162 u32 (*read)(struct rtl8169_private *, int);
44163- } csi_ops;
44164+ } __no_const csi_ops;
44165
44166 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44167 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44168diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44169index b495394..0748c54 100644
44170--- a/drivers/net/ethernet/sfc/ptp.c
44171+++ b/drivers/net/ethernet/sfc/ptp.c
44172@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44173 (u32)((u64)ptp->start.dma_addr >> 32));
44174
44175 /* Clear flag that signals MC ready */
44176- ACCESS_ONCE(*start) = 0;
44177+ ACCESS_ONCE_RW(*start) = 0;
44178 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44179 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44180
44181diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44182index 50617c5..b13724c 100644
44183--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44184+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44185@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44186
44187 writel(value, ioaddr + MMC_CNTRL);
44188
44189- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44190- MMC_CNTRL, value);
44191+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44192+// MMC_CNTRL, value);
44193 }
44194
44195 /* To mask all all interrupts.*/
44196diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44197index e6fe0d8..2b7d752 100644
44198--- a/drivers/net/hyperv/hyperv_net.h
44199+++ b/drivers/net/hyperv/hyperv_net.h
44200@@ -101,7 +101,7 @@ struct rndis_device {
44201
44202 enum rndis_device_state state;
44203 bool link_state;
44204- atomic_t new_req_id;
44205+ atomic_unchecked_t new_req_id;
44206
44207 spinlock_t request_lock;
44208 struct list_head req_list;
44209diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44210index 0775f0a..d4fb316 100644
44211--- a/drivers/net/hyperv/rndis_filter.c
44212+++ b/drivers/net/hyperv/rndis_filter.c
44213@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44214 * template
44215 */
44216 set = &rndis_msg->msg.set_req;
44217- set->req_id = atomic_inc_return(&dev->new_req_id);
44218+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44219
44220 /* Add to the request list */
44221 spin_lock_irqsave(&dev->request_lock, flags);
44222@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44223
44224 /* Setup the rndis set */
44225 halt = &request->request_msg.msg.halt_req;
44226- halt->req_id = atomic_inc_return(&dev->new_req_id);
44227+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44228
44229 /* Ignore return since this msg is optional. */
44230 rndis_filter_send_request(dev, request);
44231diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44232index bf0d55e..82bcfbd1 100644
44233--- a/drivers/net/ieee802154/fakehard.c
44234+++ b/drivers/net/ieee802154/fakehard.c
44235@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44236 phy->transmit_power = 0xbf;
44237
44238 dev->netdev_ops = &fake_ops;
44239- dev->ml_priv = &fake_mlme;
44240+ dev->ml_priv = (void *)&fake_mlme;
44241
44242 priv = netdev_priv(dev);
44243 priv->phy = phy;
44244diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44245index 16b43bf..ead0c35 100644
44246--- a/drivers/net/macvlan.c
44247+++ b/drivers/net/macvlan.c
44248@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44249 int macvlan_link_register(struct rtnl_link_ops *ops)
44250 {
44251 /* common fields */
44252- ops->priv_size = sizeof(struct macvlan_dev);
44253- ops->validate = macvlan_validate;
44254- ops->maxtype = IFLA_MACVLAN_MAX;
44255- ops->policy = macvlan_policy;
44256- ops->changelink = macvlan_changelink;
44257- ops->get_size = macvlan_get_size;
44258- ops->fill_info = macvlan_fill_info;
44259+ pax_open_kernel();
44260+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44261+ *(void **)&ops->validate = macvlan_validate;
44262+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44263+ *(const void **)&ops->policy = macvlan_policy;
44264+ *(void **)&ops->changelink = macvlan_changelink;
44265+ *(void **)&ops->get_size = macvlan_get_size;
44266+ *(void **)&ops->fill_info = macvlan_fill_info;
44267+ pax_close_kernel();
44268
44269 return rtnl_link_register(ops);
44270 };
44271@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44272 return NOTIFY_DONE;
44273 }
44274
44275-static struct notifier_block macvlan_notifier_block __read_mostly = {
44276+static struct notifier_block macvlan_notifier_block = {
44277 .notifier_call = macvlan_device_event,
44278 };
44279
44280diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44281index ea53abb..2e4d087 100644
44282--- a/drivers/net/macvtap.c
44283+++ b/drivers/net/macvtap.c
44284@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44285 return NOTIFY_DONE;
44286 }
44287
44288-static struct notifier_block macvtap_notifier_block __read_mostly = {
44289+static struct notifier_block macvtap_notifier_block = {
44290 .notifier_call = macvtap_device_event,
44291 };
44292
44293diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44294index daec9b0..6428fcb 100644
44295--- a/drivers/net/phy/mdio-bitbang.c
44296+++ b/drivers/net/phy/mdio-bitbang.c
44297@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44298 struct mdiobb_ctrl *ctrl = bus->priv;
44299
44300 module_put(ctrl->ops->owner);
44301+ mdiobus_unregister(bus);
44302 mdiobus_free(bus);
44303 }
44304 EXPORT_SYMBOL(free_mdio_bitbang);
44305diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44306index 72ff14b..11d442d 100644
44307--- a/drivers/net/ppp/ppp_generic.c
44308+++ b/drivers/net/ppp/ppp_generic.c
44309@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44310 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44311 struct ppp_stats stats;
44312 struct ppp_comp_stats cstats;
44313- char *vers;
44314
44315 switch (cmd) {
44316 case SIOCGPPPSTATS:
44317@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44318 break;
44319
44320 case SIOCGPPPVER:
44321- vers = PPP_VERSION;
44322- if (copy_to_user(addr, vers, strlen(vers) + 1))
44323+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44324 break;
44325 err = 0;
44326 break;
44327diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44328index 1252d9c..80e660b 100644
44329--- a/drivers/net/slip/slhc.c
44330+++ b/drivers/net/slip/slhc.c
44331@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44332 register struct tcphdr *thp;
44333 register struct iphdr *ip;
44334 register struct cstate *cs;
44335- int len, hdrlen;
44336+ long len, hdrlen;
44337 unsigned char *cp = icp;
44338
44339 /* We've got a compressed packet; read the change byte */
44340diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44341index bff7e0b..7315137 100644
44342--- a/drivers/net/team/team.c
44343+++ b/drivers/net/team/team.c
44344@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44345 return NOTIFY_DONE;
44346 }
44347
44348-static struct notifier_block team_notifier_block __read_mostly = {
44349+static struct notifier_block team_notifier_block = {
44350 .notifier_call = team_device_event,
44351 };
44352
44353diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44354index 68b9aa3..b3c20f3 100644
44355--- a/drivers/net/tun.c
44356+++ b/drivers/net/tun.c
44357@@ -1874,7 +1874,7 @@ unlock:
44358 }
44359
44360 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44361- unsigned long arg, int ifreq_len)
44362+ unsigned long arg, size_t ifreq_len)
44363 {
44364 struct tun_file *tfile = file->private_data;
44365 struct tun_struct *tun;
44366@@ -1886,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44367 int vnet_hdr_sz;
44368 int ret;
44369
44370+ if (ifreq_len > sizeof ifr)
44371+ return -EFAULT;
44372+
44373 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44374 if (copy_from_user(&ifr, argp, ifreq_len))
44375 return -EFAULT;
44376diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44377index 86292e6..8d34433 100644
44378--- a/drivers/net/usb/hso.c
44379+++ b/drivers/net/usb/hso.c
44380@@ -71,7 +71,7 @@
44381 #include <asm/byteorder.h>
44382 #include <linux/serial_core.h>
44383 #include <linux/serial.h>
44384-
44385+#include <asm/local.h>
44386
44387 #define MOD_AUTHOR "Option Wireless"
44388 #define MOD_DESCRIPTION "USB High Speed Option driver"
44389@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44390 struct urb *urb;
44391
44392 urb = serial->rx_urb[0];
44393- if (serial->port.count > 0) {
44394+ if (atomic_read(&serial->port.count) > 0) {
44395 count = put_rxbuf_data(urb, serial);
44396 if (count == -1)
44397 return;
44398@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44399 DUMP1(urb->transfer_buffer, urb->actual_length);
44400
44401 /* Anyone listening? */
44402- if (serial->port.count == 0)
44403+ if (atomic_read(&serial->port.count) == 0)
44404 return;
44405
44406 if (status == 0) {
44407@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44408 tty_port_tty_set(&serial->port, tty);
44409
44410 /* check for port already opened, if not set the termios */
44411- serial->port.count++;
44412- if (serial->port.count == 1) {
44413+ if (atomic_inc_return(&serial->port.count) == 1) {
44414 serial->rx_state = RX_IDLE;
44415 /* Force default termio settings */
44416 _hso_serial_set_termios(tty, NULL);
44417@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44418 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44419 if (result) {
44420 hso_stop_serial_device(serial->parent);
44421- serial->port.count--;
44422+ atomic_dec(&serial->port.count);
44423 kref_put(&serial->parent->ref, hso_serial_ref_free);
44424 }
44425 } else {
44426@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44427
44428 /* reset the rts and dtr */
44429 /* do the actual close */
44430- serial->port.count--;
44431+ atomic_dec(&serial->port.count);
44432
44433- if (serial->port.count <= 0) {
44434- serial->port.count = 0;
44435+ if (atomic_read(&serial->port.count) <= 0) {
44436+ atomic_set(&serial->port.count, 0);
44437 tty_port_tty_set(&serial->port, NULL);
44438 if (!usb_gone)
44439 hso_stop_serial_device(serial->parent);
44440@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44441
44442 /* the actual setup */
44443 spin_lock_irqsave(&serial->serial_lock, flags);
44444- if (serial->port.count)
44445+ if (atomic_read(&serial->port.count))
44446 _hso_serial_set_termios(tty, old);
44447 else
44448 tty->termios = *old;
44449@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44450 D1("Pending read interrupt on port %d\n", i);
44451 spin_lock(&serial->serial_lock);
44452 if (serial->rx_state == RX_IDLE &&
44453- serial->port.count > 0) {
44454+ atomic_read(&serial->port.count) > 0) {
44455 /* Setup and send a ctrl req read on
44456 * port i */
44457 if (!serial->rx_urb_filled[0]) {
44458@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44459 /* Start all serial ports */
44460 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44461 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44462- if (dev2ser(serial_table[i])->port.count) {
44463+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44464 result =
44465 hso_start_serial_device(serial_table[i], GFP_NOIO);
44466 hso_kick_transmit(dev2ser(serial_table[i]));
44467diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44468index a79e9d3..78cd4fa 100644
44469--- a/drivers/net/usb/sierra_net.c
44470+++ b/drivers/net/usb/sierra_net.c
44471@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44472 /* atomic counter partially included in MAC address to make sure 2 devices
44473 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44474 */
44475-static atomic_t iface_counter = ATOMIC_INIT(0);
44476+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44477
44478 /*
44479 * SYNC Timer Delay definition used to set the expiry time
44480@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44481 dev->net->netdev_ops = &sierra_net_device_ops;
44482
44483 /* change MAC addr to include, ifacenum, and to be unique */
44484- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44485+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44486 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44487
44488 /* we will have to manufacture ethernet headers, prepare template */
44489diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44490index 8a05d77..ba8b9c5 100644
44491--- a/drivers/net/vxlan.c
44492+++ b/drivers/net/vxlan.c
44493@@ -1870,7 +1870,7 @@ nla_put_failure:
44494 return -EMSGSIZE;
44495 }
44496
44497-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44498+static struct rtnl_link_ops vxlan_link_ops = {
44499 .kind = "vxlan",
44500 .maxtype = IFLA_VXLAN_MAX,
44501 .policy = vxlan_policy,
44502diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
44503index 3f0c4f2..bcfff0d 100644
44504--- a/drivers/net/wan/farsync.c
44505+++ b/drivers/net/wan/farsync.c
44506@@ -1972,6 +1972,7 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port,
44507 }
44508
44509 i = port->index;
44510+ memset(&sync, 0, sizeof(sync));
44511 sync.clock_rate = FST_RDL(card, portConfig[i].lineSpeed);
44512 /* Lucky card and linux use same encoding here */
44513 sync.clock_type = FST_RDB(card, portConfig[i].internalClock) ==
44514diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
44515index 6a24a5a..4c0a697 100644
44516--- a/drivers/net/wan/wanxl.c
44517+++ b/drivers/net/wan/wanxl.c
44518@@ -355,6 +355,7 @@ static int wanxl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44519 ifr->ifr_settings.size = size; /* data size wanted */
44520 return -ENOBUFS;
44521 }
44522+ memset(&line, 0, sizeof(line));
44523 line.clock_type = get_status(port)->clocking;
44524 line.clock_rate = 0;
44525 line.loopback = 0;
44526diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44527index 0b60295..b8bfa5b 100644
44528--- a/drivers/net/wimax/i2400m/rx.c
44529+++ b/drivers/net/wimax/i2400m/rx.c
44530@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44531 if (i2400m->rx_roq == NULL)
44532 goto error_roq_alloc;
44533
44534- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44535+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44536 GFP_KERNEL);
44537 if (rd == NULL) {
44538 result = -ENOMEM;
44539diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44540index 34c8a33..3261fdc 100644
44541--- a/drivers/net/wireless/at76c50x-usb.c
44542+++ b/drivers/net/wireless/at76c50x-usb.c
44543@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44544 }
44545
44546 /* Convert timeout from the DFU status to jiffies */
44547-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44548+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44549 {
44550 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44551 | (s->poll_timeout[1] << 8)
44552diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44553index 2b3426b..1f564be 100644
44554--- a/drivers/net/wireless/ath/ath10k/core.c
44555+++ b/drivers/net/wireless/ath/ath10k/core.c
44556@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44557
44558 int ath10k_core_register(struct ath10k *ar)
44559 {
44560- struct ath10k_htc_ops htc_ops;
44561+ static struct ath10k_htc_ops htc_ops = {
44562+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44563+ };
44564 struct bmi_target_info target_info;
44565 int status;
44566
44567@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44568 if (status)
44569 goto err;
44570
44571- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44572-
44573 ar->htc = ath10k_htc_create(ar, &htc_ops);
44574 if (IS_ERR(ar->htc)) {
44575 status = PTR_ERR(ar->htc);
44576diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44577index 74363c9..237b926 100644
44578--- a/drivers/net/wireless/ath/ath10k/htc.c
44579+++ b/drivers/net/wireless/ath/ath10k/htc.c
44580@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44581 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44582 struct ath10k_htc_ops *htc_ops)
44583 {
44584- struct ath10k_hif_cb htc_callbacks;
44585+ static struct ath10k_hif_cb htc_callbacks = {
44586+ .rx_completion = ath10k_htc_rx_completion_handler,
44587+ .tx_completion = ath10k_htc_tx_completion_handler,
44588+ };
44589 struct ath10k_htc_ep *ep = NULL;
44590 struct ath10k_htc *htc = NULL;
44591
44592@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44593 ath10k_htc_reset_endpoint_states(htc);
44594
44595 /* setup HIF layer callbacks */
44596- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44597- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44598 htc->ar = ar;
44599
44600 /* Get HIF default pipe for HTC message exchange */
44601diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44602index 8d78253..bebbb68 100644
44603--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44604+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44605@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44606 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44607 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44608
44609- ACCESS_ONCE(ads->ds_link) = i->link;
44610- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44611+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44612+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44613
44614 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44615 ctl6 = SM(i->keytype, AR_EncrType);
44616@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44617
44618 if ((i->is_first || i->is_last) &&
44619 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44620- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44621+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44622 | set11nTries(i->rates, 1)
44623 | set11nTries(i->rates, 2)
44624 | set11nTries(i->rates, 3)
44625 | (i->dur_update ? AR_DurUpdateEna : 0)
44626 | SM(0, AR_BurstDur);
44627
44628- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44629+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44630 | set11nRate(i->rates, 1)
44631 | set11nRate(i->rates, 2)
44632 | set11nRate(i->rates, 3);
44633 } else {
44634- ACCESS_ONCE(ads->ds_ctl2) = 0;
44635- ACCESS_ONCE(ads->ds_ctl3) = 0;
44636+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44637+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44638 }
44639
44640 if (!i->is_first) {
44641- ACCESS_ONCE(ads->ds_ctl0) = 0;
44642- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44643- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44644+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44645+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44646+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44647 return;
44648 }
44649
44650@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44651 break;
44652 }
44653
44654- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44655+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44656 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44657 | SM(i->txpower, AR_XmitPower)
44658 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44659@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44660 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44661 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44662
44663- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44664- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44665+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44666+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44667
44668 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44669 return;
44670
44671- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44672+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44673 | set11nPktDurRTSCTS(i->rates, 1);
44674
44675- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44676+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44677 | set11nPktDurRTSCTS(i->rates, 3);
44678
44679- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44680+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44681 | set11nRateFlags(i->rates, 1)
44682 | set11nRateFlags(i->rates, 2)
44683 | set11nRateFlags(i->rates, 3)
44684diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44685index 5163abd..3ada4c2 100644
44686--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44687+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44688@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44689 (i->qcu << AR_TxQcuNum_S) | desc_len;
44690
44691 checksum += val;
44692- ACCESS_ONCE(ads->info) = val;
44693+ ACCESS_ONCE_RW(ads->info) = val;
44694
44695 checksum += i->link;
44696- ACCESS_ONCE(ads->link) = i->link;
44697+ ACCESS_ONCE_RW(ads->link) = i->link;
44698
44699 checksum += i->buf_addr[0];
44700- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44701+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44702 checksum += i->buf_addr[1];
44703- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44704+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44705 checksum += i->buf_addr[2];
44706- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44707+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44708 checksum += i->buf_addr[3];
44709- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44710+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44711
44712 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44713- ACCESS_ONCE(ads->ctl3) = val;
44714+ ACCESS_ONCE_RW(ads->ctl3) = val;
44715 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44716- ACCESS_ONCE(ads->ctl5) = val;
44717+ ACCESS_ONCE_RW(ads->ctl5) = val;
44718 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44719- ACCESS_ONCE(ads->ctl7) = val;
44720+ ACCESS_ONCE_RW(ads->ctl7) = val;
44721 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44722- ACCESS_ONCE(ads->ctl9) = val;
44723+ ACCESS_ONCE_RW(ads->ctl9) = val;
44724
44725 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44726- ACCESS_ONCE(ads->ctl10) = checksum;
44727+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44728
44729 if (i->is_first || i->is_last) {
44730- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44731+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44732 | set11nTries(i->rates, 1)
44733 | set11nTries(i->rates, 2)
44734 | set11nTries(i->rates, 3)
44735 | (i->dur_update ? AR_DurUpdateEna : 0)
44736 | SM(0, AR_BurstDur);
44737
44738- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44739+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44740 | set11nRate(i->rates, 1)
44741 | set11nRate(i->rates, 2)
44742 | set11nRate(i->rates, 3);
44743 } else {
44744- ACCESS_ONCE(ads->ctl13) = 0;
44745- ACCESS_ONCE(ads->ctl14) = 0;
44746+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44747+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44748 }
44749
44750 ads->ctl20 = 0;
44751@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44752
44753 ctl17 = SM(i->keytype, AR_EncrType);
44754 if (!i->is_first) {
44755- ACCESS_ONCE(ads->ctl11) = 0;
44756- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44757- ACCESS_ONCE(ads->ctl15) = 0;
44758- ACCESS_ONCE(ads->ctl16) = 0;
44759- ACCESS_ONCE(ads->ctl17) = ctl17;
44760- ACCESS_ONCE(ads->ctl18) = 0;
44761- ACCESS_ONCE(ads->ctl19) = 0;
44762+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44763+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44764+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44765+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44766+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44767+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44768+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44769 return;
44770 }
44771
44772- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44773+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44774 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44775 | SM(i->txpower, AR_XmitPower)
44776 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44777@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44778 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44779 ctl12 |= SM(val, AR_PAPRDChainMask);
44780
44781- ACCESS_ONCE(ads->ctl12) = ctl12;
44782- ACCESS_ONCE(ads->ctl17) = ctl17;
44783+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44784+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44785
44786- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44787+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44788 | set11nPktDurRTSCTS(i->rates, 1);
44789
44790- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44791+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44792 | set11nPktDurRTSCTS(i->rates, 3);
44793
44794- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44795+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44796 | set11nRateFlags(i->rates, 1)
44797 | set11nRateFlags(i->rates, 2)
44798 | set11nRateFlags(i->rates, 3)
44799 | SM(i->rtscts_rate, AR_RTSCTSRate);
44800
44801- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44802+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44803 }
44804
44805 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44806diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44807index cd74b3a..6a28d24 100644
44808--- a/drivers/net/wireless/ath/ath9k/hw.h
44809+++ b/drivers/net/wireless/ath/ath9k/hw.h
44810@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44811
44812 /* ANI */
44813 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44814-};
44815+} __no_const;
44816
44817 /**
44818 * struct ath_spec_scan - parameters for Atheros spectral scan
44819@@ -721,7 +721,7 @@ struct ath_hw_ops {
44820 struct ath_spec_scan *param);
44821 void (*spectral_scan_trigger)(struct ath_hw *ah);
44822 void (*spectral_scan_wait)(struct ath_hw *ah);
44823-};
44824+} __no_const;
44825
44826 struct ath_nf_limits {
44827 s16 max;
44828diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44829index 9581d07..84f6a76 100644
44830--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44831+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44832@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44833 */
44834 if (il3945_mod_params.disable_hw_scan) {
44835 D_INFO("Disabling hw_scan\n");
44836- il3945_mac_ops.hw_scan = NULL;
44837+ pax_open_kernel();
44838+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44839+ pax_close_kernel();
44840 }
44841
44842 D_INFO("*** LOAD DRIVER ***\n");
44843diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44844index d532948..e0d8bb1 100644
44845--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44846+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44847@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44848 {
44849 struct iwl_priv *priv = file->private_data;
44850 char buf[64];
44851- int buf_size;
44852+ size_t buf_size;
44853 u32 offset, len;
44854
44855 memset(buf, 0, sizeof(buf));
44856@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44857 struct iwl_priv *priv = file->private_data;
44858
44859 char buf[8];
44860- int buf_size;
44861+ size_t buf_size;
44862 u32 reset_flag;
44863
44864 memset(buf, 0, sizeof(buf));
44865@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44866 {
44867 struct iwl_priv *priv = file->private_data;
44868 char buf[8];
44869- int buf_size;
44870+ size_t buf_size;
44871 int ht40;
44872
44873 memset(buf, 0, sizeof(buf));
44874@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44875 {
44876 struct iwl_priv *priv = file->private_data;
44877 char buf[8];
44878- int buf_size;
44879+ size_t buf_size;
44880 int value;
44881
44882 memset(buf, 0, sizeof(buf));
44883@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44884 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44885 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44886
44887-static const char *fmt_value = " %-30s %10u\n";
44888-static const char *fmt_hex = " %-30s 0x%02X\n";
44889-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44890-static const char *fmt_header =
44891+static const char fmt_value[] = " %-30s %10u\n";
44892+static const char fmt_hex[] = " %-30s 0x%02X\n";
44893+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44894+static const char fmt_header[] =
44895 "%-32s current cumulative delta max\n";
44896
44897 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44898@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44899 {
44900 struct iwl_priv *priv = file->private_data;
44901 char buf[8];
44902- int buf_size;
44903+ size_t buf_size;
44904 int clear;
44905
44906 memset(buf, 0, sizeof(buf));
44907@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44908 {
44909 struct iwl_priv *priv = file->private_data;
44910 char buf[8];
44911- int buf_size;
44912+ size_t buf_size;
44913 int trace;
44914
44915 memset(buf, 0, sizeof(buf));
44916@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44917 {
44918 struct iwl_priv *priv = file->private_data;
44919 char buf[8];
44920- int buf_size;
44921+ size_t buf_size;
44922 int missed;
44923
44924 memset(buf, 0, sizeof(buf));
44925@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44926
44927 struct iwl_priv *priv = file->private_data;
44928 char buf[8];
44929- int buf_size;
44930+ size_t buf_size;
44931 int plcp;
44932
44933 memset(buf, 0, sizeof(buf));
44934@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44935
44936 struct iwl_priv *priv = file->private_data;
44937 char buf[8];
44938- int buf_size;
44939+ size_t buf_size;
44940 int flush;
44941
44942 memset(buf, 0, sizeof(buf));
44943@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44944
44945 struct iwl_priv *priv = file->private_data;
44946 char buf[8];
44947- int buf_size;
44948+ size_t buf_size;
44949 int rts;
44950
44951 if (!priv->cfg->ht_params)
44952@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44953 {
44954 struct iwl_priv *priv = file->private_data;
44955 char buf[8];
44956- int buf_size;
44957+ size_t buf_size;
44958
44959 memset(buf, 0, sizeof(buf));
44960 buf_size = min(count, sizeof(buf) - 1);
44961@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44962 struct iwl_priv *priv = file->private_data;
44963 u32 event_log_flag;
44964 char buf[8];
44965- int buf_size;
44966+ size_t buf_size;
44967
44968 /* check that the interface is up */
44969 if (!iwl_is_ready(priv))
44970@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44971 struct iwl_priv *priv = file->private_data;
44972 char buf[8];
44973 u32 calib_disabled;
44974- int buf_size;
44975+ size_t buf_size;
44976
44977 memset(buf, 0, sizeof(buf));
44978 buf_size = min(count, sizeof(buf) - 1);
44979diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44980index 1531a4f..21d2641 100644
44981--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44982+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44983@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44984 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44985 {
44986 struct iwl_nvm_data *data = priv->nvm_data;
44987- char *debug_msg;
44988+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44989
44990 if (data->sku_cap_11n_enable &&
44991 !priv->cfg->ht_params) {
44992@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44993 return -EINVAL;
44994 }
44995
44996- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44997 IWL_DEBUG_INFO(priv, debug_msg,
44998 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44999 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45000diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45001index 390e2f0..75cfbaf 100644
45002--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45003+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45004@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45005 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45006
45007 char buf[8];
45008- int buf_size;
45009+ size_t buf_size;
45010 u32 reset_flag;
45011
45012 memset(buf, 0, sizeof(buf));
45013@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45014 {
45015 struct iwl_trans *trans = file->private_data;
45016 char buf[8];
45017- int buf_size;
45018+ size_t buf_size;
45019 int csr;
45020
45021 memset(buf, 0, sizeof(buf));
45022diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45023index cb34c78..9fec0dc 100644
45024--- a/drivers/net/wireless/mac80211_hwsim.c
45025+++ b/drivers/net/wireless/mac80211_hwsim.c
45026@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45027
45028 if (channels > 1) {
45029 hwsim_if_comb.num_different_channels = channels;
45030- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45031- mac80211_hwsim_ops.cancel_hw_scan =
45032- mac80211_hwsim_cancel_hw_scan;
45033- mac80211_hwsim_ops.sw_scan_start = NULL;
45034- mac80211_hwsim_ops.sw_scan_complete = NULL;
45035- mac80211_hwsim_ops.remain_on_channel =
45036- mac80211_hwsim_roc;
45037- mac80211_hwsim_ops.cancel_remain_on_channel =
45038- mac80211_hwsim_croc;
45039- mac80211_hwsim_ops.add_chanctx =
45040- mac80211_hwsim_add_chanctx;
45041- mac80211_hwsim_ops.remove_chanctx =
45042- mac80211_hwsim_remove_chanctx;
45043- mac80211_hwsim_ops.change_chanctx =
45044- mac80211_hwsim_change_chanctx;
45045- mac80211_hwsim_ops.assign_vif_chanctx =
45046- mac80211_hwsim_assign_vif_chanctx;
45047- mac80211_hwsim_ops.unassign_vif_chanctx =
45048- mac80211_hwsim_unassign_vif_chanctx;
45049+ pax_open_kernel();
45050+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45051+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45052+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45053+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45054+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45055+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45056+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45057+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45058+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45059+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45060+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45061+ pax_close_kernel();
45062 }
45063
45064 spin_lock_init(&hwsim_radio_lock);
45065diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45066index 8169a85..7fa3b47 100644
45067--- a/drivers/net/wireless/rndis_wlan.c
45068+++ b/drivers/net/wireless/rndis_wlan.c
45069@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45070
45071 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45072
45073- if (rts_threshold < 0 || rts_threshold > 2347)
45074+ if (rts_threshold > 2347)
45075 rts_threshold = 2347;
45076
45077 tmp = cpu_to_le32(rts_threshold);
45078diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45079index ee3fc57..ed5ddc9 100644
45080--- a/drivers/net/wireless/rt2x00/rt2x00.h
45081+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45082@@ -386,7 +386,7 @@ struct rt2x00_intf {
45083 * for hardware which doesn't support hardware
45084 * sequence counting.
45085 */
45086- atomic_t seqno;
45087+ atomic_unchecked_t seqno;
45088 };
45089
45090 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45091diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45092index aa95c6c..a59dd67 100644
45093--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45094+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45095@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45096 * sequence counter given by mac80211.
45097 */
45098 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45099- seqno = atomic_add_return(0x10, &intf->seqno);
45100+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45101 else
45102- seqno = atomic_read(&intf->seqno);
45103+ seqno = atomic_read_unchecked(&intf->seqno);
45104
45105 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45106 hdr->seq_ctrl |= cpu_to_le16(seqno);
45107diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45108index e2b3d9c..67a5184 100644
45109--- a/drivers/net/wireless/ti/wl1251/sdio.c
45110+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45111@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45112
45113 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45114
45115- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45116- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45117+ pax_open_kernel();
45118+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45119+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45120+ pax_close_kernel();
45121
45122 wl1251_info("using dedicated interrupt line");
45123 } else {
45124- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45125- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45126+ pax_open_kernel();
45127+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45128+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45129+ pax_close_kernel();
45130
45131 wl1251_info("using SDIO interrupt");
45132 }
45133diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45134index 1c627da..69f7d17 100644
45135--- a/drivers/net/wireless/ti/wl12xx/main.c
45136+++ b/drivers/net/wireless/ti/wl12xx/main.c
45137@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45138 sizeof(wl->conf.mem));
45139
45140 /* read data preparation is only needed by wl127x */
45141- wl->ops->prepare_read = wl127x_prepare_read;
45142+ pax_open_kernel();
45143+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45144+ pax_close_kernel();
45145
45146 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45147 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45148@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45149 sizeof(wl->conf.mem));
45150
45151 /* read data preparation is only needed by wl127x */
45152- wl->ops->prepare_read = wl127x_prepare_read;
45153+ pax_open_kernel();
45154+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45155+ pax_close_kernel();
45156
45157 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45158 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45159diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45160index 7aa0eb8..5a9ef38 100644
45161--- a/drivers/net/wireless/ti/wl18xx/main.c
45162+++ b/drivers/net/wireless/ti/wl18xx/main.c
45163@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45164 }
45165
45166 if (!checksum_param) {
45167- wl18xx_ops.set_rx_csum = NULL;
45168- wl18xx_ops.init_vif = NULL;
45169+ pax_open_kernel();
45170+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45171+ *(void **)&wl18xx_ops.init_vif = NULL;
45172+ pax_close_kernel();
45173 }
45174
45175 /* Enable 11a Band only if we have 5G antennas */
45176diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45177index 7ef0b4a..ff65c28 100644
45178--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45179+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45180@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45181 {
45182 struct zd_usb *usb = urb->context;
45183 struct zd_usb_interrupt *intr = &usb->intr;
45184- int len;
45185+ unsigned int len;
45186 u16 int_num;
45187
45188 ZD_ASSERT(in_interrupt());
45189diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45190index d93b2b6..ae50401 100644
45191--- a/drivers/oprofile/buffer_sync.c
45192+++ b/drivers/oprofile/buffer_sync.c
45193@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45194 if (cookie == NO_COOKIE)
45195 offset = pc;
45196 if (cookie == INVALID_COOKIE) {
45197- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45198+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45199 offset = pc;
45200 }
45201 if (cookie != last_cookie) {
45202@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45203 /* add userspace sample */
45204
45205 if (!mm) {
45206- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45207+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45208 return 0;
45209 }
45210
45211 cookie = lookup_dcookie(mm, s->eip, &offset);
45212
45213 if (cookie == INVALID_COOKIE) {
45214- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45215+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45216 return 0;
45217 }
45218
45219@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45220 /* ignore backtraces if failed to add a sample */
45221 if (state == sb_bt_start) {
45222 state = sb_bt_ignore;
45223- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45224+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45225 }
45226 }
45227 release_mm(mm);
45228diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45229index c0cc4e7..44d4e54 100644
45230--- a/drivers/oprofile/event_buffer.c
45231+++ b/drivers/oprofile/event_buffer.c
45232@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45233 }
45234
45235 if (buffer_pos == buffer_size) {
45236- atomic_inc(&oprofile_stats.event_lost_overflow);
45237+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45238 return;
45239 }
45240
45241diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45242index ed2c3ec..deda85a 100644
45243--- a/drivers/oprofile/oprof.c
45244+++ b/drivers/oprofile/oprof.c
45245@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45246 if (oprofile_ops.switch_events())
45247 return;
45248
45249- atomic_inc(&oprofile_stats.multiplex_counter);
45250+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45251 start_switch_worker();
45252 }
45253
45254diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45255index 84a208d..d61b0a1 100644
45256--- a/drivers/oprofile/oprofile_files.c
45257+++ b/drivers/oprofile/oprofile_files.c
45258@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45259
45260 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45261
45262-static ssize_t timeout_read(struct file *file, char __user *buf,
45263+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45264 size_t count, loff_t *offset)
45265 {
45266 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45267diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45268index 917d28e..d62d981 100644
45269--- a/drivers/oprofile/oprofile_stats.c
45270+++ b/drivers/oprofile/oprofile_stats.c
45271@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45272 cpu_buf->sample_invalid_eip = 0;
45273 }
45274
45275- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45276- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45277- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45278- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45279- atomic_set(&oprofile_stats.multiplex_counter, 0);
45280+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45281+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45282+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45283+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45284+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45285 }
45286
45287
45288diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45289index 38b6fc0..b5cbfce 100644
45290--- a/drivers/oprofile/oprofile_stats.h
45291+++ b/drivers/oprofile/oprofile_stats.h
45292@@ -13,11 +13,11 @@
45293 #include <linux/atomic.h>
45294
45295 struct oprofile_stat_struct {
45296- atomic_t sample_lost_no_mm;
45297- atomic_t sample_lost_no_mapping;
45298- atomic_t bt_lost_no_mapping;
45299- atomic_t event_lost_overflow;
45300- atomic_t multiplex_counter;
45301+ atomic_unchecked_t sample_lost_no_mm;
45302+ atomic_unchecked_t sample_lost_no_mapping;
45303+ atomic_unchecked_t bt_lost_no_mapping;
45304+ atomic_unchecked_t event_lost_overflow;
45305+ atomic_unchecked_t multiplex_counter;
45306 };
45307
45308 extern struct oprofile_stat_struct oprofile_stats;
45309diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45310index 7c12d9c..558bf3bb 100644
45311--- a/drivers/oprofile/oprofilefs.c
45312+++ b/drivers/oprofile/oprofilefs.c
45313@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45314
45315
45316 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45317- char const *name, atomic_t *val)
45318+ char const *name, atomic_unchecked_t *val)
45319 {
45320 return __oprofilefs_create_file(sb, root, name,
45321 &atomic_ro_fops, 0444, val);
45322diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45323index 61be1d9..dec05d7 100644
45324--- a/drivers/oprofile/timer_int.c
45325+++ b/drivers/oprofile/timer_int.c
45326@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45327 return NOTIFY_OK;
45328 }
45329
45330-static struct notifier_block __refdata oprofile_cpu_notifier = {
45331+static struct notifier_block oprofile_cpu_notifier = {
45332 .notifier_call = oprofile_cpu_notify,
45333 };
45334
45335diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45336index 92ed045..62d39bd7 100644
45337--- a/drivers/parport/procfs.c
45338+++ b/drivers/parport/procfs.c
45339@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45340
45341 *ppos += len;
45342
45343- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45344+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45345 }
45346
45347 #ifdef CONFIG_PARPORT_1284
45348@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45349
45350 *ppos += len;
45351
45352- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45353+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45354 }
45355 #endif /* IEEE1284.3 support. */
45356
45357diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45358index c35e8ad..fc33beb 100644
45359--- a/drivers/pci/hotplug/acpiphp_ibm.c
45360+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45361@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45362 goto init_cleanup;
45363 }
45364
45365- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45366+ pax_open_kernel();
45367+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45368+ pax_close_kernel();
45369 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45370
45371 return retval;
45372diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45373index a6a71c4..c91097b 100644
45374--- a/drivers/pci/hotplug/cpcihp_generic.c
45375+++ b/drivers/pci/hotplug/cpcihp_generic.c
45376@@ -73,7 +73,6 @@ static u16 port;
45377 static unsigned int enum_bit;
45378 static u8 enum_mask;
45379
45380-static struct cpci_hp_controller_ops generic_hpc_ops;
45381 static struct cpci_hp_controller generic_hpc;
45382
45383 static int __init validate_parameters(void)
45384@@ -139,6 +138,10 @@ static int query_enum(void)
45385 return ((value & enum_mask) == enum_mask);
45386 }
45387
45388+static struct cpci_hp_controller_ops generic_hpc_ops = {
45389+ .query_enum = query_enum,
45390+};
45391+
45392 static int __init cpcihp_generic_init(void)
45393 {
45394 int status;
45395@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45396 pci_dev_put(dev);
45397
45398 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45399- generic_hpc_ops.query_enum = query_enum;
45400 generic_hpc.ops = &generic_hpc_ops;
45401
45402 status = cpci_hp_register_controller(&generic_hpc);
45403diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45404index 449b4bb..257e2e8 100644
45405--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45406+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45407@@ -59,7 +59,6 @@
45408 /* local variables */
45409 static bool debug;
45410 static bool poll;
45411-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45412 static struct cpci_hp_controller zt5550_hpc;
45413
45414 /* Primary cPCI bus bridge device */
45415@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45416 return 0;
45417 }
45418
45419+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45420+ .query_enum = zt5550_hc_query_enum,
45421+};
45422+
45423 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45424 {
45425 int status;
45426@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45427 dbg("returned from zt5550_hc_config");
45428
45429 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45430- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45431 zt5550_hpc.ops = &zt5550_hpc_ops;
45432 if(!poll) {
45433 zt5550_hpc.irq = hc_dev->irq;
45434 zt5550_hpc.irq_flags = IRQF_SHARED;
45435 zt5550_hpc.dev_id = hc_dev;
45436
45437- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45438- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45439- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45440+ pax_open_kernel();
45441+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45442+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45443+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45444+ pax_open_kernel();
45445 } else {
45446 info("using ENUM# polling mode");
45447 }
45448diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45449index 76ba8a1..20ca857 100644
45450--- a/drivers/pci/hotplug/cpqphp_nvram.c
45451+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45452@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45453
45454 void compaq_nvram_init (void __iomem *rom_start)
45455 {
45456+
45457+#ifndef CONFIG_PAX_KERNEXEC
45458 if (rom_start) {
45459 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45460 }
45461+#endif
45462+
45463 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45464
45465 /* initialize our int15 lock */
45466diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45467index ec20f74..c1d961e 100644
45468--- a/drivers/pci/hotplug/pci_hotplug_core.c
45469+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45470@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45471 return -EINVAL;
45472 }
45473
45474- slot->ops->owner = owner;
45475- slot->ops->mod_name = mod_name;
45476+ pax_open_kernel();
45477+ *(struct module **)&slot->ops->owner = owner;
45478+ *(const char **)&slot->ops->mod_name = mod_name;
45479+ pax_close_kernel();
45480
45481 mutex_lock(&pci_hp_mutex);
45482 /*
45483diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45484index 7d72c5e..edce02c 100644
45485--- a/drivers/pci/hotplug/pciehp_core.c
45486+++ b/drivers/pci/hotplug/pciehp_core.c
45487@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45488 struct slot *slot = ctrl->slot;
45489 struct hotplug_slot *hotplug = NULL;
45490 struct hotplug_slot_info *info = NULL;
45491- struct hotplug_slot_ops *ops = NULL;
45492+ hotplug_slot_ops_no_const *ops = NULL;
45493 char name[SLOT_NAME_SIZE];
45494 int retval = -ENOMEM;
45495
45496diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45497index c0dbe1f..94cf3d8 100644
45498--- a/drivers/pci/pci-sysfs.c
45499+++ b/drivers/pci/pci-sysfs.c
45500@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45501 {
45502 /* allocate attribute structure, piggyback attribute name */
45503 int name_len = write_combine ? 13 : 10;
45504- struct bin_attribute *res_attr;
45505+ bin_attribute_no_const *res_attr;
45506 int retval;
45507
45508 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45509@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45510 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45511 {
45512 int retval;
45513- struct bin_attribute *attr;
45514+ bin_attribute_no_const *attr;
45515
45516 /* If the device has VPD, try to expose it in sysfs. */
45517 if (dev->vpd) {
45518@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45519 {
45520 int retval;
45521 int rom_size = 0;
45522- struct bin_attribute *attr;
45523+ bin_attribute_no_const *attr;
45524
45525 if (!sysfs_initialized)
45526 return -EACCES;
45527diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45528index d1182c4..2a138ec 100644
45529--- a/drivers/pci/pci.h
45530+++ b/drivers/pci/pci.h
45531@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45532 struct pci_vpd {
45533 unsigned int len;
45534 const struct pci_vpd_ops *ops;
45535- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45536+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45537 };
45538
45539 int pci_vpd_pci22_init(struct pci_dev *dev);
45540diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45541index 403a443..034e050 100644
45542--- a/drivers/pci/pcie/aspm.c
45543+++ b/drivers/pci/pcie/aspm.c
45544@@ -27,9 +27,9 @@
45545 #define MODULE_PARAM_PREFIX "pcie_aspm."
45546
45547 /* Note: those are not register definitions */
45548-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45549-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45550-#define ASPM_STATE_L1 (4) /* L1 state */
45551+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45552+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45553+#define ASPM_STATE_L1 (4U) /* L1 state */
45554 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45555 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45556
45557diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45558index 46ada5c..20da716 100644
45559--- a/drivers/pci/probe.c
45560+++ b/drivers/pci/probe.c
45561@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45562 struct pci_bus_region region, inverted_region;
45563 bool bar_too_big = false, bar_disabled = false;
45564
45565- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45566+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45567
45568 /* No printks while decoding is disabled! */
45569 if (!dev->mmio_always_on) {
45570diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45571index cdc7836..528635c 100644
45572--- a/drivers/pci/proc.c
45573+++ b/drivers/pci/proc.c
45574@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45575 static int __init pci_proc_init(void)
45576 {
45577 struct pci_dev *dev = NULL;
45578+
45579+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45580+#ifdef CONFIG_GRKERNSEC_PROC_USER
45581+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45582+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45583+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45584+#endif
45585+#else
45586 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45587+#endif
45588 proc_create("devices", 0, proc_bus_pci_dir,
45589 &proc_bus_pci_dev_operations);
45590 proc_initialized = 1;
45591diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45592index 3e5b4497..dcdfb70 100644
45593--- a/drivers/platform/x86/chromeos_laptop.c
45594+++ b/drivers/platform/x86/chromeos_laptop.c
45595@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45596 return 0;
45597 }
45598
45599-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45600+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45601 {
45602 .ident = "Samsung Series 5 550 - Touchpad",
45603 .matches = {
45604diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45605index 62f8030..c7f2a45 100644
45606--- a/drivers/platform/x86/msi-laptop.c
45607+++ b/drivers/platform/x86/msi-laptop.c
45608@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45609
45610 if (!quirks->ec_read_only) {
45611 /* allow userland write sysfs file */
45612- dev_attr_bluetooth.store = store_bluetooth;
45613- dev_attr_wlan.store = store_wlan;
45614- dev_attr_threeg.store = store_threeg;
45615- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45616- dev_attr_wlan.attr.mode |= S_IWUSR;
45617- dev_attr_threeg.attr.mode |= S_IWUSR;
45618+ pax_open_kernel();
45619+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45620+ *(void **)&dev_attr_wlan.store = store_wlan;
45621+ *(void **)&dev_attr_threeg.store = store_threeg;
45622+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45623+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45624+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45625+ pax_close_kernel();
45626 }
45627
45628 /* disable hardware control by fn key */
45629diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45630index 3a1b6bf..b453930 100644
45631--- a/drivers/platform/x86/sony-laptop.c
45632+++ b/drivers/platform/x86/sony-laptop.c
45633@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45634 }
45635
45636 /* High speed charging function */
45637-static struct device_attribute *hsc_handle;
45638+static device_attribute_no_const *hsc_handle;
45639
45640 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45641 struct device_attribute *attr,
45642diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45643index 54d31c0..3f896d3 100644
45644--- a/drivers/platform/x86/thinkpad_acpi.c
45645+++ b/drivers/platform/x86/thinkpad_acpi.c
45646@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45647 return 0;
45648 }
45649
45650-void static hotkey_mask_warn_incomplete_mask(void)
45651+static void hotkey_mask_warn_incomplete_mask(void)
45652 {
45653 /* log only what the user can fix... */
45654 const u32 wantedmask = hotkey_driver_mask &
45655@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45656 }
45657 }
45658
45659-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45660- struct tp_nvram_state *newn,
45661- const u32 event_mask)
45662-{
45663-
45664 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45665 do { \
45666 if ((event_mask & (1 << __scancode)) && \
45667@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45668 tpacpi_hotkey_send_key(__scancode); \
45669 } while (0)
45670
45671- void issue_volchange(const unsigned int oldvol,
45672- const unsigned int newvol)
45673- {
45674- unsigned int i = oldvol;
45675+static void issue_volchange(const unsigned int oldvol,
45676+ const unsigned int newvol,
45677+ const u32 event_mask)
45678+{
45679+ unsigned int i = oldvol;
45680
45681- while (i > newvol) {
45682- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45683- i--;
45684- }
45685- while (i < newvol) {
45686- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45687- i++;
45688- }
45689+ while (i > newvol) {
45690+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45691+ i--;
45692 }
45693+ while (i < newvol) {
45694+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45695+ i++;
45696+ }
45697+}
45698
45699- void issue_brightnesschange(const unsigned int oldbrt,
45700- const unsigned int newbrt)
45701- {
45702- unsigned int i = oldbrt;
45703+static void issue_brightnesschange(const unsigned int oldbrt,
45704+ const unsigned int newbrt,
45705+ const u32 event_mask)
45706+{
45707+ unsigned int i = oldbrt;
45708
45709- while (i > newbrt) {
45710- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45711- i--;
45712- }
45713- while (i < newbrt) {
45714- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45715- i++;
45716- }
45717+ while (i > newbrt) {
45718+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45719+ i--;
45720+ }
45721+ while (i < newbrt) {
45722+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45723+ i++;
45724 }
45725+}
45726
45727+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45728+ struct tp_nvram_state *newn,
45729+ const u32 event_mask)
45730+{
45731 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45732 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45733 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45734@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45735 oldn->volume_level != newn->volume_level) {
45736 /* recently muted, or repeated mute keypress, or
45737 * multiple presses ending in mute */
45738- issue_volchange(oldn->volume_level, newn->volume_level);
45739+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45740 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45741 }
45742 } else {
45743@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45744 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45745 }
45746 if (oldn->volume_level != newn->volume_level) {
45747- issue_volchange(oldn->volume_level, newn->volume_level);
45748+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45749 } else if (oldn->volume_toggle != newn->volume_toggle) {
45750 /* repeated vol up/down keypress at end of scale ? */
45751 if (newn->volume_level == 0)
45752@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45753 /* handle brightness */
45754 if (oldn->brightness_level != newn->brightness_level) {
45755 issue_brightnesschange(oldn->brightness_level,
45756- newn->brightness_level);
45757+ newn->brightness_level,
45758+ event_mask);
45759 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45760 /* repeated key presses that didn't change state */
45761 if (newn->brightness_level == 0)
45762@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45763 && !tp_features.bright_unkfw)
45764 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45765 }
45766+}
45767
45768 #undef TPACPI_COMPARE_KEY
45769 #undef TPACPI_MAY_SEND_KEY
45770-}
45771
45772 /*
45773 * Polling driver
45774diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45775index 769d265..a3a05ca 100644
45776--- a/drivers/pnp/pnpbios/bioscalls.c
45777+++ b/drivers/pnp/pnpbios/bioscalls.c
45778@@ -58,7 +58,7 @@ do { \
45779 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45780 } while(0)
45781
45782-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45783+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45784 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45785
45786 /*
45787@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45788
45789 cpu = get_cpu();
45790 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45791+
45792+ pax_open_kernel();
45793 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45794+ pax_close_kernel();
45795
45796 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45797 spin_lock_irqsave(&pnp_bios_lock, flags);
45798@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45799 :"memory");
45800 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45801
45802+ pax_open_kernel();
45803 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45804+ pax_close_kernel();
45805+
45806 put_cpu();
45807
45808 /* If we get here and this is set then the PnP BIOS faulted on us. */
45809@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45810 return status;
45811 }
45812
45813-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45814+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45815 {
45816 int i;
45817
45818@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45819 pnp_bios_callpoint.offset = header->fields.pm16offset;
45820 pnp_bios_callpoint.segment = PNP_CS16;
45821
45822+ pax_open_kernel();
45823+
45824 for_each_possible_cpu(i) {
45825 struct desc_struct *gdt = get_cpu_gdt_table(i);
45826 if (!gdt)
45827@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45828 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45829 (unsigned long)__va(header->fields.pm16dseg));
45830 }
45831+
45832+ pax_close_kernel();
45833 }
45834diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45835index d95e101..67f0c3f 100644
45836--- a/drivers/pnp/resource.c
45837+++ b/drivers/pnp/resource.c
45838@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45839 return 1;
45840
45841 /* check if the resource is valid */
45842- if (*irq < 0 || *irq > 15)
45843+ if (*irq > 15)
45844 return 0;
45845
45846 /* check if the resource is reserved */
45847@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45848 return 1;
45849
45850 /* check if the resource is valid */
45851- if (*dma < 0 || *dma == 4 || *dma > 7)
45852+ if (*dma == 4 || *dma > 7)
45853 return 0;
45854
45855 /* check if the resource is reserved */
45856diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45857index 0c52e2a..3421ab7 100644
45858--- a/drivers/power/pda_power.c
45859+++ b/drivers/power/pda_power.c
45860@@ -37,7 +37,11 @@ static int polling;
45861
45862 #if IS_ENABLED(CONFIG_USB_PHY)
45863 static struct usb_phy *transceiver;
45864-static struct notifier_block otg_nb;
45865+static int otg_handle_notification(struct notifier_block *nb,
45866+ unsigned long event, void *unused);
45867+static struct notifier_block otg_nb = {
45868+ .notifier_call = otg_handle_notification
45869+};
45870 #endif
45871
45872 static struct regulator *ac_draw;
45873@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45874
45875 #if IS_ENABLED(CONFIG_USB_PHY)
45876 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45877- otg_nb.notifier_call = otg_handle_notification;
45878 ret = usb_register_notifier(transceiver, &otg_nb);
45879 if (ret) {
45880 dev_err(dev, "failure to register otg notifier\n");
45881diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45882index cc439fd..8fa30df 100644
45883--- a/drivers/power/power_supply.h
45884+++ b/drivers/power/power_supply.h
45885@@ -16,12 +16,12 @@ struct power_supply;
45886
45887 #ifdef CONFIG_SYSFS
45888
45889-extern void power_supply_init_attrs(struct device_type *dev_type);
45890+extern void power_supply_init_attrs(void);
45891 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45892
45893 #else
45894
45895-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45896+static inline void power_supply_init_attrs(void) {}
45897 #define power_supply_uevent NULL
45898
45899 #endif /* CONFIG_SYSFS */
45900diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45901index 3b2d5df..3207114 100644
45902--- a/drivers/power/power_supply_core.c
45903+++ b/drivers/power/power_supply_core.c
45904@@ -24,7 +24,10 @@
45905 struct class *power_supply_class;
45906 EXPORT_SYMBOL_GPL(power_supply_class);
45907
45908-static struct device_type power_supply_dev_type;
45909+extern const struct attribute_group *power_supply_attr_groups[];
45910+static struct device_type power_supply_dev_type = {
45911+ .groups = power_supply_attr_groups,
45912+};
45913
45914 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45915 struct power_supply *supply)
45916@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
45917 return PTR_ERR(power_supply_class);
45918
45919 power_supply_class->dev_uevent = power_supply_uevent;
45920- power_supply_init_attrs(&power_supply_dev_type);
45921+ power_supply_init_attrs();
45922
45923 return 0;
45924 }
45925diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45926index 29178f7..c65f324 100644
45927--- a/drivers/power/power_supply_sysfs.c
45928+++ b/drivers/power/power_supply_sysfs.c
45929@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45930 .is_visible = power_supply_attr_is_visible,
45931 };
45932
45933-static const struct attribute_group *power_supply_attr_groups[] = {
45934+const struct attribute_group *power_supply_attr_groups[] = {
45935 &power_supply_attr_group,
45936 NULL,
45937 };
45938
45939-void power_supply_init_attrs(struct device_type *dev_type)
45940+void power_supply_init_attrs(void)
45941 {
45942 int i;
45943
45944- dev_type->groups = power_supply_attr_groups;
45945-
45946 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45947 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45948 }
45949diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45950index 288c75a..065bc84 100644
45951--- a/drivers/regulator/core.c
45952+++ b/drivers/regulator/core.c
45953@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45954 {
45955 const struct regulation_constraints *constraints = NULL;
45956 const struct regulator_init_data *init_data;
45957- static atomic_t regulator_no = ATOMIC_INIT(0);
45958+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45959 struct regulator_dev *rdev;
45960 struct device *dev;
45961 int ret, i;
45962@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45963 rdev->dev.of_node = config->of_node;
45964 rdev->dev.parent = dev;
45965 dev_set_name(&rdev->dev, "regulator.%d",
45966- atomic_inc_return(&regulator_no) - 1);
45967+ atomic_inc_return_unchecked(&regulator_no) - 1);
45968 ret = device_register(&rdev->dev);
45969 if (ret != 0) {
45970 put_device(&rdev->dev);
45971diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45972index d428ef9..fdc0357 100644
45973--- a/drivers/regulator/max8660.c
45974+++ b/drivers/regulator/max8660.c
45975@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
45976 max8660->shadow_regs[MAX8660_OVER1] = 5;
45977 } else {
45978 /* Otherwise devices can be toggled via software */
45979- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45980- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45981+ pax_open_kernel();
45982+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45983+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45984+ pax_close_kernel();
45985 }
45986
45987 /*
45988diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45989index 0c5195a..637a453d 100644
45990--- a/drivers/regulator/max8973-regulator.c
45991+++ b/drivers/regulator/max8973-regulator.c
45992@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45993 if (!pdata || !pdata->enable_ext_control) {
45994 max->desc.enable_reg = MAX8973_VOUT;
45995 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45996- max->ops.enable = regulator_enable_regmap;
45997- max->ops.disable = regulator_disable_regmap;
45998- max->ops.is_enabled = regulator_is_enabled_regmap;
45999+ pax_open_kernel();
46000+ *(void **)&max->ops.enable = regulator_enable_regmap;
46001+ *(void **)&max->ops.disable = regulator_disable_regmap;
46002+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46003+ pax_close_kernel();
46004 }
46005
46006 if (pdata) {
46007diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46008index 1037e07..e64dea1 100644
46009--- a/drivers/regulator/mc13892-regulator.c
46010+++ b/drivers/regulator/mc13892-regulator.c
46011@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46012 }
46013 mc13xxx_unlock(mc13892);
46014
46015- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46016+ pax_open_kernel();
46017+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46018 = mc13892_vcam_set_mode;
46019- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46020+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46021 = mc13892_vcam_get_mode;
46022+ pax_close_kernel();
46023
46024 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46025 ARRAY_SIZE(mc13892_regulators));
46026diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46027index be06d71..264aee9 100644
46028--- a/drivers/rtc/rtc-cmos.c
46029+++ b/drivers/rtc/rtc-cmos.c
46030@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46031 hpet_rtc_timer_init();
46032
46033 /* export at least the first block of NVRAM */
46034- nvram.size = address_space - NVRAM_OFFSET;
46035+ pax_open_kernel();
46036+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46037+ pax_close_kernel();
46038 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46039 if (retval < 0) {
46040 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46041diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46042index d049393..bb20be0 100644
46043--- a/drivers/rtc/rtc-dev.c
46044+++ b/drivers/rtc/rtc-dev.c
46045@@ -16,6 +16,7 @@
46046 #include <linux/module.h>
46047 #include <linux/rtc.h>
46048 #include <linux/sched.h>
46049+#include <linux/grsecurity.h>
46050 #include "rtc-core.h"
46051
46052 static dev_t rtc_devt;
46053@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46054 if (copy_from_user(&tm, uarg, sizeof(tm)))
46055 return -EFAULT;
46056
46057+ gr_log_timechange();
46058+
46059 return rtc_set_time(rtc, &tm);
46060
46061 case RTC_PIE_ON:
46062diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46063index ca18fd1..055e42d 100644
46064--- a/drivers/rtc/rtc-ds1307.c
46065+++ b/drivers/rtc/rtc-ds1307.c
46066@@ -107,7 +107,7 @@ struct ds1307 {
46067 u8 offset; /* register's offset */
46068 u8 regs[11];
46069 u16 nvram_offset;
46070- struct bin_attribute *nvram;
46071+ bin_attribute_no_const *nvram;
46072 enum ds_type type;
46073 unsigned long flags;
46074 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46075diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46076index fcb0329..d77b7f2 100644
46077--- a/drivers/rtc/rtc-m48t59.c
46078+++ b/drivers/rtc/rtc-m48t59.c
46079@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46080 if (IS_ERR(m48t59->rtc))
46081 return PTR_ERR(m48t59->rtc);
46082
46083- m48t59_nvram_attr.size = pdata->offset;
46084+ pax_open_kernel();
46085+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46086+ pax_close_kernel();
46087
46088 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46089 if (ret)
46090diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46091index e693af6..2e525b6 100644
46092--- a/drivers/scsi/bfa/bfa_fcpim.h
46093+++ b/drivers/scsi/bfa/bfa_fcpim.h
46094@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46095
46096 struct bfa_itn_s {
46097 bfa_isr_func_t isr;
46098-};
46099+} __no_const;
46100
46101 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46102 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46103diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46104index 90814fe..4384138 100644
46105--- a/drivers/scsi/bfa/bfa_ioc.h
46106+++ b/drivers/scsi/bfa/bfa_ioc.h
46107@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46108 bfa_ioc_disable_cbfn_t disable_cbfn;
46109 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46110 bfa_ioc_reset_cbfn_t reset_cbfn;
46111-};
46112+} __no_const;
46113
46114 /*
46115 * IOC event notification mechanism.
46116@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46117 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46118 enum bfi_ioc_state fwstate);
46119 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46120-};
46121+} __no_const;
46122
46123 /*
46124 * Queue element to wait for room in request queue. FIFO order is
46125diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46126index c9382d6..6619864 100644
46127--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46128+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46129@@ -33,8 +33,8 @@
46130 */
46131 #include "libfcoe.h"
46132
46133-static atomic_t ctlr_num;
46134-static atomic_t fcf_num;
46135+static atomic_unchecked_t ctlr_num;
46136+static atomic_unchecked_t fcf_num;
46137
46138 /*
46139 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46140@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46141 if (!ctlr)
46142 goto out;
46143
46144- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46145+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46146 ctlr->f = f;
46147 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46148 INIT_LIST_HEAD(&ctlr->fcfs);
46149@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46150 fcf->dev.parent = &ctlr->dev;
46151 fcf->dev.bus = &fcoe_bus_type;
46152 fcf->dev.type = &fcoe_fcf_device_type;
46153- fcf->id = atomic_inc_return(&fcf_num) - 1;
46154+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46155 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46156
46157 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46158@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46159 {
46160 int error;
46161
46162- atomic_set(&ctlr_num, 0);
46163- atomic_set(&fcf_num, 0);
46164+ atomic_set_unchecked(&ctlr_num, 0);
46165+ atomic_set_unchecked(&fcf_num, 0);
46166
46167 error = bus_register(&fcoe_bus_type);
46168 if (error)
46169diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46170index df0c3c7..b00e1d0 100644
46171--- a/drivers/scsi/hosts.c
46172+++ b/drivers/scsi/hosts.c
46173@@ -42,7 +42,7 @@
46174 #include "scsi_logging.h"
46175
46176
46177-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46178+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46179
46180
46181 static void scsi_host_cls_release(struct device *dev)
46182@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46183 * subtract one because we increment first then return, but we need to
46184 * know what the next host number was before increment
46185 */
46186- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46187+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46188 shost->dma_channel = 0xff;
46189
46190 /* These three are default values which can be overridden */
46191diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46192index 7f4f790..b75b92a 100644
46193--- a/drivers/scsi/hpsa.c
46194+++ b/drivers/scsi/hpsa.c
46195@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46196 unsigned long flags;
46197
46198 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46199- return h->access.command_completed(h, q);
46200+ return h->access->command_completed(h, q);
46201
46202 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46203 a = rq->head[rq->current_entry];
46204@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46205 while (!list_empty(&h->reqQ)) {
46206 c = list_entry(h->reqQ.next, struct CommandList, list);
46207 /* can't do anything if fifo is full */
46208- if ((h->access.fifo_full(h))) {
46209+ if ((h->access->fifo_full(h))) {
46210 dev_warn(&h->pdev->dev, "fifo full\n");
46211 break;
46212 }
46213@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46214
46215 /* Tell the controller execute command */
46216 spin_unlock_irqrestore(&h->lock, flags);
46217- h->access.submit_command(h, c);
46218+ h->access->submit_command(h, c);
46219 spin_lock_irqsave(&h->lock, flags);
46220 }
46221 spin_unlock_irqrestore(&h->lock, flags);
46222@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46223
46224 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46225 {
46226- return h->access.command_completed(h, q);
46227+ return h->access->command_completed(h, q);
46228 }
46229
46230 static inline bool interrupt_pending(struct ctlr_info *h)
46231 {
46232- return h->access.intr_pending(h);
46233+ return h->access->intr_pending(h);
46234 }
46235
46236 static inline long interrupt_not_for_us(struct ctlr_info *h)
46237 {
46238- return (h->access.intr_pending(h) == 0) ||
46239+ return (h->access->intr_pending(h) == 0) ||
46240 (h->interrupts_enabled == 0);
46241 }
46242
46243@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46244 if (prod_index < 0)
46245 return -ENODEV;
46246 h->product_name = products[prod_index].product_name;
46247- h->access = *(products[prod_index].access);
46248+ h->access = products[prod_index].access;
46249
46250 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46251 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46252@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46253
46254 assert_spin_locked(&lockup_detector_lock);
46255 remove_ctlr_from_lockup_detector_list(h);
46256- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46257+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46258 spin_lock_irqsave(&h->lock, flags);
46259 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46260 spin_unlock_irqrestore(&h->lock, flags);
46261@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46262 }
46263
46264 /* make sure the board interrupts are off */
46265- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46266+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46267
46268 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46269 goto clean2;
46270@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46271 * fake ones to scoop up any residual completions.
46272 */
46273 spin_lock_irqsave(&h->lock, flags);
46274- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46275+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46276 spin_unlock_irqrestore(&h->lock, flags);
46277 free_irqs(h);
46278 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46279@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46280 dev_info(&h->pdev->dev, "Board READY.\n");
46281 dev_info(&h->pdev->dev,
46282 "Waiting for stale completions to drain.\n");
46283- h->access.set_intr_mask(h, HPSA_INTR_ON);
46284+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46285 msleep(10000);
46286- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46287+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46288
46289 rc = controller_reset_failed(h->cfgtable);
46290 if (rc)
46291@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46292 }
46293
46294 /* Turn the interrupts on so we can service requests */
46295- h->access.set_intr_mask(h, HPSA_INTR_ON);
46296+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46297
46298 hpsa_hba_inquiry(h);
46299 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46300@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46301 * To write all data in the battery backed cache to disks
46302 */
46303 hpsa_flush_cache(h);
46304- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46305+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46306 hpsa_free_irqs_and_disable_msix(h);
46307 }
46308
46309@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46310 return;
46311 }
46312 /* Change the access methods to the performant access methods */
46313- h->access = SA5_performant_access;
46314+ h->access = &SA5_performant_access;
46315 h->transMethod = CFGTBL_Trans_Performant;
46316 }
46317
46318diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46319index 9816479..c5d4e97 100644
46320--- a/drivers/scsi/hpsa.h
46321+++ b/drivers/scsi/hpsa.h
46322@@ -79,7 +79,7 @@ struct ctlr_info {
46323 unsigned int msix_vector;
46324 unsigned int msi_vector;
46325 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46326- struct access_method access;
46327+ struct access_method *access;
46328
46329 /* queue and queue Info */
46330 struct list_head reqQ;
46331diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46332index 5879929..32b241d 100644
46333--- a/drivers/scsi/libfc/fc_exch.c
46334+++ b/drivers/scsi/libfc/fc_exch.c
46335@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46336 u16 pool_max_index;
46337
46338 struct {
46339- atomic_t no_free_exch;
46340- atomic_t no_free_exch_xid;
46341- atomic_t xid_not_found;
46342- atomic_t xid_busy;
46343- atomic_t seq_not_found;
46344- atomic_t non_bls_resp;
46345+ atomic_unchecked_t no_free_exch;
46346+ atomic_unchecked_t no_free_exch_xid;
46347+ atomic_unchecked_t xid_not_found;
46348+ atomic_unchecked_t xid_busy;
46349+ atomic_unchecked_t seq_not_found;
46350+ atomic_unchecked_t non_bls_resp;
46351 } stats;
46352 };
46353
46354@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46355 /* allocate memory for exchange */
46356 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46357 if (!ep) {
46358- atomic_inc(&mp->stats.no_free_exch);
46359+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46360 goto out;
46361 }
46362 memset(ep, 0, sizeof(*ep));
46363@@ -797,7 +797,7 @@ out:
46364 return ep;
46365 err:
46366 spin_unlock_bh(&pool->lock);
46367- atomic_inc(&mp->stats.no_free_exch_xid);
46368+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46369 mempool_free(ep, mp->ep_pool);
46370 return NULL;
46371 }
46372@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46373 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46374 ep = fc_exch_find(mp, xid);
46375 if (!ep) {
46376- atomic_inc(&mp->stats.xid_not_found);
46377+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46378 reject = FC_RJT_OX_ID;
46379 goto out;
46380 }
46381@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46382 ep = fc_exch_find(mp, xid);
46383 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46384 if (ep) {
46385- atomic_inc(&mp->stats.xid_busy);
46386+ atomic_inc_unchecked(&mp->stats.xid_busy);
46387 reject = FC_RJT_RX_ID;
46388 goto rel;
46389 }
46390@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46391 }
46392 xid = ep->xid; /* get our XID */
46393 } else if (!ep) {
46394- atomic_inc(&mp->stats.xid_not_found);
46395+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46396 reject = FC_RJT_RX_ID; /* XID not found */
46397 goto out;
46398 }
46399@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46400 } else {
46401 sp = &ep->seq;
46402 if (sp->id != fh->fh_seq_id) {
46403- atomic_inc(&mp->stats.seq_not_found);
46404+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46405 if (f_ctl & FC_FC_END_SEQ) {
46406 /*
46407 * Update sequence_id based on incoming last
46408@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46409
46410 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46411 if (!ep) {
46412- atomic_inc(&mp->stats.xid_not_found);
46413+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46414 goto out;
46415 }
46416 if (ep->esb_stat & ESB_ST_COMPLETE) {
46417- atomic_inc(&mp->stats.xid_not_found);
46418+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46419 goto rel;
46420 }
46421 if (ep->rxid == FC_XID_UNKNOWN)
46422 ep->rxid = ntohs(fh->fh_rx_id);
46423 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46424- atomic_inc(&mp->stats.xid_not_found);
46425+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46426 goto rel;
46427 }
46428 if (ep->did != ntoh24(fh->fh_s_id) &&
46429 ep->did != FC_FID_FLOGI) {
46430- atomic_inc(&mp->stats.xid_not_found);
46431+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46432 goto rel;
46433 }
46434 sof = fr_sof(fp);
46435@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46436 sp->ssb_stat |= SSB_ST_RESP;
46437 sp->id = fh->fh_seq_id;
46438 } else if (sp->id != fh->fh_seq_id) {
46439- atomic_inc(&mp->stats.seq_not_found);
46440+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46441 goto rel;
46442 }
46443
46444@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46445 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46446
46447 if (!sp)
46448- atomic_inc(&mp->stats.xid_not_found);
46449+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46450 else
46451- atomic_inc(&mp->stats.non_bls_resp);
46452+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46453
46454 fc_frame_free(fp);
46455 }
46456@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46457
46458 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46459 mp = ema->mp;
46460- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46461+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46462 st->fc_no_free_exch_xid +=
46463- atomic_read(&mp->stats.no_free_exch_xid);
46464- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46465- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46466- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46467- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46468+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46469+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46470+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46471+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46472+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46473 }
46474 }
46475 EXPORT_SYMBOL(fc_exch_update_stats);
46476diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46477index 161c98e..6d563b3 100644
46478--- a/drivers/scsi/libsas/sas_ata.c
46479+++ b/drivers/scsi/libsas/sas_ata.c
46480@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46481 .postreset = ata_std_postreset,
46482 .error_handler = ata_std_error_handler,
46483 .post_internal_cmd = sas_ata_post_internal,
46484- .qc_defer = ata_std_qc_defer,
46485+ .qc_defer = ata_std_qc_defer,
46486 .qc_prep = ata_noop_qc_prep,
46487 .qc_issue = sas_ata_qc_issue,
46488 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46489diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46490index 93f222d..73e977b 100644
46491--- a/drivers/scsi/lpfc/lpfc.h
46492+++ b/drivers/scsi/lpfc/lpfc.h
46493@@ -431,7 +431,7 @@ struct lpfc_vport {
46494 struct dentry *debug_nodelist;
46495 struct dentry *vport_debugfs_root;
46496 struct lpfc_debugfs_trc *disc_trc;
46497- atomic_t disc_trc_cnt;
46498+ atomic_unchecked_t disc_trc_cnt;
46499 #endif
46500 uint8_t stat_data_enabled;
46501 uint8_t stat_data_blocked;
46502@@ -865,8 +865,8 @@ struct lpfc_hba {
46503 struct timer_list fabric_block_timer;
46504 unsigned long bit_flags;
46505 #define FABRIC_COMANDS_BLOCKED 0
46506- atomic_t num_rsrc_err;
46507- atomic_t num_cmd_success;
46508+ atomic_unchecked_t num_rsrc_err;
46509+ atomic_unchecked_t num_cmd_success;
46510 unsigned long last_rsrc_error_time;
46511 unsigned long last_ramp_down_time;
46512 unsigned long last_ramp_up_time;
46513@@ -902,7 +902,7 @@ struct lpfc_hba {
46514
46515 struct dentry *debug_slow_ring_trc;
46516 struct lpfc_debugfs_trc *slow_ring_trc;
46517- atomic_t slow_ring_trc_cnt;
46518+ atomic_unchecked_t slow_ring_trc_cnt;
46519 /* iDiag debugfs sub-directory */
46520 struct dentry *idiag_root;
46521 struct dentry *idiag_pci_cfg;
46522diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46523index 60084e6..0e2e700 100644
46524--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46525+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46526@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46527
46528 #include <linux/debugfs.h>
46529
46530-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46531+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46532 static unsigned long lpfc_debugfs_start_time = 0L;
46533
46534 /* iDiag */
46535@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46536 lpfc_debugfs_enable = 0;
46537
46538 len = 0;
46539- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46540+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46541 (lpfc_debugfs_max_disc_trc - 1);
46542 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46543 dtp = vport->disc_trc + i;
46544@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46545 lpfc_debugfs_enable = 0;
46546
46547 len = 0;
46548- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46549+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46550 (lpfc_debugfs_max_slow_ring_trc - 1);
46551 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46552 dtp = phba->slow_ring_trc + i;
46553@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46554 !vport || !vport->disc_trc)
46555 return;
46556
46557- index = atomic_inc_return(&vport->disc_trc_cnt) &
46558+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46559 (lpfc_debugfs_max_disc_trc - 1);
46560 dtp = vport->disc_trc + index;
46561 dtp->fmt = fmt;
46562 dtp->data1 = data1;
46563 dtp->data2 = data2;
46564 dtp->data3 = data3;
46565- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46566+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46567 dtp->jif = jiffies;
46568 #endif
46569 return;
46570@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46571 !phba || !phba->slow_ring_trc)
46572 return;
46573
46574- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46575+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46576 (lpfc_debugfs_max_slow_ring_trc - 1);
46577 dtp = phba->slow_ring_trc + index;
46578 dtp->fmt = fmt;
46579 dtp->data1 = data1;
46580 dtp->data2 = data2;
46581 dtp->data3 = data3;
46582- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46583+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46584 dtp->jif = jiffies;
46585 #endif
46586 return;
46587@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46588 "slow_ring buffer\n");
46589 goto debug_failed;
46590 }
46591- atomic_set(&phba->slow_ring_trc_cnt, 0);
46592+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46593 memset(phba->slow_ring_trc, 0,
46594 (sizeof(struct lpfc_debugfs_trc) *
46595 lpfc_debugfs_max_slow_ring_trc));
46596@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46597 "buffer\n");
46598 goto debug_failed;
46599 }
46600- atomic_set(&vport->disc_trc_cnt, 0);
46601+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46602
46603 snprintf(name, sizeof(name), "discovery_trace");
46604 vport->debug_disc_trc =
46605diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46606index e0b20fa..30c2c0d 100644
46607--- a/drivers/scsi/lpfc/lpfc_init.c
46608+++ b/drivers/scsi/lpfc/lpfc_init.c
46609@@ -10936,8 +10936,10 @@ lpfc_init(void)
46610 "misc_register returned with status %d", error);
46611
46612 if (lpfc_enable_npiv) {
46613- lpfc_transport_functions.vport_create = lpfc_vport_create;
46614- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46615+ pax_open_kernel();
46616+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46617+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46618+ pax_close_kernel();
46619 }
46620 lpfc_transport_template =
46621 fc_attach_transport(&lpfc_transport_functions);
46622diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46623index 243de1d..f40e3e5 100644
46624--- a/drivers/scsi/lpfc/lpfc_scsi.c
46625+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46626@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46627 uint32_t evt_posted;
46628
46629 spin_lock_irqsave(&phba->hbalock, flags);
46630- atomic_inc(&phba->num_rsrc_err);
46631+ atomic_inc_unchecked(&phba->num_rsrc_err);
46632 phba->last_rsrc_error_time = jiffies;
46633
46634 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46635@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46636 unsigned long flags;
46637 struct lpfc_hba *phba = vport->phba;
46638 uint32_t evt_posted;
46639- atomic_inc(&phba->num_cmd_success);
46640+ atomic_inc_unchecked(&phba->num_cmd_success);
46641
46642 if (vport->cfg_lun_queue_depth <= queue_depth)
46643 return;
46644@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46645 unsigned long num_rsrc_err, num_cmd_success;
46646 int i;
46647
46648- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46649- num_cmd_success = atomic_read(&phba->num_cmd_success);
46650+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46651+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46652
46653 /*
46654 * The error and success command counters are global per
46655@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46656 }
46657 }
46658 lpfc_destroy_vport_work_array(phba, vports);
46659- atomic_set(&phba->num_rsrc_err, 0);
46660- atomic_set(&phba->num_cmd_success, 0);
46661+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46662+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46663 }
46664
46665 /**
46666@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46667 }
46668 }
46669 lpfc_destroy_vport_work_array(phba, vports);
46670- atomic_set(&phba->num_rsrc_err, 0);
46671- atomic_set(&phba->num_cmd_success, 0);
46672+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46673+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46674 }
46675
46676 /**
46677diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46678index 1eb7b028..b2a6080 100644
46679--- a/drivers/scsi/pmcraid.c
46680+++ b/drivers/scsi/pmcraid.c
46681@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46682 res->scsi_dev = scsi_dev;
46683 scsi_dev->hostdata = res;
46684 res->change_detected = 0;
46685- atomic_set(&res->read_failures, 0);
46686- atomic_set(&res->write_failures, 0);
46687+ atomic_set_unchecked(&res->read_failures, 0);
46688+ atomic_set_unchecked(&res->write_failures, 0);
46689 rc = 0;
46690 }
46691 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46692@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46693
46694 /* If this was a SCSI read/write command keep count of errors */
46695 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46696- atomic_inc(&res->read_failures);
46697+ atomic_inc_unchecked(&res->read_failures);
46698 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46699- atomic_inc(&res->write_failures);
46700+ atomic_inc_unchecked(&res->write_failures);
46701
46702 if (!RES_IS_GSCSI(res->cfg_entry) &&
46703 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46704@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46705 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46706 * hrrq_id assigned here in queuecommand
46707 */
46708- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46709+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46710 pinstance->num_hrrq;
46711 cmd->cmd_done = pmcraid_io_done;
46712
46713@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46714 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46715 * hrrq_id assigned here in queuecommand
46716 */
46717- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46718+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46719 pinstance->num_hrrq;
46720
46721 if (request_size) {
46722@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46723
46724 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46725 /* add resources only after host is added into system */
46726- if (!atomic_read(&pinstance->expose_resources))
46727+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46728 return;
46729
46730 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46731@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46732 init_waitqueue_head(&pinstance->reset_wait_q);
46733
46734 atomic_set(&pinstance->outstanding_cmds, 0);
46735- atomic_set(&pinstance->last_message_id, 0);
46736- atomic_set(&pinstance->expose_resources, 0);
46737+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46738+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46739
46740 INIT_LIST_HEAD(&pinstance->free_res_q);
46741 INIT_LIST_HEAD(&pinstance->used_res_q);
46742@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46743 /* Schedule worker thread to handle CCN and take care of adding and
46744 * removing devices to OS
46745 */
46746- atomic_set(&pinstance->expose_resources, 1);
46747+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46748 schedule_work(&pinstance->worker_q);
46749 return rc;
46750
46751diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46752index e1d150f..6c6df44 100644
46753--- a/drivers/scsi/pmcraid.h
46754+++ b/drivers/scsi/pmcraid.h
46755@@ -748,7 +748,7 @@ struct pmcraid_instance {
46756 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46757
46758 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46759- atomic_t last_message_id;
46760+ atomic_unchecked_t last_message_id;
46761
46762 /* configuration table */
46763 struct pmcraid_config_table *cfg_table;
46764@@ -777,7 +777,7 @@ struct pmcraid_instance {
46765 atomic_t outstanding_cmds;
46766
46767 /* should add/delete resources to mid-layer now ?*/
46768- atomic_t expose_resources;
46769+ atomic_unchecked_t expose_resources;
46770
46771
46772
46773@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46774 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46775 };
46776 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46777- atomic_t read_failures; /* count of failed READ commands */
46778- atomic_t write_failures; /* count of failed WRITE commands */
46779+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46780+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46781
46782 /* To indicate add/delete/modify during CCN */
46783 u8 change_detected;
46784diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46785index d7a99ae..801df70 100644
46786--- a/drivers/scsi/qla2xxx/qla_attr.c
46787+++ b/drivers/scsi/qla2xxx/qla_attr.c
46788@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46789 return 0;
46790 }
46791
46792-struct fc_function_template qla2xxx_transport_functions = {
46793+fc_function_template_no_const qla2xxx_transport_functions = {
46794
46795 .show_host_node_name = 1,
46796 .show_host_port_name = 1,
46797@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46798 .bsg_timeout = qla24xx_bsg_timeout,
46799 };
46800
46801-struct fc_function_template qla2xxx_transport_vport_functions = {
46802+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46803
46804 .show_host_node_name = 1,
46805 .show_host_port_name = 1,
46806diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46807index 2d98232..a84298e 100644
46808--- a/drivers/scsi/qla2xxx/qla_gbl.h
46809+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46810@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46811 struct device_attribute;
46812 extern struct device_attribute *qla2x00_host_attrs[];
46813 struct fc_function_template;
46814-extern struct fc_function_template qla2xxx_transport_functions;
46815-extern struct fc_function_template qla2xxx_transport_vport_functions;
46816+extern fc_function_template_no_const qla2xxx_transport_functions;
46817+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46818 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46819 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46820 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46821diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46822index 3e21e9f..426ba79 100644
46823--- a/drivers/scsi/qla2xxx/qla_os.c
46824+++ b/drivers/scsi/qla2xxx/qla_os.c
46825@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46826 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46827 /* Ok, a 64bit DMA mask is applicable. */
46828 ha->flags.enable_64bit_addressing = 1;
46829- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46830- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46831+ pax_open_kernel();
46832+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46833+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46834+ pax_close_kernel();
46835 return;
46836 }
46837 }
46838diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46839index ddf16a8..80f4dd0 100644
46840--- a/drivers/scsi/qla4xxx/ql4_def.h
46841+++ b/drivers/scsi/qla4xxx/ql4_def.h
46842@@ -291,7 +291,7 @@ struct ddb_entry {
46843 * (4000 only) */
46844 atomic_t relogin_timer; /* Max Time to wait for
46845 * relogin to complete */
46846- atomic_t relogin_retry_count; /* Num of times relogin has been
46847+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46848 * retried */
46849 uint32_t default_time2wait; /* Default Min time between
46850 * relogins (+aens) */
46851diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46852index b246b3c..897004d 100644
46853--- a/drivers/scsi/qla4xxx/ql4_os.c
46854+++ b/drivers/scsi/qla4xxx/ql4_os.c
46855@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46856 */
46857 if (!iscsi_is_session_online(cls_sess)) {
46858 /* Reset retry relogin timer */
46859- atomic_inc(&ddb_entry->relogin_retry_count);
46860+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46861 DEBUG2(ql4_printk(KERN_INFO, ha,
46862 "%s: index[%d] relogin timed out-retrying"
46863 " relogin (%d), retry (%d)\n", __func__,
46864 ddb_entry->fw_ddb_index,
46865- atomic_read(&ddb_entry->relogin_retry_count),
46866+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46867 ddb_entry->default_time2wait + 4));
46868 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46869 atomic_set(&ddb_entry->retry_relogin_timer,
46870@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46871
46872 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46873 atomic_set(&ddb_entry->relogin_timer, 0);
46874- atomic_set(&ddb_entry->relogin_retry_count, 0);
46875+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46876 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46877 ddb_entry->default_relogin_timeout =
46878 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46879diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46880index eaa808e..95f8841 100644
46881--- a/drivers/scsi/scsi.c
46882+++ b/drivers/scsi/scsi.c
46883@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46884 unsigned long timeout;
46885 int rtn = 0;
46886
46887- atomic_inc(&cmd->device->iorequest_cnt);
46888+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46889
46890 /* check if the device is still usable */
46891 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46892diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46893index 124392f..75eb43e 100644
46894--- a/drivers/scsi/scsi_lib.c
46895+++ b/drivers/scsi/scsi_lib.c
46896@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46897 shost = sdev->host;
46898 scsi_init_cmd_errh(cmd);
46899 cmd->result = DID_NO_CONNECT << 16;
46900- atomic_inc(&cmd->device->iorequest_cnt);
46901+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46902
46903 /*
46904 * SCSI request completion path will do scsi_device_unbusy(),
46905@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46906
46907 INIT_LIST_HEAD(&cmd->eh_entry);
46908
46909- atomic_inc(&cmd->device->iodone_cnt);
46910+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46911 if (cmd->result)
46912- atomic_inc(&cmd->device->ioerr_cnt);
46913+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46914
46915 disposition = scsi_decide_disposition(cmd);
46916 if (disposition != SUCCESS &&
46917diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46918index 7e50061..71db7a6 100644
46919--- a/drivers/scsi/scsi_sysfs.c
46920+++ b/drivers/scsi/scsi_sysfs.c
46921@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46922 char *buf) \
46923 { \
46924 struct scsi_device *sdev = to_scsi_device(dev); \
46925- unsigned long long count = atomic_read(&sdev->field); \
46926+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46927 return snprintf(buf, 20, "0x%llx\n", count); \
46928 } \
46929 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46930diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46931index 84a1fdf..693b0d6 100644
46932--- a/drivers/scsi/scsi_tgt_lib.c
46933+++ b/drivers/scsi/scsi_tgt_lib.c
46934@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46935 int err;
46936
46937 dprintk("%lx %u\n", uaddr, len);
46938- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46939+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46940 if (err) {
46941 /*
46942 * TODO: need to fixup sg_tablesize, max_segment_size,
46943diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46944index 4628fd5..a94a1c2 100644
46945--- a/drivers/scsi/scsi_transport_fc.c
46946+++ b/drivers/scsi/scsi_transport_fc.c
46947@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46948 * Netlink Infrastructure
46949 */
46950
46951-static atomic_t fc_event_seq;
46952+static atomic_unchecked_t fc_event_seq;
46953
46954 /**
46955 * fc_get_event_number - Obtain the next sequential FC event number
46956@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46957 u32
46958 fc_get_event_number(void)
46959 {
46960- return atomic_add_return(1, &fc_event_seq);
46961+ return atomic_add_return_unchecked(1, &fc_event_seq);
46962 }
46963 EXPORT_SYMBOL(fc_get_event_number);
46964
46965@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46966 {
46967 int error;
46968
46969- atomic_set(&fc_event_seq, 0);
46970+ atomic_set_unchecked(&fc_event_seq, 0);
46971
46972 error = transport_class_register(&fc_host_class);
46973 if (error)
46974@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46975 char *cp;
46976
46977 *val = simple_strtoul(buf, &cp, 0);
46978- if ((*cp && (*cp != '\n')) || (*val < 0))
46979+ if (*cp && (*cp != '\n'))
46980 return -EINVAL;
46981 /*
46982 * Check for overflow; dev_loss_tmo is u32
46983diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46984index abf7c40..c3240ed 100644
46985--- a/drivers/scsi/scsi_transport_iscsi.c
46986+++ b/drivers/scsi/scsi_transport_iscsi.c
46987@@ -80,7 +80,7 @@ struct iscsi_internal {
46988 struct transport_container session_cont;
46989 };
46990
46991-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46992+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46993 static struct workqueue_struct *iscsi_eh_timer_workq;
46994
46995 static DEFINE_IDA(iscsi_sess_ida);
46996@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46997 int err;
46998
46999 ihost = shost->shost_data;
47000- session->sid = atomic_add_return(1, &iscsi_session_nr);
47001+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47002
47003 if (target_id == ISCSI_MAX_TARGET) {
47004 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47005@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47006 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47007 ISCSI_TRANSPORT_VERSION);
47008
47009- atomic_set(&iscsi_session_nr, 0);
47010+ atomic_set_unchecked(&iscsi_session_nr, 0);
47011
47012 err = class_register(&iscsi_transport_class);
47013 if (err)
47014diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47015index f379c7f..e8fc69c 100644
47016--- a/drivers/scsi/scsi_transport_srp.c
47017+++ b/drivers/scsi/scsi_transport_srp.c
47018@@ -33,7 +33,7 @@
47019 #include "scsi_transport_srp_internal.h"
47020
47021 struct srp_host_attrs {
47022- atomic_t next_port_id;
47023+ atomic_unchecked_t next_port_id;
47024 };
47025 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47026
47027@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47028 struct Scsi_Host *shost = dev_to_shost(dev);
47029 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47030
47031- atomic_set(&srp_host->next_port_id, 0);
47032+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47033 return 0;
47034 }
47035
47036@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47037 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47038 rport->roles = ids->roles;
47039
47040- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47041+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47042 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47043
47044 transport_setup_device(&rport->dev);
47045diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47046index 2783dd7..d20395b 100644
47047--- a/drivers/scsi/sd.c
47048+++ b/drivers/scsi/sd.c
47049@@ -2933,7 +2933,7 @@ static int sd_probe(struct device *dev)
47050 sdkp->disk = gd;
47051 sdkp->index = index;
47052 atomic_set(&sdkp->openers, 0);
47053- atomic_set(&sdkp->device->ioerr_cnt, 0);
47054+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47055
47056 if (!sdp->request_queue->rq_timeout) {
47057 if (sdp->type != TYPE_MOD)
47058diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47059index df5e961..df6b97f 100644
47060--- a/drivers/scsi/sg.c
47061+++ b/drivers/scsi/sg.c
47062@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47063 sdp->disk->disk_name,
47064 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47065 NULL,
47066- (char *)arg);
47067+ (char __user *)arg);
47068 case BLKTRACESTART:
47069 return blk_trace_startstop(sdp->device->request_queue, 1);
47070 case BLKTRACESTOP:
47071diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47072index 978dda2..cb19aa0 100644
47073--- a/drivers/spi/spi.c
47074+++ b/drivers/spi/spi.c
47075@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47076 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47077
47078 /* portable code must never pass more than 32 bytes */
47079-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47080+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47081
47082 static u8 *buf;
47083
47084diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47085index ee3a57f..18368c1 100644
47086--- a/drivers/staging/android/timed_output.c
47087+++ b/drivers/staging/android/timed_output.c
47088@@ -25,7 +25,7 @@
47089 #include "timed_output.h"
47090
47091 static struct class *timed_output_class;
47092-static atomic_t device_count;
47093+static atomic_unchecked_t device_count;
47094
47095 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47096 char *buf)
47097@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47098 timed_output_class = class_create(THIS_MODULE, "timed_output");
47099 if (IS_ERR(timed_output_class))
47100 return PTR_ERR(timed_output_class);
47101- atomic_set(&device_count, 0);
47102+ atomic_set_unchecked(&device_count, 0);
47103 }
47104
47105 return 0;
47106@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47107 if (ret < 0)
47108 return ret;
47109
47110- tdev->index = atomic_inc_return(&device_count);
47111+ tdev->index = atomic_inc_return_unchecked(&device_count);
47112 tdev->dev = device_create(timed_output_class, NULL,
47113 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47114 if (IS_ERR(tdev->dev))
47115diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47116index 3675020..e80d92c 100644
47117--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47118+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47119@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47120
47121 static int solo_sysfs_init(struct solo_dev *solo_dev)
47122 {
47123- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47124+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47125 struct device *dev = &solo_dev->dev;
47126 const char *driver;
47127 int i;
47128diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47129index 3335941..2b26186 100644
47130--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47131+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47132@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47133
47134 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47135 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47136- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47137+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47138 if (p2m_id < 0)
47139 p2m_id = -p2m_id;
47140 }
47141diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47142index 6f91d2e..3f011d2 100644
47143--- a/drivers/staging/media/solo6x10/solo6x10.h
47144+++ b/drivers/staging/media/solo6x10/solo6x10.h
47145@@ -238,7 +238,7 @@ struct solo_dev {
47146
47147 /* P2M DMA Engine */
47148 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47149- atomic_t p2m_count;
47150+ atomic_unchecked_t p2m_count;
47151 int p2m_jiffies;
47152 unsigned int p2m_timeouts;
47153
47154diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47155index 34afc16..ffe44dd 100644
47156--- a/drivers/staging/octeon/ethernet-rx.c
47157+++ b/drivers/staging/octeon/ethernet-rx.c
47158@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47159 /* Increment RX stats for virtual ports */
47160 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47161 #ifdef CONFIG_64BIT
47162- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47163- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47164+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47165+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47166 #else
47167- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47168- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47169+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47170+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47171 #endif
47172 }
47173 netif_receive_skb(skb);
47174@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47175 dev->name);
47176 */
47177 #ifdef CONFIG_64BIT
47178- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47179+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47180 #else
47181- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47182+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47183 #endif
47184 dev_kfree_skb_irq(skb);
47185 }
47186diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47187index c3a90e7..023619a 100644
47188--- a/drivers/staging/octeon/ethernet.c
47189+++ b/drivers/staging/octeon/ethernet.c
47190@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47191 * since the RX tasklet also increments it.
47192 */
47193 #ifdef CONFIG_64BIT
47194- atomic64_add(rx_status.dropped_packets,
47195- (atomic64_t *)&priv->stats.rx_dropped);
47196+ atomic64_add_unchecked(rx_status.dropped_packets,
47197+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47198 #else
47199- atomic_add(rx_status.dropped_packets,
47200- (atomic_t *)&priv->stats.rx_dropped);
47201+ atomic_add_unchecked(rx_status.dropped_packets,
47202+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47203 #endif
47204 }
47205
47206diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47207index dc23395..cf7e9b1 100644
47208--- a/drivers/staging/rtl8712/rtl871x_io.h
47209+++ b/drivers/staging/rtl8712/rtl871x_io.h
47210@@ -108,7 +108,7 @@ struct _io_ops {
47211 u8 *pmem);
47212 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47213 u8 *pmem);
47214-};
47215+} __no_const;
47216
47217 struct io_req {
47218 struct list_head list;
47219diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47220index 1f5088b..0e59820 100644
47221--- a/drivers/staging/sbe-2t3e3/netdev.c
47222+++ b/drivers/staging/sbe-2t3e3/netdev.c
47223@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47224 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47225
47226 if (rlen)
47227- if (copy_to_user(data, &resp, rlen))
47228+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47229 return -EFAULT;
47230
47231 return 0;
47232diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47233index a863a98..d272795 100644
47234--- a/drivers/staging/usbip/vhci.h
47235+++ b/drivers/staging/usbip/vhci.h
47236@@ -83,7 +83,7 @@ struct vhci_hcd {
47237 unsigned resuming:1;
47238 unsigned long re_timeout;
47239
47240- atomic_t seqnum;
47241+ atomic_unchecked_t seqnum;
47242
47243 /*
47244 * NOTE:
47245diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47246index d7974cb..d78076b 100644
47247--- a/drivers/staging/usbip/vhci_hcd.c
47248+++ b/drivers/staging/usbip/vhci_hcd.c
47249@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47250
47251 spin_lock(&vdev->priv_lock);
47252
47253- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47254+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47255 if (priv->seqnum == 0xffff)
47256 dev_info(&urb->dev->dev, "seqnum max\n");
47257
47258@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47259 return -ENOMEM;
47260 }
47261
47262- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47263+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47264 if (unlink->seqnum == 0xffff)
47265 pr_info("seqnum max\n");
47266
47267@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47268 vdev->rhport = rhport;
47269 }
47270
47271- atomic_set(&vhci->seqnum, 0);
47272+ atomic_set_unchecked(&vhci->seqnum, 0);
47273 spin_lock_init(&vhci->lock);
47274
47275 hcd->power_budget = 0; /* no limit */
47276diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47277index d07fcb5..358e1e1 100644
47278--- a/drivers/staging/usbip/vhci_rx.c
47279+++ b/drivers/staging/usbip/vhci_rx.c
47280@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47281 if (!urb) {
47282 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47283 pr_info("max seqnum %d\n",
47284- atomic_read(&the_controller->seqnum));
47285+ atomic_read_unchecked(&the_controller->seqnum));
47286 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47287 return;
47288 }
47289diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47290index 57a08c5..5b4bb7c 100644
47291--- a/drivers/staging/vt6655/hostap.c
47292+++ b/drivers/staging/vt6655/hostap.c
47293@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47294 *
47295 */
47296
47297+static net_device_ops_no_const apdev_netdev_ops;
47298+
47299 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47300 {
47301 PSDevice apdev_priv;
47302 struct net_device *dev = pDevice->dev;
47303 int ret;
47304- const struct net_device_ops apdev_netdev_ops = {
47305- .ndo_start_xmit = pDevice->tx_80211,
47306- };
47307
47308 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47309
47310@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47311 *apdev_priv = *pDevice;
47312 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47313
47314+ /* only half broken now */
47315+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47316 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47317
47318 pDevice->apdev->type = ARPHRD_IEEE80211;
47319diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47320index c699a30..b90a5fd 100644
47321--- a/drivers/staging/vt6656/hostap.c
47322+++ b/drivers/staging/vt6656/hostap.c
47323@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47324 *
47325 */
47326
47327+static net_device_ops_no_const apdev_netdev_ops;
47328+
47329 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47330 {
47331 struct vnt_private *apdev_priv;
47332 struct net_device *dev = pDevice->dev;
47333 int ret;
47334- const struct net_device_ops apdev_netdev_ops = {
47335- .ndo_start_xmit = pDevice->tx_80211,
47336- };
47337
47338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47339
47340@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47341 *apdev_priv = *pDevice;
47342 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47343
47344+ /* only half broken now */
47345+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47346 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47347
47348 pDevice->apdev->type = ARPHRD_IEEE80211;
47349diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47350index d128ce2..fc1f9a1 100644
47351--- a/drivers/staging/zcache/tmem.h
47352+++ b/drivers/staging/zcache/tmem.h
47353@@ -225,7 +225,7 @@ struct tmem_pamops {
47354 bool (*is_remote)(void *);
47355 int (*replace_in_obj)(void *, struct tmem_obj *);
47356 #endif
47357-};
47358+} __no_const;
47359 extern void tmem_register_pamops(struct tmem_pamops *m);
47360
47361 /* memory allocation methods provided by the host implementation */
47362@@ -234,7 +234,7 @@ struct tmem_hostops {
47363 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47364 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47365 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47366-};
47367+} __no_const;
47368 extern void tmem_register_hostops(struct tmem_hostops *m);
47369
47370 /* core tmem accessor functions */
47371diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47372index e51b09a..5ebac31 100644
47373--- a/drivers/target/sbp/sbp_target.c
47374+++ b/drivers/target/sbp/sbp_target.c
47375@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47376
47377 #define SESSION_MAINTENANCE_INTERVAL HZ
47378
47379-static atomic_t login_id = ATOMIC_INIT(0);
47380+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47381
47382 static void session_maintenance_work(struct work_struct *);
47383 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47384@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47385 login->lun = se_lun;
47386 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47387 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47388- login->login_id = atomic_inc_return(&login_id);
47389+ login->login_id = atomic_inc_return_unchecked(&login_id);
47390
47391 login->tgt_agt = sbp_target_agent_register(login);
47392 if (IS_ERR(login->tgt_agt)) {
47393diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47394index 8f4142f..b127f7d 100644
47395--- a/drivers/target/target_core_device.c
47396+++ b/drivers/target/target_core_device.c
47397@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47398 spin_lock_init(&dev->se_port_lock);
47399 spin_lock_init(&dev->se_tmr_lock);
47400 spin_lock_init(&dev->qf_cmd_lock);
47401- atomic_set(&dev->dev_ordered_id, 0);
47402+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47403 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47404 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47405 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47406diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47407index d8e49d7..6fcfdec 100644
47408--- a/drivers/target/target_core_transport.c
47409+++ b/drivers/target/target_core_transport.c
47410@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47411 * Used to determine when ORDERED commands should go from
47412 * Dormant to Active status.
47413 */
47414- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47415+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47416 smp_mb__after_atomic_inc();
47417 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47418 cmd->se_ordered_id, cmd->sam_task_attr,
47419diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47420index 33f83fe..d80f8e1 100644
47421--- a/drivers/tty/cyclades.c
47422+++ b/drivers/tty/cyclades.c
47423@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47424 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47425 info->port.count);
47426 #endif
47427- info->port.count++;
47428+ atomic_inc(&info->port.count);
47429 #ifdef CY_DEBUG_COUNT
47430 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47431- current->pid, info->port.count);
47432+ current->pid, atomic_read(&info->port.count));
47433 #endif
47434
47435 /*
47436@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47437 for (j = 0; j < cy_card[i].nports; j++) {
47438 info = &cy_card[i].ports[j];
47439
47440- if (info->port.count) {
47441+ if (atomic_read(&info->port.count)) {
47442 /* XXX is the ldisc num worth this? */
47443 struct tty_struct *tty;
47444 struct tty_ldisc *ld;
47445diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47446index eb255e8..f637a57 100644
47447--- a/drivers/tty/hvc/hvc_console.c
47448+++ b/drivers/tty/hvc/hvc_console.c
47449@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47450
47451 spin_lock_irqsave(&hp->port.lock, flags);
47452 /* Check and then increment for fast path open. */
47453- if (hp->port.count++ > 0) {
47454+ if (atomic_inc_return(&hp->port.count) > 1) {
47455 spin_unlock_irqrestore(&hp->port.lock, flags);
47456 hvc_kick();
47457 return 0;
47458@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47459
47460 spin_lock_irqsave(&hp->port.lock, flags);
47461
47462- if (--hp->port.count == 0) {
47463+ if (atomic_dec_return(&hp->port.count) == 0) {
47464 spin_unlock_irqrestore(&hp->port.lock, flags);
47465 /* We are done with the tty pointer now. */
47466 tty_port_tty_set(&hp->port, NULL);
47467@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47468 */
47469 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47470 } else {
47471- if (hp->port.count < 0)
47472+ if (atomic_read(&hp->port.count) < 0)
47473 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47474- hp->vtermno, hp->port.count);
47475+ hp->vtermno, atomic_read(&hp->port.count));
47476 spin_unlock_irqrestore(&hp->port.lock, flags);
47477 }
47478 }
47479@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47480 * open->hangup case this can be called after the final close so prevent
47481 * that from happening for now.
47482 */
47483- if (hp->port.count <= 0) {
47484+ if (atomic_read(&hp->port.count) <= 0) {
47485 spin_unlock_irqrestore(&hp->port.lock, flags);
47486 return;
47487 }
47488
47489- hp->port.count = 0;
47490+ atomic_set(&hp->port.count, 0);
47491 spin_unlock_irqrestore(&hp->port.lock, flags);
47492 tty_port_tty_set(&hp->port, NULL);
47493
47494@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47495 return -EPIPE;
47496
47497 /* FIXME what's this (unprotected) check for? */
47498- if (hp->port.count <= 0)
47499+ if (atomic_read(&hp->port.count) <= 0)
47500 return -EIO;
47501
47502 spin_lock_irqsave(&hp->lock, flags);
47503diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47504index 81e939e..95ead10 100644
47505--- a/drivers/tty/hvc/hvcs.c
47506+++ b/drivers/tty/hvc/hvcs.c
47507@@ -83,6 +83,7 @@
47508 #include <asm/hvcserver.h>
47509 #include <asm/uaccess.h>
47510 #include <asm/vio.h>
47511+#include <asm/local.h>
47512
47513 /*
47514 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47515@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47516
47517 spin_lock_irqsave(&hvcsd->lock, flags);
47518
47519- if (hvcsd->port.count > 0) {
47520+ if (atomic_read(&hvcsd->port.count) > 0) {
47521 spin_unlock_irqrestore(&hvcsd->lock, flags);
47522 printk(KERN_INFO "HVCS: vterm state unchanged. "
47523 "The hvcs device node is still in use.\n");
47524@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47525 }
47526 }
47527
47528- hvcsd->port.count = 0;
47529+ atomic_set(&hvcsd->port.count, 0);
47530 hvcsd->port.tty = tty;
47531 tty->driver_data = hvcsd;
47532
47533@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47534 unsigned long flags;
47535
47536 spin_lock_irqsave(&hvcsd->lock, flags);
47537- hvcsd->port.count++;
47538+ atomic_inc(&hvcsd->port.count);
47539 hvcsd->todo_mask |= HVCS_SCHED_READ;
47540 spin_unlock_irqrestore(&hvcsd->lock, flags);
47541
47542@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47543 hvcsd = tty->driver_data;
47544
47545 spin_lock_irqsave(&hvcsd->lock, flags);
47546- if (--hvcsd->port.count == 0) {
47547+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47548
47549 vio_disable_interrupts(hvcsd->vdev);
47550
47551@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47552
47553 free_irq(irq, hvcsd);
47554 return;
47555- } else if (hvcsd->port.count < 0) {
47556+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47557 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47558 " is missmanaged.\n",
47559- hvcsd->vdev->unit_address, hvcsd->port.count);
47560+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47561 }
47562
47563 spin_unlock_irqrestore(&hvcsd->lock, flags);
47564@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47565
47566 spin_lock_irqsave(&hvcsd->lock, flags);
47567 /* Preserve this so that we know how many kref refs to put */
47568- temp_open_count = hvcsd->port.count;
47569+ temp_open_count = atomic_read(&hvcsd->port.count);
47570
47571 /*
47572 * Don't kref put inside the spinlock because the destruction
47573@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47574 tty->driver_data = NULL;
47575 hvcsd->port.tty = NULL;
47576
47577- hvcsd->port.count = 0;
47578+ atomic_set(&hvcsd->port.count, 0);
47579
47580 /* This will drop any buffered data on the floor which is OK in a hangup
47581 * scenario. */
47582@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47583 * the middle of a write operation? This is a crummy place to do this
47584 * but we want to keep it all in the spinlock.
47585 */
47586- if (hvcsd->port.count <= 0) {
47587+ if (atomic_read(&hvcsd->port.count) <= 0) {
47588 spin_unlock_irqrestore(&hvcsd->lock, flags);
47589 return -ENODEV;
47590 }
47591@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47592 {
47593 struct hvcs_struct *hvcsd = tty->driver_data;
47594
47595- if (!hvcsd || hvcsd->port.count <= 0)
47596+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47597 return 0;
47598
47599 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47600diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47601index 4190199..48f2920 100644
47602--- a/drivers/tty/hvc/hvsi.c
47603+++ b/drivers/tty/hvc/hvsi.c
47604@@ -85,7 +85,7 @@ struct hvsi_struct {
47605 int n_outbuf;
47606 uint32_t vtermno;
47607 uint32_t virq;
47608- atomic_t seqno; /* HVSI packet sequence number */
47609+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47610 uint16_t mctrl;
47611 uint8_t state; /* HVSI protocol state */
47612 uint8_t flags;
47613@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47614
47615 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47616 packet.hdr.len = sizeof(struct hvsi_query_response);
47617- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47618+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47619 packet.verb = VSV_SEND_VERSION_NUMBER;
47620 packet.u.version = HVSI_VERSION;
47621 packet.query_seqno = query_seqno+1;
47622@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47623
47624 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47625 packet.hdr.len = sizeof(struct hvsi_query);
47626- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47627+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47628 packet.verb = verb;
47629
47630 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47631@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47632 int wrote;
47633
47634 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47635- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47636+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47637 packet.hdr.len = sizeof(struct hvsi_control);
47638 packet.verb = VSV_SET_MODEM_CTL;
47639 packet.mask = HVSI_TSDTR;
47640@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47641 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47642
47643 packet.hdr.type = VS_DATA_PACKET_HEADER;
47644- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47645+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47646 packet.hdr.len = count + sizeof(struct hvsi_header);
47647 memcpy(&packet.data, buf, count);
47648
47649@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47650 struct hvsi_control packet __ALIGNED__;
47651
47652 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47653- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47654+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47655 packet.hdr.len = 6;
47656 packet.verb = VSV_CLOSE_PROTOCOL;
47657
47658diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47659index ac27671..0f627ee 100644
47660--- a/drivers/tty/hvc/hvsi_lib.c
47661+++ b/drivers/tty/hvc/hvsi_lib.c
47662@@ -9,7 +9,7 @@
47663
47664 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47665 {
47666- packet->seqno = atomic_inc_return(&pv->seqno);
47667+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47668
47669 /* Assumes that always succeeds, works in practice */
47670 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47671@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47672
47673 /* Reset state */
47674 pv->established = 0;
47675- atomic_set(&pv->seqno, 0);
47676+ atomic_set_unchecked(&pv->seqno, 0);
47677
47678 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47679
47680@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47681 pv->mctrl_update = 0;
47682 q.hdr.type = VS_QUERY_PACKET_HEADER;
47683 q.hdr.len = sizeof(struct hvsi_query);
47684- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47685+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47686 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47687 rc = hvsi_send_packet(pv, &q.hdr);
47688 if (rc <= 0) {
47689diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47690index 8fd72ff..34a0bed 100644
47691--- a/drivers/tty/ipwireless/tty.c
47692+++ b/drivers/tty/ipwireless/tty.c
47693@@ -29,6 +29,7 @@
47694 #include <linux/tty_driver.h>
47695 #include <linux/tty_flip.h>
47696 #include <linux/uaccess.h>
47697+#include <asm/local.h>
47698
47699 #include "tty.h"
47700 #include "network.h"
47701@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47702 mutex_unlock(&tty->ipw_tty_mutex);
47703 return -ENODEV;
47704 }
47705- if (tty->port.count == 0)
47706+ if (atomic_read(&tty->port.count) == 0)
47707 tty->tx_bytes_queued = 0;
47708
47709- tty->port.count++;
47710+ atomic_inc(&tty->port.count);
47711
47712 tty->port.tty = linux_tty;
47713 linux_tty->driver_data = tty;
47714@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47715
47716 static void do_ipw_close(struct ipw_tty *tty)
47717 {
47718- tty->port.count--;
47719-
47720- if (tty->port.count == 0) {
47721+ if (atomic_dec_return(&tty->port.count) == 0) {
47722 struct tty_struct *linux_tty = tty->port.tty;
47723
47724 if (linux_tty != NULL) {
47725@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47726 return;
47727
47728 mutex_lock(&tty->ipw_tty_mutex);
47729- if (tty->port.count == 0) {
47730+ if (atomic_read(&tty->port.count) == 0) {
47731 mutex_unlock(&tty->ipw_tty_mutex);
47732 return;
47733 }
47734@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47735
47736 mutex_lock(&tty->ipw_tty_mutex);
47737
47738- if (!tty->port.count) {
47739+ if (!atomic_read(&tty->port.count)) {
47740 mutex_unlock(&tty->ipw_tty_mutex);
47741 return;
47742 }
47743@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47744 return -ENODEV;
47745
47746 mutex_lock(&tty->ipw_tty_mutex);
47747- if (!tty->port.count) {
47748+ if (!atomic_read(&tty->port.count)) {
47749 mutex_unlock(&tty->ipw_tty_mutex);
47750 return -EINVAL;
47751 }
47752@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47753 if (!tty)
47754 return -ENODEV;
47755
47756- if (!tty->port.count)
47757+ if (!atomic_read(&tty->port.count))
47758 return -EINVAL;
47759
47760 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47761@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47762 if (!tty)
47763 return 0;
47764
47765- if (!tty->port.count)
47766+ if (!atomic_read(&tty->port.count))
47767 return 0;
47768
47769 return tty->tx_bytes_queued;
47770@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47771 if (!tty)
47772 return -ENODEV;
47773
47774- if (!tty->port.count)
47775+ if (!atomic_read(&tty->port.count))
47776 return -EINVAL;
47777
47778 return get_control_lines(tty);
47779@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47780 if (!tty)
47781 return -ENODEV;
47782
47783- if (!tty->port.count)
47784+ if (!atomic_read(&tty->port.count))
47785 return -EINVAL;
47786
47787 return set_control_lines(tty, set, clear);
47788@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47789 if (!tty)
47790 return -ENODEV;
47791
47792- if (!tty->port.count)
47793+ if (!atomic_read(&tty->port.count))
47794 return -EINVAL;
47795
47796 /* FIXME: Exactly how is the tty object locked here .. */
47797@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47798 * are gone */
47799 mutex_lock(&ttyj->ipw_tty_mutex);
47800 }
47801- while (ttyj->port.count)
47802+ while (atomic_read(&ttyj->port.count))
47803 do_ipw_close(ttyj);
47804 ipwireless_disassociate_network_ttys(network,
47805 ttyj->channel_idx);
47806diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47807index 1deaca4..c8582d4 100644
47808--- a/drivers/tty/moxa.c
47809+++ b/drivers/tty/moxa.c
47810@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47811 }
47812
47813 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47814- ch->port.count++;
47815+ atomic_inc(&ch->port.count);
47816 tty->driver_data = ch;
47817 tty_port_tty_set(&ch->port, tty);
47818 mutex_lock(&ch->port.mutex);
47819diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47820index 6422390..49003ac8 100644
47821--- a/drivers/tty/n_gsm.c
47822+++ b/drivers/tty/n_gsm.c
47823@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47824 spin_lock_init(&dlci->lock);
47825 mutex_init(&dlci->mutex);
47826 dlci->fifo = &dlci->_fifo;
47827- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47828+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47829 kfree(dlci);
47830 return NULL;
47831 }
47832@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47833 struct gsm_dlci *dlci = tty->driver_data;
47834 struct tty_port *port = &dlci->port;
47835
47836- port->count++;
47837+ atomic_inc(&port->count);
47838 dlci_get(dlci);
47839 dlci_get(dlci->gsm->dlci[0]);
47840 mux_get(dlci->gsm);
47841diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47842index 4bf0fc0..433bd58 100644
47843--- a/drivers/tty/n_tty.c
47844+++ b/drivers/tty/n_tty.c
47845@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47846 {
47847 *ops = tty_ldisc_N_TTY;
47848 ops->owner = NULL;
47849- ops->refcount = ops->flags = 0;
47850+ atomic_set(&ops->refcount, 0);
47851+ ops->flags = 0;
47852 }
47853 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47854diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47855index abfd990..5ab5da9 100644
47856--- a/drivers/tty/pty.c
47857+++ b/drivers/tty/pty.c
47858@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
47859 panic("Couldn't register Unix98 pts driver");
47860
47861 /* Now create the /dev/ptmx special device */
47862+ pax_open_kernel();
47863 tty_default_fops(&ptmx_fops);
47864- ptmx_fops.open = ptmx_open;
47865+ *(void **)&ptmx_fops.open = ptmx_open;
47866+ pax_close_kernel();
47867
47868 cdev_init(&ptmx_cdev, &ptmx_fops);
47869 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47870diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47871index 354564e..fe50d9a 100644
47872--- a/drivers/tty/rocket.c
47873+++ b/drivers/tty/rocket.c
47874@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47875 tty->driver_data = info;
47876 tty_port_tty_set(port, tty);
47877
47878- if (port->count++ == 0) {
47879+ if (atomic_inc_return(&port->count) == 1) {
47880 atomic_inc(&rp_num_ports_open);
47881
47882 #ifdef ROCKET_DEBUG_OPEN
47883@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47884 #endif
47885 }
47886 #ifdef ROCKET_DEBUG_OPEN
47887- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47888+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47889 #endif
47890
47891 /*
47892@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47893 spin_unlock_irqrestore(&info->port.lock, flags);
47894 return;
47895 }
47896- if (info->port.count)
47897+ if (atomic_read(&info->port.count))
47898 atomic_dec(&rp_num_ports_open);
47899 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47900 spin_unlock_irqrestore(&info->port.lock, flags);
47901diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47902index e2520ab..034e20b 100644
47903--- a/drivers/tty/serial/ioc4_serial.c
47904+++ b/drivers/tty/serial/ioc4_serial.c
47905@@ -437,7 +437,7 @@ struct ioc4_soft {
47906 } is_intr_info[MAX_IOC4_INTR_ENTS];
47907
47908 /* Number of entries active in the above array */
47909- atomic_t is_num_intrs;
47910+ atomic_unchecked_t is_num_intrs;
47911 } is_intr_type[IOC4_NUM_INTR_TYPES];
47912
47913 /* is_ir_lock must be held while
47914@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47915 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47916 || (type == IOC4_OTHER_INTR_TYPE)));
47917
47918- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47919+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47920 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47921
47922 /* Save off the lower level interrupt handler */
47923@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47924
47925 soft = arg;
47926 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47927- num_intrs = (int)atomic_read(
47928+ num_intrs = (int)atomic_read_unchecked(
47929 &soft->is_intr_type[intr_type].is_num_intrs);
47930
47931 this_mir = this_ir = pending_intrs(soft, intr_type);
47932diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47933index 1002054..dd644a8 100644
47934--- a/drivers/tty/serial/kgdboc.c
47935+++ b/drivers/tty/serial/kgdboc.c
47936@@ -24,8 +24,9 @@
47937 #define MAX_CONFIG_LEN 40
47938
47939 static struct kgdb_io kgdboc_io_ops;
47940+static struct kgdb_io kgdboc_io_ops_console;
47941
47942-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47943+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47944 static int configured = -1;
47945
47946 static char config[MAX_CONFIG_LEN];
47947@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47948 kgdboc_unregister_kbd();
47949 if (configured == 1)
47950 kgdb_unregister_io_module(&kgdboc_io_ops);
47951+ else if (configured == 2)
47952+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47953 }
47954
47955 static int configure_kgdboc(void)
47956@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47957 int err;
47958 char *cptr = config;
47959 struct console *cons;
47960+ int is_console = 0;
47961
47962 err = kgdboc_option_setup(config);
47963 if (err || !strlen(config) || isspace(config[0]))
47964 goto noconfig;
47965
47966 err = -ENODEV;
47967- kgdboc_io_ops.is_console = 0;
47968 kgdb_tty_driver = NULL;
47969
47970 kgdboc_use_kms = 0;
47971@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47972 int idx;
47973 if (cons->device && cons->device(cons, &idx) == p &&
47974 idx == tty_line) {
47975- kgdboc_io_ops.is_console = 1;
47976+ is_console = 1;
47977 break;
47978 }
47979 cons = cons->next;
47980@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47981 kgdb_tty_line = tty_line;
47982
47983 do_register:
47984- err = kgdb_register_io_module(&kgdboc_io_ops);
47985+ if (is_console) {
47986+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47987+ configured = 2;
47988+ } else {
47989+ err = kgdb_register_io_module(&kgdboc_io_ops);
47990+ configured = 1;
47991+ }
47992 if (err)
47993 goto noconfig;
47994
47995@@ -205,8 +214,6 @@ do_register:
47996 if (err)
47997 goto nmi_con_failed;
47998
47999- configured = 1;
48000-
48001 return 0;
48002
48003 nmi_con_failed:
48004@@ -223,7 +230,7 @@ noconfig:
48005 static int __init init_kgdboc(void)
48006 {
48007 /* Already configured? */
48008- if (configured == 1)
48009+ if (configured >= 1)
48010 return 0;
48011
48012 return configure_kgdboc();
48013@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48014 if (config[len - 1] == '\n')
48015 config[len - 1] = '\0';
48016
48017- if (configured == 1)
48018+ if (configured >= 1)
48019 cleanup_kgdboc();
48020
48021 /* Go and configure with the new params. */
48022@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48023 .post_exception = kgdboc_post_exp_handler,
48024 };
48025
48026+static struct kgdb_io kgdboc_io_ops_console = {
48027+ .name = "kgdboc",
48028+ .read_char = kgdboc_get_char,
48029+ .write_char = kgdboc_put_char,
48030+ .pre_exception = kgdboc_pre_exp_handler,
48031+ .post_exception = kgdboc_post_exp_handler,
48032+ .is_console = 1
48033+};
48034+
48035 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48036 /* This is only available if kgdboc is a built in for early debugging */
48037 static int __init kgdboc_early_init(char *opt)
48038diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48039index 2c6cfb3..048274e 100644
48040--- a/drivers/tty/serial/msm_serial.c
48041+++ b/drivers/tty/serial/msm_serial.c
48042@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48043 .cons = MSM_CONSOLE,
48044 };
48045
48046-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48047+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48048
48049 static int __init msm_serial_probe(struct platform_device *pdev)
48050 {
48051@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48052 int irq;
48053
48054 if (pdev->id == -1)
48055- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48056+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48057
48058 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48059 return -ENXIO;
48060diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48061index 376079b..d8de7aa 100644
48062--- a/drivers/tty/serial/samsung.c
48063+++ b/drivers/tty/serial/samsung.c
48064@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48065 }
48066 }
48067
48068+static int s3c64xx_serial_startup(struct uart_port *port);
48069 static int s3c24xx_serial_startup(struct uart_port *port)
48070 {
48071 struct s3c24xx_uart_port *ourport = to_ourport(port);
48072 int ret;
48073
48074+ /* Startup sequence is different for s3c64xx and higher SoC's */
48075+ if (s3c24xx_serial_has_interrupt_mask(port))
48076+ return s3c64xx_serial_startup(port);
48077+
48078 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48079 port->mapbase, port->membase);
48080
48081@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48082 /* setup info for port */
48083 port->dev = &platdev->dev;
48084
48085- /* Startup sequence is different for s3c64xx and higher SoC's */
48086- if (s3c24xx_serial_has_interrupt_mask(port))
48087- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48088-
48089 port->uartclk = 1;
48090
48091 if (cfg->uart_flags & UPF_CONS_FLOW) {
48092diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48093index 28cdd28..56f1d60 100644
48094--- a/drivers/tty/serial/serial_core.c
48095+++ b/drivers/tty/serial/serial_core.c
48096@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48097 uart_flush_buffer(tty);
48098 uart_shutdown(tty, state);
48099 spin_lock_irqsave(&port->lock, flags);
48100- port->count = 0;
48101+ atomic_set(&port->count, 0);
48102 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48103 spin_unlock_irqrestore(&port->lock, flags);
48104 tty_port_tty_set(port, NULL);
48105@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48106 goto end;
48107 }
48108
48109- port->count++;
48110+ atomic_inc(&port->count);
48111 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48112 retval = -ENXIO;
48113 goto err_dec_count;
48114@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48115 /*
48116 * Make sure the device is in D0 state.
48117 */
48118- if (port->count == 1)
48119+ if (atomic_read(&port->count) == 1)
48120 uart_change_pm(state, UART_PM_STATE_ON);
48121
48122 /*
48123@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48124 end:
48125 return retval;
48126 err_dec_count:
48127- port->count--;
48128+ atomic_inc(&port->count);
48129 mutex_unlock(&port->mutex);
48130 goto end;
48131 }
48132diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48133index 8eaf1ab..85c030d 100644
48134--- a/drivers/tty/synclink.c
48135+++ b/drivers/tty/synclink.c
48136@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48137
48138 if (debug_level >= DEBUG_LEVEL_INFO)
48139 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48140- __FILE__,__LINE__, info->device_name, info->port.count);
48141+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48142
48143 if (tty_port_close_start(&info->port, tty, filp) == 0)
48144 goto cleanup;
48145@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48146 cleanup:
48147 if (debug_level >= DEBUG_LEVEL_INFO)
48148 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48149- tty->driver->name, info->port.count);
48150+ tty->driver->name, atomic_read(&info->port.count));
48151
48152 } /* end of mgsl_close() */
48153
48154@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48155
48156 mgsl_flush_buffer(tty);
48157 shutdown(info);
48158-
48159- info->port.count = 0;
48160+
48161+ atomic_set(&info->port.count, 0);
48162 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48163 info->port.tty = NULL;
48164
48165@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48166
48167 if (debug_level >= DEBUG_LEVEL_INFO)
48168 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48169- __FILE__,__LINE__, tty->driver->name, port->count );
48170+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48171
48172 spin_lock_irqsave(&info->irq_spinlock, flags);
48173 if (!tty_hung_up_p(filp)) {
48174 extra_count = true;
48175- port->count--;
48176+ atomic_dec(&port->count);
48177 }
48178 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48179 port->blocked_open++;
48180@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48181
48182 if (debug_level >= DEBUG_LEVEL_INFO)
48183 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48184- __FILE__,__LINE__, tty->driver->name, port->count );
48185+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48186
48187 tty_unlock(tty);
48188 schedule();
48189@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48190
48191 /* FIXME: Racy on hangup during close wait */
48192 if (extra_count)
48193- port->count++;
48194+ atomic_inc(&port->count);
48195 port->blocked_open--;
48196
48197 if (debug_level >= DEBUG_LEVEL_INFO)
48198 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48199- __FILE__,__LINE__, tty->driver->name, port->count );
48200+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48201
48202 if (!retval)
48203 port->flags |= ASYNC_NORMAL_ACTIVE;
48204@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48205
48206 if (debug_level >= DEBUG_LEVEL_INFO)
48207 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48208- __FILE__,__LINE__,tty->driver->name, info->port.count);
48209+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48210
48211 /* If port is closing, signal caller to try again */
48212 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48213@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48214 spin_unlock_irqrestore(&info->netlock, flags);
48215 goto cleanup;
48216 }
48217- info->port.count++;
48218+ atomic_inc(&info->port.count);
48219 spin_unlock_irqrestore(&info->netlock, flags);
48220
48221- if (info->port.count == 1) {
48222+ if (atomic_read(&info->port.count) == 1) {
48223 /* 1st open on this device, init hardware */
48224 retval = startup(info);
48225 if (retval < 0)
48226@@ -3446,8 +3446,8 @@ cleanup:
48227 if (retval) {
48228 if (tty->count == 1)
48229 info->port.tty = NULL; /* tty layer will release tty struct */
48230- if(info->port.count)
48231- info->port.count--;
48232+ if (atomic_read(&info->port.count))
48233+ atomic_dec(&info->port.count);
48234 }
48235
48236 return retval;
48237@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48238 unsigned short new_crctype;
48239
48240 /* return error if TTY interface open */
48241- if (info->port.count)
48242+ if (atomic_read(&info->port.count))
48243 return -EBUSY;
48244
48245 switch (encoding)
48246@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48247
48248 /* arbitrate between network and tty opens */
48249 spin_lock_irqsave(&info->netlock, flags);
48250- if (info->port.count != 0 || info->netcount != 0) {
48251+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48252 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48253 spin_unlock_irqrestore(&info->netlock, flags);
48254 return -EBUSY;
48255@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48256 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48257
48258 /* return error if TTY interface open */
48259- if (info->port.count)
48260+ if (atomic_read(&info->port.count))
48261 return -EBUSY;
48262
48263 if (cmd != SIOCWANDEV)
48264diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48265index 1abf946..1ee34fc 100644
48266--- a/drivers/tty/synclink_gt.c
48267+++ b/drivers/tty/synclink_gt.c
48268@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48269 tty->driver_data = info;
48270 info->port.tty = tty;
48271
48272- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48273+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48274
48275 /* If port is closing, signal caller to try again */
48276 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48277@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48278 mutex_unlock(&info->port.mutex);
48279 goto cleanup;
48280 }
48281- info->port.count++;
48282+ atomic_inc(&info->port.count);
48283 spin_unlock_irqrestore(&info->netlock, flags);
48284
48285- if (info->port.count == 1) {
48286+ if (atomic_read(&info->port.count) == 1) {
48287 /* 1st open on this device, init hardware */
48288 retval = startup(info);
48289 if (retval < 0) {
48290@@ -715,8 +715,8 @@ cleanup:
48291 if (retval) {
48292 if (tty->count == 1)
48293 info->port.tty = NULL; /* tty layer will release tty struct */
48294- if(info->port.count)
48295- info->port.count--;
48296+ if(atomic_read(&info->port.count))
48297+ atomic_dec(&info->port.count);
48298 }
48299
48300 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48301@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48302
48303 if (sanity_check(info, tty->name, "close"))
48304 return;
48305- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48306+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48307
48308 if (tty_port_close_start(&info->port, tty, filp) == 0)
48309 goto cleanup;
48310@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48311 tty_port_close_end(&info->port, tty);
48312 info->port.tty = NULL;
48313 cleanup:
48314- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48315+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48316 }
48317
48318 static void hangup(struct tty_struct *tty)
48319@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48320 shutdown(info);
48321
48322 spin_lock_irqsave(&info->port.lock, flags);
48323- info->port.count = 0;
48324+ atomic_set(&info->port.count, 0);
48325 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48326 info->port.tty = NULL;
48327 spin_unlock_irqrestore(&info->port.lock, flags);
48328@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48329 unsigned short new_crctype;
48330
48331 /* return error if TTY interface open */
48332- if (info->port.count)
48333+ if (atomic_read(&info->port.count))
48334 return -EBUSY;
48335
48336 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48337@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48338
48339 /* arbitrate between network and tty opens */
48340 spin_lock_irqsave(&info->netlock, flags);
48341- if (info->port.count != 0 || info->netcount != 0) {
48342+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48343 DBGINFO(("%s hdlc_open busy\n", dev->name));
48344 spin_unlock_irqrestore(&info->netlock, flags);
48345 return -EBUSY;
48346@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48347 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48348
48349 /* return error if TTY interface open */
48350- if (info->port.count)
48351+ if (atomic_read(&info->port.count))
48352 return -EBUSY;
48353
48354 if (cmd != SIOCWANDEV)
48355@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48356 if (port == NULL)
48357 continue;
48358 spin_lock(&port->lock);
48359- if ((port->port.count || port->netcount) &&
48360+ if ((atomic_read(&port->port.count) || port->netcount) &&
48361 port->pending_bh && !port->bh_running &&
48362 !port->bh_requested) {
48363 DBGISR(("%s bh queued\n", port->device_name));
48364@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48365 spin_lock_irqsave(&info->lock, flags);
48366 if (!tty_hung_up_p(filp)) {
48367 extra_count = true;
48368- port->count--;
48369+ atomic_dec(&port->count);
48370 }
48371 spin_unlock_irqrestore(&info->lock, flags);
48372 port->blocked_open++;
48373@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48374 remove_wait_queue(&port->open_wait, &wait);
48375
48376 if (extra_count)
48377- port->count++;
48378+ atomic_inc(&port->count);
48379 port->blocked_open--;
48380
48381 if (!retval)
48382diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48383index dc6e969..5dc8786 100644
48384--- a/drivers/tty/synclinkmp.c
48385+++ b/drivers/tty/synclinkmp.c
48386@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48387
48388 if (debug_level >= DEBUG_LEVEL_INFO)
48389 printk("%s(%d):%s open(), old ref count = %d\n",
48390- __FILE__,__LINE__,tty->driver->name, info->port.count);
48391+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48392
48393 /* If port is closing, signal caller to try again */
48394 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48395@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48396 spin_unlock_irqrestore(&info->netlock, flags);
48397 goto cleanup;
48398 }
48399- info->port.count++;
48400+ atomic_inc(&info->port.count);
48401 spin_unlock_irqrestore(&info->netlock, flags);
48402
48403- if (info->port.count == 1) {
48404+ if (atomic_read(&info->port.count) == 1) {
48405 /* 1st open on this device, init hardware */
48406 retval = startup(info);
48407 if (retval < 0)
48408@@ -796,8 +796,8 @@ cleanup:
48409 if (retval) {
48410 if (tty->count == 1)
48411 info->port.tty = NULL; /* tty layer will release tty struct */
48412- if(info->port.count)
48413- info->port.count--;
48414+ if(atomic_read(&info->port.count))
48415+ atomic_dec(&info->port.count);
48416 }
48417
48418 return retval;
48419@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48420
48421 if (debug_level >= DEBUG_LEVEL_INFO)
48422 printk("%s(%d):%s close() entry, count=%d\n",
48423- __FILE__,__LINE__, info->device_name, info->port.count);
48424+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48425
48426 if (tty_port_close_start(&info->port, tty, filp) == 0)
48427 goto cleanup;
48428@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48429 cleanup:
48430 if (debug_level >= DEBUG_LEVEL_INFO)
48431 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48432- tty->driver->name, info->port.count);
48433+ tty->driver->name, atomic_read(&info->port.count));
48434 }
48435
48436 /* Called by tty_hangup() when a hangup is signaled.
48437@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48438 shutdown(info);
48439
48440 spin_lock_irqsave(&info->port.lock, flags);
48441- info->port.count = 0;
48442+ atomic_set(&info->port.count, 0);
48443 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48444 info->port.tty = NULL;
48445 spin_unlock_irqrestore(&info->port.lock, flags);
48446@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48447 unsigned short new_crctype;
48448
48449 /* return error if TTY interface open */
48450- if (info->port.count)
48451+ if (atomic_read(&info->port.count))
48452 return -EBUSY;
48453
48454 switch (encoding)
48455@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48456
48457 /* arbitrate between network and tty opens */
48458 spin_lock_irqsave(&info->netlock, flags);
48459- if (info->port.count != 0 || info->netcount != 0) {
48460+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48461 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48462 spin_unlock_irqrestore(&info->netlock, flags);
48463 return -EBUSY;
48464@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48465 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48466
48467 /* return error if TTY interface open */
48468- if (info->port.count)
48469+ if (atomic_read(&info->port.count))
48470 return -EBUSY;
48471
48472 if (cmd != SIOCWANDEV)
48473@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48474 * do not request bottom half processing if the
48475 * device is not open in a normal mode.
48476 */
48477- if ( port && (port->port.count || port->netcount) &&
48478+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48479 port->pending_bh && !port->bh_running &&
48480 !port->bh_requested ) {
48481 if ( debug_level >= DEBUG_LEVEL_ISR )
48482@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48483
48484 if (debug_level >= DEBUG_LEVEL_INFO)
48485 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48486- __FILE__,__LINE__, tty->driver->name, port->count );
48487+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48488
48489 spin_lock_irqsave(&info->lock, flags);
48490 if (!tty_hung_up_p(filp)) {
48491 extra_count = true;
48492- port->count--;
48493+ atomic_dec(&port->count);
48494 }
48495 spin_unlock_irqrestore(&info->lock, flags);
48496 port->blocked_open++;
48497@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48498
48499 if (debug_level >= DEBUG_LEVEL_INFO)
48500 printk("%s(%d):%s block_til_ready() count=%d\n",
48501- __FILE__,__LINE__, tty->driver->name, port->count );
48502+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48503
48504 tty_unlock(tty);
48505 schedule();
48506@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48507 remove_wait_queue(&port->open_wait, &wait);
48508
48509 if (extra_count)
48510- port->count++;
48511+ atomic_inc(&port->count);
48512 port->blocked_open--;
48513
48514 if (debug_level >= DEBUG_LEVEL_INFO)
48515 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48516- __FILE__,__LINE__, tty->driver->name, port->count );
48517+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48518
48519 if (!retval)
48520 port->flags |= ASYNC_NORMAL_ACTIVE;
48521diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48522index d5cc3ac..3263411 100644
48523--- a/drivers/tty/sysrq.c
48524+++ b/drivers/tty/sysrq.c
48525@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48526 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48527 size_t count, loff_t *ppos)
48528 {
48529- if (count) {
48530+ if (count && capable(CAP_SYS_ADMIN)) {
48531 char c;
48532
48533 if (get_user(c, buf))
48534diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48535index 20689b9..7fd3a31 100644
48536--- a/drivers/tty/tty_io.c
48537+++ b/drivers/tty/tty_io.c
48538@@ -3468,7 +3468,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48539
48540 void tty_default_fops(struct file_operations *fops)
48541 {
48542- *fops = tty_fops;
48543+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48544 }
48545
48546 /*
48547diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48548index 1afe192..73d2c20 100644
48549--- a/drivers/tty/tty_ldisc.c
48550+++ b/drivers/tty/tty_ldisc.c
48551@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48552 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48553 tty_ldiscs[disc] = new_ldisc;
48554 new_ldisc->num = disc;
48555- new_ldisc->refcount = 0;
48556+ atomic_set(&new_ldisc->refcount, 0);
48557 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48558
48559 return ret;
48560@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48561 return -EINVAL;
48562
48563 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48564- if (tty_ldiscs[disc]->refcount)
48565+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48566 ret = -EBUSY;
48567 else
48568 tty_ldiscs[disc] = NULL;
48569@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48570 if (ldops) {
48571 ret = ERR_PTR(-EAGAIN);
48572 if (try_module_get(ldops->owner)) {
48573- ldops->refcount++;
48574+ atomic_inc(&ldops->refcount);
48575 ret = ldops;
48576 }
48577 }
48578@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48579 unsigned long flags;
48580
48581 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48582- ldops->refcount--;
48583+ atomic_dec(&ldops->refcount);
48584 module_put(ldops->owner);
48585 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48586 }
48587@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48588 /* unreleased reader reference(s) will cause this WARN */
48589 WARN_ON(!atomic_dec_and_test(&ld->users));
48590
48591- ld->ops->refcount--;
48592+ atomic_dec(&ld->ops->refcount);
48593 module_put(ld->ops->owner);
48594 kfree(ld);
48595 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48596diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48597index f597e88..b7f68ed 100644
48598--- a/drivers/tty/tty_port.c
48599+++ b/drivers/tty/tty_port.c
48600@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48601 unsigned long flags;
48602
48603 spin_lock_irqsave(&port->lock, flags);
48604- port->count = 0;
48605+ atomic_set(&port->count, 0);
48606 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48607 tty = port->tty;
48608 if (tty)
48609@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48610 /* The port lock protects the port counts */
48611 spin_lock_irqsave(&port->lock, flags);
48612 if (!tty_hung_up_p(filp))
48613- port->count--;
48614+ atomic_dec(&port->count);
48615 port->blocked_open++;
48616 spin_unlock_irqrestore(&port->lock, flags);
48617
48618@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48619 we must not mess that up further */
48620 spin_lock_irqsave(&port->lock, flags);
48621 if (!tty_hung_up_p(filp))
48622- port->count++;
48623+ atomic_inc(&port->count);
48624 port->blocked_open--;
48625 if (retval == 0)
48626 port->flags |= ASYNC_NORMAL_ACTIVE;
48627@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48628 return 0;
48629 }
48630
48631- if (tty->count == 1 && port->count != 1) {
48632+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48633 printk(KERN_WARNING
48634 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48635- port->count);
48636- port->count = 1;
48637+ atomic_read(&port->count));
48638+ atomic_set(&port->count, 1);
48639 }
48640- if (--port->count < 0) {
48641+ if (atomic_dec_return(&port->count) < 0) {
48642 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48643- port->count);
48644- port->count = 0;
48645+ atomic_read(&port->count));
48646+ atomic_set(&port->count, 0);
48647 }
48648
48649- if (port->count) {
48650+ if (atomic_read(&port->count)) {
48651 spin_unlock_irqrestore(&port->lock, flags);
48652 if (port->ops->drop)
48653 port->ops->drop(port);
48654@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48655 {
48656 spin_lock_irq(&port->lock);
48657 if (!tty_hung_up_p(filp))
48658- ++port->count;
48659+ atomic_inc(&port->count);
48660 spin_unlock_irq(&port->lock);
48661 tty_port_tty_set(port, tty);
48662
48663diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48664index a9af1b9a..1e08e7f 100644
48665--- a/drivers/tty/vt/keyboard.c
48666+++ b/drivers/tty/vt/keyboard.c
48667@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48668 kbd->kbdmode == VC_OFF) &&
48669 value != KVAL(K_SAK))
48670 return; /* SAK is allowed even in raw mode */
48671+
48672+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48673+ {
48674+ void *func = fn_handler[value];
48675+ if (func == fn_show_state || func == fn_show_ptregs ||
48676+ func == fn_show_mem)
48677+ return;
48678+ }
48679+#endif
48680+
48681 fn_handler[value](vc);
48682 }
48683
48684@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48685 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48686 return -EFAULT;
48687
48688- if (!capable(CAP_SYS_TTY_CONFIG))
48689- perm = 0;
48690-
48691 switch (cmd) {
48692 case KDGKBENT:
48693 /* Ensure another thread doesn't free it under us */
48694@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48695 spin_unlock_irqrestore(&kbd_event_lock, flags);
48696 return put_user(val, &user_kbe->kb_value);
48697 case KDSKBENT:
48698+ if (!capable(CAP_SYS_TTY_CONFIG))
48699+ perm = 0;
48700+
48701 if (!perm)
48702 return -EPERM;
48703 if (!i && v == K_NOSUCHMAP) {
48704@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48705 int i, j, k;
48706 int ret;
48707
48708- if (!capable(CAP_SYS_TTY_CONFIG))
48709- perm = 0;
48710-
48711 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48712 if (!kbs) {
48713 ret = -ENOMEM;
48714@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48715 kfree(kbs);
48716 return ((p && *p) ? -EOVERFLOW : 0);
48717 case KDSKBSENT:
48718+ if (!capable(CAP_SYS_TTY_CONFIG))
48719+ perm = 0;
48720+
48721 if (!perm) {
48722 ret = -EPERM;
48723 goto reterr;
48724diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48725index 3b96f18..026a9bf 100644
48726--- a/drivers/uio/uio.c
48727+++ b/drivers/uio/uio.c
48728@@ -25,6 +25,7 @@
48729 #include <linux/kobject.h>
48730 #include <linux/cdev.h>
48731 #include <linux/uio_driver.h>
48732+#include <asm/local.h>
48733
48734 #define UIO_MAX_DEVICES (1U << MINORBITS)
48735
48736@@ -32,10 +33,10 @@ struct uio_device {
48737 struct module *owner;
48738 struct device *dev;
48739 int minor;
48740- atomic_t event;
48741+ atomic_unchecked_t event;
48742 struct fasync_struct *async_queue;
48743 wait_queue_head_t wait;
48744- int vma_count;
48745+ local_t vma_count;
48746 struct uio_info *info;
48747 struct kobject *map_dir;
48748 struct kobject *portio_dir;
48749@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48750 struct device_attribute *attr, char *buf)
48751 {
48752 struct uio_device *idev = dev_get_drvdata(dev);
48753- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48754+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48755 }
48756
48757 static struct device_attribute uio_class_attributes[] = {
48758@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48759 {
48760 struct uio_device *idev = info->uio_dev;
48761
48762- atomic_inc(&idev->event);
48763+ atomic_inc_unchecked(&idev->event);
48764 wake_up_interruptible(&idev->wait);
48765 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48766 }
48767@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48768 }
48769
48770 listener->dev = idev;
48771- listener->event_count = atomic_read(&idev->event);
48772+ listener->event_count = atomic_read_unchecked(&idev->event);
48773 filep->private_data = listener;
48774
48775 if (idev->info->open) {
48776@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48777 return -EIO;
48778
48779 poll_wait(filep, &idev->wait, wait);
48780- if (listener->event_count != atomic_read(&idev->event))
48781+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48782 return POLLIN | POLLRDNORM;
48783 return 0;
48784 }
48785@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48786 do {
48787 set_current_state(TASK_INTERRUPTIBLE);
48788
48789- event_count = atomic_read(&idev->event);
48790+ event_count = atomic_read_unchecked(&idev->event);
48791 if (event_count != listener->event_count) {
48792 if (copy_to_user(buf, &event_count, count))
48793 retval = -EFAULT;
48794@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48795 static void uio_vma_open(struct vm_area_struct *vma)
48796 {
48797 struct uio_device *idev = vma->vm_private_data;
48798- idev->vma_count++;
48799+ local_inc(&idev->vma_count);
48800 }
48801
48802 static void uio_vma_close(struct vm_area_struct *vma)
48803 {
48804 struct uio_device *idev = vma->vm_private_data;
48805- idev->vma_count--;
48806+ local_dec(&idev->vma_count);
48807 }
48808
48809 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48810@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
48811 idev->owner = owner;
48812 idev->info = info;
48813 init_waitqueue_head(&idev->wait);
48814- atomic_set(&idev->event, 0);
48815+ atomic_set_unchecked(&idev->event, 0);
48816
48817 ret = uio_get_minor(idev);
48818 if (ret)
48819diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48820index 8a7eb77..c00402f 100644
48821--- a/drivers/usb/atm/cxacru.c
48822+++ b/drivers/usb/atm/cxacru.c
48823@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48824 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48825 if (ret < 2)
48826 return -EINVAL;
48827- if (index < 0 || index > 0x7f)
48828+ if (index > 0x7f)
48829 return -EINVAL;
48830 pos += tmp;
48831
48832diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48833index 5e0d33a..cc10579 100644
48834--- a/drivers/usb/atm/usbatm.c
48835+++ b/drivers/usb/atm/usbatm.c
48836@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48837 if (printk_ratelimit())
48838 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48839 __func__, vpi, vci);
48840- atomic_inc(&vcc->stats->rx_err);
48841+ atomic_inc_unchecked(&vcc->stats->rx_err);
48842 return;
48843 }
48844
48845@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48846 if (length > ATM_MAX_AAL5_PDU) {
48847 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48848 __func__, length, vcc);
48849- atomic_inc(&vcc->stats->rx_err);
48850+ atomic_inc_unchecked(&vcc->stats->rx_err);
48851 goto out;
48852 }
48853
48854@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48855 if (sarb->len < pdu_length) {
48856 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48857 __func__, pdu_length, sarb->len, vcc);
48858- atomic_inc(&vcc->stats->rx_err);
48859+ atomic_inc_unchecked(&vcc->stats->rx_err);
48860 goto out;
48861 }
48862
48863 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48864 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48865 __func__, vcc);
48866- atomic_inc(&vcc->stats->rx_err);
48867+ atomic_inc_unchecked(&vcc->stats->rx_err);
48868 goto out;
48869 }
48870
48871@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48872 if (printk_ratelimit())
48873 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48874 __func__, length);
48875- atomic_inc(&vcc->stats->rx_drop);
48876+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48877 goto out;
48878 }
48879
48880@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48881
48882 vcc->push(vcc, skb);
48883
48884- atomic_inc(&vcc->stats->rx);
48885+ atomic_inc_unchecked(&vcc->stats->rx);
48886 out:
48887 skb_trim(sarb, 0);
48888 }
48889@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
48890 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48891
48892 usbatm_pop(vcc, skb);
48893- atomic_inc(&vcc->stats->tx);
48894+ atomic_inc_unchecked(&vcc->stats->tx);
48895
48896 skb = skb_dequeue(&instance->sndqueue);
48897 }
48898@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48899 if (!left--)
48900 return sprintf(page,
48901 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48902- atomic_read(&atm_dev->stats.aal5.tx),
48903- atomic_read(&atm_dev->stats.aal5.tx_err),
48904- atomic_read(&atm_dev->stats.aal5.rx),
48905- atomic_read(&atm_dev->stats.aal5.rx_err),
48906- atomic_read(&atm_dev->stats.aal5.rx_drop));
48907+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48908+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48909+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48910+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48911+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48912
48913 if (!left--) {
48914 if (instance->disconnected)
48915diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48916index 2a3bbdf..91d72cf 100644
48917--- a/drivers/usb/core/devices.c
48918+++ b/drivers/usb/core/devices.c
48919@@ -126,7 +126,7 @@ static const char format_endpt[] =
48920 * time it gets called.
48921 */
48922 static struct device_connect_event {
48923- atomic_t count;
48924+ atomic_unchecked_t count;
48925 wait_queue_head_t wait;
48926 } device_event = {
48927 .count = ATOMIC_INIT(1),
48928@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48929
48930 void usbfs_conn_disc_event(void)
48931 {
48932- atomic_add(2, &device_event.count);
48933+ atomic_add_unchecked(2, &device_event.count);
48934 wake_up(&device_event.wait);
48935 }
48936
48937@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48938
48939 poll_wait(file, &device_event.wait, wait);
48940
48941- event_count = atomic_read(&device_event.count);
48942+ event_count = atomic_read_unchecked(&device_event.count);
48943 if (file->f_version != event_count) {
48944 file->f_version = event_count;
48945 return POLLIN | POLLRDNORM;
48946diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48947index 014dc99..4d25fd7 100644
48948--- a/drivers/usb/core/hcd.c
48949+++ b/drivers/usb/core/hcd.c
48950@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48951 */
48952 usb_get_urb(urb);
48953 atomic_inc(&urb->use_count);
48954- atomic_inc(&urb->dev->urbnum);
48955+ atomic_inc_unchecked(&urb->dev->urbnum);
48956 usbmon_urb_submit(&hcd->self, urb);
48957
48958 /* NOTE requirements on root-hub callers (usbfs and the hub
48959@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48960 urb->hcpriv = NULL;
48961 INIT_LIST_HEAD(&urb->urb_list);
48962 atomic_dec(&urb->use_count);
48963- atomic_dec(&urb->dev->urbnum);
48964+ atomic_dec_unchecked(&urb->dev->urbnum);
48965 if (atomic_read(&urb->reject))
48966 wake_up(&usb_kill_urb_queue);
48967 usb_put_urb(urb);
48968diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48969index 17c3785..deffb11 100644
48970--- a/drivers/usb/core/hub.c
48971+++ b/drivers/usb/core/hub.c
48972@@ -27,6 +27,7 @@
48973 #include <linux/freezer.h>
48974 #include <linux/random.h>
48975 #include <linux/pm_qos.h>
48976+#include <linux/grsecurity.h>
48977
48978 #include <asm/uaccess.h>
48979 #include <asm/byteorder.h>
48980@@ -4421,6 +4422,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48981 goto done;
48982 return;
48983 }
48984+
48985+ if (gr_handle_new_usb())
48986+ goto done;
48987+
48988 if (hub_is_superspeed(hub->hdev))
48989 unit_load = 150;
48990 else
48991diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48992index e7ee1e4..1dfc9ea4 100644
48993--- a/drivers/usb/core/message.c
48994+++ b/drivers/usb/core/message.c
48995@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48996 * method can wait for it to complete. Since you don't have a handle on the
48997 * URB used, you can't cancel the request.
48998 */
48999-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49000+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49001 __u8 requesttype, __u16 value, __u16 index, void *data,
49002 __u16 size, int timeout)
49003 {
49004diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49005index d9284b9..17023c7 100644
49006--- a/drivers/usb/core/sysfs.c
49007+++ b/drivers/usb/core/sysfs.c
49008@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49009 struct usb_device *udev;
49010
49011 udev = to_usb_device(dev);
49012- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49013+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49014 }
49015 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49016
49017diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49018index 7dad603..350f7a9 100644
49019--- a/drivers/usb/core/usb.c
49020+++ b/drivers/usb/core/usb.c
49021@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49022 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49023 dev->state = USB_STATE_ATTACHED;
49024 dev->lpm_disable_count = 1;
49025- atomic_set(&dev->urbnum, 0);
49026+ atomic_set_unchecked(&dev->urbnum, 0);
49027
49028 INIT_LIST_HEAD(&dev->ep0.urb_list);
49029 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49030diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49031index 14d28d6..5f511ac 100644
49032--- a/drivers/usb/dwc3/gadget.c
49033+++ b/drivers/usb/dwc3/gadget.c
49034@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49035 if (!usb_endpoint_xfer_isoc(desc))
49036 return 0;
49037
49038- memset(&trb_link, 0, sizeof(trb_link));
49039-
49040 /* Link TRB for ISOC. The HWO bit is never reset */
49041 trb_st_hw = &dep->trb_pool[0];
49042
49043diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49044index 5e29dde..eca992f 100644
49045--- a/drivers/usb/early/ehci-dbgp.c
49046+++ b/drivers/usb/early/ehci-dbgp.c
49047@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49048
49049 #ifdef CONFIG_KGDB
49050 static struct kgdb_io kgdbdbgp_io_ops;
49051-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49052+static struct kgdb_io kgdbdbgp_io_ops_console;
49053+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49054 #else
49055 #define dbgp_kgdb_mode (0)
49056 #endif
49057@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49058 .write_char = kgdbdbgp_write_char,
49059 };
49060
49061+static struct kgdb_io kgdbdbgp_io_ops_console = {
49062+ .name = "kgdbdbgp",
49063+ .read_char = kgdbdbgp_read_char,
49064+ .write_char = kgdbdbgp_write_char,
49065+ .is_console = 1
49066+};
49067+
49068 static int kgdbdbgp_wait_time;
49069
49070 static int __init kgdbdbgp_parse_config(char *str)
49071@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49072 ptr++;
49073 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49074 }
49075- kgdb_register_io_module(&kgdbdbgp_io_ops);
49076- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49077+ if (early_dbgp_console.index != -1)
49078+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49079+ else
49080+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49081
49082 return 0;
49083 }
49084diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49085index b369292..9f3ba40 100644
49086--- a/drivers/usb/gadget/u_serial.c
49087+++ b/drivers/usb/gadget/u_serial.c
49088@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49089 spin_lock_irq(&port->port_lock);
49090
49091 /* already open? Great. */
49092- if (port->port.count) {
49093+ if (atomic_read(&port->port.count)) {
49094 status = 0;
49095- port->port.count++;
49096+ atomic_inc(&port->port.count);
49097
49098 /* currently opening/closing? wait ... */
49099 } else if (port->openclose) {
49100@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49101 tty->driver_data = port;
49102 port->port.tty = tty;
49103
49104- port->port.count = 1;
49105+ atomic_set(&port->port.count, 1);
49106 port->openclose = false;
49107
49108 /* if connected, start the I/O stream */
49109@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49110
49111 spin_lock_irq(&port->port_lock);
49112
49113- if (port->port.count != 1) {
49114- if (port->port.count == 0)
49115+ if (atomic_read(&port->port.count) != 1) {
49116+ if (atomic_read(&port->port.count) == 0)
49117 WARN_ON(1);
49118 else
49119- --port->port.count;
49120+ atomic_dec(&port->port.count);
49121 goto exit;
49122 }
49123
49124@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49125 * and sleep if necessary
49126 */
49127 port->openclose = true;
49128- port->port.count = 0;
49129+ atomic_set(&port->port.count, 0);
49130
49131 gser = port->port_usb;
49132 if (gser && gser->disconnect)
49133@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49134 int cond;
49135
49136 spin_lock_irq(&port->port_lock);
49137- cond = (port->port.count == 0) && !port->openclose;
49138+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49139 spin_unlock_irq(&port->port_lock);
49140 return cond;
49141 }
49142@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49143 /* if it's already open, start I/O ... and notify the serial
49144 * protocol about open/close status (connect/disconnect).
49145 */
49146- if (port->port.count) {
49147+ if (atomic_read(&port->port.count)) {
49148 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49149 gs_start_io(port);
49150 if (gser->connect)
49151@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49152
49153 port->port_usb = NULL;
49154 gser->ioport = NULL;
49155- if (port->port.count > 0 || port->openclose) {
49156+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49157 wake_up_interruptible(&port->drain_wait);
49158 if (port->port.tty)
49159 tty_hangup(port->port.tty);
49160@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49161
49162 /* finally, free any unused/unusable I/O buffers */
49163 spin_lock_irqsave(&port->port_lock, flags);
49164- if (port->port.count == 0 && !port->openclose)
49165+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49166 gs_buf_free(&port->port_write_buf);
49167 gs_free_requests(gser->out, &port->read_pool, NULL);
49168 gs_free_requests(gser->out, &port->read_queue, NULL);
49169diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49170index ba6a5d6..f88f7f3 100644
49171--- a/drivers/usb/misc/appledisplay.c
49172+++ b/drivers/usb/misc/appledisplay.c
49173@@ -83,7 +83,7 @@ struct appledisplay {
49174 spinlock_t lock;
49175 };
49176
49177-static atomic_t count_displays = ATOMIC_INIT(0);
49178+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49179 static struct workqueue_struct *wq;
49180
49181 static void appledisplay_complete(struct urb *urb)
49182@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49183
49184 /* Register backlight device */
49185 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49186- atomic_inc_return(&count_displays) - 1);
49187+ atomic_inc_return_unchecked(&count_displays) - 1);
49188 memset(&props, 0, sizeof(struct backlight_properties));
49189 props.type = BACKLIGHT_RAW;
49190 props.max_brightness = 0xff;
49191diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49192index afb50ea..7b0b1cf 100644
49193--- a/drivers/usb/serial/console.c
49194+++ b/drivers/usb/serial/console.c
49195@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49196
49197 info->port = port;
49198
49199- ++port->port.count;
49200+ atomic_inc(&port->port.count);
49201 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49202 if (serial->type->set_termios) {
49203 /*
49204@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49205 }
49206 /* Now that any required fake tty operations are completed restore
49207 * the tty port count */
49208- --port->port.count;
49209+ atomic_dec(&port->port.count);
49210 /* The console is special in terms of closing the device so
49211 * indicate this port is now acting as a system console. */
49212 port->port.console = 1;
49213@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49214 free_tty:
49215 kfree(tty);
49216 reset_open_count:
49217- port->port.count = 0;
49218+ atomic_set(&port->port.count, 0);
49219 usb_autopm_put_interface(serial->interface);
49220 error_get_interface:
49221 usb_serial_put(serial);
49222diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49223index 75f70f0..d467e1a 100644
49224--- a/drivers/usb/storage/usb.h
49225+++ b/drivers/usb/storage/usb.h
49226@@ -63,7 +63,7 @@ struct us_unusual_dev {
49227 __u8 useProtocol;
49228 __u8 useTransport;
49229 int (*initFunction)(struct us_data *);
49230-};
49231+} __do_const;
49232
49233
49234 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49235diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49236index d6bea3e..60b250e 100644
49237--- a/drivers/usb/wusbcore/wa-hc.h
49238+++ b/drivers/usb/wusbcore/wa-hc.h
49239@@ -192,7 +192,7 @@ struct wahc {
49240 struct list_head xfer_delayed_list;
49241 spinlock_t xfer_list_lock;
49242 struct work_struct xfer_work;
49243- atomic_t xfer_id_count;
49244+ atomic_unchecked_t xfer_id_count;
49245 };
49246
49247
49248@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49249 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49250 spin_lock_init(&wa->xfer_list_lock);
49251 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49252- atomic_set(&wa->xfer_id_count, 1);
49253+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49254 }
49255
49256 /**
49257diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49258index d3493ca..0c33b7e 100644
49259--- a/drivers/usb/wusbcore/wa-xfer.c
49260+++ b/drivers/usb/wusbcore/wa-xfer.c
49261@@ -297,7 +297,7 @@ out:
49262 */
49263 static void wa_xfer_id_init(struct wa_xfer *xfer)
49264 {
49265- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49266+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49267 }
49268
49269 /*
49270diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49271index 842f450..d1d7409 100644
49272--- a/drivers/vfio/vfio.c
49273+++ b/drivers/vfio/vfio.c
49274@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49275 return 0;
49276
49277 /* TODO Prevent device auto probing */
49278- WARN("Device %s added to live group %d!\n", dev_name(dev),
49279+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49280 iommu_group_id(group->iommu_group));
49281
49282 return 0;
49283diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49284index 5174eba..86e764a 100644
49285--- a/drivers/vhost/vringh.c
49286+++ b/drivers/vhost/vringh.c
49287@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49288
49289 static inline int putu16_kern(u16 *p, u16 val)
49290 {
49291- ACCESS_ONCE(*p) = val;
49292+ ACCESS_ONCE_RW(*p) = val;
49293 return 0;
49294 }
49295
49296diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49297index a4dfe8c..297ddd9 100644
49298--- a/drivers/video/aty/aty128fb.c
49299+++ b/drivers/video/aty/aty128fb.c
49300@@ -149,7 +149,7 @@ enum {
49301 };
49302
49303 /* Must match above enum */
49304-static char * const r128_family[] = {
49305+static const char * const r128_family[] = {
49306 "AGP",
49307 "PCI",
49308 "PRO AGP",
49309diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49310index 9b0f12c..024673d 100644
49311--- a/drivers/video/aty/atyfb_base.c
49312+++ b/drivers/video/aty/atyfb_base.c
49313@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49314 par->accel_flags = var->accel_flags; /* hack */
49315
49316 if (var->accel_flags) {
49317- info->fbops->fb_sync = atyfb_sync;
49318+ pax_open_kernel();
49319+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49320+ pax_close_kernel();
49321 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49322 } else {
49323- info->fbops->fb_sync = NULL;
49324+ pax_open_kernel();
49325+ *(void **)&info->fbops->fb_sync = NULL;
49326+ pax_close_kernel();
49327 info->flags |= FBINFO_HWACCEL_DISABLED;
49328 }
49329
49330diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49331index 95ec042..e6affdd 100644
49332--- a/drivers/video/aty/mach64_cursor.c
49333+++ b/drivers/video/aty/mach64_cursor.c
49334@@ -7,6 +7,7 @@
49335 #include <linux/string.h>
49336
49337 #include <asm/io.h>
49338+#include <asm/pgtable.h>
49339
49340 #ifdef __sparc__
49341 #include <asm/fbio.h>
49342@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49343 info->sprite.buf_align = 16; /* and 64 lines tall. */
49344 info->sprite.flags = FB_PIXMAP_IO;
49345
49346- info->fbops->fb_cursor = atyfb_cursor;
49347+ pax_open_kernel();
49348+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49349+ pax_close_kernel();
49350
49351 return 0;
49352 }
49353diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49354index bca6ccc..252107e 100644
49355--- a/drivers/video/backlight/kb3886_bl.c
49356+++ b/drivers/video/backlight/kb3886_bl.c
49357@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49358 static unsigned long kb3886bl_flags;
49359 #define KB3886BL_SUSPENDED 0x01
49360
49361-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49362+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49363 {
49364 .ident = "Sahara Touch-iT",
49365 .matches = {
49366diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49367index 900aa4e..6d49418 100644
49368--- a/drivers/video/fb_defio.c
49369+++ b/drivers/video/fb_defio.c
49370@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49371
49372 BUG_ON(!fbdefio);
49373 mutex_init(&fbdefio->lock);
49374- info->fbops->fb_mmap = fb_deferred_io_mmap;
49375+ pax_open_kernel();
49376+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49377+ pax_close_kernel();
49378 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49379 INIT_LIST_HEAD(&fbdefio->pagelist);
49380 if (fbdefio->delay == 0) /* set a default of 1 s */
49381@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49382 page->mapping = NULL;
49383 }
49384
49385- info->fbops->fb_mmap = NULL;
49386+ *(void **)&info->fbops->fb_mmap = NULL;
49387 mutex_destroy(&fbdefio->lock);
49388 }
49389 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49390diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49391index 5c3960d..15cf8fc 100644
49392--- a/drivers/video/fbcmap.c
49393+++ b/drivers/video/fbcmap.c
49394@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49395 rc = -ENODEV;
49396 goto out;
49397 }
49398- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49399- !info->fbops->fb_setcmap)) {
49400+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49401 rc = -EINVAL;
49402 goto out1;
49403 }
49404diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49405index 36e1fe2..c744820 100644
49406--- a/drivers/video/fbmem.c
49407+++ b/drivers/video/fbmem.c
49408@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49409 image->dx += image->width + 8;
49410 }
49411 } else if (rotate == FB_ROTATE_UD) {
49412- for (x = 0; x < num && image->dx >= 0; x++) {
49413+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49414 info->fbops->fb_imageblit(info, image);
49415 image->dx -= image->width + 8;
49416 }
49417@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49418 image->dy += image->height + 8;
49419 }
49420 } else if (rotate == FB_ROTATE_CCW) {
49421- for (x = 0; x < num && image->dy >= 0; x++) {
49422+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49423 info->fbops->fb_imageblit(info, image);
49424 image->dy -= image->height + 8;
49425 }
49426@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49427 return -EFAULT;
49428 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49429 return -EINVAL;
49430- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49431+ if (con2fb.framebuffer >= FB_MAX)
49432 return -EINVAL;
49433 if (!registered_fb[con2fb.framebuffer])
49434 request_module("fb%d", con2fb.framebuffer);
49435diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49436index d4d2c5f..ebbd113 100644
49437--- a/drivers/video/hyperv_fb.c
49438+++ b/drivers/video/hyperv_fb.c
49439@@ -233,7 +233,7 @@ static uint screen_fb_size;
49440 static inline int synthvid_send(struct hv_device *hdev,
49441 struct synthvid_msg *msg)
49442 {
49443- static atomic64_t request_id = ATOMIC64_INIT(0);
49444+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49445 int ret;
49446
49447 msg->pipe_hdr.type = PIPE_MSG_DATA;
49448@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49449
49450 ret = vmbus_sendpacket(hdev->channel, msg,
49451 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49452- atomic64_inc_return(&request_id),
49453+ atomic64_inc_return_unchecked(&request_id),
49454 VM_PKT_DATA_INBAND, 0);
49455
49456 if (ret)
49457diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49458index 7672d2e..b56437f 100644
49459--- a/drivers/video/i810/i810_accel.c
49460+++ b/drivers/video/i810/i810_accel.c
49461@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49462 }
49463 }
49464 printk("ringbuffer lockup!!!\n");
49465+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49466 i810_report_error(mmio);
49467 par->dev_flags |= LOCKUP;
49468 info->pixmap.scan_align = 1;
49469diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49470index 285d552..eafa544 100644
49471--- a/drivers/video/logo/logo_linux_clut224.ppm
49472+++ b/drivers/video/logo/logo_linux_clut224.ppm
49473@@ -1,883 +1,1123 @@
49474 P3
49475 80 80
49476 255
49477-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49478-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49479-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49480-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49481-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49482-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49483-0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
49489-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49490-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49491-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49492-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49493-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49494-0 0 0 0 0 0 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 0 0 0 1 1 1 1 1 1 0 0 0
49500-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49501-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49502-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49503-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49504-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49505-6 6 6 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49511-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49512-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49513-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49514-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49515-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49516-14 14 14 6 6 6 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49522-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49523-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49524-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49525-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49526-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49527-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 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-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49533-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49534-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49535-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49536-78 78 78 34 34 34 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 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49538-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 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-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49544-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49545-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49546-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49547-26 26 26 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 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49549-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 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-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49555-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49556-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49557-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
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 86 86 86 101 101 101 46 46 46 10 10 10
49560-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 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-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49566-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49567-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49568-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
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 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49571-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 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-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49577-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49578-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49579-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 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 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49582-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 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-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49588-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49589-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49590-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49591-2 2 6 2 2 6 2 2 6 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 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49593-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 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-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49599-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49600-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49601-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49602-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49603-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49604-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 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-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49610-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49611-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49612-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49613-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49614-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49615-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 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 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49621-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49622-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49623-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49624-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49625-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49626-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
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-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49632-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49633-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49634-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49635-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49636-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49637-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
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-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49643-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49644-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49645-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49646-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49647-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49648-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 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-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49654-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49655-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49656-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49657-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49658-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49659-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 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-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49665-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49666-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49667-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49668-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49669-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49670-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 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-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49676-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49677-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49678-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49679-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49680-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49681-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 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-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49687-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49688-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49689-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49690-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49691-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49692-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 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-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49698-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49699-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49700-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49701-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49702-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49703-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
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-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49709-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49710-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49711-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49712-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49713-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49714-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
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-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49720-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49721-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49722-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49723-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49724-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49725-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49726-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49727-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49728-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49729-
49730-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49731-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49732-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49733-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49734-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49735-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49736-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49737-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49738-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49739-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49740-
49741-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49742-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49743-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49744-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49745-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49746-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49747-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49748-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49749-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49750-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49751-
49752-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49753-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49754-3 5 6 1 1 1 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 30 30 30 78 78 78 46 46 46 22 22 22
49756-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49757-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49758-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49759-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49760-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49761-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49762-
49763-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49764-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 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 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49767-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49768-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49769-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49770-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49771-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49772-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49773-
49774-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49775-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 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 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49778-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49779-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49780-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49781-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49782-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49783-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49784-
49785-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49786-0 0 0 7 12 13 27 40 45 18 25 28 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 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49789-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49790-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49791-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49792-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49793-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49794-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49795-
49796-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49797-0 0 0 21 30 33 27 40 45 2 3 3 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-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49800-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49801-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49802-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49803-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49804-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49805-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49806-
49807-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49808-18 25 28 35 52 58 17 23 26 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 0 0 0
49810-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49811-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49812-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49813-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
49814-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49815-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49816-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49817-
49818-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
49819-52 72 81 36 54 60 6 8 8 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 0 0 0
49821-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
49822-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
49823-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49824-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49825-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49826-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49827-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49828-
49829-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
49830-36 54 60 29 43 47 0 0 0 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 0 0 0 6 6 6
49832-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
49833-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
49834-246 246 246 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 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49836-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
49837-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49838-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49839-
49840-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-21 30 33 35 52 58 6 8 12 0 0 0 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 0 0 0 0 0 0 14 14 14
49843-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
49844-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 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-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49847-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
49848-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49849-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49850-
49851-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-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49853-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49854-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
49855-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
49856-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49857-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49858-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
49859-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49860-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49861-
49862-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 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
49864-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49865-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
49866-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49867-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49868-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49869-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
49870-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49871-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49872-
49873-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 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
49875-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
49876-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
49877-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
49878-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
49879-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49880-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
49881-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49882-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49883-
49884-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 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
49886-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
49887-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
49888-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
49889-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
49890-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
49891-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
49892-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49893-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49894-
49895-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 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
49897-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
49898-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
49899-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
49900-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
49901-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
49902-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
49903-18 18 18 6 6 6 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 21 30 33 35 52 58 6 8 12 0 0 0
49908-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
49909-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
49910-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 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 246 246 246
49912-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
49913-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
49914-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49915-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49916-
49917-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 6 8 8 33 49 54 29 43 47 6 8 12
49919-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
49920-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 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 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
49924-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
49925-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49926-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49927-
49928-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 12 17 20 33 49 54 17 23 26
49930-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
49931-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
49932-253 253 253 253 253 253 253 253 253 253 253 253 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 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
49935-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
49936-58 58 58 22 22 22 6 6 6 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 15 22 25 36 54 60
49941-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
49942-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49943-253 253 253 253 253 253 253 253 253 253 253 253 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 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
49946-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
49947-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49948-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49949-
49950-0 0 0 0 0 0 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 21 30 33
49952-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
49953-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49954-253 253 253 253 253 253 253 253 253 250 250 250 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 246 246 246 46 46 46 38 38 38
49957-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
49958-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49959-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49960-
49961-0 0 0 0 0 0 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-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
49964-2 2 6 116 116 116 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 250 250 250 238 238 238 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 94 94 94 6 6 6
49968-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
49969-74 74 74 58 58 58 22 22 22 6 6 6 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-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
49975-14 14 14 210 210 210 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 246 246 246 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 151 151 151 2 2 6
49979-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49980-42 42 42 74 74 74 30 30 30 10 10 10 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 0 0 0
49985-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
49986-74 74 74 250 250 250 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 242 242 242 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 180 180 180 2 2 6
49990-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49991-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49992-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49993-
49994-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49995-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49996-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
49997-151 151 151 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 234 234 234 242 242 242 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 202 202 202 2 2 6
50001-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50002-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
50003-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50004-
50005-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 6 6 6
50007-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50008-210 210 210 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 234 234 234 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 221 221 221 6 6 6
50012-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50013-2 2 6 82 82 82 54 54 54 18 18 18 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 0 0 0 10 10 10
50018-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50019-238 238 238 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 238 238 238 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 231 231 231 6 6 6
50023-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50024-2 2 6 66 66 66 58 58 58 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 0 0 0 10 10 10
50029-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50030-246 246 246 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 242 242 242 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 234 234 234 10 10 10
50034-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50035-2 2 6 66 66 66 62 62 62 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 18 18 18
50040-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
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 234 234 234 14 14 14
50045-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50046-2 2 6 66 66 66 62 62 62 22 22 22 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 18 18 18
50051-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50052-250 250 250 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 226 226 226 10 10 10
50056-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50057-2 2 6 66 66 66 58 58 58 22 22 22 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 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50062-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50063-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50064-253 253 253 253 253 253 231 231 231 246 246 246 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 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50067-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50068-2 2 6 82 82 82 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50073-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50074-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50075-253 253 253 253 253 253 231 231 231 246 246 246 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 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50078-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50079-6 6 6 94 94 94 50 50 50 18 18 18 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-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50084-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50085-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50086-253 253 253 253 253 253 231 231 231 250 250 250 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 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50089-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50090-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50091-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50092-
50093-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50094-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50095-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50096-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50097-253 253 253 253 253 253 231 231 231 250 250 250 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 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50100-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50101-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50102-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50103-
50104-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50105-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50106-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50107-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50108-253 253 253 253 253 253 234 234 234 242 242 242 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 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50111-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50112-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50113-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50114-
50115-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50116-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50117-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50118-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50119-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50120-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50121-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50122-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50123-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50124-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50125-
50126-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50127-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50128-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50129-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50130-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50131-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50132-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50133-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50134-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50135-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50136-
50137-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50138-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 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 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50141-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50142-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50143-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50144-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50145-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50146-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50147-
50148-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50149-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 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 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50152-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50153-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50154-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50155-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50156-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50157-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50158-
50159-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50160-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 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 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50163-78 78 78 250 250 250 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-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50166-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50167-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50168-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50169-
50170-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50171-30 30 30 74 74 74 174 140 55 216 158 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 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50174-22 22 22 238 238 238 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-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50177-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50178-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50179-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50180-
50181-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50182-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 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 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50185-46 46 46 246 246 246 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 253 253 253
50187-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50188-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50189-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50190-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50191-
50192-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50193-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 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 232 195 16 121 92 8 34 34 34 106 106 106
50196-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50197-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50198-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 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 190 14 246 190 14 242 186 14 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 0 0 0 10 10 10
50204-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 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 241 196 14 220 174 15 198 179 130 253 253 253
50207-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50208-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50209-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 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 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50212-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50213-
50214-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50215-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 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 190 14 232 195 16 190 146 13 214 214 214
50218-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50219-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50220-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 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 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50223-46 46 46 18 18 18 6 6 6 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 18 18 18
50226-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50227-246 190 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 242 186 14 230 187 11 204 160 10 133 118 54
50229-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50230-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50231-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50232-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50233-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50234-30 30 30 10 10 10 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 22 22 22
50237-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50238-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50239-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50240-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50241-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50242-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50243-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50244-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50245-18 18 18 6 6 6 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 6 6 6 22 22 22
50248-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50249-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50250-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50251-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50252-14 14 14 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 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50254-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50255-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50256-6 6 6 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 6 6 6 18 18 18
50259-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50260-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50261-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50262-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50263-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50264-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50265-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50266-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
50270-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50271-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50272-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50273-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50274-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50275-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50276-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50277-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 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 6 6 6
50281-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50282-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50283-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50284-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50285-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50286-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50287-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50288-50 50 50 30 30 30 14 14 14 6 6 6 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-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50293-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50294-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50295-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50296-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50297-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50298-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50299-22 22 22 10 10 10 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 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50304-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50305-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50306-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50307-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50308-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50309-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50310-6 6 6 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 6 6 6 6 6 6 10 10 10
50315-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50316-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50317-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50318-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50319-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50320-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
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 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50327-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50328-30 30 30 14 14 14 6 6 6 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-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50331-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50332-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50333-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50334-
50335-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50336-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50337-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50338-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50339-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50340-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50341-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50342-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50343-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50344-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50345-
50346-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50347-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50348-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50349-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50350-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50351-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50352-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50353-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50354-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50355-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50356-
50357+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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
50424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50426+4 4 4 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 4 4 4 4 4 4
50429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
50438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50440+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 4 4 4 4 4 4 4 4 4 4 4 4
50443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50445+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50446+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
50451+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50452+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50454+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 4 4 4 4 4 4 4 4 4 4 4 4
50457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50459+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50460+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50461+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
50465+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50466+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50467+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50468+4 4 4 4 4 4
50469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50473+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50474+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50475+0 0 0 3 3 3 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 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50479+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50480+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50481+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50482+4 4 4 4 4 4
50483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50486+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50487+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50488+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50489+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
50492+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50493+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50494+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50495+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50496+4 4 4 4 4 4
50497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50500+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50501+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50502+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50503+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50504+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50505+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50506+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50507+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50508+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50509+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50510+4 4 4 4 4 4
50511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50514+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50515+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50516+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50517+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50518+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50519+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50520+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50521+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50522+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50523+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50524+4 4 4 4 4 4
50525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50527+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50528+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50529+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50530+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50531+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50532+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50533+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50534+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50535+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50536+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50537+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50538+4 4 4 4 4 4
50539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50541+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50542+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50543+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50544+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50545+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50546+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50547+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50548+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50549+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50550+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50551+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50552+4 4 4 4 4 4
50553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50555+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50556+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50557+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50558+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50559+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50560+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50561+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50562+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50563+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50564+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50565+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50566+4 4 4 4 4 4
50567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50569+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50570+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50571+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50572+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50573+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50574+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50575+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50576+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50577+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50578+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50579+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50580+4 4 4 4 4 4
50581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50582+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50583+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50584+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50585+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50586+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50587+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50588+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50589+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50590+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50591+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50592+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50593+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50594+4 4 4 4 4 4
50595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50596+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50597+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50598+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50599+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50600+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50601+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50602+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50603+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50604+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50605+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50606+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50607+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50608+0 0 0 4 4 4
50609+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50610+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50611+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50612+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50613+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50614+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50615+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50616+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50617+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50618+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50619+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50620+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50621+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50622+2 0 0 0 0 0
50623+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50624+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50625+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50626+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50627+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50628+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50629+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50630+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50631+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50632+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50633+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50634+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50635+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50636+37 38 37 0 0 0
50637+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50638+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50639+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50640+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50641+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50642+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50643+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50644+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50645+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50646+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50647+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50648+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50649+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50650+85 115 134 4 0 0
50651+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50652+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50653+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50654+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50655+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50656+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50657+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50658+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50659+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50660+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50661+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50662+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50663+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50664+60 73 81 4 0 0
50665+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50666+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50667+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50668+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50669+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50670+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50671+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50672+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50673+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50674+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50675+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50676+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50677+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50678+16 19 21 4 0 0
50679+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50680+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50681+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50682+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50683+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50684+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50685+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50686+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50687+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50688+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50689+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50690+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50691+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50692+4 0 0 4 3 3
50693+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50694+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50695+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50697+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50698+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50699+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50700+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50701+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50702+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50703+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50704+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50705+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50706+3 2 2 4 4 4
50707+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50708+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50709+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50710+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50711+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50712+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50713+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50714+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50715+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50716+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50717+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50718+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50719+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50720+4 4 4 4 4 4
50721+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50722+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50723+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50724+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50725+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50726+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50727+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50728+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50729+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50730+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50731+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50732+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50733+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50734+4 4 4 4 4 4
50735+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50736+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50737+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50738+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50739+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50740+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50741+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50742+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50743+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50744+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50745+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50746+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50747+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50748+5 5 5 5 5 5
50749+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50750+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50751+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50752+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50753+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50754+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50755+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50756+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50757+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50758+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50759+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50760+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50761+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50762+5 5 5 4 4 4
50763+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50764+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50765+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50766+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50767+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50768+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50769+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50770+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50771+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50772+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50773+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50774+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50776+4 4 4 4 4 4
50777+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50778+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50779+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50780+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50781+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50782+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50783+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50784+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50785+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50786+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50787+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50788+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50790+4 4 4 4 4 4
50791+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50792+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50793+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50794+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50795+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50796+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50797+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50798+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50799+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50800+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50801+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
50802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50804+4 4 4 4 4 4
50805+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50806+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50807+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50808+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50809+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50810+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50811+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50812+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50813+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
50814+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
50815+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
50816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50818+4 4 4 4 4 4
50819+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
50820+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
50821+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
50822+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
50823+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50824+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
50825+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50826+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
50827+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
50828+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
50829+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50832+4 4 4 4 4 4
50833+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
50834+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
50835+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
50836+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
50837+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50838+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
50839+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
50840+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
50841+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
50842+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
50843+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
50844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50846+4 4 4 4 4 4
50847+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
50848+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
50849+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
50850+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
50851+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50852+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
50853+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
50854+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
50855+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
50856+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
50857+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
50858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50860+4 4 4 4 4 4
50861+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
50862+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
50863+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
50864+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50865+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
50866+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
50867+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
50868+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
50869+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
50870+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
50871+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50874+4 4 4 4 4 4
50875+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
50876+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
50877+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
50878+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50879+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50880+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
50881+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
50882+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
50883+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
50884+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
50885+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50888+4 4 4 4 4 4
50889+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
50890+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
50891+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50892+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50893+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50894+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
50895+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
50896+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
50897+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
50898+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
50899+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50902+4 4 4 4 4 4
50903+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
50904+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
50905+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50906+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50907+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50908+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
50909+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
50910+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
50911+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50912+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50913+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50916+4 4 4 4 4 4
50917+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50918+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
50919+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50920+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
50921+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
50922+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
50923+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
50924+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
50925+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50926+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50927+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50930+4 4 4 4 4 4
50931+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50932+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
50933+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50934+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
50935+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50936+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
50937+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
50938+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
50939+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50940+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50941+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50944+4 4 4 4 4 4
50945+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
50946+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
50947+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50948+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
50949+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
50950+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
50951+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
50952+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
50953+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50954+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50955+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50958+4 4 4 4 4 4
50959+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
50960+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
50961+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50962+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
50963+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
50964+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
50965+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
50966+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
50967+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50968+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50969+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50972+4 4 4 4 4 4
50973+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50974+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
50975+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50976+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
50977+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
50978+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
50979+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
50980+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
50981+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50982+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50983+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50986+4 4 4 4 4 4
50987+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
50988+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
50989+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50990+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
50991+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
50992+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
50993+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
50994+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
50995+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
50996+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50997+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51000+4 4 4 4 4 4
51001+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51002+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51003+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51004+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51005+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51006+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51007+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51008+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51009+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51010+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51011+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51014+4 4 4 4 4 4
51015+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51016+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51017+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51018+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51019+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51020+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51021+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51022+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51023+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51024+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51025+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51028+4 4 4 4 4 4
51029+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51030+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51031+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51032+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51033+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51034+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51035+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51036+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51037+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51038+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51039+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51042+4 4 4 4 4 4
51043+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51044+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51045+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51046+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51047+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51048+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51049+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51050+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51051+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51052+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51053+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51056+4 4 4 4 4 4
51057+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51058+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51059+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51060+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51061+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51062+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51063+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51064+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51065+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51066+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51067+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51070+4 4 4 4 4 4
51071+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51072+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51073+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51074+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51075+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51076+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51077+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51078+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51079+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51080+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51081+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51084+4 4 4 4 4 4
51085+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51086+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51087+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51088+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51089+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51090+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51091+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51092+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51093+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51094+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51095+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51098+4 4 4 4 4 4
51099+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51100+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51101+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51102+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51103+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51104+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51105+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51106+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51107+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51108+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51109+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51112+4 4 4 4 4 4
51113+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51114+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51115+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51116+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51117+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51118+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51119+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51120+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51121+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51122+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51123+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51126+4 4 4 4 4 4
51127+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51128+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51129+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51130+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51131+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51132+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51133+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51134+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51135+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51136+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51137+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51140+4 4 4 4 4 4
51141+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51142+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51143+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51144+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51145+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51146+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51147+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51148+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51149+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51150+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51151+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51154+4 4 4 4 4 4
51155+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51156+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51157+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51158+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51159+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51160+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51161+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51162+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51163+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51164+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51165+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51168+4 4 4 4 4 4
51169+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51170+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51171+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51172+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51173+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51174+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51175+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51176+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51177+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51178+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51182+4 4 4 4 4 4
51183+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51184+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51185+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51186+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51187+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51188+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51189+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51190+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51191+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51192+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51196+4 4 4 4 4 4
51197+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51198+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51199+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51200+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51201+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51202+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51203+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51204+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51205+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51206+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51210+4 4 4 4 4 4
51211+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51212+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51213+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51214+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51215+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51216+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51217+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51218+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51219+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51220+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51224+4 4 4 4 4 4
51225+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51226+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51227+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51228+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51229+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51230+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51231+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51232+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51233+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51238+4 4 4 4 4 4
51239+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51240+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51241+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51242+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51243+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51244+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51245+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51246+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51247+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51252+4 4 4 4 4 4
51253+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51254+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51255+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51256+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51257+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51258+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51259+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51260+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51261+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51266+4 4 4 4 4 4
51267+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51268+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51269+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51270+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51271+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51272+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51273+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51274+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51280+4 4 4 4 4 4
51281+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51282+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51283+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51284+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51285+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51286+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51287+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51288+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51294+4 4 4 4 4 4
51295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51296+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51297+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51298+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51299+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51300+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51301+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51302+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51308+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51311+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51312+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51313+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51314+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51315+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51316+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51322+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 5 5 5 5 5 5 5 5 5
51325+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51326+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51327+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51328+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51329+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51330+5 5 5 5 5 5 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 4 4 4
51332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51336+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51340+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51341+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51342+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51343+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51344+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51350+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 5 5 5
51354+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51355+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51356+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51357+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
51361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51364+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51369+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51370+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51371+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4
51375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51378+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
51383+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51384+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51385+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4
51389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51392+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
51397+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51398+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51399+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51406+4 4 4 4 4 4
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 5 5 5
51411+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51412+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51413+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51420+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51426+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51427+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4
51432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51434+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51440+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51441+5 5 5 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 4 4 4 4 4 4
51446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51448+4 4 4 4 4 4
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 5 5 5 4 3 3 6 6 6
51454+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51462+4 4 4 4 4 4
51463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51467+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51468+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51476+4 4 4 4 4 4
51477diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51478index fe92eed..106e085 100644
51479--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51480+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51481@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51482 struct mb862xxfb_par *par = info->par;
51483
51484 if (info->var.bits_per_pixel == 32) {
51485- info->fbops->fb_fillrect = cfb_fillrect;
51486- info->fbops->fb_copyarea = cfb_copyarea;
51487- info->fbops->fb_imageblit = cfb_imageblit;
51488+ pax_open_kernel();
51489+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51490+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51491+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51492+ pax_close_kernel();
51493 } else {
51494 outreg(disp, GC_L0EM, 3);
51495- info->fbops->fb_fillrect = mb86290fb_fillrect;
51496- info->fbops->fb_copyarea = mb86290fb_copyarea;
51497- info->fbops->fb_imageblit = mb86290fb_imageblit;
51498+ pax_open_kernel();
51499+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51500+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51501+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51502+ pax_close_kernel();
51503 }
51504 outreg(draw, GDC_REG_DRAW_BASE, 0);
51505 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51506diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51507index ff22871..b129bed 100644
51508--- a/drivers/video/nvidia/nvidia.c
51509+++ b/drivers/video/nvidia/nvidia.c
51510@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51511 info->fix.line_length = (info->var.xres_virtual *
51512 info->var.bits_per_pixel) >> 3;
51513 if (info->var.accel_flags) {
51514- info->fbops->fb_imageblit = nvidiafb_imageblit;
51515- info->fbops->fb_fillrect = nvidiafb_fillrect;
51516- info->fbops->fb_copyarea = nvidiafb_copyarea;
51517- info->fbops->fb_sync = nvidiafb_sync;
51518+ pax_open_kernel();
51519+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51520+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51521+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51522+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51523+ pax_close_kernel();
51524 info->pixmap.scan_align = 4;
51525 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51526 info->flags |= FBINFO_READS_FAST;
51527 NVResetGraphics(info);
51528 } else {
51529- info->fbops->fb_imageblit = cfb_imageblit;
51530- info->fbops->fb_fillrect = cfb_fillrect;
51531- info->fbops->fb_copyarea = cfb_copyarea;
51532- info->fbops->fb_sync = NULL;
51533+ pax_open_kernel();
51534+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51535+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51536+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51537+ *(void **)&info->fbops->fb_sync = NULL;
51538+ pax_close_kernel();
51539 info->pixmap.scan_align = 1;
51540 info->flags |= FBINFO_HWACCEL_DISABLED;
51541 info->flags &= ~FBINFO_READS_FAST;
51542@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51543 info->pixmap.size = 8 * 1024;
51544 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51545
51546- if (!hwcur)
51547- info->fbops->fb_cursor = NULL;
51548+ if (!hwcur) {
51549+ pax_open_kernel();
51550+ *(void **)&info->fbops->fb_cursor = NULL;
51551+ pax_close_kernel();
51552+ }
51553
51554 info->var.accel_flags = (!noaccel);
51555
51556diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51557index 05c2dc3..ea1f391 100644
51558--- a/drivers/video/s1d13xxxfb.c
51559+++ b/drivers/video/s1d13xxxfb.c
51560@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51561
51562 switch(prod_id) {
51563 case S1D13506_PROD_ID: /* activate acceleration */
51564- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51565- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51566+ pax_open_kernel();
51567+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51568+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51569+ pax_close_kernel();
51570 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51571 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51572 break;
51573diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51574index e188ada..aac63c8 100644
51575--- a/drivers/video/smscufx.c
51576+++ b/drivers/video/smscufx.c
51577@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51578 fb_deferred_io_cleanup(info);
51579 kfree(info->fbdefio);
51580 info->fbdefio = NULL;
51581- info->fbops->fb_mmap = ufx_ops_mmap;
51582+ pax_open_kernel();
51583+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51584+ pax_close_kernel();
51585 }
51586
51587 pr_debug("released /dev/fb%d user=%d count=%d",
51588diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51589index d2e5bc3..4cb05d1 100644
51590--- a/drivers/video/udlfb.c
51591+++ b/drivers/video/udlfb.c
51592@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51593 dlfb_urb_completion(urb);
51594
51595 error:
51596- atomic_add(bytes_sent, &dev->bytes_sent);
51597- atomic_add(bytes_identical, &dev->bytes_identical);
51598- atomic_add(width*height*2, &dev->bytes_rendered);
51599+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51600+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51601+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51602 end_cycles = get_cycles();
51603- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51604+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51605 >> 10)), /* Kcycles */
51606 &dev->cpu_kcycles_used);
51607
51608@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51609 dlfb_urb_completion(urb);
51610
51611 error:
51612- atomic_add(bytes_sent, &dev->bytes_sent);
51613- atomic_add(bytes_identical, &dev->bytes_identical);
51614- atomic_add(bytes_rendered, &dev->bytes_rendered);
51615+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51616+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51617+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51618 end_cycles = get_cycles();
51619- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51620+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51621 >> 10)), /* Kcycles */
51622 &dev->cpu_kcycles_used);
51623 }
51624@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51625 fb_deferred_io_cleanup(info);
51626 kfree(info->fbdefio);
51627 info->fbdefio = NULL;
51628- info->fbops->fb_mmap = dlfb_ops_mmap;
51629+ pax_open_kernel();
51630+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51631+ pax_close_kernel();
51632 }
51633
51634 pr_warn("released /dev/fb%d user=%d count=%d\n",
51635@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51636 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51637 struct dlfb_data *dev = fb_info->par;
51638 return snprintf(buf, PAGE_SIZE, "%u\n",
51639- atomic_read(&dev->bytes_rendered));
51640+ atomic_read_unchecked(&dev->bytes_rendered));
51641 }
51642
51643 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51644@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51645 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51646 struct dlfb_data *dev = fb_info->par;
51647 return snprintf(buf, PAGE_SIZE, "%u\n",
51648- atomic_read(&dev->bytes_identical));
51649+ atomic_read_unchecked(&dev->bytes_identical));
51650 }
51651
51652 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51653@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51654 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51655 struct dlfb_data *dev = fb_info->par;
51656 return snprintf(buf, PAGE_SIZE, "%u\n",
51657- atomic_read(&dev->bytes_sent));
51658+ atomic_read_unchecked(&dev->bytes_sent));
51659 }
51660
51661 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51662@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51663 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51664 struct dlfb_data *dev = fb_info->par;
51665 return snprintf(buf, PAGE_SIZE, "%u\n",
51666- atomic_read(&dev->cpu_kcycles_used));
51667+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51668 }
51669
51670 static ssize_t edid_show(
51671@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51672 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51673 struct dlfb_data *dev = fb_info->par;
51674
51675- atomic_set(&dev->bytes_rendered, 0);
51676- atomic_set(&dev->bytes_identical, 0);
51677- atomic_set(&dev->bytes_sent, 0);
51678- atomic_set(&dev->cpu_kcycles_used, 0);
51679+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51680+ atomic_set_unchecked(&dev->bytes_identical, 0);
51681+ atomic_set_unchecked(&dev->bytes_sent, 0);
51682+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51683
51684 return count;
51685 }
51686diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51687index 7aec6f3..e3b2d55 100644
51688--- a/drivers/video/uvesafb.c
51689+++ b/drivers/video/uvesafb.c
51690@@ -19,6 +19,7 @@
51691 #include <linux/io.h>
51692 #include <linux/mutex.h>
51693 #include <linux/slab.h>
51694+#include <linux/moduleloader.h>
51695 #include <video/edid.h>
51696 #include <video/uvesafb.h>
51697 #ifdef CONFIG_X86
51698@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51699 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51700 par->pmi_setpal = par->ypan = 0;
51701 } else {
51702+
51703+#ifdef CONFIG_PAX_KERNEXEC
51704+#ifdef CONFIG_MODULES
51705+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51706+#endif
51707+ if (!par->pmi_code) {
51708+ par->pmi_setpal = par->ypan = 0;
51709+ return 0;
51710+ }
51711+#endif
51712+
51713 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51714 + task->t.regs.edi);
51715+
51716+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51717+ pax_open_kernel();
51718+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51719+ pax_close_kernel();
51720+
51721+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51722+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51723+#else
51724 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51725 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51726+#endif
51727+
51728 printk(KERN_INFO "uvesafb: protected mode interface info at "
51729 "%04x:%04x\n",
51730 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51731@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51732 par->ypan = ypan;
51733
51734 if (par->pmi_setpal || par->ypan) {
51735+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51736 if (__supported_pte_mask & _PAGE_NX) {
51737 par->pmi_setpal = par->ypan = 0;
51738 printk(KERN_WARNING "uvesafb: NX protection is active, "
51739 "better not use the PMI.\n");
51740- } else {
51741+ } else
51742+#endif
51743 uvesafb_vbe_getpmi(task, par);
51744- }
51745 }
51746 #else
51747 /* The protected mode interface is not available on non-x86. */
51748@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51749 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51750
51751 /* Disable blanking if the user requested so. */
51752- if (!blank)
51753- info->fbops->fb_blank = NULL;
51754+ if (!blank) {
51755+ pax_open_kernel();
51756+ *(void **)&info->fbops->fb_blank = NULL;
51757+ pax_close_kernel();
51758+ }
51759
51760 /*
51761 * Find out how much IO memory is required for the mode with
51762@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51763 info->flags = FBINFO_FLAG_DEFAULT |
51764 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51765
51766- if (!par->ypan)
51767- info->fbops->fb_pan_display = NULL;
51768+ if (!par->ypan) {
51769+ pax_open_kernel();
51770+ *(void **)&info->fbops->fb_pan_display = NULL;
51771+ pax_close_kernel();
51772+ }
51773 }
51774
51775 static void uvesafb_init_mtrr(struct fb_info *info)
51776@@ -1796,6 +1826,11 @@ out:
51777 if (par->vbe_modes)
51778 kfree(par->vbe_modes);
51779
51780+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51781+ if (par->pmi_code)
51782+ module_free_exec(NULL, par->pmi_code);
51783+#endif
51784+
51785 framebuffer_release(info);
51786 return err;
51787 }
51788@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51789 kfree(par->vbe_state_orig);
51790 if (par->vbe_state_saved)
51791 kfree(par->vbe_state_saved);
51792+
51793+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51794+ if (par->pmi_code)
51795+ module_free_exec(NULL, par->pmi_code);
51796+#endif
51797+
51798 }
51799
51800 framebuffer_release(info);
51801diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51802index 501b340..d80aa17 100644
51803--- a/drivers/video/vesafb.c
51804+++ b/drivers/video/vesafb.c
51805@@ -9,6 +9,7 @@
51806 */
51807
51808 #include <linux/module.h>
51809+#include <linux/moduleloader.h>
51810 #include <linux/kernel.h>
51811 #include <linux/errno.h>
51812 #include <linux/string.h>
51813@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
51814 static int vram_total __initdata; /* Set total amount of memory */
51815 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
51816 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
51817-static void (*pmi_start)(void) __read_mostly;
51818-static void (*pmi_pal) (void) __read_mostly;
51819+static void (*pmi_start)(void) __read_only;
51820+static void (*pmi_pal) (void) __read_only;
51821 static int depth __read_mostly;
51822 static int vga_compat __read_mostly;
51823 /* --------------------------------------------------------------------- */
51824@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
51825 unsigned int size_vmode;
51826 unsigned int size_remap;
51827 unsigned int size_total;
51828+ void *pmi_code = NULL;
51829
51830 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
51831 return -ENODEV;
51832@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
51833 size_remap = size_total;
51834 vesafb_fix.smem_len = size_remap;
51835
51836-#ifndef __i386__
51837- screen_info.vesapm_seg = 0;
51838-#endif
51839-
51840 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
51841 printk(KERN_WARNING
51842 "vesafb: cannot reserve video memory at 0x%lx\n",
51843@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
51844 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
51845 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
51846
51847+#ifdef __i386__
51848+
51849+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51850+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
51851+ if (!pmi_code)
51852+#elif !defined(CONFIG_PAX_KERNEXEC)
51853+ if (0)
51854+#endif
51855+
51856+#endif
51857+ screen_info.vesapm_seg = 0;
51858+
51859 if (screen_info.vesapm_seg) {
51860- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
51861- screen_info.vesapm_seg,screen_info.vesapm_off);
51862+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
51863+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
51864 }
51865
51866 if (screen_info.vesapm_seg < 0xc000)
51867@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
51868
51869 if (ypan || pmi_setpal) {
51870 unsigned short *pmi_base;
51871+
51872 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
51873- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
51874- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
51875+
51876+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51877+ pax_open_kernel();
51878+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
51879+#else
51880+ pmi_code = pmi_base;
51881+#endif
51882+
51883+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
51884+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
51885+
51886+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51887+ pmi_start = ktva_ktla(pmi_start);
51888+ pmi_pal = ktva_ktla(pmi_pal);
51889+ pax_close_kernel();
51890+#endif
51891+
51892 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
51893 if (pmi_base[3]) {
51894 printk(KERN_INFO "vesafb: pmi: ports = ");
51895@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51896 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
51897 (ypan ? FBINFO_HWACCEL_YPAN : 0);
51898
51899- if (!ypan)
51900- info->fbops->fb_pan_display = NULL;
51901+ if (!ypan) {
51902+ pax_open_kernel();
51903+ *(void **)&info->fbops->fb_pan_display = NULL;
51904+ pax_close_kernel();
51905+ }
51906
51907 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
51908 err = -ENOMEM;
51909@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51910 info->node, info->fix.id);
51911 return 0;
51912 err:
51913+
51914+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51915+ module_free_exec(NULL, pmi_code);
51916+#endif
51917+
51918 if (info->screen_base)
51919 iounmap(info->screen_base);
51920 framebuffer_release(info);
51921diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
51922index 88714ae..16c2e11 100644
51923--- a/drivers/video/via/via_clock.h
51924+++ b/drivers/video/via/via_clock.h
51925@@ -56,7 +56,7 @@ struct via_clock {
51926
51927 void (*set_engine_pll_state)(u8 state);
51928 void (*set_engine_pll)(struct via_pll_config config);
51929-};
51930+} __no_const;
51931
51932
51933 static inline u32 get_pll_internal_frequency(u32 ref_freq,
51934diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
51935index fef20db..d28b1ab 100644
51936--- a/drivers/xen/xenfs/xenstored.c
51937+++ b/drivers/xen/xenfs/xenstored.c
51938@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
51939 static int xsd_kva_open(struct inode *inode, struct file *file)
51940 {
51941 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
51942+#ifdef CONFIG_GRKERNSEC_HIDESYM
51943+ NULL);
51944+#else
51945 xen_store_interface);
51946+#endif
51947+
51948 if (!file->private_data)
51949 return -ENOMEM;
51950 return 0;
51951diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
51952index 9ff073f..05cef23 100644
51953--- a/fs/9p/vfs_addr.c
51954+++ b/fs/9p/vfs_addr.c
51955@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
51956
51957 retval = v9fs_file_write_internal(inode,
51958 v9inode->writeback_fid,
51959- (__force const char __user *)buffer,
51960+ (const char __force_user *)buffer,
51961 len, &offset, 0);
51962 if (retval > 0)
51963 retval = 0;
51964diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
51965index 25b018e..b941525 100644
51966--- a/fs/9p/vfs_inode.c
51967+++ b/fs/9p/vfs_inode.c
51968@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51969 void
51970 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51971 {
51972- char *s = nd_get_link(nd);
51973+ const char *s = nd_get_link(nd);
51974
51975 p9_debug(P9_DEBUG_VFS, " %s %s\n",
51976 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
51977diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
51978index 370b24c..ff0be7b 100644
51979--- a/fs/Kconfig.binfmt
51980+++ b/fs/Kconfig.binfmt
51981@@ -103,7 +103,7 @@ config HAVE_AOUT
51982
51983 config BINFMT_AOUT
51984 tristate "Kernel support for a.out and ECOFF binaries"
51985- depends on HAVE_AOUT
51986+ depends on HAVE_AOUT && BROKEN
51987 ---help---
51988 A.out (Assembler.OUTput) is a set of formats for libraries and
51989 executables used in the earliest versions of UNIX. Linux used
51990diff --git a/fs/afs/inode.c b/fs/afs/inode.c
51991index 789bc25..fafaeea 100644
51992--- a/fs/afs/inode.c
51993+++ b/fs/afs/inode.c
51994@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51995 struct afs_vnode *vnode;
51996 struct super_block *sb;
51997 struct inode *inode;
51998- static atomic_t afs_autocell_ino;
51999+ static atomic_unchecked_t afs_autocell_ino;
52000
52001 _enter("{%x:%u},%*.*s,",
52002 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52003@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52004 data.fid.unique = 0;
52005 data.fid.vnode = 0;
52006
52007- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52008+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52009 afs_iget5_autocell_test, afs_iget5_set,
52010 &data);
52011 if (!inode) {
52012diff --git a/fs/aio.c b/fs/aio.c
52013index 9b5ca11..c530886 100644
52014--- a/fs/aio.c
52015+++ b/fs/aio.c
52016@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52017 size += sizeof(struct io_event) * nr_events;
52018 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52019
52020- if (nr_pages < 0)
52021+ if (nr_pages <= 0)
52022 return -EINVAL;
52023
52024 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52025@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52026 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52027 {
52028 ssize_t ret;
52029+ struct iovec iovstack;
52030
52031 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52032
52033@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52034 if (compat)
52035 ret = compat_rw_copy_check_uvector(rw,
52036 (struct compat_iovec __user *)kiocb->ki_buf,
52037- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52038+ kiocb->ki_nr_segs, 1, &iovstack,
52039 &kiocb->ki_iovec);
52040 else
52041 #endif
52042 ret = rw_copy_check_uvector(rw,
52043 (struct iovec __user *)kiocb->ki_buf,
52044- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52045+ kiocb->ki_nr_segs, 1, &iovstack,
52046 &kiocb->ki_iovec);
52047 if (ret < 0)
52048 return ret;
52049
52050+ if (kiocb->ki_iovec == &iovstack) {
52051+ kiocb->ki_inline_vec = iovstack;
52052+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52053+ }
52054+
52055 /* ki_nbytes now reflect bytes instead of segs */
52056 kiocb->ki_nbytes = ret;
52057 return 0;
52058diff --git a/fs/attr.c b/fs/attr.c
52059index 1449adb..a2038c2 100644
52060--- a/fs/attr.c
52061+++ b/fs/attr.c
52062@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52063 unsigned long limit;
52064
52065 limit = rlimit(RLIMIT_FSIZE);
52066+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52067 if (limit != RLIM_INFINITY && offset > limit)
52068 goto out_sig;
52069 if (offset > inode->i_sb->s_maxbytes)
52070diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52071index 3db70da..7aeec5b 100644
52072--- a/fs/autofs4/waitq.c
52073+++ b/fs/autofs4/waitq.c
52074@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52075 {
52076 unsigned long sigpipe, flags;
52077 mm_segment_t fs;
52078- const char *data = (const char *)addr;
52079+ const char __user *data = (const char __force_user *)addr;
52080 ssize_t wr = 0;
52081
52082 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52083@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52084 return 1;
52085 }
52086
52087+#ifdef CONFIG_GRKERNSEC_HIDESYM
52088+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52089+#endif
52090+
52091 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52092 enum autofs_notify notify)
52093 {
52094@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52095
52096 /* If this is a direct mount request create a dummy name */
52097 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52098+#ifdef CONFIG_GRKERNSEC_HIDESYM
52099+ /* this name does get written to userland via autofs4_write() */
52100+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52101+#else
52102 qstr.len = sprintf(name, "%p", dentry);
52103+#endif
52104 else {
52105 qstr.len = autofs4_getpath(sbi, dentry, &name);
52106 if (!qstr.len) {
52107diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52108index 2722387..c8dd2a7 100644
52109--- a/fs/befs/endian.h
52110+++ b/fs/befs/endian.h
52111@@ -11,7 +11,7 @@
52112
52113 #include <asm/byteorder.h>
52114
52115-static inline u64
52116+static inline u64 __intentional_overflow(-1)
52117 fs64_to_cpu(const struct super_block *sb, fs64 n)
52118 {
52119 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52120@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52121 return (__force fs64)cpu_to_be64(n);
52122 }
52123
52124-static inline u32
52125+static inline u32 __intentional_overflow(-1)
52126 fs32_to_cpu(const struct super_block *sb, fs32 n)
52127 {
52128 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52129diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52130index e9c75e2..1baece1 100644
52131--- a/fs/befs/linuxvfs.c
52132+++ b/fs/befs/linuxvfs.c
52133@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52134 {
52135 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52136 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52137- char *link = nd_get_link(nd);
52138+ const char *link = nd_get_link(nd);
52139 if (!IS_ERR(link))
52140 kfree(link);
52141 }
52142diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52143index 89dec7f..361b0d75 100644
52144--- a/fs/binfmt_aout.c
52145+++ b/fs/binfmt_aout.c
52146@@ -16,6 +16,7 @@
52147 #include <linux/string.h>
52148 #include <linux/fs.h>
52149 #include <linux/file.h>
52150+#include <linux/security.h>
52151 #include <linux/stat.h>
52152 #include <linux/fcntl.h>
52153 #include <linux/ptrace.h>
52154@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52155 #endif
52156 # define START_STACK(u) ((void __user *)u.start_stack)
52157
52158+ memset(&dump, 0, sizeof(dump));
52159+
52160 fs = get_fs();
52161 set_fs(KERNEL_DS);
52162 has_dumped = 1;
52163@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52164
52165 /* If the size of the dump file exceeds the rlimit, then see what would happen
52166 if we wrote the stack, but not the data area. */
52167+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52168 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52169 dump.u_dsize = 0;
52170
52171 /* Make sure we have enough room to write the stack and data areas. */
52172+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52173 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52174 dump.u_ssize = 0;
52175
52176@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52177 rlim = rlimit(RLIMIT_DATA);
52178 if (rlim >= RLIM_INFINITY)
52179 rlim = ~0;
52180+
52181+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52182 if (ex.a_data + ex.a_bss > rlim)
52183 return -ENOMEM;
52184
52185@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52186
52187 install_exec_creds(bprm);
52188
52189+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52190+ current->mm->pax_flags = 0UL;
52191+#endif
52192+
52193+#ifdef CONFIG_PAX_PAGEEXEC
52194+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52195+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52196+
52197+#ifdef CONFIG_PAX_EMUTRAMP
52198+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52199+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52200+#endif
52201+
52202+#ifdef CONFIG_PAX_MPROTECT
52203+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52204+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52205+#endif
52206+
52207+ }
52208+#endif
52209+
52210 if (N_MAGIC(ex) == OMAGIC) {
52211 unsigned long text_addr, map_size;
52212 loff_t pos;
52213@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52214 }
52215
52216 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52217- PROT_READ | PROT_WRITE | PROT_EXEC,
52218+ PROT_READ | PROT_WRITE,
52219 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52220 fd_offset + ex.a_text);
52221 if (error != N_DATADDR(ex)) {
52222diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52223index 4c94a79..f428019 100644
52224--- a/fs/binfmt_elf.c
52225+++ b/fs/binfmt_elf.c
52226@@ -34,6 +34,7 @@
52227 #include <linux/utsname.h>
52228 #include <linux/coredump.h>
52229 #include <linux/sched.h>
52230+#include <linux/xattr.h>
52231 #include <asm/uaccess.h>
52232 #include <asm/param.h>
52233 #include <asm/page.h>
52234@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52235 #define elf_core_dump NULL
52236 #endif
52237
52238+#ifdef CONFIG_PAX_MPROTECT
52239+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52240+#endif
52241+
52242+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52243+static void elf_handle_mmap(struct file *file);
52244+#endif
52245+
52246 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52247 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52248 #else
52249@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52250 .load_binary = load_elf_binary,
52251 .load_shlib = load_elf_library,
52252 .core_dump = elf_core_dump,
52253+
52254+#ifdef CONFIG_PAX_MPROTECT
52255+ .handle_mprotect= elf_handle_mprotect,
52256+#endif
52257+
52258+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52259+ .handle_mmap = elf_handle_mmap,
52260+#endif
52261+
52262 .min_coredump = ELF_EXEC_PAGESIZE,
52263 };
52264
52265@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52266
52267 static int set_brk(unsigned long start, unsigned long end)
52268 {
52269+ unsigned long e = end;
52270+
52271 start = ELF_PAGEALIGN(start);
52272 end = ELF_PAGEALIGN(end);
52273 if (end > start) {
52274@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52275 if (BAD_ADDR(addr))
52276 return addr;
52277 }
52278- current->mm->start_brk = current->mm->brk = end;
52279+ current->mm->start_brk = current->mm->brk = e;
52280 return 0;
52281 }
52282
52283@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52284 elf_addr_t __user *u_rand_bytes;
52285 const char *k_platform = ELF_PLATFORM;
52286 const char *k_base_platform = ELF_BASE_PLATFORM;
52287- unsigned char k_rand_bytes[16];
52288+ u32 k_rand_bytes[4];
52289 int items;
52290 elf_addr_t *elf_info;
52291 int ei_index = 0;
52292 const struct cred *cred = current_cred();
52293 struct vm_area_struct *vma;
52294+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52295
52296 /*
52297 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52298@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52299 * Generate 16 random bytes for userspace PRNG seeding.
52300 */
52301 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52302- u_rand_bytes = (elf_addr_t __user *)
52303- STACK_ALLOC(p, sizeof(k_rand_bytes));
52304+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52305+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52306+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52307+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52308+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52309+ u_rand_bytes = (elf_addr_t __user *) p;
52310 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52311 return -EFAULT;
52312
52313@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52314 return -EFAULT;
52315 current->mm->env_end = p;
52316
52317+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52318+
52319 /* Put the elf_info on the stack in the right place. */
52320 sp = (elf_addr_t __user *)envp + 1;
52321- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52322+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52323 return -EFAULT;
52324 return 0;
52325 }
52326@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52327 an ELF header */
52328
52329 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52330- struct file *interpreter, unsigned long *interp_map_addr,
52331- unsigned long no_base)
52332+ struct file *interpreter, unsigned long no_base)
52333 {
52334 struct elf_phdr *elf_phdata;
52335 struct elf_phdr *eppnt;
52336- unsigned long load_addr = 0;
52337+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52338 int load_addr_set = 0;
52339 unsigned long last_bss = 0, elf_bss = 0;
52340- unsigned long error = ~0UL;
52341+ unsigned long error = -EINVAL;
52342 unsigned long total_size;
52343 int retval, i, size;
52344
52345@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52346 goto out_close;
52347 }
52348
52349+#ifdef CONFIG_PAX_SEGMEXEC
52350+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52351+ pax_task_size = SEGMEXEC_TASK_SIZE;
52352+#endif
52353+
52354 eppnt = elf_phdata;
52355 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52356 if (eppnt->p_type == PT_LOAD) {
52357@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52358 map_addr = elf_map(interpreter, load_addr + vaddr,
52359 eppnt, elf_prot, elf_type, total_size);
52360 total_size = 0;
52361- if (!*interp_map_addr)
52362- *interp_map_addr = map_addr;
52363 error = map_addr;
52364 if (BAD_ADDR(map_addr))
52365 goto out_close;
52366@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52367 k = load_addr + eppnt->p_vaddr;
52368 if (BAD_ADDR(k) ||
52369 eppnt->p_filesz > eppnt->p_memsz ||
52370- eppnt->p_memsz > TASK_SIZE ||
52371- TASK_SIZE - eppnt->p_memsz < k) {
52372+ eppnt->p_memsz > pax_task_size ||
52373+ pax_task_size - eppnt->p_memsz < k) {
52374 error = -ENOMEM;
52375 goto out_close;
52376 }
52377@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52378 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52379
52380 /* Map the last of the bss segment */
52381- error = vm_brk(elf_bss, last_bss - elf_bss);
52382- if (BAD_ADDR(error))
52383- goto out_close;
52384+ if (last_bss > elf_bss) {
52385+ error = vm_brk(elf_bss, last_bss - elf_bss);
52386+ if (BAD_ADDR(error))
52387+ goto out_close;
52388+ }
52389 }
52390
52391 error = load_addr;
52392@@ -538,6 +569,315 @@ out:
52393 return error;
52394 }
52395
52396+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52397+#ifdef CONFIG_PAX_SOFTMODE
52398+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52399+{
52400+ unsigned long pax_flags = 0UL;
52401+
52402+#ifdef CONFIG_PAX_PAGEEXEC
52403+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52404+ pax_flags |= MF_PAX_PAGEEXEC;
52405+#endif
52406+
52407+#ifdef CONFIG_PAX_SEGMEXEC
52408+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52409+ pax_flags |= MF_PAX_SEGMEXEC;
52410+#endif
52411+
52412+#ifdef CONFIG_PAX_EMUTRAMP
52413+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52414+ pax_flags |= MF_PAX_EMUTRAMP;
52415+#endif
52416+
52417+#ifdef CONFIG_PAX_MPROTECT
52418+ if (elf_phdata->p_flags & PF_MPROTECT)
52419+ pax_flags |= MF_PAX_MPROTECT;
52420+#endif
52421+
52422+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52423+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52424+ pax_flags |= MF_PAX_RANDMMAP;
52425+#endif
52426+
52427+ return pax_flags;
52428+}
52429+#endif
52430+
52431+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52432+{
52433+ unsigned long pax_flags = 0UL;
52434+
52435+#ifdef CONFIG_PAX_PAGEEXEC
52436+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52437+ pax_flags |= MF_PAX_PAGEEXEC;
52438+#endif
52439+
52440+#ifdef CONFIG_PAX_SEGMEXEC
52441+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52442+ pax_flags |= MF_PAX_SEGMEXEC;
52443+#endif
52444+
52445+#ifdef CONFIG_PAX_EMUTRAMP
52446+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52447+ pax_flags |= MF_PAX_EMUTRAMP;
52448+#endif
52449+
52450+#ifdef CONFIG_PAX_MPROTECT
52451+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52452+ pax_flags |= MF_PAX_MPROTECT;
52453+#endif
52454+
52455+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52456+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52457+ pax_flags |= MF_PAX_RANDMMAP;
52458+#endif
52459+
52460+ return pax_flags;
52461+}
52462+#endif
52463+
52464+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52465+#ifdef CONFIG_PAX_SOFTMODE
52466+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52467+{
52468+ unsigned long pax_flags = 0UL;
52469+
52470+#ifdef CONFIG_PAX_PAGEEXEC
52471+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52472+ pax_flags |= MF_PAX_PAGEEXEC;
52473+#endif
52474+
52475+#ifdef CONFIG_PAX_SEGMEXEC
52476+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52477+ pax_flags |= MF_PAX_SEGMEXEC;
52478+#endif
52479+
52480+#ifdef CONFIG_PAX_EMUTRAMP
52481+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52482+ pax_flags |= MF_PAX_EMUTRAMP;
52483+#endif
52484+
52485+#ifdef CONFIG_PAX_MPROTECT
52486+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52487+ pax_flags |= MF_PAX_MPROTECT;
52488+#endif
52489+
52490+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52491+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52492+ pax_flags |= MF_PAX_RANDMMAP;
52493+#endif
52494+
52495+ return pax_flags;
52496+}
52497+#endif
52498+
52499+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52500+{
52501+ unsigned long pax_flags = 0UL;
52502+
52503+#ifdef CONFIG_PAX_PAGEEXEC
52504+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52505+ pax_flags |= MF_PAX_PAGEEXEC;
52506+#endif
52507+
52508+#ifdef CONFIG_PAX_SEGMEXEC
52509+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52510+ pax_flags |= MF_PAX_SEGMEXEC;
52511+#endif
52512+
52513+#ifdef CONFIG_PAX_EMUTRAMP
52514+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52515+ pax_flags |= MF_PAX_EMUTRAMP;
52516+#endif
52517+
52518+#ifdef CONFIG_PAX_MPROTECT
52519+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52520+ pax_flags |= MF_PAX_MPROTECT;
52521+#endif
52522+
52523+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52524+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52525+ pax_flags |= MF_PAX_RANDMMAP;
52526+#endif
52527+
52528+ return pax_flags;
52529+}
52530+#endif
52531+
52532+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52533+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52534+{
52535+ unsigned long pax_flags = 0UL;
52536+
52537+#ifdef CONFIG_PAX_EI_PAX
52538+
52539+#ifdef CONFIG_PAX_PAGEEXEC
52540+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52541+ pax_flags |= MF_PAX_PAGEEXEC;
52542+#endif
52543+
52544+#ifdef CONFIG_PAX_SEGMEXEC
52545+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52546+ pax_flags |= MF_PAX_SEGMEXEC;
52547+#endif
52548+
52549+#ifdef CONFIG_PAX_EMUTRAMP
52550+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52551+ pax_flags |= MF_PAX_EMUTRAMP;
52552+#endif
52553+
52554+#ifdef CONFIG_PAX_MPROTECT
52555+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52556+ pax_flags |= MF_PAX_MPROTECT;
52557+#endif
52558+
52559+#ifdef CONFIG_PAX_ASLR
52560+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52561+ pax_flags |= MF_PAX_RANDMMAP;
52562+#endif
52563+
52564+#else
52565+
52566+#ifdef CONFIG_PAX_PAGEEXEC
52567+ pax_flags |= MF_PAX_PAGEEXEC;
52568+#endif
52569+
52570+#ifdef CONFIG_PAX_SEGMEXEC
52571+ pax_flags |= MF_PAX_SEGMEXEC;
52572+#endif
52573+
52574+#ifdef CONFIG_PAX_MPROTECT
52575+ pax_flags |= MF_PAX_MPROTECT;
52576+#endif
52577+
52578+#ifdef CONFIG_PAX_RANDMMAP
52579+ if (randomize_va_space)
52580+ pax_flags |= MF_PAX_RANDMMAP;
52581+#endif
52582+
52583+#endif
52584+
52585+ return pax_flags;
52586+}
52587+
52588+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52589+{
52590+
52591+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52592+ unsigned long i;
52593+
52594+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52595+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52596+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52597+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52598+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52599+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52600+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52601+ return ~0UL;
52602+
52603+#ifdef CONFIG_PAX_SOFTMODE
52604+ if (pax_softmode)
52605+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52606+ else
52607+#endif
52608+
52609+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52610+ break;
52611+ }
52612+#endif
52613+
52614+ return ~0UL;
52615+}
52616+
52617+static unsigned long pax_parse_xattr_pax(struct file * const file)
52618+{
52619+
52620+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52621+ ssize_t xattr_size, i;
52622+ unsigned char xattr_value[sizeof("pemrs") - 1];
52623+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52624+
52625+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52626+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52627+ return ~0UL;
52628+
52629+ for (i = 0; i < xattr_size; i++)
52630+ switch (xattr_value[i]) {
52631+ default:
52632+ return ~0UL;
52633+
52634+#define parse_flag(option1, option2, flag) \
52635+ case option1: \
52636+ if (pax_flags_hardmode & MF_PAX_##flag) \
52637+ return ~0UL; \
52638+ pax_flags_hardmode |= MF_PAX_##flag; \
52639+ break; \
52640+ case option2: \
52641+ if (pax_flags_softmode & MF_PAX_##flag) \
52642+ return ~0UL; \
52643+ pax_flags_softmode |= MF_PAX_##flag; \
52644+ break;
52645+
52646+ parse_flag('p', 'P', PAGEEXEC);
52647+ parse_flag('e', 'E', EMUTRAMP);
52648+ parse_flag('m', 'M', MPROTECT);
52649+ parse_flag('r', 'R', RANDMMAP);
52650+ parse_flag('s', 'S', SEGMEXEC);
52651+
52652+#undef parse_flag
52653+ }
52654+
52655+ if (pax_flags_hardmode & pax_flags_softmode)
52656+ return ~0UL;
52657+
52658+#ifdef CONFIG_PAX_SOFTMODE
52659+ if (pax_softmode)
52660+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52661+ else
52662+#endif
52663+
52664+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52665+#else
52666+ return ~0UL;
52667+#endif
52668+
52669+}
52670+
52671+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52672+{
52673+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52674+
52675+ pax_flags = pax_parse_ei_pax(elf_ex);
52676+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52677+ xattr_pax_flags = pax_parse_xattr_pax(file);
52678+
52679+ if (pt_pax_flags == ~0UL)
52680+ pt_pax_flags = xattr_pax_flags;
52681+ else if (xattr_pax_flags == ~0UL)
52682+ xattr_pax_flags = pt_pax_flags;
52683+ if (pt_pax_flags != xattr_pax_flags)
52684+ return -EINVAL;
52685+ if (pt_pax_flags != ~0UL)
52686+ pax_flags = pt_pax_flags;
52687+
52688+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52689+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52690+ if ((__supported_pte_mask & _PAGE_NX))
52691+ pax_flags &= ~MF_PAX_SEGMEXEC;
52692+ else
52693+ pax_flags &= ~MF_PAX_PAGEEXEC;
52694+ }
52695+#endif
52696+
52697+ if (0 > pax_check_flags(&pax_flags))
52698+ return -EINVAL;
52699+
52700+ current->mm->pax_flags = pax_flags;
52701+ return 0;
52702+}
52703+#endif
52704+
52705 /*
52706 * These are the functions used to load ELF style executables and shared
52707 * libraries. There is no binary dependent code anywhere else.
52708@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52709 {
52710 unsigned int random_variable = 0;
52711
52712+#ifdef CONFIG_PAX_RANDUSTACK
52713+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52714+ return stack_top - current->mm->delta_stack;
52715+#endif
52716+
52717 if ((current->flags & PF_RANDOMIZE) &&
52718 !(current->personality & ADDR_NO_RANDOMIZE)) {
52719 random_variable = get_random_int() & STACK_RND_MASK;
52720@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52721 unsigned long load_addr = 0, load_bias = 0;
52722 int load_addr_set = 0;
52723 char * elf_interpreter = NULL;
52724- unsigned long error;
52725+ unsigned long error = 0;
52726 struct elf_phdr *elf_ppnt, *elf_phdata;
52727 unsigned long elf_bss, elf_brk;
52728 int retval, i;
52729@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52730 unsigned long start_code, end_code, start_data, end_data;
52731 unsigned long reloc_func_desc __maybe_unused = 0;
52732 int executable_stack = EXSTACK_DEFAULT;
52733- unsigned long def_flags = 0;
52734 struct pt_regs *regs = current_pt_regs();
52735 struct {
52736 struct elfhdr elf_ex;
52737 struct elfhdr interp_elf_ex;
52738 } *loc;
52739+ unsigned long pax_task_size = TASK_SIZE;
52740
52741 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52742 if (!loc) {
52743@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52744 goto out_free_dentry;
52745
52746 /* OK, This is the point of no return */
52747- current->mm->def_flags = def_flags;
52748+
52749+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52750+ current->mm->pax_flags = 0UL;
52751+#endif
52752+
52753+#ifdef CONFIG_PAX_DLRESOLVE
52754+ current->mm->call_dl_resolve = 0UL;
52755+#endif
52756+
52757+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52758+ current->mm->call_syscall = 0UL;
52759+#endif
52760+
52761+#ifdef CONFIG_PAX_ASLR
52762+ current->mm->delta_mmap = 0UL;
52763+ current->mm->delta_stack = 0UL;
52764+#endif
52765+
52766+ current->mm->def_flags = 0;
52767+
52768+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52769+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52770+ send_sig(SIGKILL, current, 0);
52771+ goto out_free_dentry;
52772+ }
52773+#endif
52774+
52775+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52776+ pax_set_initial_flags(bprm);
52777+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52778+ if (pax_set_initial_flags_func)
52779+ (pax_set_initial_flags_func)(bprm);
52780+#endif
52781+
52782+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52783+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52784+ current->mm->context.user_cs_limit = PAGE_SIZE;
52785+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52786+ }
52787+#endif
52788+
52789+#ifdef CONFIG_PAX_SEGMEXEC
52790+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52791+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52792+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52793+ pax_task_size = SEGMEXEC_TASK_SIZE;
52794+ current->mm->def_flags |= VM_NOHUGEPAGE;
52795+ }
52796+#endif
52797+
52798+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52799+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52800+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52801+ put_cpu();
52802+ }
52803+#endif
52804
52805 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52806 may depend on the personality. */
52807 SET_PERSONALITY(loc->elf_ex);
52808+
52809+#ifdef CONFIG_PAX_ASLR
52810+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52811+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52812+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52813+ }
52814+#endif
52815+
52816+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52817+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52818+ executable_stack = EXSTACK_DISABLE_X;
52819+ current->personality &= ~READ_IMPLIES_EXEC;
52820+ } else
52821+#endif
52822+
52823 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52824 current->personality |= READ_IMPLIES_EXEC;
52825
52826@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52827 #else
52828 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
52829 #endif
52830+
52831+#ifdef CONFIG_PAX_RANDMMAP
52832+ /* PaX: randomize base address at the default exe base if requested */
52833+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
52834+#ifdef CONFIG_SPARC64
52835+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
52836+#else
52837+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
52838+#endif
52839+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
52840+ elf_flags |= MAP_FIXED;
52841+ }
52842+#endif
52843+
52844 }
52845
52846 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
52847@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
52848 * allowed task size. Note that p_filesz must always be
52849 * <= p_memsz so it is only necessary to check p_memsz.
52850 */
52851- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52852- elf_ppnt->p_memsz > TASK_SIZE ||
52853- TASK_SIZE - elf_ppnt->p_memsz < k) {
52854+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52855+ elf_ppnt->p_memsz > pax_task_size ||
52856+ pax_task_size - elf_ppnt->p_memsz < k) {
52857 /* set_brk can never work. Avoid overflows. */
52858 send_sig(SIGKILL, current, 0);
52859 retval = -EINVAL;
52860@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
52861 goto out_free_dentry;
52862 }
52863 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
52864- send_sig(SIGSEGV, current, 0);
52865- retval = -EFAULT; /* Nobody gets to see this, but.. */
52866- goto out_free_dentry;
52867+ /*
52868+ * This bss-zeroing can fail if the ELF
52869+ * file specifies odd protections. So
52870+ * we don't check the return value
52871+ */
52872 }
52873
52874+#ifdef CONFIG_PAX_RANDMMAP
52875+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52876+ unsigned long start, size, flags;
52877+ vm_flags_t vm_flags;
52878+
52879+ start = ELF_PAGEALIGN(elf_brk);
52880+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
52881+ flags = MAP_FIXED | MAP_PRIVATE;
52882+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
52883+
52884+ down_write(&current->mm->mmap_sem);
52885+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
52886+ retval = -ENOMEM;
52887+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
52888+// if (current->personality & ADDR_NO_RANDOMIZE)
52889+// vm_flags |= VM_READ | VM_MAYREAD;
52890+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
52891+ retval = IS_ERR_VALUE(start) ? start : 0;
52892+ }
52893+ up_write(&current->mm->mmap_sem);
52894+ if (retval == 0)
52895+ retval = set_brk(start + size, start + size + PAGE_SIZE);
52896+ if (retval < 0) {
52897+ send_sig(SIGKILL, current, 0);
52898+ goto out_free_dentry;
52899+ }
52900+ }
52901+#endif
52902+
52903 if (elf_interpreter) {
52904- unsigned long interp_map_addr = 0;
52905-
52906 elf_entry = load_elf_interp(&loc->interp_elf_ex,
52907 interpreter,
52908- &interp_map_addr,
52909 load_bias);
52910 if (!IS_ERR((void *)elf_entry)) {
52911 /*
52912@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
52913 * Decide what to dump of a segment, part, all or none.
52914 */
52915 static unsigned long vma_dump_size(struct vm_area_struct *vma,
52916- unsigned long mm_flags)
52917+ unsigned long mm_flags, long signr)
52918 {
52919 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
52920
52921@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
52922 if (vma->vm_file == NULL)
52923 return 0;
52924
52925- if (FILTER(MAPPED_PRIVATE))
52926+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
52927 goto whole;
52928
52929 /*
52930@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
52931 {
52932 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
52933 int i = 0;
52934- do
52935+ do {
52936 i += 2;
52937- while (auxv[i - 2] != AT_NULL);
52938+ } while (auxv[i - 2] != AT_NULL);
52939 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
52940 }
52941
52942@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
52943 {
52944 mm_segment_t old_fs = get_fs();
52945 set_fs(KERNEL_DS);
52946- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
52947+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
52948 set_fs(old_fs);
52949 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
52950 }
52951@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
52952 }
52953
52954 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
52955- unsigned long mm_flags)
52956+ struct coredump_params *cprm)
52957 {
52958 struct vm_area_struct *vma;
52959 size_t size = 0;
52960
52961 for (vma = first_vma(current, gate_vma); vma != NULL;
52962 vma = next_vma(vma, gate_vma))
52963- size += vma_dump_size(vma, mm_flags);
52964+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52965 return size;
52966 }
52967
52968@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52969
52970 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
52971
52972- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
52973+ offset += elf_core_vma_data_size(gate_vma, cprm);
52974 offset += elf_core_extra_data_size();
52975 e_shoff = offset;
52976
52977@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
52978 offset = dataoff;
52979
52980 size += sizeof(*elf);
52981+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52982 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
52983 goto end_coredump;
52984
52985 size += sizeof(*phdr4note);
52986+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52987 if (size > cprm->limit
52988 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
52989 goto end_coredump;
52990@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52991 phdr.p_offset = offset;
52992 phdr.p_vaddr = vma->vm_start;
52993 phdr.p_paddr = 0;
52994- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
52995+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52996 phdr.p_memsz = vma->vm_end - vma->vm_start;
52997 offset += phdr.p_filesz;
52998 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
52999@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53000 phdr.p_align = ELF_EXEC_PAGESIZE;
53001
53002 size += sizeof(phdr);
53003+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53004 if (size > cprm->limit
53005 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53006 goto end_coredump;
53007@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53008 unsigned long addr;
53009 unsigned long end;
53010
53011- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53012+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53013
53014 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53015 struct page *page;
53016@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53017 page = get_dump_page(addr);
53018 if (page) {
53019 void *kaddr = kmap(page);
53020+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53021 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53022 !dump_write(cprm->file, kaddr,
53023 PAGE_SIZE);
53024@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53025
53026 if (e_phnum == PN_XNUM) {
53027 size += sizeof(*shdr4extnum);
53028+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53029 if (size > cprm->limit
53030 || !dump_write(cprm->file, shdr4extnum,
53031 sizeof(*shdr4extnum)))
53032@@ -2235,6 +2697,167 @@ out:
53033
53034 #endif /* CONFIG_ELF_CORE */
53035
53036+#ifdef CONFIG_PAX_MPROTECT
53037+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53038+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53039+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53040+ *
53041+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53042+ * basis because we want to allow the common case and not the special ones.
53043+ */
53044+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53045+{
53046+ struct elfhdr elf_h;
53047+ struct elf_phdr elf_p;
53048+ unsigned long i;
53049+ unsigned long oldflags;
53050+ bool is_textrel_rw, is_textrel_rx, is_relro;
53051+
53052+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53053+ return;
53054+
53055+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53056+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53057+
53058+#ifdef CONFIG_PAX_ELFRELOCS
53059+ /* possible TEXTREL */
53060+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53061+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53062+#else
53063+ is_textrel_rw = false;
53064+ is_textrel_rx = false;
53065+#endif
53066+
53067+ /* possible RELRO */
53068+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53069+
53070+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53071+ return;
53072+
53073+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53074+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53075+
53076+#ifdef CONFIG_PAX_ETEXECRELOCS
53077+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53078+#else
53079+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53080+#endif
53081+
53082+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53083+ !elf_check_arch(&elf_h) ||
53084+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53085+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53086+ return;
53087+
53088+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53089+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53090+ return;
53091+ switch (elf_p.p_type) {
53092+ case PT_DYNAMIC:
53093+ if (!is_textrel_rw && !is_textrel_rx)
53094+ continue;
53095+ i = 0UL;
53096+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53097+ elf_dyn dyn;
53098+
53099+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53100+ break;
53101+ if (dyn.d_tag == DT_NULL)
53102+ break;
53103+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53104+ gr_log_textrel(vma);
53105+ if (is_textrel_rw)
53106+ vma->vm_flags |= VM_MAYWRITE;
53107+ else
53108+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53109+ vma->vm_flags &= ~VM_MAYWRITE;
53110+ break;
53111+ }
53112+ i++;
53113+ }
53114+ is_textrel_rw = false;
53115+ is_textrel_rx = false;
53116+ continue;
53117+
53118+ case PT_GNU_RELRO:
53119+ if (!is_relro)
53120+ continue;
53121+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53122+ vma->vm_flags &= ~VM_MAYWRITE;
53123+ is_relro = false;
53124+ continue;
53125+
53126+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53127+ case PT_PAX_FLAGS: {
53128+ const char *msg_mprotect = "", *msg_emutramp = "";
53129+ char *buffer_lib, *buffer_exe;
53130+
53131+ if (elf_p.p_flags & PF_NOMPROTECT)
53132+ msg_mprotect = "MPROTECT disabled";
53133+
53134+#ifdef CONFIG_PAX_EMUTRAMP
53135+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53136+ msg_emutramp = "EMUTRAMP enabled";
53137+#endif
53138+
53139+ if (!msg_mprotect[0] && !msg_emutramp[0])
53140+ continue;
53141+
53142+ if (!printk_ratelimit())
53143+ continue;
53144+
53145+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53146+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53147+ if (buffer_lib && buffer_exe) {
53148+ char *path_lib, *path_exe;
53149+
53150+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53151+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53152+
53153+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53154+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53155+
53156+ }
53157+ free_page((unsigned long)buffer_exe);
53158+ free_page((unsigned long)buffer_lib);
53159+ continue;
53160+ }
53161+#endif
53162+
53163+ }
53164+ }
53165+}
53166+#endif
53167+
53168+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53169+
53170+extern int grsec_enable_log_rwxmaps;
53171+
53172+static void elf_handle_mmap(struct file *file)
53173+{
53174+ struct elfhdr elf_h;
53175+ struct elf_phdr elf_p;
53176+ unsigned long i;
53177+
53178+ if (!grsec_enable_log_rwxmaps)
53179+ return;
53180+
53181+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53182+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53183+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53184+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53185+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53186+ return;
53187+
53188+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53189+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53190+ return;
53191+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53192+ gr_log_ptgnustack(file);
53193+ }
53194+}
53195+#endif
53196+
53197 static int __init init_elf_binfmt(void)
53198 {
53199 register_binfmt(&elf_format);
53200diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53201index d50bbe5..af3b649 100644
53202--- a/fs/binfmt_flat.c
53203+++ b/fs/binfmt_flat.c
53204@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53205 realdatastart = (unsigned long) -ENOMEM;
53206 printk("Unable to allocate RAM for process data, errno %d\n",
53207 (int)-realdatastart);
53208+ down_write(&current->mm->mmap_sem);
53209 vm_munmap(textpos, text_len);
53210+ up_write(&current->mm->mmap_sem);
53211 ret = realdatastart;
53212 goto err;
53213 }
53214@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53215 }
53216 if (IS_ERR_VALUE(result)) {
53217 printk("Unable to read data+bss, errno %d\n", (int)-result);
53218+ down_write(&current->mm->mmap_sem);
53219 vm_munmap(textpos, text_len);
53220 vm_munmap(realdatastart, len);
53221+ up_write(&current->mm->mmap_sem);
53222 ret = result;
53223 goto err;
53224 }
53225@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53226 }
53227 if (IS_ERR_VALUE(result)) {
53228 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53229+ down_write(&current->mm->mmap_sem);
53230 vm_munmap(textpos, text_len + data_len + extra +
53231 MAX_SHARED_LIBS * sizeof(unsigned long));
53232+ up_write(&current->mm->mmap_sem);
53233 ret = result;
53234 goto err;
53235 }
53236diff --git a/fs/bio.c b/fs/bio.c
53237index 5e7507d..418c639 100644
53238--- a/fs/bio.c
53239+++ b/fs/bio.c
53240@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53241 /*
53242 * Overflow, abort
53243 */
53244- if (end < start)
53245+ if (end < start || end - start > INT_MAX - nr_pages)
53246 return ERR_PTR(-EINVAL);
53247
53248 nr_pages += end - start;
53249@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53250 /*
53251 * Overflow, abort
53252 */
53253- if (end < start)
53254+ if (end < start || end - start > INT_MAX - nr_pages)
53255 return ERR_PTR(-EINVAL);
53256
53257 nr_pages += end - start;
53258@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53259 const int read = bio_data_dir(bio) == READ;
53260 struct bio_map_data *bmd = bio->bi_private;
53261 int i;
53262- char *p = bmd->sgvecs[0].iov_base;
53263+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53264
53265 bio_for_each_segment_all(bvec, bio, i) {
53266 char *addr = page_address(bvec->bv_page);
53267diff --git a/fs/block_dev.c b/fs/block_dev.c
53268index c7bda5c..2121e94 100644
53269--- a/fs/block_dev.c
53270+++ b/fs/block_dev.c
53271@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53272 else if (bdev->bd_contains == bdev)
53273 return true; /* is a whole device which isn't held */
53274
53275- else if (whole->bd_holder == bd_may_claim)
53276+ else if (whole->bd_holder == (void *)bd_may_claim)
53277 return true; /* is a partition of a device that is being partitioned */
53278 else if (whole->bd_holder != NULL)
53279 return false; /* is a partition of a held device */
53280diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53281index ed50460..fe84385 100644
53282--- a/fs/btrfs/ctree.c
53283+++ b/fs/btrfs/ctree.c
53284@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53285 free_extent_buffer(buf);
53286 add_root_to_dirty_list(root);
53287 } else {
53288- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53289- parent_start = parent->start;
53290- else
53291+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53292+ if (parent)
53293+ parent_start = parent->start;
53294+ else
53295+ parent_start = 0;
53296+ } else
53297 parent_start = 0;
53298
53299 WARN_ON(trans->transid != btrfs_header_generation(parent));
53300diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53301index 3755109..e3d457f 100644
53302--- a/fs/btrfs/delayed-inode.c
53303+++ b/fs/btrfs/delayed-inode.c
53304@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53305
53306 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53307 {
53308- int seq = atomic_inc_return(&delayed_root->items_seq);
53309+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53310 if ((atomic_dec_return(&delayed_root->items) <
53311 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53312 waitqueue_active(&delayed_root->wait))
53313@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53314 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53315 int seq, int count)
53316 {
53317- int val = atomic_read(&delayed_root->items_seq);
53318+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53319
53320 if (val < seq || val >= seq + count)
53321 return 1;
53322@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53323 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53324 return;
53325
53326- seq = atomic_read(&delayed_root->items_seq);
53327+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53328
53329 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53330 int ret;
53331diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53332index a4b38f9..f86a509 100644
53333--- a/fs/btrfs/delayed-inode.h
53334+++ b/fs/btrfs/delayed-inode.h
53335@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53336 */
53337 struct list_head prepare_list;
53338 atomic_t items; /* for delayed items */
53339- atomic_t items_seq; /* for delayed items */
53340+ atomic_unchecked_t items_seq; /* for delayed items */
53341 int nodes; /* for delayed nodes */
53342 wait_queue_head_t wait;
53343 };
53344@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53345 struct btrfs_delayed_root *delayed_root)
53346 {
53347 atomic_set(&delayed_root->items, 0);
53348- atomic_set(&delayed_root->items_seq, 0);
53349+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53350 delayed_root->nodes = 0;
53351 spin_lock_init(&delayed_root->lock);
53352 init_waitqueue_head(&delayed_root->wait);
53353diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53354index 9877a2a..7ebf9ab 100644
53355--- a/fs/btrfs/ioctl.c
53356+++ b/fs/btrfs/ioctl.c
53357@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53358 for (i = 0; i < num_types; i++) {
53359 struct btrfs_space_info *tmp;
53360
53361+ /* Don't copy in more than we allocated */
53362 if (!slot_count)
53363 break;
53364
53365+ slot_count--;
53366+
53367 info = NULL;
53368 rcu_read_lock();
53369 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53370@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53371 memcpy(dest, &space, sizeof(space));
53372 dest++;
53373 space_args.total_spaces++;
53374- slot_count--;
53375 }
53376- if (!slot_count)
53377- break;
53378 }
53379 up_read(&info->groups_sem);
53380 }
53381diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53382index 8eb6191..eda91e2 100644
53383--- a/fs/btrfs/super.c
53384+++ b/fs/btrfs/super.c
53385@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53386 function, line, errstr);
53387 return;
53388 }
53389- ACCESS_ONCE(trans->transaction->aborted) = errno;
53390+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53391 /* Wake up anybody who may be waiting on this transaction */
53392 wake_up(&root->fs_info->transaction_wait);
53393 wake_up(&root->fs_info->transaction_blocked_wait);
53394diff --git a/fs/buffer.c b/fs/buffer.c
53395index 4d74335..7bd000a 100644
53396--- a/fs/buffer.c
53397+++ b/fs/buffer.c
53398@@ -1005,9 +1005,19 @@ grow_dev_page(struct block_device *bdev, sector_t block,
53399 struct buffer_head *bh;
53400 sector_t end_block;
53401 int ret = 0; /* Will call free_more_memory() */
53402+ gfp_t gfp_mask;
53403
53404- page = find_or_create_page(inode->i_mapping, index,
53405- (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS)|__GFP_MOVABLE);
53406+ gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS;
53407+ gfp_mask |= __GFP_MOVABLE;
53408+ /*
53409+ * XXX: __getblk_slow() can not really deal with failure and
53410+ * will endlessly loop on improvised global reclaim. Prefer
53411+ * looping in the allocator rather than here, at least that
53412+ * code knows what it's doing.
53413+ */
53414+ gfp_mask |= __GFP_NOFAIL;
53415+
53416+ page = find_or_create_page(inode->i_mapping, index, gfp_mask);
53417 if (!page)
53418 return ret;
53419
53420@@ -3416,7 +3426,7 @@ void __init buffer_init(void)
53421 bh_cachep = kmem_cache_create("buffer_head",
53422 sizeof(struct buffer_head), 0,
53423 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53424- SLAB_MEM_SPREAD),
53425+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53426 NULL);
53427
53428 /*
53429diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53430index 622f469..e8d2d55 100644
53431--- a/fs/cachefiles/bind.c
53432+++ b/fs/cachefiles/bind.c
53433@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53434 args);
53435
53436 /* start by checking things over */
53437- ASSERT(cache->fstop_percent >= 0 &&
53438- cache->fstop_percent < cache->fcull_percent &&
53439+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53440 cache->fcull_percent < cache->frun_percent &&
53441 cache->frun_percent < 100);
53442
53443- ASSERT(cache->bstop_percent >= 0 &&
53444- cache->bstop_percent < cache->bcull_percent &&
53445+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53446 cache->bcull_percent < cache->brun_percent &&
53447 cache->brun_percent < 100);
53448
53449diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53450index 0a1467b..6a53245 100644
53451--- a/fs/cachefiles/daemon.c
53452+++ b/fs/cachefiles/daemon.c
53453@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53454 if (n > buflen)
53455 return -EMSGSIZE;
53456
53457- if (copy_to_user(_buffer, buffer, n) != 0)
53458+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53459 return -EFAULT;
53460
53461 return n;
53462@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53463 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53464 return -EIO;
53465
53466- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53467+ if (datalen > PAGE_SIZE - 1)
53468 return -EOPNOTSUPP;
53469
53470 /* drag the command string into the kernel so we can parse it */
53471@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53472 if (args[0] != '%' || args[1] != '\0')
53473 return -EINVAL;
53474
53475- if (fstop < 0 || fstop >= cache->fcull_percent)
53476+ if (fstop >= cache->fcull_percent)
53477 return cachefiles_daemon_range_error(cache, args);
53478
53479 cache->fstop_percent = fstop;
53480@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53481 if (args[0] != '%' || args[1] != '\0')
53482 return -EINVAL;
53483
53484- if (bstop < 0 || bstop >= cache->bcull_percent)
53485+ if (bstop >= cache->bcull_percent)
53486 return cachefiles_daemon_range_error(cache, args);
53487
53488 cache->bstop_percent = bstop;
53489diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53490index 4938251..7e01445 100644
53491--- a/fs/cachefiles/internal.h
53492+++ b/fs/cachefiles/internal.h
53493@@ -59,7 +59,7 @@ struct cachefiles_cache {
53494 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53495 struct rb_root active_nodes; /* active nodes (can't be culled) */
53496 rwlock_t active_lock; /* lock for active_nodes */
53497- atomic_t gravecounter; /* graveyard uniquifier */
53498+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53499 unsigned frun_percent; /* when to stop culling (% files) */
53500 unsigned fcull_percent; /* when to start culling (% files) */
53501 unsigned fstop_percent; /* when to stop allocating (% files) */
53502@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53503 * proc.c
53504 */
53505 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53506-extern atomic_t cachefiles_lookup_histogram[HZ];
53507-extern atomic_t cachefiles_mkdir_histogram[HZ];
53508-extern atomic_t cachefiles_create_histogram[HZ];
53509+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53510+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53511+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53512
53513 extern int __init cachefiles_proc_init(void);
53514 extern void cachefiles_proc_cleanup(void);
53515 static inline
53516-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53517+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53518 {
53519 unsigned long jif = jiffies - start_jif;
53520 if (jif >= HZ)
53521 jif = HZ - 1;
53522- atomic_inc(&histogram[jif]);
53523+ atomic_inc_unchecked(&histogram[jif]);
53524 }
53525
53526 #else
53527diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53528index 25badd1..d70d918 100644
53529--- a/fs/cachefiles/namei.c
53530+++ b/fs/cachefiles/namei.c
53531@@ -317,7 +317,7 @@ try_again:
53532 /* first step is to make up a grave dentry in the graveyard */
53533 sprintf(nbuffer, "%08x%08x",
53534 (uint32_t) get_seconds(),
53535- (uint32_t) atomic_inc_return(&cache->gravecounter));
53536+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53537
53538 /* do the multiway lock magic */
53539 trap = lock_rename(cache->graveyard, dir);
53540diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53541index eccd339..4c1d995 100644
53542--- a/fs/cachefiles/proc.c
53543+++ b/fs/cachefiles/proc.c
53544@@ -14,9 +14,9 @@
53545 #include <linux/seq_file.h>
53546 #include "internal.h"
53547
53548-atomic_t cachefiles_lookup_histogram[HZ];
53549-atomic_t cachefiles_mkdir_histogram[HZ];
53550-atomic_t cachefiles_create_histogram[HZ];
53551+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53552+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53553+atomic_unchecked_t cachefiles_create_histogram[HZ];
53554
53555 /*
53556 * display the latency histogram
53557@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53558 return 0;
53559 default:
53560 index = (unsigned long) v - 3;
53561- x = atomic_read(&cachefiles_lookup_histogram[index]);
53562- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53563- z = atomic_read(&cachefiles_create_histogram[index]);
53564+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53565+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53566+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53567 if (x == 0 && y == 0 && z == 0)
53568 return 0;
53569
53570diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53571index ebaff36..7e3ea26 100644
53572--- a/fs/cachefiles/rdwr.c
53573+++ b/fs/cachefiles/rdwr.c
53574@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53575 old_fs = get_fs();
53576 set_fs(KERNEL_DS);
53577 ret = file->f_op->write(
53578- file, (const void __user *) data, len, &pos);
53579+ file, (const void __force_user *) data, len, &pos);
53580 set_fs(old_fs);
53581 kunmap(page);
53582 file_end_write(file);
53583diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53584index a40ceda..f43d17c 100644
53585--- a/fs/ceph/dir.c
53586+++ b/fs/ceph/dir.c
53587@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53588 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53589 struct ceph_mds_client *mdsc = fsc->mdsc;
53590 unsigned frag = fpos_frag(ctx->pos);
53591- int off = fpos_off(ctx->pos);
53592+ unsigned int off = fpos_off(ctx->pos);
53593 int err;
53594 u32 ftype;
53595 struct ceph_mds_reply_info_parsed *rinfo;
53596diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53597index 6627b26..634ec4b 100644
53598--- a/fs/ceph/super.c
53599+++ b/fs/ceph/super.c
53600@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53601 /*
53602 * construct our own bdi so we can control readahead, etc.
53603 */
53604-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53605+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53606
53607 static int ceph_register_bdi(struct super_block *sb,
53608 struct ceph_fs_client *fsc)
53609@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53610 default_backing_dev_info.ra_pages;
53611
53612 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53613- atomic_long_inc_return(&bdi_seq));
53614+ atomic_long_inc_return_unchecked(&bdi_seq));
53615 if (!err)
53616 sb->s_bdi = &fsc->backing_dev_info;
53617 return err;
53618diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53619index f3ac415..3d2420c 100644
53620--- a/fs/cifs/cifs_debug.c
53621+++ b/fs/cifs/cifs_debug.c
53622@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53623
53624 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53625 #ifdef CONFIG_CIFS_STATS2
53626- atomic_set(&totBufAllocCount, 0);
53627- atomic_set(&totSmBufAllocCount, 0);
53628+ atomic_set_unchecked(&totBufAllocCount, 0);
53629+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53630 #endif /* CONFIG_CIFS_STATS2 */
53631 spin_lock(&cifs_tcp_ses_lock);
53632 list_for_each(tmp1, &cifs_tcp_ses_list) {
53633@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53634 tcon = list_entry(tmp3,
53635 struct cifs_tcon,
53636 tcon_list);
53637- atomic_set(&tcon->num_smbs_sent, 0);
53638+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53639 if (server->ops->clear_stats)
53640 server->ops->clear_stats(tcon);
53641 }
53642@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53643 smBufAllocCount.counter, cifs_min_small);
53644 #ifdef CONFIG_CIFS_STATS2
53645 seq_printf(m, "Total Large %d Small %d Allocations\n",
53646- atomic_read(&totBufAllocCount),
53647- atomic_read(&totSmBufAllocCount));
53648+ atomic_read_unchecked(&totBufAllocCount),
53649+ atomic_read_unchecked(&totSmBufAllocCount));
53650 #endif /* CONFIG_CIFS_STATS2 */
53651
53652 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53653@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53654 if (tcon->need_reconnect)
53655 seq_puts(m, "\tDISCONNECTED ");
53656 seq_printf(m, "\nSMBs: %d",
53657- atomic_read(&tcon->num_smbs_sent));
53658+ atomic_read_unchecked(&tcon->num_smbs_sent));
53659 if (server->ops->print_stats)
53660 server->ops->print_stats(m, tcon);
53661 }
53662diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53663index 85ea98d..1eee040 100644
53664--- a/fs/cifs/cifsfs.c
53665+++ b/fs/cifs/cifsfs.c
53666@@ -120,14 +120,16 @@ cifs_read_super(struct super_block *sb)
53667 {
53668 struct inode *inode;
53669 struct cifs_sb_info *cifs_sb;
53670+ struct cifs_tcon *tcon;
53671 int rc = 0;
53672
53673 cifs_sb = CIFS_SB(sb);
53674+ tcon = cifs_sb_master_tcon(cifs_sb);
53675
53676 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
53677 sb->s_flags |= MS_POSIXACL;
53678
53679- if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
53680+ if (tcon->ses->capabilities & tcon->ses->server->vals->cap_large_files)
53681 sb->s_maxbytes = MAX_LFS_FILESIZE;
53682 else
53683 sb->s_maxbytes = MAX_NON_LFS;
53684@@ -147,7 +149,7 @@ cifs_read_super(struct super_block *sb)
53685 goto out_no_root;
53686 }
53687
53688- if (cifs_sb_master_tcon(cifs_sb)->nocase)
53689+ if (tcon->nocase)
53690 sb->s_d_op = &cifs_ci_dentry_ops;
53691 else
53692 sb->s_d_op = &cifs_dentry_ops;
53693@@ -1037,7 +1039,7 @@ cifs_init_request_bufs(void)
53694 */
53695 cifs_req_cachep = kmem_cache_create("cifs_request",
53696 CIFSMaxBufSize + max_hdr_size, 0,
53697- SLAB_HWCACHE_ALIGN, NULL);
53698+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53699 if (cifs_req_cachep == NULL)
53700 return -ENOMEM;
53701
53702@@ -1064,7 +1066,7 @@ cifs_init_request_bufs(void)
53703 efficient to alloc 1 per page off the slab compared to 17K (5page)
53704 alloc of large cifs buffers even when page debugging is on */
53705 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53706- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53707+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53708 NULL);
53709 if (cifs_sm_req_cachep == NULL) {
53710 mempool_destroy(cifs_req_poolp);
53711@@ -1149,8 +1151,8 @@ init_cifs(void)
53712 atomic_set(&bufAllocCount, 0);
53713 atomic_set(&smBufAllocCount, 0);
53714 #ifdef CONFIG_CIFS_STATS2
53715- atomic_set(&totBufAllocCount, 0);
53716- atomic_set(&totSmBufAllocCount, 0);
53717+ atomic_set_unchecked(&totBufAllocCount, 0);
53718+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53719 #endif /* CONFIG_CIFS_STATS2 */
53720
53721 atomic_set(&midCount, 0);
53722diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53723index 52ca861..47f309c 100644
53724--- a/fs/cifs/cifsglob.h
53725+++ b/fs/cifs/cifsglob.h
53726@@ -756,35 +756,35 @@ struct cifs_tcon {
53727 __u16 Flags; /* optional support bits */
53728 enum statusEnum tidStatus;
53729 #ifdef CONFIG_CIFS_STATS
53730- atomic_t num_smbs_sent;
53731+ atomic_unchecked_t num_smbs_sent;
53732 union {
53733 struct {
53734- atomic_t num_writes;
53735- atomic_t num_reads;
53736- atomic_t num_flushes;
53737- atomic_t num_oplock_brks;
53738- atomic_t num_opens;
53739- atomic_t num_closes;
53740- atomic_t num_deletes;
53741- atomic_t num_mkdirs;
53742- atomic_t num_posixopens;
53743- atomic_t num_posixmkdirs;
53744- atomic_t num_rmdirs;
53745- atomic_t num_renames;
53746- atomic_t num_t2renames;
53747- atomic_t num_ffirst;
53748- atomic_t num_fnext;
53749- atomic_t num_fclose;
53750- atomic_t num_hardlinks;
53751- atomic_t num_symlinks;
53752- atomic_t num_locks;
53753- atomic_t num_acl_get;
53754- atomic_t num_acl_set;
53755+ atomic_unchecked_t num_writes;
53756+ atomic_unchecked_t num_reads;
53757+ atomic_unchecked_t num_flushes;
53758+ atomic_unchecked_t num_oplock_brks;
53759+ atomic_unchecked_t num_opens;
53760+ atomic_unchecked_t num_closes;
53761+ atomic_unchecked_t num_deletes;
53762+ atomic_unchecked_t num_mkdirs;
53763+ atomic_unchecked_t num_posixopens;
53764+ atomic_unchecked_t num_posixmkdirs;
53765+ atomic_unchecked_t num_rmdirs;
53766+ atomic_unchecked_t num_renames;
53767+ atomic_unchecked_t num_t2renames;
53768+ atomic_unchecked_t num_ffirst;
53769+ atomic_unchecked_t num_fnext;
53770+ atomic_unchecked_t num_fclose;
53771+ atomic_unchecked_t num_hardlinks;
53772+ atomic_unchecked_t num_symlinks;
53773+ atomic_unchecked_t num_locks;
53774+ atomic_unchecked_t num_acl_get;
53775+ atomic_unchecked_t num_acl_set;
53776 } cifs_stats;
53777 #ifdef CONFIG_CIFS_SMB2
53778 struct {
53779- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53780- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53781+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53782+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53783 } smb2_stats;
53784 #endif /* CONFIG_CIFS_SMB2 */
53785 } stats;
53786@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53787 }
53788
53789 #ifdef CONFIG_CIFS_STATS
53790-#define cifs_stats_inc atomic_inc
53791+#define cifs_stats_inc atomic_inc_unchecked
53792
53793 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53794 unsigned int bytes)
53795@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53796 /* Various Debug counters */
53797 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53798 #ifdef CONFIG_CIFS_STATS2
53799-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53800-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53801+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53802+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53803 #endif
53804 GLOBAL_EXTERN atomic_t smBufAllocCount;
53805 GLOBAL_EXTERN atomic_t midCount;
53806diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53807index 562044f..4af6a17 100644
53808--- a/fs/cifs/link.c
53809+++ b/fs/cifs/link.c
53810@@ -638,7 +638,7 @@ symlink_exit:
53811
53812 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53813 {
53814- char *p = nd_get_link(nd);
53815+ const char *p = nd_get_link(nd);
53816 if (!IS_ERR(p))
53817 kfree(p);
53818 }
53819diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53820index f7d4b22..1254377 100644
53821--- a/fs/cifs/misc.c
53822+++ b/fs/cifs/misc.c
53823@@ -169,7 +169,7 @@ cifs_buf_get(void)
53824 memset(ret_buf, 0, buf_size + 3);
53825 atomic_inc(&bufAllocCount);
53826 #ifdef CONFIG_CIFS_STATS2
53827- atomic_inc(&totBufAllocCount);
53828+ atomic_inc_unchecked(&totBufAllocCount);
53829 #endif /* CONFIG_CIFS_STATS2 */
53830 }
53831
53832@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53833 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53834 atomic_inc(&smBufAllocCount);
53835 #ifdef CONFIG_CIFS_STATS2
53836- atomic_inc(&totSmBufAllocCount);
53837+ atomic_inc_unchecked(&totSmBufAllocCount);
53838 #endif /* CONFIG_CIFS_STATS2 */
53839
53840 }
53841diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
53842index af847e1..651a527 100644
53843--- a/fs/cifs/netmisc.c
53844+++ b/fs/cifs/netmisc.c
53845@@ -780,7 +780,9 @@ static const struct {
53846 ERRDOS, ERRnoaccess, 0xc0000290}, {
53847 ERRDOS, ERRbadfunc, 0xc000029c}, {
53848 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
53849- ERRDOS, ERRinvlevel, 0x007c0001}, };
53850+ ERRDOS, ERRinvlevel, 0x007c0001}, {
53851+ 0, 0, 0 }
53852+};
53853
53854 /*****************************************************************************
53855 Print an error message from the status code
53856diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53857index 6094397..51e576f 100644
53858--- a/fs/cifs/smb1ops.c
53859+++ b/fs/cifs/smb1ops.c
53860@@ -590,27 +590,27 @@ static void
53861 cifs_clear_stats(struct cifs_tcon *tcon)
53862 {
53863 #ifdef CONFIG_CIFS_STATS
53864- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53865- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53866- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53867- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53868- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53869- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53870- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53871- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53872- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53873- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53874- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53875- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53876- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53877- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53878- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53879- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53880- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53881- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53882- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53883- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53884- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53885+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53886+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53887+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53888+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53889+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53890+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53891+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53892+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
53893+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
53894+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
53895+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
53896+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
53897+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
53898+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
53899+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
53900+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
53901+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
53902+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
53903+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
53904+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
53905+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
53906 #endif
53907 }
53908
53909@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53910 {
53911 #ifdef CONFIG_CIFS_STATS
53912 seq_printf(m, " Oplocks breaks: %d",
53913- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
53914+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
53915 seq_printf(m, "\nReads: %d Bytes: %llu",
53916- atomic_read(&tcon->stats.cifs_stats.num_reads),
53917+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
53918 (long long)(tcon->bytes_read));
53919 seq_printf(m, "\nWrites: %d Bytes: %llu",
53920- atomic_read(&tcon->stats.cifs_stats.num_writes),
53921+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
53922 (long long)(tcon->bytes_written));
53923 seq_printf(m, "\nFlushes: %d",
53924- atomic_read(&tcon->stats.cifs_stats.num_flushes));
53925+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
53926 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
53927- atomic_read(&tcon->stats.cifs_stats.num_locks),
53928- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
53929- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
53930+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
53931+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
53932+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
53933 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
53934- atomic_read(&tcon->stats.cifs_stats.num_opens),
53935- atomic_read(&tcon->stats.cifs_stats.num_closes),
53936- atomic_read(&tcon->stats.cifs_stats.num_deletes));
53937+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
53938+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
53939+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
53940 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
53941- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
53942- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
53943+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
53944+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
53945 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
53946- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
53947- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
53948+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
53949+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
53950 seq_printf(m, "\nRenames: %d T2 Renames %d",
53951- atomic_read(&tcon->stats.cifs_stats.num_renames),
53952- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
53953+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
53954+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
53955 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
53956- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
53957- atomic_read(&tcon->stats.cifs_stats.num_fnext),
53958- atomic_read(&tcon->stats.cifs_stats.num_fclose));
53959+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
53960+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
53961+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
53962 #endif
53963 }
53964
53965diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
53966index f259e6c..ca948ff 100644
53967--- a/fs/cifs/smb2ops.c
53968+++ b/fs/cifs/smb2ops.c
53969@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
53970 #ifdef CONFIG_CIFS_STATS
53971 int i;
53972 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
53973- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53974- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53975+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53976+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53977 }
53978 #endif
53979 }
53980@@ -310,65 +310,65 @@ static void
53981 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53982 {
53983 #ifdef CONFIG_CIFS_STATS
53984- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53985- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53986+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53987+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53988 seq_printf(m, "\nNegotiates: %d sent %d failed",
53989- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
53990- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
53991+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
53992+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
53993 seq_printf(m, "\nSessionSetups: %d sent %d failed",
53994- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
53995- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
53996+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
53997+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
53998 seq_printf(m, "\nLogoffs: %d sent %d failed",
53999- atomic_read(&sent[SMB2_LOGOFF_HE]),
54000- atomic_read(&failed[SMB2_LOGOFF_HE]));
54001+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54002+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54003 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54004- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54005- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54006+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54007+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54008 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54009- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54010- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54011+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54012+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54013 seq_printf(m, "\nCreates: %d sent %d failed",
54014- atomic_read(&sent[SMB2_CREATE_HE]),
54015- atomic_read(&failed[SMB2_CREATE_HE]));
54016+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54017+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54018 seq_printf(m, "\nCloses: %d sent %d failed",
54019- atomic_read(&sent[SMB2_CLOSE_HE]),
54020- atomic_read(&failed[SMB2_CLOSE_HE]));
54021+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54022+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54023 seq_printf(m, "\nFlushes: %d sent %d failed",
54024- atomic_read(&sent[SMB2_FLUSH_HE]),
54025- atomic_read(&failed[SMB2_FLUSH_HE]));
54026+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54027+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54028 seq_printf(m, "\nReads: %d sent %d failed",
54029- atomic_read(&sent[SMB2_READ_HE]),
54030- atomic_read(&failed[SMB2_READ_HE]));
54031+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54032+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54033 seq_printf(m, "\nWrites: %d sent %d failed",
54034- atomic_read(&sent[SMB2_WRITE_HE]),
54035- atomic_read(&failed[SMB2_WRITE_HE]));
54036+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54037+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54038 seq_printf(m, "\nLocks: %d sent %d failed",
54039- atomic_read(&sent[SMB2_LOCK_HE]),
54040- atomic_read(&failed[SMB2_LOCK_HE]));
54041+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54042+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54043 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54044- atomic_read(&sent[SMB2_IOCTL_HE]),
54045- atomic_read(&failed[SMB2_IOCTL_HE]));
54046+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54047+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54048 seq_printf(m, "\nCancels: %d sent %d failed",
54049- atomic_read(&sent[SMB2_CANCEL_HE]),
54050- atomic_read(&failed[SMB2_CANCEL_HE]));
54051+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54052+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54053 seq_printf(m, "\nEchos: %d sent %d failed",
54054- atomic_read(&sent[SMB2_ECHO_HE]),
54055- atomic_read(&failed[SMB2_ECHO_HE]));
54056+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54057+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54058 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54059- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54060- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54061+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54062+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54063 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54064- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54065- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54066+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54067+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54068 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54069- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54070- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54071+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54072+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54073 seq_printf(m, "\nSetInfos: %d sent %d failed",
54074- atomic_read(&sent[SMB2_SET_INFO_HE]),
54075- atomic_read(&failed[SMB2_SET_INFO_HE]));
54076+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54077+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54078 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54079- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54080- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54081+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54082+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54083 #endif
54084 }
54085
54086diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54087index abc9c28..3fdae28 100644
54088--- a/fs/cifs/smb2pdu.c
54089+++ b/fs/cifs/smb2pdu.c
54090@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54091 default:
54092 cifs_dbg(VFS, "info level %u isn't supported\n",
54093 srch_inf->info_level);
54094- rc = -EINVAL;
54095- goto qdir_exit;
54096+ return -EINVAL;
54097 }
54098
54099 req->FileIndex = cpu_to_le32(index);
54100diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54101index 1da168c..8bc7ff6 100644
54102--- a/fs/coda/cache.c
54103+++ b/fs/coda/cache.c
54104@@ -24,7 +24,7 @@
54105 #include "coda_linux.h"
54106 #include "coda_cache.h"
54107
54108-static atomic_t permission_epoch = ATOMIC_INIT(0);
54109+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54110
54111 /* replace or extend an acl cache hit */
54112 void coda_cache_enter(struct inode *inode, int mask)
54113@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54114 struct coda_inode_info *cii = ITOC(inode);
54115
54116 spin_lock(&cii->c_lock);
54117- cii->c_cached_epoch = atomic_read(&permission_epoch);
54118+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54119 if (!uid_eq(cii->c_uid, current_fsuid())) {
54120 cii->c_uid = current_fsuid();
54121 cii->c_cached_perm = mask;
54122@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54123 {
54124 struct coda_inode_info *cii = ITOC(inode);
54125 spin_lock(&cii->c_lock);
54126- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54127+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54128 spin_unlock(&cii->c_lock);
54129 }
54130
54131 /* remove all acl caches */
54132 void coda_cache_clear_all(struct super_block *sb)
54133 {
54134- atomic_inc(&permission_epoch);
54135+ atomic_inc_unchecked(&permission_epoch);
54136 }
54137
54138
54139@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54140 spin_lock(&cii->c_lock);
54141 hit = (mask & cii->c_cached_perm) == mask &&
54142 uid_eq(cii->c_uid, current_fsuid()) &&
54143- cii->c_cached_epoch == atomic_read(&permission_epoch);
54144+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54145 spin_unlock(&cii->c_lock);
54146
54147 return hit;
54148diff --git a/fs/compat.c b/fs/compat.c
54149index 6af20de..fec3fbb 100644
54150--- a/fs/compat.c
54151+++ b/fs/compat.c
54152@@ -54,7 +54,7 @@
54153 #include <asm/ioctls.h>
54154 #include "internal.h"
54155
54156-int compat_log = 1;
54157+int compat_log = 0;
54158
54159 int compat_printk(const char *fmt, ...)
54160 {
54161@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54162
54163 set_fs(KERNEL_DS);
54164 /* The __user pointer cast is valid because of the set_fs() */
54165- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54166+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54167 set_fs(oldfs);
54168 /* truncating is ok because it's a user address */
54169 if (!ret)
54170@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54171 goto out;
54172
54173 ret = -EINVAL;
54174- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54175+ if (nr_segs > UIO_MAXIOV)
54176 goto out;
54177 if (nr_segs > fast_segs) {
54178 ret = -ENOMEM;
54179@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54180 struct compat_readdir_callback {
54181 struct dir_context ctx;
54182 struct compat_old_linux_dirent __user *dirent;
54183+ struct file * file;
54184 int result;
54185 };
54186
54187@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54188 buf->result = -EOVERFLOW;
54189 return -EOVERFLOW;
54190 }
54191+
54192+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54193+ return 0;
54194+
54195 buf->result++;
54196 dirent = buf->dirent;
54197 if (!access_ok(VERIFY_WRITE, dirent,
54198@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54199 if (!f.file)
54200 return -EBADF;
54201
54202+ buf.file = f.file;
54203 error = iterate_dir(f.file, &buf.ctx);
54204 if (buf.result)
54205 error = buf.result;
54206@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54207 struct dir_context ctx;
54208 struct compat_linux_dirent __user *current_dir;
54209 struct compat_linux_dirent __user *previous;
54210+ struct file * file;
54211 int count;
54212 int error;
54213 };
54214@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54215 buf->error = -EOVERFLOW;
54216 return -EOVERFLOW;
54217 }
54218+
54219+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54220+ return 0;
54221+
54222 dirent = buf->previous;
54223 if (dirent) {
54224 if (__put_user(offset, &dirent->d_off))
54225@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54226 if (!f.file)
54227 return -EBADF;
54228
54229+ buf.file = f.file;
54230 error = iterate_dir(f.file, &buf.ctx);
54231 if (error >= 0)
54232 error = buf.error;
54233@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54234 struct dir_context ctx;
54235 struct linux_dirent64 __user *current_dir;
54236 struct linux_dirent64 __user *previous;
54237+ struct file * file;
54238 int count;
54239 int error;
54240 };
54241@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54242 buf->error = -EINVAL; /* only used if we fail.. */
54243 if (reclen > buf->count)
54244 return -EINVAL;
54245+
54246+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54247+ return 0;
54248+
54249 dirent = buf->previous;
54250
54251 if (dirent) {
54252@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54253 if (!f.file)
54254 return -EBADF;
54255
54256+ buf.file = f.file;
54257 error = iterate_dir(f.file, &buf.ctx);
54258 if (error >= 0)
54259 error = buf.error;
54260diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54261index a81147e..20bf2b5 100644
54262--- a/fs/compat_binfmt_elf.c
54263+++ b/fs/compat_binfmt_elf.c
54264@@ -30,11 +30,13 @@
54265 #undef elf_phdr
54266 #undef elf_shdr
54267 #undef elf_note
54268+#undef elf_dyn
54269 #undef elf_addr_t
54270 #define elfhdr elf32_hdr
54271 #define elf_phdr elf32_phdr
54272 #define elf_shdr elf32_shdr
54273 #define elf_note elf32_note
54274+#define elf_dyn Elf32_Dyn
54275 #define elf_addr_t Elf32_Addr
54276
54277 /*
54278diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54279index 5d19acf..9ab093b 100644
54280--- a/fs/compat_ioctl.c
54281+++ b/fs/compat_ioctl.c
54282@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54283 return -EFAULT;
54284 if (__get_user(udata, &ss32->iomem_base))
54285 return -EFAULT;
54286- ss.iomem_base = compat_ptr(udata);
54287+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54288 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54289 __get_user(ss.port_high, &ss32->port_high))
54290 return -EFAULT;
54291@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54292 for (i = 0; i < nmsgs; i++) {
54293 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54294 return -EFAULT;
54295- if (get_user(datap, &umsgs[i].buf) ||
54296- put_user(compat_ptr(datap), &tmsgs[i].buf))
54297+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54298+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54299 return -EFAULT;
54300 }
54301 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54302@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54303 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54304 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54305 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54306- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54307+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54308 return -EFAULT;
54309
54310 return ioctl_preallocate(file, p);
54311@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54312 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54313 {
54314 unsigned int a, b;
54315- a = *(unsigned int *)p;
54316- b = *(unsigned int *)q;
54317+ a = *(const unsigned int *)p;
54318+ b = *(const unsigned int *)q;
54319 if (a > b)
54320 return 1;
54321 if (a < b)
54322diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54323index 277bd1b..f312c9e 100644
54324--- a/fs/configfs/dir.c
54325+++ b/fs/configfs/dir.c
54326@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54327 }
54328 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54329 struct configfs_dirent *next;
54330- const char *name;
54331+ const unsigned char * name;
54332+ char d_name[sizeof(next->s_dentry->d_iname)];
54333 int len;
54334 struct inode *inode = NULL;
54335
54336@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54337 continue;
54338
54339 name = configfs_get_name(next);
54340- len = strlen(name);
54341+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54342+ len = next->s_dentry->d_name.len;
54343+ memcpy(d_name, name, len);
54344+ name = d_name;
54345+ } else
54346+ len = strlen(name);
54347
54348 /*
54349 * We'll have a dentry and an inode for
54350diff --git a/fs/coredump.c b/fs/coredump.c
54351index 72f816d..1ba8eff 100644
54352--- a/fs/coredump.c
54353+++ b/fs/coredump.c
54354@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54355 struct pipe_inode_info *pipe = file->private_data;
54356
54357 pipe_lock(pipe);
54358- pipe->readers++;
54359- pipe->writers--;
54360+ atomic_inc(&pipe->readers);
54361+ atomic_dec(&pipe->writers);
54362 wake_up_interruptible_sync(&pipe->wait);
54363 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54364 pipe_unlock(pipe);
54365@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54366 * We actually want wait_event_freezable() but then we need
54367 * to clear TIF_SIGPENDING and improve dump_interrupted().
54368 */
54369- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54370+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54371
54372 pipe_lock(pipe);
54373- pipe->readers--;
54374- pipe->writers++;
54375+ atomic_dec(&pipe->readers);
54376+ atomic_inc(&pipe->writers);
54377 pipe_unlock(pipe);
54378 }
54379
54380@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54381 struct files_struct *displaced;
54382 bool need_nonrelative = false;
54383 bool core_dumped = false;
54384- static atomic_t core_dump_count = ATOMIC_INIT(0);
54385+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54386+ long signr = siginfo->si_signo;
54387 struct coredump_params cprm = {
54388 .siginfo = siginfo,
54389 .regs = signal_pt_regs(),
54390@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54391 .mm_flags = mm->flags,
54392 };
54393
54394- audit_core_dumps(siginfo->si_signo);
54395+ audit_core_dumps(signr);
54396+
54397+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54398+ gr_handle_brute_attach(cprm.mm_flags);
54399
54400 binfmt = mm->binfmt;
54401 if (!binfmt || !binfmt->core_dump)
54402@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54403 need_nonrelative = true;
54404 }
54405
54406- retval = coredump_wait(siginfo->si_signo, &core_state);
54407+ retval = coredump_wait(signr, &core_state);
54408 if (retval < 0)
54409 goto fail_creds;
54410
54411@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54412 }
54413 cprm.limit = RLIM_INFINITY;
54414
54415- dump_count = atomic_inc_return(&core_dump_count);
54416+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54417 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54418 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54419 task_tgid_vnr(current), current->comm);
54420@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54421 } else {
54422 struct inode *inode;
54423
54424+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54425+
54426 if (cprm.limit < binfmt->min_coredump)
54427 goto fail_unlock;
54428
54429@@ -664,7 +670,7 @@ close_fail:
54430 filp_close(cprm.file, NULL);
54431 fail_dropcount:
54432 if (ispipe)
54433- atomic_dec(&core_dump_count);
54434+ atomic_dec_unchecked(&core_dump_count);
54435 fail_unlock:
54436 kfree(cn.corename);
54437 coredump_finish(mm, core_dumped);
54438@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54439 {
54440 return !dump_interrupted() &&
54441 access_ok(VERIFY_READ, addr, nr) &&
54442- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54443+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54444 }
54445 EXPORT_SYMBOL(dump_write);
54446
54447diff --git a/fs/dcache.c b/fs/dcache.c
54448index b949af8..5978926 100644
54449--- a/fs/dcache.c
54450+++ b/fs/dcache.c
54451@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54452 mempages -= reserve;
54453
54454 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54455- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54456+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54457+ SLAB_NO_SANITIZE, NULL);
54458
54459 dcache_init();
54460 inode_init();
54461diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54462index c7c83ff..bda9461 100644
54463--- a/fs/debugfs/inode.c
54464+++ b/fs/debugfs/inode.c
54465@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54466 */
54467 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54468 {
54469+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54470+ return __create_file(name, S_IFDIR | S_IRWXU,
54471+#else
54472 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54473+#endif
54474 parent, NULL, NULL);
54475 }
54476 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54477diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
54478index d107576..40db688 100644
54479--- a/fs/ecryptfs/crypto.c
54480+++ b/fs/ecryptfs/crypto.c
54481@@ -408,7 +408,7 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat,
54482 struct page *page)
54483 {
54484 return ecryptfs_lower_header_size(crypt_stat) +
54485- (page->index << PAGE_CACHE_SHIFT);
54486+ ((loff_t)page->index << PAGE_CACHE_SHIFT);
54487 }
54488
54489 /**
54490diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54491index 67e9b63..a9adb68 100644
54492--- a/fs/ecryptfs/inode.c
54493+++ b/fs/ecryptfs/inode.c
54494@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54495 old_fs = get_fs();
54496 set_fs(get_ds());
54497 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54498- (char __user *)lower_buf,
54499+ (char __force_user *)lower_buf,
54500 PATH_MAX);
54501 set_fs(old_fs);
54502 if (rc < 0)
54503@@ -706,7 +706,7 @@ out:
54504 static void
54505 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54506 {
54507- char *buf = nd_get_link(nd);
54508+ const char *buf = nd_get_link(nd);
54509 if (!IS_ERR(buf)) {
54510 /* Free the char* */
54511 kfree(buf);
54512diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
54513index 7d52806..4725a07 100644
54514--- a/fs/ecryptfs/keystore.c
54515+++ b/fs/ecryptfs/keystore.c
54516@@ -1149,7 +1149,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
54517 struct ecryptfs_msg_ctx *msg_ctx;
54518 struct ecryptfs_message *msg = NULL;
54519 char *auth_tok_sig;
54520- char *payload;
54521+ char *payload = NULL;
54522 size_t payload_len = 0;
54523 int rc;
54524
54525@@ -1203,6 +1203,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
54526 }
54527 out:
54528 kfree(msg);
54529+ kfree(payload);
54530 return rc;
54531 }
54532
54533diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54534index e4141f2..d8263e8 100644
54535--- a/fs/ecryptfs/miscdev.c
54536+++ b/fs/ecryptfs/miscdev.c
54537@@ -304,7 +304,7 @@ check_list:
54538 goto out_unlock_msg_ctx;
54539 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54540 if (msg_ctx->msg) {
54541- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54542+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54543 goto out_unlock_msg_ctx;
54544 i += packet_length_size;
54545 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54546diff --git a/fs/exec.c b/fs/exec.c
54547index fd774c7..1c6a7bf 100644
54548--- a/fs/exec.c
54549+++ b/fs/exec.c
54550@@ -55,8 +55,20 @@
54551 #include <linux/pipe_fs_i.h>
54552 #include <linux/oom.h>
54553 #include <linux/compat.h>
54554+#include <linux/random.h>
54555+#include <linux/seq_file.h>
54556+#include <linux/coredump.h>
54557+#include <linux/mman.h>
54558+
54559+#ifdef CONFIG_PAX_REFCOUNT
54560+#include <linux/kallsyms.h>
54561+#include <linux/kdebug.h>
54562+#endif
54563+
54564+#include <trace/events/fs.h>
54565
54566 #include <asm/uaccess.h>
54567+#include <asm/sections.h>
54568 #include <asm/mmu_context.h>
54569 #include <asm/tlb.h>
54570
54571@@ -66,17 +78,32 @@
54572
54573 #include <trace/events/sched.h>
54574
54575+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54576+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54577+{
54578+ 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");
54579+}
54580+#endif
54581+
54582+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54583+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54584+EXPORT_SYMBOL(pax_set_initial_flags_func);
54585+#endif
54586+
54587 int suid_dumpable = 0;
54588
54589 static LIST_HEAD(formats);
54590 static DEFINE_RWLOCK(binfmt_lock);
54591
54592+extern int gr_process_kernel_exec_ban(void);
54593+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54594+
54595 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54596 {
54597 BUG_ON(!fmt);
54598 write_lock(&binfmt_lock);
54599- insert ? list_add(&fmt->lh, &formats) :
54600- list_add_tail(&fmt->lh, &formats);
54601+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54602+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54603 write_unlock(&binfmt_lock);
54604 }
54605
54606@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54607 void unregister_binfmt(struct linux_binfmt * fmt)
54608 {
54609 write_lock(&binfmt_lock);
54610- list_del(&fmt->lh);
54611+ pax_list_del((struct list_head *)&fmt->lh);
54612 write_unlock(&binfmt_lock);
54613 }
54614
54615@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54616 int write)
54617 {
54618 struct page *page;
54619- int ret;
54620
54621-#ifdef CONFIG_STACK_GROWSUP
54622- if (write) {
54623- ret = expand_downwards(bprm->vma, pos);
54624- if (ret < 0)
54625- return NULL;
54626- }
54627-#endif
54628- ret = get_user_pages(current, bprm->mm, pos,
54629- 1, write, 1, &page, NULL);
54630- if (ret <= 0)
54631+ if (0 > expand_downwards(bprm->vma, pos))
54632+ return NULL;
54633+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54634 return NULL;
54635
54636 if (write) {
54637@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54638 if (size <= ARG_MAX)
54639 return page;
54640
54641+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54642+ // only allow 512KB for argv+env on suid/sgid binaries
54643+ // to prevent easy ASLR exhaustion
54644+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54645+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54646+ (size > (512 * 1024))) {
54647+ put_page(page);
54648+ return NULL;
54649+ }
54650+#endif
54651+
54652 /*
54653 * Limit to 1/4-th the stack size for the argv+env strings.
54654 * This ensures that:
54655@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54656 vma->vm_end = STACK_TOP_MAX;
54657 vma->vm_start = vma->vm_end - PAGE_SIZE;
54658 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54659+
54660+#ifdef CONFIG_PAX_SEGMEXEC
54661+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54662+#endif
54663+
54664 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54665 INIT_LIST_HEAD(&vma->anon_vma_chain);
54666
54667@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54668 mm->stack_vm = mm->total_vm = 1;
54669 up_write(&mm->mmap_sem);
54670 bprm->p = vma->vm_end - sizeof(void *);
54671+
54672+#ifdef CONFIG_PAX_RANDUSTACK
54673+ if (randomize_va_space)
54674+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54675+#endif
54676+
54677 return 0;
54678 err:
54679 up_write(&mm->mmap_sem);
54680@@ -397,7 +438,7 @@ struct user_arg_ptr {
54681 } ptr;
54682 };
54683
54684-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54685+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54686 {
54687 const char __user *native;
54688
54689@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54690 compat_uptr_t compat;
54691
54692 if (get_user(compat, argv.ptr.compat + nr))
54693- return ERR_PTR(-EFAULT);
54694+ return (const char __force_user *)ERR_PTR(-EFAULT);
54695
54696 return compat_ptr(compat);
54697 }
54698 #endif
54699
54700 if (get_user(native, argv.ptr.native + nr))
54701- return ERR_PTR(-EFAULT);
54702+ return (const char __force_user *)ERR_PTR(-EFAULT);
54703
54704 return native;
54705 }
54706@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54707 if (!p)
54708 break;
54709
54710- if (IS_ERR(p))
54711+ if (IS_ERR((const char __force_kernel *)p))
54712 return -EFAULT;
54713
54714 if (i >= max)
54715@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54716
54717 ret = -EFAULT;
54718 str = get_user_arg_ptr(argv, argc);
54719- if (IS_ERR(str))
54720+ if (IS_ERR((const char __force_kernel *)str))
54721 goto out;
54722
54723 len = strnlen_user(str, MAX_ARG_STRLEN);
54724@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54725 int r;
54726 mm_segment_t oldfs = get_fs();
54727 struct user_arg_ptr argv = {
54728- .ptr.native = (const char __user *const __user *)__argv,
54729+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54730 };
54731
54732 set_fs(KERNEL_DS);
54733@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54734 unsigned long new_end = old_end - shift;
54735 struct mmu_gather tlb;
54736
54737- BUG_ON(new_start > new_end);
54738+ if (new_start >= new_end || new_start < mmap_min_addr)
54739+ return -ENOMEM;
54740
54741 /*
54742 * ensure there are no vmas between where we want to go
54743@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54744 if (vma != find_vma(mm, new_start))
54745 return -EFAULT;
54746
54747+#ifdef CONFIG_PAX_SEGMEXEC
54748+ BUG_ON(pax_find_mirror_vma(vma));
54749+#endif
54750+
54751 /*
54752 * cover the whole range: [new_start, old_end)
54753 */
54754@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54755 stack_top = arch_align_stack(stack_top);
54756 stack_top = PAGE_ALIGN(stack_top);
54757
54758- if (unlikely(stack_top < mmap_min_addr) ||
54759- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54760- return -ENOMEM;
54761-
54762 stack_shift = vma->vm_end - stack_top;
54763
54764 bprm->p -= stack_shift;
54765@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54766 bprm->exec -= stack_shift;
54767
54768 down_write(&mm->mmap_sem);
54769+
54770+ /* Move stack pages down in memory. */
54771+ if (stack_shift) {
54772+ ret = shift_arg_pages(vma, stack_shift);
54773+ if (ret)
54774+ goto out_unlock;
54775+ }
54776+
54777 vm_flags = VM_STACK_FLAGS;
54778
54779+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54780+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54781+ vm_flags &= ~VM_EXEC;
54782+
54783+#ifdef CONFIG_PAX_MPROTECT
54784+ if (mm->pax_flags & MF_PAX_MPROTECT)
54785+ vm_flags &= ~VM_MAYEXEC;
54786+#endif
54787+
54788+ }
54789+#endif
54790+
54791 /*
54792 * Adjust stack execute permissions; explicitly enable for
54793 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54794@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54795 goto out_unlock;
54796 BUG_ON(prev != vma);
54797
54798- /* Move stack pages down in memory. */
54799- if (stack_shift) {
54800- ret = shift_arg_pages(vma, stack_shift);
54801- if (ret)
54802- goto out_unlock;
54803- }
54804-
54805 /* mprotect_fixup is overkill to remove the temporary stack flags */
54806 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54807
54808@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54809 #endif
54810 current->mm->start_stack = bprm->p;
54811 ret = expand_stack(vma, stack_base);
54812+
54813+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54814+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54815+ unsigned long size;
54816+ vm_flags_t vm_flags;
54817+
54818+ size = STACK_TOP - vma->vm_end;
54819+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54820+
54821+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54822+
54823+#ifdef CONFIG_X86
54824+ if (!ret) {
54825+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54826+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54827+ }
54828+#endif
54829+
54830+ }
54831+#endif
54832+
54833 if (ret)
54834 ret = -EFAULT;
54835
54836@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54837
54838 fsnotify_open(file);
54839
54840+ trace_open_exec(name);
54841+
54842 err = deny_write_access(file);
54843 if (err)
54844 goto exit;
54845@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54846 old_fs = get_fs();
54847 set_fs(get_ds());
54848 /* The cast to a user pointer is valid due to the set_fs() */
54849- result = vfs_read(file, (void __user *)addr, count, &pos);
54850+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54851 set_fs(old_fs);
54852 return result;
54853 }
54854@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54855 }
54856 rcu_read_unlock();
54857
54858- if (p->fs->users > n_fs) {
54859+ if (atomic_read(&p->fs->users) > n_fs) {
54860 bprm->unsafe |= LSM_UNSAFE_SHARE;
54861 } else {
54862 res = -EAGAIN;
54863@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54864
54865 EXPORT_SYMBOL(search_binary_handler);
54866
54867+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54868+static DEFINE_PER_CPU(u64, exec_counter);
54869+static int __init init_exec_counters(void)
54870+{
54871+ unsigned int cpu;
54872+
54873+ for_each_possible_cpu(cpu) {
54874+ per_cpu(exec_counter, cpu) = (u64)cpu;
54875+ }
54876+
54877+ return 0;
54878+}
54879+early_initcall(init_exec_counters);
54880+static inline void increment_exec_counter(void)
54881+{
54882+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54883+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54884+}
54885+#else
54886+static inline void increment_exec_counter(void) {}
54887+#endif
54888+
54889+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54890+ struct user_arg_ptr argv);
54891+
54892 /*
54893 * sys_execve() executes a new program.
54894 */
54895@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54896 struct user_arg_ptr argv,
54897 struct user_arg_ptr envp)
54898 {
54899+#ifdef CONFIG_GRKERNSEC
54900+ struct file *old_exec_file;
54901+ struct acl_subject_label *old_acl;
54902+ struct rlimit old_rlim[RLIM_NLIMITS];
54903+#endif
54904 struct linux_binprm *bprm;
54905 struct file *file;
54906 struct files_struct *displaced;
54907 bool clear_in_exec;
54908 int retval;
54909
54910+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54911+
54912 /*
54913 * We move the actual failure in case of RLIMIT_NPROC excess from
54914 * set*uid() to execve() because too many poorly written programs
54915@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54916 if (IS_ERR(file))
54917 goto out_unmark;
54918
54919+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54920+ retval = -EPERM;
54921+ goto out_file;
54922+ }
54923+
54924 sched_exec();
54925
54926 bprm->file = file;
54927 bprm->filename = filename;
54928 bprm->interp = filename;
54929
54930+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
54931+ retval = -EACCES;
54932+ goto out_file;
54933+ }
54934+
54935 retval = bprm_mm_init(bprm);
54936 if (retval)
54937 goto out_file;
54938@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
54939 if (retval < 0)
54940 goto out;
54941
54942+#ifdef CONFIG_GRKERNSEC
54943+ old_acl = current->acl;
54944+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
54945+ old_exec_file = current->exec_file;
54946+ get_file(file);
54947+ current->exec_file = file;
54948+#endif
54949+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54950+ /* limit suid stack to 8MB
54951+ * we saved the old limits above and will restore them if this exec fails
54952+ */
54953+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
54954+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
54955+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
54956+#endif
54957+
54958+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
54959+ retval = -EPERM;
54960+ goto out_fail;
54961+ }
54962+
54963+ if (!gr_tpe_allow(file)) {
54964+ retval = -EACCES;
54965+ goto out_fail;
54966+ }
54967+
54968+ if (gr_check_crash_exec(file)) {
54969+ retval = -EACCES;
54970+ goto out_fail;
54971+ }
54972+
54973+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
54974+ bprm->unsafe);
54975+ if (retval < 0)
54976+ goto out_fail;
54977+
54978 retval = copy_strings_kernel(1, &bprm->filename, bprm);
54979 if (retval < 0)
54980- goto out;
54981+ goto out_fail;
54982
54983 bprm->exec = bprm->p;
54984 retval = copy_strings(bprm->envc, envp, bprm);
54985 if (retval < 0)
54986- goto out;
54987+ goto out_fail;
54988
54989 retval = copy_strings(bprm->argc, argv, bprm);
54990 if (retval < 0)
54991- goto out;
54992+ goto out_fail;
54993+
54994+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
54995+
54996+ gr_handle_exec_args(bprm, argv);
54997
54998 retval = search_binary_handler(bprm);
54999 if (retval < 0)
55000- goto out;
55001+ goto out_fail;
55002+#ifdef CONFIG_GRKERNSEC
55003+ if (old_exec_file)
55004+ fput(old_exec_file);
55005+#endif
55006
55007 /* execve succeeded */
55008+
55009+ increment_exec_counter();
55010 current->fs->in_exec = 0;
55011 current->in_execve = 0;
55012 acct_update_integrals(current);
55013@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55014 put_files_struct(displaced);
55015 return retval;
55016
55017+out_fail:
55018+#ifdef CONFIG_GRKERNSEC
55019+ current->acl = old_acl;
55020+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55021+ fput(current->exec_file);
55022+ current->exec_file = old_exec_file;
55023+#endif
55024+
55025 out:
55026 if (bprm->mm) {
55027 acct_arg_size(bprm, 0);
55028@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55029 return error;
55030 }
55031 #endif
55032+
55033+int pax_check_flags(unsigned long *flags)
55034+{
55035+ int retval = 0;
55036+
55037+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55038+ if (*flags & MF_PAX_SEGMEXEC)
55039+ {
55040+ *flags &= ~MF_PAX_SEGMEXEC;
55041+ retval = -EINVAL;
55042+ }
55043+#endif
55044+
55045+ if ((*flags & MF_PAX_PAGEEXEC)
55046+
55047+#ifdef CONFIG_PAX_PAGEEXEC
55048+ && (*flags & MF_PAX_SEGMEXEC)
55049+#endif
55050+
55051+ )
55052+ {
55053+ *flags &= ~MF_PAX_PAGEEXEC;
55054+ retval = -EINVAL;
55055+ }
55056+
55057+ if ((*flags & MF_PAX_MPROTECT)
55058+
55059+#ifdef CONFIG_PAX_MPROTECT
55060+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55061+#endif
55062+
55063+ )
55064+ {
55065+ *flags &= ~MF_PAX_MPROTECT;
55066+ retval = -EINVAL;
55067+ }
55068+
55069+ if ((*flags & MF_PAX_EMUTRAMP)
55070+
55071+#ifdef CONFIG_PAX_EMUTRAMP
55072+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55073+#endif
55074+
55075+ )
55076+ {
55077+ *flags &= ~MF_PAX_EMUTRAMP;
55078+ retval = -EINVAL;
55079+ }
55080+
55081+ return retval;
55082+}
55083+
55084+EXPORT_SYMBOL(pax_check_flags);
55085+
55086+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55087+char *pax_get_path(const struct path *path, char *buf, int buflen)
55088+{
55089+ char *pathname = d_path(path, buf, buflen);
55090+
55091+ if (IS_ERR(pathname))
55092+ goto toolong;
55093+
55094+ pathname = mangle_path(buf, pathname, "\t\n\\");
55095+ if (!pathname)
55096+ goto toolong;
55097+
55098+ *pathname = 0;
55099+ return buf;
55100+
55101+toolong:
55102+ return "<path too long>";
55103+}
55104+EXPORT_SYMBOL(pax_get_path);
55105+
55106+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55107+{
55108+ struct task_struct *tsk = current;
55109+ struct mm_struct *mm = current->mm;
55110+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55111+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55112+ char *path_exec = NULL;
55113+ char *path_fault = NULL;
55114+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55115+ siginfo_t info = { };
55116+
55117+ if (buffer_exec && buffer_fault) {
55118+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55119+
55120+ down_read(&mm->mmap_sem);
55121+ vma = mm->mmap;
55122+ while (vma && (!vma_exec || !vma_fault)) {
55123+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55124+ vma_exec = vma;
55125+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55126+ vma_fault = vma;
55127+ vma = vma->vm_next;
55128+ }
55129+ if (vma_exec)
55130+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55131+ if (vma_fault) {
55132+ start = vma_fault->vm_start;
55133+ end = vma_fault->vm_end;
55134+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55135+ if (vma_fault->vm_file)
55136+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55137+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55138+ path_fault = "<heap>";
55139+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55140+ path_fault = "<stack>";
55141+ else
55142+ path_fault = "<anonymous mapping>";
55143+ }
55144+ up_read(&mm->mmap_sem);
55145+ }
55146+ if (tsk->signal->curr_ip)
55147+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55148+ else
55149+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55150+ 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),
55151+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55152+ free_page((unsigned long)buffer_exec);
55153+ free_page((unsigned long)buffer_fault);
55154+ pax_report_insns(regs, pc, sp);
55155+ info.si_signo = SIGKILL;
55156+ info.si_errno = 0;
55157+ info.si_code = SI_KERNEL;
55158+ info.si_pid = 0;
55159+ info.si_uid = 0;
55160+ do_coredump(&info);
55161+}
55162+#endif
55163+
55164+#ifdef CONFIG_PAX_REFCOUNT
55165+void pax_report_refcount_overflow(struct pt_regs *regs)
55166+{
55167+ if (current->signal->curr_ip)
55168+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55169+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55170+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55171+ else
55172+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55173+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55174+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55175+ preempt_disable();
55176+ show_regs(regs);
55177+ preempt_enable();
55178+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55179+}
55180+#endif
55181+
55182+#ifdef CONFIG_PAX_USERCOPY
55183+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55184+static noinline int check_stack_object(const void *obj, unsigned long len)
55185+{
55186+ const void * const stack = task_stack_page(current);
55187+ const void * const stackend = stack + THREAD_SIZE;
55188+
55189+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55190+ const void *frame = NULL;
55191+ const void *oldframe;
55192+#endif
55193+
55194+ if (obj + len < obj)
55195+ return -1;
55196+
55197+ if (obj + len <= stack || stackend <= obj)
55198+ return 0;
55199+
55200+ if (obj < stack || stackend < obj + len)
55201+ return -1;
55202+
55203+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55204+ oldframe = __builtin_frame_address(1);
55205+ if (oldframe)
55206+ frame = __builtin_frame_address(2);
55207+ /*
55208+ low ----------------------------------------------> high
55209+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55210+ ^----------------^
55211+ allow copies only within here
55212+ */
55213+ while (stack <= frame && frame < stackend) {
55214+ /* if obj + len extends past the last frame, this
55215+ check won't pass and the next frame will be 0,
55216+ causing us to bail out and correctly report
55217+ the copy as invalid
55218+ */
55219+ if (obj + len <= frame)
55220+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55221+ oldframe = frame;
55222+ frame = *(const void * const *)frame;
55223+ }
55224+ return -1;
55225+#else
55226+ return 1;
55227+#endif
55228+}
55229+
55230+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55231+{
55232+ if (current->signal->curr_ip)
55233+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55234+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55235+ else
55236+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55237+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55238+ dump_stack();
55239+ gr_handle_kernel_exploit();
55240+ do_group_exit(SIGKILL);
55241+}
55242+#endif
55243+
55244+#ifdef CONFIG_PAX_USERCOPY
55245+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55246+{
55247+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55248+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55249+#ifdef CONFIG_MODULES
55250+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55251+#else
55252+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55253+#endif
55254+
55255+#else
55256+ unsigned long textlow = (unsigned long)_stext;
55257+ unsigned long texthigh = (unsigned long)_etext;
55258+#endif
55259+
55260+ if (high <= textlow || low > texthigh)
55261+ return false;
55262+ else
55263+ return true;
55264+}
55265+#endif
55266+
55267+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55268+{
55269+
55270+#ifdef CONFIG_PAX_USERCOPY
55271+ const char *type;
55272+
55273+ if (!n)
55274+ return;
55275+
55276+ type = check_heap_object(ptr, n);
55277+ if (!type) {
55278+ int ret = check_stack_object(ptr, n);
55279+ if (ret == 1 || ret == 2)
55280+ return;
55281+ if (ret == 0) {
55282+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55283+ type = "<kernel text>";
55284+ else
55285+ return;
55286+ } else
55287+ type = "<process stack>";
55288+ }
55289+
55290+ pax_report_usercopy(ptr, n, to_user, type);
55291+#endif
55292+
55293+}
55294+EXPORT_SYMBOL(__check_object_size);
55295+
55296+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55297+void pax_track_stack(void)
55298+{
55299+ unsigned long sp = (unsigned long)&sp;
55300+ if (sp < current_thread_info()->lowest_stack &&
55301+ sp > (unsigned long)task_stack_page(current))
55302+ current_thread_info()->lowest_stack = sp;
55303+}
55304+EXPORT_SYMBOL(pax_track_stack);
55305+#endif
55306+
55307+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55308+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55309+{
55310+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55311+ dump_stack();
55312+ do_group_exit(SIGKILL);
55313+}
55314+EXPORT_SYMBOL(report_size_overflow);
55315+#endif
55316diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55317index 9f9992b..8b59411 100644
55318--- a/fs/ext2/balloc.c
55319+++ b/fs/ext2/balloc.c
55320@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55321
55322 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55323 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55324- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55325+ if (free_blocks < root_blocks + 1 &&
55326 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55327 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55328- !in_group_p (sbi->s_resgid))) {
55329+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55330 return 0;
55331 }
55332 return 1;
55333diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55334index 22548f5..41521d8 100644
55335--- a/fs/ext3/balloc.c
55336+++ b/fs/ext3/balloc.c
55337@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55338
55339 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55340 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55341- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55342+ if (free_blocks < root_blocks + 1 &&
55343 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55344 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55345- !in_group_p (sbi->s_resgid))) {
55346+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55347 return 0;
55348 }
55349 return 1;
55350diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
55351index 1194b1f..f8cde46 100644
55352--- a/fs/ext3/namei.c
55353+++ b/fs/ext3/namei.c
55354@@ -1783,7 +1783,7 @@ retry:
55355 d_tmpfile(dentry, inode);
55356 err = ext3_orphan_add(handle, inode);
55357 if (err)
55358- goto err_drop_inode;
55359+ goto err_unlock_inode;
55360 mark_inode_dirty(inode);
55361 unlock_new_inode(inode);
55362 }
55363@@ -1791,10 +1791,9 @@ retry:
55364 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
55365 goto retry;
55366 return err;
55367-err_drop_inode:
55368+err_unlock_inode:
55369 ext3_journal_stop(handle);
55370 unlock_new_inode(inode);
55371- iput(inode);
55372 return err;
55373 }
55374
55375diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55376index ddd715e..c772f88 100644
55377--- a/fs/ext4/balloc.c
55378+++ b/fs/ext4/balloc.c
55379@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55380 /* Hm, nope. Are (enough) root reserved clusters available? */
55381 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55382 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55383- capable(CAP_SYS_RESOURCE) ||
55384- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55385+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55386+ capable_nolog(CAP_SYS_RESOURCE)) {
55387
55388 if (free_clusters >= (nclusters + dirty_clusters +
55389 resv_clusters))
55390diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55391index 0ab26fb..b6ecb39 100644
55392--- a/fs/ext4/ext4.h
55393+++ b/fs/ext4/ext4.h
55394@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55395 unsigned long s_mb_last_start;
55396
55397 /* stats for buddy allocator */
55398- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55399- atomic_t s_bal_success; /* we found long enough chunks */
55400- atomic_t s_bal_allocated; /* in blocks */
55401- atomic_t s_bal_ex_scanned; /* total extents scanned */
55402- atomic_t s_bal_goals; /* goal hits */
55403- atomic_t s_bal_breaks; /* too long searches */
55404- atomic_t s_bal_2orders; /* 2^order hits */
55405+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55406+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55407+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55408+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55409+ atomic_unchecked_t s_bal_goals; /* goal hits */
55410+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55411+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55412 spinlock_t s_bal_lock;
55413 unsigned long s_mb_buddies_generated;
55414 unsigned long long s_mb_generation_time;
55415- atomic_t s_mb_lost_chunks;
55416- atomic_t s_mb_preallocated;
55417- atomic_t s_mb_discarded;
55418+ atomic_unchecked_t s_mb_lost_chunks;
55419+ atomic_unchecked_t s_mb_preallocated;
55420+ atomic_unchecked_t s_mb_discarded;
55421 atomic_t s_lock_busy;
55422
55423 /* locality groups */
55424diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55425index 4bbbf13b..dcceaeb 100644
55426--- a/fs/ext4/mballoc.c
55427+++ b/fs/ext4/mballoc.c
55428@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55429 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55430
55431 if (EXT4_SB(sb)->s_mb_stats)
55432- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55433+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55434
55435 break;
55436 }
55437@@ -2171,7 +2171,7 @@ repeat:
55438 ac->ac_status = AC_STATUS_CONTINUE;
55439 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55440 cr = 3;
55441- atomic_inc(&sbi->s_mb_lost_chunks);
55442+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55443 goto repeat;
55444 }
55445 }
55446@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55447 if (sbi->s_mb_stats) {
55448 ext4_msg(sb, KERN_INFO,
55449 "mballoc: %u blocks %u reqs (%u success)",
55450- atomic_read(&sbi->s_bal_allocated),
55451- atomic_read(&sbi->s_bal_reqs),
55452- atomic_read(&sbi->s_bal_success));
55453+ atomic_read_unchecked(&sbi->s_bal_allocated),
55454+ atomic_read_unchecked(&sbi->s_bal_reqs),
55455+ atomic_read_unchecked(&sbi->s_bal_success));
55456 ext4_msg(sb, KERN_INFO,
55457 "mballoc: %u extents scanned, %u goal hits, "
55458 "%u 2^N hits, %u breaks, %u lost",
55459- atomic_read(&sbi->s_bal_ex_scanned),
55460- atomic_read(&sbi->s_bal_goals),
55461- atomic_read(&sbi->s_bal_2orders),
55462- atomic_read(&sbi->s_bal_breaks),
55463- atomic_read(&sbi->s_mb_lost_chunks));
55464+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55465+ atomic_read_unchecked(&sbi->s_bal_goals),
55466+ atomic_read_unchecked(&sbi->s_bal_2orders),
55467+ atomic_read_unchecked(&sbi->s_bal_breaks),
55468+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55469 ext4_msg(sb, KERN_INFO,
55470 "mballoc: %lu generated and it took %Lu",
55471 sbi->s_mb_buddies_generated,
55472 sbi->s_mb_generation_time);
55473 ext4_msg(sb, KERN_INFO,
55474 "mballoc: %u preallocated, %u discarded",
55475- atomic_read(&sbi->s_mb_preallocated),
55476- atomic_read(&sbi->s_mb_discarded));
55477+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55478+ atomic_read_unchecked(&sbi->s_mb_discarded));
55479 }
55480
55481 free_percpu(sbi->s_locality_groups);
55482@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55483 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55484
55485 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55486- atomic_inc(&sbi->s_bal_reqs);
55487- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55488+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55489+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55490 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55491- atomic_inc(&sbi->s_bal_success);
55492- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55493+ atomic_inc_unchecked(&sbi->s_bal_success);
55494+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55495 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55496 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55497- atomic_inc(&sbi->s_bal_goals);
55498+ atomic_inc_unchecked(&sbi->s_bal_goals);
55499 if (ac->ac_found > sbi->s_mb_max_to_scan)
55500- atomic_inc(&sbi->s_bal_breaks);
55501+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55502 }
55503
55504 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55505@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55506 trace_ext4_mb_new_inode_pa(ac, pa);
55507
55508 ext4_mb_use_inode_pa(ac, pa);
55509- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55510+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55511
55512 ei = EXT4_I(ac->ac_inode);
55513 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55514@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55515 trace_ext4_mb_new_group_pa(ac, pa);
55516
55517 ext4_mb_use_group_pa(ac, pa);
55518- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55519+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55520
55521 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55522 lg = ac->ac_lg;
55523@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55524 * from the bitmap and continue.
55525 */
55526 }
55527- atomic_add(free, &sbi->s_mb_discarded);
55528+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55529
55530 return err;
55531 }
55532@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55533 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55534 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55535 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55536- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55537+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55538 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55539
55540 return 0;
55541diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55542index 214461e..3614c89 100644
55543--- a/fs/ext4/mmp.c
55544+++ b/fs/ext4/mmp.c
55545@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55546 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55547 const char *function, unsigned int line, const char *msg)
55548 {
55549- __ext4_warning(sb, function, line, msg);
55550+ __ext4_warning(sb, function, line, "%s", msg);
55551 __ext4_warning(sb, function, line,
55552 "MMP failure info: last update time: %llu, last update "
55553 "node: %s, last update device: %s\n",
55554diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
55555index 35f55a0..b53cbc6 100644
55556--- a/fs/ext4/namei.c
55557+++ b/fs/ext4/namei.c
55558@@ -2319,7 +2319,7 @@ retry:
55559 d_tmpfile(dentry, inode);
55560 err = ext4_orphan_add(handle, inode);
55561 if (err)
55562- goto err_drop_inode;
55563+ goto err_unlock_inode;
55564 mark_inode_dirty(inode);
55565 unlock_new_inode(inode);
55566 }
55567@@ -2328,10 +2328,9 @@ retry:
55568 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
55569 goto retry;
55570 return err;
55571-err_drop_inode:
55572+err_unlock_inode:
55573 ext4_journal_stop(handle);
55574 unlock_new_inode(inode);
55575- iput(inode);
55576 return err;
55577 }
55578
55579diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55580index b59373b..f41c2b5 100644
55581--- a/fs/ext4/super.c
55582+++ b/fs/ext4/super.c
55583@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55584 }
55585
55586 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55587-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55588+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55589 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55590
55591 #ifdef CONFIG_QUOTA
55592@@ -2394,7 +2394,7 @@ struct ext4_attr {
55593 int offset;
55594 int deprecated_val;
55595 } u;
55596-};
55597+} __do_const;
55598
55599 static int parse_strtoull(const char *buf,
55600 unsigned long long max, unsigned long long *value)
55601diff --git a/fs/fcntl.c b/fs/fcntl.c
55602index 65343c3..9969dcf 100644
55603--- a/fs/fcntl.c
55604+++ b/fs/fcntl.c
55605@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55606 if (err)
55607 return err;
55608
55609+ if (gr_handle_chroot_fowner(pid, type))
55610+ return -ENOENT;
55611+ if (gr_check_protected_task_fowner(pid, type))
55612+ return -EACCES;
55613+
55614 f_modown(filp, pid, type, force);
55615 return 0;
55616 }
55617diff --git a/fs/fhandle.c b/fs/fhandle.c
55618index 999ff5c..41f4109 100644
55619--- a/fs/fhandle.c
55620+++ b/fs/fhandle.c
55621@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55622 } else
55623 retval = 0;
55624 /* copy the mount id */
55625- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55626- sizeof(*mnt_id)) ||
55627+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55628 copy_to_user(ufh, handle,
55629 sizeof(struct file_handle) + handle_bytes))
55630 retval = -EFAULT;
55631diff --git a/fs/file.c b/fs/file.c
55632index 4a78f98..9447397 100644
55633--- a/fs/file.c
55634+++ b/fs/file.c
55635@@ -16,6 +16,7 @@
55636 #include <linux/slab.h>
55637 #include <linux/vmalloc.h>
55638 #include <linux/file.h>
55639+#include <linux/security.h>
55640 #include <linux/fdtable.h>
55641 #include <linux/bitops.h>
55642 #include <linux/interrupt.h>
55643@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55644 if (!file)
55645 return __close_fd(files, fd);
55646
55647+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55648 if (fd >= rlimit(RLIMIT_NOFILE))
55649 return -EBADF;
55650
55651@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55652 if (unlikely(oldfd == newfd))
55653 return -EINVAL;
55654
55655+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55656 if (newfd >= rlimit(RLIMIT_NOFILE))
55657 return -EBADF;
55658
55659@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55660 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55661 {
55662 int err;
55663+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55664 if (from >= rlimit(RLIMIT_NOFILE))
55665 return -EINVAL;
55666 err = alloc_fd(from, flags);
55667diff --git a/fs/filesystems.c b/fs/filesystems.c
55668index 92567d9..fcd8cbf 100644
55669--- a/fs/filesystems.c
55670+++ b/fs/filesystems.c
55671@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55672 int len = dot ? dot - name : strlen(name);
55673
55674 fs = __get_fs_type(name, len);
55675+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55676+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55677+#else
55678 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55679+#endif
55680 fs = __get_fs_type(name, len);
55681
55682 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55683diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55684index d8ac61d..79a36f0 100644
55685--- a/fs/fs_struct.c
55686+++ b/fs/fs_struct.c
55687@@ -4,6 +4,7 @@
55688 #include <linux/path.h>
55689 #include <linux/slab.h>
55690 #include <linux/fs_struct.h>
55691+#include <linux/grsecurity.h>
55692 #include "internal.h"
55693
55694 /*
55695@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55696 write_seqcount_begin(&fs->seq);
55697 old_root = fs->root;
55698 fs->root = *path;
55699+ gr_set_chroot_entries(current, path);
55700 write_seqcount_end(&fs->seq);
55701 spin_unlock(&fs->lock);
55702 if (old_root.dentry)
55703@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55704 int hits = 0;
55705 spin_lock(&fs->lock);
55706 write_seqcount_begin(&fs->seq);
55707+ /* this root replacement is only done by pivot_root,
55708+ leave grsec's chroot tagging alone for this task
55709+ so that a pivoted root isn't treated as a chroot
55710+ */
55711 hits += replace_path(&fs->root, old_root, new_root);
55712 hits += replace_path(&fs->pwd, old_root, new_root);
55713 write_seqcount_end(&fs->seq);
55714@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55715 task_lock(tsk);
55716 spin_lock(&fs->lock);
55717 tsk->fs = NULL;
55718- kill = !--fs->users;
55719+ gr_clear_chroot_entries(tsk);
55720+ kill = !atomic_dec_return(&fs->users);
55721 spin_unlock(&fs->lock);
55722 task_unlock(tsk);
55723 if (kill)
55724@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55725 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55726 /* We don't need to lock fs - think why ;-) */
55727 if (fs) {
55728- fs->users = 1;
55729+ atomic_set(&fs->users, 1);
55730 fs->in_exec = 0;
55731 spin_lock_init(&fs->lock);
55732 seqcount_init(&fs->seq);
55733@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55734 spin_lock(&old->lock);
55735 fs->root = old->root;
55736 path_get(&fs->root);
55737+ /* instead of calling gr_set_chroot_entries here,
55738+ we call it from every caller of this function
55739+ */
55740 fs->pwd = old->pwd;
55741 path_get(&fs->pwd);
55742 spin_unlock(&old->lock);
55743@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55744
55745 task_lock(current);
55746 spin_lock(&fs->lock);
55747- kill = !--fs->users;
55748+ kill = !atomic_dec_return(&fs->users);
55749 current->fs = new_fs;
55750+ gr_set_chroot_entries(current, &new_fs->root);
55751 spin_unlock(&fs->lock);
55752 task_unlock(current);
55753
55754@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55755
55756 int current_umask(void)
55757 {
55758- return current->fs->umask;
55759+ return current->fs->umask | gr_acl_umask();
55760 }
55761 EXPORT_SYMBOL(current_umask);
55762
55763 /* to be mentioned only in INIT_TASK */
55764 struct fs_struct init_fs = {
55765- .users = 1,
55766+ .users = ATOMIC_INIT(1),
55767 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55768 .seq = SEQCNT_ZERO,
55769 .umask = 0022,
55770diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55771index 0e91a3c..6c6d2e0 100644
55772--- a/fs/fscache/cookie.c
55773+++ b/fs/fscache/cookie.c
55774@@ -19,7 +19,7 @@
55775
55776 struct kmem_cache *fscache_cookie_jar;
55777
55778-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55779+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55780
55781 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55782 static int fscache_alloc_object(struct fscache_cache *cache,
55783@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55784 parent ? (char *) parent->def->name : "<no-parent>",
55785 def->name, netfs_data);
55786
55787- fscache_stat(&fscache_n_acquires);
55788+ fscache_stat_unchecked(&fscache_n_acquires);
55789
55790 /* if there's no parent cookie, then we don't create one here either */
55791 if (!parent) {
55792- fscache_stat(&fscache_n_acquires_null);
55793+ fscache_stat_unchecked(&fscache_n_acquires_null);
55794 _leave(" [no parent]");
55795 return NULL;
55796 }
55797@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55798 /* allocate and initialise a cookie */
55799 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55800 if (!cookie) {
55801- fscache_stat(&fscache_n_acquires_oom);
55802+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55803 _leave(" [ENOMEM]");
55804 return NULL;
55805 }
55806@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55807
55808 switch (cookie->def->type) {
55809 case FSCACHE_COOKIE_TYPE_INDEX:
55810- fscache_stat(&fscache_n_cookie_index);
55811+ fscache_stat_unchecked(&fscache_n_cookie_index);
55812 break;
55813 case FSCACHE_COOKIE_TYPE_DATAFILE:
55814- fscache_stat(&fscache_n_cookie_data);
55815+ fscache_stat_unchecked(&fscache_n_cookie_data);
55816 break;
55817 default:
55818- fscache_stat(&fscache_n_cookie_special);
55819+ fscache_stat_unchecked(&fscache_n_cookie_special);
55820 break;
55821 }
55822
55823@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55824 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55825 atomic_dec(&parent->n_children);
55826 __fscache_cookie_put(cookie);
55827- fscache_stat(&fscache_n_acquires_nobufs);
55828+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55829 _leave(" = NULL");
55830 return NULL;
55831 }
55832 }
55833
55834- fscache_stat(&fscache_n_acquires_ok);
55835+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55836 _leave(" = %p", cookie);
55837 return cookie;
55838 }
55839@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55840 cache = fscache_select_cache_for_object(cookie->parent);
55841 if (!cache) {
55842 up_read(&fscache_addremove_sem);
55843- fscache_stat(&fscache_n_acquires_no_cache);
55844+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55845 _leave(" = -ENOMEDIUM [no cache]");
55846 return -ENOMEDIUM;
55847 }
55848@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55849 object = cache->ops->alloc_object(cache, cookie);
55850 fscache_stat_d(&fscache_n_cop_alloc_object);
55851 if (IS_ERR(object)) {
55852- fscache_stat(&fscache_n_object_no_alloc);
55853+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55854 ret = PTR_ERR(object);
55855 goto error;
55856 }
55857
55858- fscache_stat(&fscache_n_object_alloc);
55859+ fscache_stat_unchecked(&fscache_n_object_alloc);
55860
55861- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55862+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55863
55864 _debug("ALLOC OBJ%x: %s {%lx}",
55865 object->debug_id, cookie->def->name, object->events);
55866@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55867
55868 _enter("{%s}", cookie->def->name);
55869
55870- fscache_stat(&fscache_n_invalidates);
55871+ fscache_stat_unchecked(&fscache_n_invalidates);
55872
55873 /* Only permit invalidation of data files. Invalidating an index will
55874 * require the caller to release all its attachments to the tree rooted
55875@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55876 {
55877 struct fscache_object *object;
55878
55879- fscache_stat(&fscache_n_updates);
55880+ fscache_stat_unchecked(&fscache_n_updates);
55881
55882 if (!cookie) {
55883- fscache_stat(&fscache_n_updates_null);
55884+ fscache_stat_unchecked(&fscache_n_updates_null);
55885 _leave(" [no cookie]");
55886 return;
55887 }
55888@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55889 {
55890 struct fscache_object *object;
55891
55892- fscache_stat(&fscache_n_relinquishes);
55893+ fscache_stat_unchecked(&fscache_n_relinquishes);
55894 if (retire)
55895- fscache_stat(&fscache_n_relinquishes_retire);
55896+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55897
55898 if (!cookie) {
55899- fscache_stat(&fscache_n_relinquishes_null);
55900+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55901 _leave(" [no cookie]");
55902 return;
55903 }
55904diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55905index 12d505b..86473a3 100644
55906--- a/fs/fscache/internal.h
55907+++ b/fs/fscache/internal.h
55908@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55909 * stats.c
55910 */
55911 #ifdef CONFIG_FSCACHE_STATS
55912-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55913-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55914+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55915+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55916
55917-extern atomic_t fscache_n_op_pend;
55918-extern atomic_t fscache_n_op_run;
55919-extern atomic_t fscache_n_op_enqueue;
55920-extern atomic_t fscache_n_op_deferred_release;
55921-extern atomic_t fscache_n_op_release;
55922-extern atomic_t fscache_n_op_gc;
55923-extern atomic_t fscache_n_op_cancelled;
55924-extern atomic_t fscache_n_op_rejected;
55925+extern atomic_unchecked_t fscache_n_op_pend;
55926+extern atomic_unchecked_t fscache_n_op_run;
55927+extern atomic_unchecked_t fscache_n_op_enqueue;
55928+extern atomic_unchecked_t fscache_n_op_deferred_release;
55929+extern atomic_unchecked_t fscache_n_op_release;
55930+extern atomic_unchecked_t fscache_n_op_gc;
55931+extern atomic_unchecked_t fscache_n_op_cancelled;
55932+extern atomic_unchecked_t fscache_n_op_rejected;
55933
55934-extern atomic_t fscache_n_attr_changed;
55935-extern atomic_t fscache_n_attr_changed_ok;
55936-extern atomic_t fscache_n_attr_changed_nobufs;
55937-extern atomic_t fscache_n_attr_changed_nomem;
55938-extern atomic_t fscache_n_attr_changed_calls;
55939+extern atomic_unchecked_t fscache_n_attr_changed;
55940+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55941+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55942+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55943+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55944
55945-extern atomic_t fscache_n_allocs;
55946-extern atomic_t fscache_n_allocs_ok;
55947-extern atomic_t fscache_n_allocs_wait;
55948-extern atomic_t fscache_n_allocs_nobufs;
55949-extern atomic_t fscache_n_allocs_intr;
55950-extern atomic_t fscache_n_allocs_object_dead;
55951-extern atomic_t fscache_n_alloc_ops;
55952-extern atomic_t fscache_n_alloc_op_waits;
55953+extern atomic_unchecked_t fscache_n_allocs;
55954+extern atomic_unchecked_t fscache_n_allocs_ok;
55955+extern atomic_unchecked_t fscache_n_allocs_wait;
55956+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55957+extern atomic_unchecked_t fscache_n_allocs_intr;
55958+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55959+extern atomic_unchecked_t fscache_n_alloc_ops;
55960+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55961
55962-extern atomic_t fscache_n_retrievals;
55963-extern atomic_t fscache_n_retrievals_ok;
55964-extern atomic_t fscache_n_retrievals_wait;
55965-extern atomic_t fscache_n_retrievals_nodata;
55966-extern atomic_t fscache_n_retrievals_nobufs;
55967-extern atomic_t fscache_n_retrievals_intr;
55968-extern atomic_t fscache_n_retrievals_nomem;
55969-extern atomic_t fscache_n_retrievals_object_dead;
55970-extern atomic_t fscache_n_retrieval_ops;
55971-extern atomic_t fscache_n_retrieval_op_waits;
55972+extern atomic_unchecked_t fscache_n_retrievals;
55973+extern atomic_unchecked_t fscache_n_retrievals_ok;
55974+extern atomic_unchecked_t fscache_n_retrievals_wait;
55975+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55976+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
55977+extern atomic_unchecked_t fscache_n_retrievals_intr;
55978+extern atomic_unchecked_t fscache_n_retrievals_nomem;
55979+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
55980+extern atomic_unchecked_t fscache_n_retrieval_ops;
55981+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
55982
55983-extern atomic_t fscache_n_stores;
55984-extern atomic_t fscache_n_stores_ok;
55985-extern atomic_t fscache_n_stores_again;
55986-extern atomic_t fscache_n_stores_nobufs;
55987-extern atomic_t fscache_n_stores_oom;
55988-extern atomic_t fscache_n_store_ops;
55989-extern atomic_t fscache_n_store_calls;
55990-extern atomic_t fscache_n_store_pages;
55991-extern atomic_t fscache_n_store_radix_deletes;
55992-extern atomic_t fscache_n_store_pages_over_limit;
55993+extern atomic_unchecked_t fscache_n_stores;
55994+extern atomic_unchecked_t fscache_n_stores_ok;
55995+extern atomic_unchecked_t fscache_n_stores_again;
55996+extern atomic_unchecked_t fscache_n_stores_nobufs;
55997+extern atomic_unchecked_t fscache_n_stores_oom;
55998+extern atomic_unchecked_t fscache_n_store_ops;
55999+extern atomic_unchecked_t fscache_n_store_calls;
56000+extern atomic_unchecked_t fscache_n_store_pages;
56001+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56002+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56003
56004-extern atomic_t fscache_n_store_vmscan_not_storing;
56005-extern atomic_t fscache_n_store_vmscan_gone;
56006-extern atomic_t fscache_n_store_vmscan_busy;
56007-extern atomic_t fscache_n_store_vmscan_cancelled;
56008-extern atomic_t fscache_n_store_vmscan_wait;
56009+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56010+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56011+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56012+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56013+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56014
56015-extern atomic_t fscache_n_marks;
56016-extern atomic_t fscache_n_uncaches;
56017+extern atomic_unchecked_t fscache_n_marks;
56018+extern atomic_unchecked_t fscache_n_uncaches;
56019
56020-extern atomic_t fscache_n_acquires;
56021-extern atomic_t fscache_n_acquires_null;
56022-extern atomic_t fscache_n_acquires_no_cache;
56023-extern atomic_t fscache_n_acquires_ok;
56024-extern atomic_t fscache_n_acquires_nobufs;
56025-extern atomic_t fscache_n_acquires_oom;
56026+extern atomic_unchecked_t fscache_n_acquires;
56027+extern atomic_unchecked_t fscache_n_acquires_null;
56028+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56029+extern atomic_unchecked_t fscache_n_acquires_ok;
56030+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56031+extern atomic_unchecked_t fscache_n_acquires_oom;
56032
56033-extern atomic_t fscache_n_invalidates;
56034-extern atomic_t fscache_n_invalidates_run;
56035+extern atomic_unchecked_t fscache_n_invalidates;
56036+extern atomic_unchecked_t fscache_n_invalidates_run;
56037
56038-extern atomic_t fscache_n_updates;
56039-extern atomic_t fscache_n_updates_null;
56040-extern atomic_t fscache_n_updates_run;
56041+extern atomic_unchecked_t fscache_n_updates;
56042+extern atomic_unchecked_t fscache_n_updates_null;
56043+extern atomic_unchecked_t fscache_n_updates_run;
56044
56045-extern atomic_t fscache_n_relinquishes;
56046-extern atomic_t fscache_n_relinquishes_null;
56047-extern atomic_t fscache_n_relinquishes_waitcrt;
56048-extern atomic_t fscache_n_relinquishes_retire;
56049+extern atomic_unchecked_t fscache_n_relinquishes;
56050+extern atomic_unchecked_t fscache_n_relinquishes_null;
56051+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56052+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56053
56054-extern atomic_t fscache_n_cookie_index;
56055-extern atomic_t fscache_n_cookie_data;
56056-extern atomic_t fscache_n_cookie_special;
56057+extern atomic_unchecked_t fscache_n_cookie_index;
56058+extern atomic_unchecked_t fscache_n_cookie_data;
56059+extern atomic_unchecked_t fscache_n_cookie_special;
56060
56061-extern atomic_t fscache_n_object_alloc;
56062-extern atomic_t fscache_n_object_no_alloc;
56063-extern atomic_t fscache_n_object_lookups;
56064-extern atomic_t fscache_n_object_lookups_negative;
56065-extern atomic_t fscache_n_object_lookups_positive;
56066-extern atomic_t fscache_n_object_lookups_timed_out;
56067-extern atomic_t fscache_n_object_created;
56068-extern atomic_t fscache_n_object_avail;
56069-extern atomic_t fscache_n_object_dead;
56070+extern atomic_unchecked_t fscache_n_object_alloc;
56071+extern atomic_unchecked_t fscache_n_object_no_alloc;
56072+extern atomic_unchecked_t fscache_n_object_lookups;
56073+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56074+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56075+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56076+extern atomic_unchecked_t fscache_n_object_created;
56077+extern atomic_unchecked_t fscache_n_object_avail;
56078+extern atomic_unchecked_t fscache_n_object_dead;
56079
56080-extern atomic_t fscache_n_checkaux_none;
56081-extern atomic_t fscache_n_checkaux_okay;
56082-extern atomic_t fscache_n_checkaux_update;
56083-extern atomic_t fscache_n_checkaux_obsolete;
56084+extern atomic_unchecked_t fscache_n_checkaux_none;
56085+extern atomic_unchecked_t fscache_n_checkaux_okay;
56086+extern atomic_unchecked_t fscache_n_checkaux_update;
56087+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56088
56089 extern atomic_t fscache_n_cop_alloc_object;
56090 extern atomic_t fscache_n_cop_lookup_object;
56091@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56092 atomic_inc(stat);
56093 }
56094
56095+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56096+{
56097+ atomic_inc_unchecked(stat);
56098+}
56099+
56100 static inline void fscache_stat_d(atomic_t *stat)
56101 {
56102 atomic_dec(stat);
56103@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56104
56105 #define __fscache_stat(stat) (NULL)
56106 #define fscache_stat(stat) do {} while (0)
56107+#define fscache_stat_unchecked(stat) do {} while (0)
56108 #define fscache_stat_d(stat) do {} while (0)
56109 #endif
56110
56111diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56112index 86d75a6..5f3d7a0 100644
56113--- a/fs/fscache/object.c
56114+++ b/fs/fscache/object.c
56115@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56116 _debug("LOOKUP \"%s\" in \"%s\"",
56117 cookie->def->name, object->cache->tag->name);
56118
56119- fscache_stat(&fscache_n_object_lookups);
56120+ fscache_stat_unchecked(&fscache_n_object_lookups);
56121 fscache_stat(&fscache_n_cop_lookup_object);
56122 ret = object->cache->ops->lookup_object(object);
56123 fscache_stat_d(&fscache_n_cop_lookup_object);
56124@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56125 if (ret == -ETIMEDOUT) {
56126 /* probably stuck behind another object, so move this one to
56127 * the back of the queue */
56128- fscache_stat(&fscache_n_object_lookups_timed_out);
56129+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56130 _leave(" [timeout]");
56131 return NO_TRANSIT;
56132 }
56133@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56134 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56135
56136 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56137- fscache_stat(&fscache_n_object_lookups_negative);
56138+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56139
56140 /* Allow write requests to begin stacking up and read requests to begin
56141 * returning ENODATA.
56142@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56143 /* if we were still looking up, then we must have a positive lookup
56144 * result, in which case there may be data available */
56145 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56146- fscache_stat(&fscache_n_object_lookups_positive);
56147+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56148
56149 /* We do (presumably) have data */
56150 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56151@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56152 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56153 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56154 } else {
56155- fscache_stat(&fscache_n_object_created);
56156+ fscache_stat_unchecked(&fscache_n_object_created);
56157 }
56158
56159 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56160@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56161 fscache_stat_d(&fscache_n_cop_lookup_complete);
56162
56163 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56164- fscache_stat(&fscache_n_object_avail);
56165+ fscache_stat_unchecked(&fscache_n_object_avail);
56166
56167 _leave("");
56168 return transit_to(JUMPSTART_DEPS);
56169@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56170
56171 /* this just shifts the object release to the work processor */
56172 fscache_put_object(object);
56173- fscache_stat(&fscache_n_object_dead);
56174+ fscache_stat_unchecked(&fscache_n_object_dead);
56175
56176 _leave("");
56177 return transit_to(OBJECT_DEAD);
56178@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56179 enum fscache_checkaux result;
56180
56181 if (!object->cookie->def->check_aux) {
56182- fscache_stat(&fscache_n_checkaux_none);
56183+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56184 return FSCACHE_CHECKAUX_OKAY;
56185 }
56186
56187@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56188 switch (result) {
56189 /* entry okay as is */
56190 case FSCACHE_CHECKAUX_OKAY:
56191- fscache_stat(&fscache_n_checkaux_okay);
56192+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56193 break;
56194
56195 /* entry requires update */
56196 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56197- fscache_stat(&fscache_n_checkaux_update);
56198+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56199 break;
56200
56201 /* entry requires deletion */
56202 case FSCACHE_CHECKAUX_OBSOLETE:
56203- fscache_stat(&fscache_n_checkaux_obsolete);
56204+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56205 break;
56206
56207 default:
56208@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56209 {
56210 const struct fscache_state *s;
56211
56212- fscache_stat(&fscache_n_invalidates_run);
56213+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56214 fscache_stat(&fscache_n_cop_invalidate_object);
56215 s = _fscache_invalidate_object(object, event);
56216 fscache_stat_d(&fscache_n_cop_invalidate_object);
56217@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56218 {
56219 _enter("{OBJ%x},%d", object->debug_id, event);
56220
56221- fscache_stat(&fscache_n_updates_run);
56222+ fscache_stat_unchecked(&fscache_n_updates_run);
56223 fscache_stat(&fscache_n_cop_update_object);
56224 object->cache->ops->update_object(object);
56225 fscache_stat_d(&fscache_n_cop_update_object);
56226diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56227index 318071a..379938b 100644
56228--- a/fs/fscache/operation.c
56229+++ b/fs/fscache/operation.c
56230@@ -17,7 +17,7 @@
56231 #include <linux/slab.h>
56232 #include "internal.h"
56233
56234-atomic_t fscache_op_debug_id;
56235+atomic_unchecked_t fscache_op_debug_id;
56236 EXPORT_SYMBOL(fscache_op_debug_id);
56237
56238 /**
56239@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56240 ASSERTCMP(atomic_read(&op->usage), >, 0);
56241 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56242
56243- fscache_stat(&fscache_n_op_enqueue);
56244+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56245 switch (op->flags & FSCACHE_OP_TYPE) {
56246 case FSCACHE_OP_ASYNC:
56247 _debug("queue async");
56248@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56249 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56250 if (op->processor)
56251 fscache_enqueue_operation(op);
56252- fscache_stat(&fscache_n_op_run);
56253+ fscache_stat_unchecked(&fscache_n_op_run);
56254 }
56255
56256 /*
56257@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56258 if (object->n_in_progress > 0) {
56259 atomic_inc(&op->usage);
56260 list_add_tail(&op->pend_link, &object->pending_ops);
56261- fscache_stat(&fscache_n_op_pend);
56262+ fscache_stat_unchecked(&fscache_n_op_pend);
56263 } else if (!list_empty(&object->pending_ops)) {
56264 atomic_inc(&op->usage);
56265 list_add_tail(&op->pend_link, &object->pending_ops);
56266- fscache_stat(&fscache_n_op_pend);
56267+ fscache_stat_unchecked(&fscache_n_op_pend);
56268 fscache_start_operations(object);
56269 } else {
56270 ASSERTCMP(object->n_in_progress, ==, 0);
56271@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56272 object->n_exclusive++; /* reads and writes must wait */
56273 atomic_inc(&op->usage);
56274 list_add_tail(&op->pend_link, &object->pending_ops);
56275- fscache_stat(&fscache_n_op_pend);
56276+ fscache_stat_unchecked(&fscache_n_op_pend);
56277 ret = 0;
56278 } else {
56279 /* If we're in any other state, there must have been an I/O
56280@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56281 if (object->n_exclusive > 0) {
56282 atomic_inc(&op->usage);
56283 list_add_tail(&op->pend_link, &object->pending_ops);
56284- fscache_stat(&fscache_n_op_pend);
56285+ fscache_stat_unchecked(&fscache_n_op_pend);
56286 } else if (!list_empty(&object->pending_ops)) {
56287 atomic_inc(&op->usage);
56288 list_add_tail(&op->pend_link, &object->pending_ops);
56289- fscache_stat(&fscache_n_op_pend);
56290+ fscache_stat_unchecked(&fscache_n_op_pend);
56291 fscache_start_operations(object);
56292 } else {
56293 ASSERTCMP(object->n_exclusive, ==, 0);
56294@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56295 object->n_ops++;
56296 atomic_inc(&op->usage);
56297 list_add_tail(&op->pend_link, &object->pending_ops);
56298- fscache_stat(&fscache_n_op_pend);
56299+ fscache_stat_unchecked(&fscache_n_op_pend);
56300 ret = 0;
56301 } else if (fscache_object_is_dying(object)) {
56302- fscache_stat(&fscache_n_op_rejected);
56303+ fscache_stat_unchecked(&fscache_n_op_rejected);
56304 op->state = FSCACHE_OP_ST_CANCELLED;
56305 ret = -ENOBUFS;
56306 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56307@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56308 ret = -EBUSY;
56309 if (op->state == FSCACHE_OP_ST_PENDING) {
56310 ASSERT(!list_empty(&op->pend_link));
56311- fscache_stat(&fscache_n_op_cancelled);
56312+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56313 list_del_init(&op->pend_link);
56314 if (do_cancel)
56315 do_cancel(op);
56316@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56317 while (!list_empty(&object->pending_ops)) {
56318 op = list_entry(object->pending_ops.next,
56319 struct fscache_operation, pend_link);
56320- fscache_stat(&fscache_n_op_cancelled);
56321+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56322 list_del_init(&op->pend_link);
56323
56324 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56325@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56326 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56327 op->state = FSCACHE_OP_ST_DEAD;
56328
56329- fscache_stat(&fscache_n_op_release);
56330+ fscache_stat_unchecked(&fscache_n_op_release);
56331
56332 if (op->release) {
56333 op->release(op);
56334@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56335 * lock, and defer it otherwise */
56336 if (!spin_trylock(&object->lock)) {
56337 _debug("defer put");
56338- fscache_stat(&fscache_n_op_deferred_release);
56339+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56340
56341 cache = object->cache;
56342 spin_lock(&cache->op_gc_list_lock);
56343@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56344
56345 _debug("GC DEFERRED REL OBJ%x OP%x",
56346 object->debug_id, op->debug_id);
56347- fscache_stat(&fscache_n_op_gc);
56348+ fscache_stat_unchecked(&fscache_n_op_gc);
56349
56350 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56351 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56352diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56353index d479ab3..727a7f2 100644
56354--- a/fs/fscache/page.c
56355+++ b/fs/fscache/page.c
56356@@ -61,7 +61,7 @@ try_again:
56357 val = radix_tree_lookup(&cookie->stores, page->index);
56358 if (!val) {
56359 rcu_read_unlock();
56360- fscache_stat(&fscache_n_store_vmscan_not_storing);
56361+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56362 __fscache_uncache_page(cookie, page);
56363 return true;
56364 }
56365@@ -91,11 +91,11 @@ try_again:
56366 spin_unlock(&cookie->stores_lock);
56367
56368 if (xpage) {
56369- fscache_stat(&fscache_n_store_vmscan_cancelled);
56370- fscache_stat(&fscache_n_store_radix_deletes);
56371+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56372+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56373 ASSERTCMP(xpage, ==, page);
56374 } else {
56375- fscache_stat(&fscache_n_store_vmscan_gone);
56376+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56377 }
56378
56379 wake_up_bit(&cookie->flags, 0);
56380@@ -110,11 +110,11 @@ page_busy:
56381 * sleeping on memory allocation, so we may need to impose a timeout
56382 * too. */
56383 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56384- fscache_stat(&fscache_n_store_vmscan_busy);
56385+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56386 return false;
56387 }
56388
56389- fscache_stat(&fscache_n_store_vmscan_wait);
56390+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56391 __fscache_wait_on_page_write(cookie, page);
56392 gfp &= ~__GFP_WAIT;
56393 goto try_again;
56394@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56395 FSCACHE_COOKIE_STORING_TAG);
56396 if (!radix_tree_tag_get(&cookie->stores, page->index,
56397 FSCACHE_COOKIE_PENDING_TAG)) {
56398- fscache_stat(&fscache_n_store_radix_deletes);
56399+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56400 xpage = radix_tree_delete(&cookie->stores, page->index);
56401 }
56402 spin_unlock(&cookie->stores_lock);
56403@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56404
56405 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56406
56407- fscache_stat(&fscache_n_attr_changed_calls);
56408+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56409
56410 if (fscache_object_is_active(object) &&
56411 fscache_use_cookie(object)) {
56412@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56413
56414 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56415
56416- fscache_stat(&fscache_n_attr_changed);
56417+ fscache_stat_unchecked(&fscache_n_attr_changed);
56418
56419 op = kzalloc(sizeof(*op), GFP_KERNEL);
56420 if (!op) {
56421- fscache_stat(&fscache_n_attr_changed_nomem);
56422+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56423 _leave(" = -ENOMEM");
56424 return -ENOMEM;
56425 }
56426@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56427 if (fscache_submit_exclusive_op(object, op) < 0)
56428 goto nobufs;
56429 spin_unlock(&cookie->lock);
56430- fscache_stat(&fscache_n_attr_changed_ok);
56431+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56432 fscache_put_operation(op);
56433 _leave(" = 0");
56434 return 0;
56435@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56436 nobufs:
56437 spin_unlock(&cookie->lock);
56438 kfree(op);
56439- fscache_stat(&fscache_n_attr_changed_nobufs);
56440+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56441 _leave(" = %d", -ENOBUFS);
56442 return -ENOBUFS;
56443 }
56444@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56445 /* allocate a retrieval operation and attempt to submit it */
56446 op = kzalloc(sizeof(*op), GFP_NOIO);
56447 if (!op) {
56448- fscache_stat(&fscache_n_retrievals_nomem);
56449+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56450 return NULL;
56451 }
56452
56453@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56454 return 0;
56455 }
56456
56457- fscache_stat(&fscache_n_retrievals_wait);
56458+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56459
56460 jif = jiffies;
56461 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56462 fscache_wait_bit_interruptible,
56463 TASK_INTERRUPTIBLE) != 0) {
56464- fscache_stat(&fscache_n_retrievals_intr);
56465+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56466 _leave(" = -ERESTARTSYS");
56467 return -ERESTARTSYS;
56468 }
56469@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56470 */
56471 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56472 struct fscache_retrieval *op,
56473- atomic_t *stat_op_waits,
56474- atomic_t *stat_object_dead)
56475+ atomic_unchecked_t *stat_op_waits,
56476+ atomic_unchecked_t *stat_object_dead)
56477 {
56478 int ret;
56479
56480@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56481 goto check_if_dead;
56482
56483 _debug(">>> WT");
56484- fscache_stat(stat_op_waits);
56485+ fscache_stat_unchecked(stat_op_waits);
56486 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56487 fscache_wait_bit_interruptible,
56488 TASK_INTERRUPTIBLE) != 0) {
56489@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56490
56491 check_if_dead:
56492 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56493- fscache_stat(stat_object_dead);
56494+ fscache_stat_unchecked(stat_object_dead);
56495 _leave(" = -ENOBUFS [cancelled]");
56496 return -ENOBUFS;
56497 }
56498 if (unlikely(fscache_object_is_dead(object))) {
56499 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56500 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56501- fscache_stat(stat_object_dead);
56502+ fscache_stat_unchecked(stat_object_dead);
56503 return -ENOBUFS;
56504 }
56505 return 0;
56506@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56507
56508 _enter("%p,%p,,,", cookie, page);
56509
56510- fscache_stat(&fscache_n_retrievals);
56511+ fscache_stat_unchecked(&fscache_n_retrievals);
56512
56513 if (hlist_empty(&cookie->backing_objects))
56514 goto nobufs;
56515@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56516 goto nobufs_unlock_dec;
56517 spin_unlock(&cookie->lock);
56518
56519- fscache_stat(&fscache_n_retrieval_ops);
56520+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56521
56522 /* pin the netfs read context in case we need to do the actual netfs
56523 * read because we've encountered a cache read failure */
56524@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56525
56526 error:
56527 if (ret == -ENOMEM)
56528- fscache_stat(&fscache_n_retrievals_nomem);
56529+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56530 else if (ret == -ERESTARTSYS)
56531- fscache_stat(&fscache_n_retrievals_intr);
56532+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56533 else if (ret == -ENODATA)
56534- fscache_stat(&fscache_n_retrievals_nodata);
56535+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56536 else if (ret < 0)
56537- fscache_stat(&fscache_n_retrievals_nobufs);
56538+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56539 else
56540- fscache_stat(&fscache_n_retrievals_ok);
56541+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56542
56543 fscache_put_retrieval(op);
56544 _leave(" = %d", ret);
56545@@ -475,7 +475,7 @@ nobufs_unlock:
56546 atomic_dec(&cookie->n_active);
56547 kfree(op);
56548 nobufs:
56549- fscache_stat(&fscache_n_retrievals_nobufs);
56550+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56551 _leave(" = -ENOBUFS");
56552 return -ENOBUFS;
56553 }
56554@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56555
56556 _enter("%p,,%d,,,", cookie, *nr_pages);
56557
56558- fscache_stat(&fscache_n_retrievals);
56559+ fscache_stat_unchecked(&fscache_n_retrievals);
56560
56561 if (hlist_empty(&cookie->backing_objects))
56562 goto nobufs;
56563@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56564 goto nobufs_unlock_dec;
56565 spin_unlock(&cookie->lock);
56566
56567- fscache_stat(&fscache_n_retrieval_ops);
56568+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56569
56570 /* pin the netfs read context in case we need to do the actual netfs
56571 * read because we've encountered a cache read failure */
56572@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56573
56574 error:
56575 if (ret == -ENOMEM)
56576- fscache_stat(&fscache_n_retrievals_nomem);
56577+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56578 else if (ret == -ERESTARTSYS)
56579- fscache_stat(&fscache_n_retrievals_intr);
56580+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56581 else if (ret == -ENODATA)
56582- fscache_stat(&fscache_n_retrievals_nodata);
56583+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56584 else if (ret < 0)
56585- fscache_stat(&fscache_n_retrievals_nobufs);
56586+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56587 else
56588- fscache_stat(&fscache_n_retrievals_ok);
56589+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56590
56591 fscache_put_retrieval(op);
56592 _leave(" = %d", ret);
56593@@ -600,7 +600,7 @@ nobufs_unlock:
56594 atomic_dec(&cookie->n_active);
56595 kfree(op);
56596 nobufs:
56597- fscache_stat(&fscache_n_retrievals_nobufs);
56598+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56599 _leave(" = -ENOBUFS");
56600 return -ENOBUFS;
56601 }
56602@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56603
56604 _enter("%p,%p,,,", cookie, page);
56605
56606- fscache_stat(&fscache_n_allocs);
56607+ fscache_stat_unchecked(&fscache_n_allocs);
56608
56609 if (hlist_empty(&cookie->backing_objects))
56610 goto nobufs;
56611@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56612 goto nobufs_unlock;
56613 spin_unlock(&cookie->lock);
56614
56615- fscache_stat(&fscache_n_alloc_ops);
56616+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56617
56618 ret = fscache_wait_for_retrieval_activation(
56619 object, op,
56620@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56621
56622 error:
56623 if (ret == -ERESTARTSYS)
56624- fscache_stat(&fscache_n_allocs_intr);
56625+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56626 else if (ret < 0)
56627- fscache_stat(&fscache_n_allocs_nobufs);
56628+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56629 else
56630- fscache_stat(&fscache_n_allocs_ok);
56631+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56632
56633 fscache_put_retrieval(op);
56634 _leave(" = %d", ret);
56635@@ -687,7 +687,7 @@ nobufs_unlock:
56636 atomic_dec(&cookie->n_active);
56637 kfree(op);
56638 nobufs:
56639- fscache_stat(&fscache_n_allocs_nobufs);
56640+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56641 _leave(" = -ENOBUFS");
56642 return -ENOBUFS;
56643 }
56644@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56645
56646 spin_lock(&cookie->stores_lock);
56647
56648- fscache_stat(&fscache_n_store_calls);
56649+ fscache_stat_unchecked(&fscache_n_store_calls);
56650
56651 /* find a page to store */
56652 page = NULL;
56653@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56654 page = results[0];
56655 _debug("gang %d [%lx]", n, page->index);
56656 if (page->index > op->store_limit) {
56657- fscache_stat(&fscache_n_store_pages_over_limit);
56658+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56659 goto superseded;
56660 }
56661
56662@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56663 spin_unlock(&cookie->stores_lock);
56664 spin_unlock(&object->lock);
56665
56666- fscache_stat(&fscache_n_store_pages);
56667+ fscache_stat_unchecked(&fscache_n_store_pages);
56668 fscache_stat(&fscache_n_cop_write_page);
56669 ret = object->cache->ops->write_page(op, page);
56670 fscache_stat_d(&fscache_n_cop_write_page);
56671@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56672 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56673 ASSERT(PageFsCache(page));
56674
56675- fscache_stat(&fscache_n_stores);
56676+ fscache_stat_unchecked(&fscache_n_stores);
56677
56678 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56679 _leave(" = -ENOBUFS [invalidating]");
56680@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56681 spin_unlock(&cookie->stores_lock);
56682 spin_unlock(&object->lock);
56683
56684- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56685+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56686 op->store_limit = object->store_limit;
56687
56688 atomic_inc(&cookie->n_active);
56689@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56690
56691 spin_unlock(&cookie->lock);
56692 radix_tree_preload_end();
56693- fscache_stat(&fscache_n_store_ops);
56694- fscache_stat(&fscache_n_stores_ok);
56695+ fscache_stat_unchecked(&fscache_n_store_ops);
56696+ fscache_stat_unchecked(&fscache_n_stores_ok);
56697
56698 /* the work queue now carries its own ref on the object */
56699 fscache_put_operation(&op->op);
56700@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56701 return 0;
56702
56703 already_queued:
56704- fscache_stat(&fscache_n_stores_again);
56705+ fscache_stat_unchecked(&fscache_n_stores_again);
56706 already_pending:
56707 spin_unlock(&cookie->stores_lock);
56708 spin_unlock(&object->lock);
56709 spin_unlock(&cookie->lock);
56710 radix_tree_preload_end();
56711 kfree(op);
56712- fscache_stat(&fscache_n_stores_ok);
56713+ fscache_stat_unchecked(&fscache_n_stores_ok);
56714 _leave(" = 0");
56715 return 0;
56716
56717@@ -976,14 +976,14 @@ nobufs:
56718 spin_unlock(&cookie->lock);
56719 radix_tree_preload_end();
56720 kfree(op);
56721- fscache_stat(&fscache_n_stores_nobufs);
56722+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56723 _leave(" = -ENOBUFS");
56724 return -ENOBUFS;
56725
56726 nomem_free:
56727 kfree(op);
56728 nomem:
56729- fscache_stat(&fscache_n_stores_oom);
56730+ fscache_stat_unchecked(&fscache_n_stores_oom);
56731 _leave(" = -ENOMEM");
56732 return -ENOMEM;
56733 }
56734@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56735 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56736 ASSERTCMP(page, !=, NULL);
56737
56738- fscache_stat(&fscache_n_uncaches);
56739+ fscache_stat_unchecked(&fscache_n_uncaches);
56740
56741 /* cache withdrawal may beat us to it */
56742 if (!PageFsCache(page))
56743@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56744 struct fscache_cookie *cookie = op->op.object->cookie;
56745
56746 #ifdef CONFIG_FSCACHE_STATS
56747- atomic_inc(&fscache_n_marks);
56748+ atomic_inc_unchecked(&fscache_n_marks);
56749 #endif
56750
56751 _debug("- mark %p{%lx}", page, page->index);
56752diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56753index 40d13c7..ddf52b9 100644
56754--- a/fs/fscache/stats.c
56755+++ b/fs/fscache/stats.c
56756@@ -18,99 +18,99 @@
56757 /*
56758 * operation counters
56759 */
56760-atomic_t fscache_n_op_pend;
56761-atomic_t fscache_n_op_run;
56762-atomic_t fscache_n_op_enqueue;
56763-atomic_t fscache_n_op_requeue;
56764-atomic_t fscache_n_op_deferred_release;
56765-atomic_t fscache_n_op_release;
56766-atomic_t fscache_n_op_gc;
56767-atomic_t fscache_n_op_cancelled;
56768-atomic_t fscache_n_op_rejected;
56769+atomic_unchecked_t fscache_n_op_pend;
56770+atomic_unchecked_t fscache_n_op_run;
56771+atomic_unchecked_t fscache_n_op_enqueue;
56772+atomic_unchecked_t fscache_n_op_requeue;
56773+atomic_unchecked_t fscache_n_op_deferred_release;
56774+atomic_unchecked_t fscache_n_op_release;
56775+atomic_unchecked_t fscache_n_op_gc;
56776+atomic_unchecked_t fscache_n_op_cancelled;
56777+atomic_unchecked_t fscache_n_op_rejected;
56778
56779-atomic_t fscache_n_attr_changed;
56780-atomic_t fscache_n_attr_changed_ok;
56781-atomic_t fscache_n_attr_changed_nobufs;
56782-atomic_t fscache_n_attr_changed_nomem;
56783-atomic_t fscache_n_attr_changed_calls;
56784+atomic_unchecked_t fscache_n_attr_changed;
56785+atomic_unchecked_t fscache_n_attr_changed_ok;
56786+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56787+atomic_unchecked_t fscache_n_attr_changed_nomem;
56788+atomic_unchecked_t fscache_n_attr_changed_calls;
56789
56790-atomic_t fscache_n_allocs;
56791-atomic_t fscache_n_allocs_ok;
56792-atomic_t fscache_n_allocs_wait;
56793-atomic_t fscache_n_allocs_nobufs;
56794-atomic_t fscache_n_allocs_intr;
56795-atomic_t fscache_n_allocs_object_dead;
56796-atomic_t fscache_n_alloc_ops;
56797-atomic_t fscache_n_alloc_op_waits;
56798+atomic_unchecked_t fscache_n_allocs;
56799+atomic_unchecked_t fscache_n_allocs_ok;
56800+atomic_unchecked_t fscache_n_allocs_wait;
56801+atomic_unchecked_t fscache_n_allocs_nobufs;
56802+atomic_unchecked_t fscache_n_allocs_intr;
56803+atomic_unchecked_t fscache_n_allocs_object_dead;
56804+atomic_unchecked_t fscache_n_alloc_ops;
56805+atomic_unchecked_t fscache_n_alloc_op_waits;
56806
56807-atomic_t fscache_n_retrievals;
56808-atomic_t fscache_n_retrievals_ok;
56809-atomic_t fscache_n_retrievals_wait;
56810-atomic_t fscache_n_retrievals_nodata;
56811-atomic_t fscache_n_retrievals_nobufs;
56812-atomic_t fscache_n_retrievals_intr;
56813-atomic_t fscache_n_retrievals_nomem;
56814-atomic_t fscache_n_retrievals_object_dead;
56815-atomic_t fscache_n_retrieval_ops;
56816-atomic_t fscache_n_retrieval_op_waits;
56817+atomic_unchecked_t fscache_n_retrievals;
56818+atomic_unchecked_t fscache_n_retrievals_ok;
56819+atomic_unchecked_t fscache_n_retrievals_wait;
56820+atomic_unchecked_t fscache_n_retrievals_nodata;
56821+atomic_unchecked_t fscache_n_retrievals_nobufs;
56822+atomic_unchecked_t fscache_n_retrievals_intr;
56823+atomic_unchecked_t fscache_n_retrievals_nomem;
56824+atomic_unchecked_t fscache_n_retrievals_object_dead;
56825+atomic_unchecked_t fscache_n_retrieval_ops;
56826+atomic_unchecked_t fscache_n_retrieval_op_waits;
56827
56828-atomic_t fscache_n_stores;
56829-atomic_t fscache_n_stores_ok;
56830-atomic_t fscache_n_stores_again;
56831-atomic_t fscache_n_stores_nobufs;
56832-atomic_t fscache_n_stores_oom;
56833-atomic_t fscache_n_store_ops;
56834-atomic_t fscache_n_store_calls;
56835-atomic_t fscache_n_store_pages;
56836-atomic_t fscache_n_store_radix_deletes;
56837-atomic_t fscache_n_store_pages_over_limit;
56838+atomic_unchecked_t fscache_n_stores;
56839+atomic_unchecked_t fscache_n_stores_ok;
56840+atomic_unchecked_t fscache_n_stores_again;
56841+atomic_unchecked_t fscache_n_stores_nobufs;
56842+atomic_unchecked_t fscache_n_stores_oom;
56843+atomic_unchecked_t fscache_n_store_ops;
56844+atomic_unchecked_t fscache_n_store_calls;
56845+atomic_unchecked_t fscache_n_store_pages;
56846+atomic_unchecked_t fscache_n_store_radix_deletes;
56847+atomic_unchecked_t fscache_n_store_pages_over_limit;
56848
56849-atomic_t fscache_n_store_vmscan_not_storing;
56850-atomic_t fscache_n_store_vmscan_gone;
56851-atomic_t fscache_n_store_vmscan_busy;
56852-atomic_t fscache_n_store_vmscan_cancelled;
56853-atomic_t fscache_n_store_vmscan_wait;
56854+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56855+atomic_unchecked_t fscache_n_store_vmscan_gone;
56856+atomic_unchecked_t fscache_n_store_vmscan_busy;
56857+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56858+atomic_unchecked_t fscache_n_store_vmscan_wait;
56859
56860-atomic_t fscache_n_marks;
56861-atomic_t fscache_n_uncaches;
56862+atomic_unchecked_t fscache_n_marks;
56863+atomic_unchecked_t fscache_n_uncaches;
56864
56865-atomic_t fscache_n_acquires;
56866-atomic_t fscache_n_acquires_null;
56867-atomic_t fscache_n_acquires_no_cache;
56868-atomic_t fscache_n_acquires_ok;
56869-atomic_t fscache_n_acquires_nobufs;
56870-atomic_t fscache_n_acquires_oom;
56871+atomic_unchecked_t fscache_n_acquires;
56872+atomic_unchecked_t fscache_n_acquires_null;
56873+atomic_unchecked_t fscache_n_acquires_no_cache;
56874+atomic_unchecked_t fscache_n_acquires_ok;
56875+atomic_unchecked_t fscache_n_acquires_nobufs;
56876+atomic_unchecked_t fscache_n_acquires_oom;
56877
56878-atomic_t fscache_n_invalidates;
56879-atomic_t fscache_n_invalidates_run;
56880+atomic_unchecked_t fscache_n_invalidates;
56881+atomic_unchecked_t fscache_n_invalidates_run;
56882
56883-atomic_t fscache_n_updates;
56884-atomic_t fscache_n_updates_null;
56885-atomic_t fscache_n_updates_run;
56886+atomic_unchecked_t fscache_n_updates;
56887+atomic_unchecked_t fscache_n_updates_null;
56888+atomic_unchecked_t fscache_n_updates_run;
56889
56890-atomic_t fscache_n_relinquishes;
56891-atomic_t fscache_n_relinquishes_null;
56892-atomic_t fscache_n_relinquishes_waitcrt;
56893-atomic_t fscache_n_relinquishes_retire;
56894+atomic_unchecked_t fscache_n_relinquishes;
56895+atomic_unchecked_t fscache_n_relinquishes_null;
56896+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56897+atomic_unchecked_t fscache_n_relinquishes_retire;
56898
56899-atomic_t fscache_n_cookie_index;
56900-atomic_t fscache_n_cookie_data;
56901-atomic_t fscache_n_cookie_special;
56902+atomic_unchecked_t fscache_n_cookie_index;
56903+atomic_unchecked_t fscache_n_cookie_data;
56904+atomic_unchecked_t fscache_n_cookie_special;
56905
56906-atomic_t fscache_n_object_alloc;
56907-atomic_t fscache_n_object_no_alloc;
56908-atomic_t fscache_n_object_lookups;
56909-atomic_t fscache_n_object_lookups_negative;
56910-atomic_t fscache_n_object_lookups_positive;
56911-atomic_t fscache_n_object_lookups_timed_out;
56912-atomic_t fscache_n_object_created;
56913-atomic_t fscache_n_object_avail;
56914-atomic_t fscache_n_object_dead;
56915+atomic_unchecked_t fscache_n_object_alloc;
56916+atomic_unchecked_t fscache_n_object_no_alloc;
56917+atomic_unchecked_t fscache_n_object_lookups;
56918+atomic_unchecked_t fscache_n_object_lookups_negative;
56919+atomic_unchecked_t fscache_n_object_lookups_positive;
56920+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56921+atomic_unchecked_t fscache_n_object_created;
56922+atomic_unchecked_t fscache_n_object_avail;
56923+atomic_unchecked_t fscache_n_object_dead;
56924
56925-atomic_t fscache_n_checkaux_none;
56926-atomic_t fscache_n_checkaux_okay;
56927-atomic_t fscache_n_checkaux_update;
56928-atomic_t fscache_n_checkaux_obsolete;
56929+atomic_unchecked_t fscache_n_checkaux_none;
56930+atomic_unchecked_t fscache_n_checkaux_okay;
56931+atomic_unchecked_t fscache_n_checkaux_update;
56932+atomic_unchecked_t fscache_n_checkaux_obsolete;
56933
56934 atomic_t fscache_n_cop_alloc_object;
56935 atomic_t fscache_n_cop_lookup_object;
56936@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56937 seq_puts(m, "FS-Cache statistics\n");
56938
56939 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56940- atomic_read(&fscache_n_cookie_index),
56941- atomic_read(&fscache_n_cookie_data),
56942- atomic_read(&fscache_n_cookie_special));
56943+ atomic_read_unchecked(&fscache_n_cookie_index),
56944+ atomic_read_unchecked(&fscache_n_cookie_data),
56945+ atomic_read_unchecked(&fscache_n_cookie_special));
56946
56947 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56948- atomic_read(&fscache_n_object_alloc),
56949- atomic_read(&fscache_n_object_no_alloc),
56950- atomic_read(&fscache_n_object_avail),
56951- atomic_read(&fscache_n_object_dead));
56952+ atomic_read_unchecked(&fscache_n_object_alloc),
56953+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56954+ atomic_read_unchecked(&fscache_n_object_avail),
56955+ atomic_read_unchecked(&fscache_n_object_dead));
56956 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56957- atomic_read(&fscache_n_checkaux_none),
56958- atomic_read(&fscache_n_checkaux_okay),
56959- atomic_read(&fscache_n_checkaux_update),
56960- atomic_read(&fscache_n_checkaux_obsolete));
56961+ atomic_read_unchecked(&fscache_n_checkaux_none),
56962+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56963+ atomic_read_unchecked(&fscache_n_checkaux_update),
56964+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56965
56966 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56967- atomic_read(&fscache_n_marks),
56968- atomic_read(&fscache_n_uncaches));
56969+ atomic_read_unchecked(&fscache_n_marks),
56970+ atomic_read_unchecked(&fscache_n_uncaches));
56971
56972 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56973 " oom=%u\n",
56974- atomic_read(&fscache_n_acquires),
56975- atomic_read(&fscache_n_acquires_null),
56976- atomic_read(&fscache_n_acquires_no_cache),
56977- atomic_read(&fscache_n_acquires_ok),
56978- atomic_read(&fscache_n_acquires_nobufs),
56979- atomic_read(&fscache_n_acquires_oom));
56980+ atomic_read_unchecked(&fscache_n_acquires),
56981+ atomic_read_unchecked(&fscache_n_acquires_null),
56982+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
56983+ atomic_read_unchecked(&fscache_n_acquires_ok),
56984+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
56985+ atomic_read_unchecked(&fscache_n_acquires_oom));
56986
56987 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
56988- atomic_read(&fscache_n_object_lookups),
56989- atomic_read(&fscache_n_object_lookups_negative),
56990- atomic_read(&fscache_n_object_lookups_positive),
56991- atomic_read(&fscache_n_object_created),
56992- atomic_read(&fscache_n_object_lookups_timed_out));
56993+ atomic_read_unchecked(&fscache_n_object_lookups),
56994+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
56995+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
56996+ atomic_read_unchecked(&fscache_n_object_created),
56997+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
56998
56999 seq_printf(m, "Invals : n=%u run=%u\n",
57000- atomic_read(&fscache_n_invalidates),
57001- atomic_read(&fscache_n_invalidates_run));
57002+ atomic_read_unchecked(&fscache_n_invalidates),
57003+ atomic_read_unchecked(&fscache_n_invalidates_run));
57004
57005 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57006- atomic_read(&fscache_n_updates),
57007- atomic_read(&fscache_n_updates_null),
57008- atomic_read(&fscache_n_updates_run));
57009+ atomic_read_unchecked(&fscache_n_updates),
57010+ atomic_read_unchecked(&fscache_n_updates_null),
57011+ atomic_read_unchecked(&fscache_n_updates_run));
57012
57013 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57014- atomic_read(&fscache_n_relinquishes),
57015- atomic_read(&fscache_n_relinquishes_null),
57016- atomic_read(&fscache_n_relinquishes_waitcrt),
57017- atomic_read(&fscache_n_relinquishes_retire));
57018+ atomic_read_unchecked(&fscache_n_relinquishes),
57019+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57020+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57021+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57022
57023 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57024- atomic_read(&fscache_n_attr_changed),
57025- atomic_read(&fscache_n_attr_changed_ok),
57026- atomic_read(&fscache_n_attr_changed_nobufs),
57027- atomic_read(&fscache_n_attr_changed_nomem),
57028- atomic_read(&fscache_n_attr_changed_calls));
57029+ atomic_read_unchecked(&fscache_n_attr_changed),
57030+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57031+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57032+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57033+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57034
57035 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57036- atomic_read(&fscache_n_allocs),
57037- atomic_read(&fscache_n_allocs_ok),
57038- atomic_read(&fscache_n_allocs_wait),
57039- atomic_read(&fscache_n_allocs_nobufs),
57040- atomic_read(&fscache_n_allocs_intr));
57041+ atomic_read_unchecked(&fscache_n_allocs),
57042+ atomic_read_unchecked(&fscache_n_allocs_ok),
57043+ atomic_read_unchecked(&fscache_n_allocs_wait),
57044+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57045+ atomic_read_unchecked(&fscache_n_allocs_intr));
57046 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57047- atomic_read(&fscache_n_alloc_ops),
57048- atomic_read(&fscache_n_alloc_op_waits),
57049- atomic_read(&fscache_n_allocs_object_dead));
57050+ atomic_read_unchecked(&fscache_n_alloc_ops),
57051+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57052+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57053
57054 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57055 " int=%u oom=%u\n",
57056- atomic_read(&fscache_n_retrievals),
57057- atomic_read(&fscache_n_retrievals_ok),
57058- atomic_read(&fscache_n_retrievals_wait),
57059- atomic_read(&fscache_n_retrievals_nodata),
57060- atomic_read(&fscache_n_retrievals_nobufs),
57061- atomic_read(&fscache_n_retrievals_intr),
57062- atomic_read(&fscache_n_retrievals_nomem));
57063+ atomic_read_unchecked(&fscache_n_retrievals),
57064+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57065+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57066+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57067+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57068+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57069+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57070 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57071- atomic_read(&fscache_n_retrieval_ops),
57072- atomic_read(&fscache_n_retrieval_op_waits),
57073- atomic_read(&fscache_n_retrievals_object_dead));
57074+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57075+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57076+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57077
57078 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57079- atomic_read(&fscache_n_stores),
57080- atomic_read(&fscache_n_stores_ok),
57081- atomic_read(&fscache_n_stores_again),
57082- atomic_read(&fscache_n_stores_nobufs),
57083- atomic_read(&fscache_n_stores_oom));
57084+ atomic_read_unchecked(&fscache_n_stores),
57085+ atomic_read_unchecked(&fscache_n_stores_ok),
57086+ atomic_read_unchecked(&fscache_n_stores_again),
57087+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57088+ atomic_read_unchecked(&fscache_n_stores_oom));
57089 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57090- atomic_read(&fscache_n_store_ops),
57091- atomic_read(&fscache_n_store_calls),
57092- atomic_read(&fscache_n_store_pages),
57093- atomic_read(&fscache_n_store_radix_deletes),
57094- atomic_read(&fscache_n_store_pages_over_limit));
57095+ atomic_read_unchecked(&fscache_n_store_ops),
57096+ atomic_read_unchecked(&fscache_n_store_calls),
57097+ atomic_read_unchecked(&fscache_n_store_pages),
57098+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57099+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57100
57101 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57102- atomic_read(&fscache_n_store_vmscan_not_storing),
57103- atomic_read(&fscache_n_store_vmscan_gone),
57104- atomic_read(&fscache_n_store_vmscan_busy),
57105- atomic_read(&fscache_n_store_vmscan_cancelled),
57106- atomic_read(&fscache_n_store_vmscan_wait));
57107+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57108+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57109+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57110+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57111+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57112
57113 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57114- atomic_read(&fscache_n_op_pend),
57115- atomic_read(&fscache_n_op_run),
57116- atomic_read(&fscache_n_op_enqueue),
57117- atomic_read(&fscache_n_op_cancelled),
57118- atomic_read(&fscache_n_op_rejected));
57119+ atomic_read_unchecked(&fscache_n_op_pend),
57120+ atomic_read_unchecked(&fscache_n_op_run),
57121+ atomic_read_unchecked(&fscache_n_op_enqueue),
57122+ atomic_read_unchecked(&fscache_n_op_cancelled),
57123+ atomic_read_unchecked(&fscache_n_op_rejected));
57124 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57125- atomic_read(&fscache_n_op_deferred_release),
57126- atomic_read(&fscache_n_op_release),
57127- atomic_read(&fscache_n_op_gc));
57128+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57129+ atomic_read_unchecked(&fscache_n_op_release),
57130+ atomic_read_unchecked(&fscache_n_op_gc));
57131
57132 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57133 atomic_read(&fscache_n_cop_alloc_object),
57134diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57135index aef34b1..59bfd7b 100644
57136--- a/fs/fuse/cuse.c
57137+++ b/fs/fuse/cuse.c
57138@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57139 INIT_LIST_HEAD(&cuse_conntbl[i]);
57140
57141 /* inherit and extend fuse_dev_operations */
57142- cuse_channel_fops = fuse_dev_operations;
57143- cuse_channel_fops.owner = THIS_MODULE;
57144- cuse_channel_fops.open = cuse_channel_open;
57145- cuse_channel_fops.release = cuse_channel_release;
57146+ pax_open_kernel();
57147+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57148+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57149+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57150+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57151+ pax_close_kernel();
57152
57153 cuse_class = class_create(THIS_MODULE, "cuse");
57154 if (IS_ERR(cuse_class))
57155diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57156index 1d55f94..088da65 100644
57157--- a/fs/fuse/dev.c
57158+++ b/fs/fuse/dev.c
57159@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57160 ret = 0;
57161 pipe_lock(pipe);
57162
57163- if (!pipe->readers) {
57164+ if (!atomic_read(&pipe->readers)) {
57165 send_sig(SIGPIPE, current, 0);
57166 if (!ret)
57167 ret = -EPIPE;
57168@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57169 page_nr++;
57170 ret += buf->len;
57171
57172- if (pipe->files)
57173+ if (atomic_read(&pipe->files))
57174 do_wakeup = 1;
57175 }
57176
57177diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57178index 8fec28f..cd40dba 100644
57179--- a/fs/fuse/dir.c
57180+++ b/fs/fuse/dir.c
57181@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
57182 return link;
57183 }
57184
57185-static void free_link(char *link)
57186+static void free_link(const char *link)
57187 {
57188 if (!IS_ERR(link))
57189 free_page((unsigned long) link);
57190diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57191index 64915ee..6bed500 100644
57192--- a/fs/gfs2/inode.c
57193+++ b/fs/gfs2/inode.c
57194@@ -1506,7 +1506,7 @@ out:
57195
57196 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57197 {
57198- char *s = nd_get_link(nd);
57199+ const char *s = nd_get_link(nd);
57200 if (!IS_ERR(s))
57201 kfree(s);
57202 }
57203diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57204index d19b30a..ef89c36 100644
57205--- a/fs/hugetlbfs/inode.c
57206+++ b/fs/hugetlbfs/inode.c
57207@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57208 struct mm_struct *mm = current->mm;
57209 struct vm_area_struct *vma;
57210 struct hstate *h = hstate_file(file);
57211+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57212 struct vm_unmapped_area_info info;
57213
57214 if (len & ~huge_page_mask(h))
57215@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57216 return addr;
57217 }
57218
57219+#ifdef CONFIG_PAX_RANDMMAP
57220+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57221+#endif
57222+
57223 if (addr) {
57224 addr = ALIGN(addr, huge_page_size(h));
57225 vma = find_vma(mm, addr);
57226- if (TASK_SIZE - len >= addr &&
57227- (!vma || addr + len <= vma->vm_start))
57228+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57229 return addr;
57230 }
57231
57232 info.flags = 0;
57233 info.length = len;
57234 info.low_limit = TASK_UNMAPPED_BASE;
57235+
57236+#ifdef CONFIG_PAX_RANDMMAP
57237+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57238+ info.low_limit += mm->delta_mmap;
57239+#endif
57240+
57241 info.high_limit = TASK_SIZE;
57242 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57243 info.align_offset = 0;
57244@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57245 };
57246 MODULE_ALIAS_FS("hugetlbfs");
57247
57248-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57249+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57250
57251 static int can_do_hugetlb_shm(void)
57252 {
57253diff --git a/fs/inode.c b/fs/inode.c
57254index d6dfb09..602e77e 100644
57255--- a/fs/inode.c
57256+++ b/fs/inode.c
57257@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57258
57259 #ifdef CONFIG_SMP
57260 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57261- static atomic_t shared_last_ino;
57262- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57263+ static atomic_unchecked_t shared_last_ino;
57264+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57265
57266 res = next - LAST_INO_BATCH;
57267 }
57268diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57269index 4a6cf28..d3a29d3 100644
57270--- a/fs/jffs2/erase.c
57271+++ b/fs/jffs2/erase.c
57272@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57273 struct jffs2_unknown_node marker = {
57274 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57275 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57276- .totlen = cpu_to_je32(c->cleanmarker_size)
57277+ .totlen = cpu_to_je32(c->cleanmarker_size),
57278+ .hdr_crc = cpu_to_je32(0)
57279 };
57280
57281 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57282diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57283index a6597d6..41b30ec 100644
57284--- a/fs/jffs2/wbuf.c
57285+++ b/fs/jffs2/wbuf.c
57286@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57287 {
57288 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57289 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57290- .totlen = constant_cpu_to_je32(8)
57291+ .totlen = constant_cpu_to_je32(8),
57292+ .hdr_crc = constant_cpu_to_je32(0)
57293 };
57294
57295 /*
57296diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57297index 6669aa2..36b033d 100644
57298--- a/fs/jfs/super.c
57299+++ b/fs/jfs/super.c
57300@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57301
57302 jfs_inode_cachep =
57303 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57304- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57305+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57306 init_once);
57307 if (jfs_inode_cachep == NULL)
57308 return -ENOMEM;
57309diff --git a/fs/libfs.c b/fs/libfs.c
57310index 3a3a9b5..3a9b074 100644
57311--- a/fs/libfs.c
57312+++ b/fs/libfs.c
57313@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57314
57315 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57316 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57317+ char d_name[sizeof(next->d_iname)];
57318+ const unsigned char *name;
57319+
57320 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57321 if (!simple_positive(next)) {
57322 spin_unlock(&next->d_lock);
57323@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57324
57325 spin_unlock(&next->d_lock);
57326 spin_unlock(&dentry->d_lock);
57327- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57328+ name = next->d_name.name;
57329+ if (name == next->d_iname) {
57330+ memcpy(d_name, name, next->d_name.len);
57331+ name = d_name;
57332+ }
57333+ if (!dir_emit(ctx, name, next->d_name.len,
57334 next->d_inode->i_ino, dt_type(next->d_inode)))
57335 return 0;
57336 spin_lock(&dentry->d_lock);
57337diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57338index acd3947..1f896e2 100644
57339--- a/fs/lockd/clntproc.c
57340+++ b/fs/lockd/clntproc.c
57341@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57342 /*
57343 * Cookie counter for NLM requests
57344 */
57345-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57346+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57347
57348 void nlmclnt_next_cookie(struct nlm_cookie *c)
57349 {
57350- u32 cookie = atomic_inc_return(&nlm_cookie);
57351+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57352
57353 memcpy(c->data, &cookie, 4);
57354 c->len=4;
57355diff --git a/fs/locks.c b/fs/locks.c
57356index b27a300..4156d0b 100644
57357--- a/fs/locks.c
57358+++ b/fs/locks.c
57359@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57360 return;
57361
57362 if (filp->f_op && filp->f_op->flock) {
57363- struct file_lock fl = {
57364+ struct file_lock flock = {
57365 .fl_pid = current->tgid,
57366 .fl_file = filp,
57367 .fl_flags = FL_FLOCK,
57368 .fl_type = F_UNLCK,
57369 .fl_end = OFFSET_MAX,
57370 };
57371- filp->f_op->flock(filp, F_SETLKW, &fl);
57372- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57373- fl.fl_ops->fl_release_private(&fl);
57374+ filp->f_op->flock(filp, F_SETLKW, &flock);
57375+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57376+ flock.fl_ops->fl_release_private(&flock);
57377 }
57378
57379 spin_lock(&inode->i_lock);
57380diff --git a/fs/namei.c b/fs/namei.c
57381index 7720fbd..7934bb2 100644
57382--- a/fs/namei.c
57383+++ b/fs/namei.c
57384@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57385 if (ret != -EACCES)
57386 return ret;
57387
57388+#ifdef CONFIG_GRKERNSEC
57389+ /* we'll block if we have to log due to a denied capability use */
57390+ if (mask & MAY_NOT_BLOCK)
57391+ return -ECHILD;
57392+#endif
57393+
57394 if (S_ISDIR(inode->i_mode)) {
57395 /* DACs are overridable for directories */
57396- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57397- return 0;
57398 if (!(mask & MAY_WRITE))
57399- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57400+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57401+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57402 return 0;
57403+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57404+ return 0;
57405 return -EACCES;
57406 }
57407 /*
57408+ * Searching includes executable on directories, else just read.
57409+ */
57410+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57411+ if (mask == MAY_READ)
57412+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57413+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57414+ return 0;
57415+
57416+ /*
57417 * Read/write DACs are always overridable.
57418 * Executable DACs are overridable when there is
57419 * at least one exec bit set.
57420@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57421 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57422 return 0;
57423
57424- /*
57425- * Searching includes executable on directories, else just read.
57426- */
57427- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57428- if (mask == MAY_READ)
57429- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57430- return 0;
57431-
57432 return -EACCES;
57433 }
57434
57435@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57436 {
57437 struct dentry *dentry = link->dentry;
57438 int error;
57439- char *s;
57440+ const char *s;
57441
57442 BUG_ON(nd->flags & LOOKUP_RCU);
57443
57444@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57445 if (error)
57446 goto out_put_nd_path;
57447
57448+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57449+ dentry->d_inode, dentry, nd->path.mnt)) {
57450+ error = -EACCES;
57451+ goto out_put_nd_path;
57452+ }
57453+
57454 nd->last_type = LAST_BIND;
57455 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57456 error = PTR_ERR(*p);
57457@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57458 if (res)
57459 break;
57460 res = walk_component(nd, path, LOOKUP_FOLLOW);
57461+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57462+ res = -EACCES;
57463 put_link(nd, &link, cookie);
57464 } while (res > 0);
57465
57466@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57467 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57468 {
57469 unsigned long a, b, adata, bdata, mask, hash, len;
57470- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57471+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57472
57473 hash = a = 0;
57474 len = -sizeof(unsigned long);
57475@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57476 if (err)
57477 break;
57478 err = lookup_last(nd, &path);
57479+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57480+ err = -EACCES;
57481 put_link(nd, &link, cookie);
57482 }
57483 }
57484@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57485 if (!err)
57486 err = complete_walk(nd);
57487
57488+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57489+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57490+ path_put(&nd->path);
57491+ err = -ENOENT;
57492+ }
57493+ }
57494+
57495 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57496 if (!can_lookup(nd->inode)) {
57497 path_put(&nd->path);
57498@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57499 retval = path_lookupat(dfd, name->name,
57500 flags | LOOKUP_REVAL, nd);
57501
57502- if (likely(!retval))
57503+ if (likely(!retval)) {
57504 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57505+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57506+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57507+ path_put(&nd->path);
57508+ return -ENOENT;
57509+ }
57510+ }
57511+ }
57512 return retval;
57513 }
57514
57515@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57516 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57517 return -EPERM;
57518
57519+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57520+ return -EPERM;
57521+ if (gr_handle_rawio(inode))
57522+ return -EPERM;
57523+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57524+ return -EACCES;
57525+
57526 return 0;
57527 }
57528
57529@@ -2601,7 +2640,7 @@ looked_up:
57530 * cleared otherwise prior to returning.
57531 */
57532 static int lookup_open(struct nameidata *nd, struct path *path,
57533- struct file *file,
57534+ struct path *link, struct file *file,
57535 const struct open_flags *op,
57536 bool got_write, int *opened)
57537 {
57538@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57539 /* Negative dentry, just create the file */
57540 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57541 umode_t mode = op->mode;
57542+
57543+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57544+ error = -EACCES;
57545+ goto out_dput;
57546+ }
57547+
57548+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57549+ error = -EACCES;
57550+ goto out_dput;
57551+ }
57552+
57553 if (!IS_POSIXACL(dir->d_inode))
57554 mode &= ~current_umask();
57555 /*
57556@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57557 nd->flags & LOOKUP_EXCL);
57558 if (error)
57559 goto out_dput;
57560+ else
57561+ gr_handle_create(dentry, nd->path.mnt);
57562 }
57563 out_no_open:
57564 path->dentry = dentry;
57565@@ -2671,7 +2723,7 @@ out_dput:
57566 /*
57567 * Handle the last step of open()
57568 */
57569-static int do_last(struct nameidata *nd, struct path *path,
57570+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57571 struct file *file, const struct open_flags *op,
57572 int *opened, struct filename *name)
57573 {
57574@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57575 if (error)
57576 return error;
57577
57578+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57579+ error = -ENOENT;
57580+ goto out;
57581+ }
57582+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57583+ error = -EACCES;
57584+ goto out;
57585+ }
57586+
57587 audit_inode(name, dir, LOOKUP_PARENT);
57588 error = -EISDIR;
57589 /* trailing slashes? */
57590@@ -2740,7 +2801,7 @@ retry_lookup:
57591 */
57592 }
57593 mutex_lock(&dir->d_inode->i_mutex);
57594- error = lookup_open(nd, path, file, op, got_write, opened);
57595+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57596 mutex_unlock(&dir->d_inode->i_mutex);
57597
57598 if (error <= 0) {
57599@@ -2764,11 +2825,28 @@ retry_lookup:
57600 goto finish_open_created;
57601 }
57602
57603+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57604+ error = -ENOENT;
57605+ goto exit_dput;
57606+ }
57607+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57608+ error = -EACCES;
57609+ goto exit_dput;
57610+ }
57611+
57612 /*
57613 * create/update audit record if it already exists.
57614 */
57615- if (path->dentry->d_inode)
57616+ if (path->dentry->d_inode) {
57617+ /* only check if O_CREAT is specified, all other checks need to go
57618+ into may_open */
57619+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57620+ error = -EACCES;
57621+ goto exit_dput;
57622+ }
57623+
57624 audit_inode(name, path->dentry, 0);
57625+ }
57626
57627 /*
57628 * If atomic_open() acquired write access it is dropped now due to
57629@@ -2809,6 +2887,11 @@ finish_lookup:
57630 }
57631 }
57632 BUG_ON(inode != path->dentry->d_inode);
57633+ /* if we're resolving a symlink to another symlink */
57634+ if (link && gr_handle_symlink_owner(link, inode)) {
57635+ error = -EACCES;
57636+ goto out;
57637+ }
57638 return 1;
57639 }
57640
57641@@ -2818,7 +2901,6 @@ finish_lookup:
57642 save_parent.dentry = nd->path.dentry;
57643 save_parent.mnt = mntget(path->mnt);
57644 nd->path.dentry = path->dentry;
57645-
57646 }
57647 nd->inode = inode;
57648 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57649@@ -2828,7 +2910,18 @@ finish_open:
57650 path_put(&save_parent);
57651 return error;
57652 }
57653+
57654+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57655+ error = -ENOENT;
57656+ goto out;
57657+ }
57658+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57659+ error = -EACCES;
57660+ goto out;
57661+ }
57662+
57663 audit_inode(name, nd->path.dentry, 0);
57664+
57665 error = -EISDIR;
57666 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57667 goto out;
57668@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57669 if (unlikely(error))
57670 goto out;
57671
57672- error = do_last(nd, &path, file, op, &opened, pathname);
57673+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57674 while (unlikely(error > 0)) { /* trailing symlink */
57675 struct path link = path;
57676 void *cookie;
57677@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57678 error = follow_link(&link, nd, &cookie);
57679 if (unlikely(error))
57680 break;
57681- error = do_last(nd, &path, file, op, &opened, pathname);
57682+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57683 put_link(nd, &link, cookie);
57684 }
57685 out:
57686@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57687 goto unlock;
57688
57689 error = -EEXIST;
57690- if (dentry->d_inode)
57691+ if (dentry->d_inode) {
57692+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57693+ error = -ENOENT;
57694+ }
57695 goto fail;
57696+ }
57697 /*
57698 * Special case - lookup gave negative, but... we had foo/bar/
57699 * From the vfs_mknod() POV we just have a negative dentry -
57700@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57701 }
57702 EXPORT_SYMBOL(user_path_create);
57703
57704+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57705+{
57706+ struct filename *tmp = getname(pathname);
57707+ struct dentry *res;
57708+ if (IS_ERR(tmp))
57709+ return ERR_CAST(tmp);
57710+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57711+ if (IS_ERR(res))
57712+ putname(tmp);
57713+ else
57714+ *to = tmp;
57715+ return res;
57716+}
57717+
57718 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57719 {
57720 int error = may_create(dir, dentry);
57721@@ -3224,6 +3335,17 @@ retry:
57722
57723 if (!IS_POSIXACL(path.dentry->d_inode))
57724 mode &= ~current_umask();
57725+
57726+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57727+ error = -EPERM;
57728+ goto out;
57729+ }
57730+
57731+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57732+ error = -EACCES;
57733+ goto out;
57734+ }
57735+
57736 error = security_path_mknod(&path, dentry, mode, dev);
57737 if (error)
57738 goto out;
57739@@ -3240,6 +3362,8 @@ retry:
57740 break;
57741 }
57742 out:
57743+ if (!error)
57744+ gr_handle_create(dentry, path.mnt);
57745 done_path_create(&path, dentry);
57746 if (retry_estale(error, lookup_flags)) {
57747 lookup_flags |= LOOKUP_REVAL;
57748@@ -3292,9 +3416,16 @@ retry:
57749
57750 if (!IS_POSIXACL(path.dentry->d_inode))
57751 mode &= ~current_umask();
57752+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57753+ error = -EACCES;
57754+ goto out;
57755+ }
57756 error = security_path_mkdir(&path, dentry, mode);
57757 if (!error)
57758 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57759+ if (!error)
57760+ gr_handle_create(dentry, path.mnt);
57761+out:
57762 done_path_create(&path, dentry);
57763 if (retry_estale(error, lookup_flags)) {
57764 lookup_flags |= LOOKUP_REVAL;
57765@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57766 struct filename *name;
57767 struct dentry *dentry;
57768 struct nameidata nd;
57769+ ino_t saved_ino = 0;
57770+ dev_t saved_dev = 0;
57771 unsigned int lookup_flags = 0;
57772 retry:
57773 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57774@@ -3407,10 +3540,21 @@ retry:
57775 error = -ENOENT;
57776 goto exit3;
57777 }
57778+
57779+ saved_ino = dentry->d_inode->i_ino;
57780+ saved_dev = gr_get_dev_from_dentry(dentry);
57781+
57782+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57783+ error = -EACCES;
57784+ goto exit3;
57785+ }
57786+
57787 error = security_path_rmdir(&nd.path, dentry);
57788 if (error)
57789 goto exit3;
57790 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57791+ if (!error && (saved_dev || saved_ino))
57792+ gr_handle_delete(saved_ino, saved_dev);
57793 exit3:
57794 dput(dentry);
57795 exit2:
57796@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57797 struct dentry *dentry;
57798 struct nameidata nd;
57799 struct inode *inode = NULL;
57800+ ino_t saved_ino = 0;
57801+ dev_t saved_dev = 0;
57802 unsigned int lookup_flags = 0;
57803 retry:
57804 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57805@@ -3502,10 +3648,22 @@ retry:
57806 if (!inode)
57807 goto slashes;
57808 ihold(inode);
57809+
57810+ if (inode->i_nlink <= 1) {
57811+ saved_ino = inode->i_ino;
57812+ saved_dev = gr_get_dev_from_dentry(dentry);
57813+ }
57814+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57815+ error = -EACCES;
57816+ goto exit2;
57817+ }
57818+
57819 error = security_path_unlink(&nd.path, dentry);
57820 if (error)
57821 goto exit2;
57822 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57823+ if (!error && (saved_ino || saved_dev))
57824+ gr_handle_delete(saved_ino, saved_dev);
57825 exit2:
57826 dput(dentry);
57827 }
57828@@ -3583,9 +3741,17 @@ retry:
57829 if (IS_ERR(dentry))
57830 goto out_putname;
57831
57832+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57833+ error = -EACCES;
57834+ goto out;
57835+ }
57836+
57837 error = security_path_symlink(&path, dentry, from->name);
57838 if (!error)
57839 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57840+ if (!error)
57841+ gr_handle_create(dentry, path.mnt);
57842+out:
57843 done_path_create(&path, dentry);
57844 if (retry_estale(error, lookup_flags)) {
57845 lookup_flags |= LOOKUP_REVAL;
57846@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57847 {
57848 struct dentry *new_dentry;
57849 struct path old_path, new_path;
57850+ struct filename *to = NULL;
57851 int how = 0;
57852 int error;
57853
57854@@ -3688,7 +3855,7 @@ retry:
57855 if (error)
57856 return error;
57857
57858- new_dentry = user_path_create(newdfd, newname, &new_path,
57859+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57860 (how & LOOKUP_REVAL));
57861 error = PTR_ERR(new_dentry);
57862 if (IS_ERR(new_dentry))
57863@@ -3700,11 +3867,28 @@ retry:
57864 error = may_linkat(&old_path);
57865 if (unlikely(error))
57866 goto out_dput;
57867+
57868+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57869+ old_path.dentry->d_inode,
57870+ old_path.dentry->d_inode->i_mode, to)) {
57871+ error = -EACCES;
57872+ goto out_dput;
57873+ }
57874+
57875+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57876+ old_path.dentry, old_path.mnt, to)) {
57877+ error = -EACCES;
57878+ goto out_dput;
57879+ }
57880+
57881 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57882 if (error)
57883 goto out_dput;
57884 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57885+ if (!error)
57886+ gr_handle_create(new_dentry, new_path.mnt);
57887 out_dput:
57888+ putname(to);
57889 done_path_create(&new_path, new_dentry);
57890 if (retry_estale(error, how)) {
57891 how |= LOOKUP_REVAL;
57892@@ -3950,12 +4134,21 @@ retry:
57893 if (new_dentry == trap)
57894 goto exit5;
57895
57896+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57897+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57898+ to);
57899+ if (error)
57900+ goto exit5;
57901+
57902 error = security_path_rename(&oldnd.path, old_dentry,
57903 &newnd.path, new_dentry);
57904 if (error)
57905 goto exit5;
57906 error = vfs_rename(old_dir->d_inode, old_dentry,
57907 new_dir->d_inode, new_dentry);
57908+ if (!error)
57909+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57910+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57911 exit5:
57912 dput(new_dentry);
57913 exit4:
57914@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57915
57916 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57917 {
57918+ char tmpbuf[64];
57919+ const char *newlink;
57920 int len;
57921
57922 len = PTR_ERR(link);
57923@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57924 len = strlen(link);
57925 if (len > (unsigned) buflen)
57926 len = buflen;
57927- if (copy_to_user(buffer, link, len))
57928+
57929+ if (len < sizeof(tmpbuf)) {
57930+ memcpy(tmpbuf, link, len);
57931+ newlink = tmpbuf;
57932+ } else
57933+ newlink = link;
57934+
57935+ if (copy_to_user(buffer, newlink, len))
57936 len = -EFAULT;
57937 out:
57938 return len;
57939diff --git a/fs/namespace.c b/fs/namespace.c
57940index a45ba4f..b4c7d07 100644
57941--- a/fs/namespace.c
57942+++ b/fs/namespace.c
57943@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57944 if (!(sb->s_flags & MS_RDONLY))
57945 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57946 up_write(&sb->s_umount);
57947+
57948+ gr_log_remount(mnt->mnt_devname, retval);
57949+
57950 return retval;
57951 }
57952
57953@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57954 }
57955 br_write_unlock(&vfsmount_lock);
57956 namespace_unlock();
57957+
57958+ gr_log_unmount(mnt->mnt_devname, retval);
57959+
57960 return retval;
57961 }
57962
57963@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57964 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57965 */
57966
57967-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57968+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57969 {
57970 struct path path;
57971 struct mount *mnt;
57972@@ -1342,7 +1348,7 @@ out:
57973 /*
57974 * The 2.0 compatible umount. No flags.
57975 */
57976-SYSCALL_DEFINE1(oldumount, char __user *, name)
57977+SYSCALL_DEFINE1(oldumount, const char __user *, name)
57978 {
57979 return sys_umount(name, 0);
57980 }
57981@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
57982 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
57983 MS_STRICTATIME);
57984
57985+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
57986+ retval = -EPERM;
57987+ goto dput_out;
57988+ }
57989+
57990+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
57991+ retval = -EPERM;
57992+ goto dput_out;
57993+ }
57994+
57995 if (flags & MS_REMOUNT)
57996 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
57997 data_page);
57998@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
57999 dev_name, data_page);
58000 dput_out:
58001 path_put(&path);
58002+
58003+ gr_log_mount(dev_name, dir_name, retval);
58004+
58005 return retval;
58006 }
58007
58008@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58009 * number incrementing at 10Ghz will take 12,427 years to wrap which
58010 * is effectively never, so we can ignore the possibility.
58011 */
58012-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58013+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58014
58015 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58016 {
58017@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58018 kfree(new_ns);
58019 return ERR_PTR(ret);
58020 }
58021- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58022+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58023 atomic_set(&new_ns->count, 1);
58024 new_ns->root = NULL;
58025 INIT_LIST_HEAD(&new_ns->list);
58026@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58027 * Allocate a new namespace structure and populate it with contents
58028 * copied from the namespace of the passed in task structure.
58029 */
58030-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58031+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58032 struct user_namespace *user_ns, struct fs_struct *fs)
58033 {
58034 struct mnt_namespace *new_ns;
58035@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58036 }
58037 EXPORT_SYMBOL(mount_subtree);
58038
58039-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58040- char __user *, type, unsigned long, flags, void __user *, data)
58041+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58042+ const char __user *, type, unsigned long, flags, void __user *, data)
58043 {
58044 int ret;
58045 char *kernel_type;
58046@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58047 if (error)
58048 goto out2;
58049
58050+ if (gr_handle_chroot_pivot()) {
58051+ error = -EPERM;
58052+ goto out2;
58053+ }
58054+
58055 get_fs_root(current->fs, &root);
58056 old_mp = lock_mount(&old);
58057 error = PTR_ERR(old_mp);
58058@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58059 !nsown_capable(CAP_SYS_ADMIN))
58060 return -EPERM;
58061
58062- if (fs->users != 1)
58063+ if (atomic_read(&fs->users) != 1)
58064 return -EINVAL;
58065
58066 get_mnt_ns(mnt_ns);
58067diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58068index f4ccfe6..a5cf064 100644
58069--- a/fs/nfs/callback_xdr.c
58070+++ b/fs/nfs/callback_xdr.c
58071@@ -51,7 +51,7 @@ struct callback_op {
58072 callback_decode_arg_t decode_args;
58073 callback_encode_res_t encode_res;
58074 long res_maxsize;
58075-};
58076+} __do_const;
58077
58078 static struct callback_op callback_ops[];
58079
58080diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58081index 941246f..17d8724 100644
58082--- a/fs/nfs/inode.c
58083+++ b/fs/nfs/inode.c
58084@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58085 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58086 }
58087
58088-static atomic_long_t nfs_attr_generation_counter;
58089+static atomic_long_unchecked_t nfs_attr_generation_counter;
58090
58091 static unsigned long nfs_read_attr_generation_counter(void)
58092 {
58093- return atomic_long_read(&nfs_attr_generation_counter);
58094+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58095 }
58096
58097 unsigned long nfs_inc_attr_generation_counter(void)
58098 {
58099- return atomic_long_inc_return(&nfs_attr_generation_counter);
58100+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58101 }
58102
58103 void nfs_fattr_init(struct nfs_fattr *fattr)
58104diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58105index 419572f..5414a23 100644
58106--- a/fs/nfsd/nfs4proc.c
58107+++ b/fs/nfsd/nfs4proc.c
58108@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58109 nfsd4op_rsize op_rsize_bop;
58110 stateid_getter op_get_currentstateid;
58111 stateid_setter op_set_currentstateid;
58112-};
58113+} __do_const;
58114
58115 static struct nfsd4_operation nfsd4_ops[];
58116
58117diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58118index c2a4701..fd80e29 100644
58119--- a/fs/nfsd/nfs4xdr.c
58120+++ b/fs/nfsd/nfs4xdr.c
58121@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58122
58123 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58124
58125-static nfsd4_dec nfsd4_dec_ops[] = {
58126+static const nfsd4_dec nfsd4_dec_ops[] = {
58127 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58128 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58129 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58130@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58131 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58132 };
58133
58134-static nfsd4_dec nfsd41_dec_ops[] = {
58135+static const nfsd4_dec nfsd41_dec_ops[] = {
58136 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58137 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58138 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58139@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58140 };
58141
58142 struct nfsd4_minorversion_ops {
58143- nfsd4_dec *decoders;
58144+ const nfsd4_dec *decoders;
58145 int nops;
58146 };
58147
58148diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58149index e76244e..9fe8f2f1 100644
58150--- a/fs/nfsd/nfscache.c
58151+++ b/fs/nfsd/nfscache.c
58152@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58153 {
58154 struct svc_cacherep *rp = rqstp->rq_cacherep;
58155 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58156- int len;
58157+ long len;
58158 size_t bufsize = 0;
58159
58160 if (!rp)
58161 return;
58162
58163- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58164- len >>= 2;
58165+ if (statp) {
58166+ len = (char*)statp - (char*)resv->iov_base;
58167+ len = resv->iov_len - len;
58168+ len >>= 2;
58169+ }
58170
58171 /* Don't cache excessive amounts of data and XDR failures */
58172 if (!statp || len > (256 >> 2)) {
58173diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58174index c827acb..b253b77 100644
58175--- a/fs/nfsd/vfs.c
58176+++ b/fs/nfsd/vfs.c
58177@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58178 } else {
58179 oldfs = get_fs();
58180 set_fs(KERNEL_DS);
58181- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58182+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58183 set_fs(oldfs);
58184 }
58185
58186@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58187
58188 /* Write the data. */
58189 oldfs = get_fs(); set_fs(KERNEL_DS);
58190- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58191+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58192 set_fs(oldfs);
58193 if (host_err < 0)
58194 goto out_nfserr;
58195@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58196 */
58197
58198 oldfs = get_fs(); set_fs(KERNEL_DS);
58199- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58200+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58201 set_fs(oldfs);
58202
58203 if (host_err < 0)
58204diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58205index fea6bd5..8ee9d81 100644
58206--- a/fs/nls/nls_base.c
58207+++ b/fs/nls/nls_base.c
58208@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58209
58210 int register_nls(struct nls_table * nls)
58211 {
58212- struct nls_table ** tmp = &tables;
58213+ struct nls_table *tmp = tables;
58214
58215 if (nls->next)
58216 return -EBUSY;
58217
58218 spin_lock(&nls_lock);
58219- while (*tmp) {
58220- if (nls == *tmp) {
58221+ while (tmp) {
58222+ if (nls == tmp) {
58223 spin_unlock(&nls_lock);
58224 return -EBUSY;
58225 }
58226- tmp = &(*tmp)->next;
58227+ tmp = tmp->next;
58228 }
58229- nls->next = tables;
58230+ pax_open_kernel();
58231+ *(struct nls_table **)&nls->next = tables;
58232+ pax_close_kernel();
58233 tables = nls;
58234 spin_unlock(&nls_lock);
58235 return 0;
58236@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58237
58238 int unregister_nls(struct nls_table * nls)
58239 {
58240- struct nls_table ** tmp = &tables;
58241+ struct nls_table * const * tmp = &tables;
58242
58243 spin_lock(&nls_lock);
58244 while (*tmp) {
58245 if (nls == *tmp) {
58246- *tmp = nls->next;
58247+ pax_open_kernel();
58248+ *(struct nls_table **)tmp = nls->next;
58249+ pax_close_kernel();
58250 spin_unlock(&nls_lock);
58251 return 0;
58252 }
58253diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58254index 7424929..35f6be5 100644
58255--- a/fs/nls/nls_euc-jp.c
58256+++ b/fs/nls/nls_euc-jp.c
58257@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58258 p_nls = load_nls("cp932");
58259
58260 if (p_nls) {
58261- table.charset2upper = p_nls->charset2upper;
58262- table.charset2lower = p_nls->charset2lower;
58263+ pax_open_kernel();
58264+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58265+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58266+ pax_close_kernel();
58267 return register_nls(&table);
58268 }
58269
58270diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58271index e7bc1d7..06bd4bb 100644
58272--- a/fs/nls/nls_koi8-ru.c
58273+++ b/fs/nls/nls_koi8-ru.c
58274@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58275 p_nls = load_nls("koi8-u");
58276
58277 if (p_nls) {
58278- table.charset2upper = p_nls->charset2upper;
58279- table.charset2lower = p_nls->charset2lower;
58280+ pax_open_kernel();
58281+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58282+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58283+ pax_close_kernel();
58284 return register_nls(&table);
58285 }
58286
58287diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58288index e44cb64..4807084 100644
58289--- a/fs/notify/fanotify/fanotify_user.c
58290+++ b/fs/notify/fanotify/fanotify_user.c
58291@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58292
58293 fd = fanotify_event_metadata.fd;
58294 ret = -EFAULT;
58295- if (copy_to_user(buf, &fanotify_event_metadata,
58296- fanotify_event_metadata.event_len))
58297+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58298+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58299 goto out_close_fd;
58300
58301 ret = prepare_for_access_response(group, event, fd);
58302diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58303index 7b51b05..5ea5ef6 100644
58304--- a/fs/notify/notification.c
58305+++ b/fs/notify/notification.c
58306@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58307 * get set to 0 so it will never get 'freed'
58308 */
58309 static struct fsnotify_event *q_overflow_event;
58310-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58311+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58312
58313 /**
58314 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58315@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58316 */
58317 u32 fsnotify_get_cookie(void)
58318 {
58319- return atomic_inc_return(&fsnotify_sync_cookie);
58320+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58321 }
58322 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58323
58324diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58325index 9e38daf..5727cae 100644
58326--- a/fs/ntfs/dir.c
58327+++ b/fs/ntfs/dir.c
58328@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58329 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58330 ~(s64)(ndir->itype.index.block_size - 1)));
58331 /* Bounds checks. */
58332- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58333+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58334 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58335 "inode 0x%lx or driver bug.", vdir->i_ino);
58336 goto err_out;
58337diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58338index c5670b8..d590213 100644
58339--- a/fs/ntfs/file.c
58340+++ b/fs/ntfs/file.c
58341@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58342 char *addr;
58343 size_t total = 0;
58344 unsigned len;
58345- int left;
58346+ unsigned left;
58347
58348 do {
58349 len = PAGE_CACHE_SIZE - ofs;
58350diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58351index 82650d5..db37dcf 100644
58352--- a/fs/ntfs/super.c
58353+++ b/fs/ntfs/super.c
58354@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58355 if (!silent)
58356 ntfs_error(sb, "Primary boot sector is invalid.");
58357 } else if (!silent)
58358- ntfs_error(sb, read_err_str, "primary");
58359+ ntfs_error(sb, read_err_str, "%s", "primary");
58360 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58361 if (bh_primary)
58362 brelse(bh_primary);
58363@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58364 goto hotfix_primary_boot_sector;
58365 brelse(bh_backup);
58366 } else if (!silent)
58367- ntfs_error(sb, read_err_str, "backup");
58368+ ntfs_error(sb, read_err_str, "%s", "backup");
58369 /* Try to read NT3.51- backup boot sector. */
58370 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58371 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58372@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58373 "sector.");
58374 brelse(bh_backup);
58375 } else if (!silent)
58376- ntfs_error(sb, read_err_str, "backup");
58377+ ntfs_error(sb, read_err_str, "%s", "backup");
58378 /* We failed. Cleanup and return. */
58379 if (bh_primary)
58380 brelse(bh_primary);
58381diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58382index aebeacd..0dcdd26 100644
58383--- a/fs/ocfs2/localalloc.c
58384+++ b/fs/ocfs2/localalloc.c
58385@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58386 goto bail;
58387 }
58388
58389- atomic_inc(&osb->alloc_stats.moves);
58390+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58391
58392 bail:
58393 if (handle)
58394diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58395index 3a90347..c40bef8 100644
58396--- a/fs/ocfs2/ocfs2.h
58397+++ b/fs/ocfs2/ocfs2.h
58398@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58399
58400 struct ocfs2_alloc_stats
58401 {
58402- atomic_t moves;
58403- atomic_t local_data;
58404- atomic_t bitmap_data;
58405- atomic_t bg_allocs;
58406- atomic_t bg_extends;
58407+ atomic_unchecked_t moves;
58408+ atomic_unchecked_t local_data;
58409+ atomic_unchecked_t bitmap_data;
58410+ atomic_unchecked_t bg_allocs;
58411+ atomic_unchecked_t bg_extends;
58412 };
58413
58414 enum ocfs2_local_alloc_state
58415diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58416index 5397c07..54afc55 100644
58417--- a/fs/ocfs2/suballoc.c
58418+++ b/fs/ocfs2/suballoc.c
58419@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58420 mlog_errno(status);
58421 goto bail;
58422 }
58423- atomic_inc(&osb->alloc_stats.bg_extends);
58424+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58425
58426 /* You should never ask for this much metadata */
58427 BUG_ON(bits_wanted >
58428@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58429 mlog_errno(status);
58430 goto bail;
58431 }
58432- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58433+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58434
58435 *suballoc_loc = res.sr_bg_blkno;
58436 *suballoc_bit_start = res.sr_bit_offset;
58437@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58438 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58439 res->sr_bits);
58440
58441- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58442+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58443
58444 BUG_ON(res->sr_bits != 1);
58445
58446@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58447 mlog_errno(status);
58448 goto bail;
58449 }
58450- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58451+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58452
58453 BUG_ON(res.sr_bits != 1);
58454
58455@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58456 cluster_start,
58457 num_clusters);
58458 if (!status)
58459- atomic_inc(&osb->alloc_stats.local_data);
58460+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58461 } else {
58462 if (min_clusters > (osb->bitmap_cpg - 1)) {
58463 /* The only paths asking for contiguousness
58464@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58465 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58466 res.sr_bg_blkno,
58467 res.sr_bit_offset);
58468- atomic_inc(&osb->alloc_stats.bitmap_data);
58469+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58470 *num_clusters = res.sr_bits;
58471 }
58472 }
58473diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58474index 121da2d..a0232bc 100644
58475--- a/fs/ocfs2/super.c
58476+++ b/fs/ocfs2/super.c
58477@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58478 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58479 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58480 "Stats",
58481- atomic_read(&osb->alloc_stats.bitmap_data),
58482- atomic_read(&osb->alloc_stats.local_data),
58483- atomic_read(&osb->alloc_stats.bg_allocs),
58484- atomic_read(&osb->alloc_stats.moves),
58485- atomic_read(&osb->alloc_stats.bg_extends));
58486+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58487+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58488+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58489+ atomic_read_unchecked(&osb->alloc_stats.moves),
58490+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58491
58492 out += snprintf(buf + out, len - out,
58493 "%10s => State: %u Descriptor: %llu Size: %u bits "
58494@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58495 spin_lock_init(&osb->osb_xattr_lock);
58496 ocfs2_init_steal_slots(osb);
58497
58498- atomic_set(&osb->alloc_stats.moves, 0);
58499- atomic_set(&osb->alloc_stats.local_data, 0);
58500- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58501- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58502- atomic_set(&osb->alloc_stats.bg_extends, 0);
58503+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58504+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58505+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58506+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58507+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58508
58509 /* Copy the blockcheck stats from the superblock probe */
58510 osb->osb_ecc_stats = *stats;
58511diff --git a/fs/open.c b/fs/open.c
58512index 7931f76..7b03f3b 100644
58513--- a/fs/open.c
58514+++ b/fs/open.c
58515@@ -32,6 +32,8 @@
58516 #include <linux/dnotify.h>
58517 #include <linux/compat.h>
58518
58519+#define CREATE_TRACE_POINTS
58520+#include <trace/events/fs.h>
58521 #include "internal.h"
58522
58523 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58524@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58525 error = locks_verify_truncate(inode, NULL, length);
58526 if (!error)
58527 error = security_path_truncate(path);
58528+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58529+ error = -EACCES;
58530 if (!error)
58531 error = do_truncate(path->dentry, length, 0, NULL);
58532
58533@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58534 error = locks_verify_truncate(inode, f.file, length);
58535 if (!error)
58536 error = security_path_truncate(&f.file->f_path);
58537+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58538+ error = -EACCES;
58539 if (!error)
58540 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58541 sb_end_write(inode->i_sb);
58542@@ -360,6 +366,9 @@ retry:
58543 if (__mnt_is_readonly(path.mnt))
58544 res = -EROFS;
58545
58546+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58547+ res = -EACCES;
58548+
58549 out_path_release:
58550 path_put(&path);
58551 if (retry_estale(res, lookup_flags)) {
58552@@ -391,6 +400,8 @@ retry:
58553 if (error)
58554 goto dput_and_out;
58555
58556+ gr_log_chdir(path.dentry, path.mnt);
58557+
58558 set_fs_pwd(current->fs, &path);
58559
58560 dput_and_out:
58561@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58562 goto out_putf;
58563
58564 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58565+
58566+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58567+ error = -EPERM;
58568+
58569+ if (!error)
58570+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58571+
58572 if (!error)
58573 set_fs_pwd(current->fs, &f.file->f_path);
58574 out_putf:
58575@@ -449,7 +467,13 @@ retry:
58576 if (error)
58577 goto dput_and_out;
58578
58579+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58580+ goto dput_and_out;
58581+
58582 set_fs_root(current->fs, &path);
58583+
58584+ gr_handle_chroot_chdir(&path);
58585+
58586 error = 0;
58587 dput_and_out:
58588 path_put(&path);
58589@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58590 if (error)
58591 return error;
58592 mutex_lock(&inode->i_mutex);
58593+
58594+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58595+ error = -EACCES;
58596+ goto out_unlock;
58597+ }
58598+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58599+ error = -EACCES;
58600+ goto out_unlock;
58601+ }
58602+
58603 error = security_path_chmod(path, mode);
58604 if (error)
58605 goto out_unlock;
58606@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58607 uid = make_kuid(current_user_ns(), user);
58608 gid = make_kgid(current_user_ns(), group);
58609
58610+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58611+ return -EACCES;
58612+
58613 newattrs.ia_valid = ATTR_CTIME;
58614 if (user != (uid_t) -1) {
58615 if (!uid_valid(uid))
58616@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58617 } else {
58618 fsnotify_open(f);
58619 fd_install(fd, f);
58620+ trace_do_sys_open(tmp->name, flags, mode);
58621 }
58622 }
58623 putname(tmp);
58624diff --git a/fs/pipe.c b/fs/pipe.c
58625index d2c45e1..009fe1c 100644
58626--- a/fs/pipe.c
58627+++ b/fs/pipe.c
58628@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58629
58630 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58631 {
58632- if (pipe->files)
58633+ if (atomic_read(&pipe->files))
58634 mutex_lock_nested(&pipe->mutex, subclass);
58635 }
58636
58637@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58638
58639 void pipe_unlock(struct pipe_inode_info *pipe)
58640 {
58641- if (pipe->files)
58642+ if (atomic_read(&pipe->files))
58643 mutex_unlock(&pipe->mutex);
58644 }
58645 EXPORT_SYMBOL(pipe_unlock);
58646@@ -449,9 +449,9 @@ redo:
58647 }
58648 if (bufs) /* More to do? */
58649 continue;
58650- if (!pipe->writers)
58651+ if (!atomic_read(&pipe->writers))
58652 break;
58653- if (!pipe->waiting_writers) {
58654+ if (!atomic_read(&pipe->waiting_writers)) {
58655 /* syscall merging: Usually we must not sleep
58656 * if O_NONBLOCK is set, or if we got some data.
58657 * But if a writer sleeps in kernel space, then
58658@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58659 ret = 0;
58660 __pipe_lock(pipe);
58661
58662- if (!pipe->readers) {
58663+ if (!atomic_read(&pipe->readers)) {
58664 send_sig(SIGPIPE, current, 0);
58665 ret = -EPIPE;
58666 goto out;
58667@@ -562,7 +562,7 @@ redo1:
58668 for (;;) {
58669 int bufs;
58670
58671- if (!pipe->readers) {
58672+ if (!atomic_read(&pipe->readers)) {
58673 send_sig(SIGPIPE, current, 0);
58674 if (!ret)
58675 ret = -EPIPE;
58676@@ -653,9 +653,9 @@ redo2:
58677 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58678 do_wakeup = 0;
58679 }
58680- pipe->waiting_writers++;
58681+ atomic_inc(&pipe->waiting_writers);
58682 pipe_wait(pipe);
58683- pipe->waiting_writers--;
58684+ atomic_dec(&pipe->waiting_writers);
58685 }
58686 out:
58687 __pipe_unlock(pipe);
58688@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58689 mask = 0;
58690 if (filp->f_mode & FMODE_READ) {
58691 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58692- if (!pipe->writers && filp->f_version != pipe->w_counter)
58693+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58694 mask |= POLLHUP;
58695 }
58696
58697@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58698 * Most Unices do not set POLLERR for FIFOs but on Linux they
58699 * behave exactly like pipes for poll().
58700 */
58701- if (!pipe->readers)
58702+ if (!atomic_read(&pipe->readers))
58703 mask |= POLLERR;
58704 }
58705
58706@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58707
58708 __pipe_lock(pipe);
58709 if (file->f_mode & FMODE_READ)
58710- pipe->readers--;
58711+ atomic_dec(&pipe->readers);
58712 if (file->f_mode & FMODE_WRITE)
58713- pipe->writers--;
58714+ atomic_dec(&pipe->writers);
58715
58716- if (pipe->readers || pipe->writers) {
58717+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58718 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58719 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58720 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58721 }
58722 spin_lock(&inode->i_lock);
58723- if (!--pipe->files) {
58724+ if (atomic_dec_and_test(&pipe->files)) {
58725 inode->i_pipe = NULL;
58726 kill = 1;
58727 }
58728@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58729 kfree(pipe);
58730 }
58731
58732-static struct vfsmount *pipe_mnt __read_mostly;
58733+struct vfsmount *pipe_mnt __read_mostly;
58734
58735 /*
58736 * pipefs_dname() is called from d_path().
58737@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58738 goto fail_iput;
58739
58740 inode->i_pipe = pipe;
58741- pipe->files = 2;
58742- pipe->readers = pipe->writers = 1;
58743+ atomic_set(&pipe->files, 2);
58744+ atomic_set(&pipe->readers, 1);
58745+ atomic_set(&pipe->writers, 1);
58746 inode->i_fop = &pipefifo_fops;
58747
58748 /*
58749@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58750 spin_lock(&inode->i_lock);
58751 if (inode->i_pipe) {
58752 pipe = inode->i_pipe;
58753- pipe->files++;
58754+ atomic_inc(&pipe->files);
58755 spin_unlock(&inode->i_lock);
58756 } else {
58757 spin_unlock(&inode->i_lock);
58758 pipe = alloc_pipe_info();
58759 if (!pipe)
58760 return -ENOMEM;
58761- pipe->files = 1;
58762+ atomic_set(&pipe->files, 1);
58763 spin_lock(&inode->i_lock);
58764 if (unlikely(inode->i_pipe)) {
58765- inode->i_pipe->files++;
58766+ atomic_inc(&inode->i_pipe->files);
58767 spin_unlock(&inode->i_lock);
58768 free_pipe_info(pipe);
58769 pipe = inode->i_pipe;
58770@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58771 * opened, even when there is no process writing the FIFO.
58772 */
58773 pipe->r_counter++;
58774- if (pipe->readers++ == 0)
58775+ if (atomic_inc_return(&pipe->readers) == 1)
58776 wake_up_partner(pipe);
58777
58778- if (!is_pipe && !pipe->writers) {
58779+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58780 if ((filp->f_flags & O_NONBLOCK)) {
58781 /* suppress POLLHUP until we have
58782 * seen a writer */
58783@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58784 * errno=ENXIO when there is no process reading the FIFO.
58785 */
58786 ret = -ENXIO;
58787- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58788+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58789 goto err;
58790
58791 pipe->w_counter++;
58792- if (!pipe->writers++)
58793+ if (atomic_inc_return(&pipe->writers) == 1)
58794 wake_up_partner(pipe);
58795
58796- if (!is_pipe && !pipe->readers) {
58797+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58798 if (wait_for_partner(pipe, &pipe->r_counter))
58799 goto err_wr;
58800 }
58801@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58802 * the process can at least talk to itself.
58803 */
58804
58805- pipe->readers++;
58806- pipe->writers++;
58807+ atomic_inc(&pipe->readers);
58808+ atomic_inc(&pipe->writers);
58809 pipe->r_counter++;
58810 pipe->w_counter++;
58811- if (pipe->readers == 1 || pipe->writers == 1)
58812+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58813 wake_up_partner(pipe);
58814 break;
58815
58816@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58817 return 0;
58818
58819 err_rd:
58820- if (!--pipe->readers)
58821+ if (atomic_dec_and_test(&pipe->readers))
58822 wake_up_interruptible(&pipe->wait);
58823 ret = -ERESTARTSYS;
58824 goto err;
58825
58826 err_wr:
58827- if (!--pipe->writers)
58828+ if (atomic_dec_and_test(&pipe->writers))
58829 wake_up_interruptible(&pipe->wait);
58830 ret = -ERESTARTSYS;
58831 goto err;
58832
58833 err:
58834 spin_lock(&inode->i_lock);
58835- if (!--pipe->files) {
58836+ if (atomic_dec_and_test(&pipe->files)) {
58837 inode->i_pipe = NULL;
58838 kill = 1;
58839 }
58840diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58841index 15af622..0e9f4467 100644
58842--- a/fs/proc/Kconfig
58843+++ b/fs/proc/Kconfig
58844@@ -30,12 +30,12 @@ config PROC_FS
58845
58846 config PROC_KCORE
58847 bool "/proc/kcore support" if !ARM
58848- depends on PROC_FS && MMU
58849+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58850
58851 config PROC_VMCORE
58852 bool "/proc/vmcore support"
58853- depends on PROC_FS && CRASH_DUMP
58854- default y
58855+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58856+ default n
58857 help
58858 Exports the dump image of crashed kernel in ELF format.
58859
58860@@ -59,8 +59,8 @@ config PROC_SYSCTL
58861 limited in memory.
58862
58863 config PROC_PAGE_MONITOR
58864- default y
58865- depends on PROC_FS && MMU
58866+ default n
58867+ depends on PROC_FS && MMU && !GRKERNSEC
58868 bool "Enable /proc page monitoring" if EXPERT
58869 help
58870 Various /proc files exist to monitor process memory utilization:
58871diff --git a/fs/proc/array.c b/fs/proc/array.c
58872index cbd0f1b..adec3f0 100644
58873--- a/fs/proc/array.c
58874+++ b/fs/proc/array.c
58875@@ -60,6 +60,7 @@
58876 #include <linux/tty.h>
58877 #include <linux/string.h>
58878 #include <linux/mman.h>
58879+#include <linux/grsecurity.h>
58880 #include <linux/proc_fs.h>
58881 #include <linux/ioport.h>
58882 #include <linux/uaccess.h>
58883@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58884 seq_putc(m, '\n');
58885 }
58886
58887+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58888+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58889+{
58890+ if (p->mm)
58891+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58892+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58893+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58894+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58895+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58896+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58897+ else
58898+ seq_printf(m, "PaX:\t-----\n");
58899+}
58900+#endif
58901+
58902 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58903 struct pid *pid, struct task_struct *task)
58904 {
58905@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58906 task_cpus_allowed(m, task);
58907 cpuset_task_status_allowed(m, task);
58908 task_context_switch_counts(m, task);
58909+
58910+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58911+ task_pax(m, task);
58912+#endif
58913+
58914+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58915+ task_grsec_rbac(m, task);
58916+#endif
58917+
58918 return 0;
58919 }
58920
58921+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58922+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58923+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58924+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58925+#endif
58926+
58927 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58928 struct pid *pid, struct task_struct *task, int whole)
58929 {
58930@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58931 char tcomm[sizeof(task->comm)];
58932 unsigned long flags;
58933
58934+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58935+ if (current->exec_id != m->exec_id) {
58936+ gr_log_badprocpid("stat");
58937+ return 0;
58938+ }
58939+#endif
58940+
58941 state = *get_task_state(task);
58942 vsize = eip = esp = 0;
58943 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58944@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58945 gtime = task_gtime(task);
58946 }
58947
58948+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58949+ if (PAX_RAND_FLAGS(mm)) {
58950+ eip = 0;
58951+ esp = 0;
58952+ wchan = 0;
58953+ }
58954+#endif
58955+#ifdef CONFIG_GRKERNSEC_HIDESYM
58956+ wchan = 0;
58957+ eip =0;
58958+ esp =0;
58959+#endif
58960+
58961 /* scale priority and nice values from timeslices to -20..20 */
58962 /* to make it look like a "normal" Unix priority/nice value */
58963 priority = task_prio(task);
58964@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58965 seq_put_decimal_ull(m, ' ', vsize);
58966 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58967 seq_put_decimal_ull(m, ' ', rsslim);
58968+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58969+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
58970+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
58971+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
58972+#else
58973 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
58974 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
58975 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
58976+#endif
58977 seq_put_decimal_ull(m, ' ', esp);
58978 seq_put_decimal_ull(m, ' ', eip);
58979 /* The signal information here is obsolete.
58980@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58981 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
58982 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
58983
58984- if (mm && permitted) {
58985+ if (mm && permitted
58986+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58987+ && !PAX_RAND_FLAGS(mm)
58988+#endif
58989+ ) {
58990 seq_put_decimal_ull(m, ' ', mm->start_data);
58991 seq_put_decimal_ull(m, ' ', mm->end_data);
58992 seq_put_decimal_ull(m, ' ', mm->start_brk);
58993@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58994 struct pid *pid, struct task_struct *task)
58995 {
58996 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
58997- struct mm_struct *mm = get_task_mm(task);
58998+ struct mm_struct *mm;
58999
59000+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59001+ if (current->exec_id != m->exec_id) {
59002+ gr_log_badprocpid("statm");
59003+ return 0;
59004+ }
59005+#endif
59006+ mm = get_task_mm(task);
59007 if (mm) {
59008 size = task_statm(mm, &shared, &text, &data, &resident);
59009 mmput(mm);
59010@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59011 return 0;
59012 }
59013
59014+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59015+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59016+{
59017+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59018+}
59019+#endif
59020+
59021 #ifdef CONFIG_CHECKPOINT_RESTORE
59022 static struct pid *
59023 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59024diff --git a/fs/proc/base.c b/fs/proc/base.c
59025index 1485e38..8ad4236 100644
59026--- a/fs/proc/base.c
59027+++ b/fs/proc/base.c
59028@@ -113,6 +113,14 @@ struct pid_entry {
59029 union proc_op op;
59030 };
59031
59032+struct getdents_callback {
59033+ struct linux_dirent __user * current_dir;
59034+ struct linux_dirent __user * previous;
59035+ struct file * file;
59036+ int count;
59037+ int error;
59038+};
59039+
59040 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59041 .name = (NAME), \
59042 .len = sizeof(NAME) - 1, \
59043@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59044 if (!mm->arg_end)
59045 goto out_mm; /* Shh! No looking before we're done */
59046
59047+ if (gr_acl_handle_procpidmem(task))
59048+ goto out_mm;
59049+
59050 len = mm->arg_end - mm->arg_start;
59051
59052 if (len > PAGE_SIZE)
59053@@ -237,12 +248,28 @@ out:
59054 return res;
59055 }
59056
59057+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59058+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59059+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59060+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59061+#endif
59062+
59063 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59064 {
59065 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59066 int res = PTR_ERR(mm);
59067 if (mm && !IS_ERR(mm)) {
59068 unsigned int nwords = 0;
59069+
59070+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59071+ /* allow if we're currently ptracing this task */
59072+ if (PAX_RAND_FLAGS(mm) &&
59073+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59074+ mmput(mm);
59075+ return 0;
59076+ }
59077+#endif
59078+
59079 do {
59080 nwords += 2;
59081 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59082@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59083 }
59084
59085
59086-#ifdef CONFIG_KALLSYMS
59087+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59088 /*
59089 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59090 * Returns the resolved symbol. If that fails, simply return the address.
59091@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59092 mutex_unlock(&task->signal->cred_guard_mutex);
59093 }
59094
59095-#ifdef CONFIG_STACKTRACE
59096+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59097
59098 #define MAX_STACK_TRACE_DEPTH 64
59099
59100@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59101 return count;
59102 }
59103
59104-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59105+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59106 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59107 {
59108 long nr;
59109@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59110 /************************************************************************/
59111
59112 /* permission checks */
59113-static int proc_fd_access_allowed(struct inode *inode)
59114+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59115 {
59116 struct task_struct *task;
59117 int allowed = 0;
59118@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59119 */
59120 task = get_proc_task(inode);
59121 if (task) {
59122- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59123+ if (log)
59124+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59125+ else
59126+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59127 put_task_struct(task);
59128 }
59129 return allowed;
59130@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59131 struct task_struct *task,
59132 int hide_pid_min)
59133 {
59134+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59135+ return false;
59136+
59137+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59138+ rcu_read_lock();
59139+ {
59140+ const struct cred *tmpcred = current_cred();
59141+ const struct cred *cred = __task_cred(task);
59142+
59143+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59144+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59145+ || in_group_p(grsec_proc_gid)
59146+#endif
59147+ ) {
59148+ rcu_read_unlock();
59149+ return true;
59150+ }
59151+ }
59152+ rcu_read_unlock();
59153+
59154+ if (!pid->hide_pid)
59155+ return false;
59156+#endif
59157+
59158 if (pid->hide_pid < hide_pid_min)
59159 return true;
59160 if (in_group_p(pid->pid_gid))
59161 return true;
59162+
59163 return ptrace_may_access(task, PTRACE_MODE_READ);
59164 }
59165
59166@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59167 put_task_struct(task);
59168
59169 if (!has_perms) {
59170+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59171+ {
59172+#else
59173 if (pid->hide_pid == 2) {
59174+#endif
59175 /*
59176 * Let's make getdents(), stat(), and open()
59177 * consistent with each other. If a process
59178@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59179 if (!task)
59180 return -ESRCH;
59181
59182+ if (gr_acl_handle_procpidmem(task)) {
59183+ put_task_struct(task);
59184+ return -EPERM;
59185+ }
59186+
59187 mm = mm_access(task, mode);
59188 put_task_struct(task);
59189
59190@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59191
59192 file->private_data = mm;
59193
59194+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59195+ file->f_version = current->exec_id;
59196+#endif
59197+
59198 return 0;
59199 }
59200
59201@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59202 ssize_t copied;
59203 char *page;
59204
59205+#ifdef CONFIG_GRKERNSEC
59206+ if (write)
59207+ return -EPERM;
59208+#endif
59209+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59210+ if (file->f_version != current->exec_id) {
59211+ gr_log_badprocpid("mem");
59212+ return 0;
59213+ }
59214+#endif
59215+
59216 if (!mm)
59217 return 0;
59218
59219@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59220 goto free;
59221
59222 while (count > 0) {
59223- int this_len = min_t(int, count, PAGE_SIZE);
59224+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59225
59226 if (write && copy_from_user(page, buf, this_len)) {
59227 copied = -EFAULT;
59228@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59229 if (!mm)
59230 return 0;
59231
59232+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59233+ if (file->f_version != current->exec_id) {
59234+ gr_log_badprocpid("environ");
59235+ return 0;
59236+ }
59237+#endif
59238+
59239 page = (char *)__get_free_page(GFP_TEMPORARY);
59240 if (!page)
59241 return -ENOMEM;
59242@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59243 goto free;
59244 while (count > 0) {
59245 size_t this_len, max_len;
59246- int retval;
59247+ ssize_t retval;
59248
59249 if (src >= (mm->env_end - mm->env_start))
59250 break;
59251@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59252 int error = -EACCES;
59253
59254 /* Are we allowed to snoop on the tasks file descriptors? */
59255- if (!proc_fd_access_allowed(inode))
59256+ if (!proc_fd_access_allowed(inode, 0))
59257 goto out;
59258
59259 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59260@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59261 struct path path;
59262
59263 /* Are we allowed to snoop on the tasks file descriptors? */
59264- if (!proc_fd_access_allowed(inode))
59265- goto out;
59266+ /* logging this is needed for learning on chromium to work properly,
59267+ but we don't want to flood the logs from 'ps' which does a readlink
59268+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59269+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59270+ */
59271+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59272+ if (!proc_fd_access_allowed(inode,0))
59273+ goto out;
59274+ } else {
59275+ if (!proc_fd_access_allowed(inode,1))
59276+ goto out;
59277+ }
59278
59279 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59280 if (error)
59281@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59282 rcu_read_lock();
59283 cred = __task_cred(task);
59284 inode->i_uid = cred->euid;
59285+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59286+ inode->i_gid = grsec_proc_gid;
59287+#else
59288 inode->i_gid = cred->egid;
59289+#endif
59290 rcu_read_unlock();
59291 }
59292 security_task_to_inode(task, inode);
59293@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59294 return -ENOENT;
59295 }
59296 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59297+#ifdef CONFIG_GRKERNSEC_PROC_USER
59298+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59299+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59300+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59301+#endif
59302 task_dumpable(task)) {
59303 cred = __task_cred(task);
59304 stat->uid = cred->euid;
59305+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59306+ stat->gid = grsec_proc_gid;
59307+#else
59308 stat->gid = cred->egid;
59309+#endif
59310 }
59311 }
59312 rcu_read_unlock();
59313@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59314
59315 if (task) {
59316 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59317+#ifdef CONFIG_GRKERNSEC_PROC_USER
59318+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59319+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59320+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59321+#endif
59322 task_dumpable(task)) {
59323 rcu_read_lock();
59324 cred = __task_cred(task);
59325 inode->i_uid = cred->euid;
59326+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59327+ inode->i_gid = grsec_proc_gid;
59328+#else
59329 inode->i_gid = cred->egid;
59330+#endif
59331 rcu_read_unlock();
59332 } else {
59333 inode->i_uid = GLOBAL_ROOT_UID;
59334@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59335 if (!task)
59336 goto out_no_task;
59337
59338+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59339+ goto out;
59340+
59341 /*
59342 * Yes, it does not scale. And it should not. Don't add
59343 * new entries into /proc/<tgid>/ without very good reasons.
59344@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59345 if (!task)
59346 return -ENOENT;
59347
59348+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59349+ goto out;
59350+
59351 if (!dir_emit_dots(file, ctx))
59352 goto out;
59353
59354@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59355 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59356 #endif
59357 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59358-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59359+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59360 INF("syscall", S_IRUGO, proc_pid_syscall),
59361 #endif
59362 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59363@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59364 #ifdef CONFIG_SECURITY
59365 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59366 #endif
59367-#ifdef CONFIG_KALLSYMS
59368+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59369 INF("wchan", S_IRUGO, proc_pid_wchan),
59370 #endif
59371-#ifdef CONFIG_STACKTRACE
59372+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59373 ONE("stack", S_IRUGO, proc_pid_stack),
59374 #endif
59375 #ifdef CONFIG_SCHEDSTATS
59376@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59377 #ifdef CONFIG_HARDWALL
59378 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59379 #endif
59380+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59381+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59382+#endif
59383 #ifdef CONFIG_USER_NS
59384 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59385 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59386@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59387 if (!inode)
59388 goto out;
59389
59390+#ifdef CONFIG_GRKERNSEC_PROC_USER
59391+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59392+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59393+ inode->i_gid = grsec_proc_gid;
59394+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59395+#else
59396 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59397+#endif
59398 inode->i_op = &proc_tgid_base_inode_operations;
59399 inode->i_fop = &proc_tgid_base_operations;
59400 inode->i_flags|=S_IMMUTABLE;
59401@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59402 if (!task)
59403 goto out;
59404
59405+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59406+ goto out_put_task;
59407+
59408 result = proc_pid_instantiate(dir, dentry, task, NULL);
59409+out_put_task:
59410 put_task_struct(task);
59411 out:
59412 return ERR_PTR(result);
59413@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59414 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59415 #endif
59416 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59417-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59418+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59419 INF("syscall", S_IRUGO, proc_pid_syscall),
59420 #endif
59421 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59422@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59423 #ifdef CONFIG_SECURITY
59424 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59425 #endif
59426-#ifdef CONFIG_KALLSYMS
59427+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59428 INF("wchan", S_IRUGO, proc_pid_wchan),
59429 #endif
59430-#ifdef CONFIG_STACKTRACE
59431+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59432 ONE("stack", S_IRUGO, proc_pid_stack),
59433 #endif
59434 #ifdef CONFIG_SCHEDSTATS
59435diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59436index 82676e3..5f8518a 100644
59437--- a/fs/proc/cmdline.c
59438+++ b/fs/proc/cmdline.c
59439@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59440
59441 static int __init proc_cmdline_init(void)
59442 {
59443+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59444+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59445+#else
59446 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59447+#endif
59448 return 0;
59449 }
59450 module_init(proc_cmdline_init);
59451diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59452index b143471..bb105e5 100644
59453--- a/fs/proc/devices.c
59454+++ b/fs/proc/devices.c
59455@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59456
59457 static int __init proc_devices_init(void)
59458 {
59459+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59460+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59461+#else
59462 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59463+#endif
59464 return 0;
59465 }
59466 module_init(proc_devices_init);
59467diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59468index 0ff80f9..a1d7500 100644
59469--- a/fs/proc/fd.c
59470+++ b/fs/proc/fd.c
59471@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59472 if (!task)
59473 return -ENOENT;
59474
59475- files = get_files_struct(task);
59476+ if (!gr_acl_handle_procpidmem(task))
59477+ files = get_files_struct(task);
59478 put_task_struct(task);
59479
59480 if (files) {
59481@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59482 */
59483 int proc_fd_permission(struct inode *inode, int mask)
59484 {
59485+ struct task_struct *task;
59486 int rv = generic_permission(inode, mask);
59487- if (rv == 0)
59488- return 0;
59489+
59490 if (task_pid(current) == proc_pid(inode))
59491 rv = 0;
59492+
59493+ task = get_proc_task(inode);
59494+ if (task == NULL)
59495+ return rv;
59496+
59497+ if (gr_acl_handle_procpidmem(task))
59498+ rv = -EACCES;
59499+
59500+ put_task_struct(task);
59501+
59502 return rv;
59503 }
59504
59505diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59506index 073aea6..0630370 100644
59507--- a/fs/proc/inode.c
59508+++ b/fs/proc/inode.c
59509@@ -23,11 +23,17 @@
59510 #include <linux/slab.h>
59511 #include <linux/mount.h>
59512 #include <linux/magic.h>
59513+#include <linux/grsecurity.h>
59514
59515 #include <asm/uaccess.h>
59516
59517 #include "internal.h"
59518
59519+#ifdef CONFIG_PROC_SYSCTL
59520+extern const struct inode_operations proc_sys_inode_operations;
59521+extern const struct inode_operations proc_sys_dir_operations;
59522+#endif
59523+
59524 static void proc_evict_inode(struct inode *inode)
59525 {
59526 struct proc_dir_entry *de;
59527@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59528 ns = PROC_I(inode)->ns.ns;
59529 if (ns_ops && ns)
59530 ns_ops->put(ns);
59531+
59532+#ifdef CONFIG_PROC_SYSCTL
59533+ if (inode->i_op == &proc_sys_inode_operations ||
59534+ inode->i_op == &proc_sys_dir_operations)
59535+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59536+#endif
59537+
59538 }
59539
59540 static struct kmem_cache * proc_inode_cachep;
59541@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59542 if (de->mode) {
59543 inode->i_mode = de->mode;
59544 inode->i_uid = de->uid;
59545+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59546+ inode->i_gid = grsec_proc_gid;
59547+#else
59548 inode->i_gid = de->gid;
59549+#endif
59550 }
59551 if (de->size)
59552 inode->i_size = de->size;
59553diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59554index 651d09a..60c73ae 100644
59555--- a/fs/proc/internal.h
59556+++ b/fs/proc/internal.h
59557@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59558 struct pid *, struct task_struct *);
59559 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59560 struct pid *, struct task_struct *);
59561+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59562+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59563+#endif
59564
59565 /*
59566 * base.c
59567diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59568index 06ea155..9a798c7 100644
59569--- a/fs/proc/kcore.c
59570+++ b/fs/proc/kcore.c
59571@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59572 * the addresses in the elf_phdr on our list.
59573 */
59574 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59575- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59576+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59577+ if (tsz > buflen)
59578 tsz = buflen;
59579-
59580+
59581 while (buflen) {
59582 struct kcore_list *m;
59583
59584@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59585 kfree(elf_buf);
59586 } else {
59587 if (kern_addr_valid(start)) {
59588- unsigned long n;
59589+ char *elf_buf;
59590+ mm_segment_t oldfs;
59591
59592- n = copy_to_user(buffer, (char *)start, tsz);
59593- /*
59594- * We cannot distinguish between fault on source
59595- * and fault on destination. When this happens
59596- * we clear too and hope it will trigger the
59597- * EFAULT again.
59598- */
59599- if (n) {
59600- if (clear_user(buffer + tsz - n,
59601- n))
59602+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59603+ if (!elf_buf)
59604+ return -ENOMEM;
59605+ oldfs = get_fs();
59606+ set_fs(KERNEL_DS);
59607+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59608+ set_fs(oldfs);
59609+ if (copy_to_user(buffer, elf_buf, tsz)) {
59610+ kfree(elf_buf);
59611 return -EFAULT;
59612+ }
59613 }
59614+ set_fs(oldfs);
59615+ kfree(elf_buf);
59616 } else {
59617 if (clear_user(buffer, tsz))
59618 return -EFAULT;
59619@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59620
59621 static int open_kcore(struct inode *inode, struct file *filp)
59622 {
59623+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59624+ return -EPERM;
59625+#endif
59626 if (!capable(CAP_SYS_RAWIO))
59627 return -EPERM;
59628 if (kcore_need_update)
59629diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59630index 5aa847a..f77c8d4 100644
59631--- a/fs/proc/meminfo.c
59632+++ b/fs/proc/meminfo.c
59633@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59634 vmi.used >> 10,
59635 vmi.largest_chunk >> 10
59636 #ifdef CONFIG_MEMORY_FAILURE
59637- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59638+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59639 #endif
59640 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59641 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59642diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59643index ccfd99b..1b7e255 100644
59644--- a/fs/proc/nommu.c
59645+++ b/fs/proc/nommu.c
59646@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59647 if (len < 1)
59648 len = 1;
59649 seq_printf(m, "%*c", len, ' ');
59650- seq_path(m, &file->f_path, "");
59651+ seq_path(m, &file->f_path, "\n\\");
59652 }
59653
59654 seq_putc(m, '\n');
59655diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59656index 4677bb7..408e936 100644
59657--- a/fs/proc/proc_net.c
59658+++ b/fs/proc/proc_net.c
59659@@ -23,6 +23,7 @@
59660 #include <linux/nsproxy.h>
59661 #include <net/net_namespace.h>
59662 #include <linux/seq_file.h>
59663+#include <linux/grsecurity.h>
59664
59665 #include "internal.h"
59666
59667@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59668 struct task_struct *task;
59669 struct nsproxy *ns;
59670 struct net *net = NULL;
59671+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59672+ const struct cred *cred = current_cred();
59673+#endif
59674+
59675+#ifdef CONFIG_GRKERNSEC_PROC_USER
59676+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59677+ return net;
59678+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59679+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59680+ return net;
59681+#endif
59682
59683 rcu_read_lock();
59684 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59685diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59686index 7129046..f2779c6 100644
59687--- a/fs/proc/proc_sysctl.c
59688+++ b/fs/proc/proc_sysctl.c
59689@@ -13,11 +13,15 @@
59690 #include <linux/module.h>
59691 #include "internal.h"
59692
59693+extern int gr_handle_chroot_sysctl(const int op);
59694+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59695+ const int op);
59696+
59697 static const struct dentry_operations proc_sys_dentry_operations;
59698 static const struct file_operations proc_sys_file_operations;
59699-static const struct inode_operations proc_sys_inode_operations;
59700+const struct inode_operations proc_sys_inode_operations;
59701 static const struct file_operations proc_sys_dir_file_operations;
59702-static const struct inode_operations proc_sys_dir_operations;
59703+const struct inode_operations proc_sys_dir_operations;
59704
59705 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59706 {
59707@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59708
59709 err = NULL;
59710 d_set_d_op(dentry, &proc_sys_dentry_operations);
59711+
59712+ gr_handle_proc_create(dentry, inode);
59713+
59714 d_add(dentry, inode);
59715
59716 out:
59717@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59718 struct inode *inode = file_inode(filp);
59719 struct ctl_table_header *head = grab_header(inode);
59720 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59721+ int op = write ? MAY_WRITE : MAY_READ;
59722 ssize_t error;
59723 size_t res;
59724
59725@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59726 * and won't be until we finish.
59727 */
59728 error = -EPERM;
59729- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59730+ if (sysctl_perm(head, table, op))
59731 goto out;
59732
59733 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59734@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59735 if (!table->proc_handler)
59736 goto out;
59737
59738+#ifdef CONFIG_GRKERNSEC
59739+ error = -EPERM;
59740+ if (gr_handle_chroot_sysctl(op))
59741+ goto out;
59742+ dget(filp->f_path.dentry);
59743+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59744+ dput(filp->f_path.dentry);
59745+ goto out;
59746+ }
59747+ dput(filp->f_path.dentry);
59748+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59749+ goto out;
59750+ if (write && !capable(CAP_SYS_ADMIN))
59751+ goto out;
59752+#endif
59753+
59754 /* careful: calling conventions are nasty here */
59755 res = count;
59756 error = table->proc_handler(table, write, buf, &res, ppos);
59757@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59758 return false;
59759 } else {
59760 d_set_d_op(child, &proc_sys_dentry_operations);
59761+
59762+ gr_handle_proc_create(child, inode);
59763+
59764 d_add(child, inode);
59765 }
59766 } else {
59767@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59768 if ((*pos)++ < ctx->pos)
59769 return true;
59770
59771+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59772+ return 0;
59773+
59774 if (unlikely(S_ISLNK(table->mode)))
59775 res = proc_sys_link_fill_cache(file, ctx, head, table);
59776 else
59777@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59778 if (IS_ERR(head))
59779 return PTR_ERR(head);
59780
59781+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59782+ return -ENOENT;
59783+
59784 generic_fillattr(inode, stat);
59785 if (table)
59786 stat->mode = (stat->mode & S_IFMT) | table->mode;
59787@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59788 .llseek = generic_file_llseek,
59789 };
59790
59791-static const struct inode_operations proc_sys_inode_operations = {
59792+const struct inode_operations proc_sys_inode_operations = {
59793 .permission = proc_sys_permission,
59794 .setattr = proc_sys_setattr,
59795 .getattr = proc_sys_getattr,
59796 };
59797
59798-static const struct inode_operations proc_sys_dir_operations = {
59799+const struct inode_operations proc_sys_dir_operations = {
59800 .lookup = proc_sys_lookup,
59801 .permission = proc_sys_permission,
59802 .setattr = proc_sys_setattr,
59803@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59804 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59805 const char *name, int namelen)
59806 {
59807- struct ctl_table *table;
59808+ ctl_table_no_const *table;
59809 struct ctl_dir *new;
59810 struct ctl_node *node;
59811 char *new_name;
59812@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59813 return NULL;
59814
59815 node = (struct ctl_node *)(new + 1);
59816- table = (struct ctl_table *)(node + 1);
59817+ table = (ctl_table_no_const *)(node + 1);
59818 new_name = (char *)(table + 2);
59819 memcpy(new_name, name, namelen);
59820 new_name[namelen] = '\0';
59821@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59822 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59823 struct ctl_table_root *link_root)
59824 {
59825- struct ctl_table *link_table, *entry, *link;
59826+ ctl_table_no_const *link_table, *link;
59827+ struct ctl_table *entry;
59828 struct ctl_table_header *links;
59829 struct ctl_node *node;
59830 char *link_name;
59831@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59832 return NULL;
59833
59834 node = (struct ctl_node *)(links + 1);
59835- link_table = (struct ctl_table *)(node + nr_entries);
59836+ link_table = (ctl_table_no_const *)(node + nr_entries);
59837 link_name = (char *)&link_table[nr_entries + 1];
59838
59839 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59840@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59841 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59842 struct ctl_table *table)
59843 {
59844- struct ctl_table *ctl_table_arg = NULL;
59845- struct ctl_table *entry, *files;
59846+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59847+ struct ctl_table *entry;
59848 int nr_files = 0;
59849 int nr_dirs = 0;
59850 int err = -ENOMEM;
59851@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59852 nr_files++;
59853 }
59854
59855- files = table;
59856 /* If there are mixed files and directories we need a new table */
59857 if (nr_dirs && nr_files) {
59858- struct ctl_table *new;
59859+ ctl_table_no_const *new;
59860 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59861 GFP_KERNEL);
59862 if (!files)
59863@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59864 /* Register everything except a directory full of subdirectories */
59865 if (nr_files || !nr_dirs) {
59866 struct ctl_table_header *header;
59867- header = __register_sysctl_table(set, path, files);
59868+ header = __register_sysctl_table(set, path, files ? files : table);
59869 if (!header) {
59870 kfree(ctl_table_arg);
59871 goto out;
59872diff --git a/fs/proc/root.c b/fs/proc/root.c
59873index 0e0e83c..005ba6a 100644
59874--- a/fs/proc/root.c
59875+++ b/fs/proc/root.c
59876@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59877 #ifdef CONFIG_PROC_DEVICETREE
59878 proc_device_tree_init();
59879 #endif
59880+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59881+#ifdef CONFIG_GRKERNSEC_PROC_USER
59882+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59883+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59884+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59885+#endif
59886+#else
59887 proc_mkdir("bus", NULL);
59888+#endif
59889 proc_sys_init();
59890 }
59891
59892diff --git a/fs/proc/self.c b/fs/proc/self.c
59893index 6b6a993..807cccc 100644
59894--- a/fs/proc/self.c
59895+++ b/fs/proc/self.c
59896@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59897 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59898 void *cookie)
59899 {
59900- char *s = nd_get_link(nd);
59901+ const char *s = nd_get_link(nd);
59902 if (!IS_ERR(s))
59903 kfree(s);
59904 }
59905diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59906index 107d026..c715aeb 100644
59907--- a/fs/proc/task_mmu.c
59908+++ b/fs/proc/task_mmu.c
59909@@ -12,12 +12,19 @@
59910 #include <linux/swap.h>
59911 #include <linux/swapops.h>
59912 #include <linux/mmu_notifier.h>
59913+#include <linux/grsecurity.h>
59914
59915 #include <asm/elf.h>
59916 #include <asm/uaccess.h>
59917 #include <asm/tlbflush.h>
59918 #include "internal.h"
59919
59920+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59921+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59922+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59923+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59924+#endif
59925+
59926 void task_mem(struct seq_file *m, struct mm_struct *mm)
59927 {
59928 unsigned long data, text, lib, swap;
59929@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59930 "VmExe:\t%8lu kB\n"
59931 "VmLib:\t%8lu kB\n"
59932 "VmPTE:\t%8lu kB\n"
59933- "VmSwap:\t%8lu kB\n",
59934- hiwater_vm << (PAGE_SHIFT-10),
59935+ "VmSwap:\t%8lu kB\n"
59936+
59937+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59938+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59939+#endif
59940+
59941+ ,hiwater_vm << (PAGE_SHIFT-10),
59942 total_vm << (PAGE_SHIFT-10),
59943 mm->locked_vm << (PAGE_SHIFT-10),
59944 mm->pinned_vm << (PAGE_SHIFT-10),
59945@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59946 data << (PAGE_SHIFT-10),
59947 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59948 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59949- swap << (PAGE_SHIFT-10));
59950+ swap << (PAGE_SHIFT-10)
59951+
59952+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59953+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59954+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59955+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59956+#else
59957+ , mm->context.user_cs_base
59958+ , mm->context.user_cs_limit
59959+#endif
59960+#endif
59961+
59962+ );
59963 }
59964
59965 unsigned long task_vsize(struct mm_struct *mm)
59966@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59967 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59968 }
59969
59970- /* We don't show the stack guard page in /proc/maps */
59971+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59972+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59973+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59974+#else
59975 start = vma->vm_start;
59976- if (stack_guard_page_start(vma, start))
59977- start += PAGE_SIZE;
59978 end = vma->vm_end;
59979- if (stack_guard_page_end(vma, end))
59980- end -= PAGE_SIZE;
59981+#endif
59982
59983 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59984 start,
59985@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59986 flags & VM_WRITE ? 'w' : '-',
59987 flags & VM_EXEC ? 'x' : '-',
59988 flags & VM_MAYSHARE ? 's' : 'p',
59989+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59990+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59991+#else
59992 pgoff,
59993+#endif
59994 MAJOR(dev), MINOR(dev), ino, &len);
59995
59996 /*
59997@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59998 */
59999 if (file) {
60000 pad_len_spaces(m, len);
60001- seq_path(m, &file->f_path, "\n");
60002+ seq_path(m, &file->f_path, "\n\\");
60003 goto done;
60004 }
60005
60006@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60007 * Thread stack in /proc/PID/task/TID/maps or
60008 * the main process stack.
60009 */
60010- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60011- vma->vm_end >= mm->start_stack)) {
60012+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60013+ (vma->vm_start <= mm->start_stack &&
60014+ vma->vm_end >= mm->start_stack)) {
60015 name = "[stack]";
60016 } else {
60017 /* Thread stack in /proc/PID/maps */
60018@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60019 struct proc_maps_private *priv = m->private;
60020 struct task_struct *task = priv->task;
60021
60022+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60023+ if (current->exec_id != m->exec_id) {
60024+ gr_log_badprocpid("maps");
60025+ return 0;
60026+ }
60027+#endif
60028+
60029 show_map_vma(m, vma, is_pid);
60030
60031 if (m->count < m->size) /* vma is copied successfully */
60032@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60033 .private = &mss,
60034 };
60035
60036+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60037+ if (current->exec_id != m->exec_id) {
60038+ gr_log_badprocpid("smaps");
60039+ return 0;
60040+ }
60041+#endif
60042 memset(&mss, 0, sizeof mss);
60043- mss.vma = vma;
60044- /* mmap_sem is held in m_start */
60045- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60046- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60047-
60048+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60049+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60050+#endif
60051+ mss.vma = vma;
60052+ /* mmap_sem is held in m_start */
60053+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60054+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60055+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60056+ }
60057+#endif
60058 show_map_vma(m, vma, is_pid);
60059
60060 seq_printf(m,
60061@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60062 "KernelPageSize: %8lu kB\n"
60063 "MMUPageSize: %8lu kB\n"
60064 "Locked: %8lu kB\n",
60065+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60066+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60067+#else
60068 (vma->vm_end - vma->vm_start) >> 10,
60069+#endif
60070 mss.resident >> 10,
60071 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60072 mss.shared_clean >> 10,
60073@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60074 int n;
60075 char buffer[50];
60076
60077+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60078+ if (current->exec_id != m->exec_id) {
60079+ gr_log_badprocpid("numa_maps");
60080+ return 0;
60081+ }
60082+#endif
60083+
60084 if (!mm)
60085 return 0;
60086
60087@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60088 mpol_to_str(buffer, sizeof(buffer), pol);
60089 mpol_cond_put(pol);
60090
60091+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60092+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60093+#else
60094 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60095+#endif
60096
60097 if (file) {
60098 seq_printf(m, " file=");
60099- seq_path(m, &file->f_path, "\n\t= ");
60100+ seq_path(m, &file->f_path, "\n\t\\= ");
60101 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60102 seq_printf(m, " heap");
60103 } else {
60104diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60105index 56123a6..5a2f6ec 100644
60106--- a/fs/proc/task_nommu.c
60107+++ b/fs/proc/task_nommu.c
60108@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60109 else
60110 bytes += kobjsize(mm);
60111
60112- if (current->fs && current->fs->users > 1)
60113+ if (current->fs && atomic_read(&current->fs->users) > 1)
60114 sbytes += kobjsize(current->fs);
60115 else
60116 bytes += kobjsize(current->fs);
60117@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60118
60119 if (file) {
60120 pad_len_spaces(m, len);
60121- seq_path(m, &file->f_path, "");
60122+ seq_path(m, &file->f_path, "\n\\");
60123 } else if (mm) {
60124 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60125
60126diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60127index a1a16eb..6be46ed 100644
60128--- a/fs/proc/vmcore.c
60129+++ b/fs/proc/vmcore.c
60130@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60131 nr_bytes = count;
60132
60133 /* If pfn is not ram, return zeros for sparse dump files */
60134- if (pfn_is_ram(pfn) == 0)
60135- memset(buf, 0, nr_bytes);
60136- else {
60137+ if (pfn_is_ram(pfn) == 0) {
60138+ if (userbuf) {
60139+ if (clear_user((char __force_user *)buf, nr_bytes))
60140+ return -EFAULT;
60141+ } else
60142+ memset(buf, 0, nr_bytes);
60143+ } else {
60144 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60145 offset, userbuf);
60146 if (tmp < 0)
60147@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60148 if (*fpos < m->offset + m->size) {
60149 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60150 start = m->paddr + *fpos - m->offset;
60151- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60152+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60153 if (tmp < 0)
60154 return tmp;
60155 buflen -= tsz;
60156diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60157index b00fcc9..e0c6381 100644
60158--- a/fs/qnx6/qnx6.h
60159+++ b/fs/qnx6/qnx6.h
60160@@ -74,7 +74,7 @@ enum {
60161 BYTESEX_BE,
60162 };
60163
60164-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60165+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60166 {
60167 if (sbi->s_bytesex == BYTESEX_LE)
60168 return le64_to_cpu((__force __le64)n);
60169@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60170 return (__force __fs64)cpu_to_be64(n);
60171 }
60172
60173-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60174+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60175 {
60176 if (sbi->s_bytesex == BYTESEX_LE)
60177 return le32_to_cpu((__force __le32)n);
60178diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60179index 16e8abb..2dcf914 100644
60180--- a/fs/quota/netlink.c
60181+++ b/fs/quota/netlink.c
60182@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60183 void quota_send_warning(struct kqid qid, dev_t dev,
60184 const char warntype)
60185 {
60186- static atomic_t seq;
60187+ static atomic_unchecked_t seq;
60188 struct sk_buff *skb;
60189 void *msg_head;
60190 int ret;
60191@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60192 "VFS: Not enough memory to send quota warning.\n");
60193 return;
60194 }
60195- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60196+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60197 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60198 if (!msg_head) {
60199 printk(KERN_ERR
60200diff --git a/fs/read_write.c b/fs/read_write.c
60201index 122a384..0b7ecf2 100644
60202--- a/fs/read_write.c
60203+++ b/fs/read_write.c
60204@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60205
60206 old_fs = get_fs();
60207 set_fs(get_ds());
60208- p = (__force const char __user *)buf;
60209+ p = (const char __force_user *)buf;
60210 if (count > MAX_RW_COUNT)
60211 count = MAX_RW_COUNT;
60212 if (file->f_op->write)
60213diff --git a/fs/readdir.c b/fs/readdir.c
60214index 93d71e5..6a14be8 100644
60215--- a/fs/readdir.c
60216+++ b/fs/readdir.c
60217@@ -17,6 +17,7 @@
60218 #include <linux/security.h>
60219 #include <linux/syscalls.h>
60220 #include <linux/unistd.h>
60221+#include <linux/namei.h>
60222
60223 #include <asm/uaccess.h>
60224
60225@@ -69,6 +70,7 @@ struct old_linux_dirent {
60226 struct readdir_callback {
60227 struct dir_context ctx;
60228 struct old_linux_dirent __user * dirent;
60229+ struct file * file;
60230 int result;
60231 };
60232
60233@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60234 buf->result = -EOVERFLOW;
60235 return -EOVERFLOW;
60236 }
60237+
60238+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60239+ return 0;
60240+
60241 buf->result++;
60242 dirent = buf->dirent;
60243 if (!access_ok(VERIFY_WRITE, dirent,
60244@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60245 if (!f.file)
60246 return -EBADF;
60247
60248+ buf.file = f.file;
60249 error = iterate_dir(f.file, &buf.ctx);
60250 if (buf.result)
60251 error = buf.result;
60252@@ -142,6 +149,7 @@ struct getdents_callback {
60253 struct dir_context ctx;
60254 struct linux_dirent __user * current_dir;
60255 struct linux_dirent __user * previous;
60256+ struct file * file;
60257 int count;
60258 int error;
60259 };
60260@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60261 buf->error = -EOVERFLOW;
60262 return -EOVERFLOW;
60263 }
60264+
60265+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60266+ return 0;
60267+
60268 dirent = buf->previous;
60269 if (dirent) {
60270 if (__put_user(offset, &dirent->d_off))
60271@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60272 if (!f.file)
60273 return -EBADF;
60274
60275+ buf.file = f.file;
60276 error = iterate_dir(f.file, &buf.ctx);
60277 if (error >= 0)
60278 error = buf.error;
60279@@ -226,6 +239,7 @@ struct getdents_callback64 {
60280 struct dir_context ctx;
60281 struct linux_dirent64 __user * current_dir;
60282 struct linux_dirent64 __user * previous;
60283+ struct file *file;
60284 int count;
60285 int error;
60286 };
60287@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60288 buf->error = -EINVAL; /* only used if we fail.. */
60289 if (reclen > buf->count)
60290 return -EINVAL;
60291+
60292+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60293+ return 0;
60294+
60295 dirent = buf->previous;
60296 if (dirent) {
60297 if (__put_user(offset, &dirent->d_off))
60298@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60299 if (!f.file)
60300 return -EBADF;
60301
60302+ buf.file = f.file;
60303 error = iterate_dir(f.file, &buf.ctx);
60304 if (error >= 0)
60305 error = buf.error;
60306diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60307index 2b7882b..1c5ef48 100644
60308--- a/fs/reiserfs/do_balan.c
60309+++ b/fs/reiserfs/do_balan.c
60310@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60311 return;
60312 }
60313
60314- atomic_inc(&(fs_generation(tb->tb_sb)));
60315+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60316 do_balance_starts(tb);
60317
60318 /* balance leaf returns 0 except if combining L R and S into
60319diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60320index a958444..42b2323 100644
60321--- a/fs/reiserfs/procfs.c
60322+++ b/fs/reiserfs/procfs.c
60323@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60324 "SMALL_TAILS " : "NO_TAILS ",
60325 replay_only(sb) ? "REPLAY_ONLY " : "",
60326 convert_reiserfs(sb) ? "CONV " : "",
60327- atomic_read(&r->s_generation_counter),
60328+ atomic_read_unchecked(&r->s_generation_counter),
60329 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60330 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60331 SF(s_good_search_by_key_reada), SF(s_bmaps),
60332diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60333index 3df5ce6..8c0f4b0 100644
60334--- a/fs/reiserfs/reiserfs.h
60335+++ b/fs/reiserfs/reiserfs.h
60336@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60337 /* Comment? -Hans */
60338 wait_queue_head_t s_wait;
60339 /* To be obsoleted soon by per buffer seals.. -Hans */
60340- atomic_t s_generation_counter; // increased by one every time the
60341+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60342 // tree gets re-balanced
60343 unsigned long s_properties; /* File system properties. Currently holds
60344 on-disk FS format */
60345@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60346 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60347
60348 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60349-#define get_generation(s) atomic_read (&fs_generation(s))
60350+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60351 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60352 #define __fs_changed(gen,s) (gen != get_generation (s))
60353 #define fs_changed(gen,s) \
60354diff --git a/fs/select.c b/fs/select.c
60355index 35d4adc7..d6c60db 100644
60356--- a/fs/select.c
60357+++ b/fs/select.c
60358@@ -20,6 +20,7 @@
60359 #include <linux/export.h>
60360 #include <linux/slab.h>
60361 #include <linux/poll.h>
60362+#include <linux/security.h>
60363 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60364 #include <linux/file.h>
60365 #include <linux/fdtable.h>
60366@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60367 struct poll_list *walk = head;
60368 unsigned long todo = nfds;
60369
60370+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60371 if (nfds > rlimit(RLIMIT_NOFILE))
60372 return -EINVAL;
60373
60374diff --git a/fs/seq_file.c b/fs/seq_file.c
60375index 3135c25..d0395dd 100644
60376--- a/fs/seq_file.c
60377+++ b/fs/seq_file.c
60378@@ -10,6 +10,7 @@
60379 #include <linux/seq_file.h>
60380 #include <linux/slab.h>
60381 #include <linux/cred.h>
60382+#include <linux/sched.h>
60383
60384 #include <asm/uaccess.h>
60385 #include <asm/page.h>
60386@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60387 #ifdef CONFIG_USER_NS
60388 p->user_ns = file->f_cred->user_ns;
60389 #endif
60390+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60391+ p->exec_id = current->exec_id;
60392+#endif
60393
60394 /*
60395 * Wrappers around seq_open(e.g. swaps_open) need to be
60396@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60397 return 0;
60398 }
60399 if (!m->buf) {
60400- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60401+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60402 if (!m->buf)
60403 return -ENOMEM;
60404 }
60405@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60406 Eoverflow:
60407 m->op->stop(m, p);
60408 kfree(m->buf);
60409- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60410+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60411 return !m->buf ? -ENOMEM : -EAGAIN;
60412 }
60413
60414@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60415
60416 /* grab buffer if we didn't have one */
60417 if (!m->buf) {
60418- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60419+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60420 if (!m->buf)
60421 goto Enomem;
60422 }
60423@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60424 goto Fill;
60425 m->op->stop(m, p);
60426 kfree(m->buf);
60427- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60428+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60429 if (!m->buf)
60430 goto Enomem;
60431 m->count = 0;
60432@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60433 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60434 void *data)
60435 {
60436- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60437+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60438 int res = -ENOMEM;
60439
60440 if (op) {
60441diff --git a/fs/splice.c b/fs/splice.c
60442index 3b7ee65..87fc2e4 100644
60443--- a/fs/splice.c
60444+++ b/fs/splice.c
60445@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60446 pipe_lock(pipe);
60447
60448 for (;;) {
60449- if (!pipe->readers) {
60450+ if (!atomic_read(&pipe->readers)) {
60451 send_sig(SIGPIPE, current, 0);
60452 if (!ret)
60453 ret = -EPIPE;
60454@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60455 page_nr++;
60456 ret += buf->len;
60457
60458- if (pipe->files)
60459+ if (atomic_read(&pipe->files))
60460 do_wakeup = 1;
60461
60462 if (!--spd->nr_pages)
60463@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60464 do_wakeup = 0;
60465 }
60466
60467- pipe->waiting_writers++;
60468+ atomic_inc(&pipe->waiting_writers);
60469 pipe_wait(pipe);
60470- pipe->waiting_writers--;
60471+ atomic_dec(&pipe->waiting_writers);
60472 }
60473
60474 pipe_unlock(pipe);
60475@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60476 old_fs = get_fs();
60477 set_fs(get_ds());
60478 /* The cast to a user pointer is valid due to the set_fs() */
60479- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60480+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60481 set_fs(old_fs);
60482
60483 return res;
60484@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60485 old_fs = get_fs();
60486 set_fs(get_ds());
60487 /* The cast to a user pointer is valid due to the set_fs() */
60488- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60489+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60490 set_fs(old_fs);
60491
60492 return res;
60493@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60494 goto err;
60495
60496 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60497- vec[i].iov_base = (void __user *) page_address(page);
60498+ vec[i].iov_base = (void __force_user *) page_address(page);
60499 vec[i].iov_len = this_len;
60500 spd.pages[i] = page;
60501 spd.nr_pages++;
60502@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60503 ops->release(pipe, buf);
60504 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60505 pipe->nrbufs--;
60506- if (pipe->files)
60507+ if (atomic_read(&pipe->files))
60508 sd->need_wakeup = true;
60509 }
60510
60511@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60512 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60513 {
60514 while (!pipe->nrbufs) {
60515- if (!pipe->writers)
60516+ if (!atomic_read(&pipe->writers))
60517 return 0;
60518
60519- if (!pipe->waiting_writers && sd->num_spliced)
60520+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60521 return 0;
60522
60523 if (sd->flags & SPLICE_F_NONBLOCK)
60524@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60525 * out of the pipe right after the splice_to_pipe(). So set
60526 * PIPE_READERS appropriately.
60527 */
60528- pipe->readers = 1;
60529+ atomic_set(&pipe->readers, 1);
60530
60531 current->splice_pipe = pipe;
60532 }
60533@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60534
60535 partial[buffers].offset = off;
60536 partial[buffers].len = plen;
60537+ partial[buffers].private = 0;
60538
60539 off = 0;
60540 len -= plen;
60541@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60542 ret = -ERESTARTSYS;
60543 break;
60544 }
60545- if (!pipe->writers)
60546+ if (!atomic_read(&pipe->writers))
60547 break;
60548- if (!pipe->waiting_writers) {
60549+ if (!atomic_read(&pipe->waiting_writers)) {
60550 if (flags & SPLICE_F_NONBLOCK) {
60551 ret = -EAGAIN;
60552 break;
60553@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60554 pipe_lock(pipe);
60555
60556 while (pipe->nrbufs >= pipe->buffers) {
60557- if (!pipe->readers) {
60558+ if (!atomic_read(&pipe->readers)) {
60559 send_sig(SIGPIPE, current, 0);
60560 ret = -EPIPE;
60561 break;
60562@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60563 ret = -ERESTARTSYS;
60564 break;
60565 }
60566- pipe->waiting_writers++;
60567+ atomic_inc(&pipe->waiting_writers);
60568 pipe_wait(pipe);
60569- pipe->waiting_writers--;
60570+ atomic_dec(&pipe->waiting_writers);
60571 }
60572
60573 pipe_unlock(pipe);
60574@@ -1862,14 +1863,14 @@ retry:
60575 pipe_double_lock(ipipe, opipe);
60576
60577 do {
60578- if (!opipe->readers) {
60579+ if (!atomic_read(&opipe->readers)) {
60580 send_sig(SIGPIPE, current, 0);
60581 if (!ret)
60582 ret = -EPIPE;
60583 break;
60584 }
60585
60586- if (!ipipe->nrbufs && !ipipe->writers)
60587+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60588 break;
60589
60590 /*
60591@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60592 pipe_double_lock(ipipe, opipe);
60593
60594 do {
60595- if (!opipe->readers) {
60596+ if (!atomic_read(&opipe->readers)) {
60597 send_sig(SIGPIPE, current, 0);
60598 if (!ret)
60599 ret = -EPIPE;
60600@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60601 * return EAGAIN if we have the potential of some data in the
60602 * future, otherwise just return 0
60603 */
60604- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60605+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60606 ret = -EAGAIN;
60607
60608 pipe_unlock(ipipe);
60609diff --git a/fs/stat.c b/fs/stat.c
60610index 04ce1ac..a13dd1e 100644
60611--- a/fs/stat.c
60612+++ b/fs/stat.c
60613@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60614 stat->gid = inode->i_gid;
60615 stat->rdev = inode->i_rdev;
60616 stat->size = i_size_read(inode);
60617- stat->atime = inode->i_atime;
60618- stat->mtime = inode->i_mtime;
60619+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60620+ stat->atime = inode->i_ctime;
60621+ stat->mtime = inode->i_ctime;
60622+ } else {
60623+ stat->atime = inode->i_atime;
60624+ stat->mtime = inode->i_mtime;
60625+ }
60626 stat->ctime = inode->i_ctime;
60627 stat->blksize = (1 << inode->i_blkbits);
60628 stat->blocks = inode->i_blocks;
60629@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60630 if (retval)
60631 return retval;
60632
60633- if (inode->i_op->getattr)
60634- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60635+ if (inode->i_op->getattr) {
60636+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60637+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60638+ stat->atime = stat->ctime;
60639+ stat->mtime = stat->ctime;
60640+ }
60641+ return retval;
60642+ }
60643
60644 generic_fillattr(inode, stat);
60645 return 0;
60646diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60647index 15c68f9..36a8b3e 100644
60648--- a/fs/sysfs/bin.c
60649+++ b/fs/sysfs/bin.c
60650@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60651 return ret;
60652 }
60653
60654-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60655- void *buf, int len, int write)
60656+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60657+ void *buf, size_t len, int write)
60658 {
60659 struct file *file = vma->vm_file;
60660 struct bin_buffer *bb = file->private_data;
60661 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60662- int ret;
60663+ ssize_t ret;
60664
60665 if (!bb->vm_ops)
60666 return -EINVAL;
60667diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60668index e068e74..92edeb8 100644
60669--- a/fs/sysfs/dir.c
60670+++ b/fs/sysfs/dir.c
60671@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60672 *
60673 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60674 */
60675-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60676+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60677 {
60678 unsigned long hash = init_name_hash();
60679 unsigned int len = strlen(name);
60680@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60681 struct sysfs_dirent *sd;
60682 int rc;
60683
60684+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60685+ const char *parent_name = parent_sd->s_name;
60686+
60687+ mode = S_IFDIR | S_IRWXU;
60688+
60689+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60690+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60691+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60692+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60693+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60694+#endif
60695+
60696 /* allocate */
60697 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60698 if (!sd)
60699diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60700index d2bb7ed..fe8c331 100644
60701--- a/fs/sysfs/file.c
60702+++ b/fs/sysfs/file.c
60703@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60704
60705 struct sysfs_open_dirent {
60706 atomic_t refcnt;
60707- atomic_t event;
60708+ atomic_unchecked_t event;
60709 wait_queue_head_t poll;
60710 struct list_head buffers; /* goes through sysfs_buffer.list */
60711 };
60712@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60713 if (!sysfs_get_active(attr_sd))
60714 return -ENODEV;
60715
60716- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60717+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60718 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60719
60720 sysfs_put_active(attr_sd);
60721@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60722 return -ENOMEM;
60723
60724 atomic_set(&new_od->refcnt, 0);
60725- atomic_set(&new_od->event, 1);
60726+ atomic_set_unchecked(&new_od->event, 1);
60727 init_waitqueue_head(&new_od->poll);
60728 INIT_LIST_HEAD(&new_od->buffers);
60729 goto retry;
60730@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60731
60732 sysfs_put_active(attr_sd);
60733
60734- if (buffer->event != atomic_read(&od->event))
60735+ if (buffer->event != atomic_read_unchecked(&od->event))
60736 goto trigger;
60737
60738 return DEFAULT_POLLMASK;
60739@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60740 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60741 od = sd->s_attr.open;
60742 if (od) {
60743- atomic_inc(&od->event);
60744+ atomic_inc_unchecked(&od->event);
60745 wake_up_interruptible(&od->poll);
60746 }
60747 }
60748diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60749index 8c940df..25b733e 100644
60750--- a/fs/sysfs/symlink.c
60751+++ b/fs/sysfs/symlink.c
60752@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60753
60754 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60755 {
60756- char *page = nd_get_link(nd);
60757+ const char *page = nd_get_link(nd);
60758 if (!IS_ERR(page))
60759 free_page((unsigned long)page);
60760 }
60761diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60762index 69d4889..a810bd4 100644
60763--- a/fs/sysv/sysv.h
60764+++ b/fs/sysv/sysv.h
60765@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60766 #endif
60767 }
60768
60769-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60770+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60771 {
60772 if (sbi->s_bytesex == BYTESEX_PDP)
60773 return PDP_swab((__force __u32)n);
60774diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60775index e18b988..f1d4ad0f 100644
60776--- a/fs/ubifs/io.c
60777+++ b/fs/ubifs/io.c
60778@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60779 return err;
60780 }
60781
60782-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60783+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60784 {
60785 int err;
60786
60787diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60788index c175b4d..8f36a16 100644
60789--- a/fs/udf/misc.c
60790+++ b/fs/udf/misc.c
60791@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60792
60793 u8 udf_tag_checksum(const struct tag *t)
60794 {
60795- u8 *data = (u8 *)t;
60796+ const u8 *data = (const u8 *)t;
60797 u8 checksum = 0;
60798 int i;
60799 for (i = 0; i < sizeof(struct tag); ++i)
60800diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60801index 8d974c4..b82f6ec 100644
60802--- a/fs/ufs/swab.h
60803+++ b/fs/ufs/swab.h
60804@@ -22,7 +22,7 @@ enum {
60805 BYTESEX_BE
60806 };
60807
60808-static inline u64
60809+static inline u64 __intentional_overflow(-1)
60810 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60811 {
60812 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60813@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60814 return (__force __fs64)cpu_to_be64(n);
60815 }
60816
60817-static inline u32
60818+static inline u32 __intentional_overflow(-1)
60819 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60820 {
60821 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60822diff --git a/fs/utimes.c b/fs/utimes.c
60823index f4fb7ec..3fe03c0 100644
60824--- a/fs/utimes.c
60825+++ b/fs/utimes.c
60826@@ -1,6 +1,7 @@
60827 #include <linux/compiler.h>
60828 #include <linux/file.h>
60829 #include <linux/fs.h>
60830+#include <linux/security.h>
60831 #include <linux/linkage.h>
60832 #include <linux/mount.h>
60833 #include <linux/namei.h>
60834@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60835 goto mnt_drop_write_and_out;
60836 }
60837 }
60838+
60839+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60840+ error = -EACCES;
60841+ goto mnt_drop_write_and_out;
60842+ }
60843+
60844 mutex_lock(&inode->i_mutex);
60845 error = notify_change(path->dentry, &newattrs);
60846 mutex_unlock(&inode->i_mutex);
60847diff --git a/fs/xattr.c b/fs/xattr.c
60848index 3377dff..4d074d9 100644
60849--- a/fs/xattr.c
60850+++ b/fs/xattr.c
60851@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60852 return rc;
60853 }
60854
60855+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60856+ssize_t
60857+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60858+{
60859+ struct inode *inode = dentry->d_inode;
60860+ ssize_t error;
60861+
60862+ error = inode_permission(inode, MAY_EXEC);
60863+ if (error)
60864+ return error;
60865+
60866+ if (inode->i_op->getxattr)
60867+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60868+ else
60869+ error = -EOPNOTSUPP;
60870+
60871+ return error;
60872+}
60873+EXPORT_SYMBOL(pax_getxattr);
60874+#endif
60875+
60876 ssize_t
60877 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60878 {
60879@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60880 * Extended attribute SET operations
60881 */
60882 static long
60883-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60884+setxattr(struct path *path, const char __user *name, const void __user *value,
60885 size_t size, int flags)
60886 {
60887 int error;
60888@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60889 posix_acl_fix_xattr_from_user(kvalue, size);
60890 }
60891
60892- error = vfs_setxattr(d, kname, kvalue, size, flags);
60893+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60894+ error = -EACCES;
60895+ goto out;
60896+ }
60897+
60898+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60899 out:
60900 if (vvalue)
60901 vfree(vvalue);
60902@@ -377,7 +403,7 @@ retry:
60903 return error;
60904 error = mnt_want_write(path.mnt);
60905 if (!error) {
60906- error = setxattr(path.dentry, name, value, size, flags);
60907+ error = setxattr(&path, name, value, size, flags);
60908 mnt_drop_write(path.mnt);
60909 }
60910 path_put(&path);
60911@@ -401,7 +427,7 @@ retry:
60912 return error;
60913 error = mnt_want_write(path.mnt);
60914 if (!error) {
60915- error = setxattr(path.dentry, name, value, size, flags);
60916+ error = setxattr(&path, name, value, size, flags);
60917 mnt_drop_write(path.mnt);
60918 }
60919 path_put(&path);
60920@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60921 const void __user *,value, size_t, size, int, flags)
60922 {
60923 struct fd f = fdget(fd);
60924- struct dentry *dentry;
60925 int error = -EBADF;
60926
60927 if (!f.file)
60928 return error;
60929- dentry = f.file->f_path.dentry;
60930- audit_inode(NULL, dentry, 0);
60931+ audit_inode(NULL, f.file->f_path.dentry, 0);
60932 error = mnt_want_write_file(f.file);
60933 if (!error) {
60934- error = setxattr(dentry, name, value, size, flags);
60935+ error = setxattr(&f.file->f_path, name, value, size, flags);
60936 mnt_drop_write_file(f.file);
60937 }
60938 fdput(f);
60939diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60940index 9fbea87..6b19972 100644
60941--- a/fs/xattr_acl.c
60942+++ b/fs/xattr_acl.c
60943@@ -76,8 +76,8 @@ struct posix_acl *
60944 posix_acl_from_xattr(struct user_namespace *user_ns,
60945 const void *value, size_t size)
60946 {
60947- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60948- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60949+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60950+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60951 int count;
60952 struct posix_acl *acl;
60953 struct posix_acl_entry *acl_e;
60954diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60955index 05c698c..6b918af 100644
60956--- a/fs/xfs/xfs_bmap.c
60957+++ b/fs/xfs/xfs_bmap.c
60958@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60959
60960 #else
60961 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60962-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60963+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60964 #endif /* DEBUG */
60965
60966 /*
60967diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60968index 97676a3..399a75d 100644
60969--- a/fs/xfs/xfs_dir2_sf.c
60970+++ b/fs/xfs/xfs_dir2_sf.c
60971@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60972
60973 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60974 ctx->pos = off & 0x7fffffff;
60975- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60976+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60977+ char name[sfep->namelen];
60978+ memcpy(name, sfep->name, sfep->namelen);
60979+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60980+ return 0;
60981+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60982 ino, DT_UNKNOWN))
60983 return 0;
60984 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60985diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60986index 6e2bca5..6ce80d3 100644
60987--- a/fs/xfs/xfs_ioctl.c
60988+++ b/fs/xfs/xfs_ioctl.c
60989@@ -127,7 +127,7 @@ xfs_find_handle(
60990 }
60991
60992 error = -EFAULT;
60993- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60994+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60995 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60996 goto out_put;
60997
60998diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60999index 96dda62..d6c6a52 100644
61000--- a/fs/xfs/xfs_iops.c
61001+++ b/fs/xfs/xfs_iops.c
61002@@ -395,7 +395,7 @@ xfs_vn_put_link(
61003 struct nameidata *nd,
61004 void *p)
61005 {
61006- char *s = nd_get_link(nd);
61007+ const char *s = nd_get_link(nd);
61008
61009 if (!IS_ERR(s))
61010 kfree(s);
61011diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61012new file mode 100644
61013index 0000000..0fd7c82
61014--- /dev/null
61015+++ b/grsecurity/Kconfig
61016@@ -0,0 +1,1080 @@
61017+#
61018+# grecurity configuration
61019+#
61020+menu "Memory Protections"
61021+depends on GRKERNSEC
61022+
61023+config GRKERNSEC_KMEM
61024+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61025+ default y if GRKERNSEC_CONFIG_AUTO
61026+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61027+ help
61028+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61029+ be written to or read from to modify or leak the contents of the running
61030+ kernel. /dev/port will also not be allowed to be opened and support
61031+ for /dev/cpu/*/msr will be removed. If you have module
61032+ support disabled, enabling this will close up five ways that are
61033+ currently used to insert malicious code into the running kernel.
61034+
61035+ Even with all these features enabled, we still highly recommend that
61036+ you use the RBAC system, as it is still possible for an attacker to
61037+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61038+
61039+ If you are not using XFree86, you may be able to stop this additional
61040+ case by enabling the 'Disable privileged I/O' option. Though nothing
61041+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61042+ but only to video memory, which is the only writing we allow in this
61043+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61044+ not be allowed to mprotect it with PROT_WRITE later.
61045+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61046+ from working.
61047+
61048+ It is highly recommended that you say Y here if you meet all the
61049+ conditions above.
61050+
61051+config GRKERNSEC_VM86
61052+ bool "Restrict VM86 mode"
61053+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61054+ depends on X86_32
61055+
61056+ help
61057+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61058+ make use of a special execution mode on 32bit x86 processors called
61059+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61060+ video cards and will still work with this option enabled. The purpose
61061+ of the option is to prevent exploitation of emulation errors in
61062+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61063+ Nearly all users should be able to enable this option.
61064+
61065+config GRKERNSEC_IO
61066+ bool "Disable privileged I/O"
61067+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61068+ depends on X86
61069+ select RTC_CLASS
61070+ select RTC_INTF_DEV
61071+ select RTC_DRV_CMOS
61072+
61073+ help
61074+ If you say Y here, all ioperm and iopl calls will return an error.
61075+ Ioperm and iopl can be used to modify the running kernel.
61076+ Unfortunately, some programs need this access to operate properly,
61077+ the most notable of which are XFree86 and hwclock. hwclock can be
61078+ remedied by having RTC support in the kernel, so real-time
61079+ clock support is enabled if this option is enabled, to ensure
61080+ that hwclock operates correctly. XFree86 still will not
61081+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61082+ IF YOU USE XFree86. If you use XFree86 and you still want to
61083+ protect your kernel against modification, use the RBAC system.
61084+
61085+config GRKERNSEC_JIT_HARDEN
61086+ bool "Harden BPF JIT against spray attacks"
61087+ default y if GRKERNSEC_CONFIG_AUTO
61088+ depends on BPF_JIT
61089+ help
61090+ If you say Y here, the native code generated by the kernel's Berkeley
61091+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61092+ attacks that attempt to fit attacker-beneficial instructions in
61093+ 32bit immediate fields of JIT-generated native instructions. The
61094+ attacker will generally aim to cause an unintended instruction sequence
61095+ of JIT-generated native code to execute by jumping into the middle of
61096+ a generated instruction. This feature effectively randomizes the 32bit
61097+ immediate constants present in the generated code to thwart such attacks.
61098+
61099+ If you're using KERNEXEC, it's recommended that you enable this option
61100+ to supplement the hardening of the kernel.
61101+
61102+config GRKERNSEC_PERF_HARDEN
61103+ bool "Disable unprivileged PERF_EVENTS usage by default"
61104+ default y if GRKERNSEC_CONFIG_AUTO
61105+ depends on PERF_EVENTS
61106+ help
61107+ If you say Y here, the range of acceptable values for the
61108+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61109+ default to a new value: 3. When the sysctl is set to this value, no
61110+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61111+
61112+ Though PERF_EVENTS can be used legitimately for performance monitoring
61113+ and low-level application profiling, it is forced on regardless of
61114+ configuration, has been at fault for several vulnerabilities, and
61115+ creates new opportunities for side channels and other information leaks.
61116+
61117+ This feature puts PERF_EVENTS into a secure default state and permits
61118+ the administrator to change out of it temporarily if unprivileged
61119+ application profiling is needed.
61120+
61121+config GRKERNSEC_RAND_THREADSTACK
61122+ bool "Insert random gaps between thread stacks"
61123+ default y if GRKERNSEC_CONFIG_AUTO
61124+ depends on PAX_RANDMMAP && !PPC
61125+ help
61126+ If you say Y here, a random-sized gap will be enforced between allocated
61127+ thread stacks. Glibc's NPTL and other threading libraries that
61128+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61129+ The implementation currently provides 8 bits of entropy for the gap.
61130+
61131+ Many distributions do not compile threaded remote services with the
61132+ -fstack-check argument to GCC, causing the variable-sized stack-based
61133+ allocator, alloca(), to not probe the stack on allocation. This
61134+ permits an unbounded alloca() to skip over any guard page and potentially
61135+ modify another thread's stack reliably. An enforced random gap
61136+ reduces the reliability of such an attack and increases the chance
61137+ that such a read/write to another thread's stack instead lands in
61138+ an unmapped area, causing a crash and triggering grsecurity's
61139+ anti-bruteforcing logic.
61140+
61141+config GRKERNSEC_PROC_MEMMAP
61142+ bool "Harden ASLR against information leaks and entropy reduction"
61143+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61144+ depends on PAX_NOEXEC || PAX_ASLR
61145+ help
61146+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61147+ give no information about the addresses of its mappings if
61148+ PaX features that rely on random addresses are enabled on the task.
61149+ In addition to sanitizing this information and disabling other
61150+ dangerous sources of information, this option causes reads of sensitive
61151+ /proc/<pid> entries where the file descriptor was opened in a different
61152+ task than the one performing the read. Such attempts are logged.
61153+ This option also limits argv/env strings for suid/sgid binaries
61154+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61155+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61156+ binaries to prevent alternative mmap layouts from being abused.
61157+
61158+ If you use PaX it is essential that you say Y here as it closes up
61159+ several holes that make full ASLR useless locally.
61160+
61161+config GRKERNSEC_BRUTE
61162+ bool "Deter exploit bruteforcing"
61163+ default y if GRKERNSEC_CONFIG_AUTO
61164+ help
61165+ If you say Y here, attempts to bruteforce exploits against forking
61166+ daemons such as apache or sshd, as well as against suid/sgid binaries
61167+ will be deterred. When a child of a forking daemon is killed by PaX
61168+ or crashes due to an illegal instruction or other suspicious signal,
61169+ the parent process will be delayed 30 seconds upon every subsequent
61170+ fork until the administrator is able to assess the situation and
61171+ restart the daemon.
61172+ In the suid/sgid case, the attempt is logged, the user has all their
61173+ existing instances of the suid/sgid binary terminated and will
61174+ be unable to execute any suid/sgid binaries for 15 minutes.
61175+
61176+ It is recommended that you also enable signal logging in the auditing
61177+ section so that logs are generated when a process triggers a suspicious
61178+ signal.
61179+ If the sysctl option is enabled, a sysctl option with name
61180+ "deter_bruteforce" is created.
61181+
61182+
61183+config GRKERNSEC_MODHARDEN
61184+ bool "Harden module auto-loading"
61185+ default y if GRKERNSEC_CONFIG_AUTO
61186+ depends on MODULES
61187+ help
61188+ If you say Y here, module auto-loading in response to use of some
61189+ feature implemented by an unloaded module will be restricted to
61190+ root users. Enabling this option helps defend against attacks
61191+ by unprivileged users who abuse the auto-loading behavior to
61192+ cause a vulnerable module to load that is then exploited.
61193+
61194+ If this option prevents a legitimate use of auto-loading for a
61195+ non-root user, the administrator can execute modprobe manually
61196+ with the exact name of the module mentioned in the alert log.
61197+ Alternatively, the administrator can add the module to the list
61198+ of modules loaded at boot by modifying init scripts.
61199+
61200+ Modification of init scripts will most likely be needed on
61201+ Ubuntu servers with encrypted home directory support enabled,
61202+ as the first non-root user logging in will cause the ecb(aes),
61203+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61204+
61205+config GRKERNSEC_HIDESYM
61206+ bool "Hide kernel symbols"
61207+ default y if GRKERNSEC_CONFIG_AUTO
61208+ select PAX_USERCOPY_SLABS
61209+ help
61210+ If you say Y here, getting information on loaded modules, and
61211+ displaying all kernel symbols through a syscall will be restricted
61212+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61213+ /proc/kallsyms will be restricted to the root user. The RBAC
61214+ system can hide that entry even from root.
61215+
61216+ This option also prevents leaking of kernel addresses through
61217+ several /proc entries.
61218+
61219+ Note that this option is only effective provided the following
61220+ conditions are met:
61221+ 1) The kernel using grsecurity is not precompiled by some distribution
61222+ 2) You have also enabled GRKERNSEC_DMESG
61223+ 3) You are using the RBAC system and hiding other files such as your
61224+ kernel image and System.map. Alternatively, enabling this option
61225+ causes the permissions on /boot, /lib/modules, and the kernel
61226+ source directory to change at compile time to prevent
61227+ reading by non-root users.
61228+ If the above conditions are met, this option will aid in providing a
61229+ useful protection against local kernel exploitation of overflows
61230+ and arbitrary read/write vulnerabilities.
61231+
61232+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61233+ in addition to this feature.
61234+
61235+config GRKERNSEC_KERN_LOCKOUT
61236+ bool "Active kernel exploit response"
61237+ default y if GRKERNSEC_CONFIG_AUTO
61238+ depends on X86 || ARM || PPC || SPARC
61239+ help
61240+ If you say Y here, when a PaX alert is triggered due to suspicious
61241+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61242+ or an OOPS occurs due to bad memory accesses, instead of just
61243+ terminating the offending process (and potentially allowing
61244+ a subsequent exploit from the same user), we will take one of two
61245+ actions:
61246+ If the user was root, we will panic the system
61247+ If the user was non-root, we will log the attempt, terminate
61248+ all processes owned by the user, then prevent them from creating
61249+ any new processes until the system is restarted
61250+ This deters repeated kernel exploitation/bruteforcing attempts
61251+ and is useful for later forensics.
61252+
61253+endmenu
61254+menu "Role Based Access Control Options"
61255+depends on GRKERNSEC
61256+
61257+config GRKERNSEC_RBAC_DEBUG
61258+ bool
61259+
61260+config GRKERNSEC_NO_RBAC
61261+ bool "Disable RBAC system"
61262+ help
61263+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61264+ preventing the RBAC system from being enabled. You should only say Y
61265+ here if you have no intention of using the RBAC system, so as to prevent
61266+ an attacker with root access from misusing the RBAC system to hide files
61267+ and processes when loadable module support and /dev/[k]mem have been
61268+ locked down.
61269+
61270+config GRKERNSEC_ACL_HIDEKERN
61271+ bool "Hide kernel processes"
61272+ help
61273+ If you say Y here, all kernel threads will be hidden to all
61274+ processes but those whose subject has the "view hidden processes"
61275+ flag.
61276+
61277+config GRKERNSEC_ACL_MAXTRIES
61278+ int "Maximum tries before password lockout"
61279+ default 3
61280+ help
61281+ This option enforces the maximum number of times a user can attempt
61282+ to authorize themselves with the grsecurity RBAC system before being
61283+ denied the ability to attempt authorization again for a specified time.
61284+ The lower the number, the harder it will be to brute-force a password.
61285+
61286+config GRKERNSEC_ACL_TIMEOUT
61287+ int "Time to wait after max password tries, in seconds"
61288+ default 30
61289+ help
61290+ This option specifies the time the user must wait after attempting to
61291+ authorize to the RBAC system with the maximum number of invalid
61292+ passwords. The higher the number, the harder it will be to brute-force
61293+ a password.
61294+
61295+endmenu
61296+menu "Filesystem Protections"
61297+depends on GRKERNSEC
61298+
61299+config GRKERNSEC_PROC
61300+ bool "Proc restrictions"
61301+ default y if GRKERNSEC_CONFIG_AUTO
61302+ help
61303+ If you say Y here, the permissions of the /proc filesystem
61304+ will be altered to enhance system security and privacy. You MUST
61305+ choose either a user only restriction or a user and group restriction.
61306+ Depending upon the option you choose, you can either restrict users to
61307+ see only the processes they themselves run, or choose a group that can
61308+ view all processes and files normally restricted to root if you choose
61309+ the "restrict to user only" option. NOTE: If you're running identd or
61310+ ntpd as a non-root user, you will have to run it as the group you
61311+ specify here.
61312+
61313+config GRKERNSEC_PROC_USER
61314+ bool "Restrict /proc to user only"
61315+ depends on GRKERNSEC_PROC
61316+ help
61317+ If you say Y here, non-root users will only be able to view their own
61318+ processes, and restricts them from viewing network-related information,
61319+ and viewing kernel symbol and module information.
61320+
61321+config GRKERNSEC_PROC_USERGROUP
61322+ bool "Allow special group"
61323+ default y if GRKERNSEC_CONFIG_AUTO
61324+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61325+ help
61326+ If you say Y here, you will be able to select a group that will be
61327+ able to view all processes and network-related information. If you've
61328+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61329+ remain hidden. This option is useful if you want to run identd as
61330+ a non-root user. The group you select may also be chosen at boot time
61331+ via "grsec_proc_gid=" on the kernel commandline.
61332+
61333+config GRKERNSEC_PROC_GID
61334+ int "GID for special group"
61335+ depends on GRKERNSEC_PROC_USERGROUP
61336+ default 1001
61337+
61338+config GRKERNSEC_PROC_ADD
61339+ bool "Additional restrictions"
61340+ default y if GRKERNSEC_CONFIG_AUTO
61341+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61342+ help
61343+ If you say Y here, additional restrictions will be placed on
61344+ /proc that keep normal users from viewing device information and
61345+ slabinfo information that could be useful for exploits.
61346+
61347+config GRKERNSEC_LINK
61348+ bool "Linking restrictions"
61349+ default y if GRKERNSEC_CONFIG_AUTO
61350+ help
61351+ If you say Y here, /tmp race exploits will be prevented, since users
61352+ will no longer be able to follow symlinks owned by other users in
61353+ world-writable +t directories (e.g. /tmp), unless the owner of the
61354+ symlink is the owner of the directory. users will also not be
61355+ able to hardlink to files they do not own. If the sysctl option is
61356+ enabled, a sysctl option with name "linking_restrictions" is created.
61357+
61358+config GRKERNSEC_SYMLINKOWN
61359+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61360+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61361+ help
61362+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61363+ that prevents it from being used as a security feature. As Apache
61364+ verifies the symlink by performing a stat() against the target of
61365+ the symlink before it is followed, an attacker can setup a symlink
61366+ to point to a same-owned file, then replace the symlink with one
61367+ that targets another user's file just after Apache "validates" the
61368+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61369+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61370+ will be in place for the group you specify. If the sysctl option
61371+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61372+ created.
61373+
61374+config GRKERNSEC_SYMLINKOWN_GID
61375+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61376+ depends on GRKERNSEC_SYMLINKOWN
61377+ default 1006
61378+ help
61379+ Setting this GID determines what group kernel-enforced
61380+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61381+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61382+
61383+config GRKERNSEC_FIFO
61384+ bool "FIFO restrictions"
61385+ default y if GRKERNSEC_CONFIG_AUTO
61386+ help
61387+ If you say Y here, users will not be able to write to FIFOs they don't
61388+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61389+ the FIFO is the same owner of the directory it's held in. If the sysctl
61390+ option is enabled, a sysctl option with name "fifo_restrictions" is
61391+ created.
61392+
61393+config GRKERNSEC_SYSFS_RESTRICT
61394+ bool "Sysfs/debugfs restriction"
61395+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61396+ depends on SYSFS
61397+ help
61398+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61399+ any filesystem normally mounted under it (e.g. debugfs) will be
61400+ mostly accessible only by root. These filesystems generally provide access
61401+ to hardware and debug information that isn't appropriate for unprivileged
61402+ users of the system. Sysfs and debugfs have also become a large source
61403+ of new vulnerabilities, ranging from infoleaks to local compromise.
61404+ There has been very little oversight with an eye toward security involved
61405+ in adding new exporters of information to these filesystems, so their
61406+ use is discouraged.
61407+ For reasons of compatibility, a few directories have been whitelisted
61408+ for access by non-root users:
61409+ /sys/fs/selinux
61410+ /sys/fs/fuse
61411+ /sys/devices/system/cpu
61412+
61413+config GRKERNSEC_ROFS
61414+ bool "Runtime read-only mount protection"
61415+ depends on SYSCTL
61416+ help
61417+ If you say Y here, a sysctl option with name "romount_protect" will
61418+ be created. By setting this option to 1 at runtime, filesystems
61419+ will be protected in the following ways:
61420+ * No new writable mounts will be allowed
61421+ * Existing read-only mounts won't be able to be remounted read/write
61422+ * Write operations will be denied on all block devices
61423+ This option acts independently of grsec_lock: once it is set to 1,
61424+ it cannot be turned off. Therefore, please be mindful of the resulting
61425+ behavior if this option is enabled in an init script on a read-only
61426+ filesystem. This feature is mainly intended for secure embedded systems.
61427+
61428+config GRKERNSEC_DEVICE_SIDECHANNEL
61429+ bool "Eliminate stat/notify-based device sidechannels"
61430+ default y if GRKERNSEC_CONFIG_AUTO
61431+ help
61432+ If you say Y here, timing analyses on block or character
61433+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61434+ will be thwarted for unprivileged users. If a process without
61435+ CAP_MKNOD stats such a device, the last access and last modify times
61436+ will match the device's create time. No access or modify events
61437+ will be triggered through inotify/dnotify/fanotify for such devices.
61438+ This feature will prevent attacks that may at a minimum
61439+ allow an attacker to determine the administrator's password length.
61440+
61441+config GRKERNSEC_CHROOT
61442+ bool "Chroot jail restrictions"
61443+ default y if GRKERNSEC_CONFIG_AUTO
61444+ help
61445+ If you say Y here, you will be able to choose several options that will
61446+ make breaking out of a chrooted jail much more difficult. If you
61447+ encounter no software incompatibilities with the following options, it
61448+ is recommended that you enable each one.
61449+
61450+config GRKERNSEC_CHROOT_MOUNT
61451+ bool "Deny mounts"
61452+ default y if GRKERNSEC_CONFIG_AUTO
61453+ depends on GRKERNSEC_CHROOT
61454+ help
61455+ If you say Y here, processes inside a chroot will not be able to
61456+ mount or remount filesystems. If the sysctl option is enabled, a
61457+ sysctl option with name "chroot_deny_mount" is created.
61458+
61459+config GRKERNSEC_CHROOT_DOUBLE
61460+ bool "Deny double-chroots"
61461+ default y if GRKERNSEC_CONFIG_AUTO
61462+ depends on GRKERNSEC_CHROOT
61463+ help
61464+ If you say Y here, processes inside a chroot will not be able to chroot
61465+ again outside the chroot. This is a widely used method of breaking
61466+ out of a chroot jail and should not be allowed. If the sysctl
61467+ option is enabled, a sysctl option with name
61468+ "chroot_deny_chroot" is created.
61469+
61470+config GRKERNSEC_CHROOT_PIVOT
61471+ bool "Deny pivot_root in chroot"
61472+ default y if GRKERNSEC_CONFIG_AUTO
61473+ depends on GRKERNSEC_CHROOT
61474+ help
61475+ If you say Y here, processes inside a chroot will not be able to use
61476+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61477+ works similar to chroot in that it changes the root filesystem. This
61478+ function could be misused in a chrooted process to attempt to break out
61479+ of the chroot, and therefore should not be allowed. If the sysctl
61480+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61481+ created.
61482+
61483+config GRKERNSEC_CHROOT_CHDIR
61484+ bool "Enforce chdir(\"/\") on all chroots"
61485+ default y if GRKERNSEC_CONFIG_AUTO
61486+ depends on GRKERNSEC_CHROOT
61487+ help
61488+ If you say Y here, the current working directory of all newly-chrooted
61489+ applications will be set to the the root directory of the chroot.
61490+ The man page on chroot(2) states:
61491+ Note that this call does not change the current working
61492+ directory, so that `.' can be outside the tree rooted at
61493+ `/'. In particular, the super-user can escape from a
61494+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61495+
61496+ It is recommended that you say Y here, since it's not known to break
61497+ any software. If the sysctl option is enabled, a sysctl option with
61498+ name "chroot_enforce_chdir" is created.
61499+
61500+config GRKERNSEC_CHROOT_CHMOD
61501+ bool "Deny (f)chmod +s"
61502+ default y if GRKERNSEC_CONFIG_AUTO
61503+ depends on GRKERNSEC_CHROOT
61504+ help
61505+ If you say Y here, processes inside a chroot will not be able to chmod
61506+ or fchmod files to make them have suid or sgid bits. This protects
61507+ against another published method of breaking a chroot. If the sysctl
61508+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61509+ created.
61510+
61511+config GRKERNSEC_CHROOT_FCHDIR
61512+ bool "Deny fchdir out of chroot"
61513+ default y if GRKERNSEC_CONFIG_AUTO
61514+ depends on GRKERNSEC_CHROOT
61515+ help
61516+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61517+ to a file descriptor of the chrooting process that points to a directory
61518+ outside the filesystem will be stopped. If the sysctl option
61519+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61520+
61521+config GRKERNSEC_CHROOT_MKNOD
61522+ bool "Deny mknod"
61523+ default y if GRKERNSEC_CONFIG_AUTO
61524+ depends on GRKERNSEC_CHROOT
61525+ help
61526+ If you say Y here, processes inside a chroot will not be allowed to
61527+ mknod. The problem with using mknod inside a chroot is that it
61528+ would allow an attacker to create a device entry that is the same
61529+ as one on the physical root of your system, which could range from
61530+ anything from the console device to a device for your harddrive (which
61531+ they could then use to wipe the drive or steal data). It is recommended
61532+ that you say Y here, unless you run into software incompatibilities.
61533+ If the sysctl option is enabled, a sysctl option with name
61534+ "chroot_deny_mknod" is created.
61535+
61536+config GRKERNSEC_CHROOT_SHMAT
61537+ bool "Deny shmat() out of chroot"
61538+ default y if GRKERNSEC_CONFIG_AUTO
61539+ depends on GRKERNSEC_CHROOT
61540+ help
61541+ If you say Y here, processes inside a chroot will not be able to attach
61542+ to shared memory segments that were created outside of the chroot jail.
61543+ It is recommended that you say Y here. If the sysctl option is enabled,
61544+ a sysctl option with name "chroot_deny_shmat" is created.
61545+
61546+config GRKERNSEC_CHROOT_UNIX
61547+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61548+ default y if GRKERNSEC_CONFIG_AUTO
61549+ depends on GRKERNSEC_CHROOT
61550+ help
61551+ If you say Y here, processes inside a chroot will not be able to
61552+ connect to abstract (meaning not belonging to a filesystem) Unix
61553+ domain sockets that were bound outside of a chroot. It is recommended
61554+ that you say Y here. If the sysctl option is enabled, a sysctl option
61555+ with name "chroot_deny_unix" is created.
61556+
61557+config GRKERNSEC_CHROOT_FINDTASK
61558+ bool "Protect outside processes"
61559+ default y if GRKERNSEC_CONFIG_AUTO
61560+ depends on GRKERNSEC_CHROOT
61561+ help
61562+ If you say Y here, processes inside a chroot will not be able to
61563+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61564+ getsid, or view any process outside of the chroot. If the sysctl
61565+ option is enabled, a sysctl option with name "chroot_findtask" is
61566+ created.
61567+
61568+config GRKERNSEC_CHROOT_NICE
61569+ bool "Restrict priority changes"
61570+ default y if GRKERNSEC_CONFIG_AUTO
61571+ depends on GRKERNSEC_CHROOT
61572+ help
61573+ If you say Y here, processes inside a chroot will not be able to raise
61574+ the priority of processes in the chroot, or alter the priority of
61575+ processes outside the chroot. This provides more security than simply
61576+ removing CAP_SYS_NICE from the process' capability set. If the
61577+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61578+ is created.
61579+
61580+config GRKERNSEC_CHROOT_SYSCTL
61581+ bool "Deny sysctl writes"
61582+ default y if GRKERNSEC_CONFIG_AUTO
61583+ depends on GRKERNSEC_CHROOT
61584+ help
61585+ If you say Y here, an attacker in a chroot will not be able to
61586+ write to sysctl entries, either by sysctl(2) or through a /proc
61587+ interface. It is strongly recommended that you say Y here. If the
61588+ sysctl option is enabled, a sysctl option with name
61589+ "chroot_deny_sysctl" is created.
61590+
61591+config GRKERNSEC_CHROOT_CAPS
61592+ bool "Capability restrictions"
61593+ default y if GRKERNSEC_CONFIG_AUTO
61594+ depends on GRKERNSEC_CHROOT
61595+ help
61596+ If you say Y here, the capabilities on all processes within a
61597+ chroot jail will be lowered to stop module insertion, raw i/o,
61598+ system and net admin tasks, rebooting the system, modifying immutable
61599+ files, modifying IPC owned by another, and changing the system time.
61600+ This is left an option because it can break some apps. Disable this
61601+ if your chrooted apps are having problems performing those kinds of
61602+ tasks. If the sysctl option is enabled, a sysctl option with
61603+ name "chroot_caps" is created.
61604+
61605+config GRKERNSEC_CHROOT_INITRD
61606+ bool "Exempt initrd tasks from restrictions"
61607+ default y if GRKERNSEC_CONFIG_AUTO
61608+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61609+ help
61610+ If you say Y here, tasks started prior to init will be exempted from
61611+ grsecurity's chroot restrictions. This option is mainly meant to
61612+ resolve Plymouth's performing privileged operations unnecessarily
61613+ in a chroot.
61614+
61615+endmenu
61616+menu "Kernel Auditing"
61617+depends on GRKERNSEC
61618+
61619+config GRKERNSEC_AUDIT_GROUP
61620+ bool "Single group for auditing"
61621+ help
61622+ If you say Y here, the exec and chdir logging features will only operate
61623+ on a group you specify. This option is recommended if you only want to
61624+ watch certain users instead of having a large amount of logs from the
61625+ entire system. If the sysctl option is enabled, a sysctl option with
61626+ name "audit_group" is created.
61627+
61628+config GRKERNSEC_AUDIT_GID
61629+ int "GID for auditing"
61630+ depends on GRKERNSEC_AUDIT_GROUP
61631+ default 1007
61632+
61633+config GRKERNSEC_EXECLOG
61634+ bool "Exec logging"
61635+ help
61636+ If you say Y here, all execve() calls will be logged (since the
61637+ other exec*() calls are frontends to execve(), all execution
61638+ will be logged). Useful for shell-servers that like to keep track
61639+ of their users. If the sysctl option is enabled, a sysctl option with
61640+ name "exec_logging" is created.
61641+ WARNING: This option when enabled will produce a LOT of logs, especially
61642+ on an active system.
61643+
61644+config GRKERNSEC_RESLOG
61645+ bool "Resource logging"
61646+ default y if GRKERNSEC_CONFIG_AUTO
61647+ help
61648+ If you say Y here, all attempts to overstep resource limits will
61649+ be logged with the resource name, the requested size, and the current
61650+ limit. It is highly recommended that you say Y here. If the sysctl
61651+ option is enabled, a sysctl option with name "resource_logging" is
61652+ created. If the RBAC system is enabled, the sysctl value is ignored.
61653+
61654+config GRKERNSEC_CHROOT_EXECLOG
61655+ bool "Log execs within chroot"
61656+ help
61657+ If you say Y here, all executions inside a chroot jail will be logged
61658+ to syslog. This can cause a large amount of logs if certain
61659+ applications (eg. djb's daemontools) are installed on the system, and
61660+ is therefore left as an option. If the sysctl option is enabled, a
61661+ sysctl option with name "chroot_execlog" is created.
61662+
61663+config GRKERNSEC_AUDIT_PTRACE
61664+ bool "Ptrace logging"
61665+ help
61666+ If you say Y here, all attempts to attach to a process via ptrace
61667+ will be logged. If the sysctl option is enabled, a sysctl option
61668+ with name "audit_ptrace" is created.
61669+
61670+config GRKERNSEC_AUDIT_CHDIR
61671+ bool "Chdir logging"
61672+ help
61673+ If you say Y here, all chdir() calls will be logged. If the sysctl
61674+ option is enabled, a sysctl option with name "audit_chdir" is created.
61675+
61676+config GRKERNSEC_AUDIT_MOUNT
61677+ bool "(Un)Mount logging"
61678+ help
61679+ If you say Y here, all mounts and unmounts will be logged. If the
61680+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61681+ created.
61682+
61683+config GRKERNSEC_SIGNAL
61684+ bool "Signal logging"
61685+ default y if GRKERNSEC_CONFIG_AUTO
61686+ help
61687+ If you say Y here, certain important signals will be logged, such as
61688+ SIGSEGV, which will as a result inform you of when a error in a program
61689+ occurred, which in some cases could mean a possible exploit attempt.
61690+ If the sysctl option is enabled, a sysctl option with name
61691+ "signal_logging" is created.
61692+
61693+config GRKERNSEC_FORKFAIL
61694+ bool "Fork failure logging"
61695+ help
61696+ If you say Y here, all failed fork() attempts will be logged.
61697+ This could suggest a fork bomb, or someone attempting to overstep
61698+ their process limit. If the sysctl option is enabled, a sysctl option
61699+ with name "forkfail_logging" is created.
61700+
61701+config GRKERNSEC_TIME
61702+ bool "Time change logging"
61703+ default y if GRKERNSEC_CONFIG_AUTO
61704+ help
61705+ If you say Y here, any changes of the system clock will be logged.
61706+ If the sysctl option is enabled, a sysctl option with name
61707+ "timechange_logging" is created.
61708+
61709+config GRKERNSEC_PROC_IPADDR
61710+ bool "/proc/<pid>/ipaddr support"
61711+ default y if GRKERNSEC_CONFIG_AUTO
61712+ help
61713+ If you say Y here, a new entry will be added to each /proc/<pid>
61714+ directory that contains the IP address of the person using the task.
61715+ The IP is carried across local TCP and AF_UNIX stream sockets.
61716+ This information can be useful for IDS/IPSes to perform remote response
61717+ to a local attack. The entry is readable by only the owner of the
61718+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61719+ the RBAC system), and thus does not create privacy concerns.
61720+
61721+config GRKERNSEC_RWXMAP_LOG
61722+ bool 'Denied RWX mmap/mprotect logging'
61723+ default y if GRKERNSEC_CONFIG_AUTO
61724+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61725+ help
61726+ If you say Y here, calls to mmap() and mprotect() with explicit
61727+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61728+ denied by the PAX_MPROTECT feature. This feature will also
61729+ log other problematic scenarios that can occur when PAX_MPROTECT
61730+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61731+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61732+ is created.
61733+
61734+endmenu
61735+
61736+menu "Executable Protections"
61737+depends on GRKERNSEC
61738+
61739+config GRKERNSEC_DMESG
61740+ bool "Dmesg(8) restriction"
61741+ default y if GRKERNSEC_CONFIG_AUTO
61742+ help
61743+ If you say Y here, non-root users will not be able to use dmesg(8)
61744+ to view the contents of the kernel's circular log buffer.
61745+ The kernel's log buffer often contains kernel addresses and other
61746+ identifying information useful to an attacker in fingerprinting a
61747+ system for a targeted exploit.
61748+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61749+ created.
61750+
61751+config GRKERNSEC_HARDEN_PTRACE
61752+ bool "Deter ptrace-based process snooping"
61753+ default y if GRKERNSEC_CONFIG_AUTO
61754+ help
61755+ If you say Y here, TTY sniffers and other malicious monitoring
61756+ programs implemented through ptrace will be defeated. If you
61757+ have been using the RBAC system, this option has already been
61758+ enabled for several years for all users, with the ability to make
61759+ fine-grained exceptions.
61760+
61761+ This option only affects the ability of non-root users to ptrace
61762+ processes that are not a descendent of the ptracing process.
61763+ This means that strace ./binary and gdb ./binary will still work,
61764+ but attaching to arbitrary processes will not. If the sysctl
61765+ option is enabled, a sysctl option with name "harden_ptrace" is
61766+ created.
61767+
61768+config GRKERNSEC_PTRACE_READEXEC
61769+ bool "Require read access to ptrace sensitive binaries"
61770+ default y if GRKERNSEC_CONFIG_AUTO
61771+ help
61772+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61773+ binaries. This option is useful in environments that
61774+ remove the read bits (e.g. file mode 4711) from suid binaries to
61775+ prevent infoleaking of their contents. This option adds
61776+ consistency to the use of that file mode, as the binary could normally
61777+ be read out when run without privileges while ptracing.
61778+
61779+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61780+ is created.
61781+
61782+config GRKERNSEC_SETXID
61783+ bool "Enforce consistent multithreaded privileges"
61784+ default y if GRKERNSEC_CONFIG_AUTO
61785+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61786+ help
61787+ If you say Y here, a change from a root uid to a non-root uid
61788+ in a multithreaded application will cause the resulting uids,
61789+ gids, supplementary groups, and capabilities in that thread
61790+ to be propagated to the other threads of the process. In most
61791+ cases this is unnecessary, as glibc will emulate this behavior
61792+ on behalf of the application. Other libcs do not act in the
61793+ same way, allowing the other threads of the process to continue
61794+ running with root privileges. If the sysctl option is enabled,
61795+ a sysctl option with name "consistent_setxid" is created.
61796+
61797+config GRKERNSEC_TPE
61798+ bool "Trusted Path Execution (TPE)"
61799+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61800+ help
61801+ If you say Y here, you will be able to choose a gid to add to the
61802+ supplementary groups of users you want to mark as "untrusted."
61803+ These users will not be able to execute any files that are not in
61804+ root-owned directories writable only by root. If the sysctl option
61805+ is enabled, a sysctl option with name "tpe" is created.
61806+
61807+config GRKERNSEC_TPE_ALL
61808+ bool "Partially restrict all non-root users"
61809+ depends on GRKERNSEC_TPE
61810+ help
61811+ If you say Y here, all non-root users will be covered under
61812+ a weaker TPE restriction. This is separate from, and in addition to,
61813+ the main TPE options that you have selected elsewhere. Thus, if a
61814+ "trusted" GID is chosen, this restriction applies to even that GID.
61815+ Under this restriction, all non-root users will only be allowed to
61816+ execute files in directories they own that are not group or
61817+ world-writable, or in directories owned by root and writable only by
61818+ root. If the sysctl option is enabled, a sysctl option with name
61819+ "tpe_restrict_all" is created.
61820+
61821+config GRKERNSEC_TPE_INVERT
61822+ bool "Invert GID option"
61823+ depends on GRKERNSEC_TPE
61824+ help
61825+ If you say Y here, the group you specify in the TPE configuration will
61826+ decide what group TPE restrictions will be *disabled* for. This
61827+ option is useful if you want TPE restrictions to be applied to most
61828+ users on the system. If the sysctl option is enabled, a sysctl option
61829+ with name "tpe_invert" is created. Unlike other sysctl options, this
61830+ entry will default to on for backward-compatibility.
61831+
61832+config GRKERNSEC_TPE_GID
61833+ int
61834+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61835+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61836+
61837+config GRKERNSEC_TPE_UNTRUSTED_GID
61838+ int "GID for TPE-untrusted users"
61839+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61840+ default 1005
61841+ help
61842+ Setting this GID determines what group TPE restrictions will be
61843+ *enabled* for. If the sysctl option is enabled, a sysctl option
61844+ with name "tpe_gid" is created.
61845+
61846+config GRKERNSEC_TPE_TRUSTED_GID
61847+ int "GID for TPE-trusted users"
61848+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61849+ default 1005
61850+ help
61851+ Setting this GID determines what group TPE restrictions will be
61852+ *disabled* for. If the sysctl option is enabled, a sysctl option
61853+ with name "tpe_gid" is created.
61854+
61855+endmenu
61856+menu "Network Protections"
61857+depends on GRKERNSEC
61858+
61859+config GRKERNSEC_RANDNET
61860+ bool "Larger entropy pools"
61861+ default y if GRKERNSEC_CONFIG_AUTO
61862+ help
61863+ If you say Y here, the entropy pools used for many features of Linux
61864+ and grsecurity will be doubled in size. Since several grsecurity
61865+ features use additional randomness, it is recommended that you say Y
61866+ here. Saying Y here has a similar effect as modifying
61867+ /proc/sys/kernel/random/poolsize.
61868+
61869+config GRKERNSEC_BLACKHOLE
61870+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61871+ default y if GRKERNSEC_CONFIG_AUTO
61872+ depends on NET
61873+ help
61874+ If you say Y here, neither TCP resets nor ICMP
61875+ destination-unreachable packets will be sent in response to packets
61876+ sent to ports for which no associated listening process exists.
61877+ This feature supports both IPV4 and IPV6 and exempts the
61878+ loopback interface from blackholing. Enabling this feature
61879+ makes a host more resilient to DoS attacks and reduces network
61880+ visibility against scanners.
61881+
61882+ The blackhole feature as-implemented is equivalent to the FreeBSD
61883+ blackhole feature, as it prevents RST responses to all packets, not
61884+ just SYNs. Under most application behavior this causes no
61885+ problems, but applications (like haproxy) may not close certain
61886+ connections in a way that cleanly terminates them on the remote
61887+ end, leaving the remote host in LAST_ACK state. Because of this
61888+ side-effect and to prevent intentional LAST_ACK DoSes, this
61889+ feature also adds automatic mitigation against such attacks.
61890+ The mitigation drastically reduces the amount of time a socket
61891+ can spend in LAST_ACK state. If you're using haproxy and not
61892+ all servers it connects to have this option enabled, consider
61893+ disabling this feature on the haproxy host.
61894+
61895+ If the sysctl option is enabled, two sysctl options with names
61896+ "ip_blackhole" and "lastack_retries" will be created.
61897+ While "ip_blackhole" takes the standard zero/non-zero on/off
61898+ toggle, "lastack_retries" uses the same kinds of values as
61899+ "tcp_retries1" and "tcp_retries2". The default value of 4
61900+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61901+ state.
61902+
61903+config GRKERNSEC_NO_SIMULT_CONNECT
61904+ bool "Disable TCP Simultaneous Connect"
61905+ default y if GRKERNSEC_CONFIG_AUTO
61906+ depends on NET
61907+ help
61908+ If you say Y here, a feature by Willy Tarreau will be enabled that
61909+ removes a weakness in Linux's strict implementation of TCP that
61910+ allows two clients to connect to each other without either entering
61911+ a listening state. The weakness allows an attacker to easily prevent
61912+ a client from connecting to a known server provided the source port
61913+ for the connection is guessed correctly.
61914+
61915+ As the weakness could be used to prevent an antivirus or IPS from
61916+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61917+ it should be eliminated by enabling this option. Though Linux is
61918+ one of few operating systems supporting simultaneous connect, it
61919+ has no legitimate use in practice and is rarely supported by firewalls.
61920+
61921+config GRKERNSEC_SOCKET
61922+ bool "Socket restrictions"
61923+ depends on NET
61924+ help
61925+ If you say Y here, you will be able to choose from several options.
61926+ If you assign a GID on your system and add it to the supplementary
61927+ groups of users you want to restrict socket access to, this patch
61928+ will perform up to three things, based on the option(s) you choose.
61929+
61930+config GRKERNSEC_SOCKET_ALL
61931+ bool "Deny any sockets to group"
61932+ depends on GRKERNSEC_SOCKET
61933+ help
61934+ If you say Y here, you will be able to choose a GID of whose users will
61935+ be unable to connect to other hosts from your machine or run server
61936+ applications from your machine. If the sysctl option is enabled, a
61937+ sysctl option with name "socket_all" is created.
61938+
61939+config GRKERNSEC_SOCKET_ALL_GID
61940+ int "GID to deny all sockets for"
61941+ depends on GRKERNSEC_SOCKET_ALL
61942+ default 1004
61943+ help
61944+ Here you can choose the GID to disable socket access for. Remember to
61945+ add the users you want socket access disabled for to the GID
61946+ specified here. If the sysctl option is enabled, a sysctl option
61947+ with name "socket_all_gid" is created.
61948+
61949+config GRKERNSEC_SOCKET_CLIENT
61950+ bool "Deny client sockets to group"
61951+ depends on GRKERNSEC_SOCKET
61952+ help
61953+ If you say Y here, you will be able to choose a GID of whose users will
61954+ be unable to connect to other hosts from your machine, but will be
61955+ able to run servers. If this option is enabled, all users in the group
61956+ you specify will have to use passive mode when initiating ftp transfers
61957+ from the shell on your machine. If the sysctl option is enabled, a
61958+ sysctl option with name "socket_client" is created.
61959+
61960+config GRKERNSEC_SOCKET_CLIENT_GID
61961+ int "GID to deny client sockets for"
61962+ depends on GRKERNSEC_SOCKET_CLIENT
61963+ default 1003
61964+ help
61965+ Here you can choose the GID to disable client socket access for.
61966+ Remember to add the users you want client socket access disabled for to
61967+ the GID specified here. If the sysctl option is enabled, a sysctl
61968+ option with name "socket_client_gid" is created.
61969+
61970+config GRKERNSEC_SOCKET_SERVER
61971+ bool "Deny server sockets to group"
61972+ depends on GRKERNSEC_SOCKET
61973+ help
61974+ If you say Y here, you will be able to choose a GID of whose users will
61975+ be unable to run server applications from your machine. If the sysctl
61976+ option is enabled, a sysctl option with name "socket_server" is created.
61977+
61978+config GRKERNSEC_SOCKET_SERVER_GID
61979+ int "GID to deny server sockets for"
61980+ depends on GRKERNSEC_SOCKET_SERVER
61981+ default 1002
61982+ help
61983+ Here you can choose the GID to disable server socket access for.
61984+ Remember to add the users you want server socket access disabled for to
61985+ the GID specified here. If the sysctl option is enabled, a sysctl
61986+ option with name "socket_server_gid" is created.
61987+
61988+endmenu
61989+
61990+menu "Physical Protections"
61991+depends on GRKERNSEC
61992+
61993+config GRKERNSEC_DENYUSB
61994+ bool "Deny new USB connections after toggle"
61995+ default y if GRKERNSEC_CONFIG_AUTO
61996+ depends on SYSCTL && USB_SUPPORT
61997+ help
61998+ If you say Y here, a new sysctl option with name "deny_new_usb"
61999+ will be created. Setting its value to 1 will prevent any new
62000+ USB devices from being recognized by the OS. Any attempted USB
62001+ device insertion will be logged. This option is intended to be
62002+ used against custom USB devices designed to exploit vulnerabilities
62003+ in various USB device drivers.
62004+
62005+ For greatest effectiveness, this sysctl should be set after any
62006+ relevant init scripts. This option is safe to enable in distros
62007+ as each user can choose whether or not to toggle the sysctl.
62008+
62009+config GRKERNSEC_DENYUSB_FORCE
62010+ bool "Reject all USB devices not connected at boot"
62011+ select USB
62012+ depends on GRKERNSEC_DENYUSB
62013+ help
62014+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62015+ that doesn't involve a sysctl entry. This option should only be
62016+ enabled if you're sure you want to deny all new USB connections
62017+ at runtime and don't want to modify init scripts. This should not
62018+ be enabled by distros. It forces the core USB code to be built
62019+ into the kernel image so that all devices connected at boot time
62020+ can be recognized and new USB device connections can be prevented
62021+ prior to init running.
62022+
62023+endmenu
62024+
62025+menu "Sysctl Support"
62026+depends on GRKERNSEC && SYSCTL
62027+
62028+config GRKERNSEC_SYSCTL
62029+ bool "Sysctl support"
62030+ default y if GRKERNSEC_CONFIG_AUTO
62031+ help
62032+ If you say Y here, you will be able to change the options that
62033+ grsecurity runs with at bootup, without having to recompile your
62034+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62035+ to enable (1) or disable (0) various features. All the sysctl entries
62036+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62037+ All features enabled in the kernel configuration are disabled at boot
62038+ if you do not say Y to the "Turn on features by default" option.
62039+ All options should be set at startup, and the grsec_lock entry should
62040+ be set to a non-zero value after all the options are set.
62041+ *THIS IS EXTREMELY IMPORTANT*
62042+
62043+config GRKERNSEC_SYSCTL_DISTRO
62044+ bool "Extra sysctl support for distro makers (READ HELP)"
62045+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62046+ help
62047+ If you say Y here, additional sysctl options will be created
62048+ for features that affect processes running as root. Therefore,
62049+ it is critical when using this option that the grsec_lock entry be
62050+ enabled after boot. Only distros with prebuilt kernel packages
62051+ with this option enabled that can ensure grsec_lock is enabled
62052+ after boot should use this option.
62053+ *Failure to set grsec_lock after boot makes all grsec features
62054+ this option covers useless*
62055+
62056+ Currently this option creates the following sysctl entries:
62057+ "Disable Privileged I/O": "disable_priv_io"
62058+
62059+config GRKERNSEC_SYSCTL_ON
62060+ bool "Turn on features by default"
62061+ default y if GRKERNSEC_CONFIG_AUTO
62062+ depends on GRKERNSEC_SYSCTL
62063+ help
62064+ If you say Y here, instead of having all features enabled in the
62065+ kernel configuration disabled at boot time, the features will be
62066+ enabled at boot time. It is recommended you say Y here unless
62067+ there is some reason you would want all sysctl-tunable features to
62068+ be disabled by default. As mentioned elsewhere, it is important
62069+ to enable the grsec_lock entry once you have finished modifying
62070+ the sysctl entries.
62071+
62072+endmenu
62073+menu "Logging Options"
62074+depends on GRKERNSEC
62075+
62076+config GRKERNSEC_FLOODTIME
62077+ int "Seconds in between log messages (minimum)"
62078+ default 10
62079+ help
62080+ This option allows you to enforce the number of seconds between
62081+ grsecurity log messages. The default should be suitable for most
62082+ people, however, if you choose to change it, choose a value small enough
62083+ to allow informative logs to be produced, but large enough to
62084+ prevent flooding.
62085+
62086+config GRKERNSEC_FLOODBURST
62087+ int "Number of messages in a burst (maximum)"
62088+ default 6
62089+ help
62090+ This option allows you to choose the maximum number of messages allowed
62091+ within the flood time interval you chose in a separate option. The
62092+ default should be suitable for most people, however if you find that
62093+ many of your logs are being interpreted as flooding, you may want to
62094+ raise this value.
62095+
62096+endmenu
62097diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62098new file mode 100644
62099index 0000000..b0b77d5
62100--- /dev/null
62101+++ b/grsecurity/Makefile
62102@@ -0,0 +1,43 @@
62103+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62104+# during 2001-2009 it has been completely redesigned by Brad Spengler
62105+# into an RBAC system
62106+#
62107+# All code in this directory and various hooks inserted throughout the kernel
62108+# are copyright Brad Spengler - Open Source Security, Inc., and released
62109+# under the GPL v2 or higher
62110+
62111+KBUILD_CFLAGS += -Werror
62112+
62113+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62114+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62115+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62116+ grsec_usb.o
62117+
62118+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62119+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62120+ gracl_learn.o grsec_log.o
62121+ifdef CONFIG_COMPAT
62122+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62123+endif
62124+
62125+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62126+
62127+ifdef CONFIG_NET
62128+obj-y += grsec_sock.o
62129+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62130+endif
62131+
62132+ifndef CONFIG_GRKERNSEC
62133+obj-y += grsec_disabled.o
62134+endif
62135+
62136+ifdef CONFIG_GRKERNSEC_HIDESYM
62137+extra-y := grsec_hidesym.o
62138+$(obj)/grsec_hidesym.o:
62139+ @-chmod -f 500 /boot
62140+ @-chmod -f 500 /lib/modules
62141+ @-chmod -f 500 /lib64/modules
62142+ @-chmod -f 500 /lib32/modules
62143+ @-chmod -f 700 .
62144+ @echo ' grsec: protected kernel image paths'
62145+endif
62146diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62147new file mode 100644
62148index 0000000..c0793fd
62149--- /dev/null
62150+++ b/grsecurity/gracl.c
62151@@ -0,0 +1,4178 @@
62152+#include <linux/kernel.h>
62153+#include <linux/module.h>
62154+#include <linux/sched.h>
62155+#include <linux/mm.h>
62156+#include <linux/file.h>
62157+#include <linux/fs.h>
62158+#include <linux/namei.h>
62159+#include <linux/mount.h>
62160+#include <linux/tty.h>
62161+#include <linux/proc_fs.h>
62162+#include <linux/lglock.h>
62163+#include <linux/slab.h>
62164+#include <linux/vmalloc.h>
62165+#include <linux/types.h>
62166+#include <linux/sysctl.h>
62167+#include <linux/netdevice.h>
62168+#include <linux/ptrace.h>
62169+#include <linux/gracl.h>
62170+#include <linux/gralloc.h>
62171+#include <linux/security.h>
62172+#include <linux/grinternal.h>
62173+#include <linux/pid_namespace.h>
62174+#include <linux/stop_machine.h>
62175+#include <linux/fdtable.h>
62176+#include <linux/percpu.h>
62177+#include <linux/lglock.h>
62178+#include <linux/hugetlb.h>
62179+#include <linux/posix-timers.h>
62180+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62181+#include <linux/magic.h>
62182+#include <linux/pagemap.h>
62183+#include "../fs/btrfs/async-thread.h"
62184+#include "../fs/btrfs/ctree.h"
62185+#include "../fs/btrfs/btrfs_inode.h"
62186+#endif
62187+#include "../fs/mount.h"
62188+
62189+#include <asm/uaccess.h>
62190+#include <asm/errno.h>
62191+#include <asm/mman.h>
62192+
62193+extern struct lglock vfsmount_lock;
62194+
62195+static struct acl_role_db acl_role_set;
62196+static struct name_db name_set;
62197+static struct inodev_db inodev_set;
62198+
62199+/* for keeping track of userspace pointers used for subjects, so we
62200+ can share references in the kernel as well
62201+*/
62202+
62203+static struct path real_root;
62204+
62205+static struct acl_subj_map_db subj_map_set;
62206+
62207+static struct acl_role_label *default_role;
62208+
62209+static struct acl_role_label *role_list;
62210+
62211+static u16 acl_sp_role_value;
62212+
62213+extern char *gr_shared_page[4];
62214+static DEFINE_MUTEX(gr_dev_mutex);
62215+DEFINE_RWLOCK(gr_inode_lock);
62216+
62217+struct gr_arg *gr_usermode;
62218+
62219+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62220+
62221+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62222+extern void gr_clear_learn_entries(void);
62223+
62224+unsigned char *gr_system_salt;
62225+unsigned char *gr_system_sum;
62226+
62227+static struct sprole_pw **acl_special_roles = NULL;
62228+static __u16 num_sprole_pws = 0;
62229+
62230+static struct acl_role_label *kernel_role = NULL;
62231+
62232+static unsigned int gr_auth_attempts = 0;
62233+static unsigned long gr_auth_expires = 0UL;
62234+
62235+#ifdef CONFIG_NET
62236+extern struct vfsmount *sock_mnt;
62237+#endif
62238+
62239+extern struct vfsmount *pipe_mnt;
62240+extern struct vfsmount *shm_mnt;
62241+
62242+#ifdef CONFIG_HUGETLBFS
62243+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62244+#endif
62245+
62246+static struct acl_object_label *fakefs_obj_rw;
62247+static struct acl_object_label *fakefs_obj_rwx;
62248+
62249+extern int gr_init_uidset(void);
62250+extern void gr_free_uidset(void);
62251+extern void gr_remove_uid(uid_t uid);
62252+extern int gr_find_uid(uid_t uid);
62253+
62254+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62255+{
62256+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62257+ return -EFAULT;
62258+
62259+ return 0;
62260+}
62261+
62262+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62263+{
62264+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62265+ return -EFAULT;
62266+
62267+ return 0;
62268+}
62269+
62270+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62271+{
62272+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62273+ return -EFAULT;
62274+
62275+ return 0;
62276+}
62277+
62278+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62279+{
62280+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62281+ return -EFAULT;
62282+
62283+ return 0;
62284+}
62285+
62286+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62287+{
62288+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62289+ return -EFAULT;
62290+
62291+ return 0;
62292+}
62293+
62294+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62295+{
62296+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62297+ return -EFAULT;
62298+
62299+ return 0;
62300+}
62301+
62302+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62303+{
62304+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62305+ return -EFAULT;
62306+
62307+ return 0;
62308+}
62309+
62310+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62311+{
62312+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62313+ return -EFAULT;
62314+
62315+ return 0;
62316+}
62317+
62318+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62319+{
62320+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62321+ return -EFAULT;
62322+
62323+ return 0;
62324+}
62325+
62326+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62327+{
62328+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62329+ return -EFAULT;
62330+
62331+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62332+ return -EINVAL;
62333+
62334+ return 0;
62335+}
62336+
62337+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62338+{
62339+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62340+ return -EFAULT;
62341+
62342+ return 0;
62343+}
62344+
62345+static size_t get_gr_arg_wrapper_size_normal(void)
62346+{
62347+ return sizeof(struct gr_arg_wrapper);
62348+}
62349+
62350+#ifdef CONFIG_COMPAT
62351+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62352+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62353+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62354+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62355+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62356+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62357+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62358+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62359+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62360+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62361+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62362+extern size_t get_gr_arg_wrapper_size_compat(void);
62363+
62364+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62365+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62366+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62367+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62368+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62369+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62370+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62371+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62372+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62373+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62374+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62375+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62376+
62377+#else
62378+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62379+#define copy_gr_arg copy_gr_arg_normal
62380+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62381+#define copy_acl_object_label copy_acl_object_label_normal
62382+#define copy_acl_subject_label copy_acl_subject_label_normal
62383+#define copy_acl_role_label copy_acl_role_label_normal
62384+#define copy_acl_ip_label copy_acl_ip_label_normal
62385+#define copy_pointer_from_array copy_pointer_from_array_normal
62386+#define copy_sprole_pw copy_sprole_pw_normal
62387+#define copy_role_transition copy_role_transition_normal
62388+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62389+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62390+#endif
62391+
62392+__inline__ int
62393+gr_acl_is_enabled(void)
62394+{
62395+ return (gr_status & GR_READY);
62396+}
62397+
62398+static inline dev_t __get_dev(const struct dentry *dentry)
62399+{
62400+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62401+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62402+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62403+ else
62404+#endif
62405+ return dentry->d_sb->s_dev;
62406+}
62407+
62408+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62409+{
62410+ return __get_dev(dentry);
62411+}
62412+
62413+static char gr_task_roletype_to_char(struct task_struct *task)
62414+{
62415+ switch (task->role->roletype &
62416+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62417+ GR_ROLE_SPECIAL)) {
62418+ case GR_ROLE_DEFAULT:
62419+ return 'D';
62420+ case GR_ROLE_USER:
62421+ return 'U';
62422+ case GR_ROLE_GROUP:
62423+ return 'G';
62424+ case GR_ROLE_SPECIAL:
62425+ return 'S';
62426+ }
62427+
62428+ return 'X';
62429+}
62430+
62431+char gr_roletype_to_char(void)
62432+{
62433+ return gr_task_roletype_to_char(current);
62434+}
62435+
62436+__inline__ int
62437+gr_acl_tpe_check(void)
62438+{
62439+ if (unlikely(!(gr_status & GR_READY)))
62440+ return 0;
62441+ if (current->role->roletype & GR_ROLE_TPE)
62442+ return 1;
62443+ else
62444+ return 0;
62445+}
62446+
62447+int
62448+gr_handle_rawio(const struct inode *inode)
62449+{
62450+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62451+ if (inode && S_ISBLK(inode->i_mode) &&
62452+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62453+ !capable(CAP_SYS_RAWIO))
62454+ return 1;
62455+#endif
62456+ return 0;
62457+}
62458+
62459+static int
62460+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62461+{
62462+ if (likely(lena != lenb))
62463+ return 0;
62464+
62465+ return !memcmp(a, b, lena);
62466+}
62467+
62468+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62469+{
62470+ *buflen -= namelen;
62471+ if (*buflen < 0)
62472+ return -ENAMETOOLONG;
62473+ *buffer -= namelen;
62474+ memcpy(*buffer, str, namelen);
62475+ return 0;
62476+}
62477+
62478+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62479+{
62480+ return prepend(buffer, buflen, name->name, name->len);
62481+}
62482+
62483+static int prepend_path(const struct path *path, struct path *root,
62484+ char **buffer, int *buflen)
62485+{
62486+ struct dentry *dentry = path->dentry;
62487+ struct vfsmount *vfsmnt = path->mnt;
62488+ struct mount *mnt = real_mount(vfsmnt);
62489+ bool slash = false;
62490+ int error = 0;
62491+
62492+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62493+ struct dentry * parent;
62494+
62495+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62496+ /* Global root? */
62497+ if (!mnt_has_parent(mnt)) {
62498+ goto out;
62499+ }
62500+ dentry = mnt->mnt_mountpoint;
62501+ mnt = mnt->mnt_parent;
62502+ vfsmnt = &mnt->mnt;
62503+ continue;
62504+ }
62505+ parent = dentry->d_parent;
62506+ prefetch(parent);
62507+ spin_lock(&dentry->d_lock);
62508+ error = prepend_name(buffer, buflen, &dentry->d_name);
62509+ spin_unlock(&dentry->d_lock);
62510+ if (!error)
62511+ error = prepend(buffer, buflen, "/", 1);
62512+ if (error)
62513+ break;
62514+
62515+ slash = true;
62516+ dentry = parent;
62517+ }
62518+
62519+out:
62520+ if (!error && !slash)
62521+ error = prepend(buffer, buflen, "/", 1);
62522+
62523+ return error;
62524+}
62525+
62526+/* this must be called with vfsmount_lock and rename_lock held */
62527+
62528+static char *__our_d_path(const struct path *path, struct path *root,
62529+ char *buf, int buflen)
62530+{
62531+ char *res = buf + buflen;
62532+ int error;
62533+
62534+ prepend(&res, &buflen, "\0", 1);
62535+ error = prepend_path(path, root, &res, &buflen);
62536+ if (error)
62537+ return ERR_PTR(error);
62538+
62539+ return res;
62540+}
62541+
62542+static char *
62543+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62544+{
62545+ char *retval;
62546+
62547+ retval = __our_d_path(path, root, buf, buflen);
62548+ if (unlikely(IS_ERR(retval)))
62549+ retval = strcpy(buf, "<path too long>");
62550+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62551+ retval[1] = '\0';
62552+
62553+ return retval;
62554+}
62555+
62556+static char *
62557+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62558+ char *buf, int buflen)
62559+{
62560+ struct path path;
62561+ char *res;
62562+
62563+ path.dentry = (struct dentry *)dentry;
62564+ path.mnt = (struct vfsmount *)vfsmnt;
62565+
62566+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62567+ by the RBAC system */
62568+ res = gen_full_path(&path, &real_root, buf, buflen);
62569+
62570+ return res;
62571+}
62572+
62573+static char *
62574+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62575+ char *buf, int buflen)
62576+{
62577+ char *res;
62578+ struct path path;
62579+ struct path root;
62580+ struct task_struct *reaper = init_pid_ns.child_reaper;
62581+
62582+ path.dentry = (struct dentry *)dentry;
62583+ path.mnt = (struct vfsmount *)vfsmnt;
62584+
62585+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62586+ get_fs_root(reaper->fs, &root);
62587+
62588+ br_read_lock(&vfsmount_lock);
62589+ write_seqlock(&rename_lock);
62590+ res = gen_full_path(&path, &root, buf, buflen);
62591+ write_sequnlock(&rename_lock);
62592+ br_read_unlock(&vfsmount_lock);
62593+
62594+ path_put(&root);
62595+ return res;
62596+}
62597+
62598+static char *
62599+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62600+{
62601+ char *ret;
62602+ br_read_lock(&vfsmount_lock);
62603+ write_seqlock(&rename_lock);
62604+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62605+ PAGE_SIZE);
62606+ write_sequnlock(&rename_lock);
62607+ br_read_unlock(&vfsmount_lock);
62608+ return ret;
62609+}
62610+
62611+static char *
62612+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62613+{
62614+ char *ret;
62615+ char *buf;
62616+ int buflen;
62617+
62618+ br_read_lock(&vfsmount_lock);
62619+ write_seqlock(&rename_lock);
62620+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62621+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62622+ buflen = (int)(ret - buf);
62623+ if (buflen >= 5)
62624+ prepend(&ret, &buflen, "/proc", 5);
62625+ else
62626+ ret = strcpy(buf, "<path too long>");
62627+ write_sequnlock(&rename_lock);
62628+ br_read_unlock(&vfsmount_lock);
62629+ return ret;
62630+}
62631+
62632+char *
62633+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62634+{
62635+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62636+ PAGE_SIZE);
62637+}
62638+
62639+char *
62640+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62641+{
62642+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62643+ PAGE_SIZE);
62644+}
62645+
62646+char *
62647+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62648+{
62649+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62650+ PAGE_SIZE);
62651+}
62652+
62653+char *
62654+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62655+{
62656+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62657+ PAGE_SIZE);
62658+}
62659+
62660+char *
62661+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62662+{
62663+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62664+ PAGE_SIZE);
62665+}
62666+
62667+__inline__ __u32
62668+to_gr_audit(const __u32 reqmode)
62669+{
62670+ /* masks off auditable permission flags, then shifts them to create
62671+ auditing flags, and adds the special case of append auditing if
62672+ we're requesting write */
62673+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62674+}
62675+
62676+struct acl_subject_label *
62677+lookup_subject_map(const struct acl_subject_label *userp)
62678+{
62679+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62680+ struct subject_map *match;
62681+
62682+ match = subj_map_set.s_hash[index];
62683+
62684+ while (match && match->user != userp)
62685+ match = match->next;
62686+
62687+ if (match != NULL)
62688+ return match->kernel;
62689+ else
62690+ return NULL;
62691+}
62692+
62693+static void
62694+insert_subj_map_entry(struct subject_map *subjmap)
62695+{
62696+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62697+ struct subject_map **curr;
62698+
62699+ subjmap->prev = NULL;
62700+
62701+ curr = &subj_map_set.s_hash[index];
62702+ if (*curr != NULL)
62703+ (*curr)->prev = subjmap;
62704+
62705+ subjmap->next = *curr;
62706+ *curr = subjmap;
62707+
62708+ return;
62709+}
62710+
62711+static struct acl_role_label *
62712+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62713+ const gid_t gid)
62714+{
62715+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62716+ struct acl_role_label *match;
62717+ struct role_allowed_ip *ipp;
62718+ unsigned int x;
62719+ u32 curr_ip = task->signal->curr_ip;
62720+
62721+ task->signal->saved_ip = curr_ip;
62722+
62723+ match = acl_role_set.r_hash[index];
62724+
62725+ while (match) {
62726+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62727+ for (x = 0; x < match->domain_child_num; x++) {
62728+ if (match->domain_children[x] == uid)
62729+ goto found;
62730+ }
62731+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62732+ break;
62733+ match = match->next;
62734+ }
62735+found:
62736+ if (match == NULL) {
62737+ try_group:
62738+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62739+ match = acl_role_set.r_hash[index];
62740+
62741+ while (match) {
62742+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62743+ for (x = 0; x < match->domain_child_num; x++) {
62744+ if (match->domain_children[x] == gid)
62745+ goto found2;
62746+ }
62747+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62748+ break;
62749+ match = match->next;
62750+ }
62751+found2:
62752+ if (match == NULL)
62753+ match = default_role;
62754+ if (match->allowed_ips == NULL)
62755+ return match;
62756+ else {
62757+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62758+ if (likely
62759+ ((ntohl(curr_ip) & ipp->netmask) ==
62760+ (ntohl(ipp->addr) & ipp->netmask)))
62761+ return match;
62762+ }
62763+ match = default_role;
62764+ }
62765+ } else if (match->allowed_ips == NULL) {
62766+ return match;
62767+ } else {
62768+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62769+ if (likely
62770+ ((ntohl(curr_ip) & ipp->netmask) ==
62771+ (ntohl(ipp->addr) & ipp->netmask)))
62772+ return match;
62773+ }
62774+ goto try_group;
62775+ }
62776+
62777+ return match;
62778+}
62779+
62780+struct acl_subject_label *
62781+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62782+ const struct acl_role_label *role)
62783+{
62784+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62785+ struct acl_subject_label *match;
62786+
62787+ match = role->subj_hash[index];
62788+
62789+ while (match && (match->inode != ino || match->device != dev ||
62790+ (match->mode & GR_DELETED))) {
62791+ match = match->next;
62792+ }
62793+
62794+ if (match && !(match->mode & GR_DELETED))
62795+ return match;
62796+ else
62797+ return NULL;
62798+}
62799+
62800+struct acl_subject_label *
62801+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62802+ const struct acl_role_label *role)
62803+{
62804+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62805+ struct acl_subject_label *match;
62806+
62807+ match = role->subj_hash[index];
62808+
62809+ while (match && (match->inode != ino || match->device != dev ||
62810+ !(match->mode & GR_DELETED))) {
62811+ match = match->next;
62812+ }
62813+
62814+ if (match && (match->mode & GR_DELETED))
62815+ return match;
62816+ else
62817+ return NULL;
62818+}
62819+
62820+static struct acl_object_label *
62821+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62822+ const struct acl_subject_label *subj)
62823+{
62824+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62825+ struct acl_object_label *match;
62826+
62827+ match = subj->obj_hash[index];
62828+
62829+ while (match && (match->inode != ino || match->device != dev ||
62830+ (match->mode & GR_DELETED))) {
62831+ match = match->next;
62832+ }
62833+
62834+ if (match && !(match->mode & GR_DELETED))
62835+ return match;
62836+ else
62837+ return NULL;
62838+}
62839+
62840+static struct acl_object_label *
62841+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62842+ const struct acl_subject_label *subj)
62843+{
62844+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62845+ struct acl_object_label *match;
62846+
62847+ match = subj->obj_hash[index];
62848+
62849+ while (match && (match->inode != ino || match->device != dev ||
62850+ !(match->mode & GR_DELETED))) {
62851+ match = match->next;
62852+ }
62853+
62854+ if (match && (match->mode & GR_DELETED))
62855+ return match;
62856+
62857+ match = subj->obj_hash[index];
62858+
62859+ while (match && (match->inode != ino || match->device != dev ||
62860+ (match->mode & GR_DELETED))) {
62861+ match = match->next;
62862+ }
62863+
62864+ if (match && !(match->mode & GR_DELETED))
62865+ return match;
62866+ else
62867+ return NULL;
62868+}
62869+
62870+static struct name_entry *
62871+lookup_name_entry(const char *name)
62872+{
62873+ unsigned int len = strlen(name);
62874+ unsigned int key = full_name_hash(name, len);
62875+ unsigned int index = key % name_set.n_size;
62876+ struct name_entry *match;
62877+
62878+ match = name_set.n_hash[index];
62879+
62880+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62881+ match = match->next;
62882+
62883+ return match;
62884+}
62885+
62886+static struct name_entry *
62887+lookup_name_entry_create(const char *name)
62888+{
62889+ unsigned int len = strlen(name);
62890+ unsigned int key = full_name_hash(name, len);
62891+ unsigned int index = key % name_set.n_size;
62892+ struct name_entry *match;
62893+
62894+ match = name_set.n_hash[index];
62895+
62896+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62897+ !match->deleted))
62898+ match = match->next;
62899+
62900+ if (match && match->deleted)
62901+ return match;
62902+
62903+ match = name_set.n_hash[index];
62904+
62905+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62906+ match->deleted))
62907+ match = match->next;
62908+
62909+ if (match && !match->deleted)
62910+ return match;
62911+ else
62912+ return NULL;
62913+}
62914+
62915+static struct inodev_entry *
62916+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62917+{
62918+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62919+ struct inodev_entry *match;
62920+
62921+ match = inodev_set.i_hash[index];
62922+
62923+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62924+ match = match->next;
62925+
62926+ return match;
62927+}
62928+
62929+static void
62930+insert_inodev_entry(struct inodev_entry *entry)
62931+{
62932+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62933+ inodev_set.i_size);
62934+ struct inodev_entry **curr;
62935+
62936+ entry->prev = NULL;
62937+
62938+ curr = &inodev_set.i_hash[index];
62939+ if (*curr != NULL)
62940+ (*curr)->prev = entry;
62941+
62942+ entry->next = *curr;
62943+ *curr = entry;
62944+
62945+ return;
62946+}
62947+
62948+static void
62949+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62950+{
62951+ unsigned int index =
62952+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62953+ struct acl_role_label **curr;
62954+ struct acl_role_label *tmp, *tmp2;
62955+
62956+ curr = &acl_role_set.r_hash[index];
62957+
62958+ /* simple case, slot is empty, just set it to our role */
62959+ if (*curr == NULL) {
62960+ *curr = role;
62961+ } else {
62962+ /* example:
62963+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62964+ 2 -> 3
62965+ */
62966+ /* first check to see if we can already be reached via this slot */
62967+ tmp = *curr;
62968+ while (tmp && tmp != role)
62969+ tmp = tmp->next;
62970+ if (tmp == role) {
62971+ /* we don't need to add ourselves to this slot's chain */
62972+ return;
62973+ }
62974+ /* we need to add ourselves to this chain, two cases */
62975+ if (role->next == NULL) {
62976+ /* simple case, append the current chain to our role */
62977+ role->next = *curr;
62978+ *curr = role;
62979+ } else {
62980+ /* 1 -> 2 -> 3 -> 4
62981+ 2 -> 3 -> 4
62982+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62983+ */
62984+ /* trickier case: walk our role's chain until we find
62985+ the role for the start of the current slot's chain */
62986+ tmp = role;
62987+ tmp2 = *curr;
62988+ while (tmp->next && tmp->next != tmp2)
62989+ tmp = tmp->next;
62990+ if (tmp->next == tmp2) {
62991+ /* from example above, we found 3, so just
62992+ replace this slot's chain with ours */
62993+ *curr = role;
62994+ } else {
62995+ /* we didn't find a subset of our role's chain
62996+ in the current slot's chain, so append their
62997+ chain to ours, and set us as the first role in
62998+ the slot's chain
62999+
63000+ we could fold this case with the case above,
63001+ but making it explicit for clarity
63002+ */
63003+ tmp->next = tmp2;
63004+ *curr = role;
63005+ }
63006+ }
63007+ }
63008+
63009+ return;
63010+}
63011+
63012+static void
63013+insert_acl_role_label(struct acl_role_label *role)
63014+{
63015+ int i;
63016+
63017+ if (role_list == NULL) {
63018+ role_list = role;
63019+ role->prev = NULL;
63020+ } else {
63021+ role->prev = role_list;
63022+ role_list = role;
63023+ }
63024+
63025+ /* used for hash chains */
63026+ role->next = NULL;
63027+
63028+ if (role->roletype & GR_ROLE_DOMAIN) {
63029+ for (i = 0; i < role->domain_child_num; i++)
63030+ __insert_acl_role_label(role, role->domain_children[i]);
63031+ } else
63032+ __insert_acl_role_label(role, role->uidgid);
63033+}
63034+
63035+static int
63036+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63037+{
63038+ struct name_entry **curr, *nentry;
63039+ struct inodev_entry *ientry;
63040+ unsigned int len = strlen(name);
63041+ unsigned int key = full_name_hash(name, len);
63042+ unsigned int index = key % name_set.n_size;
63043+
63044+ curr = &name_set.n_hash[index];
63045+
63046+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63047+ curr = &((*curr)->next);
63048+
63049+ if (*curr != NULL)
63050+ return 1;
63051+
63052+ nentry = acl_alloc(sizeof (struct name_entry));
63053+ if (nentry == NULL)
63054+ return 0;
63055+ ientry = acl_alloc(sizeof (struct inodev_entry));
63056+ if (ientry == NULL)
63057+ return 0;
63058+ ientry->nentry = nentry;
63059+
63060+ nentry->key = key;
63061+ nentry->name = name;
63062+ nentry->inode = inode;
63063+ nentry->device = device;
63064+ nentry->len = len;
63065+ nentry->deleted = deleted;
63066+
63067+ nentry->prev = NULL;
63068+ curr = &name_set.n_hash[index];
63069+ if (*curr != NULL)
63070+ (*curr)->prev = nentry;
63071+ nentry->next = *curr;
63072+ *curr = nentry;
63073+
63074+ /* insert us into the table searchable by inode/dev */
63075+ insert_inodev_entry(ientry);
63076+
63077+ return 1;
63078+}
63079+
63080+static void
63081+insert_acl_obj_label(struct acl_object_label *obj,
63082+ struct acl_subject_label *subj)
63083+{
63084+ unsigned int index =
63085+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63086+ struct acl_object_label **curr;
63087+
63088+
63089+ obj->prev = NULL;
63090+
63091+ curr = &subj->obj_hash[index];
63092+ if (*curr != NULL)
63093+ (*curr)->prev = obj;
63094+
63095+ obj->next = *curr;
63096+ *curr = obj;
63097+
63098+ return;
63099+}
63100+
63101+static void
63102+insert_acl_subj_label(struct acl_subject_label *obj,
63103+ struct acl_role_label *role)
63104+{
63105+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63106+ struct acl_subject_label **curr;
63107+
63108+ obj->prev = NULL;
63109+
63110+ curr = &role->subj_hash[index];
63111+ if (*curr != NULL)
63112+ (*curr)->prev = obj;
63113+
63114+ obj->next = *curr;
63115+ *curr = obj;
63116+
63117+ return;
63118+}
63119+
63120+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63121+
63122+static void *
63123+create_table(__u32 * len, int elementsize)
63124+{
63125+ unsigned int table_sizes[] = {
63126+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63127+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63128+ 4194301, 8388593, 16777213, 33554393, 67108859
63129+ };
63130+ void *newtable = NULL;
63131+ unsigned int pwr = 0;
63132+
63133+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63134+ table_sizes[pwr] <= *len)
63135+ pwr++;
63136+
63137+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63138+ return newtable;
63139+
63140+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63141+ newtable =
63142+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63143+ else
63144+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63145+
63146+ *len = table_sizes[pwr];
63147+
63148+ return newtable;
63149+}
63150+
63151+static int
63152+init_variables(const struct gr_arg *arg)
63153+{
63154+ struct task_struct *reaper = init_pid_ns.child_reaper;
63155+ unsigned int stacksize;
63156+
63157+ subj_map_set.s_size = arg->role_db.num_subjects;
63158+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63159+ name_set.n_size = arg->role_db.num_objects;
63160+ inodev_set.i_size = arg->role_db.num_objects;
63161+
63162+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63163+ !name_set.n_size || !inodev_set.i_size)
63164+ return 1;
63165+
63166+ if (!gr_init_uidset())
63167+ return 1;
63168+
63169+ /* set up the stack that holds allocation info */
63170+
63171+ stacksize = arg->role_db.num_pointers + 5;
63172+
63173+ if (!acl_alloc_stack_init(stacksize))
63174+ return 1;
63175+
63176+ /* grab reference for the real root dentry and vfsmount */
63177+ get_fs_root(reaper->fs, &real_root);
63178+
63179+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63180+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63181+#endif
63182+
63183+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63184+ if (fakefs_obj_rw == NULL)
63185+ return 1;
63186+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63187+
63188+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63189+ if (fakefs_obj_rwx == NULL)
63190+ return 1;
63191+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63192+
63193+ subj_map_set.s_hash =
63194+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63195+ acl_role_set.r_hash =
63196+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63197+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63198+ inodev_set.i_hash =
63199+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63200+
63201+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63202+ !name_set.n_hash || !inodev_set.i_hash)
63203+ return 1;
63204+
63205+ memset(subj_map_set.s_hash, 0,
63206+ sizeof(struct subject_map *) * subj_map_set.s_size);
63207+ memset(acl_role_set.r_hash, 0,
63208+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63209+ memset(name_set.n_hash, 0,
63210+ sizeof (struct name_entry *) * name_set.n_size);
63211+ memset(inodev_set.i_hash, 0,
63212+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63213+
63214+ return 0;
63215+}
63216+
63217+/* free information not needed after startup
63218+ currently contains user->kernel pointer mappings for subjects
63219+*/
63220+
63221+static void
63222+free_init_variables(void)
63223+{
63224+ __u32 i;
63225+
63226+ if (subj_map_set.s_hash) {
63227+ for (i = 0; i < subj_map_set.s_size; i++) {
63228+ if (subj_map_set.s_hash[i]) {
63229+ kfree(subj_map_set.s_hash[i]);
63230+ subj_map_set.s_hash[i] = NULL;
63231+ }
63232+ }
63233+
63234+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63235+ PAGE_SIZE)
63236+ kfree(subj_map_set.s_hash);
63237+ else
63238+ vfree(subj_map_set.s_hash);
63239+ }
63240+
63241+ return;
63242+}
63243+
63244+static void
63245+free_variables(void)
63246+{
63247+ struct acl_subject_label *s;
63248+ struct acl_role_label *r;
63249+ struct task_struct *task, *task2;
63250+ unsigned int x;
63251+
63252+ gr_clear_learn_entries();
63253+
63254+ read_lock(&tasklist_lock);
63255+ do_each_thread(task2, task) {
63256+ task->acl_sp_role = 0;
63257+ task->acl_role_id = 0;
63258+ task->acl = NULL;
63259+ task->role = NULL;
63260+ } while_each_thread(task2, task);
63261+ read_unlock(&tasklist_lock);
63262+
63263+ /* release the reference to the real root dentry and vfsmount */
63264+ path_put(&real_root);
63265+ memset(&real_root, 0, sizeof(real_root));
63266+
63267+ /* free all object hash tables */
63268+
63269+ FOR_EACH_ROLE_START(r)
63270+ if (r->subj_hash == NULL)
63271+ goto next_role;
63272+ FOR_EACH_SUBJECT_START(r, s, x)
63273+ if (s->obj_hash == NULL)
63274+ break;
63275+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63276+ kfree(s->obj_hash);
63277+ else
63278+ vfree(s->obj_hash);
63279+ FOR_EACH_SUBJECT_END(s, x)
63280+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63281+ if (s->obj_hash == NULL)
63282+ break;
63283+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63284+ kfree(s->obj_hash);
63285+ else
63286+ vfree(s->obj_hash);
63287+ FOR_EACH_NESTED_SUBJECT_END(s)
63288+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63289+ kfree(r->subj_hash);
63290+ else
63291+ vfree(r->subj_hash);
63292+ r->subj_hash = NULL;
63293+next_role:
63294+ FOR_EACH_ROLE_END(r)
63295+
63296+ acl_free_all();
63297+
63298+ if (acl_role_set.r_hash) {
63299+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63300+ PAGE_SIZE)
63301+ kfree(acl_role_set.r_hash);
63302+ else
63303+ vfree(acl_role_set.r_hash);
63304+ }
63305+ if (name_set.n_hash) {
63306+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63307+ PAGE_SIZE)
63308+ kfree(name_set.n_hash);
63309+ else
63310+ vfree(name_set.n_hash);
63311+ }
63312+
63313+ if (inodev_set.i_hash) {
63314+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63315+ PAGE_SIZE)
63316+ kfree(inodev_set.i_hash);
63317+ else
63318+ vfree(inodev_set.i_hash);
63319+ }
63320+
63321+ gr_free_uidset();
63322+
63323+ memset(&name_set, 0, sizeof (struct name_db));
63324+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63325+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63326+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63327+
63328+ default_role = NULL;
63329+ kernel_role = NULL;
63330+ role_list = NULL;
63331+
63332+ return;
63333+}
63334+
63335+static struct acl_subject_label *
63336+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63337+
63338+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63339+{
63340+ unsigned int len = strnlen_user(*name, maxlen);
63341+ char *tmp;
63342+
63343+ if (!len || len >= maxlen)
63344+ return -EINVAL;
63345+
63346+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63347+ return -ENOMEM;
63348+
63349+ if (copy_from_user(tmp, *name, len))
63350+ return -EFAULT;
63351+
63352+ tmp[len-1] = '\0';
63353+ *name = tmp;
63354+
63355+ return 0;
63356+}
63357+
63358+static int
63359+copy_user_glob(struct acl_object_label *obj)
63360+{
63361+ struct acl_object_label *g_tmp, **guser;
63362+ int error;
63363+
63364+ if (obj->globbed == NULL)
63365+ return 0;
63366+
63367+ guser = &obj->globbed;
63368+ while (*guser) {
63369+ g_tmp = (struct acl_object_label *)
63370+ acl_alloc(sizeof (struct acl_object_label));
63371+ if (g_tmp == NULL)
63372+ return -ENOMEM;
63373+
63374+ if (copy_acl_object_label(g_tmp, *guser))
63375+ return -EFAULT;
63376+
63377+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63378+ if (error)
63379+ return error;
63380+
63381+ *guser = g_tmp;
63382+ guser = &(g_tmp->next);
63383+ }
63384+
63385+ return 0;
63386+}
63387+
63388+static int
63389+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63390+ struct acl_role_label *role)
63391+{
63392+ struct acl_object_label *o_tmp;
63393+ int ret;
63394+
63395+ while (userp) {
63396+ if ((o_tmp = (struct acl_object_label *)
63397+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63398+ return -ENOMEM;
63399+
63400+ if (copy_acl_object_label(o_tmp, userp))
63401+ return -EFAULT;
63402+
63403+ userp = o_tmp->prev;
63404+
63405+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63406+ if (ret)
63407+ return ret;
63408+
63409+ insert_acl_obj_label(o_tmp, subj);
63410+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63411+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63412+ return -ENOMEM;
63413+
63414+ ret = copy_user_glob(o_tmp);
63415+ if (ret)
63416+ return ret;
63417+
63418+ if (o_tmp->nested) {
63419+ int already_copied;
63420+
63421+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63422+ if (IS_ERR(o_tmp->nested))
63423+ return PTR_ERR(o_tmp->nested);
63424+
63425+ /* insert into nested subject list if we haven't copied this one yet
63426+ to prevent duplicate entries */
63427+ if (!already_copied) {
63428+ o_tmp->nested->next = role->hash->first;
63429+ role->hash->first = o_tmp->nested;
63430+ }
63431+ }
63432+ }
63433+
63434+ return 0;
63435+}
63436+
63437+static __u32
63438+count_user_subjs(struct acl_subject_label *userp)
63439+{
63440+ struct acl_subject_label s_tmp;
63441+ __u32 num = 0;
63442+
63443+ while (userp) {
63444+ if (copy_acl_subject_label(&s_tmp, userp))
63445+ break;
63446+
63447+ userp = s_tmp.prev;
63448+ }
63449+
63450+ return num;
63451+}
63452+
63453+static int
63454+copy_user_allowedips(struct acl_role_label *rolep)
63455+{
63456+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63457+
63458+ ruserip = rolep->allowed_ips;
63459+
63460+ while (ruserip) {
63461+ rlast = rtmp;
63462+
63463+ if ((rtmp = (struct role_allowed_ip *)
63464+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63465+ return -ENOMEM;
63466+
63467+ if (copy_role_allowed_ip(rtmp, ruserip))
63468+ return -EFAULT;
63469+
63470+ ruserip = rtmp->prev;
63471+
63472+ if (!rlast) {
63473+ rtmp->prev = NULL;
63474+ rolep->allowed_ips = rtmp;
63475+ } else {
63476+ rlast->next = rtmp;
63477+ rtmp->prev = rlast;
63478+ }
63479+
63480+ if (!ruserip)
63481+ rtmp->next = NULL;
63482+ }
63483+
63484+ return 0;
63485+}
63486+
63487+static int
63488+copy_user_transitions(struct acl_role_label *rolep)
63489+{
63490+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63491+ int error;
63492+
63493+ rusertp = rolep->transitions;
63494+
63495+ while (rusertp) {
63496+ rlast = rtmp;
63497+
63498+ if ((rtmp = (struct role_transition *)
63499+ acl_alloc(sizeof (struct role_transition))) == NULL)
63500+ return -ENOMEM;
63501+
63502+ if (copy_role_transition(rtmp, rusertp))
63503+ return -EFAULT;
63504+
63505+ rusertp = rtmp->prev;
63506+
63507+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63508+ if (error)
63509+ return error;
63510+
63511+ if (!rlast) {
63512+ rtmp->prev = NULL;
63513+ rolep->transitions = rtmp;
63514+ } else {
63515+ rlast->next = rtmp;
63516+ rtmp->prev = rlast;
63517+ }
63518+
63519+ if (!rusertp)
63520+ rtmp->next = NULL;
63521+ }
63522+
63523+ return 0;
63524+}
63525+
63526+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63527+{
63528+ struct acl_object_label o_tmp;
63529+ __u32 num = 0;
63530+
63531+ while (userp) {
63532+ if (copy_acl_object_label(&o_tmp, userp))
63533+ break;
63534+
63535+ userp = o_tmp.prev;
63536+ num++;
63537+ }
63538+
63539+ return num;
63540+}
63541+
63542+static struct acl_subject_label *
63543+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63544+{
63545+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63546+ __u32 num_objs;
63547+ struct acl_ip_label **i_tmp, *i_utmp2;
63548+ struct gr_hash_struct ghash;
63549+ struct subject_map *subjmap;
63550+ unsigned int i_num;
63551+ int err;
63552+
63553+ if (already_copied != NULL)
63554+ *already_copied = 0;
63555+
63556+ s_tmp = lookup_subject_map(userp);
63557+
63558+ /* we've already copied this subject into the kernel, just return
63559+ the reference to it, and don't copy it over again
63560+ */
63561+ if (s_tmp) {
63562+ if (already_copied != NULL)
63563+ *already_copied = 1;
63564+ return(s_tmp);
63565+ }
63566+
63567+ if ((s_tmp = (struct acl_subject_label *)
63568+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63569+ return ERR_PTR(-ENOMEM);
63570+
63571+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63572+ if (subjmap == NULL)
63573+ return ERR_PTR(-ENOMEM);
63574+
63575+ subjmap->user = userp;
63576+ subjmap->kernel = s_tmp;
63577+ insert_subj_map_entry(subjmap);
63578+
63579+ if (copy_acl_subject_label(s_tmp, userp))
63580+ return ERR_PTR(-EFAULT);
63581+
63582+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63583+ if (err)
63584+ return ERR_PTR(err);
63585+
63586+ if (!strcmp(s_tmp->filename, "/"))
63587+ role->root_label = s_tmp;
63588+
63589+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63590+ return ERR_PTR(-EFAULT);
63591+
63592+ /* copy user and group transition tables */
63593+
63594+ if (s_tmp->user_trans_num) {
63595+ uid_t *uidlist;
63596+
63597+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63598+ if (uidlist == NULL)
63599+ return ERR_PTR(-ENOMEM);
63600+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63601+ return ERR_PTR(-EFAULT);
63602+
63603+ s_tmp->user_transitions = uidlist;
63604+ }
63605+
63606+ if (s_tmp->group_trans_num) {
63607+ gid_t *gidlist;
63608+
63609+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63610+ if (gidlist == NULL)
63611+ return ERR_PTR(-ENOMEM);
63612+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63613+ return ERR_PTR(-EFAULT);
63614+
63615+ s_tmp->group_transitions = gidlist;
63616+ }
63617+
63618+ /* set up object hash table */
63619+ num_objs = count_user_objs(ghash.first);
63620+
63621+ s_tmp->obj_hash_size = num_objs;
63622+ s_tmp->obj_hash =
63623+ (struct acl_object_label **)
63624+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63625+
63626+ if (!s_tmp->obj_hash)
63627+ return ERR_PTR(-ENOMEM);
63628+
63629+ memset(s_tmp->obj_hash, 0,
63630+ s_tmp->obj_hash_size *
63631+ sizeof (struct acl_object_label *));
63632+
63633+ /* add in objects */
63634+ err = copy_user_objs(ghash.first, s_tmp, role);
63635+
63636+ if (err)
63637+ return ERR_PTR(err);
63638+
63639+ /* set pointer for parent subject */
63640+ if (s_tmp->parent_subject) {
63641+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63642+
63643+ if (IS_ERR(s_tmp2))
63644+ return s_tmp2;
63645+
63646+ s_tmp->parent_subject = s_tmp2;
63647+ }
63648+
63649+ /* add in ip acls */
63650+
63651+ if (!s_tmp->ip_num) {
63652+ s_tmp->ips = NULL;
63653+ goto insert;
63654+ }
63655+
63656+ i_tmp =
63657+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63658+ sizeof (struct acl_ip_label *));
63659+
63660+ if (!i_tmp)
63661+ return ERR_PTR(-ENOMEM);
63662+
63663+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63664+ *(i_tmp + i_num) =
63665+ (struct acl_ip_label *)
63666+ acl_alloc(sizeof (struct acl_ip_label));
63667+ if (!*(i_tmp + i_num))
63668+ return ERR_PTR(-ENOMEM);
63669+
63670+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63671+ return ERR_PTR(-EFAULT);
63672+
63673+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63674+ return ERR_PTR(-EFAULT);
63675+
63676+ if ((*(i_tmp + i_num))->iface == NULL)
63677+ continue;
63678+
63679+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63680+ if (err)
63681+ return ERR_PTR(err);
63682+ }
63683+
63684+ s_tmp->ips = i_tmp;
63685+
63686+insert:
63687+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63688+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63689+ return ERR_PTR(-ENOMEM);
63690+
63691+ return s_tmp;
63692+}
63693+
63694+static int
63695+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63696+{
63697+ struct acl_subject_label s_pre;
63698+ struct acl_subject_label * ret;
63699+ int err;
63700+
63701+ while (userp) {
63702+ if (copy_acl_subject_label(&s_pre, userp))
63703+ return -EFAULT;
63704+
63705+ ret = do_copy_user_subj(userp, role, NULL);
63706+
63707+ err = PTR_ERR(ret);
63708+ if (IS_ERR(ret))
63709+ return err;
63710+
63711+ insert_acl_subj_label(ret, role);
63712+
63713+ userp = s_pre.prev;
63714+ }
63715+
63716+ return 0;
63717+}
63718+
63719+static int
63720+copy_user_acl(struct gr_arg *arg)
63721+{
63722+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63723+ struct acl_subject_label *subj_list;
63724+ struct sprole_pw *sptmp;
63725+ struct gr_hash_struct *ghash;
63726+ uid_t *domainlist;
63727+ unsigned int r_num;
63728+ int err = 0;
63729+ __u16 i;
63730+ __u32 num_subjs;
63731+
63732+ /* we need a default and kernel role */
63733+ if (arg->role_db.num_roles < 2)
63734+ return -EINVAL;
63735+
63736+ /* copy special role authentication info from userspace */
63737+
63738+ num_sprole_pws = arg->num_sprole_pws;
63739+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63740+
63741+ if (!acl_special_roles && num_sprole_pws)
63742+ return -ENOMEM;
63743+
63744+ for (i = 0; i < num_sprole_pws; i++) {
63745+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63746+ if (!sptmp)
63747+ return -ENOMEM;
63748+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63749+ return -EFAULT;
63750+
63751+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63752+ if (err)
63753+ return err;
63754+
63755+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63756+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63757+#endif
63758+
63759+ acl_special_roles[i] = sptmp;
63760+ }
63761+
63762+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63763+
63764+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63765+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63766+
63767+ if (!r_tmp)
63768+ return -ENOMEM;
63769+
63770+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63771+ return -EFAULT;
63772+
63773+ if (copy_acl_role_label(r_tmp, r_utmp2))
63774+ return -EFAULT;
63775+
63776+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63777+ if (err)
63778+ return err;
63779+
63780+ if (!strcmp(r_tmp->rolename, "default")
63781+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63782+ default_role = r_tmp;
63783+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63784+ kernel_role = r_tmp;
63785+ }
63786+
63787+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63788+ return -ENOMEM;
63789+
63790+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63791+ return -EFAULT;
63792+
63793+ r_tmp->hash = ghash;
63794+
63795+ num_subjs = count_user_subjs(r_tmp->hash->first);
63796+
63797+ r_tmp->subj_hash_size = num_subjs;
63798+ r_tmp->subj_hash =
63799+ (struct acl_subject_label **)
63800+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63801+
63802+ if (!r_tmp->subj_hash)
63803+ return -ENOMEM;
63804+
63805+ err = copy_user_allowedips(r_tmp);
63806+ if (err)
63807+ return err;
63808+
63809+ /* copy domain info */
63810+ if (r_tmp->domain_children != NULL) {
63811+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63812+ if (domainlist == NULL)
63813+ return -ENOMEM;
63814+
63815+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63816+ return -EFAULT;
63817+
63818+ r_tmp->domain_children = domainlist;
63819+ }
63820+
63821+ err = copy_user_transitions(r_tmp);
63822+ if (err)
63823+ return err;
63824+
63825+ memset(r_tmp->subj_hash, 0,
63826+ r_tmp->subj_hash_size *
63827+ sizeof (struct acl_subject_label *));
63828+
63829+ /* acquire the list of subjects, then NULL out
63830+ the list prior to parsing the subjects for this role,
63831+ as during this parsing the list is replaced with a list
63832+ of *nested* subjects for the role
63833+ */
63834+ subj_list = r_tmp->hash->first;
63835+
63836+ /* set nested subject list to null */
63837+ r_tmp->hash->first = NULL;
63838+
63839+ err = copy_user_subjs(subj_list, r_tmp);
63840+
63841+ if (err)
63842+ return err;
63843+
63844+ insert_acl_role_label(r_tmp);
63845+ }
63846+
63847+ if (default_role == NULL || kernel_role == NULL)
63848+ return -EINVAL;
63849+
63850+ return err;
63851+}
63852+
63853+static int
63854+gracl_init(struct gr_arg *args)
63855+{
63856+ int error = 0;
63857+
63858+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63859+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63860+
63861+ if (init_variables(args)) {
63862+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63863+ error = -ENOMEM;
63864+ free_variables();
63865+ goto out;
63866+ }
63867+
63868+ error = copy_user_acl(args);
63869+ free_init_variables();
63870+ if (error) {
63871+ free_variables();
63872+ goto out;
63873+ }
63874+
63875+ if ((error = gr_set_acls(0))) {
63876+ free_variables();
63877+ goto out;
63878+ }
63879+
63880+ pax_open_kernel();
63881+ gr_status |= GR_READY;
63882+ pax_close_kernel();
63883+
63884+ out:
63885+ return error;
63886+}
63887+
63888+/* derived from glibc fnmatch() 0: match, 1: no match*/
63889+
63890+static int
63891+glob_match(const char *p, const char *n)
63892+{
63893+ char c;
63894+
63895+ while ((c = *p++) != '\0') {
63896+ switch (c) {
63897+ case '?':
63898+ if (*n == '\0')
63899+ return 1;
63900+ else if (*n == '/')
63901+ return 1;
63902+ break;
63903+ case '\\':
63904+ if (*n != c)
63905+ return 1;
63906+ break;
63907+ case '*':
63908+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63909+ if (*n == '/')
63910+ return 1;
63911+ else if (c == '?') {
63912+ if (*n == '\0')
63913+ return 1;
63914+ else
63915+ ++n;
63916+ }
63917+ }
63918+ if (c == '\0') {
63919+ return 0;
63920+ } else {
63921+ const char *endp;
63922+
63923+ if ((endp = strchr(n, '/')) == NULL)
63924+ endp = n + strlen(n);
63925+
63926+ if (c == '[') {
63927+ for (--p; n < endp; ++n)
63928+ if (!glob_match(p, n))
63929+ return 0;
63930+ } else if (c == '/') {
63931+ while (*n != '\0' && *n != '/')
63932+ ++n;
63933+ if (*n == '/' && !glob_match(p, n + 1))
63934+ return 0;
63935+ } else {
63936+ for (--p; n < endp; ++n)
63937+ if (*n == c && !glob_match(p, n))
63938+ return 0;
63939+ }
63940+
63941+ return 1;
63942+ }
63943+ case '[':
63944+ {
63945+ int not;
63946+ char cold;
63947+
63948+ if (*n == '\0' || *n == '/')
63949+ return 1;
63950+
63951+ not = (*p == '!' || *p == '^');
63952+ if (not)
63953+ ++p;
63954+
63955+ c = *p++;
63956+ for (;;) {
63957+ unsigned char fn = (unsigned char)*n;
63958+
63959+ if (c == '\0')
63960+ return 1;
63961+ else {
63962+ if (c == fn)
63963+ goto matched;
63964+ cold = c;
63965+ c = *p++;
63966+
63967+ if (c == '-' && *p != ']') {
63968+ unsigned char cend = *p++;
63969+
63970+ if (cend == '\0')
63971+ return 1;
63972+
63973+ if (cold <= fn && fn <= cend)
63974+ goto matched;
63975+
63976+ c = *p++;
63977+ }
63978+ }
63979+
63980+ if (c == ']')
63981+ break;
63982+ }
63983+ if (!not)
63984+ return 1;
63985+ break;
63986+ matched:
63987+ while (c != ']') {
63988+ if (c == '\0')
63989+ return 1;
63990+
63991+ c = *p++;
63992+ }
63993+ if (not)
63994+ return 1;
63995+ }
63996+ break;
63997+ default:
63998+ if (c != *n)
63999+ return 1;
64000+ }
64001+
64002+ ++n;
64003+ }
64004+
64005+ if (*n == '\0')
64006+ return 0;
64007+
64008+ if (*n == '/')
64009+ return 0;
64010+
64011+ return 1;
64012+}
64013+
64014+static struct acl_object_label *
64015+chk_glob_label(struct acl_object_label *globbed,
64016+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64017+{
64018+ struct acl_object_label *tmp;
64019+
64020+ if (*path == NULL)
64021+ *path = gr_to_filename_nolock(dentry, mnt);
64022+
64023+ tmp = globbed;
64024+
64025+ while (tmp) {
64026+ if (!glob_match(tmp->filename, *path))
64027+ return tmp;
64028+ tmp = tmp->next;
64029+ }
64030+
64031+ return NULL;
64032+}
64033+
64034+static struct acl_object_label *
64035+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64036+ const ino_t curr_ino, const dev_t curr_dev,
64037+ const struct acl_subject_label *subj, char **path, const int checkglob)
64038+{
64039+ struct acl_subject_label *tmpsubj;
64040+ struct acl_object_label *retval;
64041+ struct acl_object_label *retval2;
64042+
64043+ tmpsubj = (struct acl_subject_label *) subj;
64044+ read_lock(&gr_inode_lock);
64045+ do {
64046+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64047+ if (retval) {
64048+ if (checkglob && retval->globbed) {
64049+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64050+ if (retval2)
64051+ retval = retval2;
64052+ }
64053+ break;
64054+ }
64055+ } while ((tmpsubj = tmpsubj->parent_subject));
64056+ read_unlock(&gr_inode_lock);
64057+
64058+ return retval;
64059+}
64060+
64061+static __inline__ struct acl_object_label *
64062+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64063+ struct dentry *curr_dentry,
64064+ const struct acl_subject_label *subj, char **path, const int checkglob)
64065+{
64066+ int newglob = checkglob;
64067+ ino_t inode;
64068+ dev_t device;
64069+
64070+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64071+ as we don't want a / * rule to match instead of the / object
64072+ don't do this for create lookups that call this function though, since they're looking up
64073+ on the parent and thus need globbing checks on all paths
64074+ */
64075+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64076+ newglob = GR_NO_GLOB;
64077+
64078+ spin_lock(&curr_dentry->d_lock);
64079+ inode = curr_dentry->d_inode->i_ino;
64080+ device = __get_dev(curr_dentry);
64081+ spin_unlock(&curr_dentry->d_lock);
64082+
64083+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64084+}
64085+
64086+#ifdef CONFIG_HUGETLBFS
64087+static inline bool
64088+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64089+{
64090+ int i;
64091+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64092+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64093+ return true;
64094+ }
64095+
64096+ return false;
64097+}
64098+#endif
64099+
64100+static struct acl_object_label *
64101+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64102+ const struct acl_subject_label *subj, char *path, const int checkglob)
64103+{
64104+ struct dentry *dentry = (struct dentry *) l_dentry;
64105+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64106+ struct mount *real_mnt = real_mount(mnt);
64107+ struct acl_object_label *retval;
64108+ struct dentry *parent;
64109+
64110+ br_read_lock(&vfsmount_lock);
64111+ write_seqlock(&rename_lock);
64112+
64113+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64114+#ifdef CONFIG_NET
64115+ mnt == sock_mnt ||
64116+#endif
64117+#ifdef CONFIG_HUGETLBFS
64118+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64119+#endif
64120+ /* ignore Eric Biederman */
64121+ IS_PRIVATE(l_dentry->d_inode))) {
64122+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64123+ goto out;
64124+ }
64125+
64126+ for (;;) {
64127+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64128+ break;
64129+
64130+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64131+ if (!mnt_has_parent(real_mnt))
64132+ break;
64133+
64134+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64135+ if (retval != NULL)
64136+ goto out;
64137+
64138+ dentry = real_mnt->mnt_mountpoint;
64139+ real_mnt = real_mnt->mnt_parent;
64140+ mnt = &real_mnt->mnt;
64141+ continue;
64142+ }
64143+
64144+ parent = dentry->d_parent;
64145+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64146+ if (retval != NULL)
64147+ goto out;
64148+
64149+ dentry = parent;
64150+ }
64151+
64152+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64153+
64154+ /* real_root is pinned so we don't have to hold a reference */
64155+ if (retval == NULL)
64156+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64157+out:
64158+ write_sequnlock(&rename_lock);
64159+ br_read_unlock(&vfsmount_lock);
64160+
64161+ BUG_ON(retval == NULL);
64162+
64163+ return retval;
64164+}
64165+
64166+static __inline__ struct acl_object_label *
64167+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64168+ const struct acl_subject_label *subj)
64169+{
64170+ char *path = NULL;
64171+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64172+}
64173+
64174+static __inline__ struct acl_object_label *
64175+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64176+ const struct acl_subject_label *subj)
64177+{
64178+ char *path = NULL;
64179+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64180+}
64181+
64182+static __inline__ struct acl_object_label *
64183+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64184+ const struct acl_subject_label *subj, char *path)
64185+{
64186+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64187+}
64188+
64189+static struct acl_subject_label *
64190+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64191+ const struct acl_role_label *role)
64192+{
64193+ struct dentry *dentry = (struct dentry *) l_dentry;
64194+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64195+ struct mount *real_mnt = real_mount(mnt);
64196+ struct acl_subject_label *retval;
64197+ struct dentry *parent;
64198+
64199+ br_read_lock(&vfsmount_lock);
64200+ write_seqlock(&rename_lock);
64201+
64202+ for (;;) {
64203+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64204+ break;
64205+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64206+ if (!mnt_has_parent(real_mnt))
64207+ break;
64208+
64209+ spin_lock(&dentry->d_lock);
64210+ read_lock(&gr_inode_lock);
64211+ retval =
64212+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64213+ __get_dev(dentry), role);
64214+ read_unlock(&gr_inode_lock);
64215+ spin_unlock(&dentry->d_lock);
64216+ if (retval != NULL)
64217+ goto out;
64218+
64219+ dentry = real_mnt->mnt_mountpoint;
64220+ real_mnt = real_mnt->mnt_parent;
64221+ mnt = &real_mnt->mnt;
64222+ continue;
64223+ }
64224+
64225+ spin_lock(&dentry->d_lock);
64226+ read_lock(&gr_inode_lock);
64227+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64228+ __get_dev(dentry), role);
64229+ read_unlock(&gr_inode_lock);
64230+ parent = dentry->d_parent;
64231+ spin_unlock(&dentry->d_lock);
64232+
64233+ if (retval != NULL)
64234+ goto out;
64235+
64236+ dentry = parent;
64237+ }
64238+
64239+ spin_lock(&dentry->d_lock);
64240+ read_lock(&gr_inode_lock);
64241+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64242+ __get_dev(dentry), role);
64243+ read_unlock(&gr_inode_lock);
64244+ spin_unlock(&dentry->d_lock);
64245+
64246+ if (unlikely(retval == NULL)) {
64247+ /* real_root is pinned, we don't need to hold a reference */
64248+ read_lock(&gr_inode_lock);
64249+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64250+ __get_dev(real_root.dentry), role);
64251+ read_unlock(&gr_inode_lock);
64252+ }
64253+out:
64254+ write_sequnlock(&rename_lock);
64255+ br_read_unlock(&vfsmount_lock);
64256+
64257+ BUG_ON(retval == NULL);
64258+
64259+ return retval;
64260+}
64261+
64262+static void
64263+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64264+{
64265+ struct task_struct *task = current;
64266+ const struct cred *cred = current_cred();
64267+
64268+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64269+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64270+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64271+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64272+
64273+ return;
64274+}
64275+
64276+static void
64277+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64278+{
64279+ struct task_struct *task = current;
64280+ const struct cred *cred = current_cred();
64281+
64282+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64283+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64284+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64285+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64286+
64287+ return;
64288+}
64289+
64290+static void
64291+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64292+{
64293+ struct task_struct *task = current;
64294+ const struct cred *cred = current_cred();
64295+
64296+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64297+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64298+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64299+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64300+
64301+ return;
64302+}
64303+
64304+__u32
64305+gr_search_file(const struct dentry * dentry, const __u32 mode,
64306+ const struct vfsmount * mnt)
64307+{
64308+ __u32 retval = mode;
64309+ struct acl_subject_label *curracl;
64310+ struct acl_object_label *currobj;
64311+
64312+ if (unlikely(!(gr_status & GR_READY)))
64313+ return (mode & ~GR_AUDITS);
64314+
64315+ curracl = current->acl;
64316+
64317+ currobj = chk_obj_label(dentry, mnt, curracl);
64318+ retval = currobj->mode & mode;
64319+
64320+ /* if we're opening a specified transfer file for writing
64321+ (e.g. /dev/initctl), then transfer our role to init
64322+ */
64323+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64324+ current->role->roletype & GR_ROLE_PERSIST)) {
64325+ struct task_struct *task = init_pid_ns.child_reaper;
64326+
64327+ if (task->role != current->role) {
64328+ task->acl_sp_role = 0;
64329+ task->acl_role_id = current->acl_role_id;
64330+ task->role = current->role;
64331+ rcu_read_lock();
64332+ read_lock(&grsec_exec_file_lock);
64333+ gr_apply_subject_to_task(task);
64334+ read_unlock(&grsec_exec_file_lock);
64335+ rcu_read_unlock();
64336+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64337+ }
64338+ }
64339+
64340+ if (unlikely
64341+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64342+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64343+ __u32 new_mode = mode;
64344+
64345+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64346+
64347+ retval = new_mode;
64348+
64349+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64350+ new_mode |= GR_INHERIT;
64351+
64352+ if (!(mode & GR_NOLEARN))
64353+ gr_log_learn(dentry, mnt, new_mode);
64354+ }
64355+
64356+ return retval;
64357+}
64358+
64359+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64360+ const struct dentry *parent,
64361+ const struct vfsmount *mnt)
64362+{
64363+ struct name_entry *match;
64364+ struct acl_object_label *matchpo;
64365+ struct acl_subject_label *curracl;
64366+ char *path;
64367+
64368+ if (unlikely(!(gr_status & GR_READY)))
64369+ return NULL;
64370+
64371+ preempt_disable();
64372+ path = gr_to_filename_rbac(new_dentry, mnt);
64373+ match = lookup_name_entry_create(path);
64374+
64375+ curracl = current->acl;
64376+
64377+ if (match) {
64378+ read_lock(&gr_inode_lock);
64379+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64380+ read_unlock(&gr_inode_lock);
64381+
64382+ if (matchpo) {
64383+ preempt_enable();
64384+ return matchpo;
64385+ }
64386+ }
64387+
64388+ // lookup parent
64389+
64390+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64391+
64392+ preempt_enable();
64393+ return matchpo;
64394+}
64395+
64396+__u32
64397+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64398+ const struct vfsmount * mnt, const __u32 mode)
64399+{
64400+ struct acl_object_label *matchpo;
64401+ __u32 retval;
64402+
64403+ if (unlikely(!(gr_status & GR_READY)))
64404+ return (mode & ~GR_AUDITS);
64405+
64406+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64407+
64408+ retval = matchpo->mode & mode;
64409+
64410+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64411+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64412+ __u32 new_mode = mode;
64413+
64414+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64415+
64416+ gr_log_learn(new_dentry, mnt, new_mode);
64417+ return new_mode;
64418+ }
64419+
64420+ return retval;
64421+}
64422+
64423+__u32
64424+gr_check_link(const struct dentry * new_dentry,
64425+ const struct dentry * parent_dentry,
64426+ const struct vfsmount * parent_mnt,
64427+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64428+{
64429+ struct acl_object_label *obj;
64430+ __u32 oldmode, newmode;
64431+ __u32 needmode;
64432+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64433+ GR_DELETE | GR_INHERIT;
64434+
64435+ if (unlikely(!(gr_status & GR_READY)))
64436+ return (GR_CREATE | GR_LINK);
64437+
64438+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64439+ oldmode = obj->mode;
64440+
64441+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64442+ newmode = obj->mode;
64443+
64444+ needmode = newmode & checkmodes;
64445+
64446+ // old name for hardlink must have at least the permissions of the new name
64447+ if ((oldmode & needmode) != needmode)
64448+ goto bad;
64449+
64450+ // if old name had restrictions/auditing, make sure the new name does as well
64451+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64452+
64453+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64454+ if (is_privileged_binary(old_dentry))
64455+ needmode |= GR_SETID;
64456+
64457+ if ((newmode & needmode) != needmode)
64458+ goto bad;
64459+
64460+ // enforce minimum permissions
64461+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64462+ return newmode;
64463+bad:
64464+ needmode = oldmode;
64465+ if (is_privileged_binary(old_dentry))
64466+ needmode |= GR_SETID;
64467+
64468+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64469+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64470+ return (GR_CREATE | GR_LINK);
64471+ } else if (newmode & GR_SUPPRESS)
64472+ return GR_SUPPRESS;
64473+ else
64474+ return 0;
64475+}
64476+
64477+int
64478+gr_check_hidden_task(const struct task_struct *task)
64479+{
64480+ if (unlikely(!(gr_status & GR_READY)))
64481+ return 0;
64482+
64483+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64484+ return 1;
64485+
64486+ return 0;
64487+}
64488+
64489+int
64490+gr_check_protected_task(const struct task_struct *task)
64491+{
64492+ if (unlikely(!(gr_status & GR_READY) || !task))
64493+ return 0;
64494+
64495+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64496+ task->acl != current->acl)
64497+ return 1;
64498+
64499+ return 0;
64500+}
64501+
64502+int
64503+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64504+{
64505+ struct task_struct *p;
64506+ int ret = 0;
64507+
64508+ if (unlikely(!(gr_status & GR_READY) || !pid))
64509+ return ret;
64510+
64511+ read_lock(&tasklist_lock);
64512+ do_each_pid_task(pid, type, p) {
64513+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64514+ p->acl != current->acl) {
64515+ ret = 1;
64516+ goto out;
64517+ }
64518+ } while_each_pid_task(pid, type, p);
64519+out:
64520+ read_unlock(&tasklist_lock);
64521+
64522+ return ret;
64523+}
64524+
64525+void
64526+gr_copy_label(struct task_struct *tsk)
64527+{
64528+ tsk->signal->used_accept = 0;
64529+ tsk->acl_sp_role = 0;
64530+ tsk->acl_role_id = current->acl_role_id;
64531+ tsk->acl = current->acl;
64532+ tsk->role = current->role;
64533+ tsk->signal->curr_ip = current->signal->curr_ip;
64534+ tsk->signal->saved_ip = current->signal->saved_ip;
64535+ if (current->exec_file)
64536+ get_file(current->exec_file);
64537+ tsk->exec_file = current->exec_file;
64538+ tsk->is_writable = current->is_writable;
64539+ if (unlikely(current->signal->used_accept)) {
64540+ current->signal->curr_ip = 0;
64541+ current->signal->saved_ip = 0;
64542+ }
64543+
64544+ return;
64545+}
64546+
64547+static void
64548+gr_set_proc_res(struct task_struct *task)
64549+{
64550+ struct acl_subject_label *proc;
64551+ unsigned short i;
64552+
64553+ proc = task->acl;
64554+
64555+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64556+ return;
64557+
64558+ for (i = 0; i < RLIM_NLIMITS; i++) {
64559+ if (!(proc->resmask & (1U << i)))
64560+ continue;
64561+
64562+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64563+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64564+
64565+ if (i == RLIMIT_CPU)
64566+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64567+ }
64568+
64569+ return;
64570+}
64571+
64572+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64573+
64574+int
64575+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64576+{
64577+ unsigned int i;
64578+ __u16 num;
64579+ uid_t *uidlist;
64580+ uid_t curuid;
64581+ int realok = 0;
64582+ int effectiveok = 0;
64583+ int fsok = 0;
64584+ uid_t globalreal, globaleffective, globalfs;
64585+
64586+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64587+ struct user_struct *user;
64588+
64589+ if (!uid_valid(real))
64590+ goto skipit;
64591+
64592+ /* find user based on global namespace */
64593+
64594+ globalreal = GR_GLOBAL_UID(real);
64595+
64596+ user = find_user(make_kuid(&init_user_ns, globalreal));
64597+ if (user == NULL)
64598+ goto skipit;
64599+
64600+ if (gr_process_kernel_setuid_ban(user)) {
64601+ /* for find_user */
64602+ free_uid(user);
64603+ return 1;
64604+ }
64605+
64606+ /* for find_user */
64607+ free_uid(user);
64608+
64609+skipit:
64610+#endif
64611+
64612+ if (unlikely(!(gr_status & GR_READY)))
64613+ return 0;
64614+
64615+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64616+ gr_log_learn_uid_change(real, effective, fs);
64617+
64618+ num = current->acl->user_trans_num;
64619+ uidlist = current->acl->user_transitions;
64620+
64621+ if (uidlist == NULL)
64622+ return 0;
64623+
64624+ if (!uid_valid(real)) {
64625+ realok = 1;
64626+ globalreal = (uid_t)-1;
64627+ } else {
64628+ globalreal = GR_GLOBAL_UID(real);
64629+ }
64630+ if (!uid_valid(effective)) {
64631+ effectiveok = 1;
64632+ globaleffective = (uid_t)-1;
64633+ } else {
64634+ globaleffective = GR_GLOBAL_UID(effective);
64635+ }
64636+ if (!uid_valid(fs)) {
64637+ fsok = 1;
64638+ globalfs = (uid_t)-1;
64639+ } else {
64640+ globalfs = GR_GLOBAL_UID(fs);
64641+ }
64642+
64643+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64644+ for (i = 0; i < num; i++) {
64645+ curuid = uidlist[i];
64646+ if (globalreal == curuid)
64647+ realok = 1;
64648+ if (globaleffective == curuid)
64649+ effectiveok = 1;
64650+ if (globalfs == curuid)
64651+ fsok = 1;
64652+ }
64653+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64654+ for (i = 0; i < num; i++) {
64655+ curuid = uidlist[i];
64656+ if (globalreal == curuid)
64657+ break;
64658+ if (globaleffective == curuid)
64659+ break;
64660+ if (globalfs == curuid)
64661+ break;
64662+ }
64663+ /* not in deny list */
64664+ if (i == num) {
64665+ realok = 1;
64666+ effectiveok = 1;
64667+ fsok = 1;
64668+ }
64669+ }
64670+
64671+ if (realok && effectiveok && fsok)
64672+ return 0;
64673+ else {
64674+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64675+ return 1;
64676+ }
64677+}
64678+
64679+int
64680+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64681+{
64682+ unsigned int i;
64683+ __u16 num;
64684+ gid_t *gidlist;
64685+ gid_t curgid;
64686+ int realok = 0;
64687+ int effectiveok = 0;
64688+ int fsok = 0;
64689+ gid_t globalreal, globaleffective, globalfs;
64690+
64691+ if (unlikely(!(gr_status & GR_READY)))
64692+ return 0;
64693+
64694+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64695+ gr_log_learn_gid_change(real, effective, fs);
64696+
64697+ num = current->acl->group_trans_num;
64698+ gidlist = current->acl->group_transitions;
64699+
64700+ if (gidlist == NULL)
64701+ return 0;
64702+
64703+ if (!gid_valid(real)) {
64704+ realok = 1;
64705+ globalreal = (gid_t)-1;
64706+ } else {
64707+ globalreal = GR_GLOBAL_GID(real);
64708+ }
64709+ if (!gid_valid(effective)) {
64710+ effectiveok = 1;
64711+ globaleffective = (gid_t)-1;
64712+ } else {
64713+ globaleffective = GR_GLOBAL_GID(effective);
64714+ }
64715+ if (!gid_valid(fs)) {
64716+ fsok = 1;
64717+ globalfs = (gid_t)-1;
64718+ } else {
64719+ globalfs = GR_GLOBAL_GID(fs);
64720+ }
64721+
64722+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64723+ for (i = 0; i < num; i++) {
64724+ curgid = gidlist[i];
64725+ if (globalreal == curgid)
64726+ realok = 1;
64727+ if (globaleffective == curgid)
64728+ effectiveok = 1;
64729+ if (globalfs == curgid)
64730+ fsok = 1;
64731+ }
64732+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64733+ for (i = 0; i < num; i++) {
64734+ curgid = gidlist[i];
64735+ if (globalreal == curgid)
64736+ break;
64737+ if (globaleffective == curgid)
64738+ break;
64739+ if (globalfs == curgid)
64740+ break;
64741+ }
64742+ /* not in deny list */
64743+ if (i == num) {
64744+ realok = 1;
64745+ effectiveok = 1;
64746+ fsok = 1;
64747+ }
64748+ }
64749+
64750+ if (realok && effectiveok && fsok)
64751+ return 0;
64752+ else {
64753+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64754+ return 1;
64755+ }
64756+}
64757+
64758+extern int gr_acl_is_capable(const int cap);
64759+
64760+void
64761+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64762+{
64763+ struct acl_role_label *role = task->role;
64764+ struct acl_subject_label *subj = NULL;
64765+ struct acl_object_label *obj;
64766+ struct file *filp;
64767+ uid_t uid;
64768+ gid_t gid;
64769+
64770+ if (unlikely(!(gr_status & GR_READY)))
64771+ return;
64772+
64773+ uid = GR_GLOBAL_UID(kuid);
64774+ gid = GR_GLOBAL_GID(kgid);
64775+
64776+ filp = task->exec_file;
64777+
64778+ /* kernel process, we'll give them the kernel role */
64779+ if (unlikely(!filp)) {
64780+ task->role = kernel_role;
64781+ task->acl = kernel_role->root_label;
64782+ return;
64783+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64784+ role = lookup_acl_role_label(task, uid, gid);
64785+
64786+ /* don't change the role if we're not a privileged process */
64787+ if (role && task->role != role &&
64788+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64789+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64790+ return;
64791+
64792+ /* perform subject lookup in possibly new role
64793+ we can use this result below in the case where role == task->role
64794+ */
64795+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64796+
64797+ /* if we changed uid/gid, but result in the same role
64798+ and are using inheritance, don't lose the inherited subject
64799+ if current subject is other than what normal lookup
64800+ would result in, we arrived via inheritance, don't
64801+ lose subject
64802+ */
64803+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64804+ (subj == task->acl)))
64805+ task->acl = subj;
64806+
64807+ task->role = role;
64808+
64809+ task->is_writable = 0;
64810+
64811+ /* ignore additional mmap checks for processes that are writable
64812+ by the default ACL */
64813+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64814+ if (unlikely(obj->mode & GR_WRITE))
64815+ task->is_writable = 1;
64816+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64817+ if (unlikely(obj->mode & GR_WRITE))
64818+ task->is_writable = 1;
64819+
64820+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64821+ 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);
64822+#endif
64823+
64824+ gr_set_proc_res(task);
64825+
64826+ return;
64827+}
64828+
64829+int
64830+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64831+ const int unsafe_flags)
64832+{
64833+ struct task_struct *task = current;
64834+ struct acl_subject_label *newacl;
64835+ struct acl_object_label *obj;
64836+ __u32 retmode;
64837+
64838+ if (unlikely(!(gr_status & GR_READY)))
64839+ return 0;
64840+
64841+ newacl = chk_subj_label(dentry, mnt, task->role);
64842+
64843+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64844+ did an exec
64845+ */
64846+ rcu_read_lock();
64847+ read_lock(&tasklist_lock);
64848+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64849+ (task->parent->acl->mode & GR_POVERRIDE))) {
64850+ read_unlock(&tasklist_lock);
64851+ rcu_read_unlock();
64852+ goto skip_check;
64853+ }
64854+ read_unlock(&tasklist_lock);
64855+ rcu_read_unlock();
64856+
64857+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64858+ !(task->role->roletype & GR_ROLE_GOD) &&
64859+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64860+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64861+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64862+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64863+ else
64864+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64865+ return -EACCES;
64866+ }
64867+
64868+skip_check:
64869+
64870+ obj = chk_obj_label(dentry, mnt, task->acl);
64871+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64872+
64873+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64874+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64875+ if (obj->nested)
64876+ task->acl = obj->nested;
64877+ else
64878+ task->acl = newacl;
64879+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64880+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64881+
64882+ task->is_writable = 0;
64883+
64884+ /* ignore additional mmap checks for processes that are writable
64885+ by the default ACL */
64886+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64887+ if (unlikely(obj->mode & GR_WRITE))
64888+ task->is_writable = 1;
64889+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64890+ if (unlikely(obj->mode & GR_WRITE))
64891+ task->is_writable = 1;
64892+
64893+ gr_set_proc_res(task);
64894+
64895+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64896+ 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);
64897+#endif
64898+ return 0;
64899+}
64900+
64901+/* always called with valid inodev ptr */
64902+static void
64903+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64904+{
64905+ struct acl_object_label *matchpo;
64906+ struct acl_subject_label *matchps;
64907+ struct acl_subject_label *subj;
64908+ struct acl_role_label *role;
64909+ unsigned int x;
64910+
64911+ FOR_EACH_ROLE_START(role)
64912+ FOR_EACH_SUBJECT_START(role, subj, x)
64913+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64914+ matchpo->mode |= GR_DELETED;
64915+ FOR_EACH_SUBJECT_END(subj,x)
64916+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64917+ /* nested subjects aren't in the role's subj_hash table */
64918+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64919+ matchpo->mode |= GR_DELETED;
64920+ FOR_EACH_NESTED_SUBJECT_END(subj)
64921+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64922+ matchps->mode |= GR_DELETED;
64923+ FOR_EACH_ROLE_END(role)
64924+
64925+ inodev->nentry->deleted = 1;
64926+
64927+ return;
64928+}
64929+
64930+void
64931+gr_handle_delete(const ino_t ino, const dev_t dev)
64932+{
64933+ struct inodev_entry *inodev;
64934+
64935+ if (unlikely(!(gr_status & GR_READY)))
64936+ return;
64937+
64938+ write_lock(&gr_inode_lock);
64939+ inodev = lookup_inodev_entry(ino, dev);
64940+ if (inodev != NULL)
64941+ do_handle_delete(inodev, ino, dev);
64942+ write_unlock(&gr_inode_lock);
64943+
64944+ return;
64945+}
64946+
64947+static void
64948+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64949+ const ino_t newinode, const dev_t newdevice,
64950+ struct acl_subject_label *subj)
64951+{
64952+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64953+ struct acl_object_label *match;
64954+
64955+ match = subj->obj_hash[index];
64956+
64957+ while (match && (match->inode != oldinode ||
64958+ match->device != olddevice ||
64959+ !(match->mode & GR_DELETED)))
64960+ match = match->next;
64961+
64962+ if (match && (match->inode == oldinode)
64963+ && (match->device == olddevice)
64964+ && (match->mode & GR_DELETED)) {
64965+ if (match->prev == NULL) {
64966+ subj->obj_hash[index] = match->next;
64967+ if (match->next != NULL)
64968+ match->next->prev = NULL;
64969+ } else {
64970+ match->prev->next = match->next;
64971+ if (match->next != NULL)
64972+ match->next->prev = match->prev;
64973+ }
64974+ match->prev = NULL;
64975+ match->next = NULL;
64976+ match->inode = newinode;
64977+ match->device = newdevice;
64978+ match->mode &= ~GR_DELETED;
64979+
64980+ insert_acl_obj_label(match, subj);
64981+ }
64982+
64983+ return;
64984+}
64985+
64986+static void
64987+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64988+ const ino_t newinode, const dev_t newdevice,
64989+ struct acl_role_label *role)
64990+{
64991+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64992+ struct acl_subject_label *match;
64993+
64994+ match = role->subj_hash[index];
64995+
64996+ while (match && (match->inode != oldinode ||
64997+ match->device != olddevice ||
64998+ !(match->mode & GR_DELETED)))
64999+ match = match->next;
65000+
65001+ if (match && (match->inode == oldinode)
65002+ && (match->device == olddevice)
65003+ && (match->mode & GR_DELETED)) {
65004+ if (match->prev == NULL) {
65005+ role->subj_hash[index] = match->next;
65006+ if (match->next != NULL)
65007+ match->next->prev = NULL;
65008+ } else {
65009+ match->prev->next = match->next;
65010+ if (match->next != NULL)
65011+ match->next->prev = match->prev;
65012+ }
65013+ match->prev = NULL;
65014+ match->next = NULL;
65015+ match->inode = newinode;
65016+ match->device = newdevice;
65017+ match->mode &= ~GR_DELETED;
65018+
65019+ insert_acl_subj_label(match, role);
65020+ }
65021+
65022+ return;
65023+}
65024+
65025+static void
65026+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65027+ const ino_t newinode, const dev_t newdevice)
65028+{
65029+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65030+ struct inodev_entry *match;
65031+
65032+ match = inodev_set.i_hash[index];
65033+
65034+ while (match && (match->nentry->inode != oldinode ||
65035+ match->nentry->device != olddevice || !match->nentry->deleted))
65036+ match = match->next;
65037+
65038+ if (match && (match->nentry->inode == oldinode)
65039+ && (match->nentry->device == olddevice) &&
65040+ match->nentry->deleted) {
65041+ if (match->prev == NULL) {
65042+ inodev_set.i_hash[index] = match->next;
65043+ if (match->next != NULL)
65044+ match->next->prev = NULL;
65045+ } else {
65046+ match->prev->next = match->next;
65047+ if (match->next != NULL)
65048+ match->next->prev = match->prev;
65049+ }
65050+ match->prev = NULL;
65051+ match->next = NULL;
65052+ match->nentry->inode = newinode;
65053+ match->nentry->device = newdevice;
65054+ match->nentry->deleted = 0;
65055+
65056+ insert_inodev_entry(match);
65057+ }
65058+
65059+ return;
65060+}
65061+
65062+static void
65063+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65064+{
65065+ struct acl_subject_label *subj;
65066+ struct acl_role_label *role;
65067+ unsigned int x;
65068+
65069+ FOR_EACH_ROLE_START(role)
65070+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65071+
65072+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65073+ if ((subj->inode == ino) && (subj->device == dev)) {
65074+ subj->inode = ino;
65075+ subj->device = dev;
65076+ }
65077+ /* nested subjects aren't in the role's subj_hash table */
65078+ update_acl_obj_label(matchn->inode, matchn->device,
65079+ ino, dev, subj);
65080+ FOR_EACH_NESTED_SUBJECT_END(subj)
65081+ FOR_EACH_SUBJECT_START(role, subj, x)
65082+ update_acl_obj_label(matchn->inode, matchn->device,
65083+ ino, dev, subj);
65084+ FOR_EACH_SUBJECT_END(subj,x)
65085+ FOR_EACH_ROLE_END(role)
65086+
65087+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65088+
65089+ return;
65090+}
65091+
65092+static void
65093+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65094+ const struct vfsmount *mnt)
65095+{
65096+ ino_t ino = dentry->d_inode->i_ino;
65097+ dev_t dev = __get_dev(dentry);
65098+
65099+ __do_handle_create(matchn, ino, dev);
65100+
65101+ return;
65102+}
65103+
65104+void
65105+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65106+{
65107+ struct name_entry *matchn;
65108+
65109+ if (unlikely(!(gr_status & GR_READY)))
65110+ return;
65111+
65112+ preempt_disable();
65113+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65114+
65115+ if (unlikely((unsigned long)matchn)) {
65116+ write_lock(&gr_inode_lock);
65117+ do_handle_create(matchn, dentry, mnt);
65118+ write_unlock(&gr_inode_lock);
65119+ }
65120+ preempt_enable();
65121+
65122+ return;
65123+}
65124+
65125+void
65126+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65127+{
65128+ struct name_entry *matchn;
65129+
65130+ if (unlikely(!(gr_status & GR_READY)))
65131+ return;
65132+
65133+ preempt_disable();
65134+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65135+
65136+ if (unlikely((unsigned long)matchn)) {
65137+ write_lock(&gr_inode_lock);
65138+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65139+ write_unlock(&gr_inode_lock);
65140+ }
65141+ preempt_enable();
65142+
65143+ return;
65144+}
65145+
65146+void
65147+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65148+ struct dentry *old_dentry,
65149+ struct dentry *new_dentry,
65150+ struct vfsmount *mnt, const __u8 replace)
65151+{
65152+ struct name_entry *matchn;
65153+ struct inodev_entry *inodev;
65154+ struct inode *inode = new_dentry->d_inode;
65155+ ino_t old_ino = old_dentry->d_inode->i_ino;
65156+ dev_t old_dev = __get_dev(old_dentry);
65157+
65158+ /* vfs_rename swaps the name and parent link for old_dentry and
65159+ new_dentry
65160+ at this point, old_dentry has the new name, parent link, and inode
65161+ for the renamed file
65162+ if a file is being replaced by a rename, new_dentry has the inode
65163+ and name for the replaced file
65164+ */
65165+
65166+ if (unlikely(!(gr_status & GR_READY)))
65167+ return;
65168+
65169+ preempt_disable();
65170+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65171+
65172+ /* we wouldn't have to check d_inode if it weren't for
65173+ NFS silly-renaming
65174+ */
65175+
65176+ write_lock(&gr_inode_lock);
65177+ if (unlikely(replace && inode)) {
65178+ ino_t new_ino = inode->i_ino;
65179+ dev_t new_dev = __get_dev(new_dentry);
65180+
65181+ inodev = lookup_inodev_entry(new_ino, new_dev);
65182+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65183+ do_handle_delete(inodev, new_ino, new_dev);
65184+ }
65185+
65186+ inodev = lookup_inodev_entry(old_ino, old_dev);
65187+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65188+ do_handle_delete(inodev, old_ino, old_dev);
65189+
65190+ if (unlikely((unsigned long)matchn))
65191+ do_handle_create(matchn, old_dentry, mnt);
65192+
65193+ write_unlock(&gr_inode_lock);
65194+ preempt_enable();
65195+
65196+ return;
65197+}
65198+
65199+static int
65200+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65201+ unsigned char **sum)
65202+{
65203+ struct acl_role_label *r;
65204+ struct role_allowed_ip *ipp;
65205+ struct role_transition *trans;
65206+ unsigned int i;
65207+ int found = 0;
65208+ u32 curr_ip = current->signal->curr_ip;
65209+
65210+ current->signal->saved_ip = curr_ip;
65211+
65212+ /* check transition table */
65213+
65214+ for (trans = current->role->transitions; trans; trans = trans->next) {
65215+ if (!strcmp(rolename, trans->rolename)) {
65216+ found = 1;
65217+ break;
65218+ }
65219+ }
65220+
65221+ if (!found)
65222+ return 0;
65223+
65224+ /* handle special roles that do not require authentication
65225+ and check ip */
65226+
65227+ FOR_EACH_ROLE_START(r)
65228+ if (!strcmp(rolename, r->rolename) &&
65229+ (r->roletype & GR_ROLE_SPECIAL)) {
65230+ found = 0;
65231+ if (r->allowed_ips != NULL) {
65232+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65233+ if ((ntohl(curr_ip) & ipp->netmask) ==
65234+ (ntohl(ipp->addr) & ipp->netmask))
65235+ found = 1;
65236+ }
65237+ } else
65238+ found = 2;
65239+ if (!found)
65240+ return 0;
65241+
65242+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65243+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65244+ *salt = NULL;
65245+ *sum = NULL;
65246+ return 1;
65247+ }
65248+ }
65249+ FOR_EACH_ROLE_END(r)
65250+
65251+ for (i = 0; i < num_sprole_pws; i++) {
65252+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65253+ *salt = acl_special_roles[i]->salt;
65254+ *sum = acl_special_roles[i]->sum;
65255+ return 1;
65256+ }
65257+ }
65258+
65259+ return 0;
65260+}
65261+
65262+static void
65263+assign_special_role(char *rolename)
65264+{
65265+ struct acl_object_label *obj;
65266+ struct acl_role_label *r;
65267+ struct acl_role_label *assigned = NULL;
65268+ struct task_struct *tsk;
65269+ struct file *filp;
65270+
65271+ FOR_EACH_ROLE_START(r)
65272+ if (!strcmp(rolename, r->rolename) &&
65273+ (r->roletype & GR_ROLE_SPECIAL)) {
65274+ assigned = r;
65275+ break;
65276+ }
65277+ FOR_EACH_ROLE_END(r)
65278+
65279+ if (!assigned)
65280+ return;
65281+
65282+ read_lock(&tasklist_lock);
65283+ read_lock(&grsec_exec_file_lock);
65284+
65285+ tsk = current->real_parent;
65286+ if (tsk == NULL)
65287+ goto out_unlock;
65288+
65289+ filp = tsk->exec_file;
65290+ if (filp == NULL)
65291+ goto out_unlock;
65292+
65293+ tsk->is_writable = 0;
65294+
65295+ tsk->acl_sp_role = 1;
65296+ tsk->acl_role_id = ++acl_sp_role_value;
65297+ tsk->role = assigned;
65298+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65299+
65300+ /* ignore additional mmap checks for processes that are writable
65301+ by the default ACL */
65302+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65303+ if (unlikely(obj->mode & GR_WRITE))
65304+ tsk->is_writable = 1;
65305+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65306+ if (unlikely(obj->mode & GR_WRITE))
65307+ tsk->is_writable = 1;
65308+
65309+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65310+ 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));
65311+#endif
65312+
65313+out_unlock:
65314+ read_unlock(&grsec_exec_file_lock);
65315+ read_unlock(&tasklist_lock);
65316+ return;
65317+}
65318+
65319+int gr_check_secure_terminal(struct task_struct *task)
65320+{
65321+ struct task_struct *p, *p2, *p3;
65322+ struct files_struct *files;
65323+ struct fdtable *fdt;
65324+ struct file *our_file = NULL, *file;
65325+ int i;
65326+
65327+ if (task->signal->tty == NULL)
65328+ return 1;
65329+
65330+ files = get_files_struct(task);
65331+ if (files != NULL) {
65332+ rcu_read_lock();
65333+ fdt = files_fdtable(files);
65334+ for (i=0; i < fdt->max_fds; i++) {
65335+ file = fcheck_files(files, i);
65336+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65337+ get_file(file);
65338+ our_file = file;
65339+ }
65340+ }
65341+ rcu_read_unlock();
65342+ put_files_struct(files);
65343+ }
65344+
65345+ if (our_file == NULL)
65346+ return 1;
65347+
65348+ read_lock(&tasklist_lock);
65349+ do_each_thread(p2, p) {
65350+ files = get_files_struct(p);
65351+ if (files == NULL ||
65352+ (p->signal && p->signal->tty == task->signal->tty)) {
65353+ if (files != NULL)
65354+ put_files_struct(files);
65355+ continue;
65356+ }
65357+ rcu_read_lock();
65358+ fdt = files_fdtable(files);
65359+ for (i=0; i < fdt->max_fds; i++) {
65360+ file = fcheck_files(files, i);
65361+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65362+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65363+ p3 = task;
65364+ while (task_pid_nr(p3) > 0) {
65365+ if (p3 == p)
65366+ break;
65367+ p3 = p3->real_parent;
65368+ }
65369+ if (p3 == p)
65370+ break;
65371+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65372+ gr_handle_alertkill(p);
65373+ rcu_read_unlock();
65374+ put_files_struct(files);
65375+ read_unlock(&tasklist_lock);
65376+ fput(our_file);
65377+ return 0;
65378+ }
65379+ }
65380+ rcu_read_unlock();
65381+ put_files_struct(files);
65382+ } while_each_thread(p2, p);
65383+ read_unlock(&tasklist_lock);
65384+
65385+ fput(our_file);
65386+ return 1;
65387+}
65388+
65389+static int gr_rbac_disable(void *unused)
65390+{
65391+ pax_open_kernel();
65392+ gr_status &= ~GR_READY;
65393+ pax_close_kernel();
65394+
65395+ return 0;
65396+}
65397+
65398+ssize_t
65399+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65400+{
65401+ struct gr_arg_wrapper uwrap;
65402+ unsigned char *sprole_salt = NULL;
65403+ unsigned char *sprole_sum = NULL;
65404+ int error = 0;
65405+ int error2 = 0;
65406+ size_t req_count = 0;
65407+
65408+ mutex_lock(&gr_dev_mutex);
65409+
65410+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65411+ error = -EPERM;
65412+ goto out;
65413+ }
65414+
65415+#ifdef CONFIG_COMPAT
65416+ pax_open_kernel();
65417+ if (is_compat_task()) {
65418+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65419+ copy_gr_arg = &copy_gr_arg_compat;
65420+ copy_acl_object_label = &copy_acl_object_label_compat;
65421+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65422+ copy_acl_role_label = &copy_acl_role_label_compat;
65423+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65424+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65425+ copy_role_transition = &copy_role_transition_compat;
65426+ copy_sprole_pw = &copy_sprole_pw_compat;
65427+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65428+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65429+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65430+ } else {
65431+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65432+ copy_gr_arg = &copy_gr_arg_normal;
65433+ copy_acl_object_label = &copy_acl_object_label_normal;
65434+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65435+ copy_acl_role_label = &copy_acl_role_label_normal;
65436+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65437+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65438+ copy_role_transition = &copy_role_transition_normal;
65439+ copy_sprole_pw = &copy_sprole_pw_normal;
65440+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65441+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65442+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65443+ }
65444+ pax_close_kernel();
65445+#endif
65446+
65447+ req_count = get_gr_arg_wrapper_size();
65448+
65449+ if (count != req_count) {
65450+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65451+ error = -EINVAL;
65452+ goto out;
65453+ }
65454+
65455+
65456+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65457+ gr_auth_expires = 0;
65458+ gr_auth_attempts = 0;
65459+ }
65460+
65461+ error = copy_gr_arg_wrapper(buf, &uwrap);
65462+ if (error)
65463+ goto out;
65464+
65465+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65466+ if (error)
65467+ goto out;
65468+
65469+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65470+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65471+ time_after(gr_auth_expires, get_seconds())) {
65472+ error = -EBUSY;
65473+ goto out;
65474+ }
65475+
65476+ /* if non-root trying to do anything other than use a special role,
65477+ do not attempt authentication, do not count towards authentication
65478+ locking
65479+ */
65480+
65481+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65482+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65483+ gr_is_global_nonroot(current_uid())) {
65484+ error = -EPERM;
65485+ goto out;
65486+ }
65487+
65488+ /* ensure pw and special role name are null terminated */
65489+
65490+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65491+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65492+
65493+ /* Okay.
65494+ * We have our enough of the argument structure..(we have yet
65495+ * to copy_from_user the tables themselves) . Copy the tables
65496+ * only if we need them, i.e. for loading operations. */
65497+
65498+ switch (gr_usermode->mode) {
65499+ case GR_STATUS:
65500+ if (gr_status & GR_READY) {
65501+ error = 1;
65502+ if (!gr_check_secure_terminal(current))
65503+ error = 3;
65504+ } else
65505+ error = 2;
65506+ goto out;
65507+ case GR_SHUTDOWN:
65508+ if ((gr_status & GR_READY)
65509+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65510+ stop_machine(gr_rbac_disable, NULL, NULL);
65511+ free_variables();
65512+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65513+ memset(gr_system_salt, 0, GR_SALT_LEN);
65514+ memset(gr_system_sum, 0, GR_SHA_LEN);
65515+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65516+ } else if (gr_status & GR_READY) {
65517+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65518+ error = -EPERM;
65519+ } else {
65520+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65521+ error = -EAGAIN;
65522+ }
65523+ break;
65524+ case GR_ENABLE:
65525+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65526+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65527+ else {
65528+ if (gr_status & GR_READY)
65529+ error = -EAGAIN;
65530+ else
65531+ error = error2;
65532+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65533+ }
65534+ break;
65535+ case GR_RELOAD:
65536+ if (!(gr_status & GR_READY)) {
65537+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65538+ error = -EAGAIN;
65539+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65540+ stop_machine(gr_rbac_disable, NULL, NULL);
65541+ free_variables();
65542+ error2 = gracl_init(gr_usermode);
65543+ if (!error2)
65544+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65545+ else {
65546+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65547+ error = error2;
65548+ }
65549+ } else {
65550+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65551+ error = -EPERM;
65552+ }
65553+ break;
65554+ case GR_SEGVMOD:
65555+ if (unlikely(!(gr_status & GR_READY))) {
65556+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65557+ error = -EAGAIN;
65558+ break;
65559+ }
65560+
65561+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65562+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65563+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65564+ struct acl_subject_label *segvacl;
65565+ segvacl =
65566+ lookup_acl_subj_label(gr_usermode->segv_inode,
65567+ gr_usermode->segv_device,
65568+ current->role);
65569+ if (segvacl) {
65570+ segvacl->crashes = 0;
65571+ segvacl->expires = 0;
65572+ }
65573+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65574+ gr_remove_uid(gr_usermode->segv_uid);
65575+ }
65576+ } else {
65577+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65578+ error = -EPERM;
65579+ }
65580+ break;
65581+ case GR_SPROLE:
65582+ case GR_SPROLEPAM:
65583+ if (unlikely(!(gr_status & GR_READY))) {
65584+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65585+ error = -EAGAIN;
65586+ break;
65587+ }
65588+
65589+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65590+ current->role->expires = 0;
65591+ current->role->auth_attempts = 0;
65592+ }
65593+
65594+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65595+ time_after(current->role->expires, get_seconds())) {
65596+ error = -EBUSY;
65597+ goto out;
65598+ }
65599+
65600+ if (lookup_special_role_auth
65601+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65602+ && ((!sprole_salt && !sprole_sum)
65603+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65604+ char *p = "";
65605+ assign_special_role(gr_usermode->sp_role);
65606+ read_lock(&tasklist_lock);
65607+ if (current->real_parent)
65608+ p = current->real_parent->role->rolename;
65609+ read_unlock(&tasklist_lock);
65610+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65611+ p, acl_sp_role_value);
65612+ } else {
65613+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65614+ error = -EPERM;
65615+ if(!(current->role->auth_attempts++))
65616+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65617+
65618+ goto out;
65619+ }
65620+ break;
65621+ case GR_UNSPROLE:
65622+ if (unlikely(!(gr_status & GR_READY))) {
65623+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65624+ error = -EAGAIN;
65625+ break;
65626+ }
65627+
65628+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65629+ char *p = "";
65630+ int i = 0;
65631+
65632+ read_lock(&tasklist_lock);
65633+ if (current->real_parent) {
65634+ p = current->real_parent->role->rolename;
65635+ i = current->real_parent->acl_role_id;
65636+ }
65637+ read_unlock(&tasklist_lock);
65638+
65639+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65640+ gr_set_acls(1);
65641+ } else {
65642+ error = -EPERM;
65643+ goto out;
65644+ }
65645+ break;
65646+ default:
65647+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65648+ error = -EINVAL;
65649+ break;
65650+ }
65651+
65652+ if (error != -EPERM)
65653+ goto out;
65654+
65655+ if(!(gr_auth_attempts++))
65656+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65657+
65658+ out:
65659+ mutex_unlock(&gr_dev_mutex);
65660+
65661+ if (!error)
65662+ error = req_count;
65663+
65664+ return error;
65665+}
65666+
65667+/* must be called with
65668+ rcu_read_lock();
65669+ read_lock(&tasklist_lock);
65670+ read_lock(&grsec_exec_file_lock);
65671+*/
65672+int gr_apply_subject_to_task(struct task_struct *task)
65673+{
65674+ struct acl_object_label *obj;
65675+ char *tmpname;
65676+ struct acl_subject_label *tmpsubj;
65677+ struct file *filp;
65678+ struct name_entry *nmatch;
65679+
65680+ filp = task->exec_file;
65681+ if (filp == NULL)
65682+ return 0;
65683+
65684+ /* the following is to apply the correct subject
65685+ on binaries running when the RBAC system
65686+ is enabled, when the binaries have been
65687+ replaced or deleted since their execution
65688+ -----
65689+ when the RBAC system starts, the inode/dev
65690+ from exec_file will be one the RBAC system
65691+ is unaware of. It only knows the inode/dev
65692+ of the present file on disk, or the absence
65693+ of it.
65694+ */
65695+ preempt_disable();
65696+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65697+
65698+ nmatch = lookup_name_entry(tmpname);
65699+ preempt_enable();
65700+ tmpsubj = NULL;
65701+ if (nmatch) {
65702+ if (nmatch->deleted)
65703+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65704+ else
65705+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65706+ if (tmpsubj != NULL)
65707+ task->acl = tmpsubj;
65708+ }
65709+ if (tmpsubj == NULL)
65710+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65711+ task->role);
65712+ if (task->acl) {
65713+ task->is_writable = 0;
65714+ /* ignore additional mmap checks for processes that are writable
65715+ by the default ACL */
65716+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65717+ if (unlikely(obj->mode & GR_WRITE))
65718+ task->is_writable = 1;
65719+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65720+ if (unlikely(obj->mode & GR_WRITE))
65721+ task->is_writable = 1;
65722+
65723+ gr_set_proc_res(task);
65724+
65725+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65726+ 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);
65727+#endif
65728+ } else {
65729+ return 1;
65730+ }
65731+
65732+ return 0;
65733+}
65734+
65735+int
65736+gr_set_acls(const int type)
65737+{
65738+ struct task_struct *task, *task2;
65739+ struct acl_role_label *role = current->role;
65740+ __u16 acl_role_id = current->acl_role_id;
65741+ const struct cred *cred;
65742+ int ret;
65743+
65744+ rcu_read_lock();
65745+ read_lock(&tasklist_lock);
65746+ read_lock(&grsec_exec_file_lock);
65747+ do_each_thread(task2, task) {
65748+ /* check to see if we're called from the exit handler,
65749+ if so, only replace ACLs that have inherited the admin
65750+ ACL */
65751+
65752+ if (type && (task->role != role ||
65753+ task->acl_role_id != acl_role_id))
65754+ continue;
65755+
65756+ task->acl_role_id = 0;
65757+ task->acl_sp_role = 0;
65758+
65759+ if (task->exec_file) {
65760+ cred = __task_cred(task);
65761+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65762+ ret = gr_apply_subject_to_task(task);
65763+ if (ret) {
65764+ read_unlock(&grsec_exec_file_lock);
65765+ read_unlock(&tasklist_lock);
65766+ rcu_read_unlock();
65767+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65768+ return ret;
65769+ }
65770+ } else {
65771+ // it's a kernel process
65772+ task->role = kernel_role;
65773+ task->acl = kernel_role->root_label;
65774+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65775+ task->acl->mode &= ~GR_PROCFIND;
65776+#endif
65777+ }
65778+ } while_each_thread(task2, task);
65779+ read_unlock(&grsec_exec_file_lock);
65780+ read_unlock(&tasklist_lock);
65781+ rcu_read_unlock();
65782+
65783+ return 0;
65784+}
65785+
65786+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65787+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65788+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65789+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65790+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65791+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65792+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65793+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65794+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65795+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65796+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65797+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65798+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65799+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65800+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65801+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65802+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65803+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65804+};
65805+
65806+void
65807+gr_learn_resource(const struct task_struct *task,
65808+ const int res, const unsigned long wanted, const int gt)
65809+{
65810+ struct acl_subject_label *acl;
65811+ const struct cred *cred;
65812+
65813+ if (unlikely((gr_status & GR_READY) &&
65814+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65815+ goto skip_reslog;
65816+
65817+ gr_log_resource(task, res, wanted, gt);
65818+skip_reslog:
65819+
65820+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65821+ return;
65822+
65823+ acl = task->acl;
65824+
65825+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65826+ !(acl->resmask & (1U << (unsigned short) res))))
65827+ return;
65828+
65829+ if (wanted >= acl->res[res].rlim_cur) {
65830+ unsigned long res_add;
65831+
65832+ res_add = wanted + res_learn_bumps[res];
65833+
65834+ acl->res[res].rlim_cur = res_add;
65835+
65836+ if (wanted > acl->res[res].rlim_max)
65837+ acl->res[res].rlim_max = res_add;
65838+
65839+ /* only log the subject filename, since resource logging is supported for
65840+ single-subject learning only */
65841+ rcu_read_lock();
65842+ cred = __task_cred(task);
65843+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65844+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65845+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65846+ "", (unsigned long) res, &task->signal->saved_ip);
65847+ rcu_read_unlock();
65848+ }
65849+
65850+ return;
65851+}
65852+EXPORT_SYMBOL(gr_learn_resource);
65853+#endif
65854+
65855+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65856+void
65857+pax_set_initial_flags(struct linux_binprm *bprm)
65858+{
65859+ struct task_struct *task = current;
65860+ struct acl_subject_label *proc;
65861+ unsigned long flags;
65862+
65863+ if (unlikely(!(gr_status & GR_READY)))
65864+ return;
65865+
65866+ flags = pax_get_flags(task);
65867+
65868+ proc = task->acl;
65869+
65870+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65871+ flags &= ~MF_PAX_PAGEEXEC;
65872+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65873+ flags &= ~MF_PAX_SEGMEXEC;
65874+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65875+ flags &= ~MF_PAX_RANDMMAP;
65876+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65877+ flags &= ~MF_PAX_EMUTRAMP;
65878+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65879+ flags &= ~MF_PAX_MPROTECT;
65880+
65881+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65882+ flags |= MF_PAX_PAGEEXEC;
65883+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65884+ flags |= MF_PAX_SEGMEXEC;
65885+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65886+ flags |= MF_PAX_RANDMMAP;
65887+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65888+ flags |= MF_PAX_EMUTRAMP;
65889+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65890+ flags |= MF_PAX_MPROTECT;
65891+
65892+ pax_set_flags(task, flags);
65893+
65894+ return;
65895+}
65896+#endif
65897+
65898+int
65899+gr_handle_proc_ptrace(struct task_struct *task)
65900+{
65901+ struct file *filp;
65902+ struct task_struct *tmp = task;
65903+ struct task_struct *curtemp = current;
65904+ __u32 retmode;
65905+
65906+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65907+ if (unlikely(!(gr_status & GR_READY)))
65908+ return 0;
65909+#endif
65910+
65911+ read_lock(&tasklist_lock);
65912+ read_lock(&grsec_exec_file_lock);
65913+ filp = task->exec_file;
65914+
65915+ while (task_pid_nr(tmp) > 0) {
65916+ if (tmp == curtemp)
65917+ break;
65918+ tmp = tmp->real_parent;
65919+ }
65920+
65921+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65922+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65923+ read_unlock(&grsec_exec_file_lock);
65924+ read_unlock(&tasklist_lock);
65925+ return 1;
65926+ }
65927+
65928+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65929+ if (!(gr_status & GR_READY)) {
65930+ read_unlock(&grsec_exec_file_lock);
65931+ read_unlock(&tasklist_lock);
65932+ return 0;
65933+ }
65934+#endif
65935+
65936+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65937+ read_unlock(&grsec_exec_file_lock);
65938+ read_unlock(&tasklist_lock);
65939+
65940+ if (retmode & GR_NOPTRACE)
65941+ return 1;
65942+
65943+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65944+ && (current->acl != task->acl || (current->acl != current->role->root_label
65945+ && task_pid_nr(current) != task_pid_nr(task))))
65946+ return 1;
65947+
65948+ return 0;
65949+}
65950+
65951+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65952+{
65953+ if (unlikely(!(gr_status & GR_READY)))
65954+ return;
65955+
65956+ if (!(current->role->roletype & GR_ROLE_GOD))
65957+ return;
65958+
65959+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65960+ p->role->rolename, gr_task_roletype_to_char(p),
65961+ p->acl->filename);
65962+}
65963+
65964+int
65965+gr_handle_ptrace(struct task_struct *task, const long request)
65966+{
65967+ struct task_struct *tmp = task;
65968+ struct task_struct *curtemp = current;
65969+ __u32 retmode;
65970+
65971+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65972+ if (unlikely(!(gr_status & GR_READY)))
65973+ return 0;
65974+#endif
65975+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65976+ read_lock(&tasklist_lock);
65977+ while (task_pid_nr(tmp) > 0) {
65978+ if (tmp == curtemp)
65979+ break;
65980+ tmp = tmp->real_parent;
65981+ }
65982+
65983+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65984+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65985+ read_unlock(&tasklist_lock);
65986+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65987+ return 1;
65988+ }
65989+ read_unlock(&tasklist_lock);
65990+ }
65991+
65992+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65993+ if (!(gr_status & GR_READY))
65994+ return 0;
65995+#endif
65996+
65997+ read_lock(&grsec_exec_file_lock);
65998+ if (unlikely(!task->exec_file)) {
65999+ read_unlock(&grsec_exec_file_lock);
66000+ return 0;
66001+ }
66002+
66003+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66004+ read_unlock(&grsec_exec_file_lock);
66005+
66006+ if (retmode & GR_NOPTRACE) {
66007+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66008+ return 1;
66009+ }
66010+
66011+ if (retmode & GR_PTRACERD) {
66012+ switch (request) {
66013+ case PTRACE_SEIZE:
66014+ case PTRACE_POKETEXT:
66015+ case PTRACE_POKEDATA:
66016+ case PTRACE_POKEUSR:
66017+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66018+ case PTRACE_SETREGS:
66019+ case PTRACE_SETFPREGS:
66020+#endif
66021+#ifdef CONFIG_X86
66022+ case PTRACE_SETFPXREGS:
66023+#endif
66024+#ifdef CONFIG_ALTIVEC
66025+ case PTRACE_SETVRREGS:
66026+#endif
66027+ return 1;
66028+ default:
66029+ return 0;
66030+ }
66031+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66032+ !(current->role->roletype & GR_ROLE_GOD) &&
66033+ (current->acl != task->acl)) {
66034+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66035+ return 1;
66036+ }
66037+
66038+ return 0;
66039+}
66040+
66041+static int is_writable_mmap(const struct file *filp)
66042+{
66043+ struct task_struct *task = current;
66044+ struct acl_object_label *obj, *obj2;
66045+
66046+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66047+ !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))) {
66048+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66049+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66050+ task->role->root_label);
66051+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66052+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66053+ return 1;
66054+ }
66055+ }
66056+ return 0;
66057+}
66058+
66059+int
66060+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66061+{
66062+ __u32 mode;
66063+
66064+ if (unlikely(!file || !(prot & PROT_EXEC)))
66065+ return 1;
66066+
66067+ if (is_writable_mmap(file))
66068+ return 0;
66069+
66070+ mode =
66071+ gr_search_file(file->f_path.dentry,
66072+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66073+ file->f_path.mnt);
66074+
66075+ if (!gr_tpe_allow(file))
66076+ return 0;
66077+
66078+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66079+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66080+ return 0;
66081+ } else if (unlikely(!(mode & GR_EXEC))) {
66082+ return 0;
66083+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66084+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66085+ return 1;
66086+ }
66087+
66088+ return 1;
66089+}
66090+
66091+int
66092+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66093+{
66094+ __u32 mode;
66095+
66096+ if (unlikely(!file || !(prot & PROT_EXEC)))
66097+ return 1;
66098+
66099+ if (is_writable_mmap(file))
66100+ return 0;
66101+
66102+ mode =
66103+ gr_search_file(file->f_path.dentry,
66104+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66105+ file->f_path.mnt);
66106+
66107+ if (!gr_tpe_allow(file))
66108+ return 0;
66109+
66110+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66111+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66112+ return 0;
66113+ } else if (unlikely(!(mode & GR_EXEC))) {
66114+ return 0;
66115+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66116+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66117+ return 1;
66118+ }
66119+
66120+ return 1;
66121+}
66122+
66123+void
66124+gr_acl_handle_psacct(struct task_struct *task, const long code)
66125+{
66126+ unsigned long runtime;
66127+ unsigned long cputime;
66128+ unsigned int wday, cday;
66129+ __u8 whr, chr;
66130+ __u8 wmin, cmin;
66131+ __u8 wsec, csec;
66132+ struct timespec timeval;
66133+
66134+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66135+ !(task->acl->mode & GR_PROCACCT)))
66136+ return;
66137+
66138+ do_posix_clock_monotonic_gettime(&timeval);
66139+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66140+ wday = runtime / (3600 * 24);
66141+ runtime -= wday * (3600 * 24);
66142+ whr = runtime / 3600;
66143+ runtime -= whr * 3600;
66144+ wmin = runtime / 60;
66145+ runtime -= wmin * 60;
66146+ wsec = runtime;
66147+
66148+ cputime = (task->utime + task->stime) / HZ;
66149+ cday = cputime / (3600 * 24);
66150+ cputime -= cday * (3600 * 24);
66151+ chr = cputime / 3600;
66152+ cputime -= chr * 3600;
66153+ cmin = cputime / 60;
66154+ cputime -= cmin * 60;
66155+ csec = cputime;
66156+
66157+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66158+
66159+ return;
66160+}
66161+
66162+void gr_set_kernel_label(struct task_struct *task)
66163+{
66164+ if (gr_status & GR_READY) {
66165+ task->role = kernel_role;
66166+ task->acl = kernel_role->root_label;
66167+ }
66168+ return;
66169+}
66170+
66171+#ifdef CONFIG_TASKSTATS
66172+int gr_is_taskstats_denied(int pid)
66173+{
66174+ struct task_struct *task;
66175+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66176+ const struct cred *cred;
66177+#endif
66178+ int ret = 0;
66179+
66180+ /* restrict taskstats viewing to un-chrooted root users
66181+ who have the 'view' subject flag if the RBAC system is enabled
66182+ */
66183+
66184+ rcu_read_lock();
66185+ read_lock(&tasklist_lock);
66186+ task = find_task_by_vpid(pid);
66187+ if (task) {
66188+#ifdef CONFIG_GRKERNSEC_CHROOT
66189+ if (proc_is_chrooted(task))
66190+ ret = -EACCES;
66191+#endif
66192+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66193+ cred = __task_cred(task);
66194+#ifdef CONFIG_GRKERNSEC_PROC_USER
66195+ if (gr_is_global_nonroot(cred->uid))
66196+ ret = -EACCES;
66197+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66198+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66199+ ret = -EACCES;
66200+#endif
66201+#endif
66202+ if (gr_status & GR_READY) {
66203+ if (!(task->acl->mode & GR_VIEW))
66204+ ret = -EACCES;
66205+ }
66206+ } else
66207+ ret = -ENOENT;
66208+
66209+ read_unlock(&tasklist_lock);
66210+ rcu_read_unlock();
66211+
66212+ return ret;
66213+}
66214+#endif
66215+
66216+/* AUXV entries are filled via a descendant of search_binary_handler
66217+ after we've already applied the subject for the target
66218+*/
66219+int gr_acl_enable_at_secure(void)
66220+{
66221+ if (unlikely(!(gr_status & GR_READY)))
66222+ return 0;
66223+
66224+ if (current->acl->mode & GR_ATSECURE)
66225+ return 1;
66226+
66227+ return 0;
66228+}
66229+
66230+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66231+{
66232+ struct task_struct *task = current;
66233+ struct dentry *dentry = file->f_path.dentry;
66234+ struct vfsmount *mnt = file->f_path.mnt;
66235+ struct acl_object_label *obj, *tmp;
66236+ struct acl_subject_label *subj;
66237+ unsigned int bufsize;
66238+ int is_not_root;
66239+ char *path;
66240+ dev_t dev = __get_dev(dentry);
66241+
66242+ if (unlikely(!(gr_status & GR_READY)))
66243+ return 1;
66244+
66245+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66246+ return 1;
66247+
66248+ /* ignore Eric Biederman */
66249+ if (IS_PRIVATE(dentry->d_inode))
66250+ return 1;
66251+
66252+ subj = task->acl;
66253+ read_lock(&gr_inode_lock);
66254+ do {
66255+ obj = lookup_acl_obj_label(ino, dev, subj);
66256+ if (obj != NULL) {
66257+ read_unlock(&gr_inode_lock);
66258+ return (obj->mode & GR_FIND) ? 1 : 0;
66259+ }
66260+ } while ((subj = subj->parent_subject));
66261+ read_unlock(&gr_inode_lock);
66262+
66263+ /* this is purely an optimization since we're looking for an object
66264+ for the directory we're doing a readdir on
66265+ if it's possible for any globbed object to match the entry we're
66266+ filling into the directory, then the object we find here will be
66267+ an anchor point with attached globbed objects
66268+ */
66269+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66270+ if (obj->globbed == NULL)
66271+ return (obj->mode & GR_FIND) ? 1 : 0;
66272+
66273+ is_not_root = ((obj->filename[0] == '/') &&
66274+ (obj->filename[1] == '\0')) ? 0 : 1;
66275+ bufsize = PAGE_SIZE - namelen - is_not_root;
66276+
66277+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66278+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66279+ return 1;
66280+
66281+ preempt_disable();
66282+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66283+ bufsize);
66284+
66285+ bufsize = strlen(path);
66286+
66287+ /* if base is "/", don't append an additional slash */
66288+ if (is_not_root)
66289+ *(path + bufsize) = '/';
66290+ memcpy(path + bufsize + is_not_root, name, namelen);
66291+ *(path + bufsize + namelen + is_not_root) = '\0';
66292+
66293+ tmp = obj->globbed;
66294+ while (tmp) {
66295+ if (!glob_match(tmp->filename, path)) {
66296+ preempt_enable();
66297+ return (tmp->mode & GR_FIND) ? 1 : 0;
66298+ }
66299+ tmp = tmp->next;
66300+ }
66301+ preempt_enable();
66302+ return (obj->mode & GR_FIND) ? 1 : 0;
66303+}
66304+
66305+void gr_put_exec_file(struct task_struct *task)
66306+{
66307+ struct file *filp;
66308+
66309+ write_lock(&grsec_exec_file_lock);
66310+ filp = task->exec_file;
66311+ task->exec_file = NULL;
66312+ write_unlock(&grsec_exec_file_lock);
66313+
66314+ if (filp)
66315+ fput(filp);
66316+
66317+ return;
66318+}
66319+
66320+
66321+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66322+EXPORT_SYMBOL(gr_acl_is_enabled);
66323+#endif
66324+EXPORT_SYMBOL(gr_set_kernel_label);
66325+#ifdef CONFIG_SECURITY
66326+EXPORT_SYMBOL(gr_check_user_change);
66327+EXPORT_SYMBOL(gr_check_group_change);
66328+#endif
66329+
66330diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66331new file mode 100644
66332index 0000000..34fefda
66333--- /dev/null
66334+++ b/grsecurity/gracl_alloc.c
66335@@ -0,0 +1,105 @@
66336+#include <linux/kernel.h>
66337+#include <linux/mm.h>
66338+#include <linux/slab.h>
66339+#include <linux/vmalloc.h>
66340+#include <linux/gracl.h>
66341+#include <linux/grsecurity.h>
66342+
66343+static unsigned long alloc_stack_next = 1;
66344+static unsigned long alloc_stack_size = 1;
66345+static void **alloc_stack;
66346+
66347+static __inline__ int
66348+alloc_pop(void)
66349+{
66350+ if (alloc_stack_next == 1)
66351+ return 0;
66352+
66353+ kfree(alloc_stack[alloc_stack_next - 2]);
66354+
66355+ alloc_stack_next--;
66356+
66357+ return 1;
66358+}
66359+
66360+static __inline__ int
66361+alloc_push(void *buf)
66362+{
66363+ if (alloc_stack_next >= alloc_stack_size)
66364+ return 1;
66365+
66366+ alloc_stack[alloc_stack_next - 1] = buf;
66367+
66368+ alloc_stack_next++;
66369+
66370+ return 0;
66371+}
66372+
66373+void *
66374+acl_alloc(unsigned long len)
66375+{
66376+ void *ret = NULL;
66377+
66378+ if (!len || len > PAGE_SIZE)
66379+ goto out;
66380+
66381+ ret = kmalloc(len, GFP_KERNEL);
66382+
66383+ if (ret) {
66384+ if (alloc_push(ret)) {
66385+ kfree(ret);
66386+ ret = NULL;
66387+ }
66388+ }
66389+
66390+out:
66391+ return ret;
66392+}
66393+
66394+void *
66395+acl_alloc_num(unsigned long num, unsigned long len)
66396+{
66397+ if (!len || (num > (PAGE_SIZE / len)))
66398+ return NULL;
66399+
66400+ return acl_alloc(num * len);
66401+}
66402+
66403+void
66404+acl_free_all(void)
66405+{
66406+ if (gr_acl_is_enabled() || !alloc_stack)
66407+ return;
66408+
66409+ while (alloc_pop()) ;
66410+
66411+ if (alloc_stack) {
66412+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66413+ kfree(alloc_stack);
66414+ else
66415+ vfree(alloc_stack);
66416+ }
66417+
66418+ alloc_stack = NULL;
66419+ alloc_stack_size = 1;
66420+ alloc_stack_next = 1;
66421+
66422+ return;
66423+}
66424+
66425+int
66426+acl_alloc_stack_init(unsigned long size)
66427+{
66428+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66429+ alloc_stack =
66430+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66431+ else
66432+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66433+
66434+ alloc_stack_size = size;
66435+
66436+ if (!alloc_stack)
66437+ return 0;
66438+ else
66439+ return 1;
66440+}
66441diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66442new file mode 100644
66443index 0000000..bdd51ea
66444--- /dev/null
66445+++ b/grsecurity/gracl_cap.c
66446@@ -0,0 +1,110 @@
66447+#include <linux/kernel.h>
66448+#include <linux/module.h>
66449+#include <linux/sched.h>
66450+#include <linux/gracl.h>
66451+#include <linux/grsecurity.h>
66452+#include <linux/grinternal.h>
66453+
66454+extern const char *captab_log[];
66455+extern int captab_log_entries;
66456+
66457+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66458+{
66459+ struct acl_subject_label *curracl;
66460+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66461+ kernel_cap_t cap_audit = __cap_empty_set;
66462+
66463+ if (!gr_acl_is_enabled())
66464+ return 1;
66465+
66466+ curracl = task->acl;
66467+
66468+ cap_drop = curracl->cap_lower;
66469+ cap_mask = curracl->cap_mask;
66470+ cap_audit = curracl->cap_invert_audit;
66471+
66472+ while ((curracl = curracl->parent_subject)) {
66473+ /* if the cap isn't specified in the current computed mask but is specified in the
66474+ current level subject, and is lowered in the current level subject, then add
66475+ it to the set of dropped capabilities
66476+ otherwise, add the current level subject's mask to the current computed mask
66477+ */
66478+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66479+ cap_raise(cap_mask, cap);
66480+ if (cap_raised(curracl->cap_lower, cap))
66481+ cap_raise(cap_drop, cap);
66482+ if (cap_raised(curracl->cap_invert_audit, cap))
66483+ cap_raise(cap_audit, cap);
66484+ }
66485+ }
66486+
66487+ if (!cap_raised(cap_drop, cap)) {
66488+ if (cap_raised(cap_audit, cap))
66489+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66490+ return 1;
66491+ }
66492+
66493+ curracl = task->acl;
66494+
66495+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66496+ && cap_raised(cred->cap_effective, cap)) {
66497+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66498+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66499+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66500+ gr_to_filename(task->exec_file->f_path.dentry,
66501+ task->exec_file->f_path.mnt) : curracl->filename,
66502+ curracl->filename, 0UL,
66503+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66504+ return 1;
66505+ }
66506+
66507+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66508+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66509+
66510+ return 0;
66511+}
66512+
66513+int
66514+gr_acl_is_capable(const int cap)
66515+{
66516+ return gr_task_acl_is_capable(current, current_cred(), cap);
66517+}
66518+
66519+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66520+{
66521+ struct acl_subject_label *curracl;
66522+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66523+
66524+ if (!gr_acl_is_enabled())
66525+ return 1;
66526+
66527+ curracl = task->acl;
66528+
66529+ cap_drop = curracl->cap_lower;
66530+ cap_mask = curracl->cap_mask;
66531+
66532+ while ((curracl = curracl->parent_subject)) {
66533+ /* if the cap isn't specified in the current computed mask but is specified in the
66534+ current level subject, and is lowered in the current level subject, then add
66535+ it to the set of dropped capabilities
66536+ otherwise, add the current level subject's mask to the current computed mask
66537+ */
66538+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66539+ cap_raise(cap_mask, cap);
66540+ if (cap_raised(curracl->cap_lower, cap))
66541+ cap_raise(cap_drop, cap);
66542+ }
66543+ }
66544+
66545+ if (!cap_raised(cap_drop, cap))
66546+ return 1;
66547+
66548+ return 0;
66549+}
66550+
66551+int
66552+gr_acl_is_capable_nolog(const int cap)
66553+{
66554+ return gr_task_acl_is_capable_nolog(current, cap);
66555+}
66556+
66557diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66558new file mode 100644
66559index 0000000..a43dd06
66560--- /dev/null
66561+++ b/grsecurity/gracl_compat.c
66562@@ -0,0 +1,269 @@
66563+#include <linux/kernel.h>
66564+#include <linux/gracl.h>
66565+#include <linux/compat.h>
66566+#include <linux/gracl_compat.h>
66567+
66568+#include <asm/uaccess.h>
66569+
66570+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66571+{
66572+ struct gr_arg_wrapper_compat uwrapcompat;
66573+
66574+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66575+ return -EFAULT;
66576+
66577+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66578+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66579+ return -EINVAL;
66580+
66581+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66582+ uwrap->version = uwrapcompat.version;
66583+ uwrap->size = sizeof(struct gr_arg);
66584+
66585+ return 0;
66586+}
66587+
66588+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66589+{
66590+ struct gr_arg_compat argcompat;
66591+
66592+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66593+ return -EFAULT;
66594+
66595+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66596+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66597+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66598+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66599+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66600+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66601+
66602+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66603+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66604+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66605+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66606+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66607+ arg->segv_device = argcompat.segv_device;
66608+ arg->segv_inode = argcompat.segv_inode;
66609+ arg->segv_uid = argcompat.segv_uid;
66610+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66611+ arg->mode = argcompat.mode;
66612+
66613+ return 0;
66614+}
66615+
66616+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66617+{
66618+ struct acl_object_label_compat objcompat;
66619+
66620+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66621+ return -EFAULT;
66622+
66623+ obj->filename = compat_ptr(objcompat.filename);
66624+ obj->inode = objcompat.inode;
66625+ obj->device = objcompat.device;
66626+ obj->mode = objcompat.mode;
66627+
66628+ obj->nested = compat_ptr(objcompat.nested);
66629+ obj->globbed = compat_ptr(objcompat.globbed);
66630+
66631+ obj->prev = compat_ptr(objcompat.prev);
66632+ obj->next = compat_ptr(objcompat.next);
66633+
66634+ return 0;
66635+}
66636+
66637+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66638+{
66639+ unsigned int i;
66640+ struct acl_subject_label_compat subjcompat;
66641+
66642+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66643+ return -EFAULT;
66644+
66645+ subj->filename = compat_ptr(subjcompat.filename);
66646+ subj->inode = subjcompat.inode;
66647+ subj->device = subjcompat.device;
66648+ subj->mode = subjcompat.mode;
66649+ subj->cap_mask = subjcompat.cap_mask;
66650+ subj->cap_lower = subjcompat.cap_lower;
66651+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66652+
66653+ for (i = 0; i < GR_NLIMITS; i++) {
66654+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66655+ subj->res[i].rlim_cur = RLIM_INFINITY;
66656+ else
66657+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66658+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66659+ subj->res[i].rlim_max = RLIM_INFINITY;
66660+ else
66661+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66662+ }
66663+ subj->resmask = subjcompat.resmask;
66664+
66665+ subj->user_trans_type = subjcompat.user_trans_type;
66666+ subj->group_trans_type = subjcompat.group_trans_type;
66667+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66668+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66669+ subj->user_trans_num = subjcompat.user_trans_num;
66670+ subj->group_trans_num = subjcompat.group_trans_num;
66671+
66672+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66673+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66674+ subj->ip_type = subjcompat.ip_type;
66675+ subj->ips = compat_ptr(subjcompat.ips);
66676+ subj->ip_num = subjcompat.ip_num;
66677+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66678+
66679+ subj->crashes = subjcompat.crashes;
66680+ subj->expires = subjcompat.expires;
66681+
66682+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66683+ subj->hash = compat_ptr(subjcompat.hash);
66684+ subj->prev = compat_ptr(subjcompat.prev);
66685+ subj->next = compat_ptr(subjcompat.next);
66686+
66687+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66688+ subj->obj_hash_size = subjcompat.obj_hash_size;
66689+ subj->pax_flags = subjcompat.pax_flags;
66690+
66691+ return 0;
66692+}
66693+
66694+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66695+{
66696+ struct acl_role_label_compat rolecompat;
66697+
66698+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66699+ return -EFAULT;
66700+
66701+ role->rolename = compat_ptr(rolecompat.rolename);
66702+ role->uidgid = rolecompat.uidgid;
66703+ role->roletype = rolecompat.roletype;
66704+
66705+ role->auth_attempts = rolecompat.auth_attempts;
66706+ role->expires = rolecompat.expires;
66707+
66708+ role->root_label = compat_ptr(rolecompat.root_label);
66709+ role->hash = compat_ptr(rolecompat.hash);
66710+
66711+ role->prev = compat_ptr(rolecompat.prev);
66712+ role->next = compat_ptr(rolecompat.next);
66713+
66714+ role->transitions = compat_ptr(rolecompat.transitions);
66715+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66716+ role->domain_children = compat_ptr(rolecompat.domain_children);
66717+ role->domain_child_num = rolecompat.domain_child_num;
66718+
66719+ role->umask = rolecompat.umask;
66720+
66721+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66722+ role->subj_hash_size = rolecompat.subj_hash_size;
66723+
66724+ return 0;
66725+}
66726+
66727+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66728+{
66729+ struct role_allowed_ip_compat roleip_compat;
66730+
66731+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66732+ return -EFAULT;
66733+
66734+ roleip->addr = roleip_compat.addr;
66735+ roleip->netmask = roleip_compat.netmask;
66736+
66737+ roleip->prev = compat_ptr(roleip_compat.prev);
66738+ roleip->next = compat_ptr(roleip_compat.next);
66739+
66740+ return 0;
66741+}
66742+
66743+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66744+{
66745+ struct role_transition_compat trans_compat;
66746+
66747+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66748+ return -EFAULT;
66749+
66750+ trans->rolename = compat_ptr(trans_compat.rolename);
66751+
66752+ trans->prev = compat_ptr(trans_compat.prev);
66753+ trans->next = compat_ptr(trans_compat.next);
66754+
66755+ return 0;
66756+
66757+}
66758+
66759+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66760+{
66761+ struct gr_hash_struct_compat hash_compat;
66762+
66763+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66764+ return -EFAULT;
66765+
66766+ hash->table = compat_ptr(hash_compat.table);
66767+ hash->nametable = compat_ptr(hash_compat.nametable);
66768+ hash->first = compat_ptr(hash_compat.first);
66769+
66770+ hash->table_size = hash_compat.table_size;
66771+ hash->used_size = hash_compat.used_size;
66772+
66773+ hash->type = hash_compat.type;
66774+
66775+ return 0;
66776+}
66777+
66778+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66779+{
66780+ compat_uptr_t ptrcompat;
66781+
66782+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66783+ return -EFAULT;
66784+
66785+ *(void **)ptr = compat_ptr(ptrcompat);
66786+
66787+ return 0;
66788+}
66789+
66790+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66791+{
66792+ struct acl_ip_label_compat ip_compat;
66793+
66794+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66795+ return -EFAULT;
66796+
66797+ ip->iface = compat_ptr(ip_compat.iface);
66798+ ip->addr = ip_compat.addr;
66799+ ip->netmask = ip_compat.netmask;
66800+ ip->low = ip_compat.low;
66801+ ip->high = ip_compat.high;
66802+ ip->mode = ip_compat.mode;
66803+ ip->type = ip_compat.type;
66804+
66805+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66806+
66807+ ip->prev = compat_ptr(ip_compat.prev);
66808+ ip->next = compat_ptr(ip_compat.next);
66809+
66810+ return 0;
66811+}
66812+
66813+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66814+{
66815+ struct sprole_pw_compat pw_compat;
66816+
66817+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66818+ return -EFAULT;
66819+
66820+ pw->rolename = compat_ptr(pw_compat.rolename);
66821+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66822+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66823+
66824+ return 0;
66825+}
66826+
66827+size_t get_gr_arg_wrapper_size_compat(void)
66828+{
66829+ return sizeof(struct gr_arg_wrapper_compat);
66830+}
66831+
66832diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66833new file mode 100644
66834index 0000000..a340c17
66835--- /dev/null
66836+++ b/grsecurity/gracl_fs.c
66837@@ -0,0 +1,431 @@
66838+#include <linux/kernel.h>
66839+#include <linux/sched.h>
66840+#include <linux/types.h>
66841+#include <linux/fs.h>
66842+#include <linux/file.h>
66843+#include <linux/stat.h>
66844+#include <linux/grsecurity.h>
66845+#include <linux/grinternal.h>
66846+#include <linux/gracl.h>
66847+
66848+umode_t
66849+gr_acl_umask(void)
66850+{
66851+ if (unlikely(!gr_acl_is_enabled()))
66852+ return 0;
66853+
66854+ return current->role->umask;
66855+}
66856+
66857+__u32
66858+gr_acl_handle_hidden_file(const struct dentry * dentry,
66859+ const struct vfsmount * mnt)
66860+{
66861+ __u32 mode;
66862+
66863+ if (unlikely(!dentry->d_inode))
66864+ return GR_FIND;
66865+
66866+ mode =
66867+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66868+
66869+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66870+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66871+ return mode;
66872+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66873+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66874+ return 0;
66875+ } else if (unlikely(!(mode & GR_FIND)))
66876+ return 0;
66877+
66878+ return GR_FIND;
66879+}
66880+
66881+__u32
66882+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66883+ int acc_mode)
66884+{
66885+ __u32 reqmode = GR_FIND;
66886+ __u32 mode;
66887+
66888+ if (unlikely(!dentry->d_inode))
66889+ return reqmode;
66890+
66891+ if (acc_mode & MAY_APPEND)
66892+ reqmode |= GR_APPEND;
66893+ else if (acc_mode & MAY_WRITE)
66894+ reqmode |= GR_WRITE;
66895+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66896+ reqmode |= GR_READ;
66897+
66898+ mode =
66899+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66900+ mnt);
66901+
66902+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66903+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66904+ reqmode & GR_READ ? " reading" : "",
66905+ reqmode & GR_WRITE ? " writing" : reqmode &
66906+ GR_APPEND ? " appending" : "");
66907+ return reqmode;
66908+ } else
66909+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66910+ {
66911+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66912+ reqmode & GR_READ ? " reading" : "",
66913+ reqmode & GR_WRITE ? " writing" : reqmode &
66914+ GR_APPEND ? " appending" : "");
66915+ return 0;
66916+ } else if (unlikely((mode & reqmode) != reqmode))
66917+ return 0;
66918+
66919+ return reqmode;
66920+}
66921+
66922+__u32
66923+gr_acl_handle_creat(const struct dentry * dentry,
66924+ const struct dentry * p_dentry,
66925+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66926+ const int imode)
66927+{
66928+ __u32 reqmode = GR_WRITE | GR_CREATE;
66929+ __u32 mode;
66930+
66931+ if (acc_mode & MAY_APPEND)
66932+ reqmode |= GR_APPEND;
66933+ // if a directory was required or the directory already exists, then
66934+ // don't count this open as a read
66935+ if ((acc_mode & MAY_READ) &&
66936+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66937+ reqmode |= GR_READ;
66938+ if ((open_flags & O_CREAT) &&
66939+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66940+ reqmode |= GR_SETID;
66941+
66942+ mode =
66943+ gr_check_create(dentry, p_dentry, p_mnt,
66944+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66945+
66946+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66947+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66948+ reqmode & GR_READ ? " reading" : "",
66949+ reqmode & GR_WRITE ? " writing" : reqmode &
66950+ GR_APPEND ? " appending" : "");
66951+ return reqmode;
66952+ } else
66953+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66954+ {
66955+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66956+ reqmode & GR_READ ? " reading" : "",
66957+ reqmode & GR_WRITE ? " writing" : reqmode &
66958+ GR_APPEND ? " appending" : "");
66959+ return 0;
66960+ } else if (unlikely((mode & reqmode) != reqmode))
66961+ return 0;
66962+
66963+ return reqmode;
66964+}
66965+
66966+__u32
66967+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66968+ const int fmode)
66969+{
66970+ __u32 mode, reqmode = GR_FIND;
66971+
66972+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66973+ reqmode |= GR_EXEC;
66974+ if (fmode & S_IWOTH)
66975+ reqmode |= GR_WRITE;
66976+ if (fmode & S_IROTH)
66977+ reqmode |= GR_READ;
66978+
66979+ mode =
66980+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66981+ mnt);
66982+
66983+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66984+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66985+ reqmode & GR_READ ? " reading" : "",
66986+ reqmode & GR_WRITE ? " writing" : "",
66987+ reqmode & GR_EXEC ? " executing" : "");
66988+ return reqmode;
66989+ } else
66990+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66991+ {
66992+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66993+ reqmode & GR_READ ? " reading" : "",
66994+ reqmode & GR_WRITE ? " writing" : "",
66995+ reqmode & GR_EXEC ? " executing" : "");
66996+ return 0;
66997+ } else if (unlikely((mode & reqmode) != reqmode))
66998+ return 0;
66999+
67000+ return reqmode;
67001+}
67002+
67003+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67004+{
67005+ __u32 mode;
67006+
67007+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67008+
67009+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67010+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67011+ return mode;
67012+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67013+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67014+ return 0;
67015+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67016+ return 0;
67017+
67018+ return (reqmode);
67019+}
67020+
67021+__u32
67022+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67023+{
67024+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67025+}
67026+
67027+__u32
67028+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67029+{
67030+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67031+}
67032+
67033+__u32
67034+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67035+{
67036+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67037+}
67038+
67039+__u32
67040+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67041+{
67042+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67043+}
67044+
67045+__u32
67046+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67047+ umode_t *modeptr)
67048+{
67049+ umode_t mode;
67050+
67051+ *modeptr &= ~gr_acl_umask();
67052+ mode = *modeptr;
67053+
67054+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67055+ return 1;
67056+
67057+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67058+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67059+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67060+ GR_CHMOD_ACL_MSG);
67061+ } else {
67062+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67063+ }
67064+}
67065+
67066+__u32
67067+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67068+{
67069+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67070+}
67071+
67072+__u32
67073+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67074+{
67075+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67076+}
67077+
67078+__u32
67079+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67080+{
67081+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67082+}
67083+
67084+__u32
67085+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67086+{
67087+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67088+ GR_UNIXCONNECT_ACL_MSG);
67089+}
67090+
67091+/* hardlinks require at minimum create and link permission,
67092+ any additional privilege required is based on the
67093+ privilege of the file being linked to
67094+*/
67095+__u32
67096+gr_acl_handle_link(const struct dentry * new_dentry,
67097+ const struct dentry * parent_dentry,
67098+ const struct vfsmount * parent_mnt,
67099+ const struct dentry * old_dentry,
67100+ const struct vfsmount * old_mnt, const struct filename *to)
67101+{
67102+ __u32 mode;
67103+ __u32 needmode = GR_CREATE | GR_LINK;
67104+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67105+
67106+ mode =
67107+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67108+ old_mnt);
67109+
67110+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67111+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67112+ return mode;
67113+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67114+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67115+ return 0;
67116+ } else if (unlikely((mode & needmode) != needmode))
67117+ return 0;
67118+
67119+ return 1;
67120+}
67121+
67122+__u32
67123+gr_acl_handle_symlink(const struct dentry * new_dentry,
67124+ const struct dentry * parent_dentry,
67125+ const struct vfsmount * parent_mnt, const struct filename *from)
67126+{
67127+ __u32 needmode = GR_WRITE | GR_CREATE;
67128+ __u32 mode;
67129+
67130+ mode =
67131+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67132+ GR_CREATE | GR_AUDIT_CREATE |
67133+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67134+
67135+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67136+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67137+ return mode;
67138+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67139+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67140+ return 0;
67141+ } else if (unlikely((mode & needmode) != needmode))
67142+ return 0;
67143+
67144+ return (GR_WRITE | GR_CREATE);
67145+}
67146+
67147+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)
67148+{
67149+ __u32 mode;
67150+
67151+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67152+
67153+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67154+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67155+ return mode;
67156+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67157+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67158+ return 0;
67159+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67160+ return 0;
67161+
67162+ return (reqmode);
67163+}
67164+
67165+__u32
67166+gr_acl_handle_mknod(const struct dentry * new_dentry,
67167+ const struct dentry * parent_dentry,
67168+ const struct vfsmount * parent_mnt,
67169+ const int mode)
67170+{
67171+ __u32 reqmode = GR_WRITE | GR_CREATE;
67172+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67173+ reqmode |= GR_SETID;
67174+
67175+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67176+ reqmode, GR_MKNOD_ACL_MSG);
67177+}
67178+
67179+__u32
67180+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67181+ const struct dentry *parent_dentry,
67182+ const struct vfsmount *parent_mnt)
67183+{
67184+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67185+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67186+}
67187+
67188+#define RENAME_CHECK_SUCCESS(old, new) \
67189+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67190+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67191+
67192+int
67193+gr_acl_handle_rename(struct dentry *new_dentry,
67194+ struct dentry *parent_dentry,
67195+ const struct vfsmount *parent_mnt,
67196+ struct dentry *old_dentry,
67197+ struct inode *old_parent_inode,
67198+ struct vfsmount *old_mnt, const struct filename *newname)
67199+{
67200+ __u32 comp1, comp2;
67201+ int error = 0;
67202+
67203+ if (unlikely(!gr_acl_is_enabled()))
67204+ return 0;
67205+
67206+ if (!new_dentry->d_inode) {
67207+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67208+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67209+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67210+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67211+ GR_DELETE | GR_AUDIT_DELETE |
67212+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67213+ GR_SUPPRESS, old_mnt);
67214+ } else {
67215+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67216+ GR_CREATE | GR_DELETE |
67217+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67218+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67219+ GR_SUPPRESS, parent_mnt);
67220+ comp2 =
67221+ gr_search_file(old_dentry,
67222+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67223+ GR_DELETE | GR_AUDIT_DELETE |
67224+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67225+ }
67226+
67227+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67228+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67229+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67230+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67231+ && !(comp2 & GR_SUPPRESS)) {
67232+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67233+ error = -EACCES;
67234+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67235+ error = -EACCES;
67236+
67237+ return error;
67238+}
67239+
67240+void
67241+gr_acl_handle_exit(void)
67242+{
67243+ u16 id;
67244+ char *rolename;
67245+
67246+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67247+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67248+ id = current->acl_role_id;
67249+ rolename = current->role->rolename;
67250+ gr_set_acls(1);
67251+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67252+ }
67253+
67254+ gr_put_exec_file(current);
67255+ return;
67256+}
67257+
67258+int
67259+gr_acl_handle_procpidmem(const struct task_struct *task)
67260+{
67261+ if (unlikely(!gr_acl_is_enabled()))
67262+ return 0;
67263+
67264+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67265+ return -EACCES;
67266+
67267+ return 0;
67268+}
67269diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67270new file mode 100644
67271index 0000000..f056b81
67272--- /dev/null
67273+++ b/grsecurity/gracl_ip.c
67274@@ -0,0 +1,386 @@
67275+#include <linux/kernel.h>
67276+#include <asm/uaccess.h>
67277+#include <asm/errno.h>
67278+#include <net/sock.h>
67279+#include <linux/file.h>
67280+#include <linux/fs.h>
67281+#include <linux/net.h>
67282+#include <linux/in.h>
67283+#include <linux/skbuff.h>
67284+#include <linux/ip.h>
67285+#include <linux/udp.h>
67286+#include <linux/types.h>
67287+#include <linux/sched.h>
67288+#include <linux/netdevice.h>
67289+#include <linux/inetdevice.h>
67290+#include <linux/gracl.h>
67291+#include <linux/grsecurity.h>
67292+#include <linux/grinternal.h>
67293+
67294+#define GR_BIND 0x01
67295+#define GR_CONNECT 0x02
67296+#define GR_INVERT 0x04
67297+#define GR_BINDOVERRIDE 0x08
67298+#define GR_CONNECTOVERRIDE 0x10
67299+#define GR_SOCK_FAMILY 0x20
67300+
67301+static const char * gr_protocols[IPPROTO_MAX] = {
67302+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67303+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67304+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67305+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67306+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67307+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67308+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67309+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67310+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67311+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67312+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67313+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67314+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67315+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67316+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67317+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67318+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67319+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67320+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67321+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67322+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67323+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67324+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67325+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67326+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67327+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67328+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67329+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67330+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67331+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67332+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67333+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67334+ };
67335+
67336+static const char * gr_socktypes[SOCK_MAX] = {
67337+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67338+ "unknown:7", "unknown:8", "unknown:9", "packet"
67339+ };
67340+
67341+static const char * gr_sockfamilies[AF_MAX+1] = {
67342+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67343+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67344+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67345+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67346+ };
67347+
67348+const char *
67349+gr_proto_to_name(unsigned char proto)
67350+{
67351+ return gr_protocols[proto];
67352+}
67353+
67354+const char *
67355+gr_socktype_to_name(unsigned char type)
67356+{
67357+ return gr_socktypes[type];
67358+}
67359+
67360+const char *
67361+gr_sockfamily_to_name(unsigned char family)
67362+{
67363+ return gr_sockfamilies[family];
67364+}
67365+
67366+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67367+
67368+int
67369+gr_search_socket(const int domain, const int type, const int protocol)
67370+{
67371+ struct acl_subject_label *curr;
67372+ const struct cred *cred = current_cred();
67373+
67374+ if (unlikely(!gr_acl_is_enabled()))
67375+ goto exit;
67376+
67377+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67378+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67379+ goto exit; // let the kernel handle it
67380+
67381+ curr = current->acl;
67382+
67383+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67384+ /* the family is allowed, if this is PF_INET allow it only if
67385+ the extra sock type/protocol checks pass */
67386+ if (domain == PF_INET)
67387+ goto inet_check;
67388+ goto exit;
67389+ } else {
67390+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67391+ __u32 fakeip = 0;
67392+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67393+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67394+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67395+ gr_to_filename(current->exec_file->f_path.dentry,
67396+ current->exec_file->f_path.mnt) :
67397+ curr->filename, curr->filename,
67398+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67399+ &current->signal->saved_ip);
67400+ goto exit;
67401+ }
67402+ goto exit_fail;
67403+ }
67404+
67405+inet_check:
67406+ /* the rest of this checking is for IPv4 only */
67407+ if (!curr->ips)
67408+ goto exit;
67409+
67410+ if ((curr->ip_type & (1U << type)) &&
67411+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67412+ goto exit;
67413+
67414+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67415+ /* we don't place acls on raw sockets , and sometimes
67416+ dgram/ip sockets are opened for ioctl and not
67417+ bind/connect, so we'll fake a bind learn log */
67418+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67419+ __u32 fakeip = 0;
67420+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67421+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67422+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67423+ gr_to_filename(current->exec_file->f_path.dentry,
67424+ current->exec_file->f_path.mnt) :
67425+ curr->filename, curr->filename,
67426+ &fakeip, 0, type,
67427+ protocol, GR_CONNECT, &current->signal->saved_ip);
67428+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67429+ __u32 fakeip = 0;
67430+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67431+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67432+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67433+ gr_to_filename(current->exec_file->f_path.dentry,
67434+ current->exec_file->f_path.mnt) :
67435+ curr->filename, curr->filename,
67436+ &fakeip, 0, type,
67437+ protocol, GR_BIND, &current->signal->saved_ip);
67438+ }
67439+ /* we'll log when they use connect or bind */
67440+ goto exit;
67441+ }
67442+
67443+exit_fail:
67444+ if (domain == PF_INET)
67445+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67446+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67447+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67448+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67449+ gr_socktype_to_name(type), protocol);
67450+
67451+ return 0;
67452+exit:
67453+ return 1;
67454+}
67455+
67456+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)
67457+{
67458+ if ((ip->mode & mode) &&
67459+ (ip_port >= ip->low) &&
67460+ (ip_port <= ip->high) &&
67461+ ((ntohl(ip_addr) & our_netmask) ==
67462+ (ntohl(our_addr) & our_netmask))
67463+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67464+ && (ip->type & (1U << type))) {
67465+ if (ip->mode & GR_INVERT)
67466+ return 2; // specifically denied
67467+ else
67468+ return 1; // allowed
67469+ }
67470+
67471+ return 0; // not specifically allowed, may continue parsing
67472+}
67473+
67474+static int
67475+gr_search_connectbind(const int full_mode, struct sock *sk,
67476+ struct sockaddr_in *addr, const int type)
67477+{
67478+ char iface[IFNAMSIZ] = {0};
67479+ struct acl_subject_label *curr;
67480+ struct acl_ip_label *ip;
67481+ struct inet_sock *isk;
67482+ struct net_device *dev;
67483+ struct in_device *idev;
67484+ unsigned long i;
67485+ int ret;
67486+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67487+ __u32 ip_addr = 0;
67488+ __u32 our_addr;
67489+ __u32 our_netmask;
67490+ char *p;
67491+ __u16 ip_port = 0;
67492+ const struct cred *cred = current_cred();
67493+
67494+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67495+ return 0;
67496+
67497+ curr = current->acl;
67498+ isk = inet_sk(sk);
67499+
67500+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67501+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67502+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67503+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67504+ struct sockaddr_in saddr;
67505+ int err;
67506+
67507+ saddr.sin_family = AF_INET;
67508+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67509+ saddr.sin_port = isk->inet_sport;
67510+
67511+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67512+ if (err)
67513+ return err;
67514+
67515+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67516+ if (err)
67517+ return err;
67518+ }
67519+
67520+ if (!curr->ips)
67521+ return 0;
67522+
67523+ ip_addr = addr->sin_addr.s_addr;
67524+ ip_port = ntohs(addr->sin_port);
67525+
67526+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67527+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67528+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67529+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67530+ gr_to_filename(current->exec_file->f_path.dentry,
67531+ current->exec_file->f_path.mnt) :
67532+ curr->filename, curr->filename,
67533+ &ip_addr, ip_port, type,
67534+ sk->sk_protocol, mode, &current->signal->saved_ip);
67535+ return 0;
67536+ }
67537+
67538+ for (i = 0; i < curr->ip_num; i++) {
67539+ ip = *(curr->ips + i);
67540+ if (ip->iface != NULL) {
67541+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67542+ p = strchr(iface, ':');
67543+ if (p != NULL)
67544+ *p = '\0';
67545+ dev = dev_get_by_name(sock_net(sk), iface);
67546+ if (dev == NULL)
67547+ continue;
67548+ idev = in_dev_get(dev);
67549+ if (idev == NULL) {
67550+ dev_put(dev);
67551+ continue;
67552+ }
67553+ rcu_read_lock();
67554+ for_ifa(idev) {
67555+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67556+ our_addr = ifa->ifa_address;
67557+ our_netmask = 0xffffffff;
67558+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67559+ if (ret == 1) {
67560+ rcu_read_unlock();
67561+ in_dev_put(idev);
67562+ dev_put(dev);
67563+ return 0;
67564+ } else if (ret == 2) {
67565+ rcu_read_unlock();
67566+ in_dev_put(idev);
67567+ dev_put(dev);
67568+ goto denied;
67569+ }
67570+ }
67571+ } endfor_ifa(idev);
67572+ rcu_read_unlock();
67573+ in_dev_put(idev);
67574+ dev_put(dev);
67575+ } else {
67576+ our_addr = ip->addr;
67577+ our_netmask = ip->netmask;
67578+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67579+ if (ret == 1)
67580+ return 0;
67581+ else if (ret == 2)
67582+ goto denied;
67583+ }
67584+ }
67585+
67586+denied:
67587+ if (mode == GR_BIND)
67588+ 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));
67589+ else if (mode == GR_CONNECT)
67590+ 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));
67591+
67592+ return -EACCES;
67593+}
67594+
67595+int
67596+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67597+{
67598+ /* always allow disconnection of dgram sockets with connect */
67599+ if (addr->sin_family == AF_UNSPEC)
67600+ return 0;
67601+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67602+}
67603+
67604+int
67605+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67606+{
67607+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67608+}
67609+
67610+int gr_search_listen(struct socket *sock)
67611+{
67612+ struct sock *sk = sock->sk;
67613+ struct sockaddr_in addr;
67614+
67615+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67616+ addr.sin_port = inet_sk(sk)->inet_sport;
67617+
67618+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67619+}
67620+
67621+int gr_search_accept(struct socket *sock)
67622+{
67623+ struct sock *sk = sock->sk;
67624+ struct sockaddr_in addr;
67625+
67626+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67627+ addr.sin_port = inet_sk(sk)->inet_sport;
67628+
67629+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67630+}
67631+
67632+int
67633+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67634+{
67635+ if (addr)
67636+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67637+ else {
67638+ struct sockaddr_in sin;
67639+ const struct inet_sock *inet = inet_sk(sk);
67640+
67641+ sin.sin_addr.s_addr = inet->inet_daddr;
67642+ sin.sin_port = inet->inet_dport;
67643+
67644+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67645+ }
67646+}
67647+
67648+int
67649+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67650+{
67651+ struct sockaddr_in sin;
67652+
67653+ if (unlikely(skb->len < sizeof (struct udphdr)))
67654+ return 0; // skip this packet
67655+
67656+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67657+ sin.sin_port = udp_hdr(skb)->source;
67658+
67659+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67660+}
67661diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67662new file mode 100644
67663index 0000000..25f54ef
67664--- /dev/null
67665+++ b/grsecurity/gracl_learn.c
67666@@ -0,0 +1,207 @@
67667+#include <linux/kernel.h>
67668+#include <linux/mm.h>
67669+#include <linux/sched.h>
67670+#include <linux/poll.h>
67671+#include <linux/string.h>
67672+#include <linux/file.h>
67673+#include <linux/types.h>
67674+#include <linux/vmalloc.h>
67675+#include <linux/grinternal.h>
67676+
67677+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67678+ size_t count, loff_t *ppos);
67679+extern int gr_acl_is_enabled(void);
67680+
67681+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67682+static int gr_learn_attached;
67683+
67684+/* use a 512k buffer */
67685+#define LEARN_BUFFER_SIZE (512 * 1024)
67686+
67687+static DEFINE_SPINLOCK(gr_learn_lock);
67688+static DEFINE_MUTEX(gr_learn_user_mutex);
67689+
67690+/* we need to maintain two buffers, so that the kernel context of grlearn
67691+ uses a semaphore around the userspace copying, and the other kernel contexts
67692+ use a spinlock when copying into the buffer, since they cannot sleep
67693+*/
67694+static char *learn_buffer;
67695+static char *learn_buffer_user;
67696+static int learn_buffer_len;
67697+static int learn_buffer_user_len;
67698+
67699+static ssize_t
67700+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67701+{
67702+ DECLARE_WAITQUEUE(wait, current);
67703+ ssize_t retval = 0;
67704+
67705+ add_wait_queue(&learn_wait, &wait);
67706+ set_current_state(TASK_INTERRUPTIBLE);
67707+ do {
67708+ mutex_lock(&gr_learn_user_mutex);
67709+ spin_lock(&gr_learn_lock);
67710+ if (learn_buffer_len)
67711+ break;
67712+ spin_unlock(&gr_learn_lock);
67713+ mutex_unlock(&gr_learn_user_mutex);
67714+ if (file->f_flags & O_NONBLOCK) {
67715+ retval = -EAGAIN;
67716+ goto out;
67717+ }
67718+ if (signal_pending(current)) {
67719+ retval = -ERESTARTSYS;
67720+ goto out;
67721+ }
67722+
67723+ schedule();
67724+ } while (1);
67725+
67726+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67727+ learn_buffer_user_len = learn_buffer_len;
67728+ retval = learn_buffer_len;
67729+ learn_buffer_len = 0;
67730+
67731+ spin_unlock(&gr_learn_lock);
67732+
67733+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67734+ retval = -EFAULT;
67735+
67736+ mutex_unlock(&gr_learn_user_mutex);
67737+out:
67738+ set_current_state(TASK_RUNNING);
67739+ remove_wait_queue(&learn_wait, &wait);
67740+ return retval;
67741+}
67742+
67743+static unsigned int
67744+poll_learn(struct file * file, poll_table * wait)
67745+{
67746+ poll_wait(file, &learn_wait, wait);
67747+
67748+ if (learn_buffer_len)
67749+ return (POLLIN | POLLRDNORM);
67750+
67751+ return 0;
67752+}
67753+
67754+void
67755+gr_clear_learn_entries(void)
67756+{
67757+ char *tmp;
67758+
67759+ mutex_lock(&gr_learn_user_mutex);
67760+ spin_lock(&gr_learn_lock);
67761+ tmp = learn_buffer;
67762+ learn_buffer = NULL;
67763+ spin_unlock(&gr_learn_lock);
67764+ if (tmp)
67765+ vfree(tmp);
67766+ if (learn_buffer_user != NULL) {
67767+ vfree(learn_buffer_user);
67768+ learn_buffer_user = NULL;
67769+ }
67770+ learn_buffer_len = 0;
67771+ mutex_unlock(&gr_learn_user_mutex);
67772+
67773+ return;
67774+}
67775+
67776+void
67777+gr_add_learn_entry(const char *fmt, ...)
67778+{
67779+ va_list args;
67780+ unsigned int len;
67781+
67782+ if (!gr_learn_attached)
67783+ return;
67784+
67785+ spin_lock(&gr_learn_lock);
67786+
67787+ /* leave a gap at the end so we know when it's "full" but don't have to
67788+ compute the exact length of the string we're trying to append
67789+ */
67790+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67791+ spin_unlock(&gr_learn_lock);
67792+ wake_up_interruptible(&learn_wait);
67793+ return;
67794+ }
67795+ if (learn_buffer == NULL) {
67796+ spin_unlock(&gr_learn_lock);
67797+ return;
67798+ }
67799+
67800+ va_start(args, fmt);
67801+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67802+ va_end(args);
67803+
67804+ learn_buffer_len += len + 1;
67805+
67806+ spin_unlock(&gr_learn_lock);
67807+ wake_up_interruptible(&learn_wait);
67808+
67809+ return;
67810+}
67811+
67812+static int
67813+open_learn(struct inode *inode, struct file *file)
67814+{
67815+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67816+ return -EBUSY;
67817+ if (file->f_mode & FMODE_READ) {
67818+ int retval = 0;
67819+ mutex_lock(&gr_learn_user_mutex);
67820+ if (learn_buffer == NULL)
67821+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67822+ if (learn_buffer_user == NULL)
67823+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67824+ if (learn_buffer == NULL) {
67825+ retval = -ENOMEM;
67826+ goto out_error;
67827+ }
67828+ if (learn_buffer_user == NULL) {
67829+ retval = -ENOMEM;
67830+ goto out_error;
67831+ }
67832+ learn_buffer_len = 0;
67833+ learn_buffer_user_len = 0;
67834+ gr_learn_attached = 1;
67835+out_error:
67836+ mutex_unlock(&gr_learn_user_mutex);
67837+ return retval;
67838+ }
67839+ return 0;
67840+}
67841+
67842+static int
67843+close_learn(struct inode *inode, struct file *file)
67844+{
67845+ if (file->f_mode & FMODE_READ) {
67846+ char *tmp = NULL;
67847+ mutex_lock(&gr_learn_user_mutex);
67848+ spin_lock(&gr_learn_lock);
67849+ tmp = learn_buffer;
67850+ learn_buffer = NULL;
67851+ spin_unlock(&gr_learn_lock);
67852+ if (tmp)
67853+ vfree(tmp);
67854+ if (learn_buffer_user != NULL) {
67855+ vfree(learn_buffer_user);
67856+ learn_buffer_user = NULL;
67857+ }
67858+ learn_buffer_len = 0;
67859+ learn_buffer_user_len = 0;
67860+ gr_learn_attached = 0;
67861+ mutex_unlock(&gr_learn_user_mutex);
67862+ }
67863+
67864+ return 0;
67865+}
67866+
67867+const struct file_operations grsec_fops = {
67868+ .read = read_learn,
67869+ .write = write_grsec_handler,
67870+ .open = open_learn,
67871+ .release = close_learn,
67872+ .poll = poll_learn,
67873+};
67874diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67875new file mode 100644
67876index 0000000..39645c9
67877--- /dev/null
67878+++ b/grsecurity/gracl_res.c
67879@@ -0,0 +1,68 @@
67880+#include <linux/kernel.h>
67881+#include <linux/sched.h>
67882+#include <linux/gracl.h>
67883+#include <linux/grinternal.h>
67884+
67885+static const char *restab_log[] = {
67886+ [RLIMIT_CPU] = "RLIMIT_CPU",
67887+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67888+ [RLIMIT_DATA] = "RLIMIT_DATA",
67889+ [RLIMIT_STACK] = "RLIMIT_STACK",
67890+ [RLIMIT_CORE] = "RLIMIT_CORE",
67891+ [RLIMIT_RSS] = "RLIMIT_RSS",
67892+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67893+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67894+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67895+ [RLIMIT_AS] = "RLIMIT_AS",
67896+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67897+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67898+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67899+ [RLIMIT_NICE] = "RLIMIT_NICE",
67900+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67901+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67902+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67903+};
67904+
67905+void
67906+gr_log_resource(const struct task_struct *task,
67907+ const int res, const unsigned long wanted, const int gt)
67908+{
67909+ const struct cred *cred;
67910+ unsigned long rlim;
67911+
67912+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67913+ return;
67914+
67915+ // not yet supported resource
67916+ if (unlikely(!restab_log[res]))
67917+ return;
67918+
67919+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67920+ rlim = task_rlimit_max(task, res);
67921+ else
67922+ rlim = task_rlimit(task, res);
67923+
67924+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67925+ return;
67926+
67927+ rcu_read_lock();
67928+ cred = __task_cred(task);
67929+
67930+ if (res == RLIMIT_NPROC &&
67931+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67932+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67933+ goto out_rcu_unlock;
67934+ else if (res == RLIMIT_MEMLOCK &&
67935+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67936+ goto out_rcu_unlock;
67937+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67938+ goto out_rcu_unlock;
67939+ rcu_read_unlock();
67940+
67941+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67942+
67943+ return;
67944+out_rcu_unlock:
67945+ rcu_read_unlock();
67946+ return;
67947+}
67948diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67949new file mode 100644
67950index 0000000..3c38bfe
67951--- /dev/null
67952+++ b/grsecurity/gracl_segv.c
67953@@ -0,0 +1,305 @@
67954+#include <linux/kernel.h>
67955+#include <linux/mm.h>
67956+#include <asm/uaccess.h>
67957+#include <asm/errno.h>
67958+#include <asm/mman.h>
67959+#include <net/sock.h>
67960+#include <linux/file.h>
67961+#include <linux/fs.h>
67962+#include <linux/net.h>
67963+#include <linux/in.h>
67964+#include <linux/slab.h>
67965+#include <linux/types.h>
67966+#include <linux/sched.h>
67967+#include <linux/timer.h>
67968+#include <linux/gracl.h>
67969+#include <linux/grsecurity.h>
67970+#include <linux/grinternal.h>
67971+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67972+#include <linux/magic.h>
67973+#include <linux/pagemap.h>
67974+#include "../fs/btrfs/async-thread.h"
67975+#include "../fs/btrfs/ctree.h"
67976+#include "../fs/btrfs/btrfs_inode.h"
67977+#endif
67978+
67979+static struct crash_uid *uid_set;
67980+static unsigned short uid_used;
67981+static DEFINE_SPINLOCK(gr_uid_lock);
67982+extern rwlock_t gr_inode_lock;
67983+extern struct acl_subject_label *
67984+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67985+ struct acl_role_label *role);
67986+
67987+static inline dev_t __get_dev(const struct dentry *dentry)
67988+{
67989+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67990+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67991+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67992+ else
67993+#endif
67994+ return dentry->d_sb->s_dev;
67995+}
67996+
67997+int
67998+gr_init_uidset(void)
67999+{
68000+ uid_set =
68001+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68002+ uid_used = 0;
68003+
68004+ return uid_set ? 1 : 0;
68005+}
68006+
68007+void
68008+gr_free_uidset(void)
68009+{
68010+ if (uid_set)
68011+ kfree(uid_set);
68012+
68013+ return;
68014+}
68015+
68016+int
68017+gr_find_uid(const uid_t uid)
68018+{
68019+ struct crash_uid *tmp = uid_set;
68020+ uid_t buid;
68021+ int low = 0, high = uid_used - 1, mid;
68022+
68023+ while (high >= low) {
68024+ mid = (low + high) >> 1;
68025+ buid = tmp[mid].uid;
68026+ if (buid == uid)
68027+ return mid;
68028+ if (buid > uid)
68029+ high = mid - 1;
68030+ if (buid < uid)
68031+ low = mid + 1;
68032+ }
68033+
68034+ return -1;
68035+}
68036+
68037+static __inline__ void
68038+gr_insertsort(void)
68039+{
68040+ unsigned short i, j;
68041+ struct crash_uid index;
68042+
68043+ for (i = 1; i < uid_used; i++) {
68044+ index = uid_set[i];
68045+ j = i;
68046+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68047+ uid_set[j] = uid_set[j - 1];
68048+ j--;
68049+ }
68050+ uid_set[j] = index;
68051+ }
68052+
68053+ return;
68054+}
68055+
68056+static __inline__ void
68057+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68058+{
68059+ int loc;
68060+ uid_t uid = GR_GLOBAL_UID(kuid);
68061+
68062+ if (uid_used == GR_UIDTABLE_MAX)
68063+ return;
68064+
68065+ loc = gr_find_uid(uid);
68066+
68067+ if (loc >= 0) {
68068+ uid_set[loc].expires = expires;
68069+ return;
68070+ }
68071+
68072+ uid_set[uid_used].uid = uid;
68073+ uid_set[uid_used].expires = expires;
68074+ uid_used++;
68075+
68076+ gr_insertsort();
68077+
68078+ return;
68079+}
68080+
68081+void
68082+gr_remove_uid(const unsigned short loc)
68083+{
68084+ unsigned short i;
68085+
68086+ for (i = loc + 1; i < uid_used; i++)
68087+ uid_set[i - 1] = uid_set[i];
68088+
68089+ uid_used--;
68090+
68091+ return;
68092+}
68093+
68094+int
68095+gr_check_crash_uid(const kuid_t kuid)
68096+{
68097+ int loc;
68098+ int ret = 0;
68099+ uid_t uid;
68100+
68101+ if (unlikely(!gr_acl_is_enabled()))
68102+ return 0;
68103+
68104+ uid = GR_GLOBAL_UID(kuid);
68105+
68106+ spin_lock(&gr_uid_lock);
68107+ loc = gr_find_uid(uid);
68108+
68109+ if (loc < 0)
68110+ goto out_unlock;
68111+
68112+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68113+ gr_remove_uid(loc);
68114+ else
68115+ ret = 1;
68116+
68117+out_unlock:
68118+ spin_unlock(&gr_uid_lock);
68119+ return ret;
68120+}
68121+
68122+static __inline__ int
68123+proc_is_setxid(const struct cred *cred)
68124+{
68125+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68126+ !uid_eq(cred->uid, cred->fsuid))
68127+ return 1;
68128+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68129+ !gid_eq(cred->gid, cred->fsgid))
68130+ return 1;
68131+
68132+ return 0;
68133+}
68134+
68135+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68136+
68137+void
68138+gr_handle_crash(struct task_struct *task, const int sig)
68139+{
68140+ struct acl_subject_label *curr;
68141+ struct task_struct *tsk, *tsk2;
68142+ const struct cred *cred;
68143+ const struct cred *cred2;
68144+
68145+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68146+ return;
68147+
68148+ if (unlikely(!gr_acl_is_enabled()))
68149+ return;
68150+
68151+ curr = task->acl;
68152+
68153+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68154+ return;
68155+
68156+ if (time_before_eq(curr->expires, get_seconds())) {
68157+ curr->expires = 0;
68158+ curr->crashes = 0;
68159+ }
68160+
68161+ curr->crashes++;
68162+
68163+ if (!curr->expires)
68164+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68165+
68166+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68167+ time_after(curr->expires, get_seconds())) {
68168+ rcu_read_lock();
68169+ cred = __task_cred(task);
68170+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68171+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68172+ spin_lock(&gr_uid_lock);
68173+ gr_insert_uid(cred->uid, curr->expires);
68174+ spin_unlock(&gr_uid_lock);
68175+ curr->expires = 0;
68176+ curr->crashes = 0;
68177+ read_lock(&tasklist_lock);
68178+ do_each_thread(tsk2, tsk) {
68179+ cred2 = __task_cred(tsk);
68180+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68181+ gr_fake_force_sig(SIGKILL, tsk);
68182+ } while_each_thread(tsk2, tsk);
68183+ read_unlock(&tasklist_lock);
68184+ } else {
68185+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68186+ read_lock(&tasklist_lock);
68187+ read_lock(&grsec_exec_file_lock);
68188+ do_each_thread(tsk2, tsk) {
68189+ if (likely(tsk != task)) {
68190+ // if this thread has the same subject as the one that triggered
68191+ // RES_CRASH and it's the same binary, kill it
68192+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68193+ gr_fake_force_sig(SIGKILL, tsk);
68194+ }
68195+ } while_each_thread(tsk2, tsk);
68196+ read_unlock(&grsec_exec_file_lock);
68197+ read_unlock(&tasklist_lock);
68198+ }
68199+ rcu_read_unlock();
68200+ }
68201+
68202+ return;
68203+}
68204+
68205+int
68206+gr_check_crash_exec(const struct file *filp)
68207+{
68208+ struct acl_subject_label *curr;
68209+
68210+ if (unlikely(!gr_acl_is_enabled()))
68211+ return 0;
68212+
68213+ read_lock(&gr_inode_lock);
68214+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68215+ __get_dev(filp->f_path.dentry),
68216+ current->role);
68217+ read_unlock(&gr_inode_lock);
68218+
68219+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68220+ (!curr->crashes && !curr->expires))
68221+ return 0;
68222+
68223+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68224+ time_after(curr->expires, get_seconds()))
68225+ return 1;
68226+ else if (time_before_eq(curr->expires, get_seconds())) {
68227+ curr->crashes = 0;
68228+ curr->expires = 0;
68229+ }
68230+
68231+ return 0;
68232+}
68233+
68234+void
68235+gr_handle_alertkill(struct task_struct *task)
68236+{
68237+ struct acl_subject_label *curracl;
68238+ __u32 curr_ip;
68239+ struct task_struct *p, *p2;
68240+
68241+ if (unlikely(!gr_acl_is_enabled()))
68242+ return;
68243+
68244+ curracl = task->acl;
68245+ curr_ip = task->signal->curr_ip;
68246+
68247+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68248+ read_lock(&tasklist_lock);
68249+ do_each_thread(p2, p) {
68250+ if (p->signal->curr_ip == curr_ip)
68251+ gr_fake_force_sig(SIGKILL, p);
68252+ } while_each_thread(p2, p);
68253+ read_unlock(&tasklist_lock);
68254+ } else if (curracl->mode & GR_KILLPROC)
68255+ gr_fake_force_sig(SIGKILL, task);
68256+
68257+ return;
68258+}
68259diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68260new file mode 100644
68261index 0000000..98011b0
68262--- /dev/null
68263+++ b/grsecurity/gracl_shm.c
68264@@ -0,0 +1,40 @@
68265+#include <linux/kernel.h>
68266+#include <linux/mm.h>
68267+#include <linux/sched.h>
68268+#include <linux/file.h>
68269+#include <linux/ipc.h>
68270+#include <linux/gracl.h>
68271+#include <linux/grsecurity.h>
68272+#include <linux/grinternal.h>
68273+
68274+int
68275+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68276+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68277+{
68278+ struct task_struct *task;
68279+
68280+ if (!gr_acl_is_enabled())
68281+ return 1;
68282+
68283+ rcu_read_lock();
68284+ read_lock(&tasklist_lock);
68285+
68286+ task = find_task_by_vpid(shm_cprid);
68287+
68288+ if (unlikely(!task))
68289+ task = find_task_by_vpid(shm_lapid);
68290+
68291+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68292+ (task_pid_nr(task) == shm_lapid)) &&
68293+ (task->acl->mode & GR_PROTSHM) &&
68294+ (task->acl != current->acl))) {
68295+ read_unlock(&tasklist_lock);
68296+ rcu_read_unlock();
68297+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68298+ return 0;
68299+ }
68300+ read_unlock(&tasklist_lock);
68301+ rcu_read_unlock();
68302+
68303+ return 1;
68304+}
68305diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68306new file mode 100644
68307index 0000000..bc0be01
68308--- /dev/null
68309+++ b/grsecurity/grsec_chdir.c
68310@@ -0,0 +1,19 @@
68311+#include <linux/kernel.h>
68312+#include <linux/sched.h>
68313+#include <linux/fs.h>
68314+#include <linux/file.h>
68315+#include <linux/grsecurity.h>
68316+#include <linux/grinternal.h>
68317+
68318+void
68319+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68320+{
68321+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68322+ if ((grsec_enable_chdir && grsec_enable_group &&
68323+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68324+ !grsec_enable_group)) {
68325+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68326+ }
68327+#endif
68328+ return;
68329+}
68330diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68331new file mode 100644
68332index 0000000..bd6e105
68333--- /dev/null
68334+++ b/grsecurity/grsec_chroot.c
68335@@ -0,0 +1,370 @@
68336+#include <linux/kernel.h>
68337+#include <linux/module.h>
68338+#include <linux/sched.h>
68339+#include <linux/file.h>
68340+#include <linux/fs.h>
68341+#include <linux/mount.h>
68342+#include <linux/types.h>
68343+#include "../fs/mount.h"
68344+#include <linux/grsecurity.h>
68345+#include <linux/grinternal.h>
68346+
68347+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68348+static int gr_init_ran;
68349+#endif
68350+
68351+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68352+{
68353+#ifdef CONFIG_GRKERNSEC
68354+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68355+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68356+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68357+ && gr_init_ran
68358+#endif
68359+ )
68360+ task->gr_is_chrooted = 1;
68361+ else {
68362+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68363+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68364+ gr_init_ran = 1;
68365+#endif
68366+ task->gr_is_chrooted = 0;
68367+ }
68368+
68369+ task->gr_chroot_dentry = path->dentry;
68370+#endif
68371+ return;
68372+}
68373+
68374+void gr_clear_chroot_entries(struct task_struct *task)
68375+{
68376+#ifdef CONFIG_GRKERNSEC
68377+ task->gr_is_chrooted = 0;
68378+ task->gr_chroot_dentry = NULL;
68379+#endif
68380+ return;
68381+}
68382+
68383+int
68384+gr_handle_chroot_unix(const pid_t pid)
68385+{
68386+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68387+ struct task_struct *p;
68388+
68389+ if (unlikely(!grsec_enable_chroot_unix))
68390+ return 1;
68391+
68392+ if (likely(!proc_is_chrooted(current)))
68393+ return 1;
68394+
68395+ rcu_read_lock();
68396+ read_lock(&tasklist_lock);
68397+ p = find_task_by_vpid_unrestricted(pid);
68398+ if (unlikely(p && !have_same_root(current, p))) {
68399+ read_unlock(&tasklist_lock);
68400+ rcu_read_unlock();
68401+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68402+ return 0;
68403+ }
68404+ read_unlock(&tasklist_lock);
68405+ rcu_read_unlock();
68406+#endif
68407+ return 1;
68408+}
68409+
68410+int
68411+gr_handle_chroot_nice(void)
68412+{
68413+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68414+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68415+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68416+ return -EPERM;
68417+ }
68418+#endif
68419+ return 0;
68420+}
68421+
68422+int
68423+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68424+{
68425+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68426+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68427+ && proc_is_chrooted(current)) {
68428+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68429+ return -EACCES;
68430+ }
68431+#endif
68432+ return 0;
68433+}
68434+
68435+int
68436+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68437+{
68438+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68439+ struct task_struct *p;
68440+ int ret = 0;
68441+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68442+ return ret;
68443+
68444+ read_lock(&tasklist_lock);
68445+ do_each_pid_task(pid, type, p) {
68446+ if (!have_same_root(current, p)) {
68447+ ret = 1;
68448+ goto out;
68449+ }
68450+ } while_each_pid_task(pid, type, p);
68451+out:
68452+ read_unlock(&tasklist_lock);
68453+ return ret;
68454+#endif
68455+ return 0;
68456+}
68457+
68458+int
68459+gr_pid_is_chrooted(struct task_struct *p)
68460+{
68461+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68462+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68463+ return 0;
68464+
68465+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68466+ !have_same_root(current, p)) {
68467+ return 1;
68468+ }
68469+#endif
68470+ return 0;
68471+}
68472+
68473+EXPORT_SYMBOL(gr_pid_is_chrooted);
68474+
68475+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68476+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68477+{
68478+ struct path path, currentroot;
68479+ int ret = 0;
68480+
68481+ path.dentry = (struct dentry *)u_dentry;
68482+ path.mnt = (struct vfsmount *)u_mnt;
68483+ get_fs_root(current->fs, &currentroot);
68484+ if (path_is_under(&path, &currentroot))
68485+ ret = 1;
68486+ path_put(&currentroot);
68487+
68488+ return ret;
68489+}
68490+#endif
68491+
68492+int
68493+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68494+{
68495+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68496+ if (!grsec_enable_chroot_fchdir)
68497+ return 1;
68498+
68499+ if (!proc_is_chrooted(current))
68500+ return 1;
68501+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68502+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68503+ return 0;
68504+ }
68505+#endif
68506+ return 1;
68507+}
68508+
68509+int
68510+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68511+ const time_t shm_createtime)
68512+{
68513+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68514+ struct task_struct *p;
68515+ time_t starttime;
68516+
68517+ if (unlikely(!grsec_enable_chroot_shmat))
68518+ return 1;
68519+
68520+ if (likely(!proc_is_chrooted(current)))
68521+ return 1;
68522+
68523+ rcu_read_lock();
68524+ read_lock(&tasklist_lock);
68525+
68526+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68527+ starttime = p->start_time.tv_sec;
68528+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68529+ if (have_same_root(current, p)) {
68530+ goto allow;
68531+ } else {
68532+ read_unlock(&tasklist_lock);
68533+ rcu_read_unlock();
68534+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68535+ return 0;
68536+ }
68537+ }
68538+ /* creator exited, pid reuse, fall through to next check */
68539+ }
68540+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68541+ if (unlikely(!have_same_root(current, p))) {
68542+ read_unlock(&tasklist_lock);
68543+ rcu_read_unlock();
68544+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68545+ return 0;
68546+ }
68547+ }
68548+
68549+allow:
68550+ read_unlock(&tasklist_lock);
68551+ rcu_read_unlock();
68552+#endif
68553+ return 1;
68554+}
68555+
68556+void
68557+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68558+{
68559+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68560+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68561+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68562+#endif
68563+ return;
68564+}
68565+
68566+int
68567+gr_handle_chroot_mknod(const struct dentry *dentry,
68568+ const struct vfsmount *mnt, const int mode)
68569+{
68570+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68571+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68572+ proc_is_chrooted(current)) {
68573+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68574+ return -EPERM;
68575+ }
68576+#endif
68577+ return 0;
68578+}
68579+
68580+int
68581+gr_handle_chroot_mount(const struct dentry *dentry,
68582+ const struct vfsmount *mnt, const char *dev_name)
68583+{
68584+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68585+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68586+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68587+ return -EPERM;
68588+ }
68589+#endif
68590+ return 0;
68591+}
68592+
68593+int
68594+gr_handle_chroot_pivot(void)
68595+{
68596+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68597+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68598+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68599+ return -EPERM;
68600+ }
68601+#endif
68602+ return 0;
68603+}
68604+
68605+int
68606+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68607+{
68608+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68609+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68610+ !gr_is_outside_chroot(dentry, mnt)) {
68611+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68612+ return -EPERM;
68613+ }
68614+#endif
68615+ return 0;
68616+}
68617+
68618+extern const char *captab_log[];
68619+extern int captab_log_entries;
68620+
68621+int
68622+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68623+{
68624+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68625+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68626+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68627+ if (cap_raised(chroot_caps, cap)) {
68628+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68629+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68630+ }
68631+ return 0;
68632+ }
68633+ }
68634+#endif
68635+ return 1;
68636+}
68637+
68638+int
68639+gr_chroot_is_capable(const int cap)
68640+{
68641+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68642+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68643+#endif
68644+ return 1;
68645+}
68646+
68647+int
68648+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68649+{
68650+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68651+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68652+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68653+ if (cap_raised(chroot_caps, cap)) {
68654+ return 0;
68655+ }
68656+ }
68657+#endif
68658+ return 1;
68659+}
68660+
68661+int
68662+gr_chroot_is_capable_nolog(const int cap)
68663+{
68664+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68665+ return gr_task_chroot_is_capable_nolog(current, cap);
68666+#endif
68667+ return 1;
68668+}
68669+
68670+int
68671+gr_handle_chroot_sysctl(const int op)
68672+{
68673+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68674+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68675+ proc_is_chrooted(current))
68676+ return -EACCES;
68677+#endif
68678+ return 0;
68679+}
68680+
68681+void
68682+gr_handle_chroot_chdir(const struct path *path)
68683+{
68684+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68685+ if (grsec_enable_chroot_chdir)
68686+ set_fs_pwd(current->fs, path);
68687+#endif
68688+ return;
68689+}
68690+
68691+int
68692+gr_handle_chroot_chmod(const struct dentry *dentry,
68693+ const struct vfsmount *mnt, const int mode)
68694+{
68695+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68696+ /* allow chmod +s on directories, but not files */
68697+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68698+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68699+ proc_is_chrooted(current)) {
68700+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68701+ return -EPERM;
68702+ }
68703+#endif
68704+ return 0;
68705+}
68706diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68707new file mode 100644
68708index 0000000..ce65ceb
68709--- /dev/null
68710+++ b/grsecurity/grsec_disabled.c
68711@@ -0,0 +1,434 @@
68712+#include <linux/kernel.h>
68713+#include <linux/module.h>
68714+#include <linux/sched.h>
68715+#include <linux/file.h>
68716+#include <linux/fs.h>
68717+#include <linux/kdev_t.h>
68718+#include <linux/net.h>
68719+#include <linux/in.h>
68720+#include <linux/ip.h>
68721+#include <linux/skbuff.h>
68722+#include <linux/sysctl.h>
68723+
68724+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68725+void
68726+pax_set_initial_flags(struct linux_binprm *bprm)
68727+{
68728+ return;
68729+}
68730+#endif
68731+
68732+#ifdef CONFIG_SYSCTL
68733+__u32
68734+gr_handle_sysctl(const struct ctl_table * table, const int op)
68735+{
68736+ return 0;
68737+}
68738+#endif
68739+
68740+#ifdef CONFIG_TASKSTATS
68741+int gr_is_taskstats_denied(int pid)
68742+{
68743+ return 0;
68744+}
68745+#endif
68746+
68747+int
68748+gr_acl_is_enabled(void)
68749+{
68750+ return 0;
68751+}
68752+
68753+void
68754+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68755+{
68756+ return;
68757+}
68758+
68759+int
68760+gr_handle_rawio(const struct inode *inode)
68761+{
68762+ return 0;
68763+}
68764+
68765+void
68766+gr_acl_handle_psacct(struct task_struct *task, const long code)
68767+{
68768+ return;
68769+}
68770+
68771+int
68772+gr_handle_ptrace(struct task_struct *task, const long request)
68773+{
68774+ return 0;
68775+}
68776+
68777+int
68778+gr_handle_proc_ptrace(struct task_struct *task)
68779+{
68780+ return 0;
68781+}
68782+
68783+int
68784+gr_set_acls(const int type)
68785+{
68786+ return 0;
68787+}
68788+
68789+int
68790+gr_check_hidden_task(const struct task_struct *tsk)
68791+{
68792+ return 0;
68793+}
68794+
68795+int
68796+gr_check_protected_task(const struct task_struct *task)
68797+{
68798+ return 0;
68799+}
68800+
68801+int
68802+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68803+{
68804+ return 0;
68805+}
68806+
68807+void
68808+gr_copy_label(struct task_struct *tsk)
68809+{
68810+ return;
68811+}
68812+
68813+void
68814+gr_set_pax_flags(struct task_struct *task)
68815+{
68816+ return;
68817+}
68818+
68819+int
68820+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68821+ const int unsafe_share)
68822+{
68823+ return 0;
68824+}
68825+
68826+void
68827+gr_handle_delete(const ino_t ino, const dev_t dev)
68828+{
68829+ return;
68830+}
68831+
68832+void
68833+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68834+{
68835+ return;
68836+}
68837+
68838+void
68839+gr_handle_crash(struct task_struct *task, const int sig)
68840+{
68841+ return;
68842+}
68843+
68844+int
68845+gr_check_crash_exec(const struct file *filp)
68846+{
68847+ return 0;
68848+}
68849+
68850+int
68851+gr_check_crash_uid(const kuid_t uid)
68852+{
68853+ return 0;
68854+}
68855+
68856+void
68857+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68858+ struct dentry *old_dentry,
68859+ struct dentry *new_dentry,
68860+ struct vfsmount *mnt, const __u8 replace)
68861+{
68862+ return;
68863+}
68864+
68865+int
68866+gr_search_socket(const int family, const int type, const int protocol)
68867+{
68868+ return 1;
68869+}
68870+
68871+int
68872+gr_search_connectbind(const int mode, const struct socket *sock,
68873+ const struct sockaddr_in *addr)
68874+{
68875+ return 0;
68876+}
68877+
68878+void
68879+gr_handle_alertkill(struct task_struct *task)
68880+{
68881+ return;
68882+}
68883+
68884+__u32
68885+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68886+{
68887+ return 1;
68888+}
68889+
68890+__u32
68891+gr_acl_handle_hidden_file(const struct dentry * dentry,
68892+ const struct vfsmount * mnt)
68893+{
68894+ return 1;
68895+}
68896+
68897+__u32
68898+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68899+ int acc_mode)
68900+{
68901+ return 1;
68902+}
68903+
68904+__u32
68905+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68906+{
68907+ return 1;
68908+}
68909+
68910+__u32
68911+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68912+{
68913+ return 1;
68914+}
68915+
68916+int
68917+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68918+ unsigned int *vm_flags)
68919+{
68920+ return 1;
68921+}
68922+
68923+__u32
68924+gr_acl_handle_truncate(const struct dentry * dentry,
68925+ const struct vfsmount * mnt)
68926+{
68927+ return 1;
68928+}
68929+
68930+__u32
68931+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68932+{
68933+ return 1;
68934+}
68935+
68936+__u32
68937+gr_acl_handle_access(const struct dentry * dentry,
68938+ const struct vfsmount * mnt, const int fmode)
68939+{
68940+ return 1;
68941+}
68942+
68943+__u32
68944+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68945+ umode_t *mode)
68946+{
68947+ return 1;
68948+}
68949+
68950+__u32
68951+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68952+{
68953+ return 1;
68954+}
68955+
68956+__u32
68957+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68958+{
68959+ return 1;
68960+}
68961+
68962+void
68963+grsecurity_init(void)
68964+{
68965+ return;
68966+}
68967+
68968+umode_t gr_acl_umask(void)
68969+{
68970+ return 0;
68971+}
68972+
68973+__u32
68974+gr_acl_handle_mknod(const struct dentry * new_dentry,
68975+ const struct dentry * parent_dentry,
68976+ const struct vfsmount * parent_mnt,
68977+ const int mode)
68978+{
68979+ return 1;
68980+}
68981+
68982+__u32
68983+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68984+ const struct dentry * parent_dentry,
68985+ const struct vfsmount * parent_mnt)
68986+{
68987+ return 1;
68988+}
68989+
68990+__u32
68991+gr_acl_handle_symlink(const struct dentry * new_dentry,
68992+ const struct dentry * parent_dentry,
68993+ const struct vfsmount * parent_mnt, const struct filename *from)
68994+{
68995+ return 1;
68996+}
68997+
68998+__u32
68999+gr_acl_handle_link(const struct dentry * new_dentry,
69000+ const struct dentry * parent_dentry,
69001+ const struct vfsmount * parent_mnt,
69002+ const struct dentry * old_dentry,
69003+ const struct vfsmount * old_mnt, const struct filename *to)
69004+{
69005+ return 1;
69006+}
69007+
69008+int
69009+gr_acl_handle_rename(const struct dentry *new_dentry,
69010+ const struct dentry *parent_dentry,
69011+ const struct vfsmount *parent_mnt,
69012+ const struct dentry *old_dentry,
69013+ const struct inode *old_parent_inode,
69014+ const struct vfsmount *old_mnt, const struct filename *newname)
69015+{
69016+ return 0;
69017+}
69018+
69019+int
69020+gr_acl_handle_filldir(const struct file *file, const char *name,
69021+ const int namelen, const ino_t ino)
69022+{
69023+ return 1;
69024+}
69025+
69026+int
69027+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69028+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69029+{
69030+ return 1;
69031+}
69032+
69033+int
69034+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69035+{
69036+ return 0;
69037+}
69038+
69039+int
69040+gr_search_accept(const struct socket *sock)
69041+{
69042+ return 0;
69043+}
69044+
69045+int
69046+gr_search_listen(const struct socket *sock)
69047+{
69048+ return 0;
69049+}
69050+
69051+int
69052+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69053+{
69054+ return 0;
69055+}
69056+
69057+__u32
69058+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69059+{
69060+ return 1;
69061+}
69062+
69063+__u32
69064+gr_acl_handle_creat(const struct dentry * dentry,
69065+ const struct dentry * p_dentry,
69066+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69067+ const int imode)
69068+{
69069+ return 1;
69070+}
69071+
69072+void
69073+gr_acl_handle_exit(void)
69074+{
69075+ return;
69076+}
69077+
69078+int
69079+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69080+{
69081+ return 1;
69082+}
69083+
69084+void
69085+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69086+{
69087+ return;
69088+}
69089+
69090+int
69091+gr_acl_handle_procpidmem(const struct task_struct *task)
69092+{
69093+ return 0;
69094+}
69095+
69096+int
69097+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69098+{
69099+ return 0;
69100+}
69101+
69102+int
69103+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69104+{
69105+ return 0;
69106+}
69107+
69108+void
69109+gr_set_kernel_label(struct task_struct *task)
69110+{
69111+ return;
69112+}
69113+
69114+int
69115+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69116+{
69117+ return 0;
69118+}
69119+
69120+int
69121+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69122+{
69123+ return 0;
69124+}
69125+
69126+int gr_acl_enable_at_secure(void)
69127+{
69128+ return 0;
69129+}
69130+
69131+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69132+{
69133+ return dentry->d_sb->s_dev;
69134+}
69135+
69136+void gr_put_exec_file(struct task_struct *task)
69137+{
69138+ return;
69139+}
69140+
69141+EXPORT_SYMBOL(gr_set_kernel_label);
69142+#ifdef CONFIG_SECURITY
69143+EXPORT_SYMBOL(gr_check_user_change);
69144+EXPORT_SYMBOL(gr_check_group_change);
69145+#endif
69146diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69147new file mode 100644
69148index 0000000..387032b
69149--- /dev/null
69150+++ b/grsecurity/grsec_exec.c
69151@@ -0,0 +1,187 @@
69152+#include <linux/kernel.h>
69153+#include <linux/sched.h>
69154+#include <linux/file.h>
69155+#include <linux/binfmts.h>
69156+#include <linux/fs.h>
69157+#include <linux/types.h>
69158+#include <linux/grdefs.h>
69159+#include <linux/grsecurity.h>
69160+#include <linux/grinternal.h>
69161+#include <linux/capability.h>
69162+#include <linux/module.h>
69163+#include <linux/compat.h>
69164+
69165+#include <asm/uaccess.h>
69166+
69167+#ifdef CONFIG_GRKERNSEC_EXECLOG
69168+static char gr_exec_arg_buf[132];
69169+static DEFINE_MUTEX(gr_exec_arg_mutex);
69170+#endif
69171+
69172+struct user_arg_ptr {
69173+#ifdef CONFIG_COMPAT
69174+ bool is_compat;
69175+#endif
69176+ union {
69177+ const char __user *const __user *native;
69178+#ifdef CONFIG_COMPAT
69179+ const compat_uptr_t __user *compat;
69180+#endif
69181+ } ptr;
69182+};
69183+
69184+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69185+
69186+void
69187+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69188+{
69189+#ifdef CONFIG_GRKERNSEC_EXECLOG
69190+ char *grarg = gr_exec_arg_buf;
69191+ unsigned int i, x, execlen = 0;
69192+ char c;
69193+
69194+ if (!((grsec_enable_execlog && grsec_enable_group &&
69195+ in_group_p(grsec_audit_gid))
69196+ || (grsec_enable_execlog && !grsec_enable_group)))
69197+ return;
69198+
69199+ mutex_lock(&gr_exec_arg_mutex);
69200+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69201+
69202+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69203+ const char __user *p;
69204+ unsigned int len;
69205+
69206+ p = get_user_arg_ptr(argv, i);
69207+ if (IS_ERR(p))
69208+ goto log;
69209+
69210+ len = strnlen_user(p, 128 - execlen);
69211+ if (len > 128 - execlen)
69212+ len = 128 - execlen;
69213+ else if (len > 0)
69214+ len--;
69215+ if (copy_from_user(grarg + execlen, p, len))
69216+ goto log;
69217+
69218+ /* rewrite unprintable characters */
69219+ for (x = 0; x < len; x++) {
69220+ c = *(grarg + execlen + x);
69221+ if (c < 32 || c > 126)
69222+ *(grarg + execlen + x) = ' ';
69223+ }
69224+
69225+ execlen += len;
69226+ *(grarg + execlen) = ' ';
69227+ *(grarg + execlen + 1) = '\0';
69228+ execlen++;
69229+ }
69230+
69231+ log:
69232+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69233+ bprm->file->f_path.mnt, grarg);
69234+ mutex_unlock(&gr_exec_arg_mutex);
69235+#endif
69236+ return;
69237+}
69238+
69239+#ifdef CONFIG_GRKERNSEC
69240+extern int gr_acl_is_capable(const int cap);
69241+extern int gr_acl_is_capable_nolog(const int cap);
69242+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69243+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69244+extern int gr_chroot_is_capable(const int cap);
69245+extern int gr_chroot_is_capable_nolog(const int cap);
69246+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69247+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69248+#endif
69249+
69250+const char *captab_log[] = {
69251+ "CAP_CHOWN",
69252+ "CAP_DAC_OVERRIDE",
69253+ "CAP_DAC_READ_SEARCH",
69254+ "CAP_FOWNER",
69255+ "CAP_FSETID",
69256+ "CAP_KILL",
69257+ "CAP_SETGID",
69258+ "CAP_SETUID",
69259+ "CAP_SETPCAP",
69260+ "CAP_LINUX_IMMUTABLE",
69261+ "CAP_NET_BIND_SERVICE",
69262+ "CAP_NET_BROADCAST",
69263+ "CAP_NET_ADMIN",
69264+ "CAP_NET_RAW",
69265+ "CAP_IPC_LOCK",
69266+ "CAP_IPC_OWNER",
69267+ "CAP_SYS_MODULE",
69268+ "CAP_SYS_RAWIO",
69269+ "CAP_SYS_CHROOT",
69270+ "CAP_SYS_PTRACE",
69271+ "CAP_SYS_PACCT",
69272+ "CAP_SYS_ADMIN",
69273+ "CAP_SYS_BOOT",
69274+ "CAP_SYS_NICE",
69275+ "CAP_SYS_RESOURCE",
69276+ "CAP_SYS_TIME",
69277+ "CAP_SYS_TTY_CONFIG",
69278+ "CAP_MKNOD",
69279+ "CAP_LEASE",
69280+ "CAP_AUDIT_WRITE",
69281+ "CAP_AUDIT_CONTROL",
69282+ "CAP_SETFCAP",
69283+ "CAP_MAC_OVERRIDE",
69284+ "CAP_MAC_ADMIN",
69285+ "CAP_SYSLOG",
69286+ "CAP_WAKE_ALARM"
69287+};
69288+
69289+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69290+
69291+int gr_is_capable(const int cap)
69292+{
69293+#ifdef CONFIG_GRKERNSEC
69294+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69295+ return 1;
69296+ return 0;
69297+#else
69298+ return 1;
69299+#endif
69300+}
69301+
69302+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69303+{
69304+#ifdef CONFIG_GRKERNSEC
69305+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69306+ return 1;
69307+ return 0;
69308+#else
69309+ return 1;
69310+#endif
69311+}
69312+
69313+int gr_is_capable_nolog(const int cap)
69314+{
69315+#ifdef CONFIG_GRKERNSEC
69316+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69317+ return 1;
69318+ return 0;
69319+#else
69320+ return 1;
69321+#endif
69322+}
69323+
69324+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69325+{
69326+#ifdef CONFIG_GRKERNSEC
69327+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69328+ return 1;
69329+ return 0;
69330+#else
69331+ return 1;
69332+#endif
69333+}
69334+
69335+EXPORT_SYMBOL(gr_is_capable);
69336+EXPORT_SYMBOL(gr_is_capable_nolog);
69337+EXPORT_SYMBOL(gr_task_is_capable);
69338+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69339diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69340new file mode 100644
69341index 0000000..06cc6ea
69342--- /dev/null
69343+++ b/grsecurity/grsec_fifo.c
69344@@ -0,0 +1,24 @@
69345+#include <linux/kernel.h>
69346+#include <linux/sched.h>
69347+#include <linux/fs.h>
69348+#include <linux/file.h>
69349+#include <linux/grinternal.h>
69350+
69351+int
69352+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69353+ const struct dentry *dir, const int flag, const int acc_mode)
69354+{
69355+#ifdef CONFIG_GRKERNSEC_FIFO
69356+ const struct cred *cred = current_cred();
69357+
69358+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69359+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69360+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69361+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69362+ if (!inode_permission(dentry->d_inode, acc_mode))
69363+ 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));
69364+ return -EACCES;
69365+ }
69366+#endif
69367+ return 0;
69368+}
69369diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69370new file mode 100644
69371index 0000000..8ca18bf
69372--- /dev/null
69373+++ b/grsecurity/grsec_fork.c
69374@@ -0,0 +1,23 @@
69375+#include <linux/kernel.h>
69376+#include <linux/sched.h>
69377+#include <linux/grsecurity.h>
69378+#include <linux/grinternal.h>
69379+#include <linux/errno.h>
69380+
69381+void
69382+gr_log_forkfail(const int retval)
69383+{
69384+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69385+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69386+ switch (retval) {
69387+ case -EAGAIN:
69388+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69389+ break;
69390+ case -ENOMEM:
69391+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69392+ break;
69393+ }
69394+ }
69395+#endif
69396+ return;
69397+}
69398diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69399new file mode 100644
69400index 0000000..99a0cb9
69401--- /dev/null
69402+++ b/grsecurity/grsec_init.c
69403@@ -0,0 +1,283 @@
69404+#include <linux/kernel.h>
69405+#include <linux/sched.h>
69406+#include <linux/mm.h>
69407+#include <linux/gracl.h>
69408+#include <linux/slab.h>
69409+#include <linux/vmalloc.h>
69410+#include <linux/percpu.h>
69411+#include <linux/module.h>
69412+
69413+int grsec_enable_ptrace_readexec;
69414+int grsec_enable_setxid;
69415+int grsec_enable_symlinkown;
69416+kgid_t grsec_symlinkown_gid;
69417+int grsec_enable_brute;
69418+int grsec_enable_link;
69419+int grsec_enable_dmesg;
69420+int grsec_enable_harden_ptrace;
69421+int grsec_enable_fifo;
69422+int grsec_enable_execlog;
69423+int grsec_enable_signal;
69424+int grsec_enable_forkfail;
69425+int grsec_enable_audit_ptrace;
69426+int grsec_enable_time;
69427+int grsec_enable_group;
69428+kgid_t grsec_audit_gid;
69429+int grsec_enable_chdir;
69430+int grsec_enable_mount;
69431+int grsec_enable_rofs;
69432+int grsec_deny_new_usb;
69433+int grsec_enable_chroot_findtask;
69434+int grsec_enable_chroot_mount;
69435+int grsec_enable_chroot_shmat;
69436+int grsec_enable_chroot_fchdir;
69437+int grsec_enable_chroot_double;
69438+int grsec_enable_chroot_pivot;
69439+int grsec_enable_chroot_chdir;
69440+int grsec_enable_chroot_chmod;
69441+int grsec_enable_chroot_mknod;
69442+int grsec_enable_chroot_nice;
69443+int grsec_enable_chroot_execlog;
69444+int grsec_enable_chroot_caps;
69445+int grsec_enable_chroot_sysctl;
69446+int grsec_enable_chroot_unix;
69447+int grsec_enable_tpe;
69448+kgid_t grsec_tpe_gid;
69449+int grsec_enable_blackhole;
69450+#ifdef CONFIG_IPV6_MODULE
69451+EXPORT_SYMBOL(grsec_enable_blackhole);
69452+#endif
69453+int grsec_lastack_retries;
69454+int grsec_enable_tpe_all;
69455+int grsec_enable_tpe_invert;
69456+int grsec_enable_socket_all;
69457+kgid_t grsec_socket_all_gid;
69458+int grsec_enable_socket_client;
69459+kgid_t grsec_socket_client_gid;
69460+int grsec_enable_socket_server;
69461+kgid_t grsec_socket_server_gid;
69462+int grsec_resource_logging;
69463+int grsec_disable_privio;
69464+int grsec_enable_log_rwxmaps;
69465+int grsec_lock;
69466+
69467+DEFINE_SPINLOCK(grsec_alert_lock);
69468+unsigned long grsec_alert_wtime = 0;
69469+unsigned long grsec_alert_fyet = 0;
69470+
69471+DEFINE_SPINLOCK(grsec_audit_lock);
69472+
69473+DEFINE_RWLOCK(grsec_exec_file_lock);
69474+
69475+char *gr_shared_page[4];
69476+
69477+char *gr_alert_log_fmt;
69478+char *gr_audit_log_fmt;
69479+char *gr_alert_log_buf;
69480+char *gr_audit_log_buf;
69481+
69482+extern struct gr_arg *gr_usermode;
69483+extern unsigned char *gr_system_salt;
69484+extern unsigned char *gr_system_sum;
69485+
69486+void __init
69487+grsecurity_init(void)
69488+{
69489+ int j;
69490+ /* create the per-cpu shared pages */
69491+
69492+#ifdef CONFIG_X86
69493+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69494+#endif
69495+
69496+ for (j = 0; j < 4; j++) {
69497+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69498+ if (gr_shared_page[j] == NULL) {
69499+ panic("Unable to allocate grsecurity shared page");
69500+ return;
69501+ }
69502+ }
69503+
69504+ /* allocate log buffers */
69505+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69506+ if (!gr_alert_log_fmt) {
69507+ panic("Unable to allocate grsecurity alert log format buffer");
69508+ return;
69509+ }
69510+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69511+ if (!gr_audit_log_fmt) {
69512+ panic("Unable to allocate grsecurity audit log format buffer");
69513+ return;
69514+ }
69515+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69516+ if (!gr_alert_log_buf) {
69517+ panic("Unable to allocate grsecurity alert log buffer");
69518+ return;
69519+ }
69520+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69521+ if (!gr_audit_log_buf) {
69522+ panic("Unable to allocate grsecurity audit log buffer");
69523+ return;
69524+ }
69525+
69526+ /* allocate memory for authentication structure */
69527+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69528+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69529+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69530+
69531+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69532+ panic("Unable to allocate grsecurity authentication structure");
69533+ return;
69534+ }
69535+
69536+
69537+#ifdef CONFIG_GRKERNSEC_IO
69538+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69539+ grsec_disable_privio = 1;
69540+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69541+ grsec_disable_privio = 1;
69542+#else
69543+ grsec_disable_privio = 0;
69544+#endif
69545+#endif
69546+
69547+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69548+ /* for backward compatibility, tpe_invert always defaults to on if
69549+ enabled in the kernel
69550+ */
69551+ grsec_enable_tpe_invert = 1;
69552+#endif
69553+
69554+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69555+#ifndef CONFIG_GRKERNSEC_SYSCTL
69556+ grsec_lock = 1;
69557+#endif
69558+
69559+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69560+ grsec_enable_log_rwxmaps = 1;
69561+#endif
69562+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69563+ grsec_enable_group = 1;
69564+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69565+#endif
69566+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69567+ grsec_enable_ptrace_readexec = 1;
69568+#endif
69569+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69570+ grsec_enable_chdir = 1;
69571+#endif
69572+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69573+ grsec_enable_harden_ptrace = 1;
69574+#endif
69575+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69576+ grsec_enable_mount = 1;
69577+#endif
69578+#ifdef CONFIG_GRKERNSEC_LINK
69579+ grsec_enable_link = 1;
69580+#endif
69581+#ifdef CONFIG_GRKERNSEC_BRUTE
69582+ grsec_enable_brute = 1;
69583+#endif
69584+#ifdef CONFIG_GRKERNSEC_DMESG
69585+ grsec_enable_dmesg = 1;
69586+#endif
69587+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69588+ grsec_enable_blackhole = 1;
69589+ grsec_lastack_retries = 4;
69590+#endif
69591+#ifdef CONFIG_GRKERNSEC_FIFO
69592+ grsec_enable_fifo = 1;
69593+#endif
69594+#ifdef CONFIG_GRKERNSEC_EXECLOG
69595+ grsec_enable_execlog = 1;
69596+#endif
69597+#ifdef CONFIG_GRKERNSEC_SETXID
69598+ grsec_enable_setxid = 1;
69599+#endif
69600+#ifdef CONFIG_GRKERNSEC_SIGNAL
69601+ grsec_enable_signal = 1;
69602+#endif
69603+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69604+ grsec_enable_forkfail = 1;
69605+#endif
69606+#ifdef CONFIG_GRKERNSEC_TIME
69607+ grsec_enable_time = 1;
69608+#endif
69609+#ifdef CONFIG_GRKERNSEC_RESLOG
69610+ grsec_resource_logging = 1;
69611+#endif
69612+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69613+ grsec_enable_chroot_findtask = 1;
69614+#endif
69615+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69616+ grsec_enable_chroot_unix = 1;
69617+#endif
69618+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69619+ grsec_enable_chroot_mount = 1;
69620+#endif
69621+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69622+ grsec_enable_chroot_fchdir = 1;
69623+#endif
69624+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69625+ grsec_enable_chroot_shmat = 1;
69626+#endif
69627+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69628+ grsec_enable_audit_ptrace = 1;
69629+#endif
69630+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69631+ grsec_enable_chroot_double = 1;
69632+#endif
69633+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69634+ grsec_enable_chroot_pivot = 1;
69635+#endif
69636+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69637+ grsec_enable_chroot_chdir = 1;
69638+#endif
69639+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69640+ grsec_enable_chroot_chmod = 1;
69641+#endif
69642+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69643+ grsec_enable_chroot_mknod = 1;
69644+#endif
69645+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69646+ grsec_enable_chroot_nice = 1;
69647+#endif
69648+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69649+ grsec_enable_chroot_execlog = 1;
69650+#endif
69651+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69652+ grsec_enable_chroot_caps = 1;
69653+#endif
69654+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69655+ grsec_enable_chroot_sysctl = 1;
69656+#endif
69657+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69658+ grsec_enable_symlinkown = 1;
69659+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69660+#endif
69661+#ifdef CONFIG_GRKERNSEC_TPE
69662+ grsec_enable_tpe = 1;
69663+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69664+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69665+ grsec_enable_tpe_all = 1;
69666+#endif
69667+#endif
69668+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69669+ grsec_enable_socket_all = 1;
69670+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69671+#endif
69672+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69673+ grsec_enable_socket_client = 1;
69674+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69675+#endif
69676+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69677+ grsec_enable_socket_server = 1;
69678+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69679+#endif
69680+#endif
69681+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69682+ grsec_deny_new_usb = 1;
69683+#endif
69684+
69685+ return;
69686+}
69687diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69688new file mode 100644
69689index 0000000..5e05e20
69690--- /dev/null
69691+++ b/grsecurity/grsec_link.c
69692@@ -0,0 +1,58 @@
69693+#include <linux/kernel.h>
69694+#include <linux/sched.h>
69695+#include <linux/fs.h>
69696+#include <linux/file.h>
69697+#include <linux/grinternal.h>
69698+
69699+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69700+{
69701+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69702+ const struct inode *link_inode = link->dentry->d_inode;
69703+
69704+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69705+ /* ignore root-owned links, e.g. /proc/self */
69706+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69707+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69708+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69709+ return 1;
69710+ }
69711+#endif
69712+ return 0;
69713+}
69714+
69715+int
69716+gr_handle_follow_link(const struct inode *parent,
69717+ const struct inode *inode,
69718+ const struct dentry *dentry, const struct vfsmount *mnt)
69719+{
69720+#ifdef CONFIG_GRKERNSEC_LINK
69721+ const struct cred *cred = current_cred();
69722+
69723+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69724+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69725+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69726+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69727+ return -EACCES;
69728+ }
69729+#endif
69730+ return 0;
69731+}
69732+
69733+int
69734+gr_handle_hardlink(const struct dentry *dentry,
69735+ const struct vfsmount *mnt,
69736+ struct inode *inode, const int mode, const struct filename *to)
69737+{
69738+#ifdef CONFIG_GRKERNSEC_LINK
69739+ const struct cred *cred = current_cred();
69740+
69741+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69742+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69743+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69744+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69745+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69746+ return -EPERM;
69747+ }
69748+#endif
69749+ return 0;
69750+}
69751diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69752new file mode 100644
69753index 0000000..dbe0a6b
69754--- /dev/null
69755+++ b/grsecurity/grsec_log.c
69756@@ -0,0 +1,341 @@
69757+#include <linux/kernel.h>
69758+#include <linux/sched.h>
69759+#include <linux/file.h>
69760+#include <linux/tty.h>
69761+#include <linux/fs.h>
69762+#include <linux/mm.h>
69763+#include <linux/grinternal.h>
69764+
69765+#ifdef CONFIG_TREE_PREEMPT_RCU
69766+#define DISABLE_PREEMPT() preempt_disable()
69767+#define ENABLE_PREEMPT() preempt_enable()
69768+#else
69769+#define DISABLE_PREEMPT()
69770+#define ENABLE_PREEMPT()
69771+#endif
69772+
69773+#define BEGIN_LOCKS(x) \
69774+ DISABLE_PREEMPT(); \
69775+ rcu_read_lock(); \
69776+ read_lock(&tasklist_lock); \
69777+ read_lock(&grsec_exec_file_lock); \
69778+ if (x != GR_DO_AUDIT) \
69779+ spin_lock(&grsec_alert_lock); \
69780+ else \
69781+ spin_lock(&grsec_audit_lock)
69782+
69783+#define END_LOCKS(x) \
69784+ if (x != GR_DO_AUDIT) \
69785+ spin_unlock(&grsec_alert_lock); \
69786+ else \
69787+ spin_unlock(&grsec_audit_lock); \
69788+ read_unlock(&grsec_exec_file_lock); \
69789+ read_unlock(&tasklist_lock); \
69790+ rcu_read_unlock(); \
69791+ ENABLE_PREEMPT(); \
69792+ if (x == GR_DONT_AUDIT) \
69793+ gr_handle_alertkill(current)
69794+
69795+enum {
69796+ FLOODING,
69797+ NO_FLOODING
69798+};
69799+
69800+extern char *gr_alert_log_fmt;
69801+extern char *gr_audit_log_fmt;
69802+extern char *gr_alert_log_buf;
69803+extern char *gr_audit_log_buf;
69804+
69805+static int gr_log_start(int audit)
69806+{
69807+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69808+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69809+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69810+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69811+ unsigned long curr_secs = get_seconds();
69812+
69813+ if (audit == GR_DO_AUDIT)
69814+ goto set_fmt;
69815+
69816+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69817+ grsec_alert_wtime = curr_secs;
69818+ grsec_alert_fyet = 0;
69819+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69820+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69821+ grsec_alert_fyet++;
69822+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69823+ grsec_alert_wtime = curr_secs;
69824+ grsec_alert_fyet++;
69825+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69826+ return FLOODING;
69827+ }
69828+ else return FLOODING;
69829+
69830+set_fmt:
69831+#endif
69832+ memset(buf, 0, PAGE_SIZE);
69833+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69834+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69835+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69836+ } else if (current->signal->curr_ip) {
69837+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69838+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69839+ } else if (gr_acl_is_enabled()) {
69840+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69841+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69842+ } else {
69843+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69844+ strcpy(buf, fmt);
69845+ }
69846+
69847+ return NO_FLOODING;
69848+}
69849+
69850+static void gr_log_middle(int audit, const char *msg, va_list ap)
69851+ __attribute__ ((format (printf, 2, 0)));
69852+
69853+static void gr_log_middle(int audit, const char *msg, va_list ap)
69854+{
69855+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69856+ unsigned int len = strlen(buf);
69857+
69858+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69859+
69860+ return;
69861+}
69862+
69863+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69864+ __attribute__ ((format (printf, 2, 3)));
69865+
69866+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69867+{
69868+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69869+ unsigned int len = strlen(buf);
69870+ va_list ap;
69871+
69872+ va_start(ap, msg);
69873+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69874+ va_end(ap);
69875+
69876+ return;
69877+}
69878+
69879+static void gr_log_end(int audit, int append_default)
69880+{
69881+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69882+ if (append_default) {
69883+ struct task_struct *task = current;
69884+ struct task_struct *parent = task->real_parent;
69885+ const struct cred *cred = __task_cred(task);
69886+ const struct cred *pcred = __task_cred(parent);
69887+ unsigned int len = strlen(buf);
69888+
69889+ 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));
69890+ }
69891+
69892+ printk("%s\n", buf);
69893+
69894+ return;
69895+}
69896+
69897+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69898+{
69899+ int logtype;
69900+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69901+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69902+ void *voidptr = NULL;
69903+ int num1 = 0, num2 = 0;
69904+ unsigned long ulong1 = 0, ulong2 = 0;
69905+ struct dentry *dentry = NULL;
69906+ struct vfsmount *mnt = NULL;
69907+ struct file *file = NULL;
69908+ struct task_struct *task = NULL;
69909+ struct vm_area_struct *vma = NULL;
69910+ const struct cred *cred, *pcred;
69911+ va_list ap;
69912+
69913+ BEGIN_LOCKS(audit);
69914+ logtype = gr_log_start(audit);
69915+ if (logtype == FLOODING) {
69916+ END_LOCKS(audit);
69917+ return;
69918+ }
69919+ va_start(ap, argtypes);
69920+ switch (argtypes) {
69921+ case GR_TTYSNIFF:
69922+ task = va_arg(ap, struct task_struct *);
69923+ 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));
69924+ break;
69925+ case GR_SYSCTL_HIDDEN:
69926+ str1 = va_arg(ap, char *);
69927+ gr_log_middle_varargs(audit, msg, result, str1);
69928+ break;
69929+ case GR_RBAC:
69930+ dentry = va_arg(ap, struct dentry *);
69931+ mnt = va_arg(ap, struct vfsmount *);
69932+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69933+ break;
69934+ case GR_RBAC_STR:
69935+ dentry = va_arg(ap, struct dentry *);
69936+ mnt = va_arg(ap, struct vfsmount *);
69937+ str1 = va_arg(ap, char *);
69938+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69939+ break;
69940+ case GR_STR_RBAC:
69941+ str1 = va_arg(ap, char *);
69942+ dentry = va_arg(ap, struct dentry *);
69943+ mnt = va_arg(ap, struct vfsmount *);
69944+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69945+ break;
69946+ case GR_RBAC_MODE2:
69947+ dentry = va_arg(ap, struct dentry *);
69948+ mnt = va_arg(ap, struct vfsmount *);
69949+ str1 = va_arg(ap, char *);
69950+ str2 = va_arg(ap, char *);
69951+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69952+ break;
69953+ case GR_RBAC_MODE3:
69954+ dentry = va_arg(ap, struct dentry *);
69955+ mnt = va_arg(ap, struct vfsmount *);
69956+ str1 = va_arg(ap, char *);
69957+ str2 = va_arg(ap, char *);
69958+ str3 = va_arg(ap, char *);
69959+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69960+ break;
69961+ case GR_FILENAME:
69962+ dentry = va_arg(ap, struct dentry *);
69963+ mnt = va_arg(ap, struct vfsmount *);
69964+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69965+ break;
69966+ case GR_STR_FILENAME:
69967+ str1 = va_arg(ap, char *);
69968+ dentry = va_arg(ap, struct dentry *);
69969+ mnt = va_arg(ap, struct vfsmount *);
69970+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69971+ break;
69972+ case GR_FILENAME_STR:
69973+ dentry = va_arg(ap, struct dentry *);
69974+ mnt = va_arg(ap, struct vfsmount *);
69975+ str1 = va_arg(ap, char *);
69976+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69977+ break;
69978+ case GR_FILENAME_TWO_INT:
69979+ dentry = va_arg(ap, struct dentry *);
69980+ mnt = va_arg(ap, struct vfsmount *);
69981+ num1 = va_arg(ap, int);
69982+ num2 = va_arg(ap, int);
69983+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69984+ break;
69985+ case GR_FILENAME_TWO_INT_STR:
69986+ dentry = va_arg(ap, struct dentry *);
69987+ mnt = va_arg(ap, struct vfsmount *);
69988+ num1 = va_arg(ap, int);
69989+ num2 = va_arg(ap, int);
69990+ str1 = va_arg(ap, char *);
69991+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69992+ break;
69993+ case GR_TEXTREL:
69994+ file = va_arg(ap, struct file *);
69995+ ulong1 = va_arg(ap, unsigned long);
69996+ ulong2 = va_arg(ap, unsigned long);
69997+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69998+ break;
69999+ case GR_PTRACE:
70000+ task = va_arg(ap, struct task_struct *);
70001+ 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));
70002+ break;
70003+ case GR_RESOURCE:
70004+ task = va_arg(ap, struct task_struct *);
70005+ cred = __task_cred(task);
70006+ pcred = __task_cred(task->real_parent);
70007+ ulong1 = va_arg(ap, unsigned long);
70008+ str1 = va_arg(ap, char *);
70009+ ulong2 = va_arg(ap, unsigned long);
70010+ 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));
70011+ break;
70012+ case GR_CAP:
70013+ task = va_arg(ap, struct task_struct *);
70014+ cred = __task_cred(task);
70015+ pcred = __task_cred(task->real_parent);
70016+ str1 = va_arg(ap, char *);
70017+ 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));
70018+ break;
70019+ case GR_SIG:
70020+ str1 = va_arg(ap, char *);
70021+ voidptr = va_arg(ap, void *);
70022+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70023+ break;
70024+ case GR_SIG2:
70025+ task = va_arg(ap, struct task_struct *);
70026+ cred = __task_cred(task);
70027+ pcred = __task_cred(task->real_parent);
70028+ num1 = va_arg(ap, int);
70029+ 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));
70030+ break;
70031+ case GR_CRASH1:
70032+ task = va_arg(ap, struct task_struct *);
70033+ cred = __task_cred(task);
70034+ pcred = __task_cred(task->real_parent);
70035+ ulong1 = va_arg(ap, unsigned long);
70036+ 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);
70037+ break;
70038+ case GR_CRASH2:
70039+ task = va_arg(ap, struct task_struct *);
70040+ cred = __task_cred(task);
70041+ pcred = __task_cred(task->real_parent);
70042+ ulong1 = va_arg(ap, unsigned long);
70043+ 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);
70044+ break;
70045+ case GR_RWXMAP:
70046+ file = va_arg(ap, struct file *);
70047+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70048+ break;
70049+ case GR_RWXMAPVMA:
70050+ vma = va_arg(ap, struct vm_area_struct *);
70051+ if (vma->vm_file)
70052+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70053+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70054+ str1 = "<stack>";
70055+ else if (vma->vm_start <= current->mm->brk &&
70056+ vma->vm_end >= current->mm->start_brk)
70057+ str1 = "<heap>";
70058+ else
70059+ str1 = "<anonymous mapping>";
70060+ gr_log_middle_varargs(audit, msg, str1);
70061+ break;
70062+ case GR_PSACCT:
70063+ {
70064+ unsigned int wday, cday;
70065+ __u8 whr, chr;
70066+ __u8 wmin, cmin;
70067+ __u8 wsec, csec;
70068+ char cur_tty[64] = { 0 };
70069+ char parent_tty[64] = { 0 };
70070+
70071+ task = va_arg(ap, struct task_struct *);
70072+ wday = va_arg(ap, unsigned int);
70073+ cday = va_arg(ap, unsigned int);
70074+ whr = va_arg(ap, int);
70075+ chr = va_arg(ap, int);
70076+ wmin = va_arg(ap, int);
70077+ cmin = va_arg(ap, int);
70078+ wsec = va_arg(ap, int);
70079+ csec = va_arg(ap, int);
70080+ ulong1 = va_arg(ap, unsigned long);
70081+ cred = __task_cred(task);
70082+ pcred = __task_cred(task->real_parent);
70083+
70084+ 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));
70085+ }
70086+ break;
70087+ default:
70088+ gr_log_middle(audit, msg, ap);
70089+ }
70090+ va_end(ap);
70091+ // these don't need DEFAULTSECARGS printed on the end
70092+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70093+ gr_log_end(audit, 0);
70094+ else
70095+ gr_log_end(audit, 1);
70096+ END_LOCKS(audit);
70097+}
70098diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70099new file mode 100644
70100index 0000000..f536303
70101--- /dev/null
70102+++ b/grsecurity/grsec_mem.c
70103@@ -0,0 +1,40 @@
70104+#include <linux/kernel.h>
70105+#include <linux/sched.h>
70106+#include <linux/mm.h>
70107+#include <linux/mman.h>
70108+#include <linux/grinternal.h>
70109+
70110+void
70111+gr_handle_ioperm(void)
70112+{
70113+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70114+ return;
70115+}
70116+
70117+void
70118+gr_handle_iopl(void)
70119+{
70120+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70121+ return;
70122+}
70123+
70124+void
70125+gr_handle_mem_readwrite(u64 from, u64 to)
70126+{
70127+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70128+ return;
70129+}
70130+
70131+void
70132+gr_handle_vm86(void)
70133+{
70134+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70135+ return;
70136+}
70137+
70138+void
70139+gr_log_badprocpid(const char *entry)
70140+{
70141+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70142+ return;
70143+}
70144diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70145new file mode 100644
70146index 0000000..2131422
70147--- /dev/null
70148+++ b/grsecurity/grsec_mount.c
70149@@ -0,0 +1,62 @@
70150+#include <linux/kernel.h>
70151+#include <linux/sched.h>
70152+#include <linux/mount.h>
70153+#include <linux/grsecurity.h>
70154+#include <linux/grinternal.h>
70155+
70156+void
70157+gr_log_remount(const char *devname, const int retval)
70158+{
70159+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70160+ if (grsec_enable_mount && (retval >= 0))
70161+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70162+#endif
70163+ return;
70164+}
70165+
70166+void
70167+gr_log_unmount(const char *devname, const int retval)
70168+{
70169+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70170+ if (grsec_enable_mount && (retval >= 0))
70171+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70172+#endif
70173+ return;
70174+}
70175+
70176+void
70177+gr_log_mount(const char *from, const char *to, const int retval)
70178+{
70179+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70180+ if (grsec_enable_mount && (retval >= 0))
70181+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70182+#endif
70183+ return;
70184+}
70185+
70186+int
70187+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70188+{
70189+#ifdef CONFIG_GRKERNSEC_ROFS
70190+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70191+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70192+ return -EPERM;
70193+ } else
70194+ return 0;
70195+#endif
70196+ return 0;
70197+}
70198+
70199+int
70200+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70201+{
70202+#ifdef CONFIG_GRKERNSEC_ROFS
70203+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70204+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70205+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70206+ return -EPERM;
70207+ } else
70208+ return 0;
70209+#endif
70210+ return 0;
70211+}
70212diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70213new file mode 100644
70214index 0000000..6ee9d50
70215--- /dev/null
70216+++ b/grsecurity/grsec_pax.c
70217@@ -0,0 +1,45 @@
70218+#include <linux/kernel.h>
70219+#include <linux/sched.h>
70220+#include <linux/mm.h>
70221+#include <linux/file.h>
70222+#include <linux/grinternal.h>
70223+#include <linux/grsecurity.h>
70224+
70225+void
70226+gr_log_textrel(struct vm_area_struct * vma)
70227+{
70228+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70229+ if (grsec_enable_log_rwxmaps)
70230+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70231+#endif
70232+ return;
70233+}
70234+
70235+void gr_log_ptgnustack(struct file *file)
70236+{
70237+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70238+ if (grsec_enable_log_rwxmaps)
70239+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70240+#endif
70241+ return;
70242+}
70243+
70244+void
70245+gr_log_rwxmmap(struct file *file)
70246+{
70247+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70248+ if (grsec_enable_log_rwxmaps)
70249+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70250+#endif
70251+ return;
70252+}
70253+
70254+void
70255+gr_log_rwxmprotect(struct vm_area_struct *vma)
70256+{
70257+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70258+ if (grsec_enable_log_rwxmaps)
70259+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70260+#endif
70261+ return;
70262+}
70263diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70264new file mode 100644
70265index 0000000..f7f29aa
70266--- /dev/null
70267+++ b/grsecurity/grsec_ptrace.c
70268@@ -0,0 +1,30 @@
70269+#include <linux/kernel.h>
70270+#include <linux/sched.h>
70271+#include <linux/grinternal.h>
70272+#include <linux/security.h>
70273+
70274+void
70275+gr_audit_ptrace(struct task_struct *task)
70276+{
70277+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70278+ if (grsec_enable_audit_ptrace)
70279+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70280+#endif
70281+ return;
70282+}
70283+
70284+int
70285+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70286+{
70287+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70288+ const struct dentry *dentry = file->f_path.dentry;
70289+ const struct vfsmount *mnt = file->f_path.mnt;
70290+
70291+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70292+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70293+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70294+ return -EACCES;
70295+ }
70296+#endif
70297+ return 0;
70298+}
70299diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70300new file mode 100644
70301index 0000000..4e29cc7
70302--- /dev/null
70303+++ b/grsecurity/grsec_sig.c
70304@@ -0,0 +1,246 @@
70305+#include <linux/kernel.h>
70306+#include <linux/sched.h>
70307+#include <linux/fs.h>
70308+#include <linux/delay.h>
70309+#include <linux/grsecurity.h>
70310+#include <linux/grinternal.h>
70311+#include <linux/hardirq.h>
70312+
70313+char *signames[] = {
70314+ [SIGSEGV] = "Segmentation fault",
70315+ [SIGILL] = "Illegal instruction",
70316+ [SIGABRT] = "Abort",
70317+ [SIGBUS] = "Invalid alignment/Bus error"
70318+};
70319+
70320+void
70321+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70322+{
70323+#ifdef CONFIG_GRKERNSEC_SIGNAL
70324+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70325+ (sig == SIGABRT) || (sig == SIGBUS))) {
70326+ if (task_pid_nr(t) == task_pid_nr(current)) {
70327+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70328+ } else {
70329+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70330+ }
70331+ }
70332+#endif
70333+ return;
70334+}
70335+
70336+int
70337+gr_handle_signal(const struct task_struct *p, const int sig)
70338+{
70339+#ifdef CONFIG_GRKERNSEC
70340+ /* ignore the 0 signal for protected task checks */
70341+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70342+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70343+ return -EPERM;
70344+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70345+ return -EPERM;
70346+ }
70347+#endif
70348+ return 0;
70349+}
70350+
70351+#ifdef CONFIG_GRKERNSEC
70352+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70353+
70354+int gr_fake_force_sig(int sig, struct task_struct *t)
70355+{
70356+ unsigned long int flags;
70357+ int ret, blocked, ignored;
70358+ struct k_sigaction *action;
70359+
70360+ spin_lock_irqsave(&t->sighand->siglock, flags);
70361+ action = &t->sighand->action[sig-1];
70362+ ignored = action->sa.sa_handler == SIG_IGN;
70363+ blocked = sigismember(&t->blocked, sig);
70364+ if (blocked || ignored) {
70365+ action->sa.sa_handler = SIG_DFL;
70366+ if (blocked) {
70367+ sigdelset(&t->blocked, sig);
70368+ recalc_sigpending_and_wake(t);
70369+ }
70370+ }
70371+ if (action->sa.sa_handler == SIG_DFL)
70372+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70373+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70374+
70375+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70376+
70377+ return ret;
70378+}
70379+#endif
70380+
70381+#ifdef CONFIG_GRKERNSEC_BRUTE
70382+#define GR_USER_BAN_TIME (15 * 60)
70383+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70384+
70385+static int __get_dumpable(unsigned long mm_flags)
70386+{
70387+ int ret;
70388+
70389+ ret = mm_flags & MMF_DUMPABLE_MASK;
70390+ return (ret >= 2) ? 2 : ret;
70391+}
70392+#endif
70393+
70394+void gr_handle_brute_attach(unsigned long mm_flags)
70395+{
70396+#ifdef CONFIG_GRKERNSEC_BRUTE
70397+ struct task_struct *p = current;
70398+ kuid_t uid = GLOBAL_ROOT_UID;
70399+ int daemon = 0;
70400+
70401+ if (!grsec_enable_brute)
70402+ return;
70403+
70404+ rcu_read_lock();
70405+ read_lock(&tasklist_lock);
70406+ read_lock(&grsec_exec_file_lock);
70407+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70408+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70409+ p->real_parent->brute = 1;
70410+ daemon = 1;
70411+ } else {
70412+ const struct cred *cred = __task_cred(p), *cred2;
70413+ struct task_struct *tsk, *tsk2;
70414+
70415+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70416+ struct user_struct *user;
70417+
70418+ uid = cred->uid;
70419+
70420+ /* this is put upon execution past expiration */
70421+ user = find_user(uid);
70422+ if (user == NULL)
70423+ goto unlock;
70424+ user->suid_banned = 1;
70425+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70426+ if (user->suid_ban_expires == ~0UL)
70427+ user->suid_ban_expires--;
70428+
70429+ /* only kill other threads of the same binary, from the same user */
70430+ do_each_thread(tsk2, tsk) {
70431+ cred2 = __task_cred(tsk);
70432+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70433+ gr_fake_force_sig(SIGKILL, tsk);
70434+ } while_each_thread(tsk2, tsk);
70435+ }
70436+ }
70437+unlock:
70438+ read_unlock(&grsec_exec_file_lock);
70439+ read_unlock(&tasklist_lock);
70440+ rcu_read_unlock();
70441+
70442+ if (gr_is_global_nonroot(uid))
70443+ 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);
70444+ else if (daemon)
70445+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70446+
70447+#endif
70448+ return;
70449+}
70450+
70451+void gr_handle_brute_check(void)
70452+{
70453+#ifdef CONFIG_GRKERNSEC_BRUTE
70454+ struct task_struct *p = current;
70455+
70456+ if (unlikely(p->brute)) {
70457+ if (!grsec_enable_brute)
70458+ p->brute = 0;
70459+ else if (time_before(get_seconds(), p->brute_expires))
70460+ msleep(30 * 1000);
70461+ }
70462+#endif
70463+ return;
70464+}
70465+
70466+void gr_handle_kernel_exploit(void)
70467+{
70468+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70469+ const struct cred *cred;
70470+ struct task_struct *tsk, *tsk2;
70471+ struct user_struct *user;
70472+ kuid_t uid;
70473+
70474+ if (in_irq() || in_serving_softirq() || in_nmi())
70475+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70476+
70477+ uid = current_uid();
70478+
70479+ if (gr_is_global_root(uid))
70480+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70481+ else {
70482+ /* kill all the processes of this user, hold a reference
70483+ to their creds struct, and prevent them from creating
70484+ another process until system reset
70485+ */
70486+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70487+ GR_GLOBAL_UID(uid));
70488+ /* we intentionally leak this ref */
70489+ user = get_uid(current->cred->user);
70490+ if (user)
70491+ user->kernel_banned = 1;
70492+
70493+ /* kill all processes of this user */
70494+ read_lock(&tasklist_lock);
70495+ do_each_thread(tsk2, tsk) {
70496+ cred = __task_cred(tsk);
70497+ if (uid_eq(cred->uid, uid))
70498+ gr_fake_force_sig(SIGKILL, tsk);
70499+ } while_each_thread(tsk2, tsk);
70500+ read_unlock(&tasklist_lock);
70501+ }
70502+#endif
70503+}
70504+
70505+#ifdef CONFIG_GRKERNSEC_BRUTE
70506+static bool suid_ban_expired(struct user_struct *user)
70507+{
70508+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70509+ user->suid_banned = 0;
70510+ user->suid_ban_expires = 0;
70511+ free_uid(user);
70512+ return true;
70513+ }
70514+
70515+ return false;
70516+}
70517+#endif
70518+
70519+int gr_process_kernel_exec_ban(void)
70520+{
70521+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70522+ if (unlikely(current->cred->user->kernel_banned))
70523+ return -EPERM;
70524+#endif
70525+ return 0;
70526+}
70527+
70528+int gr_process_kernel_setuid_ban(struct user_struct *user)
70529+{
70530+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70531+ if (unlikely(user->kernel_banned))
70532+ gr_fake_force_sig(SIGKILL, current);
70533+#endif
70534+ return 0;
70535+}
70536+
70537+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70538+{
70539+#ifdef CONFIG_GRKERNSEC_BRUTE
70540+ struct user_struct *user = current->cred->user;
70541+ if (unlikely(user->suid_banned)) {
70542+ if (suid_ban_expired(user))
70543+ return 0;
70544+ /* disallow execution of suid binaries only */
70545+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70546+ return -EPERM;
70547+ }
70548+#endif
70549+ return 0;
70550+}
70551diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70552new file mode 100644
70553index 0000000..4030d57
70554--- /dev/null
70555+++ b/grsecurity/grsec_sock.c
70556@@ -0,0 +1,244 @@
70557+#include <linux/kernel.h>
70558+#include <linux/module.h>
70559+#include <linux/sched.h>
70560+#include <linux/file.h>
70561+#include <linux/net.h>
70562+#include <linux/in.h>
70563+#include <linux/ip.h>
70564+#include <net/sock.h>
70565+#include <net/inet_sock.h>
70566+#include <linux/grsecurity.h>
70567+#include <linux/grinternal.h>
70568+#include <linux/gracl.h>
70569+
70570+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70571+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70572+
70573+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70574+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70575+
70576+#ifdef CONFIG_UNIX_MODULE
70577+EXPORT_SYMBOL(gr_acl_handle_unix);
70578+EXPORT_SYMBOL(gr_acl_handle_mknod);
70579+EXPORT_SYMBOL(gr_handle_chroot_unix);
70580+EXPORT_SYMBOL(gr_handle_create);
70581+#endif
70582+
70583+#ifdef CONFIG_GRKERNSEC
70584+#define gr_conn_table_size 32749
70585+struct conn_table_entry {
70586+ struct conn_table_entry *next;
70587+ struct signal_struct *sig;
70588+};
70589+
70590+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70591+DEFINE_SPINLOCK(gr_conn_table_lock);
70592+
70593+extern const char * gr_socktype_to_name(unsigned char type);
70594+extern const char * gr_proto_to_name(unsigned char proto);
70595+extern const char * gr_sockfamily_to_name(unsigned char family);
70596+
70597+static __inline__ int
70598+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70599+{
70600+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70601+}
70602+
70603+static __inline__ int
70604+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70605+ __u16 sport, __u16 dport)
70606+{
70607+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70608+ sig->gr_sport == sport && sig->gr_dport == dport))
70609+ return 1;
70610+ else
70611+ return 0;
70612+}
70613+
70614+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70615+{
70616+ struct conn_table_entry **match;
70617+ unsigned int index;
70618+
70619+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70620+ sig->gr_sport, sig->gr_dport,
70621+ gr_conn_table_size);
70622+
70623+ newent->sig = sig;
70624+
70625+ match = &gr_conn_table[index];
70626+ newent->next = *match;
70627+ *match = newent;
70628+
70629+ return;
70630+}
70631+
70632+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70633+{
70634+ struct conn_table_entry *match, *last = NULL;
70635+ unsigned int index;
70636+
70637+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70638+ sig->gr_sport, sig->gr_dport,
70639+ gr_conn_table_size);
70640+
70641+ match = gr_conn_table[index];
70642+ while (match && !conn_match(match->sig,
70643+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70644+ sig->gr_dport)) {
70645+ last = match;
70646+ match = match->next;
70647+ }
70648+
70649+ if (match) {
70650+ if (last)
70651+ last->next = match->next;
70652+ else
70653+ gr_conn_table[index] = NULL;
70654+ kfree(match);
70655+ }
70656+
70657+ return;
70658+}
70659+
70660+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70661+ __u16 sport, __u16 dport)
70662+{
70663+ struct conn_table_entry *match;
70664+ unsigned int index;
70665+
70666+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70667+
70668+ match = gr_conn_table[index];
70669+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70670+ match = match->next;
70671+
70672+ if (match)
70673+ return match->sig;
70674+ else
70675+ return NULL;
70676+}
70677+
70678+#endif
70679+
70680+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70681+{
70682+#ifdef CONFIG_GRKERNSEC
70683+ struct signal_struct *sig = task->signal;
70684+ struct conn_table_entry *newent;
70685+
70686+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70687+ if (newent == NULL)
70688+ return;
70689+ /* no bh lock needed since we are called with bh disabled */
70690+ spin_lock(&gr_conn_table_lock);
70691+ gr_del_task_from_ip_table_nolock(sig);
70692+ sig->gr_saddr = inet->inet_rcv_saddr;
70693+ sig->gr_daddr = inet->inet_daddr;
70694+ sig->gr_sport = inet->inet_sport;
70695+ sig->gr_dport = inet->inet_dport;
70696+ gr_add_to_task_ip_table_nolock(sig, newent);
70697+ spin_unlock(&gr_conn_table_lock);
70698+#endif
70699+ return;
70700+}
70701+
70702+void gr_del_task_from_ip_table(struct task_struct *task)
70703+{
70704+#ifdef CONFIG_GRKERNSEC
70705+ spin_lock_bh(&gr_conn_table_lock);
70706+ gr_del_task_from_ip_table_nolock(task->signal);
70707+ spin_unlock_bh(&gr_conn_table_lock);
70708+#endif
70709+ return;
70710+}
70711+
70712+void
70713+gr_attach_curr_ip(const struct sock *sk)
70714+{
70715+#ifdef CONFIG_GRKERNSEC
70716+ struct signal_struct *p, *set;
70717+ const struct inet_sock *inet = inet_sk(sk);
70718+
70719+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70720+ return;
70721+
70722+ set = current->signal;
70723+
70724+ spin_lock_bh(&gr_conn_table_lock);
70725+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70726+ inet->inet_dport, inet->inet_sport);
70727+ if (unlikely(p != NULL)) {
70728+ set->curr_ip = p->curr_ip;
70729+ set->used_accept = 1;
70730+ gr_del_task_from_ip_table_nolock(p);
70731+ spin_unlock_bh(&gr_conn_table_lock);
70732+ return;
70733+ }
70734+ spin_unlock_bh(&gr_conn_table_lock);
70735+
70736+ set->curr_ip = inet->inet_daddr;
70737+ set->used_accept = 1;
70738+#endif
70739+ return;
70740+}
70741+
70742+int
70743+gr_handle_sock_all(const int family, const int type, const int protocol)
70744+{
70745+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70746+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70747+ (family != AF_UNIX)) {
70748+ if (family == AF_INET)
70749+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70750+ else
70751+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70752+ return -EACCES;
70753+ }
70754+#endif
70755+ return 0;
70756+}
70757+
70758+int
70759+gr_handle_sock_server(const struct sockaddr *sck)
70760+{
70761+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70762+ if (grsec_enable_socket_server &&
70763+ in_group_p(grsec_socket_server_gid) &&
70764+ sck && (sck->sa_family != AF_UNIX) &&
70765+ (sck->sa_family != AF_LOCAL)) {
70766+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70767+ return -EACCES;
70768+ }
70769+#endif
70770+ return 0;
70771+}
70772+
70773+int
70774+gr_handle_sock_server_other(const struct sock *sck)
70775+{
70776+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70777+ if (grsec_enable_socket_server &&
70778+ in_group_p(grsec_socket_server_gid) &&
70779+ sck && (sck->sk_family != AF_UNIX) &&
70780+ (sck->sk_family != AF_LOCAL)) {
70781+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70782+ return -EACCES;
70783+ }
70784+#endif
70785+ return 0;
70786+}
70787+
70788+int
70789+gr_handle_sock_client(const struct sockaddr *sck)
70790+{
70791+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70792+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70793+ sck && (sck->sa_family != AF_UNIX) &&
70794+ (sck->sa_family != AF_LOCAL)) {
70795+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70796+ return -EACCES;
70797+ }
70798+#endif
70799+ return 0;
70800+}
70801diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70802new file mode 100644
70803index 0000000..a147ae7
70804--- /dev/null
70805+++ b/grsecurity/grsec_sysctl.c
70806@@ -0,0 +1,470 @@
70807+#include <linux/kernel.h>
70808+#include <linux/sched.h>
70809+#include <linux/sysctl.h>
70810+#include <linux/grsecurity.h>
70811+#include <linux/grinternal.h>
70812+
70813+int
70814+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70815+{
70816+#ifdef CONFIG_GRKERNSEC_SYSCTL
70817+ if (dirname == NULL || name == NULL)
70818+ return 0;
70819+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70820+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70821+ return -EACCES;
70822+ }
70823+#endif
70824+ return 0;
70825+}
70826+
70827+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70828+static int __maybe_unused __read_only one = 1;
70829+#endif
70830+
70831+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70832+ defined(CONFIG_GRKERNSEC_DENYUSB)
70833+struct ctl_table grsecurity_table[] = {
70834+#ifdef CONFIG_GRKERNSEC_SYSCTL
70835+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70836+#ifdef CONFIG_GRKERNSEC_IO
70837+ {
70838+ .procname = "disable_priv_io",
70839+ .data = &grsec_disable_privio,
70840+ .maxlen = sizeof(int),
70841+ .mode = 0600,
70842+ .proc_handler = &proc_dointvec,
70843+ },
70844+#endif
70845+#endif
70846+#ifdef CONFIG_GRKERNSEC_LINK
70847+ {
70848+ .procname = "linking_restrictions",
70849+ .data = &grsec_enable_link,
70850+ .maxlen = sizeof(int),
70851+ .mode = 0600,
70852+ .proc_handler = &proc_dointvec,
70853+ },
70854+#endif
70855+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70856+ {
70857+ .procname = "enforce_symlinksifowner",
70858+ .data = &grsec_enable_symlinkown,
70859+ .maxlen = sizeof(int),
70860+ .mode = 0600,
70861+ .proc_handler = &proc_dointvec,
70862+ },
70863+ {
70864+ .procname = "symlinkown_gid",
70865+ .data = &grsec_symlinkown_gid,
70866+ .maxlen = sizeof(int),
70867+ .mode = 0600,
70868+ .proc_handler = &proc_dointvec,
70869+ },
70870+#endif
70871+#ifdef CONFIG_GRKERNSEC_BRUTE
70872+ {
70873+ .procname = "deter_bruteforce",
70874+ .data = &grsec_enable_brute,
70875+ .maxlen = sizeof(int),
70876+ .mode = 0600,
70877+ .proc_handler = &proc_dointvec,
70878+ },
70879+#endif
70880+#ifdef CONFIG_GRKERNSEC_FIFO
70881+ {
70882+ .procname = "fifo_restrictions",
70883+ .data = &grsec_enable_fifo,
70884+ .maxlen = sizeof(int),
70885+ .mode = 0600,
70886+ .proc_handler = &proc_dointvec,
70887+ },
70888+#endif
70889+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70890+ {
70891+ .procname = "ptrace_readexec",
70892+ .data = &grsec_enable_ptrace_readexec,
70893+ .maxlen = sizeof(int),
70894+ .mode = 0600,
70895+ .proc_handler = &proc_dointvec,
70896+ },
70897+#endif
70898+#ifdef CONFIG_GRKERNSEC_SETXID
70899+ {
70900+ .procname = "consistent_setxid",
70901+ .data = &grsec_enable_setxid,
70902+ .maxlen = sizeof(int),
70903+ .mode = 0600,
70904+ .proc_handler = &proc_dointvec,
70905+ },
70906+#endif
70907+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70908+ {
70909+ .procname = "ip_blackhole",
70910+ .data = &grsec_enable_blackhole,
70911+ .maxlen = sizeof(int),
70912+ .mode = 0600,
70913+ .proc_handler = &proc_dointvec,
70914+ },
70915+ {
70916+ .procname = "lastack_retries",
70917+ .data = &grsec_lastack_retries,
70918+ .maxlen = sizeof(int),
70919+ .mode = 0600,
70920+ .proc_handler = &proc_dointvec,
70921+ },
70922+#endif
70923+#ifdef CONFIG_GRKERNSEC_EXECLOG
70924+ {
70925+ .procname = "exec_logging",
70926+ .data = &grsec_enable_execlog,
70927+ .maxlen = sizeof(int),
70928+ .mode = 0600,
70929+ .proc_handler = &proc_dointvec,
70930+ },
70931+#endif
70932+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70933+ {
70934+ .procname = "rwxmap_logging",
70935+ .data = &grsec_enable_log_rwxmaps,
70936+ .maxlen = sizeof(int),
70937+ .mode = 0600,
70938+ .proc_handler = &proc_dointvec,
70939+ },
70940+#endif
70941+#ifdef CONFIG_GRKERNSEC_SIGNAL
70942+ {
70943+ .procname = "signal_logging",
70944+ .data = &grsec_enable_signal,
70945+ .maxlen = sizeof(int),
70946+ .mode = 0600,
70947+ .proc_handler = &proc_dointvec,
70948+ },
70949+#endif
70950+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70951+ {
70952+ .procname = "forkfail_logging",
70953+ .data = &grsec_enable_forkfail,
70954+ .maxlen = sizeof(int),
70955+ .mode = 0600,
70956+ .proc_handler = &proc_dointvec,
70957+ },
70958+#endif
70959+#ifdef CONFIG_GRKERNSEC_TIME
70960+ {
70961+ .procname = "timechange_logging",
70962+ .data = &grsec_enable_time,
70963+ .maxlen = sizeof(int),
70964+ .mode = 0600,
70965+ .proc_handler = &proc_dointvec,
70966+ },
70967+#endif
70968+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70969+ {
70970+ .procname = "chroot_deny_shmat",
70971+ .data = &grsec_enable_chroot_shmat,
70972+ .maxlen = sizeof(int),
70973+ .mode = 0600,
70974+ .proc_handler = &proc_dointvec,
70975+ },
70976+#endif
70977+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70978+ {
70979+ .procname = "chroot_deny_unix",
70980+ .data = &grsec_enable_chroot_unix,
70981+ .maxlen = sizeof(int),
70982+ .mode = 0600,
70983+ .proc_handler = &proc_dointvec,
70984+ },
70985+#endif
70986+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70987+ {
70988+ .procname = "chroot_deny_mount",
70989+ .data = &grsec_enable_chroot_mount,
70990+ .maxlen = sizeof(int),
70991+ .mode = 0600,
70992+ .proc_handler = &proc_dointvec,
70993+ },
70994+#endif
70995+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70996+ {
70997+ .procname = "chroot_deny_fchdir",
70998+ .data = &grsec_enable_chroot_fchdir,
70999+ .maxlen = sizeof(int),
71000+ .mode = 0600,
71001+ .proc_handler = &proc_dointvec,
71002+ },
71003+#endif
71004+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71005+ {
71006+ .procname = "chroot_deny_chroot",
71007+ .data = &grsec_enable_chroot_double,
71008+ .maxlen = sizeof(int),
71009+ .mode = 0600,
71010+ .proc_handler = &proc_dointvec,
71011+ },
71012+#endif
71013+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71014+ {
71015+ .procname = "chroot_deny_pivot",
71016+ .data = &grsec_enable_chroot_pivot,
71017+ .maxlen = sizeof(int),
71018+ .mode = 0600,
71019+ .proc_handler = &proc_dointvec,
71020+ },
71021+#endif
71022+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71023+ {
71024+ .procname = "chroot_enforce_chdir",
71025+ .data = &grsec_enable_chroot_chdir,
71026+ .maxlen = sizeof(int),
71027+ .mode = 0600,
71028+ .proc_handler = &proc_dointvec,
71029+ },
71030+#endif
71031+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71032+ {
71033+ .procname = "chroot_deny_chmod",
71034+ .data = &grsec_enable_chroot_chmod,
71035+ .maxlen = sizeof(int),
71036+ .mode = 0600,
71037+ .proc_handler = &proc_dointvec,
71038+ },
71039+#endif
71040+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71041+ {
71042+ .procname = "chroot_deny_mknod",
71043+ .data = &grsec_enable_chroot_mknod,
71044+ .maxlen = sizeof(int),
71045+ .mode = 0600,
71046+ .proc_handler = &proc_dointvec,
71047+ },
71048+#endif
71049+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71050+ {
71051+ .procname = "chroot_restrict_nice",
71052+ .data = &grsec_enable_chroot_nice,
71053+ .maxlen = sizeof(int),
71054+ .mode = 0600,
71055+ .proc_handler = &proc_dointvec,
71056+ },
71057+#endif
71058+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71059+ {
71060+ .procname = "chroot_execlog",
71061+ .data = &grsec_enable_chroot_execlog,
71062+ .maxlen = sizeof(int),
71063+ .mode = 0600,
71064+ .proc_handler = &proc_dointvec,
71065+ },
71066+#endif
71067+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71068+ {
71069+ .procname = "chroot_caps",
71070+ .data = &grsec_enable_chroot_caps,
71071+ .maxlen = sizeof(int),
71072+ .mode = 0600,
71073+ .proc_handler = &proc_dointvec,
71074+ },
71075+#endif
71076+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71077+ {
71078+ .procname = "chroot_deny_sysctl",
71079+ .data = &grsec_enable_chroot_sysctl,
71080+ .maxlen = sizeof(int),
71081+ .mode = 0600,
71082+ .proc_handler = &proc_dointvec,
71083+ },
71084+#endif
71085+#ifdef CONFIG_GRKERNSEC_TPE
71086+ {
71087+ .procname = "tpe",
71088+ .data = &grsec_enable_tpe,
71089+ .maxlen = sizeof(int),
71090+ .mode = 0600,
71091+ .proc_handler = &proc_dointvec,
71092+ },
71093+ {
71094+ .procname = "tpe_gid",
71095+ .data = &grsec_tpe_gid,
71096+ .maxlen = sizeof(int),
71097+ .mode = 0600,
71098+ .proc_handler = &proc_dointvec,
71099+ },
71100+#endif
71101+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71102+ {
71103+ .procname = "tpe_invert",
71104+ .data = &grsec_enable_tpe_invert,
71105+ .maxlen = sizeof(int),
71106+ .mode = 0600,
71107+ .proc_handler = &proc_dointvec,
71108+ },
71109+#endif
71110+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71111+ {
71112+ .procname = "tpe_restrict_all",
71113+ .data = &grsec_enable_tpe_all,
71114+ .maxlen = sizeof(int),
71115+ .mode = 0600,
71116+ .proc_handler = &proc_dointvec,
71117+ },
71118+#endif
71119+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71120+ {
71121+ .procname = "socket_all",
71122+ .data = &grsec_enable_socket_all,
71123+ .maxlen = sizeof(int),
71124+ .mode = 0600,
71125+ .proc_handler = &proc_dointvec,
71126+ },
71127+ {
71128+ .procname = "socket_all_gid",
71129+ .data = &grsec_socket_all_gid,
71130+ .maxlen = sizeof(int),
71131+ .mode = 0600,
71132+ .proc_handler = &proc_dointvec,
71133+ },
71134+#endif
71135+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71136+ {
71137+ .procname = "socket_client",
71138+ .data = &grsec_enable_socket_client,
71139+ .maxlen = sizeof(int),
71140+ .mode = 0600,
71141+ .proc_handler = &proc_dointvec,
71142+ },
71143+ {
71144+ .procname = "socket_client_gid",
71145+ .data = &grsec_socket_client_gid,
71146+ .maxlen = sizeof(int),
71147+ .mode = 0600,
71148+ .proc_handler = &proc_dointvec,
71149+ },
71150+#endif
71151+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71152+ {
71153+ .procname = "socket_server",
71154+ .data = &grsec_enable_socket_server,
71155+ .maxlen = sizeof(int),
71156+ .mode = 0600,
71157+ .proc_handler = &proc_dointvec,
71158+ },
71159+ {
71160+ .procname = "socket_server_gid",
71161+ .data = &grsec_socket_server_gid,
71162+ .maxlen = sizeof(int),
71163+ .mode = 0600,
71164+ .proc_handler = &proc_dointvec,
71165+ },
71166+#endif
71167+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71168+ {
71169+ .procname = "audit_group",
71170+ .data = &grsec_enable_group,
71171+ .maxlen = sizeof(int),
71172+ .mode = 0600,
71173+ .proc_handler = &proc_dointvec,
71174+ },
71175+ {
71176+ .procname = "audit_gid",
71177+ .data = &grsec_audit_gid,
71178+ .maxlen = sizeof(int),
71179+ .mode = 0600,
71180+ .proc_handler = &proc_dointvec,
71181+ },
71182+#endif
71183+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71184+ {
71185+ .procname = "audit_chdir",
71186+ .data = &grsec_enable_chdir,
71187+ .maxlen = sizeof(int),
71188+ .mode = 0600,
71189+ .proc_handler = &proc_dointvec,
71190+ },
71191+#endif
71192+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71193+ {
71194+ .procname = "audit_mount",
71195+ .data = &grsec_enable_mount,
71196+ .maxlen = sizeof(int),
71197+ .mode = 0600,
71198+ .proc_handler = &proc_dointvec,
71199+ },
71200+#endif
71201+#ifdef CONFIG_GRKERNSEC_DMESG
71202+ {
71203+ .procname = "dmesg",
71204+ .data = &grsec_enable_dmesg,
71205+ .maxlen = sizeof(int),
71206+ .mode = 0600,
71207+ .proc_handler = &proc_dointvec,
71208+ },
71209+#endif
71210+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71211+ {
71212+ .procname = "chroot_findtask",
71213+ .data = &grsec_enable_chroot_findtask,
71214+ .maxlen = sizeof(int),
71215+ .mode = 0600,
71216+ .proc_handler = &proc_dointvec,
71217+ },
71218+#endif
71219+#ifdef CONFIG_GRKERNSEC_RESLOG
71220+ {
71221+ .procname = "resource_logging",
71222+ .data = &grsec_resource_logging,
71223+ .maxlen = sizeof(int),
71224+ .mode = 0600,
71225+ .proc_handler = &proc_dointvec,
71226+ },
71227+#endif
71228+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71229+ {
71230+ .procname = "audit_ptrace",
71231+ .data = &grsec_enable_audit_ptrace,
71232+ .maxlen = sizeof(int),
71233+ .mode = 0600,
71234+ .proc_handler = &proc_dointvec,
71235+ },
71236+#endif
71237+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71238+ {
71239+ .procname = "harden_ptrace",
71240+ .data = &grsec_enable_harden_ptrace,
71241+ .maxlen = sizeof(int),
71242+ .mode = 0600,
71243+ .proc_handler = &proc_dointvec,
71244+ },
71245+#endif
71246+ {
71247+ .procname = "grsec_lock",
71248+ .data = &grsec_lock,
71249+ .maxlen = sizeof(int),
71250+ .mode = 0600,
71251+ .proc_handler = &proc_dointvec,
71252+ },
71253+#endif
71254+#ifdef CONFIG_GRKERNSEC_ROFS
71255+ {
71256+ .procname = "romount_protect",
71257+ .data = &grsec_enable_rofs,
71258+ .maxlen = sizeof(int),
71259+ .mode = 0600,
71260+ .proc_handler = &proc_dointvec_minmax,
71261+ .extra1 = &one,
71262+ .extra2 = &one,
71263+ },
71264+#endif
71265+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71266+ {
71267+ .procname = "deny_new_usb",
71268+ .data = &grsec_deny_new_usb,
71269+ .maxlen = sizeof(int),
71270+ .mode = 0600,
71271+ .proc_handler = &proc_dointvec,
71272+ },
71273+#endif
71274+ { }
71275+};
71276+#endif
71277diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71278new file mode 100644
71279index 0000000..0dc13c3
71280--- /dev/null
71281+++ b/grsecurity/grsec_time.c
71282@@ -0,0 +1,16 @@
71283+#include <linux/kernel.h>
71284+#include <linux/sched.h>
71285+#include <linux/grinternal.h>
71286+#include <linux/module.h>
71287+
71288+void
71289+gr_log_timechange(void)
71290+{
71291+#ifdef CONFIG_GRKERNSEC_TIME
71292+ if (grsec_enable_time)
71293+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71294+#endif
71295+ return;
71296+}
71297+
71298+EXPORT_SYMBOL(gr_log_timechange);
71299diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71300new file mode 100644
71301index 0000000..ee57dcf
71302--- /dev/null
71303+++ b/grsecurity/grsec_tpe.c
71304@@ -0,0 +1,73 @@
71305+#include <linux/kernel.h>
71306+#include <linux/sched.h>
71307+#include <linux/file.h>
71308+#include <linux/fs.h>
71309+#include <linux/grinternal.h>
71310+
71311+extern int gr_acl_tpe_check(void);
71312+
71313+int
71314+gr_tpe_allow(const struct file *file)
71315+{
71316+#ifdef CONFIG_GRKERNSEC
71317+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71318+ const struct cred *cred = current_cred();
71319+ char *msg = NULL;
71320+ char *msg2 = NULL;
71321+
71322+ // never restrict root
71323+ if (gr_is_global_root(cred->uid))
71324+ return 1;
71325+
71326+ if (grsec_enable_tpe) {
71327+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71328+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71329+ msg = "not being in trusted group";
71330+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71331+ msg = "being in untrusted group";
71332+#else
71333+ if (in_group_p(grsec_tpe_gid))
71334+ msg = "being in untrusted group";
71335+#endif
71336+ }
71337+ if (!msg && gr_acl_tpe_check())
71338+ msg = "being in untrusted role";
71339+
71340+ // not in any affected group/role
71341+ if (!msg)
71342+ goto next_check;
71343+
71344+ if (gr_is_global_nonroot(inode->i_uid))
71345+ msg2 = "file in non-root-owned directory";
71346+ else if (inode->i_mode & S_IWOTH)
71347+ msg2 = "file in world-writable directory";
71348+ else if (inode->i_mode & S_IWGRP)
71349+ msg2 = "file in group-writable directory";
71350+
71351+ if (msg && msg2) {
71352+ char fullmsg[70] = {0};
71353+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71354+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71355+ return 0;
71356+ }
71357+ msg = NULL;
71358+next_check:
71359+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71360+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71361+ return 1;
71362+
71363+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71364+ msg = "directory not owned by user";
71365+ else if (inode->i_mode & S_IWOTH)
71366+ msg = "file in world-writable directory";
71367+ else if (inode->i_mode & S_IWGRP)
71368+ msg = "file in group-writable directory";
71369+
71370+ if (msg) {
71371+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71372+ return 0;
71373+ }
71374+#endif
71375+#endif
71376+ return 1;
71377+}
71378diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71379new file mode 100644
71380index 0000000..ae02d8e
71381--- /dev/null
71382+++ b/grsecurity/grsec_usb.c
71383@@ -0,0 +1,15 @@
71384+#include <linux/kernel.h>
71385+#include <linux/grinternal.h>
71386+#include <linux/module.h>
71387+
71388+int gr_handle_new_usb(void)
71389+{
71390+#ifdef CONFIG_GRKERNSEC_DENYUSB
71391+ if (grsec_deny_new_usb) {
71392+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71393+ return 1;
71394+ }
71395+#endif
71396+ return 0;
71397+}
71398+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71399diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71400new file mode 100644
71401index 0000000..9f7b1ac
71402--- /dev/null
71403+++ b/grsecurity/grsum.c
71404@@ -0,0 +1,61 @@
71405+#include <linux/err.h>
71406+#include <linux/kernel.h>
71407+#include <linux/sched.h>
71408+#include <linux/mm.h>
71409+#include <linux/scatterlist.h>
71410+#include <linux/crypto.h>
71411+#include <linux/gracl.h>
71412+
71413+
71414+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71415+#error "crypto and sha256 must be built into the kernel"
71416+#endif
71417+
71418+int
71419+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71420+{
71421+ char *p;
71422+ struct crypto_hash *tfm;
71423+ struct hash_desc desc;
71424+ struct scatterlist sg;
71425+ unsigned char temp_sum[GR_SHA_LEN];
71426+ volatile int retval = 0;
71427+ volatile int dummy = 0;
71428+ unsigned int i;
71429+
71430+ sg_init_table(&sg, 1);
71431+
71432+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71433+ if (IS_ERR(tfm)) {
71434+ /* should never happen, since sha256 should be built in */
71435+ return 1;
71436+ }
71437+
71438+ desc.tfm = tfm;
71439+ desc.flags = 0;
71440+
71441+ crypto_hash_init(&desc);
71442+
71443+ p = salt;
71444+ sg_set_buf(&sg, p, GR_SALT_LEN);
71445+ crypto_hash_update(&desc, &sg, sg.length);
71446+
71447+ p = entry->pw;
71448+ sg_set_buf(&sg, p, strlen(p));
71449+
71450+ crypto_hash_update(&desc, &sg, sg.length);
71451+
71452+ crypto_hash_final(&desc, temp_sum);
71453+
71454+ memset(entry->pw, 0, GR_PW_LEN);
71455+
71456+ for (i = 0; i < GR_SHA_LEN; i++)
71457+ if (sum[i] != temp_sum[i])
71458+ retval = 1;
71459+ else
71460+ dummy = 1; // waste a cycle
71461+
71462+ crypto_free_hash(tfm);
71463+
71464+ return retval;
71465+}
71466diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71467index 77ff547..181834f 100644
71468--- a/include/asm-generic/4level-fixup.h
71469+++ b/include/asm-generic/4level-fixup.h
71470@@ -13,8 +13,10 @@
71471 #define pmd_alloc(mm, pud, address) \
71472 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71473 NULL: pmd_offset(pud, address))
71474+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71475
71476 #define pud_alloc(mm, pgd, address) (pgd)
71477+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71478 #define pud_offset(pgd, start) (pgd)
71479 #define pud_none(pud) 0
71480 #define pud_bad(pud) 0
71481diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71482index b7babf0..04ad282 100644
71483--- a/include/asm-generic/atomic-long.h
71484+++ b/include/asm-generic/atomic-long.h
71485@@ -22,6 +22,12 @@
71486
71487 typedef atomic64_t atomic_long_t;
71488
71489+#ifdef CONFIG_PAX_REFCOUNT
71490+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71491+#else
71492+typedef atomic64_t atomic_long_unchecked_t;
71493+#endif
71494+
71495 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71496
71497 static inline long atomic_long_read(atomic_long_t *l)
71498@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71499 return (long)atomic64_read(v);
71500 }
71501
71502+#ifdef CONFIG_PAX_REFCOUNT
71503+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71504+{
71505+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71506+
71507+ return (long)atomic64_read_unchecked(v);
71508+}
71509+#endif
71510+
71511 static inline void atomic_long_set(atomic_long_t *l, long i)
71512 {
71513 atomic64_t *v = (atomic64_t *)l;
71514@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71515 atomic64_set(v, i);
71516 }
71517
71518+#ifdef CONFIG_PAX_REFCOUNT
71519+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71520+{
71521+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71522+
71523+ atomic64_set_unchecked(v, i);
71524+}
71525+#endif
71526+
71527 static inline void atomic_long_inc(atomic_long_t *l)
71528 {
71529 atomic64_t *v = (atomic64_t *)l;
71530@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71531 atomic64_inc(v);
71532 }
71533
71534+#ifdef CONFIG_PAX_REFCOUNT
71535+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71536+{
71537+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71538+
71539+ atomic64_inc_unchecked(v);
71540+}
71541+#endif
71542+
71543 static inline void atomic_long_dec(atomic_long_t *l)
71544 {
71545 atomic64_t *v = (atomic64_t *)l;
71546@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71547 atomic64_dec(v);
71548 }
71549
71550+#ifdef CONFIG_PAX_REFCOUNT
71551+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71552+{
71553+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71554+
71555+ atomic64_dec_unchecked(v);
71556+}
71557+#endif
71558+
71559 static inline void atomic_long_add(long i, atomic_long_t *l)
71560 {
71561 atomic64_t *v = (atomic64_t *)l;
71562@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71563 atomic64_add(i, v);
71564 }
71565
71566+#ifdef CONFIG_PAX_REFCOUNT
71567+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71568+{
71569+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71570+
71571+ atomic64_add_unchecked(i, v);
71572+}
71573+#endif
71574+
71575 static inline void atomic_long_sub(long i, atomic_long_t *l)
71576 {
71577 atomic64_t *v = (atomic64_t *)l;
71578@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71579 atomic64_sub(i, v);
71580 }
71581
71582+#ifdef CONFIG_PAX_REFCOUNT
71583+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71584+{
71585+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71586+
71587+ atomic64_sub_unchecked(i, v);
71588+}
71589+#endif
71590+
71591 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71592 {
71593 atomic64_t *v = (atomic64_t *)l;
71594@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71595 return (long)atomic64_add_return(i, v);
71596 }
71597
71598+#ifdef CONFIG_PAX_REFCOUNT
71599+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71600+{
71601+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71602+
71603+ return (long)atomic64_add_return_unchecked(i, v);
71604+}
71605+#endif
71606+
71607 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71608 {
71609 atomic64_t *v = (atomic64_t *)l;
71610@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71611 return (long)atomic64_inc_return(v);
71612 }
71613
71614+#ifdef CONFIG_PAX_REFCOUNT
71615+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71616+{
71617+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71618+
71619+ return (long)atomic64_inc_return_unchecked(v);
71620+}
71621+#endif
71622+
71623 static inline long atomic_long_dec_return(atomic_long_t *l)
71624 {
71625 atomic64_t *v = (atomic64_t *)l;
71626@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71627
71628 typedef atomic_t atomic_long_t;
71629
71630+#ifdef CONFIG_PAX_REFCOUNT
71631+typedef atomic_unchecked_t atomic_long_unchecked_t;
71632+#else
71633+typedef atomic_t atomic_long_unchecked_t;
71634+#endif
71635+
71636 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71637 static inline long atomic_long_read(atomic_long_t *l)
71638 {
71639@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71640 return (long)atomic_read(v);
71641 }
71642
71643+#ifdef CONFIG_PAX_REFCOUNT
71644+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71645+{
71646+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71647+
71648+ return (long)atomic_read_unchecked(v);
71649+}
71650+#endif
71651+
71652 static inline void atomic_long_set(atomic_long_t *l, long i)
71653 {
71654 atomic_t *v = (atomic_t *)l;
71655@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71656 atomic_set(v, i);
71657 }
71658
71659+#ifdef CONFIG_PAX_REFCOUNT
71660+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71661+{
71662+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71663+
71664+ atomic_set_unchecked(v, i);
71665+}
71666+#endif
71667+
71668 static inline void atomic_long_inc(atomic_long_t *l)
71669 {
71670 atomic_t *v = (atomic_t *)l;
71671@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71672 atomic_inc(v);
71673 }
71674
71675+#ifdef CONFIG_PAX_REFCOUNT
71676+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71677+{
71678+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71679+
71680+ atomic_inc_unchecked(v);
71681+}
71682+#endif
71683+
71684 static inline void atomic_long_dec(atomic_long_t *l)
71685 {
71686 atomic_t *v = (atomic_t *)l;
71687@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71688 atomic_dec(v);
71689 }
71690
71691+#ifdef CONFIG_PAX_REFCOUNT
71692+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71693+{
71694+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71695+
71696+ atomic_dec_unchecked(v);
71697+}
71698+#endif
71699+
71700 static inline void atomic_long_add(long i, atomic_long_t *l)
71701 {
71702 atomic_t *v = (atomic_t *)l;
71703@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71704 atomic_add(i, v);
71705 }
71706
71707+#ifdef CONFIG_PAX_REFCOUNT
71708+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71709+{
71710+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71711+
71712+ atomic_add_unchecked(i, v);
71713+}
71714+#endif
71715+
71716 static inline void atomic_long_sub(long i, atomic_long_t *l)
71717 {
71718 atomic_t *v = (atomic_t *)l;
71719@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71720 atomic_sub(i, v);
71721 }
71722
71723+#ifdef CONFIG_PAX_REFCOUNT
71724+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71725+{
71726+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71727+
71728+ atomic_sub_unchecked(i, v);
71729+}
71730+#endif
71731+
71732 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71733 {
71734 atomic_t *v = (atomic_t *)l;
71735@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71736 return (long)atomic_add_return(i, v);
71737 }
71738
71739+#ifdef CONFIG_PAX_REFCOUNT
71740+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71741+{
71742+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71743+
71744+ return (long)atomic_add_return_unchecked(i, v);
71745+}
71746+
71747+#endif
71748+
71749 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71750 {
71751 atomic_t *v = (atomic_t *)l;
71752@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71753 return (long)atomic_inc_return(v);
71754 }
71755
71756+#ifdef CONFIG_PAX_REFCOUNT
71757+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71758+{
71759+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71760+
71761+ return (long)atomic_inc_return_unchecked(v);
71762+}
71763+#endif
71764+
71765 static inline long atomic_long_dec_return(atomic_long_t *l)
71766 {
71767 atomic_t *v = (atomic_t *)l;
71768@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71769
71770 #endif /* BITS_PER_LONG == 64 */
71771
71772+#ifdef CONFIG_PAX_REFCOUNT
71773+static inline void pax_refcount_needs_these_functions(void)
71774+{
71775+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71776+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71777+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71778+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71779+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71780+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71781+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71782+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71783+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71784+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71785+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71786+#ifdef CONFIG_X86
71787+ atomic_clear_mask_unchecked(0, NULL);
71788+ atomic_set_mask_unchecked(0, NULL);
71789+#endif
71790+
71791+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71792+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71793+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71794+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71795+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71796+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71797+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71798+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71799+}
71800+#else
71801+#define atomic_read_unchecked(v) atomic_read(v)
71802+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71803+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71804+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71805+#define atomic_inc_unchecked(v) atomic_inc(v)
71806+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71807+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71808+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71809+#define atomic_dec_unchecked(v) atomic_dec(v)
71810+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71811+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71812+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71813+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71814+
71815+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71816+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71817+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71818+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71819+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71820+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71821+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71822+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71823+#endif
71824+
71825 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71826diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71827index 33bd2de..f31bff97 100644
71828--- a/include/asm-generic/atomic.h
71829+++ b/include/asm-generic/atomic.h
71830@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71831 * Atomically clears the bits set in @mask from @v
71832 */
71833 #ifndef atomic_clear_mask
71834-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71835+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71836 {
71837 unsigned long flags;
71838
71839diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71840index b18ce4f..2ee2843 100644
71841--- a/include/asm-generic/atomic64.h
71842+++ b/include/asm-generic/atomic64.h
71843@@ -16,6 +16,8 @@ typedef struct {
71844 long long counter;
71845 } atomic64_t;
71846
71847+typedef atomic64_t atomic64_unchecked_t;
71848+
71849 #define ATOMIC64_INIT(i) { (i) }
71850
71851 extern long long atomic64_read(const atomic64_t *v);
71852@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71853 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71854 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71855
71856+#define atomic64_read_unchecked(v) atomic64_read(v)
71857+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71858+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71859+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71860+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71861+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71862+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71863+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71864+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71865+
71866 #endif /* _ASM_GENERIC_ATOMIC64_H */
71867diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71868index 1bfcfe5..e04c5c9 100644
71869--- a/include/asm-generic/cache.h
71870+++ b/include/asm-generic/cache.h
71871@@ -6,7 +6,7 @@
71872 * cache lines need to provide their own cache.h.
71873 */
71874
71875-#define L1_CACHE_SHIFT 5
71876-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71877+#define L1_CACHE_SHIFT 5UL
71878+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71879
71880 #endif /* __ASM_GENERIC_CACHE_H */
71881diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71882index 0d68a1e..b74a761 100644
71883--- a/include/asm-generic/emergency-restart.h
71884+++ b/include/asm-generic/emergency-restart.h
71885@@ -1,7 +1,7 @@
71886 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71887 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71888
71889-static inline void machine_emergency_restart(void)
71890+static inline __noreturn void machine_emergency_restart(void)
71891 {
71892 machine_restart(NULL);
71893 }
71894diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71895index 90f99c7..00ce236 100644
71896--- a/include/asm-generic/kmap_types.h
71897+++ b/include/asm-generic/kmap_types.h
71898@@ -2,9 +2,9 @@
71899 #define _ASM_GENERIC_KMAP_TYPES_H
71900
71901 #ifdef __WITH_KM_FENCE
71902-# define KM_TYPE_NR 41
71903+# define KM_TYPE_NR 42
71904 #else
71905-# define KM_TYPE_NR 20
71906+# define KM_TYPE_NR 21
71907 #endif
71908
71909 #endif
71910diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71911index 9ceb03b..62b0b8f 100644
71912--- a/include/asm-generic/local.h
71913+++ b/include/asm-generic/local.h
71914@@ -23,24 +23,37 @@ typedef struct
71915 atomic_long_t a;
71916 } local_t;
71917
71918+typedef struct {
71919+ atomic_long_unchecked_t a;
71920+} local_unchecked_t;
71921+
71922 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71923
71924 #define local_read(l) atomic_long_read(&(l)->a)
71925+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71926 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71927+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71928 #define local_inc(l) atomic_long_inc(&(l)->a)
71929+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71930 #define local_dec(l) atomic_long_dec(&(l)->a)
71931+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71932 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71933+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71934 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71935+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71936
71937 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71938 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71939 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71940 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71941 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71942+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71943 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71944 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71945+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71946
71947 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71948+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71949 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71950 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71951 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71952diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71953index 725612b..9cc513a 100644
71954--- a/include/asm-generic/pgtable-nopmd.h
71955+++ b/include/asm-generic/pgtable-nopmd.h
71956@@ -1,14 +1,19 @@
71957 #ifndef _PGTABLE_NOPMD_H
71958 #define _PGTABLE_NOPMD_H
71959
71960-#ifndef __ASSEMBLY__
71961-
71962 #include <asm-generic/pgtable-nopud.h>
71963
71964-struct mm_struct;
71965-
71966 #define __PAGETABLE_PMD_FOLDED
71967
71968+#define PMD_SHIFT PUD_SHIFT
71969+#define PTRS_PER_PMD 1
71970+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71971+#define PMD_MASK (~(PMD_SIZE-1))
71972+
71973+#ifndef __ASSEMBLY__
71974+
71975+struct mm_struct;
71976+
71977 /*
71978 * Having the pmd type consist of a pud gets the size right, and allows
71979 * us to conceptually access the pud entry that this pmd is folded into
71980@@ -16,11 +21,6 @@ struct mm_struct;
71981 */
71982 typedef struct { pud_t pud; } pmd_t;
71983
71984-#define PMD_SHIFT PUD_SHIFT
71985-#define PTRS_PER_PMD 1
71986-#define PMD_SIZE (1UL << PMD_SHIFT)
71987-#define PMD_MASK (~(PMD_SIZE-1))
71988-
71989 /*
71990 * The "pud_xxx()" functions here are trivial for a folded two-level
71991 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71992diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71993index 810431d..0ec4804f 100644
71994--- a/include/asm-generic/pgtable-nopud.h
71995+++ b/include/asm-generic/pgtable-nopud.h
71996@@ -1,10 +1,15 @@
71997 #ifndef _PGTABLE_NOPUD_H
71998 #define _PGTABLE_NOPUD_H
71999
72000-#ifndef __ASSEMBLY__
72001-
72002 #define __PAGETABLE_PUD_FOLDED
72003
72004+#define PUD_SHIFT PGDIR_SHIFT
72005+#define PTRS_PER_PUD 1
72006+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72007+#define PUD_MASK (~(PUD_SIZE-1))
72008+
72009+#ifndef __ASSEMBLY__
72010+
72011 /*
72012 * Having the pud type consist of a pgd gets the size right, and allows
72013 * us to conceptually access the pgd entry that this pud is folded into
72014@@ -12,11 +17,6 @@
72015 */
72016 typedef struct { pgd_t pgd; } pud_t;
72017
72018-#define PUD_SHIFT PGDIR_SHIFT
72019-#define PTRS_PER_PUD 1
72020-#define PUD_SIZE (1UL << PUD_SHIFT)
72021-#define PUD_MASK (~(PUD_SIZE-1))
72022-
72023 /*
72024 * The "pgd_xxx()" functions here are trivial for a folded two-level
72025 * setup: the pud is never bad, and a pud always exists (as it's folded
72026@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72027 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72028
72029 #define pgd_populate(mm, pgd, pud) do { } while (0)
72030+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72031 /*
72032 * (puds are folded into pgds so this doesn't get actually called,
72033 * but the define is needed for a generic inline function.)
72034diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72035index 0807ddf..cd67747 100644
72036--- a/include/asm-generic/pgtable.h
72037+++ b/include/asm-generic/pgtable.h
72038@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72039 }
72040 #endif /* CONFIG_NUMA_BALANCING */
72041
72042+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72043+#ifdef CONFIG_PAX_KERNEXEC
72044+#error KERNEXEC requires pax_open_kernel
72045+#else
72046+static inline unsigned long pax_open_kernel(void) { return 0; }
72047+#endif
72048+#endif
72049+
72050+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72051+#ifdef CONFIG_PAX_KERNEXEC
72052+#error KERNEXEC requires pax_close_kernel
72053+#else
72054+static inline unsigned long pax_close_kernel(void) { return 0; }
72055+#endif
72056+#endif
72057+
72058 #endif /* CONFIG_MMU */
72059
72060 #endif /* !__ASSEMBLY__ */
72061diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72062index dc1269c..48a4f51 100644
72063--- a/include/asm-generic/uaccess.h
72064+++ b/include/asm-generic/uaccess.h
72065@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72066 return __clear_user(to, n);
72067 }
72068
72069+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72070+#ifdef CONFIG_PAX_MEMORY_UDEREF
72071+#error UDEREF requires pax_open_userland
72072+#else
72073+static inline unsigned long pax_open_userland(void) { return 0; }
72074+#endif
72075+#endif
72076+
72077+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72078+#ifdef CONFIG_PAX_MEMORY_UDEREF
72079+#error UDEREF requires pax_close_userland
72080+#else
72081+static inline unsigned long pax_close_userland(void) { return 0; }
72082+#endif
72083+#endif
72084+
72085 #endif /* __ASM_GENERIC_UACCESS_H */
72086diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72087index 69732d2..cbe16d9 100644
72088--- a/include/asm-generic/vmlinux.lds.h
72089+++ b/include/asm-generic/vmlinux.lds.h
72090@@ -227,6 +227,7 @@
72091 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72092 VMLINUX_SYMBOL(__start_rodata) = .; \
72093 *(.rodata) *(.rodata.*) \
72094+ *(.data..read_only) \
72095 *(__vermagic) /* Kernel version magic */ \
72096 . = ALIGN(8); \
72097 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72098@@ -710,17 +711,18 @@
72099 * section in the linker script will go there too. @phdr should have
72100 * a leading colon.
72101 *
72102- * Note that this macros defines __per_cpu_load as an absolute symbol.
72103+ * Note that this macros defines per_cpu_load as an absolute symbol.
72104 * If there is no need to put the percpu section at a predetermined
72105 * address, use PERCPU_SECTION.
72106 */
72107 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72108- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72109- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72110+ per_cpu_load = .; \
72111+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72112 - LOAD_OFFSET) { \
72113+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72114 PERCPU_INPUT(cacheline) \
72115 } phdr \
72116- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72117+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72118
72119 /**
72120 * PERCPU_SECTION - define output section for percpu area, simple version
72121diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72122index 418d270..bfd2794 100644
72123--- a/include/crypto/algapi.h
72124+++ b/include/crypto/algapi.h
72125@@ -34,7 +34,7 @@ struct crypto_type {
72126 unsigned int maskclear;
72127 unsigned int maskset;
72128 unsigned int tfmsize;
72129-};
72130+} __do_const;
72131
72132 struct crypto_instance {
72133 struct crypto_alg alg;
72134diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72135index 12083dc..39740ec 100644
72136--- a/include/drm/drmP.h
72137+++ b/include/drm/drmP.h
72138@@ -69,6 +69,7 @@
72139 #include <linux/workqueue.h>
72140 #include <linux/poll.h>
72141 #include <asm/pgalloc.h>
72142+#include <asm/local.h>
72143 #include <drm/drm.h>
72144 #include <drm/drm_sarea.h>
72145
72146@@ -293,10 +294,12 @@ do { \
72147 * \param cmd command.
72148 * \param arg argument.
72149 */
72150-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72151+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72152+ struct drm_file *file_priv);
72153+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72154 struct drm_file *file_priv);
72155
72156-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72157+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72158 unsigned long arg);
72159
72160 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72161@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72162 struct drm_ioctl_desc {
72163 unsigned int cmd;
72164 int flags;
72165- drm_ioctl_t *func;
72166+ drm_ioctl_t func;
72167 unsigned int cmd_drv;
72168 const char *name;
72169-};
72170+} __do_const;
72171
72172 /**
72173 * Creates a driver or general drm_ioctl_desc array entry for the given
72174@@ -1015,7 +1018,7 @@ struct drm_info_list {
72175 int (*show)(struct seq_file*, void*); /** show callback */
72176 u32 driver_features; /**< Required driver features for this entry */
72177 void *data;
72178-};
72179+} __do_const;
72180
72181 /**
72182 * debugfs node structure. This structure represents a debugfs file.
72183@@ -1088,7 +1091,7 @@ struct drm_device {
72184
72185 /** \name Usage Counters */
72186 /*@{ */
72187- int open_count; /**< Outstanding files open */
72188+ local_t open_count; /**< Outstanding files open */
72189 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72190 atomic_t vma_count; /**< Outstanding vma areas open */
72191 int buf_use; /**< Buffers in use -- cannot alloc */
72192@@ -1099,7 +1102,7 @@ struct drm_device {
72193 /*@{ */
72194 unsigned long counters;
72195 enum drm_stat_type types[15];
72196- atomic_t counts[15];
72197+ atomic_unchecked_t counts[15];
72198 /*@} */
72199
72200 struct list_head filelist;
72201diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72202index f43d556..94d9343 100644
72203--- a/include/drm/drm_crtc_helper.h
72204+++ b/include/drm/drm_crtc_helper.h
72205@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72206 struct drm_connector *connector);
72207 /* disable encoder when not in use - more explicit than dpms off */
72208 void (*disable)(struct drm_encoder *encoder);
72209-};
72210+} __no_const;
72211
72212 /**
72213 * drm_connector_helper_funcs - helper operations for connectors
72214diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72215index 72dcbe8..8db58d7 100644
72216--- a/include/drm/ttm/ttm_memory.h
72217+++ b/include/drm/ttm/ttm_memory.h
72218@@ -48,7 +48,7 @@
72219
72220 struct ttm_mem_shrink {
72221 int (*do_shrink) (struct ttm_mem_shrink *);
72222-};
72223+} __no_const;
72224
72225 /**
72226 * struct ttm_mem_global - Global memory accounting structure.
72227diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72228index 4b840e8..155d235 100644
72229--- a/include/keys/asymmetric-subtype.h
72230+++ b/include/keys/asymmetric-subtype.h
72231@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72232 /* Verify the signature on a key of this subtype (optional) */
72233 int (*verify_signature)(const struct key *key,
72234 const struct public_key_signature *sig);
72235-};
72236+} __do_const;
72237
72238 /**
72239 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72240diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72241index c1da539..1dcec55 100644
72242--- a/include/linux/atmdev.h
72243+++ b/include/linux/atmdev.h
72244@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72245 #endif
72246
72247 struct k_atm_aal_stats {
72248-#define __HANDLE_ITEM(i) atomic_t i
72249+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72250 __AAL_STAT_ITEMS
72251 #undef __HANDLE_ITEM
72252 };
72253@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72254 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72255 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72256 struct module *owner;
72257-};
72258+} __do_const ;
72259
72260 struct atmphy_ops {
72261 int (*start)(struct atm_dev *dev);
72262diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72263index 70cf138..0418ee2 100644
72264--- a/include/linux/binfmts.h
72265+++ b/include/linux/binfmts.h
72266@@ -73,8 +73,10 @@ struct linux_binfmt {
72267 int (*load_binary)(struct linux_binprm *);
72268 int (*load_shlib)(struct file *);
72269 int (*core_dump)(struct coredump_params *cprm);
72270+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72271+ void (*handle_mmap)(struct file *);
72272 unsigned long min_coredump; /* minimal dump size */
72273-};
72274+} __do_const;
72275
72276 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72277
72278diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72279index 2fdb4a4..54aad7e 100644
72280--- a/include/linux/blkdev.h
72281+++ b/include/linux/blkdev.h
72282@@ -1526,7 +1526,7 @@ struct block_device_operations {
72283 /* this callback is with swap_lock and sometimes page table lock held */
72284 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72285 struct module *owner;
72286-};
72287+} __do_const;
72288
72289 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72290 unsigned long);
72291diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72292index 7c2e030..b72475d 100644
72293--- a/include/linux/blktrace_api.h
72294+++ b/include/linux/blktrace_api.h
72295@@ -23,7 +23,7 @@ struct blk_trace {
72296 struct dentry *dir;
72297 struct dentry *dropped_file;
72298 struct dentry *msg_file;
72299- atomic_t dropped;
72300+ atomic_unchecked_t dropped;
72301 };
72302
72303 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72304diff --git a/include/linux/cache.h b/include/linux/cache.h
72305index 4c57065..40346da 100644
72306--- a/include/linux/cache.h
72307+++ b/include/linux/cache.h
72308@@ -16,6 +16,14 @@
72309 #define __read_mostly
72310 #endif
72311
72312+#ifndef __read_only
72313+#ifdef CONFIG_PAX_KERNEXEC
72314+#error KERNEXEC requires __read_only
72315+#else
72316+#define __read_only __read_mostly
72317+#endif
72318+#endif
72319+
72320 #ifndef ____cacheline_aligned
72321 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72322 #endif
72323diff --git a/include/linux/capability.h b/include/linux/capability.h
72324index d9a4f7f4..19f77d6 100644
72325--- a/include/linux/capability.h
72326+++ b/include/linux/capability.h
72327@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72328 extern bool nsown_capable(int cap);
72329 extern bool inode_capable(const struct inode *inode, int cap);
72330 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72331+extern bool capable_nolog(int cap);
72332+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72333+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72334
72335 /* audit system wants to get cap info from files as well */
72336 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72337
72338+extern int is_privileged_binary(const struct dentry *dentry);
72339+
72340 #endif /* !_LINUX_CAPABILITY_H */
72341diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72342index 8609d57..86e4d79 100644
72343--- a/include/linux/cdrom.h
72344+++ b/include/linux/cdrom.h
72345@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72346
72347 /* driver specifications */
72348 const int capability; /* capability flags */
72349- int n_minors; /* number of active minor devices */
72350 /* handle uniform packets for scsi type devices (scsi,atapi) */
72351 int (*generic_packet) (struct cdrom_device_info *,
72352 struct packet_command *);
72353diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72354index 4ce9056..86caac6 100644
72355--- a/include/linux/cleancache.h
72356+++ b/include/linux/cleancache.h
72357@@ -31,7 +31,7 @@ struct cleancache_ops {
72358 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72359 void (*invalidate_inode)(int, struct cleancache_filekey);
72360 void (*invalidate_fs)(int);
72361-};
72362+} __no_const;
72363
72364 extern struct cleancache_ops *
72365 cleancache_register_ops(struct cleancache_ops *ops);
72366diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72367index 1ec14a7..d0654a2 100644
72368--- a/include/linux/clk-provider.h
72369+++ b/include/linux/clk-provider.h
72370@@ -132,6 +132,7 @@ struct clk_ops {
72371 unsigned long);
72372 void (*init)(struct clk_hw *hw);
72373 };
72374+typedef struct clk_ops __no_const clk_ops_no_const;
72375
72376 /**
72377 * struct clk_init_data - holds init data that's common to all clocks and is
72378diff --git a/include/linux/compat.h b/include/linux/compat.h
72379index ec1aee4..1077986 100644
72380--- a/include/linux/compat.h
72381+++ b/include/linux/compat.h
72382@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72383 compat_size_t __user *len_ptr);
72384
72385 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72386-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72387+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72388 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72389 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72390 compat_ssize_t msgsz, int msgflg);
72391@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72392 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72393 compat_ulong_t addr, compat_ulong_t data);
72394 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72395- compat_long_t addr, compat_long_t data);
72396+ compat_ulong_t addr, compat_ulong_t data);
72397
72398 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72399 /*
72400diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72401index ded4299..da50e3b 100644
72402--- a/include/linux/compiler-gcc4.h
72403+++ b/include/linux/compiler-gcc4.h
72404@@ -39,9 +39,29 @@
72405 # define __compiletime_warning(message) __attribute__((warning(message)))
72406 # define __compiletime_error(message) __attribute__((error(message)))
72407 #endif /* __CHECKER__ */
72408+
72409+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72410+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72411+#define __bos0(ptr) __bos((ptr), 0)
72412+#define __bos1(ptr) __bos((ptr), 1)
72413 #endif /* GCC_VERSION >= 40300 */
72414
72415 #if GCC_VERSION >= 40500
72416+
72417+#ifdef CONSTIFY_PLUGIN
72418+#define __no_const __attribute__((no_const))
72419+#define __do_const __attribute__((do_const))
72420+#endif
72421+
72422+#ifdef SIZE_OVERFLOW_PLUGIN
72423+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72424+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72425+#endif
72426+
72427+#ifdef LATENT_ENTROPY_PLUGIN
72428+#define __latent_entropy __attribute__((latent_entropy))
72429+#endif
72430+
72431 /*
72432 * Mark a position in code as unreachable. This can be used to
72433 * suppress control flow warnings after asm blocks that transfer
72434diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72435index 92669cd..1771a15 100644
72436--- a/include/linux/compiler.h
72437+++ b/include/linux/compiler.h
72438@@ -5,11 +5,14 @@
72439
72440 #ifdef __CHECKER__
72441 # define __user __attribute__((noderef, address_space(1)))
72442+# define __force_user __force __user
72443 # define __kernel __attribute__((address_space(0)))
72444+# define __force_kernel __force __kernel
72445 # define __safe __attribute__((safe))
72446 # define __force __attribute__((force))
72447 # define __nocast __attribute__((nocast))
72448 # define __iomem __attribute__((noderef, address_space(2)))
72449+# define __force_iomem __force __iomem
72450 # define __must_hold(x) __attribute__((context(x,1,1)))
72451 # define __acquires(x) __attribute__((context(x,0,1)))
72452 # define __releases(x) __attribute__((context(x,1,0)))
72453@@ -17,20 +20,37 @@
72454 # define __release(x) __context__(x,-1)
72455 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72456 # define __percpu __attribute__((noderef, address_space(3)))
72457+# define __force_percpu __force __percpu
72458 #ifdef CONFIG_SPARSE_RCU_POINTER
72459 # define __rcu __attribute__((noderef, address_space(4)))
72460+# define __force_rcu __force __rcu
72461 #else
72462 # define __rcu
72463+# define __force_rcu
72464 #endif
72465 extern void __chk_user_ptr(const volatile void __user *);
72466 extern void __chk_io_ptr(const volatile void __iomem *);
72467 #else
72468-# define __user
72469-# define __kernel
72470+# ifdef CHECKER_PLUGIN
72471+//# define __user
72472+//# define __force_user
72473+//# define __kernel
72474+//# define __force_kernel
72475+# else
72476+# ifdef STRUCTLEAK_PLUGIN
72477+# define __user __attribute__((user))
72478+# else
72479+# define __user
72480+# endif
72481+# define __force_user
72482+# define __kernel
72483+# define __force_kernel
72484+# endif
72485 # define __safe
72486 # define __force
72487 # define __nocast
72488 # define __iomem
72489+# define __force_iomem
72490 # define __chk_user_ptr(x) (void)0
72491 # define __chk_io_ptr(x) (void)0
72492 # define __builtin_warning(x, y...) (1)
72493@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72494 # define __release(x) (void)0
72495 # define __cond_lock(x,c) (c)
72496 # define __percpu
72497+# define __force_percpu
72498 # define __rcu
72499+# define __force_rcu
72500 #endif
72501
72502 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72503@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72504 # define __attribute_const__ /* unimplemented */
72505 #endif
72506
72507+#ifndef __no_const
72508+# define __no_const
72509+#endif
72510+
72511+#ifndef __do_const
72512+# define __do_const
72513+#endif
72514+
72515+#ifndef __size_overflow
72516+# define __size_overflow(...)
72517+#endif
72518+
72519+#ifndef __intentional_overflow
72520+# define __intentional_overflow(...)
72521+#endif
72522+
72523+#ifndef __latent_entropy
72524+# define __latent_entropy
72525+#endif
72526+
72527 /*
72528 * Tell gcc if a function is cold. The compiler will assume any path
72529 * directly leading to the call is unlikely.
72530@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72531 #define __cold
72532 #endif
72533
72534+#ifndef __alloc_size
72535+#define __alloc_size(...)
72536+#endif
72537+
72538+#ifndef __bos
72539+#define __bos(ptr, arg)
72540+#endif
72541+
72542+#ifndef __bos0
72543+#define __bos0(ptr)
72544+#endif
72545+
72546+#ifndef __bos1
72547+#define __bos1(ptr)
72548+#endif
72549+
72550 /* Simple shorthand for a section definition */
72551 #ifndef __section
72552 # define __section(S) __attribute__ ((__section__(#S)))
72553@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72554 * use is to mediate communication between process-level code and irq/NMI
72555 * handlers, all running on the same CPU.
72556 */
72557-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72558+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72559+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72560
72561 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72562 #ifdef CONFIG_KPROBES
72563diff --git a/include/linux/completion.h b/include/linux/completion.h
72564index 3cd574d..adce5fa 100644
72565--- a/include/linux/completion.h
72566+++ b/include/linux/completion.h
72567@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72568 extern void wait_for_completion(struct completion *);
72569 extern void wait_for_completion_io(struct completion *);
72570 extern int wait_for_completion_interruptible(struct completion *x);
72571-extern int wait_for_completion_killable(struct completion *x);
72572+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72573 extern unsigned long wait_for_completion_timeout(struct completion *x,
72574 unsigned long timeout);
72575 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72576 unsigned long timeout);
72577 extern long wait_for_completion_interruptible_timeout(
72578- struct completion *x, unsigned long timeout);
72579+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72580 extern long wait_for_completion_killable_timeout(
72581- struct completion *x, unsigned long timeout);
72582+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72583 extern bool try_wait_for_completion(struct completion *x);
72584 extern bool completion_done(struct completion *x);
72585
72586diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72587index 34025df..d94bbbc 100644
72588--- a/include/linux/configfs.h
72589+++ b/include/linux/configfs.h
72590@@ -125,7 +125,7 @@ struct configfs_attribute {
72591 const char *ca_name;
72592 struct module *ca_owner;
72593 umode_t ca_mode;
72594-};
72595+} __do_const;
72596
72597 /*
72598 * Users often need to create attribute structures for their configurable
72599diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72600index 90d5a15..950cb80 100644
72601--- a/include/linux/cpufreq.h
72602+++ b/include/linux/cpufreq.h
72603@@ -266,7 +266,7 @@ struct cpufreq_driver {
72604 int (*suspend) (struct cpufreq_policy *policy);
72605 int (*resume) (struct cpufreq_policy *policy);
72606 struct freq_attr **attr;
72607-};
72608+} __do_const;
72609
72610 /* flags */
72611
72612@@ -325,6 +325,7 @@ struct global_attr {
72613 ssize_t (*store)(struct kobject *a, struct attribute *b,
72614 const char *c, size_t count);
72615 };
72616+typedef struct global_attr __no_const global_attr_no_const;
72617
72618 #define define_one_global_ro(_name) \
72619 static struct global_attr _name = \
72620diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72621index 0bc4b74..973b368 100644
72622--- a/include/linux/cpuidle.h
72623+++ b/include/linux/cpuidle.h
72624@@ -52,7 +52,8 @@ struct cpuidle_state {
72625 int index);
72626
72627 int (*enter_dead) (struct cpuidle_device *dev, int index);
72628-};
72629+} __do_const;
72630+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72631
72632 /* Idle State Flags */
72633 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72634@@ -191,7 +192,7 @@ struct cpuidle_governor {
72635 void (*reflect) (struct cpuidle_device *dev, int index);
72636
72637 struct module *owner;
72638-};
72639+} __do_const;
72640
72641 #ifdef CONFIG_CPU_IDLE
72642
72643diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72644index d08e4d2..95fad61 100644
72645--- a/include/linux/cpumask.h
72646+++ b/include/linux/cpumask.h
72647@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72648 }
72649
72650 /* Valid inputs for n are -1 and 0. */
72651-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72652+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72653 {
72654 return n+1;
72655 }
72656
72657-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72658+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72659 {
72660 return n+1;
72661 }
72662
72663-static inline unsigned int cpumask_next_and(int n,
72664+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72665 const struct cpumask *srcp,
72666 const struct cpumask *andp)
72667 {
72668@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72669 *
72670 * Returns >= nr_cpu_ids if no further cpus set.
72671 */
72672-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72673+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72674 {
72675 /* -1 is a legal arg here. */
72676 if (n != -1)
72677@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72678 *
72679 * Returns >= nr_cpu_ids if no further cpus unset.
72680 */
72681-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72682+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72683 {
72684 /* -1 is a legal arg here. */
72685 if (n != -1)
72686@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72687 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72688 }
72689
72690-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72691+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72692 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72693
72694 /**
72695diff --git a/include/linux/cred.h b/include/linux/cred.h
72696index 04421e8..6bce4ef 100644
72697--- a/include/linux/cred.h
72698+++ b/include/linux/cred.h
72699@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72700 static inline void validate_process_creds(void)
72701 {
72702 }
72703+static inline void validate_task_creds(struct task_struct *task)
72704+{
72705+}
72706 #endif
72707
72708 /**
72709diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72710index b92eadf..b4ecdc1 100644
72711--- a/include/linux/crypto.h
72712+++ b/include/linux/crypto.h
72713@@ -373,7 +373,7 @@ struct cipher_tfm {
72714 const u8 *key, unsigned int keylen);
72715 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72716 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72717-};
72718+} __no_const;
72719
72720 struct hash_tfm {
72721 int (*init)(struct hash_desc *desc);
72722@@ -394,13 +394,13 @@ struct compress_tfm {
72723 int (*cot_decompress)(struct crypto_tfm *tfm,
72724 const u8 *src, unsigned int slen,
72725 u8 *dst, unsigned int *dlen);
72726-};
72727+} __no_const;
72728
72729 struct rng_tfm {
72730 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72731 unsigned int dlen);
72732 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72733-};
72734+} __no_const;
72735
72736 #define crt_ablkcipher crt_u.ablkcipher
72737 #define crt_aead crt_u.aead
72738diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72739index 653589e..4ef254a 100644
72740--- a/include/linux/ctype.h
72741+++ b/include/linux/ctype.h
72742@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72743 * Fast implementation of tolower() for internal usage. Do not use in your
72744 * code.
72745 */
72746-static inline char _tolower(const char c)
72747+static inline unsigned char _tolower(const unsigned char c)
72748 {
72749 return c | 0x20;
72750 }
72751diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72752index 7925bf0..d5143d2 100644
72753--- a/include/linux/decompress/mm.h
72754+++ b/include/linux/decompress/mm.h
72755@@ -77,7 +77,7 @@ static void free(void *where)
72756 * warnings when not needed (indeed large_malloc / large_free are not
72757 * needed by inflate */
72758
72759-#define malloc(a) kmalloc(a, GFP_KERNEL)
72760+#define malloc(a) kmalloc((a), GFP_KERNEL)
72761 #define free(a) kfree(a)
72762
72763 #define large_malloc(a) vmalloc(a)
72764diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72765index 5f1ab92..39c35ae 100644
72766--- a/include/linux/devfreq.h
72767+++ b/include/linux/devfreq.h
72768@@ -114,7 +114,7 @@ struct devfreq_governor {
72769 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72770 int (*event_handler)(struct devfreq *devfreq,
72771 unsigned int event, void *data);
72772-};
72773+} __do_const;
72774
72775 /**
72776 * struct devfreq - Device devfreq structure
72777diff --git a/include/linux/device.h b/include/linux/device.h
72778index 22b546a..a573dc9 100644
72779--- a/include/linux/device.h
72780+++ b/include/linux/device.h
72781@@ -305,7 +305,7 @@ struct subsys_interface {
72782 struct list_head node;
72783 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72784 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72785-};
72786+} __do_const;
72787
72788 int subsys_interface_register(struct subsys_interface *sif);
72789 void subsys_interface_unregister(struct subsys_interface *sif);
72790@@ -493,7 +493,7 @@ struct device_type {
72791 void (*release)(struct device *dev);
72792
72793 const struct dev_pm_ops *pm;
72794-};
72795+} __do_const;
72796
72797 /* interface for exporting device attributes */
72798 struct device_attribute {
72799@@ -503,11 +503,12 @@ struct device_attribute {
72800 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72801 const char *buf, size_t count);
72802 };
72803+typedef struct device_attribute __no_const device_attribute_no_const;
72804
72805 struct dev_ext_attribute {
72806 struct device_attribute attr;
72807 void *var;
72808-};
72809+} __do_const;
72810
72811 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72812 char *buf);
72813diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72814index 94af418..b1ca7a2 100644
72815--- a/include/linux/dma-mapping.h
72816+++ b/include/linux/dma-mapping.h
72817@@ -54,7 +54,7 @@ struct dma_map_ops {
72818 u64 (*get_required_mask)(struct device *dev);
72819 #endif
72820 int is_phys;
72821-};
72822+} __do_const;
72823
72824 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72825
72826diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72827index cb286b1..923d066 100644
72828--- a/include/linux/dmaengine.h
72829+++ b/include/linux/dmaengine.h
72830@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72831 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72832 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72833
72834-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72835+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72836 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72837-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72838+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72839 struct dma_pinned_list *pinned_list, struct page *page,
72840 unsigned int offset, size_t len);
72841
72842diff --git a/include/linux/efi.h b/include/linux/efi.h
72843index 5f8f176..62a0556 100644
72844--- a/include/linux/efi.h
72845+++ b/include/linux/efi.h
72846@@ -745,6 +745,7 @@ struct efivar_operations {
72847 efi_set_variable_t *set_variable;
72848 efi_query_variable_store_t *query_variable_store;
72849 };
72850+typedef struct efivar_operations __no_const efivar_operations_no_const;
72851
72852 struct efivars {
72853 /*
72854diff --git a/include/linux/elf.h b/include/linux/elf.h
72855index 40a3c0e..4c45a38 100644
72856--- a/include/linux/elf.h
72857+++ b/include/linux/elf.h
72858@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72859 #define elf_note elf32_note
72860 #define elf_addr_t Elf32_Off
72861 #define Elf_Half Elf32_Half
72862+#define elf_dyn Elf32_Dyn
72863
72864 #else
72865
72866@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72867 #define elf_note elf64_note
72868 #define elf_addr_t Elf64_Off
72869 #define Elf_Half Elf64_Half
72870+#define elf_dyn Elf64_Dyn
72871
72872 #endif
72873
72874diff --git a/include/linux/err.h b/include/linux/err.h
72875index 221fcfb..f29e5e2 100644
72876--- a/include/linux/err.h
72877+++ b/include/linux/err.h
72878@@ -19,12 +19,12 @@
72879
72880 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72881
72882-static inline void * __must_check ERR_PTR(long error)
72883+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72884 {
72885 return (void *) error;
72886 }
72887
72888-static inline long __must_check PTR_ERR(__force const void *ptr)
72889+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72890 {
72891 return (long) ptr;
72892 }
72893diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72894index fcb51c8..bdafcf6 100644
72895--- a/include/linux/extcon.h
72896+++ b/include/linux/extcon.h
72897@@ -134,7 +134,7 @@ struct extcon_dev {
72898 /* /sys/class/extcon/.../mutually_exclusive/... */
72899 struct attribute_group attr_g_muex;
72900 struct attribute **attrs_muex;
72901- struct device_attribute *d_attrs_muex;
72902+ device_attribute_no_const *d_attrs_muex;
72903 };
72904
72905 /**
72906diff --git a/include/linux/fb.h b/include/linux/fb.h
72907index ffac70a..ca3e711 100644
72908--- a/include/linux/fb.h
72909+++ b/include/linux/fb.h
72910@@ -304,7 +304,7 @@ struct fb_ops {
72911 /* called at KDB enter and leave time to prepare the console */
72912 int (*fb_debug_enter)(struct fb_info *info);
72913 int (*fb_debug_leave)(struct fb_info *info);
72914-};
72915+} __do_const;
72916
72917 #ifdef CONFIG_FB_TILEBLITTING
72918 #define FB_TILE_CURSOR_NONE 0
72919diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72920index 085197b..0fa6f0b 100644
72921--- a/include/linux/fdtable.h
72922+++ b/include/linux/fdtable.h
72923@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72924 void put_files_struct(struct files_struct *fs);
72925 void reset_files_struct(struct files_struct *);
72926 int unshare_files(struct files_struct **);
72927-struct files_struct *dup_fd(struct files_struct *, int *);
72928+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72929 void do_close_on_exec(struct files_struct *);
72930 int iterate_fd(struct files_struct *, unsigned,
72931 int (*)(const void *, struct file *, unsigned),
72932diff --git a/include/linux/filter.h b/include/linux/filter.h
72933index a6ac848..a104a76 100644
72934--- a/include/linux/filter.h
72935+++ b/include/linux/filter.h
72936@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72937
72938 struct sk_buff;
72939 struct sock;
72940+struct bpf_jit_work;
72941
72942 struct sk_filter
72943 {
72944@@ -27,6 +28,9 @@ struct sk_filter
72945 unsigned int len; /* Number of filter blocks */
72946 unsigned int (*bpf_func)(const struct sk_buff *skb,
72947 const struct sock_filter *filter);
72948+#ifdef CONFIG_BPF_JIT
72949+ struct bpf_jit_work *work;
72950+#endif
72951 struct rcu_head rcu;
72952 struct sock_filter insns[0];
72953 };
72954diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72955index 8293262..2b3b8bd 100644
72956--- a/include/linux/frontswap.h
72957+++ b/include/linux/frontswap.h
72958@@ -11,7 +11,7 @@ struct frontswap_ops {
72959 int (*load)(unsigned, pgoff_t, struct page *);
72960 void (*invalidate_page)(unsigned, pgoff_t);
72961 void (*invalidate_area)(unsigned);
72962-};
72963+} __no_const;
72964
72965 extern bool frontswap_enabled;
72966 extern struct frontswap_ops *
72967diff --git a/include/linux/fs.h b/include/linux/fs.h
72968index 9818747..788bfbd 100644
72969--- a/include/linux/fs.h
72970+++ b/include/linux/fs.h
72971@@ -1554,7 +1554,8 @@ struct file_operations {
72972 long (*fallocate)(struct file *file, int mode, loff_t offset,
72973 loff_t len);
72974 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72975-};
72976+} __do_const;
72977+typedef struct file_operations __no_const file_operations_no_const;
72978
72979 struct inode_operations {
72980 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72981@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72982 return !IS_DEADDIR(inode);
72983 }
72984
72985+static inline bool is_sidechannel_device(const struct inode *inode)
72986+{
72987+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72988+ umode_t mode = inode->i_mode;
72989+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72990+#else
72991+ return false;
72992+#endif
72993+}
72994+
72995 #endif /* _LINUX_FS_H */
72996diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72997index 2b93a9a..855d94a 100644
72998--- a/include/linux/fs_struct.h
72999+++ b/include/linux/fs_struct.h
73000@@ -6,7 +6,7 @@
73001 #include <linux/seqlock.h>
73002
73003 struct fs_struct {
73004- int users;
73005+ atomic_t users;
73006 spinlock_t lock;
73007 seqcount_t seq;
73008 int umask;
73009diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73010index a9ff9a3..1ba1788 100644
73011--- a/include/linux/fscache-cache.h
73012+++ b/include/linux/fscache-cache.h
73013@@ -113,7 +113,7 @@ struct fscache_operation {
73014 fscache_operation_release_t release;
73015 };
73016
73017-extern atomic_t fscache_op_debug_id;
73018+extern atomic_unchecked_t fscache_op_debug_id;
73019 extern void fscache_op_work_func(struct work_struct *work);
73020
73021 extern void fscache_enqueue_operation(struct fscache_operation *);
73022@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73023 INIT_WORK(&op->work, fscache_op_work_func);
73024 atomic_set(&op->usage, 1);
73025 op->state = FSCACHE_OP_ST_INITIALISED;
73026- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73027+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73028 op->processor = processor;
73029 op->release = release;
73030 INIT_LIST_HEAD(&op->pend_link);
73031diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73032index 7a08623..4c07b0f 100644
73033--- a/include/linux/fscache.h
73034+++ b/include/linux/fscache.h
73035@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73036 * - this is mandatory for any object that may have data
73037 */
73038 void (*now_uncached)(void *cookie_netfs_data);
73039-};
73040+} __do_const;
73041
73042 /*
73043 * fscache cached network filesystem type
73044diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73045index 1c804b0..1432c2b 100644
73046--- a/include/linux/fsnotify.h
73047+++ b/include/linux/fsnotify.h
73048@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73049 struct inode *inode = file_inode(file);
73050 __u32 mask = FS_ACCESS;
73051
73052+ if (is_sidechannel_device(inode))
73053+ return;
73054+
73055 if (S_ISDIR(inode->i_mode))
73056 mask |= FS_ISDIR;
73057
73058@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73059 struct inode *inode = file_inode(file);
73060 __u32 mask = FS_MODIFY;
73061
73062+ if (is_sidechannel_device(inode))
73063+ return;
73064+
73065 if (S_ISDIR(inode->i_mode))
73066 mask |= FS_ISDIR;
73067
73068@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73069 */
73070 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73071 {
73072- return kstrdup(name, GFP_KERNEL);
73073+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73074 }
73075
73076 /*
73077diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73078index 9f3c275..8bdff5d 100644
73079--- a/include/linux/genhd.h
73080+++ b/include/linux/genhd.h
73081@@ -194,7 +194,7 @@ struct gendisk {
73082 struct kobject *slave_dir;
73083
73084 struct timer_rand_state *random;
73085- atomic_t sync_io; /* RAID */
73086+ atomic_unchecked_t sync_io; /* RAID */
73087 struct disk_events *ev;
73088 #ifdef CONFIG_BLK_DEV_INTEGRITY
73089 struct blk_integrity *integrity;
73090@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
73091 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
73092
73093 /* drivers/char/random.c */
73094-extern void add_disk_randomness(struct gendisk *disk);
73095+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
73096 extern void rand_initialize_disk(struct gendisk *disk);
73097
73098 static inline sector_t get_start_sect(struct block_device *bdev)
73099diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73100index 023bc34..b02b46a 100644
73101--- a/include/linux/genl_magic_func.h
73102+++ b/include/linux/genl_magic_func.h
73103@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73104 },
73105
73106 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73107-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73108+static struct genl_ops ZZZ_genl_ops[] = {
73109 #include GENL_MAGIC_INCLUDE_FILE
73110 };
73111
73112diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73113index 9b4dd49..61fd41d 100644
73114--- a/include/linux/gfp.h
73115+++ b/include/linux/gfp.h
73116@@ -35,6 +35,13 @@ struct vm_area_struct;
73117 #define ___GFP_NO_KSWAPD 0x400000u
73118 #define ___GFP_OTHER_NODE 0x800000u
73119 #define ___GFP_WRITE 0x1000000u
73120+
73121+#ifdef CONFIG_PAX_USERCOPY_SLABS
73122+#define ___GFP_USERCOPY 0x2000000u
73123+#else
73124+#define ___GFP_USERCOPY 0
73125+#endif
73126+
73127 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73128
73129 /*
73130@@ -92,6 +99,7 @@ struct vm_area_struct;
73131 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73132 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73133 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73134+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73135
73136 /*
73137 * This may seem redundant, but it's a way of annotating false positives vs.
73138@@ -99,7 +107,7 @@ struct vm_area_struct;
73139 */
73140 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73141
73142-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73143+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73144 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73145
73146 /* This equals 0, but use constants in case they ever change */
73147@@ -153,6 +161,8 @@ struct vm_area_struct;
73148 /* 4GB DMA on some platforms */
73149 #define GFP_DMA32 __GFP_DMA32
73150
73151+#define GFP_USERCOPY __GFP_USERCOPY
73152+
73153 /* Convert GFP flags to their corresponding migrate type */
73154 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73155 {
73156diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73157new file mode 100644
73158index 0000000..ebe6d72
73159--- /dev/null
73160+++ b/include/linux/gracl.h
73161@@ -0,0 +1,319 @@
73162+#ifndef GR_ACL_H
73163+#define GR_ACL_H
73164+
73165+#include <linux/grdefs.h>
73166+#include <linux/resource.h>
73167+#include <linux/capability.h>
73168+#include <linux/dcache.h>
73169+#include <asm/resource.h>
73170+
73171+/* Major status information */
73172+
73173+#define GR_VERSION "grsecurity 2.9.1"
73174+#define GRSECURITY_VERSION 0x2901
73175+
73176+enum {
73177+ GR_SHUTDOWN = 0,
73178+ GR_ENABLE = 1,
73179+ GR_SPROLE = 2,
73180+ GR_RELOAD = 3,
73181+ GR_SEGVMOD = 4,
73182+ GR_STATUS = 5,
73183+ GR_UNSPROLE = 6,
73184+ GR_PASSSET = 7,
73185+ GR_SPROLEPAM = 8,
73186+};
73187+
73188+/* Password setup definitions
73189+ * kernel/grhash.c */
73190+enum {
73191+ GR_PW_LEN = 128,
73192+ GR_SALT_LEN = 16,
73193+ GR_SHA_LEN = 32,
73194+};
73195+
73196+enum {
73197+ GR_SPROLE_LEN = 64,
73198+};
73199+
73200+enum {
73201+ GR_NO_GLOB = 0,
73202+ GR_REG_GLOB,
73203+ GR_CREATE_GLOB
73204+};
73205+
73206+#define GR_NLIMITS 32
73207+
73208+/* Begin Data Structures */
73209+
73210+struct sprole_pw {
73211+ unsigned char *rolename;
73212+ unsigned char salt[GR_SALT_LEN];
73213+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73214+};
73215+
73216+struct name_entry {
73217+ __u32 key;
73218+ ino_t inode;
73219+ dev_t device;
73220+ char *name;
73221+ __u16 len;
73222+ __u8 deleted;
73223+ struct name_entry *prev;
73224+ struct name_entry *next;
73225+};
73226+
73227+struct inodev_entry {
73228+ struct name_entry *nentry;
73229+ struct inodev_entry *prev;
73230+ struct inodev_entry *next;
73231+};
73232+
73233+struct acl_role_db {
73234+ struct acl_role_label **r_hash;
73235+ __u32 r_size;
73236+};
73237+
73238+struct inodev_db {
73239+ struct inodev_entry **i_hash;
73240+ __u32 i_size;
73241+};
73242+
73243+struct name_db {
73244+ struct name_entry **n_hash;
73245+ __u32 n_size;
73246+};
73247+
73248+struct crash_uid {
73249+ uid_t uid;
73250+ unsigned long expires;
73251+};
73252+
73253+struct gr_hash_struct {
73254+ void **table;
73255+ void **nametable;
73256+ void *first;
73257+ __u32 table_size;
73258+ __u32 used_size;
73259+ int type;
73260+};
73261+
73262+/* Userspace Grsecurity ACL data structures */
73263+
73264+struct acl_subject_label {
73265+ char *filename;
73266+ ino_t inode;
73267+ dev_t device;
73268+ __u32 mode;
73269+ kernel_cap_t cap_mask;
73270+ kernel_cap_t cap_lower;
73271+ kernel_cap_t cap_invert_audit;
73272+
73273+ struct rlimit res[GR_NLIMITS];
73274+ __u32 resmask;
73275+
73276+ __u8 user_trans_type;
73277+ __u8 group_trans_type;
73278+ uid_t *user_transitions;
73279+ gid_t *group_transitions;
73280+ __u16 user_trans_num;
73281+ __u16 group_trans_num;
73282+
73283+ __u32 sock_families[2];
73284+ __u32 ip_proto[8];
73285+ __u32 ip_type;
73286+ struct acl_ip_label **ips;
73287+ __u32 ip_num;
73288+ __u32 inaddr_any_override;
73289+
73290+ __u32 crashes;
73291+ unsigned long expires;
73292+
73293+ struct acl_subject_label *parent_subject;
73294+ struct gr_hash_struct *hash;
73295+ struct acl_subject_label *prev;
73296+ struct acl_subject_label *next;
73297+
73298+ struct acl_object_label **obj_hash;
73299+ __u32 obj_hash_size;
73300+ __u16 pax_flags;
73301+};
73302+
73303+struct role_allowed_ip {
73304+ __u32 addr;
73305+ __u32 netmask;
73306+
73307+ struct role_allowed_ip *prev;
73308+ struct role_allowed_ip *next;
73309+};
73310+
73311+struct role_transition {
73312+ char *rolename;
73313+
73314+ struct role_transition *prev;
73315+ struct role_transition *next;
73316+};
73317+
73318+struct acl_role_label {
73319+ char *rolename;
73320+ uid_t uidgid;
73321+ __u16 roletype;
73322+
73323+ __u16 auth_attempts;
73324+ unsigned long expires;
73325+
73326+ struct acl_subject_label *root_label;
73327+ struct gr_hash_struct *hash;
73328+
73329+ struct acl_role_label *prev;
73330+ struct acl_role_label *next;
73331+
73332+ struct role_transition *transitions;
73333+ struct role_allowed_ip *allowed_ips;
73334+ uid_t *domain_children;
73335+ __u16 domain_child_num;
73336+
73337+ umode_t umask;
73338+
73339+ struct acl_subject_label **subj_hash;
73340+ __u32 subj_hash_size;
73341+};
73342+
73343+struct user_acl_role_db {
73344+ struct acl_role_label **r_table;
73345+ __u32 num_pointers; /* Number of allocations to track */
73346+ __u32 num_roles; /* Number of roles */
73347+ __u32 num_domain_children; /* Number of domain children */
73348+ __u32 num_subjects; /* Number of subjects */
73349+ __u32 num_objects; /* Number of objects */
73350+};
73351+
73352+struct acl_object_label {
73353+ char *filename;
73354+ ino_t inode;
73355+ dev_t device;
73356+ __u32 mode;
73357+
73358+ struct acl_subject_label *nested;
73359+ struct acl_object_label *globbed;
73360+
73361+ /* next two structures not used */
73362+
73363+ struct acl_object_label *prev;
73364+ struct acl_object_label *next;
73365+};
73366+
73367+struct acl_ip_label {
73368+ char *iface;
73369+ __u32 addr;
73370+ __u32 netmask;
73371+ __u16 low, high;
73372+ __u8 mode;
73373+ __u32 type;
73374+ __u32 proto[8];
73375+
73376+ /* next two structures not used */
73377+
73378+ struct acl_ip_label *prev;
73379+ struct acl_ip_label *next;
73380+};
73381+
73382+struct gr_arg {
73383+ struct user_acl_role_db role_db;
73384+ unsigned char pw[GR_PW_LEN];
73385+ unsigned char salt[GR_SALT_LEN];
73386+ unsigned char sum[GR_SHA_LEN];
73387+ unsigned char sp_role[GR_SPROLE_LEN];
73388+ struct sprole_pw *sprole_pws;
73389+ dev_t segv_device;
73390+ ino_t segv_inode;
73391+ uid_t segv_uid;
73392+ __u16 num_sprole_pws;
73393+ __u16 mode;
73394+};
73395+
73396+struct gr_arg_wrapper {
73397+ struct gr_arg *arg;
73398+ __u32 version;
73399+ __u32 size;
73400+};
73401+
73402+struct subject_map {
73403+ struct acl_subject_label *user;
73404+ struct acl_subject_label *kernel;
73405+ struct subject_map *prev;
73406+ struct subject_map *next;
73407+};
73408+
73409+struct acl_subj_map_db {
73410+ struct subject_map **s_hash;
73411+ __u32 s_size;
73412+};
73413+
73414+/* End Data Structures Section */
73415+
73416+/* Hash functions generated by empirical testing by Brad Spengler
73417+ Makes good use of the low bits of the inode. Generally 0-1 times
73418+ in loop for successful match. 0-3 for unsuccessful match.
73419+ Shift/add algorithm with modulus of table size and an XOR*/
73420+
73421+static __inline__ unsigned int
73422+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73423+{
73424+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73425+}
73426+
73427+ static __inline__ unsigned int
73428+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73429+{
73430+ return ((const unsigned long)userp % sz);
73431+}
73432+
73433+static __inline__ unsigned int
73434+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73435+{
73436+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73437+}
73438+
73439+static __inline__ unsigned int
73440+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73441+{
73442+ return full_name_hash((const unsigned char *)name, len) % sz;
73443+}
73444+
73445+#define FOR_EACH_ROLE_START(role) \
73446+ role = role_list; \
73447+ while (role) {
73448+
73449+#define FOR_EACH_ROLE_END(role) \
73450+ role = role->prev; \
73451+ }
73452+
73453+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73454+ subj = NULL; \
73455+ iter = 0; \
73456+ while (iter < role->subj_hash_size) { \
73457+ if (subj == NULL) \
73458+ subj = role->subj_hash[iter]; \
73459+ if (subj == NULL) { \
73460+ iter++; \
73461+ continue; \
73462+ }
73463+
73464+#define FOR_EACH_SUBJECT_END(subj,iter) \
73465+ subj = subj->next; \
73466+ if (subj == NULL) \
73467+ iter++; \
73468+ }
73469+
73470+
73471+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73472+ subj = role->hash->first; \
73473+ while (subj != NULL) {
73474+
73475+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73476+ subj = subj->next; \
73477+ }
73478+
73479+#endif
73480+
73481diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73482new file mode 100644
73483index 0000000..33ebd1f
73484--- /dev/null
73485+++ b/include/linux/gracl_compat.h
73486@@ -0,0 +1,156 @@
73487+#ifndef GR_ACL_COMPAT_H
73488+#define GR_ACL_COMPAT_H
73489+
73490+#include <linux/resource.h>
73491+#include <asm/resource.h>
73492+
73493+struct sprole_pw_compat {
73494+ compat_uptr_t rolename;
73495+ unsigned char salt[GR_SALT_LEN];
73496+ unsigned char sum[GR_SHA_LEN];
73497+};
73498+
73499+struct gr_hash_struct_compat {
73500+ compat_uptr_t table;
73501+ compat_uptr_t nametable;
73502+ compat_uptr_t first;
73503+ __u32 table_size;
73504+ __u32 used_size;
73505+ int type;
73506+};
73507+
73508+struct acl_subject_label_compat {
73509+ compat_uptr_t filename;
73510+ compat_ino_t inode;
73511+ __u32 device;
73512+ __u32 mode;
73513+ kernel_cap_t cap_mask;
73514+ kernel_cap_t cap_lower;
73515+ kernel_cap_t cap_invert_audit;
73516+
73517+ struct compat_rlimit res[GR_NLIMITS];
73518+ __u32 resmask;
73519+
73520+ __u8 user_trans_type;
73521+ __u8 group_trans_type;
73522+ compat_uptr_t user_transitions;
73523+ compat_uptr_t group_transitions;
73524+ __u16 user_trans_num;
73525+ __u16 group_trans_num;
73526+
73527+ __u32 sock_families[2];
73528+ __u32 ip_proto[8];
73529+ __u32 ip_type;
73530+ compat_uptr_t ips;
73531+ __u32 ip_num;
73532+ __u32 inaddr_any_override;
73533+
73534+ __u32 crashes;
73535+ compat_ulong_t expires;
73536+
73537+ compat_uptr_t parent_subject;
73538+ compat_uptr_t hash;
73539+ compat_uptr_t prev;
73540+ compat_uptr_t next;
73541+
73542+ compat_uptr_t obj_hash;
73543+ __u32 obj_hash_size;
73544+ __u16 pax_flags;
73545+};
73546+
73547+struct role_allowed_ip_compat {
73548+ __u32 addr;
73549+ __u32 netmask;
73550+
73551+ compat_uptr_t prev;
73552+ compat_uptr_t next;
73553+};
73554+
73555+struct role_transition_compat {
73556+ compat_uptr_t rolename;
73557+
73558+ compat_uptr_t prev;
73559+ compat_uptr_t next;
73560+};
73561+
73562+struct acl_role_label_compat {
73563+ compat_uptr_t rolename;
73564+ uid_t uidgid;
73565+ __u16 roletype;
73566+
73567+ __u16 auth_attempts;
73568+ compat_ulong_t expires;
73569+
73570+ compat_uptr_t root_label;
73571+ compat_uptr_t hash;
73572+
73573+ compat_uptr_t prev;
73574+ compat_uptr_t next;
73575+
73576+ compat_uptr_t transitions;
73577+ compat_uptr_t allowed_ips;
73578+ compat_uptr_t domain_children;
73579+ __u16 domain_child_num;
73580+
73581+ umode_t umask;
73582+
73583+ compat_uptr_t subj_hash;
73584+ __u32 subj_hash_size;
73585+};
73586+
73587+struct user_acl_role_db_compat {
73588+ compat_uptr_t r_table;
73589+ __u32 num_pointers;
73590+ __u32 num_roles;
73591+ __u32 num_domain_children;
73592+ __u32 num_subjects;
73593+ __u32 num_objects;
73594+};
73595+
73596+struct acl_object_label_compat {
73597+ compat_uptr_t filename;
73598+ compat_ino_t inode;
73599+ __u32 device;
73600+ __u32 mode;
73601+
73602+ compat_uptr_t nested;
73603+ compat_uptr_t globbed;
73604+
73605+ compat_uptr_t prev;
73606+ compat_uptr_t next;
73607+};
73608+
73609+struct acl_ip_label_compat {
73610+ compat_uptr_t iface;
73611+ __u32 addr;
73612+ __u32 netmask;
73613+ __u16 low, high;
73614+ __u8 mode;
73615+ __u32 type;
73616+ __u32 proto[8];
73617+
73618+ compat_uptr_t prev;
73619+ compat_uptr_t next;
73620+};
73621+
73622+struct gr_arg_compat {
73623+ struct user_acl_role_db_compat role_db;
73624+ unsigned char pw[GR_PW_LEN];
73625+ unsigned char salt[GR_SALT_LEN];
73626+ unsigned char sum[GR_SHA_LEN];
73627+ unsigned char sp_role[GR_SPROLE_LEN];
73628+ compat_uptr_t sprole_pws;
73629+ __u32 segv_device;
73630+ compat_ino_t segv_inode;
73631+ uid_t segv_uid;
73632+ __u16 num_sprole_pws;
73633+ __u16 mode;
73634+};
73635+
73636+struct gr_arg_wrapper_compat {
73637+ compat_uptr_t arg;
73638+ __u32 version;
73639+ __u32 size;
73640+};
73641+
73642+#endif
73643diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73644new file mode 100644
73645index 0000000..323ecf2
73646--- /dev/null
73647+++ b/include/linux/gralloc.h
73648@@ -0,0 +1,9 @@
73649+#ifndef __GRALLOC_H
73650+#define __GRALLOC_H
73651+
73652+void acl_free_all(void);
73653+int acl_alloc_stack_init(unsigned long size);
73654+void *acl_alloc(unsigned long len);
73655+void *acl_alloc_num(unsigned long num, unsigned long len);
73656+
73657+#endif
73658diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73659new file mode 100644
73660index 0000000..be66033
73661--- /dev/null
73662+++ b/include/linux/grdefs.h
73663@@ -0,0 +1,140 @@
73664+#ifndef GRDEFS_H
73665+#define GRDEFS_H
73666+
73667+/* Begin grsecurity status declarations */
73668+
73669+enum {
73670+ GR_READY = 0x01,
73671+ GR_STATUS_INIT = 0x00 // disabled state
73672+};
73673+
73674+/* Begin ACL declarations */
73675+
73676+/* Role flags */
73677+
73678+enum {
73679+ GR_ROLE_USER = 0x0001,
73680+ GR_ROLE_GROUP = 0x0002,
73681+ GR_ROLE_DEFAULT = 0x0004,
73682+ GR_ROLE_SPECIAL = 0x0008,
73683+ GR_ROLE_AUTH = 0x0010,
73684+ GR_ROLE_NOPW = 0x0020,
73685+ GR_ROLE_GOD = 0x0040,
73686+ GR_ROLE_LEARN = 0x0080,
73687+ GR_ROLE_TPE = 0x0100,
73688+ GR_ROLE_DOMAIN = 0x0200,
73689+ GR_ROLE_PAM = 0x0400,
73690+ GR_ROLE_PERSIST = 0x0800
73691+};
73692+
73693+/* ACL Subject and Object mode flags */
73694+enum {
73695+ GR_DELETED = 0x80000000
73696+};
73697+
73698+/* ACL Object-only mode flags */
73699+enum {
73700+ GR_READ = 0x00000001,
73701+ GR_APPEND = 0x00000002,
73702+ GR_WRITE = 0x00000004,
73703+ GR_EXEC = 0x00000008,
73704+ GR_FIND = 0x00000010,
73705+ GR_INHERIT = 0x00000020,
73706+ GR_SETID = 0x00000040,
73707+ GR_CREATE = 0x00000080,
73708+ GR_DELETE = 0x00000100,
73709+ GR_LINK = 0x00000200,
73710+ GR_AUDIT_READ = 0x00000400,
73711+ GR_AUDIT_APPEND = 0x00000800,
73712+ GR_AUDIT_WRITE = 0x00001000,
73713+ GR_AUDIT_EXEC = 0x00002000,
73714+ GR_AUDIT_FIND = 0x00004000,
73715+ GR_AUDIT_INHERIT= 0x00008000,
73716+ GR_AUDIT_SETID = 0x00010000,
73717+ GR_AUDIT_CREATE = 0x00020000,
73718+ GR_AUDIT_DELETE = 0x00040000,
73719+ GR_AUDIT_LINK = 0x00080000,
73720+ GR_PTRACERD = 0x00100000,
73721+ GR_NOPTRACE = 0x00200000,
73722+ GR_SUPPRESS = 0x00400000,
73723+ GR_NOLEARN = 0x00800000,
73724+ GR_INIT_TRANSFER= 0x01000000
73725+};
73726+
73727+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73728+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73729+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73730+
73731+/* ACL subject-only mode flags */
73732+enum {
73733+ GR_KILL = 0x00000001,
73734+ GR_VIEW = 0x00000002,
73735+ GR_PROTECTED = 0x00000004,
73736+ GR_LEARN = 0x00000008,
73737+ GR_OVERRIDE = 0x00000010,
73738+ /* just a placeholder, this mode is only used in userspace */
73739+ GR_DUMMY = 0x00000020,
73740+ GR_PROTSHM = 0x00000040,
73741+ GR_KILLPROC = 0x00000080,
73742+ GR_KILLIPPROC = 0x00000100,
73743+ /* just a placeholder, this mode is only used in userspace */
73744+ GR_NOTROJAN = 0x00000200,
73745+ GR_PROTPROCFD = 0x00000400,
73746+ GR_PROCACCT = 0x00000800,
73747+ GR_RELAXPTRACE = 0x00001000,
73748+ //GR_NESTED = 0x00002000,
73749+ GR_INHERITLEARN = 0x00004000,
73750+ GR_PROCFIND = 0x00008000,
73751+ GR_POVERRIDE = 0x00010000,
73752+ GR_KERNELAUTH = 0x00020000,
73753+ GR_ATSECURE = 0x00040000,
73754+ GR_SHMEXEC = 0x00080000
73755+};
73756+
73757+enum {
73758+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73759+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73760+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73761+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73762+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73763+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73764+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73765+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73766+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73767+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73768+};
73769+
73770+enum {
73771+ GR_ID_USER = 0x01,
73772+ GR_ID_GROUP = 0x02,
73773+};
73774+
73775+enum {
73776+ GR_ID_ALLOW = 0x01,
73777+ GR_ID_DENY = 0x02,
73778+};
73779+
73780+#define GR_CRASH_RES 31
73781+#define GR_UIDTABLE_MAX 500
73782+
73783+/* begin resource learning section */
73784+enum {
73785+ GR_RLIM_CPU_BUMP = 60,
73786+ GR_RLIM_FSIZE_BUMP = 50000,
73787+ GR_RLIM_DATA_BUMP = 10000,
73788+ GR_RLIM_STACK_BUMP = 1000,
73789+ GR_RLIM_CORE_BUMP = 10000,
73790+ GR_RLIM_RSS_BUMP = 500000,
73791+ GR_RLIM_NPROC_BUMP = 1,
73792+ GR_RLIM_NOFILE_BUMP = 5,
73793+ GR_RLIM_MEMLOCK_BUMP = 50000,
73794+ GR_RLIM_AS_BUMP = 500000,
73795+ GR_RLIM_LOCKS_BUMP = 2,
73796+ GR_RLIM_SIGPENDING_BUMP = 5,
73797+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73798+ GR_RLIM_NICE_BUMP = 1,
73799+ GR_RLIM_RTPRIO_BUMP = 1,
73800+ GR_RLIM_RTTIME_BUMP = 1000000
73801+};
73802+
73803+#endif
73804diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73805new file mode 100644
73806index 0000000..e337683
73807--- /dev/null
73808+++ b/include/linux/grinternal.h
73809@@ -0,0 +1,229 @@
73810+#ifndef __GRINTERNAL_H
73811+#define __GRINTERNAL_H
73812+
73813+#ifdef CONFIG_GRKERNSEC
73814+
73815+#include <linux/fs.h>
73816+#include <linux/mnt_namespace.h>
73817+#include <linux/nsproxy.h>
73818+#include <linux/gracl.h>
73819+#include <linux/grdefs.h>
73820+#include <linux/grmsg.h>
73821+
73822+void gr_add_learn_entry(const char *fmt, ...)
73823+ __attribute__ ((format (printf, 1, 2)));
73824+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73825+ const struct vfsmount *mnt);
73826+__u32 gr_check_create(const struct dentry *new_dentry,
73827+ const struct dentry *parent,
73828+ const struct vfsmount *mnt, const __u32 mode);
73829+int gr_check_protected_task(const struct task_struct *task);
73830+__u32 to_gr_audit(const __u32 reqmode);
73831+int gr_set_acls(const int type);
73832+int gr_apply_subject_to_task(struct task_struct *task);
73833+int gr_acl_is_enabled(void);
73834+char gr_roletype_to_char(void);
73835+
73836+void gr_handle_alertkill(struct task_struct *task);
73837+char *gr_to_filename(const struct dentry *dentry,
73838+ const struct vfsmount *mnt);
73839+char *gr_to_filename1(const struct dentry *dentry,
73840+ const struct vfsmount *mnt);
73841+char *gr_to_filename2(const struct dentry *dentry,
73842+ const struct vfsmount *mnt);
73843+char *gr_to_filename3(const struct dentry *dentry,
73844+ const struct vfsmount *mnt);
73845+
73846+extern int grsec_enable_ptrace_readexec;
73847+extern int grsec_enable_harden_ptrace;
73848+extern int grsec_enable_link;
73849+extern int grsec_enable_fifo;
73850+extern int grsec_enable_execve;
73851+extern int grsec_enable_shm;
73852+extern int grsec_enable_execlog;
73853+extern int grsec_enable_signal;
73854+extern int grsec_enable_audit_ptrace;
73855+extern int grsec_enable_forkfail;
73856+extern int grsec_enable_time;
73857+extern int grsec_enable_rofs;
73858+extern int grsec_deny_new_usb;
73859+extern int grsec_enable_chroot_shmat;
73860+extern int grsec_enable_chroot_mount;
73861+extern int grsec_enable_chroot_double;
73862+extern int grsec_enable_chroot_pivot;
73863+extern int grsec_enable_chroot_chdir;
73864+extern int grsec_enable_chroot_chmod;
73865+extern int grsec_enable_chroot_mknod;
73866+extern int grsec_enable_chroot_fchdir;
73867+extern int grsec_enable_chroot_nice;
73868+extern int grsec_enable_chroot_execlog;
73869+extern int grsec_enable_chroot_caps;
73870+extern int grsec_enable_chroot_sysctl;
73871+extern int grsec_enable_chroot_unix;
73872+extern int grsec_enable_symlinkown;
73873+extern kgid_t grsec_symlinkown_gid;
73874+extern int grsec_enable_tpe;
73875+extern kgid_t grsec_tpe_gid;
73876+extern int grsec_enable_tpe_all;
73877+extern int grsec_enable_tpe_invert;
73878+extern int grsec_enable_socket_all;
73879+extern kgid_t grsec_socket_all_gid;
73880+extern int grsec_enable_socket_client;
73881+extern kgid_t grsec_socket_client_gid;
73882+extern int grsec_enable_socket_server;
73883+extern kgid_t grsec_socket_server_gid;
73884+extern kgid_t grsec_audit_gid;
73885+extern int grsec_enable_group;
73886+extern int grsec_enable_log_rwxmaps;
73887+extern int grsec_enable_mount;
73888+extern int grsec_enable_chdir;
73889+extern int grsec_resource_logging;
73890+extern int grsec_enable_blackhole;
73891+extern int grsec_lastack_retries;
73892+extern int grsec_enable_brute;
73893+extern int grsec_lock;
73894+
73895+extern spinlock_t grsec_alert_lock;
73896+extern unsigned long grsec_alert_wtime;
73897+extern unsigned long grsec_alert_fyet;
73898+
73899+extern spinlock_t grsec_audit_lock;
73900+
73901+extern rwlock_t grsec_exec_file_lock;
73902+
73903+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73904+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73905+ (tsk)->exec_file->f_path.mnt) : "/")
73906+
73907+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73908+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73909+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73910+
73911+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73912+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73913+ (tsk)->exec_file->f_path.mnt) : "/")
73914+
73915+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73916+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73917+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73918+
73919+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73920+
73921+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73922+
73923+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73924+{
73925+ if (file1 && file2) {
73926+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73927+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73928+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73929+ return true;
73930+ }
73931+
73932+ return false;
73933+}
73934+
73935+#define GR_CHROOT_CAPS {{ \
73936+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73937+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73938+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73939+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73940+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73941+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73942+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73943+
73944+#define security_learn(normal_msg,args...) \
73945+({ \
73946+ read_lock(&grsec_exec_file_lock); \
73947+ gr_add_learn_entry(normal_msg "\n", ## args); \
73948+ read_unlock(&grsec_exec_file_lock); \
73949+})
73950+
73951+enum {
73952+ GR_DO_AUDIT,
73953+ GR_DONT_AUDIT,
73954+ /* used for non-audit messages that we shouldn't kill the task on */
73955+ GR_DONT_AUDIT_GOOD
73956+};
73957+
73958+enum {
73959+ GR_TTYSNIFF,
73960+ GR_RBAC,
73961+ GR_RBAC_STR,
73962+ GR_STR_RBAC,
73963+ GR_RBAC_MODE2,
73964+ GR_RBAC_MODE3,
73965+ GR_FILENAME,
73966+ GR_SYSCTL_HIDDEN,
73967+ GR_NOARGS,
73968+ GR_ONE_INT,
73969+ GR_ONE_INT_TWO_STR,
73970+ GR_ONE_STR,
73971+ GR_STR_INT,
73972+ GR_TWO_STR_INT,
73973+ GR_TWO_INT,
73974+ GR_TWO_U64,
73975+ GR_THREE_INT,
73976+ GR_FIVE_INT_TWO_STR,
73977+ GR_TWO_STR,
73978+ GR_THREE_STR,
73979+ GR_FOUR_STR,
73980+ GR_STR_FILENAME,
73981+ GR_FILENAME_STR,
73982+ GR_FILENAME_TWO_INT,
73983+ GR_FILENAME_TWO_INT_STR,
73984+ GR_TEXTREL,
73985+ GR_PTRACE,
73986+ GR_RESOURCE,
73987+ GR_CAP,
73988+ GR_SIG,
73989+ GR_SIG2,
73990+ GR_CRASH1,
73991+ GR_CRASH2,
73992+ GR_PSACCT,
73993+ GR_RWXMAP,
73994+ GR_RWXMAPVMA
73995+};
73996+
73997+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73998+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73999+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74000+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74001+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74002+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74003+#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)
74004+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74005+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74006+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74007+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74008+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74009+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74010+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74011+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74012+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74013+#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)
74014+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74015+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74016+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74017+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74018+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74019+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74020+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74021+#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)
74022+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74023+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74024+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74025+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74026+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74027+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74028+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74029+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74030+#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)
74031+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74032+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74033+
74034+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74035+
74036+#endif
74037+
74038+#endif
74039diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74040new file mode 100644
74041index 0000000..a4396b5
74042--- /dev/null
74043+++ b/include/linux/grmsg.h
74044@@ -0,0 +1,113 @@
74045+#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"
74046+#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"
74047+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74048+#define GR_STOPMOD_MSG "denied modification of module state by "
74049+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74050+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74051+#define GR_IOPERM_MSG "denied use of ioperm() by "
74052+#define GR_IOPL_MSG "denied use of iopl() by "
74053+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74054+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74055+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74056+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74057+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74058+#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"
74059+#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"
74060+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74061+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74062+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74063+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74064+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74065+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74066+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74067+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74068+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74069+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74070+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74071+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74072+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74073+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74074+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74075+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74076+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74077+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74078+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74079+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74080+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74081+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74082+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74083+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74084+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74085+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74086+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74087+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74088+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74089+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74090+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74091+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74092+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74093+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74094+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74095+#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"
74096+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74097+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74098+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74099+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74100+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74101+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74102+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74103+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74104+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74105+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74106+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74107+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74108+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74109+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74110+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74111+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74112+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74113+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74114+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74115+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74116+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74117+#define GR_NICE_CHROOT_MSG "denied priority change by "
74118+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74119+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74120+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74121+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74122+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74123+#define GR_TIME_MSG "time set by "
74124+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74125+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74126+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74127+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74128+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74129+#define GR_BIND_MSG "denied bind() by "
74130+#define GR_CONNECT_MSG "denied connect() by "
74131+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74132+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74133+#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"
74134+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74135+#define GR_CAP_ACL_MSG "use of %s denied for "
74136+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74137+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74138+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74139+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74140+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74141+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74142+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74143+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74144+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74145+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74146+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74147+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74148+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74149+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74150+#define GR_VM86_MSG "denied use of vm86 by "
74151+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74152+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74153+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74154+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74155+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74156+#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 "
74157+#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 "
74158diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74159new file mode 100644
74160index 0000000..d6f5a21
74161--- /dev/null
74162+++ b/include/linux/grsecurity.h
74163@@ -0,0 +1,244 @@
74164+#ifndef GR_SECURITY_H
74165+#define GR_SECURITY_H
74166+#include <linux/fs.h>
74167+#include <linux/fs_struct.h>
74168+#include <linux/binfmts.h>
74169+#include <linux/gracl.h>
74170+
74171+/* notify of brain-dead configs */
74172+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74173+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74174+#endif
74175+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74176+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74177+#endif
74178+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74179+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74180+#endif
74181+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74182+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74183+#endif
74184+
74185+int gr_handle_new_usb(void);
74186+
74187+void gr_handle_brute_attach(unsigned long mm_flags);
74188+void gr_handle_brute_check(void);
74189+void gr_handle_kernel_exploit(void);
74190+
74191+char gr_roletype_to_char(void);
74192+
74193+int gr_acl_enable_at_secure(void);
74194+
74195+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74196+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74197+
74198+void gr_del_task_from_ip_table(struct task_struct *p);
74199+
74200+int gr_pid_is_chrooted(struct task_struct *p);
74201+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74202+int gr_handle_chroot_nice(void);
74203+int gr_handle_chroot_sysctl(const int op);
74204+int gr_handle_chroot_setpriority(struct task_struct *p,
74205+ const int niceval);
74206+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74207+int gr_handle_chroot_chroot(const struct dentry *dentry,
74208+ const struct vfsmount *mnt);
74209+void gr_handle_chroot_chdir(const struct path *path);
74210+int gr_handle_chroot_chmod(const struct dentry *dentry,
74211+ const struct vfsmount *mnt, const int mode);
74212+int gr_handle_chroot_mknod(const struct dentry *dentry,
74213+ const struct vfsmount *mnt, const int mode);
74214+int gr_handle_chroot_mount(const struct dentry *dentry,
74215+ const struct vfsmount *mnt,
74216+ const char *dev_name);
74217+int gr_handle_chroot_pivot(void);
74218+int gr_handle_chroot_unix(const pid_t pid);
74219+
74220+int gr_handle_rawio(const struct inode *inode);
74221+
74222+void gr_handle_ioperm(void);
74223+void gr_handle_iopl(void);
74224+
74225+umode_t gr_acl_umask(void);
74226+
74227+int gr_tpe_allow(const struct file *file);
74228+
74229+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74230+void gr_clear_chroot_entries(struct task_struct *task);
74231+
74232+void gr_log_forkfail(const int retval);
74233+void gr_log_timechange(void);
74234+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74235+void gr_log_chdir(const struct dentry *dentry,
74236+ const struct vfsmount *mnt);
74237+void gr_log_chroot_exec(const struct dentry *dentry,
74238+ const struct vfsmount *mnt);
74239+void gr_log_remount(const char *devname, const int retval);
74240+void gr_log_unmount(const char *devname, const int retval);
74241+void gr_log_mount(const char *from, const char *to, const int retval);
74242+void gr_log_textrel(struct vm_area_struct *vma);
74243+void gr_log_ptgnustack(struct file *file);
74244+void gr_log_rwxmmap(struct file *file);
74245+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74246+
74247+int gr_handle_follow_link(const struct inode *parent,
74248+ const struct inode *inode,
74249+ const struct dentry *dentry,
74250+ const struct vfsmount *mnt);
74251+int gr_handle_fifo(const struct dentry *dentry,
74252+ const struct vfsmount *mnt,
74253+ const struct dentry *dir, const int flag,
74254+ const int acc_mode);
74255+int gr_handle_hardlink(const struct dentry *dentry,
74256+ const struct vfsmount *mnt,
74257+ struct inode *inode,
74258+ const int mode, const struct filename *to);
74259+
74260+int gr_is_capable(const int cap);
74261+int gr_is_capable_nolog(const int cap);
74262+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74263+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74264+
74265+void gr_copy_label(struct task_struct *tsk);
74266+void gr_handle_crash(struct task_struct *task, const int sig);
74267+int gr_handle_signal(const struct task_struct *p, const int sig);
74268+int gr_check_crash_uid(const kuid_t uid);
74269+int gr_check_protected_task(const struct task_struct *task);
74270+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74271+int gr_acl_handle_mmap(const struct file *file,
74272+ const unsigned long prot);
74273+int gr_acl_handle_mprotect(const struct file *file,
74274+ const unsigned long prot);
74275+int gr_check_hidden_task(const struct task_struct *tsk);
74276+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74277+ const struct vfsmount *mnt);
74278+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74279+ const struct vfsmount *mnt);
74280+__u32 gr_acl_handle_access(const struct dentry *dentry,
74281+ const struct vfsmount *mnt, const int fmode);
74282+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74283+ const struct vfsmount *mnt, umode_t *mode);
74284+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74285+ const struct vfsmount *mnt);
74286+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74287+ const struct vfsmount *mnt);
74288+int gr_handle_ptrace(struct task_struct *task, const long request);
74289+int gr_handle_proc_ptrace(struct task_struct *task);
74290+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74291+ const struct vfsmount *mnt);
74292+int gr_check_crash_exec(const struct file *filp);
74293+int gr_acl_is_enabled(void);
74294+void gr_set_kernel_label(struct task_struct *task);
74295+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74296+ const kgid_t gid);
74297+int gr_set_proc_label(const struct dentry *dentry,
74298+ const struct vfsmount *mnt,
74299+ const int unsafe_flags);
74300+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74301+ const struct vfsmount *mnt);
74302+__u32 gr_acl_handle_open(const struct dentry *dentry,
74303+ const struct vfsmount *mnt, int acc_mode);
74304+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74305+ const struct dentry *p_dentry,
74306+ const struct vfsmount *p_mnt,
74307+ int open_flags, int acc_mode, const int imode);
74308+void gr_handle_create(const struct dentry *dentry,
74309+ const struct vfsmount *mnt);
74310+void gr_handle_proc_create(const struct dentry *dentry,
74311+ const struct inode *inode);
74312+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74313+ const struct dentry *parent_dentry,
74314+ const struct vfsmount *parent_mnt,
74315+ const int mode);
74316+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74317+ const struct dentry *parent_dentry,
74318+ const struct vfsmount *parent_mnt);
74319+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74320+ const struct vfsmount *mnt);
74321+void gr_handle_delete(const ino_t ino, const dev_t dev);
74322+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74323+ const struct vfsmount *mnt);
74324+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74325+ const struct dentry *parent_dentry,
74326+ const struct vfsmount *parent_mnt,
74327+ const struct filename *from);
74328+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74329+ const struct dentry *parent_dentry,
74330+ const struct vfsmount *parent_mnt,
74331+ const struct dentry *old_dentry,
74332+ const struct vfsmount *old_mnt, const struct filename *to);
74333+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74334+int gr_acl_handle_rename(struct dentry *new_dentry,
74335+ struct dentry *parent_dentry,
74336+ const struct vfsmount *parent_mnt,
74337+ struct dentry *old_dentry,
74338+ struct inode *old_parent_inode,
74339+ struct vfsmount *old_mnt, const struct filename *newname);
74340+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74341+ struct dentry *old_dentry,
74342+ struct dentry *new_dentry,
74343+ struct vfsmount *mnt, const __u8 replace);
74344+__u32 gr_check_link(const struct dentry *new_dentry,
74345+ const struct dentry *parent_dentry,
74346+ const struct vfsmount *parent_mnt,
74347+ const struct dentry *old_dentry,
74348+ const struct vfsmount *old_mnt);
74349+int gr_acl_handle_filldir(const struct file *file, const char *name,
74350+ const unsigned int namelen, const ino_t ino);
74351+
74352+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74353+ const struct vfsmount *mnt);
74354+void gr_acl_handle_exit(void);
74355+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74356+int gr_acl_handle_procpidmem(const struct task_struct *task);
74357+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74358+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74359+void gr_audit_ptrace(struct task_struct *task);
74360+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74361+void gr_put_exec_file(struct task_struct *task);
74362+
74363+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74364+
74365+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74366+extern void gr_learn_resource(const struct task_struct *task, const int res,
74367+ const unsigned long wanted, const int gt);
74368+#else
74369+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74370+ const unsigned long wanted, const int gt)
74371+{
74372+}
74373+#endif
74374+
74375+#ifdef CONFIG_GRKERNSEC_RESLOG
74376+extern void gr_log_resource(const struct task_struct *task, const int res,
74377+ const unsigned long wanted, const int gt);
74378+#else
74379+static inline void gr_log_resource(const struct task_struct *task, const int res,
74380+ const unsigned long wanted, const int gt)
74381+{
74382+}
74383+#endif
74384+
74385+#ifdef CONFIG_GRKERNSEC
74386+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74387+void gr_handle_vm86(void);
74388+void gr_handle_mem_readwrite(u64 from, u64 to);
74389+
74390+void gr_log_badprocpid(const char *entry);
74391+
74392+extern int grsec_enable_dmesg;
74393+extern int grsec_disable_privio;
74394+
74395+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74396+extern kgid_t grsec_proc_gid;
74397+#endif
74398+
74399+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74400+extern int grsec_enable_chroot_findtask;
74401+#endif
74402+#ifdef CONFIG_GRKERNSEC_SETXID
74403+extern int grsec_enable_setxid;
74404+#endif
74405+#endif
74406+
74407+#endif
74408diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74409new file mode 100644
74410index 0000000..e7ffaaf
74411--- /dev/null
74412+++ b/include/linux/grsock.h
74413@@ -0,0 +1,19 @@
74414+#ifndef __GRSOCK_H
74415+#define __GRSOCK_H
74416+
74417+extern void gr_attach_curr_ip(const struct sock *sk);
74418+extern int gr_handle_sock_all(const int family, const int type,
74419+ const int protocol);
74420+extern int gr_handle_sock_server(const struct sockaddr *sck);
74421+extern int gr_handle_sock_server_other(const struct sock *sck);
74422+extern int gr_handle_sock_client(const struct sockaddr *sck);
74423+extern int gr_search_connect(struct socket * sock,
74424+ struct sockaddr_in * addr);
74425+extern int gr_search_bind(struct socket * sock,
74426+ struct sockaddr_in * addr);
74427+extern int gr_search_listen(struct socket * sock);
74428+extern int gr_search_accept(struct socket * sock);
74429+extern int gr_search_socket(const int domain, const int type,
74430+ const int protocol);
74431+
74432+#endif
74433diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74434index 7fb31da..08b5114 100644
74435--- a/include/linux/highmem.h
74436+++ b/include/linux/highmem.h
74437@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74438 kunmap_atomic(kaddr);
74439 }
74440
74441+static inline void sanitize_highpage(struct page *page)
74442+{
74443+ void *kaddr;
74444+ unsigned long flags;
74445+
74446+ local_irq_save(flags);
74447+ kaddr = kmap_atomic(page);
74448+ clear_page(kaddr);
74449+ kunmap_atomic(kaddr);
74450+ local_irq_restore(flags);
74451+}
74452+
74453 static inline void zero_user_segments(struct page *page,
74454 unsigned start1, unsigned end1,
74455 unsigned start2, unsigned end2)
74456diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74457index 1c7b89a..7f52502 100644
74458--- a/include/linux/hwmon-sysfs.h
74459+++ b/include/linux/hwmon-sysfs.h
74460@@ -25,7 +25,8 @@
74461 struct sensor_device_attribute{
74462 struct device_attribute dev_attr;
74463 int index;
74464-};
74465+} __do_const;
74466+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74467 #define to_sensor_dev_attr(_dev_attr) \
74468 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74469
74470@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74471 struct device_attribute dev_attr;
74472 u8 index;
74473 u8 nr;
74474-};
74475+} __do_const;
74476 #define to_sensor_dev_attr_2(_dev_attr) \
74477 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74478
74479diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74480index e988fa9..ff9f17e 100644
74481--- a/include/linux/i2c.h
74482+++ b/include/linux/i2c.h
74483@@ -366,6 +366,7 @@ struct i2c_algorithm {
74484 /* To determine what the adapter supports */
74485 u32 (*functionality) (struct i2c_adapter *);
74486 };
74487+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74488
74489 /**
74490 * struct i2c_bus_recovery_info - I2C bus recovery information
74491diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74492index d23c3c2..eb63c81 100644
74493--- a/include/linux/i2o.h
74494+++ b/include/linux/i2o.h
74495@@ -565,7 +565,7 @@ struct i2o_controller {
74496 struct i2o_device *exec; /* Executive */
74497 #if BITS_PER_LONG == 64
74498 spinlock_t context_list_lock; /* lock for context_list */
74499- atomic_t context_list_counter; /* needed for unique contexts */
74500+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74501 struct list_head context_list; /* list of context id's
74502 and pointers */
74503 #endif
74504diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74505index aff7ad8..3942bbd 100644
74506--- a/include/linux/if_pppox.h
74507+++ b/include/linux/if_pppox.h
74508@@ -76,7 +76,7 @@ struct pppox_proto {
74509 int (*ioctl)(struct socket *sock, unsigned int cmd,
74510 unsigned long arg);
74511 struct module *owner;
74512-};
74513+} __do_const;
74514
74515 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74516 extern void unregister_pppox_proto(int proto_num);
74517diff --git a/include/linux/init.h b/include/linux/init.h
74518index e73f2b7..cc996e0 100644
74519--- a/include/linux/init.h
74520+++ b/include/linux/init.h
74521@@ -39,9 +39,17 @@
74522 * Also note, that this data cannot be "const".
74523 */
74524
74525+#define add_init_latent_entropy __latent_entropy
74526+
74527+#ifdef CONFIG_MEMORY_HOTPLUG
74528+#define add_meminit_latent_entropy
74529+#else
74530+#define add_meminit_latent_entropy __latent_entropy
74531+#endif
74532+
74533 /* These are for everybody (although not all archs will actually
74534 discard it in modules) */
74535-#define __init __section(.init.text) __cold notrace
74536+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74537 #define __initdata __section(.init.data)
74538 #define __initconst __constsection(.init.rodata)
74539 #define __exitdata __section(.exit.data)
74540@@ -102,7 +110,7 @@
74541 #define __cpuexitconst
74542
74543 /* Used for MEMORY_HOTPLUG */
74544-#define __meminit __section(.meminit.text) __cold notrace
74545+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74546 #define __meminitdata __section(.meminit.data)
74547 #define __meminitconst __constsection(.meminit.rodata)
74548 #define __memexit __section(.memexit.text) __exitused __cold notrace
74549diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74550index 5cd0f09..c9f67cc 100644
74551--- a/include/linux/init_task.h
74552+++ b/include/linux/init_task.h
74553@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74554
74555 #define INIT_TASK_COMM "swapper"
74556
74557+#ifdef CONFIG_X86
74558+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74559+#else
74560+#define INIT_TASK_THREAD_INFO
74561+#endif
74562+
74563 /*
74564 * INIT_TASK is used to set up the first task table, touch at
74565 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74566@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74567 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74568 .comm = INIT_TASK_COMM, \
74569 .thread = INIT_THREAD, \
74570+ INIT_TASK_THREAD_INFO \
74571 .fs = &init_fs, \
74572 .files = &init_files, \
74573 .signal = &init_signals, \
74574diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74575index 5fa5afe..ac55b25 100644
74576--- a/include/linux/interrupt.h
74577+++ b/include/linux/interrupt.h
74578@@ -430,7 +430,7 @@ enum
74579 /* map softirq index to softirq name. update 'softirq_to_name' in
74580 * kernel/softirq.c when adding a new softirq.
74581 */
74582-extern char *softirq_to_name[NR_SOFTIRQS];
74583+extern const char * const softirq_to_name[NR_SOFTIRQS];
74584
74585 /* softirq mask and active fields moved to irq_cpustat_t in
74586 * asm/hardirq.h to get better cache usage. KAO
74587@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74588
74589 struct softirq_action
74590 {
74591- void (*action)(struct softirq_action *);
74592-};
74593+ void (*action)(void);
74594+} __no_const;
74595
74596 asmlinkage void do_softirq(void);
74597 asmlinkage void __do_softirq(void);
74598-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74599+extern void open_softirq(int nr, void (*action)(void));
74600 extern void softirq_init(void);
74601 extern void __raise_softirq_irqoff(unsigned int nr);
74602
74603diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74604index 3aeb730..2177f39 100644
74605--- a/include/linux/iommu.h
74606+++ b/include/linux/iommu.h
74607@@ -113,7 +113,7 @@ struct iommu_ops {
74608 u32 (*domain_get_windows)(struct iommu_domain *domain);
74609
74610 unsigned long pgsize_bitmap;
74611-};
74612+} __do_const;
74613
74614 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74615 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74616diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74617index 89b7c24..382af74 100644
74618--- a/include/linux/ioport.h
74619+++ b/include/linux/ioport.h
74620@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74621 int adjust_resource(struct resource *res, resource_size_t start,
74622 resource_size_t size);
74623 resource_size_t resource_alignment(struct resource *res);
74624-static inline resource_size_t resource_size(const struct resource *res)
74625+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74626 {
74627 return res->end - res->start + 1;
74628 }
74629diff --git a/include/linux/irq.h b/include/linux/irq.h
74630index f04d3ba..bcf2cfb 100644
74631--- a/include/linux/irq.h
74632+++ b/include/linux/irq.h
74633@@ -333,7 +333,8 @@ struct irq_chip {
74634 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74635
74636 unsigned long flags;
74637-};
74638+} __do_const;
74639+typedef struct irq_chip __no_const irq_chip_no_const;
74640
74641 /*
74642 * irq_chip specific flags
74643diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74644index 3e203eb..3fe68d0 100644
74645--- a/include/linux/irqchip/arm-gic.h
74646+++ b/include/linux/irqchip/arm-gic.h
74647@@ -59,9 +59,11 @@
74648
74649 #ifndef __ASSEMBLY__
74650
74651+#include <linux/irq.h>
74652+
74653 struct device_node;
74654
74655-extern struct irq_chip gic_arch_extn;
74656+extern irq_chip_no_const gic_arch_extn;
74657
74658 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74659 u32 offset, struct device_node *);
74660diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74661index 6883e19..e854fcb 100644
74662--- a/include/linux/kallsyms.h
74663+++ b/include/linux/kallsyms.h
74664@@ -15,7 +15,8 @@
74665
74666 struct module;
74667
74668-#ifdef CONFIG_KALLSYMS
74669+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74670+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74671 /* Lookup the address for a symbol. Returns 0 if not found. */
74672 unsigned long kallsyms_lookup_name(const char *name);
74673
74674@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74675 /* Stupid that this does nothing, but I didn't create this mess. */
74676 #define __print_symbol(fmt, addr)
74677 #endif /*CONFIG_KALLSYMS*/
74678+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74679+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74680+extern unsigned long kallsyms_lookup_name(const char *name);
74681+extern void __print_symbol(const char *fmt, unsigned long address);
74682+extern int sprint_backtrace(char *buffer, unsigned long address);
74683+extern int sprint_symbol(char *buffer, unsigned long address);
74684+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74685+const char *kallsyms_lookup(unsigned long addr,
74686+ unsigned long *symbolsize,
74687+ unsigned long *offset,
74688+ char **modname, char *namebuf);
74689+extern int kallsyms_lookup_size_offset(unsigned long addr,
74690+ unsigned long *symbolsize,
74691+ unsigned long *offset);
74692+#endif
74693
74694 /* This macro allows us to keep printk typechecking */
74695 static __printf(1, 2)
74696diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74697index 518a53a..5e28358 100644
74698--- a/include/linux/key-type.h
74699+++ b/include/linux/key-type.h
74700@@ -125,7 +125,7 @@ struct key_type {
74701 /* internal fields */
74702 struct list_head link; /* link in types list */
74703 struct lock_class_key lock_class; /* key->sem lock class */
74704-};
74705+} __do_const;
74706
74707 extern struct key_type key_type_keyring;
74708
74709diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74710index c6e091b..a940adf 100644
74711--- a/include/linux/kgdb.h
74712+++ b/include/linux/kgdb.h
74713@@ -52,7 +52,7 @@ extern int kgdb_connected;
74714 extern int kgdb_io_module_registered;
74715
74716 extern atomic_t kgdb_setting_breakpoint;
74717-extern atomic_t kgdb_cpu_doing_single_step;
74718+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74719
74720 extern struct task_struct *kgdb_usethread;
74721 extern struct task_struct *kgdb_contthread;
74722@@ -254,7 +254,7 @@ struct kgdb_arch {
74723 void (*correct_hw_break)(void);
74724
74725 void (*enable_nmi)(bool on);
74726-};
74727+} __do_const;
74728
74729 /**
74730 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74731@@ -279,7 +279,7 @@ struct kgdb_io {
74732 void (*pre_exception) (void);
74733 void (*post_exception) (void);
74734 int is_console;
74735-};
74736+} __do_const;
74737
74738 extern struct kgdb_arch arch_kgdb_ops;
74739
74740diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74741index 0555cc6..b16a7a4 100644
74742--- a/include/linux/kmod.h
74743+++ b/include/linux/kmod.h
74744@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74745 * usually useless though. */
74746 extern __printf(2, 3)
74747 int __request_module(bool wait, const char *name, ...);
74748+extern __printf(3, 4)
74749+int ___request_module(bool wait, char *param_name, const char *name, ...);
74750 #define request_module(mod...) __request_module(true, mod)
74751 #define request_module_nowait(mod...) __request_module(false, mod)
74752 #define try_then_request_module(x, mod...) \
74753diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74754index 939b112..ed6ed51 100644
74755--- a/include/linux/kobject.h
74756+++ b/include/linux/kobject.h
74757@@ -111,7 +111,7 @@ struct kobj_type {
74758 struct attribute **default_attrs;
74759 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74760 const void *(*namespace)(struct kobject *kobj);
74761-};
74762+} __do_const;
74763
74764 struct kobj_uevent_env {
74765 char *envp[UEVENT_NUM_ENVP];
74766@@ -134,6 +134,7 @@ struct kobj_attribute {
74767 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74768 const char *buf, size_t count);
74769 };
74770+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74771
74772 extern const struct sysfs_ops kobj_sysfs_ops;
74773
74774diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74775index f66b065..c2c29b4 100644
74776--- a/include/linux/kobject_ns.h
74777+++ b/include/linux/kobject_ns.h
74778@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74779 const void *(*netlink_ns)(struct sock *sk);
74780 const void *(*initial_ns)(void);
74781 void (*drop_ns)(void *);
74782-};
74783+} __do_const;
74784
74785 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74786 int kobj_ns_type_registered(enum kobj_ns_type type);
74787diff --git a/include/linux/kref.h b/include/linux/kref.h
74788index 484604d..0f6c5b6 100644
74789--- a/include/linux/kref.h
74790+++ b/include/linux/kref.h
74791@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74792 static inline int kref_sub(struct kref *kref, unsigned int count,
74793 void (*release)(struct kref *kref))
74794 {
74795- WARN_ON(release == NULL);
74796+ BUG_ON(release == NULL);
74797
74798 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74799 release(kref);
74800diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74801index a63d83e..77fd685 100644
74802--- a/include/linux/kvm_host.h
74803+++ b/include/linux/kvm_host.h
74804@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74805 {
74806 }
74807 #endif
74808-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74809+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74810 struct module *module);
74811 void kvm_exit(void);
74812
74813@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74814 struct kvm_guest_debug *dbg);
74815 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74816
74817-int kvm_arch_init(void *opaque);
74818+int kvm_arch_init(const void *opaque);
74819 void kvm_arch_exit(void);
74820
74821 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74822diff --git a/include/linux/libata.h b/include/linux/libata.h
74823index 4ea55bb..dcd2601 100644
74824--- a/include/linux/libata.h
74825+++ b/include/linux/libata.h
74826@@ -924,7 +924,7 @@ struct ata_port_operations {
74827 * fields must be pointers.
74828 */
74829 const struct ata_port_operations *inherits;
74830-};
74831+} __do_const;
74832
74833 struct ata_port_info {
74834 unsigned long flags;
74835diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74836index d3e8ad2..a949f68 100644
74837--- a/include/linux/linkage.h
74838+++ b/include/linux/linkage.h
74839@@ -31,6 +31,7 @@
74840 #endif
74841
74842 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74843+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74844 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74845
74846 /*
74847diff --git a/include/linux/list.h b/include/linux/list.h
74848index f4d8a2f..38e6e46 100644
74849--- a/include/linux/list.h
74850+++ b/include/linux/list.h
74851@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74852 extern void list_del(struct list_head *entry);
74853 #endif
74854
74855+extern void __pax_list_add(struct list_head *new,
74856+ struct list_head *prev,
74857+ struct list_head *next);
74858+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74859+{
74860+ __pax_list_add(new, head, head->next);
74861+}
74862+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74863+{
74864+ __pax_list_add(new, head->prev, head);
74865+}
74866+extern void pax_list_del(struct list_head *entry);
74867+
74868 /**
74869 * list_replace - replace old entry by new one
74870 * @old : the element to be replaced
74871@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74872 INIT_LIST_HEAD(entry);
74873 }
74874
74875+extern void pax_list_del_init(struct list_head *entry);
74876+
74877 /**
74878 * list_move - delete from one list and add as another's head
74879 * @list: the entry to move
74880diff --git a/include/linux/math64.h b/include/linux/math64.h
74881index 2913b86..8dcbb1e 100644
74882--- a/include/linux/math64.h
74883+++ b/include/linux/math64.h
74884@@ -15,7 +15,7 @@
74885 * This is commonly provided by 32bit archs to provide an optimized 64bit
74886 * divide.
74887 */
74888-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74889+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74890 {
74891 *remainder = dividend % divisor;
74892 return dividend / divisor;
74893@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74894 /**
74895 * div64_u64 - unsigned 64bit divide with 64bit divisor
74896 */
74897-static inline u64 div64_u64(u64 dividend, u64 divisor)
74898+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74899 {
74900 return dividend / divisor;
74901 }
74902@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74903 #define div64_ul(x, y) div_u64((x), (y))
74904
74905 #ifndef div_u64_rem
74906-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74907+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74908 {
74909 *remainder = do_div(dividend, divisor);
74910 return dividend;
74911@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74912 * divide.
74913 */
74914 #ifndef div_u64
74915-static inline u64 div_u64(u64 dividend, u32 divisor)
74916+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74917 {
74918 u32 remainder;
74919 return div_u64_rem(dividend, divisor, &remainder);
74920diff --git a/include/linux/mm.h b/include/linux/mm.h
74921index f022460..6ecf4f9 100644
74922--- a/include/linux/mm.h
74923+++ b/include/linux/mm.h
74924@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74925 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74926 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74927 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74928+
74929+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74930+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74931+#endif
74932+
74933 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74934
74935 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74936@@ -208,8 +213,8 @@ struct vm_operations_struct {
74937 /* called by access_process_vm when get_user_pages() fails, typically
74938 * for use by special VMAs that can switch between memory and hardware
74939 */
74940- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74941- void *buf, int len, int write);
74942+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74943+ void *buf, size_t len, int write);
74944 #ifdef CONFIG_NUMA
74945 /*
74946 * set_policy() op must add a reference to any non-NULL @new mempolicy
74947@@ -239,6 +244,7 @@ struct vm_operations_struct {
74948 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74949 unsigned long size, pgoff_t pgoff);
74950 };
74951+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74952
74953 struct mmu_gather;
74954 struct inode;
74955@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74956 unsigned long *pfn);
74957 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74958 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74959-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74960- void *buf, int len, int write);
74961+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74962+ void *buf, size_t len, int write);
74963
74964 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74965 loff_t const holebegin, loff_t const holelen)
74966@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74967 }
74968 #endif
74969
74970-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74971-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74972- void *buf, int len, int write);
74973+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74974+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74975+ void *buf, size_t len, int write);
74976
74977 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74978 unsigned long start, unsigned long nr_pages,
74979@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74980 int set_page_dirty_lock(struct page *page);
74981 int clear_page_dirty_for_io(struct page *page);
74982
74983-/* Is the vma a continuation of the stack vma above it? */
74984-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74985-{
74986- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74987-}
74988-
74989-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74990- unsigned long addr)
74991-{
74992- return (vma->vm_flags & VM_GROWSDOWN) &&
74993- (vma->vm_start == addr) &&
74994- !vma_growsdown(vma->vm_prev, addr);
74995-}
74996-
74997-/* Is the vma a continuation of the stack vma below it? */
74998-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74999-{
75000- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
75001-}
75002-
75003-static inline int stack_guard_page_end(struct vm_area_struct *vma,
75004- unsigned long addr)
75005-{
75006- return (vma->vm_flags & VM_GROWSUP) &&
75007- (vma->vm_end == addr) &&
75008- !vma_growsup(vma->vm_next, addr);
75009-}
75010-
75011 extern pid_t
75012 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
75013
75014@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75015 }
75016 #endif
75017
75018+#ifdef CONFIG_MMU
75019+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75020+#else
75021+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75022+{
75023+ return __pgprot(0);
75024+}
75025+#endif
75026+
75027 int vma_wants_writenotify(struct vm_area_struct *vma);
75028
75029 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75030@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75031 {
75032 return 0;
75033 }
75034+
75035+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75036+ unsigned long address)
75037+{
75038+ return 0;
75039+}
75040 #else
75041 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75042+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75043 #endif
75044
75045 #ifdef __PAGETABLE_PMD_FOLDED
75046@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75047 {
75048 return 0;
75049 }
75050+
75051+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75052+ unsigned long address)
75053+{
75054+ return 0;
75055+}
75056 #else
75057 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75058+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75059 #endif
75060
75061 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75062@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75063 NULL: pud_offset(pgd, address);
75064 }
75065
75066+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75067+{
75068+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75069+ NULL: pud_offset(pgd, address);
75070+}
75071+
75072 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75073 {
75074 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75075 NULL: pmd_offset(pud, address);
75076 }
75077+
75078+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75079+{
75080+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75081+ NULL: pmd_offset(pud, address);
75082+}
75083 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75084
75085 #if USE_SPLIT_PTLOCKS
75086@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75087 unsigned long len, unsigned long prot, unsigned long flags,
75088 unsigned long pgoff, unsigned long *populate);
75089 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75090+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75091
75092 #ifdef CONFIG_MMU
75093 extern int __mm_populate(unsigned long addr, unsigned long len,
75094@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75095 unsigned long high_limit;
75096 unsigned long align_mask;
75097 unsigned long align_offset;
75098+ unsigned long threadstack_offset;
75099 };
75100
75101-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75102-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75103+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75104+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75105
75106 /*
75107 * Search for an unmapped address range.
75108@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75109 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75110 */
75111 static inline unsigned long
75112-vm_unmapped_area(struct vm_unmapped_area_info *info)
75113+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75114 {
75115 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75116 return unmapped_area(info);
75117@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75118 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75119 struct vm_area_struct **pprev);
75120
75121+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75122+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75123+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75124+
75125 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75126 NULL if none. Assume start_addr < end_addr. */
75127 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75128@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75129 return vma;
75130 }
75131
75132-#ifdef CONFIG_MMU
75133-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75134-#else
75135-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75136-{
75137- return __pgprot(0);
75138-}
75139-#endif
75140-
75141 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75142 unsigned long change_prot_numa(struct vm_area_struct *vma,
75143 unsigned long start, unsigned long end);
75144@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75145 static inline void vm_stat_account(struct mm_struct *mm,
75146 unsigned long flags, struct file *file, long pages)
75147 {
75148+
75149+#ifdef CONFIG_PAX_RANDMMAP
75150+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75151+#endif
75152+
75153 mm->total_vm += pages;
75154 }
75155 #endif /* CONFIG_PROC_FS */
75156@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75157 extern int sysctl_memory_failure_early_kill;
75158 extern int sysctl_memory_failure_recovery;
75159 extern void shake_page(struct page *p, int access);
75160-extern atomic_long_t num_poisoned_pages;
75161+extern atomic_long_unchecked_t num_poisoned_pages;
75162 extern int soft_offline_page(struct page *page, int flags);
75163
75164 extern void dump_page(struct page *page);
75165@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75166 static inline void setup_nr_node_ids(void) {}
75167 #endif
75168
75169+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75170+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75171+#else
75172+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75173+#endif
75174+
75175 #endif /* __KERNEL__ */
75176 #endif /* _LINUX_MM_H */
75177diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75178index faf4b7c..1e70c6e 100644
75179--- a/include/linux/mm_types.h
75180+++ b/include/linux/mm_types.h
75181@@ -289,6 +289,8 @@ struct vm_area_struct {
75182 #ifdef CONFIG_NUMA
75183 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75184 #endif
75185+
75186+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75187 };
75188
75189 struct core_thread {
75190@@ -435,6 +437,24 @@ struct mm_struct {
75191 int first_nid;
75192 #endif
75193 struct uprobes_state uprobes_state;
75194+
75195+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75196+ unsigned long pax_flags;
75197+#endif
75198+
75199+#ifdef CONFIG_PAX_DLRESOLVE
75200+ unsigned long call_dl_resolve;
75201+#endif
75202+
75203+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75204+ unsigned long call_syscall;
75205+#endif
75206+
75207+#ifdef CONFIG_PAX_ASLR
75208+ unsigned long delta_mmap; /* randomized offset */
75209+ unsigned long delta_stack; /* randomized offset */
75210+#endif
75211+
75212 };
75213
75214 /* first nid will either be a valid NID or one of these values */
75215diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75216index c5d5278..f0b68c8 100644
75217--- a/include/linux/mmiotrace.h
75218+++ b/include/linux/mmiotrace.h
75219@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75220 /* Called from ioremap.c */
75221 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75222 void __iomem *addr);
75223-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75224+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75225
75226 /* For anyone to insert markers. Remember trailing newline. */
75227 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75228@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75229 {
75230 }
75231
75232-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75233+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75234 {
75235 }
75236
75237diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75238index af4a3b7..9ad8889 100644
75239--- a/include/linux/mmzone.h
75240+++ b/include/linux/mmzone.h
75241@@ -396,7 +396,7 @@ struct zone {
75242 unsigned long flags; /* zone flags, see below */
75243
75244 /* Zone statistics */
75245- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75246+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75247
75248 /*
75249 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75250diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75251index 45e9214..a7227d6 100644
75252--- a/include/linux/mod_devicetable.h
75253+++ b/include/linux/mod_devicetable.h
75254@@ -13,7 +13,7 @@
75255 typedef unsigned long kernel_ulong_t;
75256 #endif
75257
75258-#define PCI_ANY_ID (~0)
75259+#define PCI_ANY_ID ((__u16)~0)
75260
75261 struct pci_device_id {
75262 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75263@@ -139,7 +139,7 @@ struct usb_device_id {
75264 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75265 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75266
75267-#define HID_ANY_ID (~0)
75268+#define HID_ANY_ID (~0U)
75269 #define HID_BUS_ANY 0xffff
75270 #define HID_GROUP_ANY 0x0000
75271
75272@@ -467,7 +467,7 @@ struct dmi_system_id {
75273 const char *ident;
75274 struct dmi_strmatch matches[4];
75275 void *driver_data;
75276-};
75277+} __do_const;
75278 /*
75279 * struct dmi_device_id appears during expansion of
75280 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75281diff --git a/include/linux/module.h b/include/linux/module.h
75282index 46f1ea0..a34ca37 100644
75283--- a/include/linux/module.h
75284+++ b/include/linux/module.h
75285@@ -17,9 +17,11 @@
75286 #include <linux/moduleparam.h>
75287 #include <linux/tracepoint.h>
75288 #include <linux/export.h>
75289+#include <linux/fs.h>
75290
75291 #include <linux/percpu.h>
75292 #include <asm/module.h>
75293+#include <asm/pgtable.h>
75294
75295 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75296 #define MODULE_SIG_STRING "~Module signature appended~\n"
75297@@ -54,12 +56,13 @@ struct module_attribute {
75298 int (*test)(struct module *);
75299 void (*free)(struct module *);
75300 };
75301+typedef struct module_attribute __no_const module_attribute_no_const;
75302
75303 struct module_version_attribute {
75304 struct module_attribute mattr;
75305 const char *module_name;
75306 const char *version;
75307-} __attribute__ ((__aligned__(sizeof(void *))));
75308+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75309
75310 extern ssize_t __modver_version_show(struct module_attribute *,
75311 struct module_kobject *, char *);
75312@@ -232,7 +235,7 @@ struct module
75313
75314 /* Sysfs stuff. */
75315 struct module_kobject mkobj;
75316- struct module_attribute *modinfo_attrs;
75317+ module_attribute_no_const *modinfo_attrs;
75318 const char *version;
75319 const char *srcversion;
75320 struct kobject *holders_dir;
75321@@ -281,19 +284,16 @@ struct module
75322 int (*init)(void);
75323
75324 /* If this is non-NULL, vfree after init() returns */
75325- void *module_init;
75326+ void *module_init_rx, *module_init_rw;
75327
75328 /* Here is the actual code + data, vfree'd on unload. */
75329- void *module_core;
75330+ void *module_core_rx, *module_core_rw;
75331
75332 /* Here are the sizes of the init and core sections */
75333- unsigned int init_size, core_size;
75334+ unsigned int init_size_rw, core_size_rw;
75335
75336 /* The size of the executable code in each section. */
75337- unsigned int init_text_size, core_text_size;
75338-
75339- /* Size of RO sections of the module (text+rodata) */
75340- unsigned int init_ro_size, core_ro_size;
75341+ unsigned int init_size_rx, core_size_rx;
75342
75343 /* Arch-specific module values */
75344 struct mod_arch_specific arch;
75345@@ -349,6 +349,10 @@ struct module
75346 #ifdef CONFIG_EVENT_TRACING
75347 struct ftrace_event_call **trace_events;
75348 unsigned int num_trace_events;
75349+ struct file_operations trace_id;
75350+ struct file_operations trace_enable;
75351+ struct file_operations trace_format;
75352+ struct file_operations trace_filter;
75353 #endif
75354 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75355 unsigned int num_ftrace_callsites;
75356@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75357 bool is_module_percpu_address(unsigned long addr);
75358 bool is_module_text_address(unsigned long addr);
75359
75360+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75361+{
75362+
75363+#ifdef CONFIG_PAX_KERNEXEC
75364+ if (ktla_ktva(addr) >= (unsigned long)start &&
75365+ ktla_ktva(addr) < (unsigned long)start + size)
75366+ return 1;
75367+#endif
75368+
75369+ return ((void *)addr >= start && (void *)addr < start + size);
75370+}
75371+
75372+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75373+{
75374+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75375+}
75376+
75377+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75378+{
75379+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75380+}
75381+
75382+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75383+{
75384+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75385+}
75386+
75387+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75388+{
75389+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75390+}
75391+
75392 static inline int within_module_core(unsigned long addr, const struct module *mod)
75393 {
75394- return (unsigned long)mod->module_core <= addr &&
75395- addr < (unsigned long)mod->module_core + mod->core_size;
75396+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75397 }
75398
75399 static inline int within_module_init(unsigned long addr, const struct module *mod)
75400 {
75401- return (unsigned long)mod->module_init <= addr &&
75402- addr < (unsigned long)mod->module_init + mod->init_size;
75403+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75404 }
75405
75406 /* Search for module by name: must hold module_mutex. */
75407diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75408index 560ca53..ef621ef 100644
75409--- a/include/linux/moduleloader.h
75410+++ b/include/linux/moduleloader.h
75411@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75412 sections. Returns NULL on failure. */
75413 void *module_alloc(unsigned long size);
75414
75415+#ifdef CONFIG_PAX_KERNEXEC
75416+void *module_alloc_exec(unsigned long size);
75417+#else
75418+#define module_alloc_exec(x) module_alloc(x)
75419+#endif
75420+
75421 /* Free memory returned from module_alloc. */
75422 void module_free(struct module *mod, void *module_region);
75423
75424+#ifdef CONFIG_PAX_KERNEXEC
75425+void module_free_exec(struct module *mod, void *module_region);
75426+#else
75427+#define module_free_exec(x, y) module_free((x), (y))
75428+#endif
75429+
75430 /*
75431 * Apply the given relocation to the (simplified) ELF. Return -error
75432 * or 0.
75433@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75434 unsigned int relsec,
75435 struct module *me)
75436 {
75437+#ifdef CONFIG_MODULES
75438 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75439+#endif
75440 return -ENOEXEC;
75441 }
75442 #endif
75443@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75444 unsigned int relsec,
75445 struct module *me)
75446 {
75447+#ifdef CONFIG_MODULES
75448 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75449+#endif
75450 return -ENOEXEC;
75451 }
75452 #endif
75453diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75454index 27d9da3..5d94aa3 100644
75455--- a/include/linux/moduleparam.h
75456+++ b/include/linux/moduleparam.h
75457@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75458 * @len is usually just sizeof(string).
75459 */
75460 #define module_param_string(name, string, len, perm) \
75461- static const struct kparam_string __param_string_##name \
75462+ static const struct kparam_string __param_string_##name __used \
75463 = { len, string }; \
75464 __module_param_call(MODULE_PARAM_PREFIX, name, \
75465 &param_ops_string, \
75466@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75467 */
75468 #define module_param_array_named(name, array, type, nump, perm) \
75469 param_check_##type(name, &(array)[0]); \
75470- static const struct kparam_array __param_arr_##name \
75471+ static const struct kparam_array __param_arr_##name __used \
75472 = { .max = ARRAY_SIZE(array), .num = nump, \
75473 .ops = &param_ops_##type, \
75474 .elemsize = sizeof(array[0]), .elem = array }; \
75475diff --git a/include/linux/namei.h b/include/linux/namei.h
75476index 5a5ff57..5ae5070 100644
75477--- a/include/linux/namei.h
75478+++ b/include/linux/namei.h
75479@@ -19,7 +19,7 @@ struct nameidata {
75480 unsigned seq;
75481 int last_type;
75482 unsigned depth;
75483- char *saved_names[MAX_NESTED_LINKS + 1];
75484+ const char *saved_names[MAX_NESTED_LINKS + 1];
75485 };
75486
75487 /*
75488@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75489
75490 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75491
75492-static inline void nd_set_link(struct nameidata *nd, char *path)
75493+static inline void nd_set_link(struct nameidata *nd, const char *path)
75494 {
75495 nd->saved_names[nd->depth] = path;
75496 }
75497
75498-static inline char *nd_get_link(struct nameidata *nd)
75499+static inline const char *nd_get_link(const struct nameidata *nd)
75500 {
75501 return nd->saved_names[nd->depth];
75502 }
75503diff --git a/include/linux/net.h b/include/linux/net.h
75504index 4f27575..fc8a65f 100644
75505--- a/include/linux/net.h
75506+++ b/include/linux/net.h
75507@@ -183,7 +183,7 @@ struct net_proto_family {
75508 int (*create)(struct net *net, struct socket *sock,
75509 int protocol, int kern);
75510 struct module *owner;
75511-};
75512+} __do_const;
75513
75514 struct iovec;
75515 struct kvec;
75516diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75517index 9a41568..203d903 100644
75518--- a/include/linux/netdevice.h
75519+++ b/include/linux/netdevice.h
75520@@ -1061,6 +1061,7 @@ struct net_device_ops {
75521 int (*ndo_change_carrier)(struct net_device *dev,
75522 bool new_carrier);
75523 };
75524+typedef struct net_device_ops __no_const net_device_ops_no_const;
75525
75526 /*
75527 * The DEVICE structure.
75528@@ -1131,7 +1132,7 @@ struct net_device {
75529 int iflink;
75530
75531 struct net_device_stats stats;
75532- atomic_long_t rx_dropped; /* dropped packets by core network
75533+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75534 * Do not use this in drivers.
75535 */
75536
75537diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75538index de70f7b..2675e91 100644
75539--- a/include/linux/netfilter.h
75540+++ b/include/linux/netfilter.h
75541@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75542 #endif
75543 /* Use the module struct to lock set/get code in place */
75544 struct module *owner;
75545-};
75546+} __do_const;
75547
75548 /* Function to register/unregister hook points. */
75549 int nf_register_hook(struct nf_hook_ops *reg);
75550diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75551index d80e275..c3510b8 100644
75552--- a/include/linux/netfilter/ipset/ip_set.h
75553+++ b/include/linux/netfilter/ipset/ip_set.h
75554@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75555 /* Return true if "b" set is the same as "a"
75556 * according to the create set parameters */
75557 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75558-};
75559+} __do_const;
75560
75561 /* The core set type structure */
75562 struct ip_set_type {
75563diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75564index cadb740..d7c37c0 100644
75565--- a/include/linux/netfilter/nfnetlink.h
75566+++ b/include/linux/netfilter/nfnetlink.h
75567@@ -16,7 +16,7 @@ struct nfnl_callback {
75568 const struct nlattr * const cda[]);
75569 const struct nla_policy *policy; /* netlink attribute policy */
75570 const u_int16_t attr_count; /* number of nlattr's */
75571-};
75572+} __do_const;
75573
75574 struct nfnetlink_subsystem {
75575 const char *name;
75576diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75577new file mode 100644
75578index 0000000..33f4af8
75579--- /dev/null
75580+++ b/include/linux/netfilter/xt_gradm.h
75581@@ -0,0 +1,9 @@
75582+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75583+#define _LINUX_NETFILTER_XT_GRADM_H 1
75584+
75585+struct xt_gradm_mtinfo {
75586+ __u16 flags;
75587+ __u16 invflags;
75588+};
75589+
75590+#endif
75591diff --git a/include/linux/nls.h b/include/linux/nls.h
75592index 5dc635f..35f5e11 100644
75593--- a/include/linux/nls.h
75594+++ b/include/linux/nls.h
75595@@ -31,7 +31,7 @@ struct nls_table {
75596 const unsigned char *charset2upper;
75597 struct module *owner;
75598 struct nls_table *next;
75599-};
75600+} __do_const;
75601
75602 /* this value hold the maximum octet of charset */
75603 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75604diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75605index d14a4c3..a078786 100644
75606--- a/include/linux/notifier.h
75607+++ b/include/linux/notifier.h
75608@@ -54,7 +54,8 @@ struct notifier_block {
75609 notifier_fn_t notifier_call;
75610 struct notifier_block __rcu *next;
75611 int priority;
75612-};
75613+} __do_const;
75614+typedef struct notifier_block __no_const notifier_block_no_const;
75615
75616 struct atomic_notifier_head {
75617 spinlock_t lock;
75618diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75619index a4c5624..79d6d88 100644
75620--- a/include/linux/oprofile.h
75621+++ b/include/linux/oprofile.h
75622@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75623 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75624 char const * name, ulong * val);
75625
75626-/** Create a file for read-only access to an atomic_t. */
75627+/** Create a file for read-only access to an atomic_unchecked_t. */
75628 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75629- char const * name, atomic_t * val);
75630+ char const * name, atomic_unchecked_t * val);
75631
75632 /** create a directory */
75633 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75634diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75635index 8db71dc..a76bf2c 100644
75636--- a/include/linux/pci_hotplug.h
75637+++ b/include/linux/pci_hotplug.h
75638@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75639 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75640 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75641 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75642-};
75643+} __do_const;
75644+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75645
75646 /**
75647 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75648diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75649index c43f6ea..2d4416f 100644
75650--- a/include/linux/perf_event.h
75651+++ b/include/linux/perf_event.h
75652@@ -328,8 +328,8 @@ struct perf_event {
75653
75654 enum perf_event_active_state state;
75655 unsigned int attach_state;
75656- local64_t count;
75657- atomic64_t child_count;
75658+ local64_t count; /* PaX: fix it one day */
75659+ atomic64_unchecked_t child_count;
75660
75661 /*
75662 * These are the total time in nanoseconds that the event
75663@@ -380,8 +380,8 @@ struct perf_event {
75664 * These accumulate total time (in nanoseconds) that children
75665 * events have been enabled and running, respectively.
75666 */
75667- atomic64_t child_total_time_enabled;
75668- atomic64_t child_total_time_running;
75669+ atomic64_unchecked_t child_total_time_enabled;
75670+ atomic64_unchecked_t child_total_time_running;
75671
75672 /*
75673 * Protect attach/detach and child_list:
75674@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75675 entry->ip[entry->nr++] = ip;
75676 }
75677
75678-extern int sysctl_perf_event_paranoid;
75679+extern int sysctl_perf_event_legitimately_concerned;
75680 extern int sysctl_perf_event_mlock;
75681 extern int sysctl_perf_event_sample_rate;
75682 extern int sysctl_perf_cpu_time_max_percent;
75683@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75684 loff_t *ppos);
75685
75686
75687+static inline bool perf_paranoid_any(void)
75688+{
75689+ return sysctl_perf_event_legitimately_concerned > 2;
75690+}
75691+
75692 static inline bool perf_paranoid_tracepoint_raw(void)
75693 {
75694- return sysctl_perf_event_paranoid > -1;
75695+ return sysctl_perf_event_legitimately_concerned > -1;
75696 }
75697
75698 static inline bool perf_paranoid_cpu(void)
75699 {
75700- return sysctl_perf_event_paranoid > 0;
75701+ return sysctl_perf_event_legitimately_concerned > 0;
75702 }
75703
75704 static inline bool perf_paranoid_kernel(void)
75705 {
75706- return sysctl_perf_event_paranoid > 1;
75707+ return sysctl_perf_event_legitimately_concerned > 1;
75708 }
75709
75710 extern void perf_event_init(void);
75711@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75712 struct device_attribute attr;
75713 u64 id;
75714 const char *event_str;
75715-};
75716+} __do_const;
75717
75718 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75719 static struct perf_pmu_events_attr _var = { \
75720diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75721index b8809fe..ae4ccd0 100644
75722--- a/include/linux/pipe_fs_i.h
75723+++ b/include/linux/pipe_fs_i.h
75724@@ -47,10 +47,10 @@ struct pipe_inode_info {
75725 struct mutex mutex;
75726 wait_queue_head_t wait;
75727 unsigned int nrbufs, curbuf, buffers;
75728- unsigned int readers;
75729- unsigned int writers;
75730- unsigned int files;
75731- unsigned int waiting_writers;
75732+ atomic_t readers;
75733+ atomic_t writers;
75734+ atomic_t files;
75735+ atomic_t waiting_writers;
75736 unsigned int r_counter;
75737 unsigned int w_counter;
75738 struct page *tmp_page;
75739diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75740index 5f28cae..3d23723 100644
75741--- a/include/linux/platform_data/usb-ehci-s5p.h
75742+++ b/include/linux/platform_data/usb-ehci-s5p.h
75743@@ -14,7 +14,7 @@
75744 struct s5p_ehci_platdata {
75745 int (*phy_init)(struct platform_device *pdev, int type);
75746 int (*phy_exit)(struct platform_device *pdev, int type);
75747-};
75748+} __no_const;
75749
75750 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75751
75752diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75753index c256c59..8ea94c7 100644
75754--- a/include/linux/platform_data/usb-ohci-exynos.h
75755+++ b/include/linux/platform_data/usb-ohci-exynos.h
75756@@ -14,7 +14,7 @@
75757 struct exynos4_ohci_platdata {
75758 int (*phy_init)(struct platform_device *pdev, int type);
75759 int (*phy_exit)(struct platform_device *pdev, int type);
75760-};
75761+} __no_const;
75762
75763 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75764
75765diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75766index 7c1d252..c5c773e 100644
75767--- a/include/linux/pm_domain.h
75768+++ b/include/linux/pm_domain.h
75769@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75770
75771 struct gpd_cpu_data {
75772 unsigned int saved_exit_latency;
75773- struct cpuidle_state *idle_state;
75774+ cpuidle_state_no_const *idle_state;
75775 };
75776
75777 struct generic_pm_domain {
75778diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75779index 6fa7cea..7bf6415 100644
75780--- a/include/linux/pm_runtime.h
75781+++ b/include/linux/pm_runtime.h
75782@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75783
75784 static inline void pm_runtime_mark_last_busy(struct device *dev)
75785 {
75786- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75787+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75788 }
75789
75790 #else /* !CONFIG_PM_RUNTIME */
75791diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75792index 195aafc..49a7bc2 100644
75793--- a/include/linux/pnp.h
75794+++ b/include/linux/pnp.h
75795@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75796 struct pnp_fixup {
75797 char id[7];
75798 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75799-};
75800+} __do_const;
75801
75802 /* config parameters */
75803 #define PNP_CONFIG_NORMAL 0x0001
75804diff --git a/include/linux/poison.h b/include/linux/poison.h
75805index 2110a81..13a11bb 100644
75806--- a/include/linux/poison.h
75807+++ b/include/linux/poison.h
75808@@ -19,8 +19,8 @@
75809 * under normal circumstances, used to verify that nobody uses
75810 * non-initialized list entries.
75811 */
75812-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75813-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75814+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75815+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75816
75817 /********** include/linux/timer.h **********/
75818 /*
75819diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75820index d8b187c3..9a9257a 100644
75821--- a/include/linux/power/smartreflex.h
75822+++ b/include/linux/power/smartreflex.h
75823@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75824 int (*notify)(struct omap_sr *sr, u32 status);
75825 u8 notify_flags;
75826 u8 class_type;
75827-};
75828+} __do_const;
75829
75830 /**
75831 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75832diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75833index 4ea1d37..80f4b33 100644
75834--- a/include/linux/ppp-comp.h
75835+++ b/include/linux/ppp-comp.h
75836@@ -84,7 +84,7 @@ struct compressor {
75837 struct module *owner;
75838 /* Extra skb space needed by the compressor algorithm */
75839 unsigned int comp_extra;
75840-};
75841+} __do_const;
75842
75843 /*
75844 * The return value from decompress routine is the length of the
75845diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75846index f5d4723..a6ea2fa 100644
75847--- a/include/linux/preempt.h
75848+++ b/include/linux/preempt.h
75849@@ -18,8 +18,13 @@
75850 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75851 #endif
75852
75853+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75854+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75855+
75856 #define inc_preempt_count() add_preempt_count(1)
75857+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75858 #define dec_preempt_count() sub_preempt_count(1)
75859+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75860
75861 #define preempt_count() (current_thread_info()->preempt_count)
75862
75863@@ -64,6 +69,12 @@ do { \
75864 barrier(); \
75865 } while (0)
75866
75867+#define raw_preempt_disable() \
75868+do { \
75869+ raw_inc_preempt_count(); \
75870+ barrier(); \
75871+} while (0)
75872+
75873 #define sched_preempt_enable_no_resched() \
75874 do { \
75875 barrier(); \
75876@@ -72,6 +83,12 @@ do { \
75877
75878 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75879
75880+#define raw_preempt_enable_no_resched() \
75881+do { \
75882+ barrier(); \
75883+ raw_dec_preempt_count(); \
75884+} while (0)
75885+
75886 #define preempt_enable() \
75887 do { \
75888 preempt_enable_no_resched(); \
75889@@ -116,8 +133,10 @@ do { \
75890 * region.
75891 */
75892 #define preempt_disable() barrier()
75893+#define raw_preempt_disable() barrier()
75894 #define sched_preempt_enable_no_resched() barrier()
75895 #define preempt_enable_no_resched() barrier()
75896+#define raw_preempt_enable_no_resched() barrier()
75897 #define preempt_enable() barrier()
75898
75899 #define preempt_disable_notrace() barrier()
75900diff --git a/include/linux/printk.h b/include/linux/printk.h
75901index 22c7052..ad3fa0a 100644
75902--- a/include/linux/printk.h
75903+++ b/include/linux/printk.h
75904@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75905 void early_printk(const char *s, ...) { }
75906 #endif
75907
75908+extern int kptr_restrict;
75909+
75910 #ifdef CONFIG_PRINTK
75911 asmlinkage __printf(5, 0)
75912 int vprintk_emit(int facility, int level,
75913@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75914
75915 extern int printk_delay_msec;
75916 extern int dmesg_restrict;
75917-extern int kptr_restrict;
75918
75919 extern void wake_up_klogd(void);
75920
75921diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75922index 608e60a..c26f864 100644
75923--- a/include/linux/proc_fs.h
75924+++ b/include/linux/proc_fs.h
75925@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75926 return proc_create_data(name, mode, parent, proc_fops, NULL);
75927 }
75928
75929+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75930+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75931+{
75932+#ifdef CONFIG_GRKERNSEC_PROC_USER
75933+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75934+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75935+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75936+#else
75937+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75938+#endif
75939+}
75940+
75941+
75942 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75943 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75944 extern void *PDE_DATA(const struct inode *);
75945diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75946index 34a1e10..03a6d03 100644
75947--- a/include/linux/proc_ns.h
75948+++ b/include/linux/proc_ns.h
75949@@ -14,7 +14,7 @@ struct proc_ns_operations {
75950 void (*put)(void *ns);
75951 int (*install)(struct nsproxy *nsproxy, void *ns);
75952 unsigned int (*inum)(void *ns);
75953-};
75954+} __do_const;
75955
75956 struct proc_ns {
75957 void *ns;
75958diff --git a/include/linux/random.h b/include/linux/random.h
75959index 6312dd9..2561947 100644
75960--- a/include/linux/random.h
75961+++ b/include/linux/random.h
75962@@ -10,9 +10,19 @@
75963
75964
75965 extern void add_device_randomness(const void *, unsigned int);
75966+
75967+static inline void add_latent_entropy(void)
75968+{
75969+
75970+#ifdef LATENT_ENTROPY_PLUGIN
75971+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75972+#endif
75973+
75974+}
75975+
75976 extern void add_input_randomness(unsigned int type, unsigned int code,
75977- unsigned int value);
75978-extern void add_interrupt_randomness(int irq, int irq_flags);
75979+ unsigned int value) __latent_entropy;
75980+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75981
75982 extern void get_random_bytes(void *buf, int nbytes);
75983 extern void get_random_bytes_arch(void *buf, int nbytes);
75984@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
75985 u32 prandom_u32_state(struct rnd_state *);
75986 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75987
75988+static inline unsigned long pax_get_random_long(void)
75989+{
75990+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75991+}
75992+
75993 /*
75994 * Handle minimum values for seeds
75995 */
75996diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75997index 4106721..132d42c 100644
75998--- a/include/linux/rculist.h
75999+++ b/include/linux/rculist.h
76000@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
76001 struct list_head *prev, struct list_head *next);
76002 #endif
76003
76004+extern void __pax_list_add_rcu(struct list_head *new,
76005+ struct list_head *prev, struct list_head *next);
76006+
76007 /**
76008 * list_add_rcu - add a new entry to rcu-protected list
76009 * @new: new entry to be added
76010@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
76011 __list_add_rcu(new, head, head->next);
76012 }
76013
76014+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76015+{
76016+ __pax_list_add_rcu(new, head, head->next);
76017+}
76018+
76019 /**
76020 * list_add_tail_rcu - add a new entry to rcu-protected list
76021 * @new: new entry to be added
76022@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76023 __list_add_rcu(new, head->prev, head);
76024 }
76025
76026+static inline void pax_list_add_tail_rcu(struct list_head *new,
76027+ struct list_head *head)
76028+{
76029+ __pax_list_add_rcu(new, head->prev, head);
76030+}
76031+
76032 /**
76033 * list_del_rcu - deletes entry from list without re-initialization
76034 * @entry: the element to delete from the list.
76035@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76036 entry->prev = LIST_POISON2;
76037 }
76038
76039+extern void pax_list_del_rcu(struct list_head *entry);
76040+
76041 /**
76042 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76043 * @n: the element to delete from the hash list.
76044diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76045index 8e00f9f..9449b55 100644
76046--- a/include/linux/reboot.h
76047+++ b/include/linux/reboot.h
76048@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76049 * Architecture-specific implementations of sys_reboot commands.
76050 */
76051
76052-extern void machine_restart(char *cmd);
76053-extern void machine_halt(void);
76054-extern void machine_power_off(void);
76055+extern void machine_restart(char *cmd) __noreturn;
76056+extern void machine_halt(void) __noreturn;
76057+extern void machine_power_off(void) __noreturn;
76058
76059 extern void machine_shutdown(void);
76060 struct pt_regs;
76061@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76062 */
76063
76064 extern void kernel_restart_prepare(char *cmd);
76065-extern void kernel_restart(char *cmd);
76066-extern void kernel_halt(void);
76067-extern void kernel_power_off(void);
76068+extern void kernel_restart(char *cmd) __noreturn;
76069+extern void kernel_halt(void) __noreturn;
76070+extern void kernel_power_off(void) __noreturn;
76071
76072 extern int C_A_D; /* for sysctl */
76073 void ctrl_alt_del(void);
76074@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76075 * Emergency restart, callable from an interrupt handler.
76076 */
76077
76078-extern void emergency_restart(void);
76079+extern void emergency_restart(void) __noreturn;
76080 #include <asm/emergency-restart.h>
76081
76082 #endif /* _LINUX_REBOOT_H */
76083diff --git a/include/linux/regset.h b/include/linux/regset.h
76084index 8e0c9fe..ac4d221 100644
76085--- a/include/linux/regset.h
76086+++ b/include/linux/regset.h
76087@@ -161,7 +161,8 @@ struct user_regset {
76088 unsigned int align;
76089 unsigned int bias;
76090 unsigned int core_note_type;
76091-};
76092+} __do_const;
76093+typedef struct user_regset __no_const user_regset_no_const;
76094
76095 /**
76096 * struct user_regset_view - available regsets
76097diff --git a/include/linux/relay.h b/include/linux/relay.h
76098index d7c8359..818daf5 100644
76099--- a/include/linux/relay.h
76100+++ b/include/linux/relay.h
76101@@ -157,7 +157,7 @@ struct rchan_callbacks
76102 * The callback should return 0 if successful, negative if not.
76103 */
76104 int (*remove_buf_file)(struct dentry *dentry);
76105-};
76106+} __no_const;
76107
76108 /*
76109 * CONFIG_RELAY kernel API, kernel/relay.c
76110diff --git a/include/linux/rio.h b/include/linux/rio.h
76111index b71d573..2f940bd 100644
76112--- a/include/linux/rio.h
76113+++ b/include/linux/rio.h
76114@@ -355,7 +355,7 @@ struct rio_ops {
76115 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76116 u64 rstart, u32 size, u32 flags);
76117 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76118-};
76119+} __no_const;
76120
76121 #define RIO_RESOURCE_MEM 0x00000100
76122 #define RIO_RESOURCE_DOORBELL 0x00000200
76123diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76124index 6dacb93..6174423 100644
76125--- a/include/linux/rmap.h
76126+++ b/include/linux/rmap.h
76127@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76128 void anon_vma_init(void); /* create anon_vma_cachep */
76129 int anon_vma_prepare(struct vm_area_struct *);
76130 void unlink_anon_vmas(struct vm_area_struct *);
76131-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76132-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76133+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76134+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76135
76136 static inline void anon_vma_merge(struct vm_area_struct *vma,
76137 struct vm_area_struct *next)
76138diff --git a/include/linux/sched.h b/include/linux/sched.h
76139index 078066d..4090b3b 100644
76140--- a/include/linux/sched.h
76141+++ b/include/linux/sched.h
76142@@ -62,6 +62,7 @@ struct bio_list;
76143 struct fs_struct;
76144 struct perf_event_context;
76145 struct blk_plug;
76146+struct linux_binprm;
76147
76148 /*
76149 * List of flags we want to share for kernel threads,
76150@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76151 extern int in_sched_functions(unsigned long addr);
76152
76153 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76154-extern signed long schedule_timeout(signed long timeout);
76155+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76156 extern signed long schedule_timeout_interruptible(signed long timeout);
76157 extern signed long schedule_timeout_killable(signed long timeout);
76158 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76159@@ -314,6 +315,19 @@ struct nsproxy;
76160 struct user_namespace;
76161
76162 #ifdef CONFIG_MMU
76163+
76164+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76165+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76166+#else
76167+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76168+{
76169+ return 0;
76170+}
76171+#endif
76172+
76173+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76174+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76175+
76176 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76177 extern unsigned long
76178 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76179@@ -589,6 +603,17 @@ struct signal_struct {
76180 #ifdef CONFIG_TASKSTATS
76181 struct taskstats *stats;
76182 #endif
76183+
76184+#ifdef CONFIG_GRKERNSEC
76185+ u32 curr_ip;
76186+ u32 saved_ip;
76187+ u32 gr_saddr;
76188+ u32 gr_daddr;
76189+ u16 gr_sport;
76190+ u16 gr_dport;
76191+ u8 used_accept:1;
76192+#endif
76193+
76194 #ifdef CONFIG_AUDIT
76195 unsigned audit_tty;
76196 unsigned audit_tty_log_passwd;
76197@@ -669,6 +694,14 @@ struct user_struct {
76198 struct key *session_keyring; /* UID's default session keyring */
76199 #endif
76200
76201+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76202+ unsigned char kernel_banned;
76203+#endif
76204+#ifdef CONFIG_GRKERNSEC_BRUTE
76205+ unsigned char suid_banned;
76206+ unsigned long suid_ban_expires;
76207+#endif
76208+
76209 /* Hash table maintenance information */
76210 struct hlist_node uidhash_node;
76211 kuid_t uid;
76212@@ -1151,8 +1184,8 @@ struct task_struct {
76213 struct list_head thread_group;
76214
76215 struct completion *vfork_done; /* for vfork() */
76216- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76217- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76218+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76219+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76220
76221 cputime_t utime, stime, utimescaled, stimescaled;
76222 cputime_t gtime;
76223@@ -1177,11 +1210,6 @@ struct task_struct {
76224 struct task_cputime cputime_expires;
76225 struct list_head cpu_timers[3];
76226
76227-/* process credentials */
76228- const struct cred __rcu *real_cred; /* objective and real subjective task
76229- * credentials (COW) */
76230- const struct cred __rcu *cred; /* effective (overridable) subjective task
76231- * credentials (COW) */
76232 char comm[TASK_COMM_LEN]; /* executable name excluding path
76233 - access with [gs]et_task_comm (which lock
76234 it with task_lock())
76235@@ -1198,6 +1226,10 @@ struct task_struct {
76236 #endif
76237 /* CPU-specific state of this task */
76238 struct thread_struct thread;
76239+/* thread_info moved to task_struct */
76240+#ifdef CONFIG_X86
76241+ struct thread_info tinfo;
76242+#endif
76243 /* filesystem information */
76244 struct fs_struct *fs;
76245 /* open file information */
76246@@ -1271,6 +1303,10 @@ struct task_struct {
76247 gfp_t lockdep_reclaim_gfp;
76248 #endif
76249
76250+/* process credentials */
76251+ const struct cred __rcu *real_cred; /* objective and real subjective task
76252+ * credentials (COW) */
76253+
76254 /* journalling filesystem info */
76255 void *journal_info;
76256
76257@@ -1309,6 +1345,10 @@ struct task_struct {
76258 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76259 struct list_head cg_list;
76260 #endif
76261+
76262+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76263+ * credentials (COW) */
76264+
76265 #ifdef CONFIG_FUTEX
76266 struct robust_list_head __user *robust_list;
76267 #ifdef CONFIG_COMPAT
76268@@ -1406,8 +1446,76 @@ struct task_struct {
76269 unsigned int sequential_io;
76270 unsigned int sequential_io_avg;
76271 #endif
76272+
76273+#ifdef CONFIG_GRKERNSEC
76274+ /* grsecurity */
76275+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76276+ u64 exec_id;
76277+#endif
76278+#ifdef CONFIG_GRKERNSEC_SETXID
76279+ const struct cred *delayed_cred;
76280+#endif
76281+ struct dentry *gr_chroot_dentry;
76282+ struct acl_subject_label *acl;
76283+ struct acl_role_label *role;
76284+ struct file *exec_file;
76285+ unsigned long brute_expires;
76286+ u16 acl_role_id;
76287+ /* is this the task that authenticated to the special role */
76288+ u8 acl_sp_role;
76289+ u8 is_writable;
76290+ u8 brute;
76291+ u8 gr_is_chrooted;
76292+#endif
76293+
76294 };
76295
76296+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76297+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76298+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76299+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76300+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76301+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76302+
76303+#ifdef CONFIG_PAX_SOFTMODE
76304+extern int pax_softmode;
76305+#endif
76306+
76307+extern int pax_check_flags(unsigned long *);
76308+
76309+/* if tsk != current then task_lock must be held on it */
76310+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76311+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76312+{
76313+ if (likely(tsk->mm))
76314+ return tsk->mm->pax_flags;
76315+ else
76316+ return 0UL;
76317+}
76318+
76319+/* if tsk != current then task_lock must be held on it */
76320+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76321+{
76322+ if (likely(tsk->mm)) {
76323+ tsk->mm->pax_flags = flags;
76324+ return 0;
76325+ }
76326+ return -EINVAL;
76327+}
76328+#endif
76329+
76330+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76331+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76332+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76333+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76334+#endif
76335+
76336+struct path;
76337+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76338+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76339+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76340+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76341+
76342 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76343 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76344
76345@@ -1466,7 +1574,7 @@ struct pid_namespace;
76346 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76347 struct pid_namespace *ns);
76348
76349-static inline pid_t task_pid_nr(struct task_struct *tsk)
76350+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76351 {
76352 return tsk->pid;
76353 }
76354@@ -1916,7 +2024,9 @@ void yield(void);
76355 extern struct exec_domain default_exec_domain;
76356
76357 union thread_union {
76358+#ifndef CONFIG_X86
76359 struct thread_info thread_info;
76360+#endif
76361 unsigned long stack[THREAD_SIZE/sizeof(long)];
76362 };
76363
76364@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76365 */
76366
76367 extern struct task_struct *find_task_by_vpid(pid_t nr);
76368+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76369 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76370 struct pid_namespace *ns);
76371
76372@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76373 extern void exit_itimers(struct signal_struct *);
76374 extern void flush_itimer_signals(void);
76375
76376-extern void do_group_exit(int);
76377+extern __noreturn void do_group_exit(int);
76378
76379 extern int allow_signal(int);
76380 extern int disallow_signal(int);
76381@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76382
76383 #endif
76384
76385-static inline int object_is_on_stack(void *obj)
76386+static inline int object_starts_on_stack(void *obj)
76387 {
76388- void *stack = task_stack_page(current);
76389+ const void *stack = task_stack_page(current);
76390
76391 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76392 }
76393diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76394index bf8086b..962b035 100644
76395--- a/include/linux/sched/sysctl.h
76396+++ b/include/linux/sched/sysctl.h
76397@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76398 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76399
76400 extern int sysctl_max_map_count;
76401+extern unsigned long sysctl_heap_stack_gap;
76402
76403 extern unsigned int sysctl_sched_latency;
76404 extern unsigned int sysctl_sched_min_granularity;
76405diff --git a/include/linux/security.h b/include/linux/security.h
76406index 7ce53ae..8ee24a5 100644
76407--- a/include/linux/security.h
76408+++ b/include/linux/security.h
76409@@ -27,6 +27,7 @@
76410 #include <linux/slab.h>
76411 #include <linux/err.h>
76412 #include <linux/string.h>
76413+#include <linux/grsecurity.h>
76414
76415 struct linux_binprm;
76416 struct cred;
76417@@ -116,8 +117,6 @@ struct seq_file;
76418
76419 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76420
76421-void reset_security_ops(void);
76422-
76423 #ifdef CONFIG_MMU
76424 extern unsigned long mmap_min_addr;
76425 extern unsigned long dac_mmap_min_addr;
76426diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76427index 4e32edc..f8f2d18 100644
76428--- a/include/linux/seq_file.h
76429+++ b/include/linux/seq_file.h
76430@@ -26,6 +26,9 @@ struct seq_file {
76431 struct mutex lock;
76432 const struct seq_operations *op;
76433 int poll_event;
76434+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76435+ u64 exec_id;
76436+#endif
76437 #ifdef CONFIG_USER_NS
76438 struct user_namespace *user_ns;
76439 #endif
76440@@ -38,6 +41,7 @@ struct seq_operations {
76441 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76442 int (*show) (struct seq_file *m, void *v);
76443 };
76444+typedef struct seq_operations __no_const seq_operations_no_const;
76445
76446 #define SEQ_SKIP 1
76447
76448diff --git a/include/linux/shm.h b/include/linux/shm.h
76449index 429c199..4d42e38 100644
76450--- a/include/linux/shm.h
76451+++ b/include/linux/shm.h
76452@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76453
76454 /* The task created the shm object. NULL if the task is dead. */
76455 struct task_struct *shm_creator;
76456+#ifdef CONFIG_GRKERNSEC
76457+ time_t shm_createtime;
76458+ pid_t shm_lapid;
76459+#endif
76460 };
76461
76462 /* shm_mode upper byte flags */
76463diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76464index 3b71a4e..4823435 100644
76465--- a/include/linux/skbuff.h
76466+++ b/include/linux/skbuff.h
76467@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76468 extern struct sk_buff *__alloc_skb(unsigned int size,
76469 gfp_t priority, int flags, int node);
76470 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76471-static inline struct sk_buff *alloc_skb(unsigned int size,
76472+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76473 gfp_t priority)
76474 {
76475 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76476@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76477 */
76478 static inline int skb_queue_empty(const struct sk_buff_head *list)
76479 {
76480- return list->next == (struct sk_buff *)list;
76481+ return list->next == (const struct sk_buff *)list;
76482 }
76483
76484 /**
76485@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76486 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76487 const struct sk_buff *skb)
76488 {
76489- return skb->next == (struct sk_buff *)list;
76490+ return skb->next == (const struct sk_buff *)list;
76491 }
76492
76493 /**
76494@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76495 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76496 const struct sk_buff *skb)
76497 {
76498- return skb->prev == (struct sk_buff *)list;
76499+ return skb->prev == (const struct sk_buff *)list;
76500 }
76501
76502 /**
76503@@ -1316,6 +1316,11 @@ static inline int skb_pagelen(const struct sk_buff *skb)
76504 return len + skb_headlen(skb);
76505 }
76506
76507+static inline bool skb_has_frags(const struct sk_buff *skb)
76508+{
76509+ return skb_shinfo(skb)->nr_frags;
76510+}
76511+
76512 /**
76513 * __skb_fill_page_desc - initialise a paged fragment in an skb
76514 * @skb: buffer containing fragment to be initialised
76515@@ -1750,7 +1755,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76516 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76517 */
76518 #ifndef NET_SKB_PAD
76519-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76520+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76521 #endif
76522
76523 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76524@@ -2345,7 +2350,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76525 int noblock, int *err);
76526 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76527 struct poll_table_struct *wait);
76528-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76529+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76530 int offset, struct iovec *to,
76531 int size);
76532 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76533@@ -2636,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
76534 nf_bridge_put(skb->nf_bridge);
76535 skb->nf_bridge = NULL;
76536 #endif
76537+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76538+ skb->nf_trace = 0;
76539+#endif
76540 }
76541
76542 static inline void nf_reset_trace(struct sk_buff *skb)
76543diff --git a/include/linux/slab.h b/include/linux/slab.h
76544index 6c5cc0e..9ca0fd6 100644
76545--- a/include/linux/slab.h
76546+++ b/include/linux/slab.h
76547@@ -12,15 +12,29 @@
76548 #include <linux/gfp.h>
76549 #include <linux/types.h>
76550 #include <linux/workqueue.h>
76551-
76552+#include <linux/err.h>
76553
76554 /*
76555 * Flags to pass to kmem_cache_create().
76556 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76557 */
76558 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76559+
76560+#ifdef CONFIG_PAX_USERCOPY_SLABS
76561+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76562+#else
76563+#define SLAB_USERCOPY 0x00000000UL
76564+#endif
76565+
76566 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76567 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76568+
76569+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76570+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76571+#else
76572+#define SLAB_NO_SANITIZE 0x00000000UL
76573+#endif
76574+
76575 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76576 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76577 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76578@@ -89,10 +103,13 @@
76579 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76580 * Both make kfree a no-op.
76581 */
76582-#define ZERO_SIZE_PTR ((void *)16)
76583+#define ZERO_SIZE_PTR \
76584+({ \
76585+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76586+ (void *)(-MAX_ERRNO-1L); \
76587+})
76588
76589-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76590- (unsigned long)ZERO_SIZE_PTR)
76591+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76592
76593
76594 struct mem_cgroup;
76595@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76596 void kfree(const void *);
76597 void kzfree(const void *);
76598 size_t ksize(const void *);
76599+const char *check_heap_object(const void *ptr, unsigned long n);
76600+bool is_usercopy_object(const void *ptr);
76601
76602 /*
76603 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76604@@ -164,7 +183,7 @@ struct kmem_cache {
76605 unsigned int align; /* Alignment as calculated */
76606 unsigned long flags; /* Active flags on the slab */
76607 const char *name; /* Slab name for sysfs */
76608- int refcount; /* Use counter */
76609+ atomic_t refcount; /* Use counter */
76610 void (*ctor)(void *); /* Called on object slot creation */
76611 struct list_head list; /* List of all slab caches on the system */
76612 };
76613@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76614 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76615 #endif
76616
76617+#ifdef CONFIG_PAX_USERCOPY_SLABS
76618+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76619+#endif
76620+
76621 /*
76622 * Figure out which kmalloc slab an allocation of a certain size
76623 * belongs to.
76624@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76625 * 2 = 120 .. 192 bytes
76626 * n = 2^(n-1) .. 2^n -1
76627 */
76628-static __always_inline int kmalloc_index(size_t size)
76629+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76630 {
76631 if (!size)
76632 return 0;
76633@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76634 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76635 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76636 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76637-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76638+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76639 #define kmalloc_track_caller(size, flags) \
76640 __kmalloc_track_caller(size, flags, _RET_IP_)
76641 #else
76642@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76643 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76644 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76645 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76646-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76647+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76648 #define kmalloc_node_track_caller(size, flags, node) \
76649 __kmalloc_node_track_caller(size, flags, node, \
76650 _RET_IP_)
76651diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76652index cd40158..4e2f7af 100644
76653--- a/include/linux/slab_def.h
76654+++ b/include/linux/slab_def.h
76655@@ -50,7 +50,7 @@ struct kmem_cache {
76656 /* 4) cache creation/removal */
76657 const char *name;
76658 struct list_head list;
76659- int refcount;
76660+ atomic_t refcount;
76661 int object_size;
76662 int align;
76663
76664@@ -66,10 +66,14 @@ struct kmem_cache {
76665 unsigned long node_allocs;
76666 unsigned long node_frees;
76667 unsigned long node_overflow;
76668- atomic_t allochit;
76669- atomic_t allocmiss;
76670- atomic_t freehit;
76671- atomic_t freemiss;
76672+ atomic_unchecked_t allochit;
76673+ atomic_unchecked_t allocmiss;
76674+ atomic_unchecked_t freehit;
76675+ atomic_unchecked_t freemiss;
76676+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76677+ atomic_unchecked_t sanitized;
76678+ atomic_unchecked_t not_sanitized;
76679+#endif
76680
76681 /*
76682 * If debugging is enabled, then the allocator can add additional
76683@@ -103,7 +107,7 @@ struct kmem_cache {
76684 };
76685
76686 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76687-void *__kmalloc(size_t size, gfp_t flags);
76688+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76689
76690 #ifdef CONFIG_TRACING
76691 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76692@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76693 cachep = kmalloc_dma_caches[i];
76694 else
76695 #endif
76696+
76697+#ifdef CONFIG_PAX_USERCOPY_SLABS
76698+ if (flags & GFP_USERCOPY)
76699+ cachep = kmalloc_usercopy_caches[i];
76700+ else
76701+#endif
76702+
76703 cachep = kmalloc_caches[i];
76704
76705 ret = kmem_cache_alloc_trace(cachep, flags, size);
76706@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76707 }
76708
76709 #ifdef CONFIG_NUMA
76710-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76711+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76712 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76713
76714 #ifdef CONFIG_TRACING
76715@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76716 cachep = kmalloc_dma_caches[i];
76717 else
76718 #endif
76719+
76720+#ifdef CONFIG_PAX_USERCOPY_SLABS
76721+ if (flags & GFP_USERCOPY)
76722+ cachep = kmalloc_usercopy_caches[i];
76723+ else
76724+#endif
76725+
76726 cachep = kmalloc_caches[i];
76727
76728 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76729diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76730index 095a5a4..4b82027 100644
76731--- a/include/linux/slob_def.h
76732+++ b/include/linux/slob_def.h
76733@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76734 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76735 }
76736
76737-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76738+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76739
76740 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76741 {
76742@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76743 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76744 }
76745
76746-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76747+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76748 {
76749 return kmalloc(size, flags);
76750 }
76751diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76752index 027276f..092bfe8 100644
76753--- a/include/linux/slub_def.h
76754+++ b/include/linux/slub_def.h
76755@@ -80,7 +80,7 @@ struct kmem_cache {
76756 struct kmem_cache_order_objects max;
76757 struct kmem_cache_order_objects min;
76758 gfp_t allocflags; /* gfp flags to use on each alloc */
76759- int refcount; /* Refcount for slab cache destroy */
76760+ atomic_t refcount; /* Refcount for slab cache destroy */
76761 void (*ctor)(void *);
76762 int inuse; /* Offset to metadata */
76763 int align; /* Alignment */
76764@@ -105,7 +105,7 @@ struct kmem_cache {
76765 };
76766
76767 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76768-void *__kmalloc(size_t size, gfp_t flags);
76769+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76770
76771 static __always_inline void *
76772 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76773@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76774 }
76775 #endif
76776
76777-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76778+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76779 {
76780 unsigned int order = get_order(size);
76781 return kmalloc_order_trace(size, flags, order);
76782@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76783 }
76784
76785 #ifdef CONFIG_NUMA
76786-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76787+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76788 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76789
76790 #ifdef CONFIG_TRACING
76791diff --git a/include/linux/smp.h b/include/linux/smp.h
76792index c181399..09d7b92 100644
76793--- a/include/linux/smp.h
76794+++ b/include/linux/smp.h
76795@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76796 #endif
76797
76798 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76799+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76800 #define put_cpu() preempt_enable()
76801+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76802
76803 /*
76804 * Callback to arch code if there's nosmp or maxcpus=0 on the
76805diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76806index 54f91d3..be2c379 100644
76807--- a/include/linux/sock_diag.h
76808+++ b/include/linux/sock_diag.h
76809@@ -11,7 +11,7 @@ struct sock;
76810 struct sock_diag_handler {
76811 __u8 family;
76812 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76813-};
76814+} __do_const;
76815
76816 int sock_diag_register(const struct sock_diag_handler *h);
76817 void sock_diag_unregister(const struct sock_diag_handler *h);
76818diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76819index 680f9a3..f13aeb0 100644
76820--- a/include/linux/sonet.h
76821+++ b/include/linux/sonet.h
76822@@ -7,7 +7,7 @@
76823 #include <uapi/linux/sonet.h>
76824
76825 struct k_sonet_stats {
76826-#define __HANDLE_ITEM(i) atomic_t i
76827+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76828 __SONET_ITEMS
76829 #undef __HANDLE_ITEM
76830 };
76831diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76832index 07d8e53..dc934c9 100644
76833--- a/include/linux/sunrpc/addr.h
76834+++ b/include/linux/sunrpc/addr.h
76835@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76836 {
76837 switch (sap->sa_family) {
76838 case AF_INET:
76839- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76840+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76841 case AF_INET6:
76842- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76843+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76844 }
76845 return 0;
76846 }
76847@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76848 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76849 const struct sockaddr *src)
76850 {
76851- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76852+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76853 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76854
76855 dsin->sin_family = ssin->sin_family;
76856@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76857 if (sa->sa_family != AF_INET6)
76858 return 0;
76859
76860- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76861+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76862 }
76863
76864 #endif /* _LINUX_SUNRPC_ADDR_H */
76865diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76866index bfe11be..12bc8c4 100644
76867--- a/include/linux/sunrpc/clnt.h
76868+++ b/include/linux/sunrpc/clnt.h
76869@@ -96,7 +96,7 @@ struct rpc_procinfo {
76870 unsigned int p_timer; /* Which RTT timer to use */
76871 u32 p_statidx; /* Which procedure to account */
76872 const char * p_name; /* name of procedure */
76873-};
76874+} __do_const;
76875
76876 #ifdef __KERNEL__
76877
76878diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76879index 1f0216b..6a4fa50 100644
76880--- a/include/linux/sunrpc/svc.h
76881+++ b/include/linux/sunrpc/svc.h
76882@@ -411,7 +411,7 @@ struct svc_procedure {
76883 unsigned int pc_count; /* call count */
76884 unsigned int pc_cachetype; /* cache info (NFS) */
76885 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76886-};
76887+} __do_const;
76888
76889 /*
76890 * Function prototypes.
76891diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76892index 0b8e3e6..33e0a01 100644
76893--- a/include/linux/sunrpc/svc_rdma.h
76894+++ b/include/linux/sunrpc/svc_rdma.h
76895@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76896 extern unsigned int svcrdma_max_requests;
76897 extern unsigned int svcrdma_max_req_size;
76898
76899-extern atomic_t rdma_stat_recv;
76900-extern atomic_t rdma_stat_read;
76901-extern atomic_t rdma_stat_write;
76902-extern atomic_t rdma_stat_sq_starve;
76903-extern atomic_t rdma_stat_rq_starve;
76904-extern atomic_t rdma_stat_rq_poll;
76905-extern atomic_t rdma_stat_rq_prod;
76906-extern atomic_t rdma_stat_sq_poll;
76907-extern atomic_t rdma_stat_sq_prod;
76908+extern atomic_unchecked_t rdma_stat_recv;
76909+extern atomic_unchecked_t rdma_stat_read;
76910+extern atomic_unchecked_t rdma_stat_write;
76911+extern atomic_unchecked_t rdma_stat_sq_starve;
76912+extern atomic_unchecked_t rdma_stat_rq_starve;
76913+extern atomic_unchecked_t rdma_stat_rq_poll;
76914+extern atomic_unchecked_t rdma_stat_rq_prod;
76915+extern atomic_unchecked_t rdma_stat_sq_poll;
76916+extern atomic_unchecked_t rdma_stat_sq_prod;
76917
76918 #define RPCRDMA_VERSION 1
76919
76920diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76921index 8d71d65..f79586e 100644
76922--- a/include/linux/sunrpc/svcauth.h
76923+++ b/include/linux/sunrpc/svcauth.h
76924@@ -120,7 +120,7 @@ struct auth_ops {
76925 int (*release)(struct svc_rqst *rq);
76926 void (*domain_release)(struct auth_domain *);
76927 int (*set_client)(struct svc_rqst *rq);
76928-};
76929+} __do_const;
76930
76931 #define SVC_GARBAGE 1
76932 #define SVC_SYSERR 2
76933diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76934index a5ffd32..0935dea 100644
76935--- a/include/linux/swiotlb.h
76936+++ b/include/linux/swiotlb.h
76937@@ -60,7 +60,8 @@ extern void
76938
76939 extern void
76940 swiotlb_free_coherent(struct device *hwdev, size_t size,
76941- void *vaddr, dma_addr_t dma_handle);
76942+ void *vaddr, dma_addr_t dma_handle,
76943+ struct dma_attrs *attrs);
76944
76945 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76946 unsigned long offset, size_t size,
76947diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76948index 84662ec..5271947 100644
76949--- a/include/linux/syscalls.h
76950+++ b/include/linux/syscalls.h
76951@@ -97,8 +97,14 @@ struct sigaltstack;
76952 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76953
76954 #define __SC_DECL(t, a) t a
76955+#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))
76956 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76957-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76958+#define __SC_LONG(t, a) __typeof( \
76959+ __builtin_choose_expr( \
76960+ sizeof(t) > sizeof(int), \
76961+ (t) 0, \
76962+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76963+ )) a
76964 #define __SC_CAST(t, a) (t) a
76965 #define __SC_ARGS(t, a) a
76966 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76967@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76968 asmlinkage long sys_fsync(unsigned int fd);
76969 asmlinkage long sys_fdatasync(unsigned int fd);
76970 asmlinkage long sys_bdflush(int func, long data);
76971-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76972- char __user *type, unsigned long flags,
76973+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76974+ const char __user *type, unsigned long flags,
76975 void __user *data);
76976-asmlinkage long sys_umount(char __user *name, int flags);
76977-asmlinkage long sys_oldumount(char __user *name);
76978+asmlinkage long sys_umount(const char __user *name, int flags);
76979+asmlinkage long sys_oldumount(const char __user *name);
76980 asmlinkage long sys_truncate(const char __user *path, long length);
76981 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76982 asmlinkage long sys_stat(const char __user *filename,
76983@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76984 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76985 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76986 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76987- struct sockaddr __user *, int);
76988+ struct sockaddr __user *, int) __intentional_overflow(0);
76989 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76990 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76991 unsigned int vlen, unsigned flags);
76992diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76993index 27b3b0b..e093dd9 100644
76994--- a/include/linux/syscore_ops.h
76995+++ b/include/linux/syscore_ops.h
76996@@ -16,7 +16,7 @@ struct syscore_ops {
76997 int (*suspend)(void);
76998 void (*resume)(void);
76999 void (*shutdown)(void);
77000-};
77001+} __do_const;
77002
77003 extern void register_syscore_ops(struct syscore_ops *ops);
77004 extern void unregister_syscore_ops(struct syscore_ops *ops);
77005diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77006index 14a8ff2..af52bad 100644
77007--- a/include/linux/sysctl.h
77008+++ b/include/linux/sysctl.h
77009@@ -34,13 +34,13 @@ struct ctl_table_root;
77010 struct ctl_table_header;
77011 struct ctl_dir;
77012
77013-typedef struct ctl_table ctl_table;
77014-
77015 typedef int proc_handler (struct ctl_table *ctl, int write,
77016 void __user *buffer, size_t *lenp, loff_t *ppos);
77017
77018 extern int proc_dostring(struct ctl_table *, int,
77019 void __user *, size_t *, loff_t *);
77020+extern int proc_dostring_modpriv(struct ctl_table *, int,
77021+ void __user *, size_t *, loff_t *);
77022 extern int proc_dointvec(struct ctl_table *, int,
77023 void __user *, size_t *, loff_t *);
77024 extern int proc_dointvec_minmax(struct ctl_table *, int,
77025@@ -115,7 +115,9 @@ struct ctl_table
77026 struct ctl_table_poll *poll;
77027 void *extra1;
77028 void *extra2;
77029-};
77030+} __do_const;
77031+typedef struct ctl_table __no_const ctl_table_no_const;
77032+typedef struct ctl_table ctl_table;
77033
77034 struct ctl_node {
77035 struct rb_node node;
77036diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77037index 9e8a9b5..753de68 100644
77038--- a/include/linux/sysfs.h
77039+++ b/include/linux/sysfs.h
77040@@ -33,7 +33,8 @@ struct attribute {
77041 struct lock_class_key *key;
77042 struct lock_class_key skey;
77043 #endif
77044-};
77045+} __do_const;
77046+typedef struct attribute __no_const attribute_no_const;
77047
77048 /**
77049 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77050@@ -62,7 +63,8 @@ struct attribute_group {
77051 struct attribute *, int);
77052 struct attribute **attrs;
77053 struct bin_attribute **bin_attrs;
77054-};
77055+} __do_const;
77056+typedef struct attribute_group __no_const attribute_group_no_const;
77057
77058 /**
77059 * Use these macros to make defining attributes easier. See include/linux/device.h
77060@@ -123,7 +125,8 @@ struct bin_attribute {
77061 char *, loff_t, size_t);
77062 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77063 struct vm_area_struct *vma);
77064-};
77065+} __do_const;
77066+typedef struct bin_attribute __no_const bin_attribute_no_const;
77067
77068 /**
77069 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77070diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77071index 7faf933..9b85a0c 100644
77072--- a/include/linux/sysrq.h
77073+++ b/include/linux/sysrq.h
77074@@ -16,6 +16,7 @@
77075
77076 #include <linux/errno.h>
77077 #include <linux/types.h>
77078+#include <linux/compiler.h>
77079
77080 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77081 #define SYSRQ_DEFAULT_ENABLE 1
77082@@ -36,7 +37,7 @@ struct sysrq_key_op {
77083 char *help_msg;
77084 char *action_msg;
77085 int enable_mask;
77086-};
77087+} __do_const;
77088
77089 #ifdef CONFIG_MAGIC_SYSRQ
77090
77091diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77092index e7e0473..7989295 100644
77093--- a/include/linux/thread_info.h
77094+++ b/include/linux/thread_info.h
77095@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77096 #error "no set_restore_sigmask() provided and default one won't work"
77097 #endif
77098
77099+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77100+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77101+{
77102+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77103+ if (!__builtin_constant_p(n))
77104+#endif
77105+ __check_object_size(ptr, n, to_user);
77106+}
77107+
77108 #endif /* __KERNEL__ */
77109
77110 #endif /* _LINUX_THREAD_INFO_H */
77111diff --git a/include/linux/tty.h b/include/linux/tty.h
77112index 01ac30e..bf18a71 100644
77113--- a/include/linux/tty.h
77114+++ b/include/linux/tty.h
77115@@ -194,7 +194,7 @@ struct tty_port {
77116 const struct tty_port_operations *ops; /* Port operations */
77117 spinlock_t lock; /* Lock protecting tty field */
77118 int blocked_open; /* Waiting to open */
77119- int count; /* Usage count */
77120+ atomic_t count; /* Usage count */
77121 wait_queue_head_t open_wait; /* Open waiters */
77122 wait_queue_head_t close_wait; /* Close waiters */
77123 wait_queue_head_t delta_msr_wait; /* Modem status change */
77124@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77125 struct tty_struct *tty, struct file *filp);
77126 static inline int tty_port_users(struct tty_port *port)
77127 {
77128- return port->count + port->blocked_open;
77129+ return atomic_read(&port->count) + port->blocked_open;
77130 }
77131
77132 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77133diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77134index 756a609..b302dd6 100644
77135--- a/include/linux/tty_driver.h
77136+++ b/include/linux/tty_driver.h
77137@@ -285,7 +285,7 @@ struct tty_operations {
77138 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77139 #endif
77140 const struct file_operations *proc_fops;
77141-};
77142+} __do_const;
77143
77144 struct tty_driver {
77145 int magic; /* magic number for this structure */
77146diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77147index a1b0489..f02e17c 100644
77148--- a/include/linux/tty_ldisc.h
77149+++ b/include/linux/tty_ldisc.h
77150@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77151
77152 struct module *owner;
77153
77154- int refcount;
77155+ atomic_t refcount;
77156 };
77157
77158 struct tty_ldisc {
77159diff --git a/include/linux/types.h b/include/linux/types.h
77160index 4d118ba..c3ee9bf 100644
77161--- a/include/linux/types.h
77162+++ b/include/linux/types.h
77163@@ -176,10 +176,26 @@ typedef struct {
77164 int counter;
77165 } atomic_t;
77166
77167+#ifdef CONFIG_PAX_REFCOUNT
77168+typedef struct {
77169+ int counter;
77170+} atomic_unchecked_t;
77171+#else
77172+typedef atomic_t atomic_unchecked_t;
77173+#endif
77174+
77175 #ifdef CONFIG_64BIT
77176 typedef struct {
77177 long counter;
77178 } atomic64_t;
77179+
77180+#ifdef CONFIG_PAX_REFCOUNT
77181+typedef struct {
77182+ long counter;
77183+} atomic64_unchecked_t;
77184+#else
77185+typedef atomic64_t atomic64_unchecked_t;
77186+#endif
77187 #endif
77188
77189 struct list_head {
77190diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77191index 5ca0951..ab496a5 100644
77192--- a/include/linux/uaccess.h
77193+++ b/include/linux/uaccess.h
77194@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77195 long ret; \
77196 mm_segment_t old_fs = get_fs(); \
77197 \
77198- set_fs(KERNEL_DS); \
77199 pagefault_disable(); \
77200- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77201- pagefault_enable(); \
77202+ set_fs(KERNEL_DS); \
77203+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77204 set_fs(old_fs); \
77205+ pagefault_enable(); \
77206 ret; \
77207 })
77208
77209diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77210index 8e522cbc..aa8572d 100644
77211--- a/include/linux/uidgid.h
77212+++ b/include/linux/uidgid.h
77213@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77214
77215 #endif /* CONFIG_USER_NS */
77216
77217+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77218+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77219+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77220+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77221+
77222 #endif /* _LINUX_UIDGID_H */
77223diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77224index 99c1b4d..562e6f3 100644
77225--- a/include/linux/unaligned/access_ok.h
77226+++ b/include/linux/unaligned/access_ok.h
77227@@ -4,34 +4,34 @@
77228 #include <linux/kernel.h>
77229 #include <asm/byteorder.h>
77230
77231-static inline u16 get_unaligned_le16(const void *p)
77232+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77233 {
77234- return le16_to_cpup((__le16 *)p);
77235+ return le16_to_cpup((const __le16 *)p);
77236 }
77237
77238-static inline u32 get_unaligned_le32(const void *p)
77239+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77240 {
77241- return le32_to_cpup((__le32 *)p);
77242+ return le32_to_cpup((const __le32 *)p);
77243 }
77244
77245-static inline u64 get_unaligned_le64(const void *p)
77246+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77247 {
77248- return le64_to_cpup((__le64 *)p);
77249+ return le64_to_cpup((const __le64 *)p);
77250 }
77251
77252-static inline u16 get_unaligned_be16(const void *p)
77253+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77254 {
77255- return be16_to_cpup((__be16 *)p);
77256+ return be16_to_cpup((const __be16 *)p);
77257 }
77258
77259-static inline u32 get_unaligned_be32(const void *p)
77260+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77261 {
77262- return be32_to_cpup((__be32 *)p);
77263+ return be32_to_cpup((const __be32 *)p);
77264 }
77265
77266-static inline u64 get_unaligned_be64(const void *p)
77267+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77268 {
77269- return be64_to_cpup((__be64 *)p);
77270+ return be64_to_cpup((const __be64 *)p);
77271 }
77272
77273 static inline void put_unaligned_le16(u16 val, void *p)
77274diff --git a/include/linux/usb.h b/include/linux/usb.h
77275index 0eec268..4496526 100644
77276--- a/include/linux/usb.h
77277+++ b/include/linux/usb.h
77278@@ -560,7 +560,7 @@ struct usb_device {
77279 int maxchild;
77280
77281 u32 quirks;
77282- atomic_t urbnum;
77283+ atomic_unchecked_t urbnum;
77284
77285 unsigned long active_duration;
77286
77287@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77288
77289 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77290 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77291- void *data, __u16 size, int timeout);
77292+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77293 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77294 void *data, int len, int *actual_length, int timeout);
77295 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77296diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77297index e452ba6..78f8e80 100644
77298--- a/include/linux/usb/renesas_usbhs.h
77299+++ b/include/linux/usb/renesas_usbhs.h
77300@@ -39,7 +39,7 @@ enum {
77301 */
77302 struct renesas_usbhs_driver_callback {
77303 int (*notify_hotplug)(struct platform_device *pdev);
77304-};
77305+} __no_const;
77306
77307 /*
77308 * callback functions for platform
77309diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77310index 6f8fbcf..8259001 100644
77311--- a/include/linux/vermagic.h
77312+++ b/include/linux/vermagic.h
77313@@ -25,9 +25,35 @@
77314 #define MODULE_ARCH_VERMAGIC ""
77315 #endif
77316
77317+#ifdef CONFIG_PAX_REFCOUNT
77318+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77319+#else
77320+#define MODULE_PAX_REFCOUNT ""
77321+#endif
77322+
77323+#ifdef CONSTIFY_PLUGIN
77324+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77325+#else
77326+#define MODULE_CONSTIFY_PLUGIN ""
77327+#endif
77328+
77329+#ifdef STACKLEAK_PLUGIN
77330+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77331+#else
77332+#define MODULE_STACKLEAK_PLUGIN ""
77333+#endif
77334+
77335+#ifdef CONFIG_GRKERNSEC
77336+#define MODULE_GRSEC "GRSEC "
77337+#else
77338+#define MODULE_GRSEC ""
77339+#endif
77340+
77341 #define VERMAGIC_STRING \
77342 UTS_RELEASE " " \
77343 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77344 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77345- MODULE_ARCH_VERMAGIC
77346+ MODULE_ARCH_VERMAGIC \
77347+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77348+ MODULE_GRSEC
77349
77350diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77351index 4b8a891..c20e936 100644
77352--- a/include/linux/vmalloc.h
77353+++ b/include/linux/vmalloc.h
77354@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77355 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77356 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77357 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77358+
77359+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77360+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77361+#endif
77362+
77363 /* bits [20..32] reserved for arch specific ioremap internals */
77364
77365 /*
77366@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77367 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77368 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77369 unsigned long start, unsigned long end, gfp_t gfp_mask,
77370- pgprot_t prot, int node, const void *caller);
77371+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77372 extern void vfree(const void *addr);
77373
77374 extern void *vmap(struct page **pages, unsigned int count,
77375@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77376 extern void free_vm_area(struct vm_struct *area);
77377
77378 /* for /dev/kmem */
77379-extern long vread(char *buf, char *addr, unsigned long count);
77380-extern long vwrite(char *buf, char *addr, unsigned long count);
77381+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77382+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77383
77384 /*
77385 * Internals. Dont't use..
77386diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77387index c586679..f06b389 100644
77388--- a/include/linux/vmstat.h
77389+++ b/include/linux/vmstat.h
77390@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77391 /*
77392 * Zone based page accounting with per cpu differentials.
77393 */
77394-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77395+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77396
77397 static inline void zone_page_state_add(long x, struct zone *zone,
77398 enum zone_stat_item item)
77399 {
77400- atomic_long_add(x, &zone->vm_stat[item]);
77401- atomic_long_add(x, &vm_stat[item]);
77402+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77403+ atomic_long_add_unchecked(x, &vm_stat[item]);
77404 }
77405
77406 static inline unsigned long global_page_state(enum zone_stat_item item)
77407 {
77408- long x = atomic_long_read(&vm_stat[item]);
77409+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77410 #ifdef CONFIG_SMP
77411 if (x < 0)
77412 x = 0;
77413@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77414 static inline unsigned long zone_page_state(struct zone *zone,
77415 enum zone_stat_item item)
77416 {
77417- long x = atomic_long_read(&zone->vm_stat[item]);
77418+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77419 #ifdef CONFIG_SMP
77420 if (x < 0)
77421 x = 0;
77422@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77423 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77424 enum zone_stat_item item)
77425 {
77426- long x = atomic_long_read(&zone->vm_stat[item]);
77427+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77428
77429 #ifdef CONFIG_SMP
77430 int cpu;
77431@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77432
77433 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77434 {
77435- atomic_long_inc(&zone->vm_stat[item]);
77436- atomic_long_inc(&vm_stat[item]);
77437+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77438+ atomic_long_inc_unchecked(&vm_stat[item]);
77439 }
77440
77441 static inline void __inc_zone_page_state(struct page *page,
77442@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77443
77444 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77445 {
77446- atomic_long_dec(&zone->vm_stat[item]);
77447- atomic_long_dec(&vm_stat[item]);
77448+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77449+ atomic_long_dec_unchecked(&vm_stat[item]);
77450 }
77451
77452 static inline void __dec_zone_page_state(struct page *page,
77453diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77454index fdbafc6..49dfe4f 100644
77455--- a/include/linux/xattr.h
77456+++ b/include/linux/xattr.h
77457@@ -28,7 +28,7 @@ struct xattr_handler {
77458 size_t size, int handler_flags);
77459 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77460 size_t size, int flags, int handler_flags);
77461-};
77462+} __do_const;
77463
77464 struct xattr {
77465 char *name;
77466@@ -37,6 +37,9 @@ struct xattr {
77467 };
77468
77469 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77470+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77471+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77472+#endif
77473 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77474 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77475 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77476diff --git a/include/linux/yam.h b/include/linux/yam.h
77477index 7fe2822..512cdc2 100644
77478--- a/include/linux/yam.h
77479+++ b/include/linux/yam.h
77480@@ -77,6 +77,6 @@ struct yamdrv_ioctl_cfg {
77481
77482 struct yamdrv_ioctl_mcs {
77483 int cmd;
77484- int bitrate;
77485+ unsigned int bitrate;
77486 unsigned char bits[YAM_FPGA_SIZE];
77487 };
77488diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77489index 9c5a6b4..09c9438 100644
77490--- a/include/linux/zlib.h
77491+++ b/include/linux/zlib.h
77492@@ -31,6 +31,7 @@
77493 #define _ZLIB_H
77494
77495 #include <linux/zconf.h>
77496+#include <linux/compiler.h>
77497
77498 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77499 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77500@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77501
77502 /* basic functions */
77503
77504-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77505+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77506 /*
77507 Returns the number of bytes that needs to be allocated for a per-
77508 stream workspace with the specified parameters. A pointer to this
77509diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77510index c768c9f..bdcaa5a 100644
77511--- a/include/media/v4l2-dev.h
77512+++ b/include/media/v4l2-dev.h
77513@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77514 int (*mmap) (struct file *, struct vm_area_struct *);
77515 int (*open) (struct file *);
77516 int (*release) (struct file *);
77517-};
77518+} __do_const;
77519
77520 /*
77521 * Newer version of video_device, handled by videodev2.c
77522diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77523index c9b1593..a572459 100644
77524--- a/include/media/v4l2-device.h
77525+++ b/include/media/v4l2-device.h
77526@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77527 this function returns 0. If the name ends with a digit (e.g. cx18),
77528 then the name will be set to cx18-0 since cx180 looks really odd. */
77529 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77530- atomic_t *instance);
77531+ atomic_unchecked_t *instance);
77532
77533 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77534 Since the parent disappears this ensures that v4l2_dev doesn't have an
77535diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77536index d9fa68f..45c88d1 100644
77537--- a/include/net/9p/transport.h
77538+++ b/include/net/9p/transport.h
77539@@ -63,7 +63,7 @@ struct p9_trans_module {
77540 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77541 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77542 char *, char *, int , int, int, int);
77543-};
77544+} __do_const;
77545
77546 void v9fs_register_trans(struct p9_trans_module *m);
77547 void v9fs_unregister_trans(struct p9_trans_module *m);
77548diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77549index 1a966af..2767cf6 100644
77550--- a/include/net/bluetooth/l2cap.h
77551+++ b/include/net/bluetooth/l2cap.h
77552@@ -551,7 +551,7 @@ struct l2cap_ops {
77553 void (*defer) (struct l2cap_chan *chan);
77554 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77555 unsigned long len, int nb);
77556-};
77557+} __do_const;
77558
77559 struct l2cap_conn {
77560 struct hci_conn *hcon;
77561diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77562index f2ae33d..c457cf0 100644
77563--- a/include/net/caif/cfctrl.h
77564+++ b/include/net/caif/cfctrl.h
77565@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77566 void (*radioset_rsp)(void);
77567 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77568 struct cflayer *client_layer);
77569-};
77570+} __no_const;
77571
77572 /* Link Setup Parameters for CAIF-Links. */
77573 struct cfctrl_link_param {
77574@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77575 struct cfctrl {
77576 struct cfsrvl serv;
77577 struct cfctrl_rsp res;
77578- atomic_t req_seq_no;
77579- atomic_t rsp_seq_no;
77580+ atomic_unchecked_t req_seq_no;
77581+ atomic_unchecked_t rsp_seq_no;
77582 struct list_head list;
77583 /* Protects from simultaneous access to first_req list */
77584 spinlock_t info_list_lock;
77585diff --git a/include/net/flow.h b/include/net/flow.h
77586index 628e11b..4c475df 100644
77587--- a/include/net/flow.h
77588+++ b/include/net/flow.h
77589@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77590
77591 extern void flow_cache_flush(void);
77592 extern void flow_cache_flush_deferred(void);
77593-extern atomic_t flow_cache_genid;
77594+extern atomic_unchecked_t flow_cache_genid;
77595
77596 #endif
77597diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77598index 8e0b6c8..73cf605 100644
77599--- a/include/net/genetlink.h
77600+++ b/include/net/genetlink.h
77601@@ -120,7 +120,7 @@ struct genl_ops {
77602 struct netlink_callback *cb);
77603 int (*done)(struct netlink_callback *cb);
77604 struct list_head ops_list;
77605-};
77606+} __do_const;
77607
77608 extern int __genl_register_family(struct genl_family *family);
77609
77610diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77611index 734d9b5..48a9a4b 100644
77612--- a/include/net/gro_cells.h
77613+++ b/include/net/gro_cells.h
77614@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77615 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77616
77617 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77618- atomic_long_inc(&dev->rx_dropped);
77619+ atomic_long_inc_unchecked(&dev->rx_dropped);
77620 kfree_skb(skb);
77621 return;
77622 }
77623diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77624index de2c785..0588a6b 100644
77625--- a/include/net/inet_connection_sock.h
77626+++ b/include/net/inet_connection_sock.h
77627@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77628 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77629 int (*bind_conflict)(const struct sock *sk,
77630 const struct inet_bind_bucket *tb, bool relax);
77631-};
77632+} __do_const;
77633
77634 /** inet_connection_sock - INET connection oriented sock
77635 *
77636diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77637index 53f464d..0bd0b49 100644
77638--- a/include/net/inetpeer.h
77639+++ b/include/net/inetpeer.h
77640@@ -47,8 +47,8 @@ struct inet_peer {
77641 */
77642 union {
77643 struct {
77644- atomic_t rid; /* Frag reception counter */
77645- atomic_t ip_id_count; /* IP ID for the next packet */
77646+ atomic_unchecked_t rid; /* Frag reception counter */
77647+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77648 };
77649 struct rcu_head rcu;
77650 struct inet_peer *gc_next;
77651@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77652 /* can be called with or without local BH being disabled */
77653 static inline int inet_getid(struct inet_peer *p, int more)
77654 {
77655- int old, new;
77656+ int id;
77657 more++;
77658 inet_peer_refcheck(p);
77659- do {
77660- old = atomic_read(&p->ip_id_count);
77661- new = old + more;
77662- if (!new)
77663- new = 1;
77664- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77665- return new;
77666+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77667+ if (!id)
77668+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77669+ return id;
77670 }
77671
77672 #endif /* _NET_INETPEER_H */
77673diff --git a/include/net/ip.h b/include/net/ip.h
77674index edfa591..a643b82 100644
77675--- a/include/net/ip.h
77676+++ b/include/net/ip.h
77677@@ -202,7 +202,7 @@ extern struct local_ports {
77678 } sysctl_local_ports;
77679 extern void inet_get_local_port_range(int *low, int *high);
77680
77681-extern unsigned long *sysctl_local_reserved_ports;
77682+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77683 static inline int inet_is_reserved_local_port(int port)
77684 {
77685 return test_bit(port, sysctl_local_reserved_ports);
77686diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77687index cbf2be3..3683f6d 100644
77688--- a/include/net/ip_fib.h
77689+++ b/include/net/ip_fib.h
77690@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77691
77692 #define FIB_RES_SADDR(net, res) \
77693 ((FIB_RES_NH(res).nh_saddr_genid == \
77694- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77695+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77696 FIB_RES_NH(res).nh_saddr : \
77697 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77698 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77699diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77700index f0d70f0..185f15b 100644
77701--- a/include/net/ip_vs.h
77702+++ b/include/net/ip_vs.h
77703@@ -588,7 +588,7 @@ struct ip_vs_conn {
77704 struct ip_vs_conn *control; /* Master control connection */
77705 atomic_t n_control; /* Number of controlled ones */
77706 struct ip_vs_dest *dest; /* real server */
77707- atomic_t in_pkts; /* incoming packet counter */
77708+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77709
77710 /* packet transmitter for different forwarding methods. If it
77711 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77712@@ -737,7 +737,7 @@ struct ip_vs_dest {
77713 __be16 port; /* port number of the server */
77714 union nf_inet_addr addr; /* IP address of the server */
77715 volatile unsigned int flags; /* dest status flags */
77716- atomic_t conn_flags; /* flags to copy to conn */
77717+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77718 atomic_t weight; /* server weight */
77719
77720 atomic_t refcnt; /* reference counter */
77721@@ -993,11 +993,11 @@ struct netns_ipvs {
77722 /* ip_vs_lblc */
77723 int sysctl_lblc_expiration;
77724 struct ctl_table_header *lblc_ctl_header;
77725- struct ctl_table *lblc_ctl_table;
77726+ ctl_table_no_const *lblc_ctl_table;
77727 /* ip_vs_lblcr */
77728 int sysctl_lblcr_expiration;
77729 struct ctl_table_header *lblcr_ctl_header;
77730- struct ctl_table *lblcr_ctl_table;
77731+ ctl_table_no_const *lblcr_ctl_table;
77732 /* ip_vs_est */
77733 struct list_head est_list; /* estimator list */
77734 spinlock_t est_lock;
77735diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77736index 80ffde3..968b0f4 100644
77737--- a/include/net/irda/ircomm_tty.h
77738+++ b/include/net/irda/ircomm_tty.h
77739@@ -35,6 +35,7 @@
77740 #include <linux/termios.h>
77741 #include <linux/timer.h>
77742 #include <linux/tty.h> /* struct tty_struct */
77743+#include <asm/local.h>
77744
77745 #include <net/irda/irias_object.h>
77746 #include <net/irda/ircomm_core.h>
77747diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77748index 714cc9a..ea05f3e 100644
77749--- a/include/net/iucv/af_iucv.h
77750+++ b/include/net/iucv/af_iucv.h
77751@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77752 struct iucv_sock_list {
77753 struct hlist_head head;
77754 rwlock_t lock;
77755- atomic_t autobind_name;
77756+ atomic_unchecked_t autobind_name;
77757 };
77758
77759 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77760diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77761index df83f69..9b640b8 100644
77762--- a/include/net/llc_c_ac.h
77763+++ b/include/net/llc_c_ac.h
77764@@ -87,7 +87,7 @@
77765 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77766 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77767
77768-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77769+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77770
77771 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77772 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77773diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77774index 6ca3113..f8026dd 100644
77775--- a/include/net/llc_c_ev.h
77776+++ b/include/net/llc_c_ev.h
77777@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77778 return (struct llc_conn_state_ev *)skb->cb;
77779 }
77780
77781-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77782-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77783+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77784+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77785
77786 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77787 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77788diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77789index 0e79cfb..f46db31 100644
77790--- a/include/net/llc_c_st.h
77791+++ b/include/net/llc_c_st.h
77792@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77793 u8 next_state;
77794 llc_conn_ev_qfyr_t *ev_qualifiers;
77795 llc_conn_action_t *ev_actions;
77796-};
77797+} __do_const;
77798
77799 struct llc_conn_state {
77800 u8 current_state;
77801diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77802index 37a3bbd..55a4241 100644
77803--- a/include/net/llc_s_ac.h
77804+++ b/include/net/llc_s_ac.h
77805@@ -23,7 +23,7 @@
77806 #define SAP_ACT_TEST_IND 9
77807
77808 /* All action functions must look like this */
77809-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77810+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77811
77812 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77813 struct sk_buff *skb);
77814diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77815index 567c681..cd73ac0 100644
77816--- a/include/net/llc_s_st.h
77817+++ b/include/net/llc_s_st.h
77818@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77819 llc_sap_ev_t ev;
77820 u8 next_state;
77821 llc_sap_action_t *ev_actions;
77822-};
77823+} __do_const;
77824
77825 struct llc_sap_state {
77826 u8 curr_state;
77827diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77828index 551ba6a..11c99c1 100644
77829--- a/include/net/mac80211.h
77830+++ b/include/net/mac80211.h
77831@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77832 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77833 struct dentry *dir);
77834 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77835-};
77836+} __do_const;
77837
77838 static inline int rate_supported(struct ieee80211_sta *sta,
77839 enum ieee80211_band band,
77840diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77841index 7e748ad..5c6229b 100644
77842--- a/include/net/neighbour.h
77843+++ b/include/net/neighbour.h
77844@@ -123,7 +123,7 @@ struct neigh_ops {
77845 void (*error_report)(struct neighbour *, struct sk_buff *);
77846 int (*output)(struct neighbour *, struct sk_buff *);
77847 int (*connected_output)(struct neighbour *, struct sk_buff *);
77848-};
77849+} __do_const;
77850
77851 struct pneigh_entry {
77852 struct pneigh_entry *next;
77853diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77854index 84e37b1..8eba19a 100644
77855--- a/include/net/net_namespace.h
77856+++ b/include/net/net_namespace.h
77857@@ -119,8 +119,8 @@ struct net {
77858 struct netns_ipvs *ipvs;
77859 #endif
77860 struct sock *diag_nlsk;
77861- atomic_t rt_genid;
77862- atomic_t fnhe_genid;
77863+ atomic_unchecked_t rt_genid;
77864+ atomic_unchecked_t fnhe_genid;
77865 };
77866
77867 /*
77868@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77869 #define __net_init __init
77870 #define __net_exit __exit_refok
77871 #define __net_initdata __initdata
77872+#ifdef CONSTIFY_PLUGIN
77873 #define __net_initconst __initconst
77874+#else
77875+#define __net_initconst __initdata
77876+#endif
77877 #endif
77878
77879 struct pernet_operations {
77880@@ -287,7 +291,7 @@ struct pernet_operations {
77881 void (*exit_batch)(struct list_head *net_exit_list);
77882 int *id;
77883 size_t size;
77884-};
77885+} __do_const;
77886
77887 /*
77888 * Use these carefully. If you implement a network device and it
77889@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77890
77891 static inline int rt_genid(struct net *net)
77892 {
77893- return atomic_read(&net->rt_genid);
77894+ return atomic_read_unchecked(&net->rt_genid);
77895 }
77896
77897 static inline void rt_genid_bump(struct net *net)
77898 {
77899- atomic_inc(&net->rt_genid);
77900+ atomic_inc_unchecked(&net->rt_genid);
77901 }
77902
77903 static inline int fnhe_genid(struct net *net)
77904 {
77905- return atomic_read(&net->fnhe_genid);
77906+ return atomic_read_unchecked(&net->fnhe_genid);
77907 }
77908
77909 static inline void fnhe_genid_bump(struct net *net)
77910 {
77911- atomic_inc(&net->fnhe_genid);
77912+ atomic_inc_unchecked(&net->fnhe_genid);
77913 }
77914
77915 #endif /* __NET_NET_NAMESPACE_H */
77916diff --git a/include/net/netdma.h b/include/net/netdma.h
77917index 8ba8ce2..99b7fff 100644
77918--- a/include/net/netdma.h
77919+++ b/include/net/netdma.h
77920@@ -24,7 +24,7 @@
77921 #include <linux/dmaengine.h>
77922 #include <linux/skbuff.h>
77923
77924-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77925+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77926 struct sk_buff *skb, int offset, struct iovec *to,
77927 size_t len, struct dma_pinned_list *pinned_list);
77928
77929diff --git a/include/net/netlink.h b/include/net/netlink.h
77930index 9690b0f..87aded7 100644
77931--- a/include/net/netlink.h
77932+++ b/include/net/netlink.h
77933@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77934 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77935 {
77936 if (mark)
77937- skb_trim(skb, (unsigned char *) mark - skb->data);
77938+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77939 }
77940
77941 /**
77942diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77943index c9c0c53..53f24c3 100644
77944--- a/include/net/netns/conntrack.h
77945+++ b/include/net/netns/conntrack.h
77946@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77947 struct nf_proto_net {
77948 #ifdef CONFIG_SYSCTL
77949 struct ctl_table_header *ctl_table_header;
77950- struct ctl_table *ctl_table;
77951+ ctl_table_no_const *ctl_table;
77952 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77953 struct ctl_table_header *ctl_compat_header;
77954- struct ctl_table *ctl_compat_table;
77955+ ctl_table_no_const *ctl_compat_table;
77956 #endif
77957 #endif
77958 unsigned int users;
77959@@ -58,7 +58,7 @@ struct nf_ip_net {
77960 struct nf_icmp_net icmpv6;
77961 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77962 struct ctl_table_header *ctl_table_header;
77963- struct ctl_table *ctl_table;
77964+ ctl_table_no_const *ctl_table;
77965 #endif
77966 };
77967
77968diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77969index 2ba9de8..47bd6c7 100644
77970--- a/include/net/netns/ipv4.h
77971+++ b/include/net/netns/ipv4.h
77972@@ -67,7 +67,7 @@ struct netns_ipv4 {
77973 kgid_t sysctl_ping_group_range[2];
77974 long sysctl_tcp_mem[3];
77975
77976- atomic_t dev_addr_genid;
77977+ atomic_unchecked_t dev_addr_genid;
77978
77979 #ifdef CONFIG_IP_MROUTE
77980 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77981diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77982index 005e2c2..023d340 100644
77983--- a/include/net/netns/ipv6.h
77984+++ b/include/net/netns/ipv6.h
77985@@ -71,7 +71,7 @@ struct netns_ipv6 {
77986 struct fib_rules_ops *mr6_rules_ops;
77987 #endif
77988 #endif
77989- atomic_t dev_addr_genid;
77990+ atomic_unchecked_t dev_addr_genid;
77991 };
77992
77993 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77994diff --git a/include/net/ping.h b/include/net/ping.h
77995index 5db0224..0d65365 100644
77996--- a/include/net/ping.h
77997+++ b/include/net/ping.h
77998@@ -55,7 +55,7 @@ struct ping_iter_state {
77999 extern struct proto ping_prot;
78000 extern struct ping_table ping_table;
78001 #if IS_ENABLED(CONFIG_IPV6)
78002-extern struct pingv6_ops pingv6_ops;
78003+extern struct pingv6_ops *pingv6_ops;
78004 #endif
78005
78006 struct pingfakehdr {
78007diff --git a/include/net/protocol.h b/include/net/protocol.h
78008index 047c047..b9dad15 100644
78009--- a/include/net/protocol.h
78010+++ b/include/net/protocol.h
78011@@ -44,7 +44,7 @@ struct net_protocol {
78012 void (*err_handler)(struct sk_buff *skb, u32 info);
78013 unsigned int no_policy:1,
78014 netns_ok:1;
78015-};
78016+} __do_const;
78017
78018 #if IS_ENABLED(CONFIG_IPV6)
78019 struct inet6_protocol {
78020@@ -57,7 +57,7 @@ struct inet6_protocol {
78021 u8 type, u8 code, int offset,
78022 __be32 info);
78023 unsigned int flags; /* INET6_PROTO_xxx */
78024-};
78025+} __do_const;
78026
78027 #define INET6_PROTO_NOPOLICY 0x1
78028 #define INET6_PROTO_FINAL 0x2
78029diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78030index 7026648..584cc8c 100644
78031--- a/include/net/rtnetlink.h
78032+++ b/include/net/rtnetlink.h
78033@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78034 const struct net_device *dev);
78035 unsigned int (*get_num_tx_queues)(void);
78036 unsigned int (*get_num_rx_queues)(void);
78037-};
78038+} __do_const;
78039
78040 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78041 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78042diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78043index 2a82d13..62a31c2 100644
78044--- a/include/net/sctp/sm.h
78045+++ b/include/net/sctp/sm.h
78046@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78047 typedef struct {
78048 sctp_state_fn_t *fn;
78049 const char *name;
78050-} sctp_sm_table_entry_t;
78051+} __do_const sctp_sm_table_entry_t;
78052
78053 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78054 * currently in use.
78055@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78056 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78057
78058 /* Extern declarations for major data structures. */
78059-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78060+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78061
78062
78063 /* Get the size of a DATA chunk payload. */
78064diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78065index e745c92..3641448 100644
78066--- a/include/net/sctp/structs.h
78067+++ b/include/net/sctp/structs.h
78068@@ -516,7 +516,7 @@ struct sctp_pf {
78069 struct sctp_association *asoc);
78070 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78071 struct sctp_af *af;
78072-};
78073+} __do_const;
78074
78075
78076 /* Structure to track chunk fragments that have been acked, but peer
78077diff --git a/include/net/sock.h b/include/net/sock.h
78078index 31d5cfb..9ee0602 100644
78079--- a/include/net/sock.h
78080+++ b/include/net/sock.h
78081@@ -331,7 +331,7 @@ struct sock {
78082 unsigned int sk_napi_id;
78083 unsigned int sk_ll_usec;
78084 #endif
78085- atomic_t sk_drops;
78086+ atomic_unchecked_t sk_drops;
78087 int sk_rcvbuf;
78088
78089 struct sk_filter __rcu *sk_filter;
78090@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78091 }
78092
78093 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78094- char __user *from, char *to,
78095+ char __user *from, unsigned char *to,
78096 int copy, int offset)
78097 {
78098 if (skb->ip_summed == CHECKSUM_NONE) {
78099@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78100 }
78101 }
78102
78103-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78104+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78105
78106 /**
78107 * sk_page_frag - return an appropriate page_frag
78108diff --git a/include/net/tcp.h b/include/net/tcp.h
78109index d198005..c974a393 100644
78110--- a/include/net/tcp.h
78111+++ b/include/net/tcp.h
78112@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78113 extern void tcp_xmit_retransmit_queue(struct sock *);
78114 extern void tcp_simple_retransmit(struct sock *);
78115 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78116-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78117+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78118
78119 extern void tcp_send_probe0(struct sock *);
78120 extern void tcp_send_partial(struct sock *);
78121@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78122 struct inet6_skb_parm h6;
78123 #endif
78124 } header; /* For incoming frames */
78125- __u32 seq; /* Starting sequence number */
78126- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78127+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78128+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78129 __u32 when; /* used to compute rtt's */
78130 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78131
78132@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78133
78134 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78135 /* 1 byte hole */
78136- __u32 ack_seq; /* Sequence number ACK'd */
78137+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78138 };
78139
78140 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78141diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78142index e823786..53b0608 100644
78143--- a/include/net/xfrm.h
78144+++ b/include/net/xfrm.h
78145@@ -287,7 +287,6 @@ struct xfrm_dst;
78146 struct xfrm_policy_afinfo {
78147 unsigned short family;
78148 struct dst_ops *dst_ops;
78149- void (*garbage_collect)(struct net *net);
78150 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78151 const xfrm_address_t *saddr,
78152 const xfrm_address_t *daddr);
78153@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78154 struct net_device *dev,
78155 const struct flowi *fl);
78156 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78157-};
78158+} __do_const;
78159
78160 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78161 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78162@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78163 int (*transport_finish)(struct sk_buff *skb,
78164 int async);
78165 void (*local_error)(struct sk_buff *skb, u32 mtu);
78166-};
78167+} __do_const;
78168
78169 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78170 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78171@@ -427,7 +426,7 @@ struct xfrm_mode {
78172 struct module *owner;
78173 unsigned int encap;
78174 int flags;
78175-};
78176+} __do_const;
78177
78178 /* Flags for xfrm_mode. */
78179 enum {
78180@@ -524,7 +523,7 @@ struct xfrm_policy {
78181 struct timer_list timer;
78182
78183 struct flow_cache_object flo;
78184- atomic_t genid;
78185+ atomic_unchecked_t genid;
78186 u32 priority;
78187 u32 index;
78188 struct xfrm_mark mark;
78189@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78190 }
78191
78192 extern void xfrm_garbage_collect(struct net *net);
78193+extern void xfrm_garbage_collect_deferred(struct net *net);
78194
78195 #else
78196
78197@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78198 static inline void xfrm_garbage_collect(struct net *net)
78199 {
78200 }
78201+static inline void xfrm_garbage_collect_deferred(struct net *net)
78202+{
78203+}
78204 #endif
78205
78206 static __inline__
78207diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78208index 1a046b1..ee0bef0 100644
78209--- a/include/rdma/iw_cm.h
78210+++ b/include/rdma/iw_cm.h
78211@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78212 int backlog);
78213
78214 int (*destroy_listen)(struct iw_cm_id *cm_id);
78215-};
78216+} __no_const;
78217
78218 /**
78219 * iw_create_cm_id - Create an IW CM identifier.
78220diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78221index e1379b4..67eafbe 100644
78222--- a/include/scsi/libfc.h
78223+++ b/include/scsi/libfc.h
78224@@ -762,6 +762,7 @@ struct libfc_function_template {
78225 */
78226 void (*disc_stop_final) (struct fc_lport *);
78227 };
78228+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78229
78230 /**
78231 * struct fc_disc - Discovery context
78232@@ -866,7 +867,7 @@ struct fc_lport {
78233 struct fc_vport *vport;
78234
78235 /* Operational Information */
78236- struct libfc_function_template tt;
78237+ libfc_function_template_no_const tt;
78238 u8 link_up;
78239 u8 qfull;
78240 enum fc_lport_state state;
78241diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78242index a44954c..5da04b2 100644
78243--- a/include/scsi/scsi_device.h
78244+++ b/include/scsi/scsi_device.h
78245@@ -172,9 +172,9 @@ struct scsi_device {
78246 unsigned int max_device_blocked; /* what device_blocked counts down from */
78247 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78248
78249- atomic_t iorequest_cnt;
78250- atomic_t iodone_cnt;
78251- atomic_t ioerr_cnt;
78252+ atomic_unchecked_t iorequest_cnt;
78253+ atomic_unchecked_t iodone_cnt;
78254+ atomic_unchecked_t ioerr_cnt;
78255
78256 struct device sdev_gendev,
78257 sdev_dev;
78258diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78259index b797e8f..8e2c3aa 100644
78260--- a/include/scsi/scsi_transport_fc.h
78261+++ b/include/scsi/scsi_transport_fc.h
78262@@ -751,7 +751,8 @@ struct fc_function_template {
78263 unsigned long show_host_system_hostname:1;
78264
78265 unsigned long disable_target_scan:1;
78266-};
78267+} __do_const;
78268+typedef struct fc_function_template __no_const fc_function_template_no_const;
78269
78270
78271 /**
78272diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78273index 9031a26..750d592 100644
78274--- a/include/sound/compress_driver.h
78275+++ b/include/sound/compress_driver.h
78276@@ -128,7 +128,7 @@ struct snd_compr_ops {
78277 struct snd_compr_caps *caps);
78278 int (*get_codec_caps) (struct snd_compr_stream *stream,
78279 struct snd_compr_codec_caps *codec);
78280-};
78281+} __no_const;
78282
78283 /**
78284 * struct snd_compr: Compressed device
78285diff --git a/include/sound/soc.h b/include/sound/soc.h
78286index 6eabee7..58afb50 100644
78287--- a/include/sound/soc.h
78288+++ b/include/sound/soc.h
78289@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78290 /* probe ordering - for components with runtime dependencies */
78291 int probe_order;
78292 int remove_order;
78293-};
78294+} __do_const;
78295
78296 /* SoC platform interface */
78297 struct snd_soc_platform_driver {
78298@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78299 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78300 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78301 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78302-};
78303+} __do_const;
78304
78305 struct snd_soc_platform {
78306 const char *name;
78307diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78308index e34fc90..ecefa2c 100644
78309--- a/include/target/target_core_base.h
78310+++ b/include/target/target_core_base.h
78311@@ -643,7 +643,7 @@ struct se_device {
78312 spinlock_t stats_lock;
78313 /* Active commands on this virtual SE device */
78314 atomic_t simple_cmds;
78315- atomic_t dev_ordered_id;
78316+ atomic_unchecked_t dev_ordered_id;
78317 atomic_t dev_ordered_sync;
78318 atomic_t dev_qf_count;
78319 int export_count;
78320diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78321new file mode 100644
78322index 0000000..fb634b7
78323--- /dev/null
78324+++ b/include/trace/events/fs.h
78325@@ -0,0 +1,53 @@
78326+#undef TRACE_SYSTEM
78327+#define TRACE_SYSTEM fs
78328+
78329+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78330+#define _TRACE_FS_H
78331+
78332+#include <linux/fs.h>
78333+#include <linux/tracepoint.h>
78334+
78335+TRACE_EVENT(do_sys_open,
78336+
78337+ TP_PROTO(const char *filename, int flags, int mode),
78338+
78339+ TP_ARGS(filename, flags, mode),
78340+
78341+ TP_STRUCT__entry(
78342+ __string( filename, filename )
78343+ __field( int, flags )
78344+ __field( int, mode )
78345+ ),
78346+
78347+ TP_fast_assign(
78348+ __assign_str(filename, filename);
78349+ __entry->flags = flags;
78350+ __entry->mode = mode;
78351+ ),
78352+
78353+ TP_printk("\"%s\" %x %o",
78354+ __get_str(filename), __entry->flags, __entry->mode)
78355+);
78356+
78357+TRACE_EVENT(open_exec,
78358+
78359+ TP_PROTO(const char *filename),
78360+
78361+ TP_ARGS(filename),
78362+
78363+ TP_STRUCT__entry(
78364+ __string( filename, filename )
78365+ ),
78366+
78367+ TP_fast_assign(
78368+ __assign_str(filename, filename);
78369+ ),
78370+
78371+ TP_printk("\"%s\"",
78372+ __get_str(filename))
78373+);
78374+
78375+#endif /* _TRACE_FS_H */
78376+
78377+/* This part must be outside protection */
78378+#include <trace/define_trace.h>
78379diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78380index 1c09820..7f5ec79 100644
78381--- a/include/trace/events/irq.h
78382+++ b/include/trace/events/irq.h
78383@@ -36,7 +36,7 @@ struct softirq_action;
78384 */
78385 TRACE_EVENT(irq_handler_entry,
78386
78387- TP_PROTO(int irq, struct irqaction *action),
78388+ TP_PROTO(int irq, const struct irqaction *action),
78389
78390 TP_ARGS(irq, action),
78391
78392@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78393 */
78394 TRACE_EVENT(irq_handler_exit,
78395
78396- TP_PROTO(int irq, struct irqaction *action, int ret),
78397+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78398
78399 TP_ARGS(irq, action, ret),
78400
78401diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78402index 7caf44c..23c6f27 100644
78403--- a/include/uapi/linux/a.out.h
78404+++ b/include/uapi/linux/a.out.h
78405@@ -39,6 +39,14 @@ enum machine_type {
78406 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78407 };
78408
78409+/* Constants for the N_FLAGS field */
78410+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78411+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78412+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78413+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78414+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78415+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78416+
78417 #if !defined (N_MAGIC)
78418 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78419 #endif
78420diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78421index d876736..ccce5c0 100644
78422--- a/include/uapi/linux/byteorder/little_endian.h
78423+++ b/include/uapi/linux/byteorder/little_endian.h
78424@@ -42,51 +42,51 @@
78425
78426 static inline __le64 __cpu_to_le64p(const __u64 *p)
78427 {
78428- return (__force __le64)*p;
78429+ return (__force const __le64)*p;
78430 }
78431-static inline __u64 __le64_to_cpup(const __le64 *p)
78432+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78433 {
78434- return (__force __u64)*p;
78435+ return (__force const __u64)*p;
78436 }
78437 static inline __le32 __cpu_to_le32p(const __u32 *p)
78438 {
78439- return (__force __le32)*p;
78440+ return (__force const __le32)*p;
78441 }
78442 static inline __u32 __le32_to_cpup(const __le32 *p)
78443 {
78444- return (__force __u32)*p;
78445+ return (__force const __u32)*p;
78446 }
78447 static inline __le16 __cpu_to_le16p(const __u16 *p)
78448 {
78449- return (__force __le16)*p;
78450+ return (__force const __le16)*p;
78451 }
78452 static inline __u16 __le16_to_cpup(const __le16 *p)
78453 {
78454- return (__force __u16)*p;
78455+ return (__force const __u16)*p;
78456 }
78457 static inline __be64 __cpu_to_be64p(const __u64 *p)
78458 {
78459- return (__force __be64)__swab64p(p);
78460+ return (__force const __be64)__swab64p(p);
78461 }
78462 static inline __u64 __be64_to_cpup(const __be64 *p)
78463 {
78464- return __swab64p((__u64 *)p);
78465+ return __swab64p((const __u64 *)p);
78466 }
78467 static inline __be32 __cpu_to_be32p(const __u32 *p)
78468 {
78469- return (__force __be32)__swab32p(p);
78470+ return (__force const __be32)__swab32p(p);
78471 }
78472-static inline __u32 __be32_to_cpup(const __be32 *p)
78473+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78474 {
78475- return __swab32p((__u32 *)p);
78476+ return __swab32p((const __u32 *)p);
78477 }
78478 static inline __be16 __cpu_to_be16p(const __u16 *p)
78479 {
78480- return (__force __be16)__swab16p(p);
78481+ return (__force const __be16)__swab16p(p);
78482 }
78483 static inline __u16 __be16_to_cpup(const __be16 *p)
78484 {
78485- return __swab16p((__u16 *)p);
78486+ return __swab16p((const __u16 *)p);
78487 }
78488 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78489 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78490diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78491index ef6103b..d4e65dd 100644
78492--- a/include/uapi/linux/elf.h
78493+++ b/include/uapi/linux/elf.h
78494@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78495 #define PT_GNU_EH_FRAME 0x6474e550
78496
78497 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78498+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78499+
78500+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78501+
78502+/* Constants for the e_flags field */
78503+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78504+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78505+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78506+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78507+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78508+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78509
78510 /*
78511 * Extended Numbering
78512@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78513 #define DT_DEBUG 21
78514 #define DT_TEXTREL 22
78515 #define DT_JMPREL 23
78516+#define DT_FLAGS 30
78517+ #define DF_TEXTREL 0x00000004
78518 #define DT_ENCODING 32
78519 #define OLD_DT_LOOS 0x60000000
78520 #define DT_LOOS 0x6000000d
78521@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78522 #define PF_W 0x2
78523 #define PF_X 0x1
78524
78525+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78526+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78527+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78528+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78529+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78530+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78531+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78532+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78533+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78534+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78535+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78536+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78537+
78538 typedef struct elf32_phdr{
78539 Elf32_Word p_type;
78540 Elf32_Off p_offset;
78541@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78542 #define EI_OSABI 7
78543 #define EI_PAD 8
78544
78545+#define EI_PAX 14
78546+
78547 #define ELFMAG0 0x7f /* EI_MAG */
78548 #define ELFMAG1 'E'
78549 #define ELFMAG2 'L'
78550diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78551index aa169c4..6a2771d 100644
78552--- a/include/uapi/linux/personality.h
78553+++ b/include/uapi/linux/personality.h
78554@@ -30,6 +30,7 @@ enum {
78555 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78556 ADDR_NO_RANDOMIZE | \
78557 ADDR_COMPAT_LAYOUT | \
78558+ ADDR_LIMIT_3GB | \
78559 MMAP_PAGE_ZERO)
78560
78561 /*
78562diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78563index 7530e74..e714828 100644
78564--- a/include/uapi/linux/screen_info.h
78565+++ b/include/uapi/linux/screen_info.h
78566@@ -43,7 +43,8 @@ struct screen_info {
78567 __u16 pages; /* 0x32 */
78568 __u16 vesa_attributes; /* 0x34 */
78569 __u32 capabilities; /* 0x36 */
78570- __u8 _reserved[6]; /* 0x3a */
78571+ __u16 vesapm_size; /* 0x3a */
78572+ __u8 _reserved[4]; /* 0x3c */
78573 } __attribute__((packed));
78574
78575 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78576diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78577index 0e011eb..82681b1 100644
78578--- a/include/uapi/linux/swab.h
78579+++ b/include/uapi/linux/swab.h
78580@@ -43,7 +43,7 @@
78581 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78582 */
78583
78584-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78585+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78586 {
78587 #ifdef __HAVE_BUILTIN_BSWAP16__
78588 return __builtin_bswap16(val);
78589@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78590 #endif
78591 }
78592
78593-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78594+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78595 {
78596 #ifdef __HAVE_BUILTIN_BSWAP32__
78597 return __builtin_bswap32(val);
78598@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78599 #endif
78600 }
78601
78602-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78603+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78604 {
78605 #ifdef __HAVE_BUILTIN_BSWAP64__
78606 return __builtin_bswap64(val);
78607diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78608index 6d67213..8dab561 100644
78609--- a/include/uapi/linux/sysctl.h
78610+++ b/include/uapi/linux/sysctl.h
78611@@ -155,7 +155,11 @@ enum
78612 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78613 };
78614
78615-
78616+#ifdef CONFIG_PAX_SOFTMODE
78617+enum {
78618+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78619+};
78620+#endif
78621
78622 /* CTL_VM names: */
78623 enum
78624diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78625index e4629b9..6958086 100644
78626--- a/include/uapi/linux/xattr.h
78627+++ b/include/uapi/linux/xattr.h
78628@@ -63,5 +63,9 @@
78629 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78630 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78631
78632+/* User namespace */
78633+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78634+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78635+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78636
78637 #endif /* _UAPI_LINUX_XATTR_H */
78638diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78639index f9466fa..f4e2b81 100644
78640--- a/include/video/udlfb.h
78641+++ b/include/video/udlfb.h
78642@@ -53,10 +53,10 @@ struct dlfb_data {
78643 u32 pseudo_palette[256];
78644 int blank_mode; /*one of FB_BLANK_ */
78645 /* blit-only rendering path metrics, exposed through sysfs */
78646- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78647- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78648- atomic_t bytes_sent; /* to usb, after compression including overhead */
78649- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78650+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78651+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78652+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78653+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78654 };
78655
78656 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78657diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78658index 30f5362..8ed8ac9 100644
78659--- a/include/video/uvesafb.h
78660+++ b/include/video/uvesafb.h
78661@@ -122,6 +122,7 @@ struct uvesafb_par {
78662 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78663 u8 pmi_setpal; /* PMI for palette changes */
78664 u16 *pmi_base; /* protected mode interface location */
78665+ u8 *pmi_code; /* protected mode code location */
78666 void *pmi_start;
78667 void *pmi_pal;
78668 u8 *vbe_state_orig; /*
78669diff --git a/init/Kconfig b/init/Kconfig
78670index fed81b5..0d3b964 100644
78671--- a/init/Kconfig
78672+++ b/init/Kconfig
78673@@ -1069,6 +1069,7 @@ endif # CGROUPS
78674
78675 config CHECKPOINT_RESTORE
78676 bool "Checkpoint/restore support" if EXPERT
78677+ depends on !GRKERNSEC
78678 default n
78679 help
78680 Enables additional kernel features in a sake of checkpoint/restore.
78681@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78682
78683 config COMPAT_BRK
78684 bool "Disable heap randomization"
78685- default y
78686+ default n
78687 help
78688 Randomizing heap placement makes heap exploits harder, but it
78689 also breaks ancient binaries (including anything libc5 based).
78690@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78691 config STOP_MACHINE
78692 bool
78693 default y
78694- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78695+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78696 help
78697 Need stop_machine() primitive.
78698
78699diff --git a/init/Makefile b/init/Makefile
78700index 7bc47ee..6da2dc7 100644
78701--- a/init/Makefile
78702+++ b/init/Makefile
78703@@ -2,6 +2,9 @@
78704 # Makefile for the linux kernel.
78705 #
78706
78707+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78708+asflags-y := $(GCC_PLUGINS_AFLAGS)
78709+
78710 obj-y := main.o version.o mounts.o
78711 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78712 obj-y += noinitramfs.o
78713diff --git a/init/do_mounts.c b/init/do_mounts.c
78714index 816014c..c2054db 100644
78715--- a/init/do_mounts.c
78716+++ b/init/do_mounts.c
78717@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78718 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78719 {
78720 struct super_block *s;
78721- int err = sys_mount(name, "/root", fs, flags, data);
78722+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78723 if (err)
78724 return err;
78725
78726- sys_chdir("/root");
78727+ sys_chdir((const char __force_user *)"/root");
78728 s = current->fs->pwd.dentry->d_sb;
78729 ROOT_DEV = s->s_dev;
78730 printk(KERN_INFO
78731@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78732 va_start(args, fmt);
78733 vsprintf(buf, fmt, args);
78734 va_end(args);
78735- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78736+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78737 if (fd >= 0) {
78738 sys_ioctl(fd, FDEJECT, 0);
78739 sys_close(fd);
78740 }
78741 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78742- fd = sys_open("/dev/console", O_RDWR, 0);
78743+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78744 if (fd >= 0) {
78745 sys_ioctl(fd, TCGETS, (long)&termios);
78746 termios.c_lflag &= ~ICANON;
78747 sys_ioctl(fd, TCSETSF, (long)&termios);
78748- sys_read(fd, &c, 1);
78749+ sys_read(fd, (char __user *)&c, 1);
78750 termios.c_lflag |= ICANON;
78751 sys_ioctl(fd, TCSETSF, (long)&termios);
78752 sys_close(fd);
78753@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78754 mount_root();
78755 out:
78756 devtmpfs_mount("dev");
78757- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78758- sys_chroot(".");
78759+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78760+ sys_chroot((const char __force_user *)".");
78761 }
78762diff --git a/init/do_mounts.h b/init/do_mounts.h
78763index f5b978a..69dbfe8 100644
78764--- a/init/do_mounts.h
78765+++ b/init/do_mounts.h
78766@@ -15,15 +15,15 @@ extern int root_mountflags;
78767
78768 static inline int create_dev(char *name, dev_t dev)
78769 {
78770- sys_unlink(name);
78771- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78772+ sys_unlink((char __force_user *)name);
78773+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78774 }
78775
78776 #if BITS_PER_LONG == 32
78777 static inline u32 bstat(char *name)
78778 {
78779 struct stat64 stat;
78780- if (sys_stat64(name, &stat) != 0)
78781+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78782 return 0;
78783 if (!S_ISBLK(stat.st_mode))
78784 return 0;
78785@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78786 static inline u32 bstat(char *name)
78787 {
78788 struct stat stat;
78789- if (sys_newstat(name, &stat) != 0)
78790+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78791 return 0;
78792 if (!S_ISBLK(stat.st_mode))
78793 return 0;
78794diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78795index 3e0878e..8a9d7a0 100644
78796--- a/init/do_mounts_initrd.c
78797+++ b/init/do_mounts_initrd.c
78798@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78799 {
78800 sys_unshare(CLONE_FS | CLONE_FILES);
78801 /* stdin/stdout/stderr for /linuxrc */
78802- sys_open("/dev/console", O_RDWR, 0);
78803+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78804 sys_dup(0);
78805 sys_dup(0);
78806 /* move initrd over / and chdir/chroot in initrd root */
78807- sys_chdir("/root");
78808- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78809- sys_chroot(".");
78810+ sys_chdir((const char __force_user *)"/root");
78811+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78812+ sys_chroot((const char __force_user *)".");
78813 sys_setsid();
78814 return 0;
78815 }
78816@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78817 create_dev("/dev/root.old", Root_RAM0);
78818 /* mount initrd on rootfs' /root */
78819 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78820- sys_mkdir("/old", 0700);
78821- sys_chdir("/old");
78822+ sys_mkdir((const char __force_user *)"/old", 0700);
78823+ sys_chdir((const char __force_user *)"/old");
78824
78825 /* try loading default modules from initrd */
78826 load_default_modules();
78827@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78828 current->flags &= ~PF_FREEZER_SKIP;
78829
78830 /* move initrd to rootfs' /old */
78831- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78832+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78833 /* switch root and cwd back to / of rootfs */
78834- sys_chroot("..");
78835+ sys_chroot((const char __force_user *)"..");
78836
78837 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78838- sys_chdir("/old");
78839+ sys_chdir((const char __force_user *)"/old");
78840 return;
78841 }
78842
78843- sys_chdir("/");
78844+ sys_chdir((const char __force_user *)"/");
78845 ROOT_DEV = new_decode_dev(real_root_dev);
78846 mount_root();
78847
78848 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78849- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78850+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78851 if (!error)
78852 printk("okay\n");
78853 else {
78854- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78855+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78856 if (error == -ENOENT)
78857 printk("/initrd does not exist. Ignored.\n");
78858 else
78859 printk("failed\n");
78860 printk(KERN_NOTICE "Unmounting old root\n");
78861- sys_umount("/old", MNT_DETACH);
78862+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78863 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78864 if (fd < 0) {
78865 error = fd;
78866@@ -127,11 +127,11 @@ int __init initrd_load(void)
78867 * mounted in the normal path.
78868 */
78869 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78870- sys_unlink("/initrd.image");
78871+ sys_unlink((const char __force_user *)"/initrd.image");
78872 handle_initrd();
78873 return 1;
78874 }
78875 }
78876- sys_unlink("/initrd.image");
78877+ sys_unlink((const char __force_user *)"/initrd.image");
78878 return 0;
78879 }
78880diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78881index 8cb6db5..d729f50 100644
78882--- a/init/do_mounts_md.c
78883+++ b/init/do_mounts_md.c
78884@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78885 partitioned ? "_d" : "", minor,
78886 md_setup_args[ent].device_names);
78887
78888- fd = sys_open(name, 0, 0);
78889+ fd = sys_open((char __force_user *)name, 0, 0);
78890 if (fd < 0) {
78891 printk(KERN_ERR "md: open failed - cannot start "
78892 "array %s\n", name);
78893@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78894 * array without it
78895 */
78896 sys_close(fd);
78897- fd = sys_open(name, 0, 0);
78898+ fd = sys_open((char __force_user *)name, 0, 0);
78899 sys_ioctl(fd, BLKRRPART, 0);
78900 }
78901 sys_close(fd);
78902@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78903
78904 wait_for_device_probe();
78905
78906- fd = sys_open("/dev/md0", 0, 0);
78907+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78908 if (fd >= 0) {
78909 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78910 sys_close(fd);
78911diff --git a/init/init_task.c b/init/init_task.c
78912index ba0a7f36..2bcf1d5 100644
78913--- a/init/init_task.c
78914+++ b/init/init_task.c
78915@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78916 * Initial thread structure. Alignment of this is handled by a special
78917 * linker map entry.
78918 */
78919+#ifdef CONFIG_X86
78920+union thread_union init_thread_union __init_task_data;
78921+#else
78922 union thread_union init_thread_union __init_task_data =
78923 { INIT_THREAD_INFO(init_task) };
78924+#endif
78925diff --git a/init/initramfs.c b/init/initramfs.c
78926index a67ef9d..2d17ed9 100644
78927--- a/init/initramfs.c
78928+++ b/init/initramfs.c
78929@@ -84,7 +84,7 @@ static void __init free_hash(void)
78930 }
78931 }
78932
78933-static long __init do_utime(char *filename, time_t mtime)
78934+static long __init do_utime(char __force_user *filename, time_t mtime)
78935 {
78936 struct timespec t[2];
78937
78938@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78939 struct dir_entry *de, *tmp;
78940 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78941 list_del(&de->list);
78942- do_utime(de->name, de->mtime);
78943+ do_utime((char __force_user *)de->name, de->mtime);
78944 kfree(de->name);
78945 kfree(de);
78946 }
78947@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78948 if (nlink >= 2) {
78949 char *old = find_link(major, minor, ino, mode, collected);
78950 if (old)
78951- return (sys_link(old, collected) < 0) ? -1 : 1;
78952+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78953 }
78954 return 0;
78955 }
78956@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78957 {
78958 struct stat st;
78959
78960- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78961+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78962 if (S_ISDIR(st.st_mode))
78963- sys_rmdir(path);
78964+ sys_rmdir((char __force_user *)path);
78965 else
78966- sys_unlink(path);
78967+ sys_unlink((char __force_user *)path);
78968 }
78969 }
78970
78971@@ -315,7 +315,7 @@ static int __init do_name(void)
78972 int openflags = O_WRONLY|O_CREAT;
78973 if (ml != 1)
78974 openflags |= O_TRUNC;
78975- wfd = sys_open(collected, openflags, mode);
78976+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78977
78978 if (wfd >= 0) {
78979 sys_fchown(wfd, uid, gid);
78980@@ -327,17 +327,17 @@ static int __init do_name(void)
78981 }
78982 }
78983 } else if (S_ISDIR(mode)) {
78984- sys_mkdir(collected, mode);
78985- sys_chown(collected, uid, gid);
78986- sys_chmod(collected, mode);
78987+ sys_mkdir((char __force_user *)collected, mode);
78988+ sys_chown((char __force_user *)collected, uid, gid);
78989+ sys_chmod((char __force_user *)collected, mode);
78990 dir_add(collected, mtime);
78991 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78992 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78993 if (maybe_link() == 0) {
78994- sys_mknod(collected, mode, rdev);
78995- sys_chown(collected, uid, gid);
78996- sys_chmod(collected, mode);
78997- do_utime(collected, mtime);
78998+ sys_mknod((char __force_user *)collected, mode, rdev);
78999+ sys_chown((char __force_user *)collected, uid, gid);
79000+ sys_chmod((char __force_user *)collected, mode);
79001+ do_utime((char __force_user *)collected, mtime);
79002 }
79003 }
79004 return 0;
79005@@ -346,15 +346,15 @@ static int __init do_name(void)
79006 static int __init do_copy(void)
79007 {
79008 if (count >= body_len) {
79009- sys_write(wfd, victim, body_len);
79010+ sys_write(wfd, (char __force_user *)victim, body_len);
79011 sys_close(wfd);
79012- do_utime(vcollected, mtime);
79013+ do_utime((char __force_user *)vcollected, mtime);
79014 kfree(vcollected);
79015 eat(body_len);
79016 state = SkipIt;
79017 return 0;
79018 } else {
79019- sys_write(wfd, victim, count);
79020+ sys_write(wfd, (char __force_user *)victim, count);
79021 body_len -= count;
79022 eat(count);
79023 return 1;
79024@@ -365,9 +365,9 @@ static int __init do_symlink(void)
79025 {
79026 collected[N_ALIGN(name_len) + body_len] = '\0';
79027 clean_path(collected, 0);
79028- sys_symlink(collected + N_ALIGN(name_len), collected);
79029- sys_lchown(collected, uid, gid);
79030- do_utime(collected, mtime);
79031+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79032+ sys_lchown((char __force_user *)collected, uid, gid);
79033+ do_utime((char __force_user *)collected, mtime);
79034 state = SkipIt;
79035 next_state = Reset;
79036 return 0;
79037@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79038 {
79039 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79040 if (err)
79041- panic(err); /* Failed to decompress INTERNAL initramfs */
79042+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79043 if (initrd_start) {
79044 #ifdef CONFIG_BLK_DEV_RAM
79045 int fd;
79046diff --git a/init/main.c b/init/main.c
79047index 586cd33..f1af30f 100644
79048--- a/init/main.c
79049+++ b/init/main.c
79050@@ -102,6 +102,8 @@ static inline void mark_rodata_ro(void) { }
79051 extern void tc_init(void);
79052 #endif
79053
79054+extern void grsecurity_init(void);
79055+
79056 /*
79057 * Debug helper: via this flag we know that we are in 'early bootup code'
79058 * where only the boot processor is running with IRQ disabled. This means
79059@@ -155,6 +157,74 @@ static int __init set_reset_devices(char *str)
79060
79061 __setup("reset_devices", set_reset_devices);
79062
79063+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79064+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79065+static int __init setup_grsec_proc_gid(char *str)
79066+{
79067+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79068+ return 1;
79069+}
79070+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79071+#endif
79072+
79073+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79074+unsigned long pax_user_shadow_base __read_only;
79075+EXPORT_SYMBOL(pax_user_shadow_base);
79076+extern char pax_enter_kernel_user[];
79077+extern char pax_exit_kernel_user[];
79078+#endif
79079+
79080+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79081+static int __init setup_pax_nouderef(char *str)
79082+{
79083+#ifdef CONFIG_X86_32
79084+ unsigned int cpu;
79085+ struct desc_struct *gdt;
79086+
79087+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79088+ gdt = get_cpu_gdt_table(cpu);
79089+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79090+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79091+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79092+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79093+ }
79094+ loadsegment(ds, __KERNEL_DS);
79095+ loadsegment(es, __KERNEL_DS);
79096+ loadsegment(ss, __KERNEL_DS);
79097+#else
79098+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79099+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79100+ clone_pgd_mask = ~(pgdval_t)0UL;
79101+ pax_user_shadow_base = 0UL;
79102+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79103+#endif
79104+
79105+ return 0;
79106+}
79107+early_param("pax_nouderef", setup_pax_nouderef);
79108+
79109+#ifdef CONFIG_X86_64
79110+static int __init setup_pax_weakuderef(char *str)
79111+{
79112+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79113+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79114+ return 1;
79115+}
79116+__setup("pax_weakuderef", setup_pax_weakuderef);
79117+#endif
79118+#endif
79119+
79120+#ifdef CONFIG_PAX_SOFTMODE
79121+int pax_softmode;
79122+
79123+static int __init setup_pax_softmode(char *str)
79124+{
79125+ get_option(&str, &pax_softmode);
79126+ return 1;
79127+}
79128+__setup("pax_softmode=", setup_pax_softmode);
79129+#endif
79130+
79131 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79132 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79133 static const char *panic_later, *panic_param;
79134@@ -680,25 +750,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79135 {
79136 int count = preempt_count();
79137 int ret;
79138- char msgbuf[64];
79139+ const char *msg1 = "", *msg2 = "";
79140
79141 if (initcall_debug)
79142 ret = do_one_initcall_debug(fn);
79143 else
79144 ret = fn();
79145
79146- msgbuf[0] = 0;
79147-
79148 if (preempt_count() != count) {
79149- sprintf(msgbuf, "preemption imbalance ");
79150+ msg1 = " preemption imbalance";
79151 preempt_count() = count;
79152 }
79153 if (irqs_disabled()) {
79154- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79155+ msg2 = " disabled interrupts";
79156 local_irq_enable();
79157 }
79158- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79159+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79160
79161+ add_latent_entropy();
79162 return ret;
79163 }
79164
79165@@ -805,8 +874,8 @@ static int run_init_process(const char *init_filename)
79166 {
79167 argv_init[0] = init_filename;
79168 return do_execve(init_filename,
79169- (const char __user *const __user *)argv_init,
79170- (const char __user *const __user *)envp_init);
79171+ (const char __user *const __force_user *)argv_init,
79172+ (const char __user *const __force_user *)envp_init);
79173 }
79174
79175 static noinline void __init kernel_init_freeable(void);
79176@@ -883,7 +952,7 @@ static noinline void __init kernel_init_freeable(void)
79177 do_basic_setup();
79178
79179 /* Open the /dev/console on the rootfs, this should never fail */
79180- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79181+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79182 pr_err("Warning: unable to open an initial console.\n");
79183
79184 (void) sys_dup(0);
79185@@ -896,11 +965,13 @@ static noinline void __init kernel_init_freeable(void)
79186 if (!ramdisk_execute_command)
79187 ramdisk_execute_command = "/init";
79188
79189- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79190+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79191 ramdisk_execute_command = NULL;
79192 prepare_namespace();
79193 }
79194
79195+ grsecurity_init();
79196+
79197 /*
79198 * Ok, we have completed the initial bootup, and
79199 * we're essentially up and running. Get rid of the
79200diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79201index 130dfec..cc88451 100644
79202--- a/ipc/ipc_sysctl.c
79203+++ b/ipc/ipc_sysctl.c
79204@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79205 static int proc_ipc_dointvec(ctl_table *table, int write,
79206 void __user *buffer, size_t *lenp, loff_t *ppos)
79207 {
79208- struct ctl_table ipc_table;
79209+ ctl_table_no_const ipc_table;
79210
79211 memcpy(&ipc_table, table, sizeof(ipc_table));
79212 ipc_table.data = get_ipc(table);
79213@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79214 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79215 void __user *buffer, size_t *lenp, loff_t *ppos)
79216 {
79217- struct ctl_table ipc_table;
79218+ ctl_table_no_const ipc_table;
79219
79220 memcpy(&ipc_table, table, sizeof(ipc_table));
79221 ipc_table.data = get_ipc(table);
79222@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79223 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79224 void __user *buffer, size_t *lenp, loff_t *ppos)
79225 {
79226- struct ctl_table ipc_table;
79227+ ctl_table_no_const ipc_table;
79228 size_t lenp_bef = *lenp;
79229 int rc;
79230
79231@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79232 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79233 void __user *buffer, size_t *lenp, loff_t *ppos)
79234 {
79235- struct ctl_table ipc_table;
79236+ ctl_table_no_const ipc_table;
79237 memcpy(&ipc_table, table, sizeof(ipc_table));
79238 ipc_table.data = get_ipc(table);
79239
79240@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79241 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79242 void __user *buffer, size_t *lenp, loff_t *ppos)
79243 {
79244- struct ctl_table ipc_table;
79245+ ctl_table_no_const ipc_table;
79246 size_t lenp_bef = *lenp;
79247 int oldval;
79248 int rc;
79249diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79250index 383d638..943fdbb 100644
79251--- a/ipc/mq_sysctl.c
79252+++ b/ipc/mq_sysctl.c
79253@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79254 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79255 void __user *buffer, size_t *lenp, loff_t *ppos)
79256 {
79257- struct ctl_table mq_table;
79258+ ctl_table_no_const mq_table;
79259 memcpy(&mq_table, table, sizeof(mq_table));
79260 mq_table.data = get_mq(table);
79261
79262diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79263index ae1996d..a35f2cc 100644
79264--- a/ipc/mqueue.c
79265+++ b/ipc/mqueue.c
79266@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79267 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79268 info->attr.mq_msgsize);
79269
79270+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79271 spin_lock(&mq_lock);
79272 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79273 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79274diff --git a/ipc/msg.c b/ipc/msg.c
79275index 558aa91..359e718 100644
79276--- a/ipc/msg.c
79277+++ b/ipc/msg.c
79278@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79279 return security_msg_queue_associate(msq, msgflg);
79280 }
79281
79282+static struct ipc_ops msg_ops = {
79283+ .getnew = newque,
79284+ .associate = msg_security,
79285+ .more_checks = NULL
79286+};
79287+
79288 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79289 {
79290 struct ipc_namespace *ns;
79291- struct ipc_ops msg_ops;
79292 struct ipc_params msg_params;
79293
79294 ns = current->nsproxy->ipc_ns;
79295
79296- msg_ops.getnew = newque;
79297- msg_ops.associate = msg_security;
79298- msg_ops.more_checks = NULL;
79299-
79300 msg_params.key = key;
79301 msg_params.flg = msgflg;
79302
79303diff --git a/ipc/sem.c b/ipc/sem.c
79304index 8e2bf30..a711151 100644
79305--- a/ipc/sem.c
79306+++ b/ipc/sem.c
79307@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79308 return 0;
79309 }
79310
79311+static struct ipc_ops sem_ops = {
79312+ .getnew = newary,
79313+ .associate = sem_security,
79314+ .more_checks = sem_more_checks
79315+};
79316+
79317 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79318 {
79319 struct ipc_namespace *ns;
79320- struct ipc_ops sem_ops;
79321 struct ipc_params sem_params;
79322
79323 ns = current->nsproxy->ipc_ns;
79324@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79325 if (nsems < 0 || nsems > ns->sc_semmsl)
79326 return -EINVAL;
79327
79328- sem_ops.getnew = newary;
79329- sem_ops.associate = sem_security;
79330- sem_ops.more_checks = sem_more_checks;
79331-
79332 sem_params.key = key;
79333 sem_params.flg = semflg;
79334 sem_params.u.nsems = nsems;
79335diff --git a/ipc/shm.c b/ipc/shm.c
79336index d697396..40e887d 100644
79337--- a/ipc/shm.c
79338+++ b/ipc/shm.c
79339@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79340 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79341 #endif
79342
79343+#ifdef CONFIG_GRKERNSEC
79344+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79345+ const time_t shm_createtime, const kuid_t cuid,
79346+ const int shmid);
79347+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79348+ const time_t shm_createtime);
79349+#endif
79350+
79351 void shm_init_ns(struct ipc_namespace *ns)
79352 {
79353 ns->shm_ctlmax = SHMMAX;
79354@@ -551,6 +559,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79355 shp->shm_lprid = 0;
79356 shp->shm_atim = shp->shm_dtim = 0;
79357 shp->shm_ctim = get_seconds();
79358+#ifdef CONFIG_GRKERNSEC
79359+ {
79360+ struct timespec timeval;
79361+ do_posix_clock_monotonic_gettime(&timeval);
79362+
79363+ shp->shm_createtime = timeval.tv_sec;
79364+ }
79365+#endif
79366 shp->shm_segsz = size;
79367 shp->shm_nattch = 0;
79368 shp->shm_file = file;
79369@@ -604,18 +620,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79370 return 0;
79371 }
79372
79373+static struct ipc_ops shm_ops = {
79374+ .getnew = newseg,
79375+ .associate = shm_security,
79376+ .more_checks = shm_more_checks
79377+};
79378+
79379 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79380 {
79381 struct ipc_namespace *ns;
79382- struct ipc_ops shm_ops;
79383 struct ipc_params shm_params;
79384
79385 ns = current->nsproxy->ipc_ns;
79386
79387- shm_ops.getnew = newseg;
79388- shm_ops.associate = shm_security;
79389- shm_ops.more_checks = shm_more_checks;
79390-
79391 shm_params.key = key;
79392 shm_params.flg = shmflg;
79393 shm_params.u.size = size;
79394@@ -1076,6 +1093,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79395 f_mode = FMODE_READ | FMODE_WRITE;
79396 }
79397 if (shmflg & SHM_EXEC) {
79398+
79399+#ifdef CONFIG_PAX_MPROTECT
79400+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79401+ goto out;
79402+#endif
79403+
79404 prot |= PROT_EXEC;
79405 acc_mode |= S_IXUGO;
79406 }
79407@@ -1100,10 +1123,22 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79408 if (err)
79409 goto out_unlock;
79410
79411+#ifdef CONFIG_GRKERNSEC
79412+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79413+ shp->shm_perm.cuid, shmid) ||
79414+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79415+ err = -EACCES;
79416+ goto out_unlock;
79417+ }
79418+#endif
79419+
79420 ipc_lock_object(&shp->shm_perm);
79421 path = shp->shm_file->f_path;
79422 path_get(&path);
79423 shp->shm_nattch++;
79424+#ifdef CONFIG_GRKERNSEC
79425+ shp->shm_lapid = current->pid;
79426+#endif
79427 size = i_size_read(path.dentry->d_inode);
79428 ipc_unlock_object(&shp->shm_perm);
79429 rcu_read_unlock();
79430diff --git a/kernel/acct.c b/kernel/acct.c
79431index 8d6e145..33e0b1e 100644
79432--- a/kernel/acct.c
79433+++ b/kernel/acct.c
79434@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79435 */
79436 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79437 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79438- file->f_op->write(file, (char *)&ac,
79439+ file->f_op->write(file, (char __force_user *)&ac,
79440 sizeof(acct_t), &file->f_pos);
79441 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79442 set_fs(fs);
79443diff --git a/kernel/audit.c b/kernel/audit.c
79444index 7b0e23a..5b27ab9 100644
79445--- a/kernel/audit.c
79446+++ b/kernel/audit.c
79447@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79448 3) suppressed due to audit_rate_limit
79449 4) suppressed due to audit_backlog_limit
79450 */
79451-static atomic_t audit_lost = ATOMIC_INIT(0);
79452+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79453
79454 /* The netlink socket. */
79455 static struct sock *audit_sock;
79456@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79457 unsigned long now;
79458 int print;
79459
79460- atomic_inc(&audit_lost);
79461+ atomic_inc_unchecked(&audit_lost);
79462
79463 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79464
79465@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79466 printk(KERN_WARNING
79467 "audit: audit_lost=%d audit_rate_limit=%d "
79468 "audit_backlog_limit=%d\n",
79469- atomic_read(&audit_lost),
79470+ atomic_read_unchecked(&audit_lost),
79471 audit_rate_limit,
79472 audit_backlog_limit);
79473 audit_panic(message);
79474@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79475
79476 switch (msg_type) {
79477 case AUDIT_GET:
79478+ status_set.mask = 0;
79479 status_set.enabled = audit_enabled;
79480 status_set.failure = audit_failure;
79481 status_set.pid = audit_pid;
79482 status_set.rate_limit = audit_rate_limit;
79483 status_set.backlog_limit = audit_backlog_limit;
79484- status_set.lost = atomic_read(&audit_lost);
79485+ status_set.lost = atomic_read_unchecked(&audit_lost);
79486 status_set.backlog = skb_queue_len(&audit_skb_queue);
79487 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79488 &status_set, sizeof(status_set));
79489 break;
79490 case AUDIT_SET:
79491- if (nlh->nlmsg_len < sizeof(struct audit_status))
79492+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
79493 return -EINVAL;
79494 status_get = (struct audit_status *)data;
79495 if (status_get->mask & AUDIT_STATUS_ENABLED) {
79496@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79497
79498 memset(&s, 0, sizeof(s));
79499 /* guard against past and future API changes */
79500- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
79501+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
79502 if ((s.enabled != 0 && s.enabled != 1) ||
79503 (s.log_passwd != 0 && s.log_passwd != 1))
79504 return -EINVAL;
79505diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79506index 9845cb3..3ec9369 100644
79507--- a/kernel/auditsc.c
79508+++ b/kernel/auditsc.c
79509@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79510 }
79511
79512 /* global counter which is incremented every time something logs in */
79513-static atomic_t session_id = ATOMIC_INIT(0);
79514+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79515
79516 /**
79517 * audit_set_loginuid - set current task's audit_context loginuid
79518@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79519 return -EPERM;
79520 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79521
79522- sessionid = atomic_inc_return(&session_id);
79523+ sessionid = atomic_inc_return_unchecked(&session_id);
79524 if (context && context->in_syscall) {
79525 struct audit_buffer *ab;
79526
79527diff --git a/kernel/capability.c b/kernel/capability.c
79528index f6c2ce5..982c0f9 100644
79529--- a/kernel/capability.c
79530+++ b/kernel/capability.c
79531@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79532 * before modification is attempted and the application
79533 * fails.
79534 */
79535+ if (tocopy > ARRAY_SIZE(kdata))
79536+ return -EFAULT;
79537+
79538 if (copy_to_user(dataptr, kdata, tocopy
79539 * sizeof(struct __user_cap_data_struct))) {
79540 return -EFAULT;
79541@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79542 int ret;
79543
79544 rcu_read_lock();
79545- ret = security_capable(__task_cred(t), ns, cap);
79546+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79547+ gr_task_is_capable(t, __task_cred(t), cap);
79548 rcu_read_unlock();
79549
79550- return (ret == 0);
79551+ return ret;
79552 }
79553
79554 /**
79555@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79556 int ret;
79557
79558 rcu_read_lock();
79559- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79560+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79561 rcu_read_unlock();
79562
79563- return (ret == 0);
79564+ return ret;
79565 }
79566
79567 /**
79568@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79569 BUG();
79570 }
79571
79572- if (security_capable(current_cred(), ns, cap) == 0) {
79573+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79574 current->flags |= PF_SUPERPRIV;
79575 return true;
79576 }
79577@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79578 }
79579 EXPORT_SYMBOL(ns_capable);
79580
79581+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79582+{
79583+ if (unlikely(!cap_valid(cap))) {
79584+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79585+ BUG();
79586+ }
79587+
79588+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79589+ current->flags |= PF_SUPERPRIV;
79590+ return true;
79591+ }
79592+ return false;
79593+}
79594+EXPORT_SYMBOL(ns_capable_nolog);
79595+
79596 /**
79597 * file_ns_capable - Determine if the file's opener had a capability in effect
79598 * @file: The file we want to check
79599@@ -432,6 +451,12 @@ bool capable(int cap)
79600 }
79601 EXPORT_SYMBOL(capable);
79602
79603+bool capable_nolog(int cap)
79604+{
79605+ return ns_capable_nolog(&init_user_ns, cap);
79606+}
79607+EXPORT_SYMBOL(capable_nolog);
79608+
79609 /**
79610 * nsown_capable - Check superior capability to one's own user_ns
79611 * @cap: The capability in question
79612@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79613
79614 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79615 }
79616+
79617+bool inode_capable_nolog(const struct inode *inode, int cap)
79618+{
79619+ struct user_namespace *ns = current_user_ns();
79620+
79621+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79622+}
79623diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79624index e919633..f46b08f 100644
79625--- a/kernel/cgroup.c
79626+++ b/kernel/cgroup.c
79627@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79628 struct css_set *cset = link->cset;
79629 struct task_struct *task;
79630 int count = 0;
79631- seq_printf(seq, "css_set %p\n", cset);
79632+ seq_printf(seq, "css_set %pK\n", cset);
79633 list_for_each_entry(task, &cset->tasks, cg_list) {
79634 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79635 seq_puts(seq, " ...\n");
79636diff --git a/kernel/compat.c b/kernel/compat.c
79637index 0a09e48..f44f3f0 100644
79638--- a/kernel/compat.c
79639+++ b/kernel/compat.c
79640@@ -13,6 +13,7 @@
79641
79642 #include <linux/linkage.h>
79643 #include <linux/compat.h>
79644+#include <linux/module.h>
79645 #include <linux/errno.h>
79646 #include <linux/time.h>
79647 #include <linux/signal.h>
79648@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79649 mm_segment_t oldfs;
79650 long ret;
79651
79652- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79653+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79654 oldfs = get_fs();
79655 set_fs(KERNEL_DS);
79656 ret = hrtimer_nanosleep_restart(restart);
79657@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79658 oldfs = get_fs();
79659 set_fs(KERNEL_DS);
79660 ret = hrtimer_nanosleep(&tu,
79661- rmtp ? (struct timespec __user *)&rmt : NULL,
79662+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79663 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79664 set_fs(oldfs);
79665
79666@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79667 mm_segment_t old_fs = get_fs();
79668
79669 set_fs(KERNEL_DS);
79670- ret = sys_sigpending((old_sigset_t __user *) &s);
79671+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79672 set_fs(old_fs);
79673 if (ret == 0)
79674 ret = put_user(s, set);
79675@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79676 mm_segment_t old_fs = get_fs();
79677
79678 set_fs(KERNEL_DS);
79679- ret = sys_old_getrlimit(resource, &r);
79680+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79681 set_fs(old_fs);
79682
79683 if (!ret) {
79684@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79685 set_fs (KERNEL_DS);
79686 ret = sys_wait4(pid,
79687 (stat_addr ?
79688- (unsigned int __user *) &status : NULL),
79689- options, (struct rusage __user *) &r);
79690+ (unsigned int __force_user *) &status : NULL),
79691+ options, (struct rusage __force_user *) &r);
79692 set_fs (old_fs);
79693
79694 if (ret > 0) {
79695@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79696 memset(&info, 0, sizeof(info));
79697
79698 set_fs(KERNEL_DS);
79699- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79700- uru ? (struct rusage __user *)&ru : NULL);
79701+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79702+ uru ? (struct rusage __force_user *)&ru : NULL);
79703 set_fs(old_fs);
79704
79705 if ((ret < 0) || (info.si_signo == 0))
79706@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79707 oldfs = get_fs();
79708 set_fs(KERNEL_DS);
79709 err = sys_timer_settime(timer_id, flags,
79710- (struct itimerspec __user *) &newts,
79711- (struct itimerspec __user *) &oldts);
79712+ (struct itimerspec __force_user *) &newts,
79713+ (struct itimerspec __force_user *) &oldts);
79714 set_fs(oldfs);
79715 if (!err && old && put_compat_itimerspec(old, &oldts))
79716 return -EFAULT;
79717@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79718 oldfs = get_fs();
79719 set_fs(KERNEL_DS);
79720 err = sys_timer_gettime(timer_id,
79721- (struct itimerspec __user *) &ts);
79722+ (struct itimerspec __force_user *) &ts);
79723 set_fs(oldfs);
79724 if (!err && put_compat_itimerspec(setting, &ts))
79725 return -EFAULT;
79726@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79727 oldfs = get_fs();
79728 set_fs(KERNEL_DS);
79729 err = sys_clock_settime(which_clock,
79730- (struct timespec __user *) &ts);
79731+ (struct timespec __force_user *) &ts);
79732 set_fs(oldfs);
79733 return err;
79734 }
79735@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79736 oldfs = get_fs();
79737 set_fs(KERNEL_DS);
79738 err = sys_clock_gettime(which_clock,
79739- (struct timespec __user *) &ts);
79740+ (struct timespec __force_user *) &ts);
79741 set_fs(oldfs);
79742 if (!err && put_compat_timespec(&ts, tp))
79743 return -EFAULT;
79744@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79745
79746 oldfs = get_fs();
79747 set_fs(KERNEL_DS);
79748- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79749+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79750 set_fs(oldfs);
79751
79752 err = compat_put_timex(utp, &txc);
79753@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79754 oldfs = get_fs();
79755 set_fs(KERNEL_DS);
79756 err = sys_clock_getres(which_clock,
79757- (struct timespec __user *) &ts);
79758+ (struct timespec __force_user *) &ts);
79759 set_fs(oldfs);
79760 if (!err && tp && put_compat_timespec(&ts, tp))
79761 return -EFAULT;
79762@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79763 long err;
79764 mm_segment_t oldfs;
79765 struct timespec tu;
79766- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79767+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79768
79769- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79770+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79771 oldfs = get_fs();
79772 set_fs(KERNEL_DS);
79773 err = clock_nanosleep_restart(restart);
79774@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79775 oldfs = get_fs();
79776 set_fs(KERNEL_DS);
79777 err = sys_clock_nanosleep(which_clock, flags,
79778- (struct timespec __user *) &in,
79779- (struct timespec __user *) &out);
79780+ (struct timespec __force_user *) &in,
79781+ (struct timespec __force_user *) &out);
79782 set_fs(oldfs);
79783
79784 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79785diff --git a/kernel/configs.c b/kernel/configs.c
79786index c18b1f1..b9a0132 100644
79787--- a/kernel/configs.c
79788+++ b/kernel/configs.c
79789@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79790 struct proc_dir_entry *entry;
79791
79792 /* create the current config file */
79793+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79794+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79795+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79796+ &ikconfig_file_ops);
79797+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79798+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79799+ &ikconfig_file_ops);
79800+#endif
79801+#else
79802 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79803 &ikconfig_file_ops);
79804+#endif
79805+
79806 if (!entry)
79807 return -ENOMEM;
79808
79809diff --git a/kernel/cred.c b/kernel/cred.c
79810index e0573a4..3874e41 100644
79811--- a/kernel/cred.c
79812+++ b/kernel/cred.c
79813@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79814 validate_creds(cred);
79815 alter_cred_subscribers(cred, -1);
79816 put_cred(cred);
79817+
79818+#ifdef CONFIG_GRKERNSEC_SETXID
79819+ cred = (struct cred *) tsk->delayed_cred;
79820+ if (cred != NULL) {
79821+ tsk->delayed_cred = NULL;
79822+ validate_creds(cred);
79823+ alter_cred_subscribers(cred, -1);
79824+ put_cred(cred);
79825+ }
79826+#endif
79827 }
79828
79829 /**
79830@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79831 * Always returns 0 thus allowing this function to be tail-called at the end
79832 * of, say, sys_setgid().
79833 */
79834-int commit_creds(struct cred *new)
79835+static int __commit_creds(struct cred *new)
79836 {
79837 struct task_struct *task = current;
79838 const struct cred *old = task->real_cred;
79839@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79840
79841 get_cred(new); /* we will require a ref for the subj creds too */
79842
79843+ gr_set_role_label(task, new->uid, new->gid);
79844+
79845 /* dumpability changes */
79846 if (!uid_eq(old->euid, new->euid) ||
79847 !gid_eq(old->egid, new->egid) ||
79848@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79849 put_cred(old);
79850 return 0;
79851 }
79852+#ifdef CONFIG_GRKERNSEC_SETXID
79853+extern int set_user(struct cred *new);
79854+
79855+void gr_delayed_cred_worker(void)
79856+{
79857+ const struct cred *new = current->delayed_cred;
79858+ struct cred *ncred;
79859+
79860+ current->delayed_cred = NULL;
79861+
79862+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79863+ // from doing get_cred on it when queueing this
79864+ put_cred(new);
79865+ return;
79866+ } else if (new == NULL)
79867+ return;
79868+
79869+ ncred = prepare_creds();
79870+ if (!ncred)
79871+ goto die;
79872+ // uids
79873+ ncred->uid = new->uid;
79874+ ncred->euid = new->euid;
79875+ ncred->suid = new->suid;
79876+ ncred->fsuid = new->fsuid;
79877+ // gids
79878+ ncred->gid = new->gid;
79879+ ncred->egid = new->egid;
79880+ ncred->sgid = new->sgid;
79881+ ncred->fsgid = new->fsgid;
79882+ // groups
79883+ if (set_groups(ncred, new->group_info) < 0) {
79884+ abort_creds(ncred);
79885+ goto die;
79886+ }
79887+ // caps
79888+ ncred->securebits = new->securebits;
79889+ ncred->cap_inheritable = new->cap_inheritable;
79890+ ncred->cap_permitted = new->cap_permitted;
79891+ ncred->cap_effective = new->cap_effective;
79892+ ncred->cap_bset = new->cap_bset;
79893+
79894+ if (set_user(ncred)) {
79895+ abort_creds(ncred);
79896+ goto die;
79897+ }
79898+
79899+ // from doing get_cred on it when queueing this
79900+ put_cred(new);
79901+
79902+ __commit_creds(ncred);
79903+ return;
79904+die:
79905+ // from doing get_cred on it when queueing this
79906+ put_cred(new);
79907+ do_group_exit(SIGKILL);
79908+}
79909+#endif
79910+
79911+int commit_creds(struct cred *new)
79912+{
79913+#ifdef CONFIG_GRKERNSEC_SETXID
79914+ int ret;
79915+ int schedule_it = 0;
79916+ struct task_struct *t;
79917+
79918+ /* we won't get called with tasklist_lock held for writing
79919+ and interrupts disabled as the cred struct in that case is
79920+ init_cred
79921+ */
79922+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79923+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79924+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79925+ schedule_it = 1;
79926+ }
79927+ ret = __commit_creds(new);
79928+ if (schedule_it) {
79929+ rcu_read_lock();
79930+ read_lock(&tasklist_lock);
79931+ for (t = next_thread(current); t != current;
79932+ t = next_thread(t)) {
79933+ if (t->delayed_cred == NULL) {
79934+ t->delayed_cred = get_cred(new);
79935+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79936+ set_tsk_need_resched(t);
79937+ }
79938+ }
79939+ read_unlock(&tasklist_lock);
79940+ rcu_read_unlock();
79941+ }
79942+ return ret;
79943+#else
79944+ return __commit_creds(new);
79945+#endif
79946+}
79947+
79948 EXPORT_SYMBOL(commit_creds);
79949
79950 /**
79951diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79952index 0506d44..2c20034 100644
79953--- a/kernel/debug/debug_core.c
79954+++ b/kernel/debug/debug_core.c
79955@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79956 */
79957 static atomic_t masters_in_kgdb;
79958 static atomic_t slaves_in_kgdb;
79959-static atomic_t kgdb_break_tasklet_var;
79960+static atomic_unchecked_t kgdb_break_tasklet_var;
79961 atomic_t kgdb_setting_breakpoint;
79962
79963 struct task_struct *kgdb_usethread;
79964@@ -133,7 +133,7 @@ int kgdb_single_step;
79965 static pid_t kgdb_sstep_pid;
79966
79967 /* to keep track of the CPU which is doing the single stepping*/
79968-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79969+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79970
79971 /*
79972 * If you are debugging a problem where roundup (the collection of
79973@@ -541,7 +541,7 @@ return_normal:
79974 * kernel will only try for the value of sstep_tries before
79975 * giving up and continuing on.
79976 */
79977- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79978+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79979 (kgdb_info[cpu].task &&
79980 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79981 atomic_set(&kgdb_active, -1);
79982@@ -635,8 +635,8 @@ cpu_master_loop:
79983 }
79984
79985 kgdb_restore:
79986- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79987- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79988+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79989+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79990 if (kgdb_info[sstep_cpu].task)
79991 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79992 else
79993@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79994 static void kgdb_tasklet_bpt(unsigned long ing)
79995 {
79996 kgdb_breakpoint();
79997- atomic_set(&kgdb_break_tasklet_var, 0);
79998+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79999 }
80000
80001 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
80002
80003 void kgdb_schedule_breakpoint(void)
80004 {
80005- if (atomic_read(&kgdb_break_tasklet_var) ||
80006+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
80007 atomic_read(&kgdb_active) != -1 ||
80008 atomic_read(&kgdb_setting_breakpoint))
80009 return;
80010- atomic_inc(&kgdb_break_tasklet_var);
80011+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
80012 tasklet_schedule(&kgdb_tasklet_breakpoint);
80013 }
80014 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
80015diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
80016index 00eb8f7..d7e3244 100644
80017--- a/kernel/debug/kdb/kdb_main.c
80018+++ b/kernel/debug/kdb/kdb_main.c
80019@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
80020 continue;
80021
80022 kdb_printf("%-20s%8u 0x%p ", mod->name,
80023- mod->core_size, (void *)mod);
80024+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
80025 #ifdef CONFIG_MODULE_UNLOAD
80026 kdb_printf("%4ld ", module_refcount(mod));
80027 #endif
80028@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80029 kdb_printf(" (Loading)");
80030 else
80031 kdb_printf(" (Live)");
80032- kdb_printf(" 0x%p", mod->module_core);
80033+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80034
80035 #ifdef CONFIG_MODULE_UNLOAD
80036 {
80037diff --git a/kernel/events/core.c b/kernel/events/core.c
80038index f86599e..b18b180 100644
80039--- a/kernel/events/core.c
80040+++ b/kernel/events/core.c
80041@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80042 * 0 - disallow raw tracepoint access for unpriv
80043 * 1 - disallow cpu events for unpriv
80044 * 2 - disallow kernel profiling for unpriv
80045+ * 3 - disallow all unpriv perf event use
80046 */
80047-int sysctl_perf_event_paranoid __read_mostly = 1;
80048+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80049+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80050+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80051+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80052+#else
80053+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80054+#endif
80055
80056 /* Minimum for 512 kiB + 1 user control page */
80057 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80058@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80059 update_perf_cpu_limits();
80060 }
80061
80062-static atomic64_t perf_event_id;
80063+static atomic64_unchecked_t perf_event_id;
80064
80065 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80066 enum event_type_t event_type);
80067@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80068
80069 static inline u64 perf_event_count(struct perf_event *event)
80070 {
80071- return local64_read(&event->count) + atomic64_read(&event->child_count);
80072+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80073 }
80074
80075 static u64 perf_event_read(struct perf_event *event)
80076@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80077 mutex_lock(&event->child_mutex);
80078 total += perf_event_read(event);
80079 *enabled += event->total_time_enabled +
80080- atomic64_read(&event->child_total_time_enabled);
80081+ atomic64_read_unchecked(&event->child_total_time_enabled);
80082 *running += event->total_time_running +
80083- atomic64_read(&event->child_total_time_running);
80084+ atomic64_read_unchecked(&event->child_total_time_running);
80085
80086 list_for_each_entry(child, &event->child_list, child_list) {
80087 total += perf_event_read(child);
80088@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80089 userpg->offset -= local64_read(&event->hw.prev_count);
80090
80091 userpg->time_enabled = enabled +
80092- atomic64_read(&event->child_total_time_enabled);
80093+ atomic64_read_unchecked(&event->child_total_time_enabled);
80094
80095 userpg->time_running = running +
80096- atomic64_read(&event->child_total_time_running);
80097+ atomic64_read_unchecked(&event->child_total_time_running);
80098
80099 arch_perf_update_userpage(userpg, now);
80100
80101@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80102
80103 /* Data. */
80104 sp = perf_user_stack_pointer(regs);
80105- rem = __output_copy_user(handle, (void *) sp, dump_size);
80106+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80107 dyn_size = dump_size - rem;
80108
80109 perf_output_skip(handle, rem);
80110@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80111 values[n++] = perf_event_count(event);
80112 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80113 values[n++] = enabled +
80114- atomic64_read(&event->child_total_time_enabled);
80115+ atomic64_read_unchecked(&event->child_total_time_enabled);
80116 }
80117 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80118 values[n++] = running +
80119- atomic64_read(&event->child_total_time_running);
80120+ atomic64_read_unchecked(&event->child_total_time_running);
80121 }
80122 if (read_format & PERF_FORMAT_ID)
80123 values[n++] = primary_event_id(event);
80124@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80125 * need to add enough zero bytes after the string to handle
80126 * the 64bit alignment we do later.
80127 */
80128- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80129+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80130 if (!buf) {
80131 name = strncpy(tmp, "//enomem", sizeof(tmp));
80132 goto got_name;
80133 }
80134- name = d_path(&file->f_path, buf, PATH_MAX);
80135+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80136 if (IS_ERR(name)) {
80137 name = strncpy(tmp, "//toolong", sizeof(tmp));
80138 goto got_name;
80139@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80140 event->parent = parent_event;
80141
80142 event->ns = get_pid_ns(task_active_pid_ns(current));
80143- event->id = atomic64_inc_return(&perf_event_id);
80144+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80145
80146 event->state = PERF_EVENT_STATE_INACTIVE;
80147
80148@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80149 if (flags & ~PERF_FLAG_ALL)
80150 return -EINVAL;
80151
80152+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80153+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80154+ return -EACCES;
80155+#endif
80156+
80157 err = perf_copy_attr(attr_uptr, &attr);
80158 if (err)
80159 return err;
80160@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80161 /*
80162 * Add back the child's count to the parent's count:
80163 */
80164- atomic64_add(child_val, &parent_event->child_count);
80165- atomic64_add(child_event->total_time_enabled,
80166+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80167+ atomic64_add_unchecked(child_event->total_time_enabled,
80168 &parent_event->child_total_time_enabled);
80169- atomic64_add(child_event->total_time_running,
80170+ atomic64_add_unchecked(child_event->total_time_running,
80171 &parent_event->child_total_time_running);
80172
80173 /*
80174diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80175index ca65997..60df03d 100644
80176--- a/kernel/events/internal.h
80177+++ b/kernel/events/internal.h
80178@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80179 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80180 }
80181
80182-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80183-static inline unsigned int \
80184+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80185+static inline unsigned long \
80186 func_name(struct perf_output_handle *handle, \
80187- const void *buf, unsigned int len) \
80188+ const void user *buf, unsigned long len) \
80189 { \
80190 unsigned long size, written; \
80191 \
80192@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80193 return n;
80194 }
80195
80196-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80197+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80198
80199 #define MEMCPY_SKIP(dst, src, n) (n)
80200
80201-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80202+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80203
80204 #ifndef arch_perf_out_copy_user
80205 #define arch_perf_out_copy_user __copy_from_user_inatomic
80206 #endif
80207
80208-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80209+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80210
80211 /* Callchain handling */
80212 extern struct perf_callchain_entry *
80213diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80214index ad8e1bd..fed7ba9 100644
80215--- a/kernel/events/uprobes.c
80216+++ b/kernel/events/uprobes.c
80217@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80218 {
80219 struct page *page;
80220 uprobe_opcode_t opcode;
80221- int result;
80222+ long result;
80223
80224 pagefault_disable();
80225 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80226diff --git a/kernel/exit.c b/kernel/exit.c
80227index a949819..a5f127d 100644
80228--- a/kernel/exit.c
80229+++ b/kernel/exit.c
80230@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80231 struct task_struct *leader;
80232 int zap_leader;
80233 repeat:
80234+#ifdef CONFIG_NET
80235+ gr_del_task_from_ip_table(p);
80236+#endif
80237+
80238 /* don't need to get the RCU readlock here - the process is dead and
80239 * can't be modifying its own credentials. But shut RCU-lockdep up */
80240 rcu_read_lock();
80241@@ -329,7 +333,7 @@ int allow_signal(int sig)
80242 * know it'll be handled, so that they don't get converted to
80243 * SIGKILL or just silently dropped.
80244 */
80245- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80246+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80247 recalc_sigpending();
80248 spin_unlock_irq(&current->sighand->siglock);
80249 return 0;
80250@@ -698,6 +702,8 @@ void do_exit(long code)
80251 struct task_struct *tsk = current;
80252 int group_dead;
80253
80254+ set_fs(USER_DS);
80255+
80256 profile_task_exit(tsk);
80257
80258 WARN_ON(blk_needs_flush_plug(tsk));
80259@@ -714,7 +720,6 @@ void do_exit(long code)
80260 * mm_release()->clear_child_tid() from writing to a user-controlled
80261 * kernel address.
80262 */
80263- set_fs(USER_DS);
80264
80265 ptrace_event(PTRACE_EVENT_EXIT, code);
80266
80267@@ -773,6 +778,9 @@ void do_exit(long code)
80268 tsk->exit_code = code;
80269 taskstats_exit(tsk, group_dead);
80270
80271+ gr_acl_handle_psacct(tsk, code);
80272+ gr_acl_handle_exit();
80273+
80274 exit_mm(tsk);
80275
80276 if (group_dead)
80277@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80278 * Take down every thread in the group. This is called by fatal signals
80279 * as well as by sys_exit_group (below).
80280 */
80281-void
80282+__noreturn void
80283 do_group_exit(int exit_code)
80284 {
80285 struct signal_struct *sig = current->signal;
80286diff --git a/kernel/fork.c b/kernel/fork.c
80287index 200a7a2..43e52da 100644
80288--- a/kernel/fork.c
80289+++ b/kernel/fork.c
80290@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80291 *stackend = STACK_END_MAGIC; /* for overflow detection */
80292
80293 #ifdef CONFIG_CC_STACKPROTECTOR
80294- tsk->stack_canary = get_random_int();
80295+ tsk->stack_canary = pax_get_random_long();
80296 #endif
80297
80298 /*
80299@@ -345,13 +345,81 @@ free_tsk:
80300 }
80301
80302 #ifdef CONFIG_MMU
80303-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80304+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80305 {
80306- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80307- struct rb_node **rb_link, *rb_parent;
80308- int retval;
80309+ struct vm_area_struct *tmp;
80310 unsigned long charge;
80311 struct mempolicy *pol;
80312+ struct file *file;
80313+
80314+ charge = 0;
80315+ if (mpnt->vm_flags & VM_ACCOUNT) {
80316+ unsigned long len = vma_pages(mpnt);
80317+
80318+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80319+ goto fail_nomem;
80320+ charge = len;
80321+ }
80322+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80323+ if (!tmp)
80324+ goto fail_nomem;
80325+ *tmp = *mpnt;
80326+ tmp->vm_mm = mm;
80327+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80328+ pol = mpol_dup(vma_policy(mpnt));
80329+ if (IS_ERR(pol))
80330+ goto fail_nomem_policy;
80331+ vma_set_policy(tmp, pol);
80332+ if (anon_vma_fork(tmp, mpnt))
80333+ goto fail_nomem_anon_vma_fork;
80334+ tmp->vm_flags &= ~VM_LOCKED;
80335+ tmp->vm_next = tmp->vm_prev = NULL;
80336+ tmp->vm_mirror = NULL;
80337+ file = tmp->vm_file;
80338+ if (file) {
80339+ struct inode *inode = file_inode(file);
80340+ struct address_space *mapping = file->f_mapping;
80341+
80342+ get_file(file);
80343+ if (tmp->vm_flags & VM_DENYWRITE)
80344+ atomic_dec(&inode->i_writecount);
80345+ mutex_lock(&mapping->i_mmap_mutex);
80346+ if (tmp->vm_flags & VM_SHARED)
80347+ mapping->i_mmap_writable++;
80348+ flush_dcache_mmap_lock(mapping);
80349+ /* insert tmp into the share list, just after mpnt */
80350+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80351+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80352+ else
80353+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80354+ flush_dcache_mmap_unlock(mapping);
80355+ mutex_unlock(&mapping->i_mmap_mutex);
80356+ }
80357+
80358+ /*
80359+ * Clear hugetlb-related page reserves for children. This only
80360+ * affects MAP_PRIVATE mappings. Faults generated by the child
80361+ * are not guaranteed to succeed, even if read-only
80362+ */
80363+ if (is_vm_hugetlb_page(tmp))
80364+ reset_vma_resv_huge_pages(tmp);
80365+
80366+ return tmp;
80367+
80368+fail_nomem_anon_vma_fork:
80369+ mpol_put(pol);
80370+fail_nomem_policy:
80371+ kmem_cache_free(vm_area_cachep, tmp);
80372+fail_nomem:
80373+ vm_unacct_memory(charge);
80374+ return NULL;
80375+}
80376+
80377+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80378+{
80379+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80380+ struct rb_node **rb_link, *rb_parent;
80381+ int retval;
80382
80383 uprobe_start_dup_mmap();
80384 down_write(&oldmm->mmap_sem);
80385@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80386
80387 prev = NULL;
80388 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80389- struct file *file;
80390-
80391 if (mpnt->vm_flags & VM_DONTCOPY) {
80392 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80393 -vma_pages(mpnt));
80394 continue;
80395 }
80396- charge = 0;
80397- if (mpnt->vm_flags & VM_ACCOUNT) {
80398- unsigned long len = vma_pages(mpnt);
80399-
80400- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80401- goto fail_nomem;
80402- charge = len;
80403- }
80404- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80405- if (!tmp)
80406- goto fail_nomem;
80407- *tmp = *mpnt;
80408- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80409- pol = mpol_dup(vma_policy(mpnt));
80410- retval = PTR_ERR(pol);
80411- if (IS_ERR(pol))
80412- goto fail_nomem_policy;
80413- vma_set_policy(tmp, pol);
80414- tmp->vm_mm = mm;
80415- if (anon_vma_fork(tmp, mpnt))
80416- goto fail_nomem_anon_vma_fork;
80417- tmp->vm_flags &= ~VM_LOCKED;
80418- tmp->vm_next = tmp->vm_prev = NULL;
80419- file = tmp->vm_file;
80420- if (file) {
80421- struct inode *inode = file_inode(file);
80422- struct address_space *mapping = file->f_mapping;
80423-
80424- get_file(file);
80425- if (tmp->vm_flags & VM_DENYWRITE)
80426- atomic_dec(&inode->i_writecount);
80427- mutex_lock(&mapping->i_mmap_mutex);
80428- if (tmp->vm_flags & VM_SHARED)
80429- mapping->i_mmap_writable++;
80430- flush_dcache_mmap_lock(mapping);
80431- /* insert tmp into the share list, just after mpnt */
80432- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80433- vma_nonlinear_insert(tmp,
80434- &mapping->i_mmap_nonlinear);
80435- else
80436- vma_interval_tree_insert_after(tmp, mpnt,
80437- &mapping->i_mmap);
80438- flush_dcache_mmap_unlock(mapping);
80439- mutex_unlock(&mapping->i_mmap_mutex);
80440+ tmp = dup_vma(mm, oldmm, mpnt);
80441+ if (!tmp) {
80442+ retval = -ENOMEM;
80443+ goto out;
80444 }
80445
80446 /*
80447@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80448 if (retval)
80449 goto out;
80450 }
80451+
80452+#ifdef CONFIG_PAX_SEGMEXEC
80453+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80454+ struct vm_area_struct *mpnt_m;
80455+
80456+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80457+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80458+
80459+ if (!mpnt->vm_mirror)
80460+ continue;
80461+
80462+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80463+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80464+ mpnt->vm_mirror = mpnt_m;
80465+ } else {
80466+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80467+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80468+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80469+ mpnt->vm_mirror->vm_mirror = mpnt;
80470+ }
80471+ }
80472+ BUG_ON(mpnt_m);
80473+ }
80474+#endif
80475+
80476 /* a new mm has just been created */
80477 arch_dup_mmap(oldmm, mm);
80478 retval = 0;
80479@@ -471,14 +522,6 @@ out:
80480 up_write(&oldmm->mmap_sem);
80481 uprobe_end_dup_mmap();
80482 return retval;
80483-fail_nomem_anon_vma_fork:
80484- mpol_put(pol);
80485-fail_nomem_policy:
80486- kmem_cache_free(vm_area_cachep, tmp);
80487-fail_nomem:
80488- retval = -ENOMEM;
80489- vm_unacct_memory(charge);
80490- goto out;
80491 }
80492
80493 static inline int mm_alloc_pgd(struct mm_struct *mm)
80494@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80495 return ERR_PTR(err);
80496
80497 mm = get_task_mm(task);
80498- if (mm && mm != current->mm &&
80499- !ptrace_may_access(task, mode)) {
80500+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80501+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80502 mmput(mm);
80503 mm = ERR_PTR(-EACCES);
80504 }
80505@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80506 spin_unlock(&fs->lock);
80507 return -EAGAIN;
80508 }
80509- fs->users++;
80510+ atomic_inc(&fs->users);
80511 spin_unlock(&fs->lock);
80512 return 0;
80513 }
80514 tsk->fs = copy_fs_struct(fs);
80515 if (!tsk->fs)
80516 return -ENOMEM;
80517+ /* Carry through gr_chroot_dentry and is_chrooted instead
80518+ of recomputing it here. Already copied when the task struct
80519+ is duplicated. This allows pivot_root to not be treated as
80520+ a chroot
80521+ */
80522+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80523+
80524 return 0;
80525 }
80526
80527@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80528 * parts of the process environment (as per the clone
80529 * flags). The actual kick-off is left to the caller.
80530 */
80531-static struct task_struct *copy_process(unsigned long clone_flags,
80532+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80533 unsigned long stack_start,
80534 unsigned long stack_size,
80535 int __user *child_tidptr,
80536@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80537 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80538 #endif
80539 retval = -EAGAIN;
80540+
80541+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80542+
80543 if (atomic_read(&p->real_cred->user->processes) >=
80544 task_rlimit(p, RLIMIT_NPROC)) {
80545 if (p->real_cred->user != INIT_USER &&
80546@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80547 goto bad_fork_free_pid;
80548 }
80549
80550+ /* synchronizes with gr_set_acls()
80551+ we need to call this past the point of no return for fork()
80552+ */
80553+ gr_copy_label(p);
80554+
80555 if (likely(p->pid)) {
80556 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80557
80558@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80559 bad_fork_free:
80560 free_task(p);
80561 fork_out:
80562+ gr_log_forkfail(retval);
80563+
80564 return ERR_PTR(retval);
80565 }
80566
80567@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80568
80569 p = copy_process(clone_flags, stack_start, stack_size,
80570 child_tidptr, NULL, trace);
80571+ add_latent_entropy();
80572 /*
80573 * Do this prior waking up the new thread - the thread pointer
80574 * might get invalid after that point, if the thread exits quickly.
80575@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80576 if (clone_flags & CLONE_PARENT_SETTID)
80577 put_user(nr, parent_tidptr);
80578
80579+ gr_handle_brute_check();
80580+
80581 if (clone_flags & CLONE_VFORK) {
80582 p->vfork_done = &vfork;
80583 init_completion(&vfork);
80584@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80585 mm_cachep = kmem_cache_create("mm_struct",
80586 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80587 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80588- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80589+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80590 mmap_init();
80591 nsproxy_cache_init();
80592 }
80593@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80594 return 0;
80595
80596 /* don't need lock here; in the worst case we'll do useless copy */
80597- if (fs->users == 1)
80598+ if (atomic_read(&fs->users) == 1)
80599 return 0;
80600
80601 *new_fsp = copy_fs_struct(fs);
80602@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80603 fs = current->fs;
80604 spin_lock(&fs->lock);
80605 current->fs = new_fs;
80606- if (--fs->users)
80607+ gr_set_chroot_entries(current, &current->fs->root);
80608+ if (atomic_dec_return(&fs->users))
80609 new_fs = NULL;
80610 else
80611 new_fs = fs;
80612diff --git a/kernel/futex.c b/kernel/futex.c
80613index c3a1a55..e32b4a98 100644
80614--- a/kernel/futex.c
80615+++ b/kernel/futex.c
80616@@ -54,6 +54,7 @@
80617 #include <linux/mount.h>
80618 #include <linux/pagemap.h>
80619 #include <linux/syscalls.h>
80620+#include <linux/ptrace.h>
80621 #include <linux/signal.h>
80622 #include <linux/export.h>
80623 #include <linux/magic.h>
80624@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80625 struct page *page, *page_head;
80626 int err, ro = 0;
80627
80628+#ifdef CONFIG_PAX_SEGMEXEC
80629+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80630+ return -EFAULT;
80631+#endif
80632+
80633 /*
80634 * The futex address must be "naturally" aligned.
80635 */
80636@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80637
80638 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80639 {
80640- int ret;
80641+ unsigned long ret;
80642
80643 pagefault_disable();
80644 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80645@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80646 {
80647 u32 curval;
80648 int i;
80649+ mm_segment_t oldfs;
80650
80651 /*
80652 * This will fail and we want it. Some arch implementations do
80653@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80654 * implementation, the non-functional ones will return
80655 * -ENOSYS.
80656 */
80657+ oldfs = get_fs();
80658+ set_fs(USER_DS);
80659 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80660 futex_cmpxchg_enabled = 1;
80661+ set_fs(oldfs);
80662
80663 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80664 plist_head_init(&futex_queues[i].chain);
80665diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80666index f9f44fd..29885e4 100644
80667--- a/kernel/futex_compat.c
80668+++ b/kernel/futex_compat.c
80669@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80670 return 0;
80671 }
80672
80673-static void __user *futex_uaddr(struct robust_list __user *entry,
80674+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80675 compat_long_t futex_offset)
80676 {
80677 compat_uptr_t base = ptr_to_compat(entry);
80678diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80679index 9b22d03..6295b62 100644
80680--- a/kernel/gcov/base.c
80681+++ b/kernel/gcov/base.c
80682@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80683 }
80684
80685 #ifdef CONFIG_MODULES
80686-static inline int within(void *addr, void *start, unsigned long size)
80687-{
80688- return ((addr >= start) && (addr < start + size));
80689-}
80690-
80691 /* Update list and generate events when modules are unloaded. */
80692 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80693 void *data)
80694@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80695 prev = NULL;
80696 /* Remove entries located in module from linked list. */
80697 for (info = gcov_info_head; info; info = info->next) {
80698- if (within(info, mod->module_core, mod->core_size)) {
80699+ if (within_module_core_rw((unsigned long)info, mod)) {
80700 if (prev)
80701 prev->next = info->next;
80702 else
80703diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80704index 383319b..56ebb13 100644
80705--- a/kernel/hrtimer.c
80706+++ b/kernel/hrtimer.c
80707@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80708 local_irq_restore(flags);
80709 }
80710
80711-static void run_hrtimer_softirq(struct softirq_action *h)
80712+static __latent_entropy void run_hrtimer_softirq(void)
80713 {
80714 hrtimer_peek_ahead_timers();
80715 }
80716diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80717index 55fcce6..0e4cf34 100644
80718--- a/kernel/irq_work.c
80719+++ b/kernel/irq_work.c
80720@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80721 return NOTIFY_OK;
80722 }
80723
80724-static struct notifier_block cpu_notify;
80725+static struct notifier_block cpu_notify = {
80726+ .notifier_call = irq_work_cpu_notify,
80727+ .priority = 0,
80728+};
80729
80730 static __init int irq_work_init_cpu_notifier(void)
80731 {
80732- cpu_notify.notifier_call = irq_work_cpu_notify;
80733- cpu_notify.priority = 0;
80734 register_cpu_notifier(&cpu_notify);
80735 return 0;
80736 }
80737diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80738index 60f48fa..7f3a770 100644
80739--- a/kernel/jump_label.c
80740+++ b/kernel/jump_label.c
80741@@ -13,6 +13,7 @@
80742 #include <linux/sort.h>
80743 #include <linux/err.h>
80744 #include <linux/static_key.h>
80745+#include <linux/mm.h>
80746
80747 #ifdef HAVE_JUMP_LABEL
80748
80749@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80750
80751 size = (((unsigned long)stop - (unsigned long)start)
80752 / sizeof(struct jump_entry));
80753+ pax_open_kernel();
80754 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80755+ pax_close_kernel();
80756 }
80757
80758 static void jump_label_update(struct static_key *key, int enable);
80759@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80760 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80761 struct jump_entry *iter;
80762
80763+ pax_open_kernel();
80764 for (iter = iter_start; iter < iter_stop; iter++) {
80765 if (within_module_init(iter->code, mod))
80766 iter->code = 0;
80767 }
80768+ pax_close_kernel();
80769 }
80770
80771 static int
80772diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80773index 3127ad5..159d880 100644
80774--- a/kernel/kallsyms.c
80775+++ b/kernel/kallsyms.c
80776@@ -11,6 +11,9 @@
80777 * Changed the compression method from stem compression to "table lookup"
80778 * compression (see scripts/kallsyms.c for a more complete description)
80779 */
80780+#ifdef CONFIG_GRKERNSEC_HIDESYM
80781+#define __INCLUDED_BY_HIDESYM 1
80782+#endif
80783 #include <linux/kallsyms.h>
80784 #include <linux/module.h>
80785 #include <linux/init.h>
80786@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80787
80788 static inline int is_kernel_inittext(unsigned long addr)
80789 {
80790+ if (system_state != SYSTEM_BOOTING)
80791+ return 0;
80792+
80793 if (addr >= (unsigned long)_sinittext
80794 && addr <= (unsigned long)_einittext)
80795 return 1;
80796 return 0;
80797 }
80798
80799+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80800+#ifdef CONFIG_MODULES
80801+static inline int is_module_text(unsigned long addr)
80802+{
80803+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80804+ return 1;
80805+
80806+ addr = ktla_ktva(addr);
80807+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80808+}
80809+#else
80810+static inline int is_module_text(unsigned long addr)
80811+{
80812+ return 0;
80813+}
80814+#endif
80815+#endif
80816+
80817 static inline int is_kernel_text(unsigned long addr)
80818 {
80819 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80820@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80821
80822 static inline int is_kernel(unsigned long addr)
80823 {
80824+
80825+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80826+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80827+ return 1;
80828+
80829+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80830+#else
80831 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80832+#endif
80833+
80834 return 1;
80835 return in_gate_area_no_mm(addr);
80836 }
80837
80838 static int is_ksym_addr(unsigned long addr)
80839 {
80840+
80841+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80842+ if (is_module_text(addr))
80843+ return 0;
80844+#endif
80845+
80846 if (all_var)
80847 return is_kernel(addr);
80848
80849@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80850
80851 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80852 {
80853- iter->name[0] = '\0';
80854 iter->nameoff = get_symbol_offset(new_pos);
80855 iter->pos = new_pos;
80856 }
80857@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80858 {
80859 struct kallsym_iter *iter = m->private;
80860
80861+#ifdef CONFIG_GRKERNSEC_HIDESYM
80862+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80863+ return 0;
80864+#endif
80865+
80866 /* Some debugging symbols have no name. Ignore them. */
80867 if (!iter->name[0])
80868 return 0;
80869@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80870 */
80871 type = iter->exported ? toupper(iter->type) :
80872 tolower(iter->type);
80873+
80874 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80875 type, iter->name, iter->module_name);
80876 } else
80877@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80878 struct kallsym_iter *iter;
80879 int ret;
80880
80881- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80882+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80883 if (!iter)
80884 return -ENOMEM;
80885 reset_iter(iter, 0);
80886diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80887index e30ac0f..3528cac 100644
80888--- a/kernel/kcmp.c
80889+++ b/kernel/kcmp.c
80890@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80891 struct task_struct *task1, *task2;
80892 int ret;
80893
80894+#ifdef CONFIG_GRKERNSEC
80895+ return -ENOSYS;
80896+#endif
80897+
80898 rcu_read_lock();
80899
80900 /*
80901diff --git a/kernel/kexec.c b/kernel/kexec.c
80902index 59f7b55..4022f65 100644
80903--- a/kernel/kexec.c
80904+++ b/kernel/kexec.c
80905@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80906 unsigned long flags)
80907 {
80908 struct compat_kexec_segment in;
80909- struct kexec_segment out, __user *ksegments;
80910+ struct kexec_segment out;
80911+ struct kexec_segment __user *ksegments;
80912 unsigned long i, result;
80913
80914 /* Don't allow clients that don't understand the native
80915diff --git a/kernel/kmod.c b/kernel/kmod.c
80916index b086006..a27913b 100644
80917--- a/kernel/kmod.c
80918+++ b/kernel/kmod.c
80919@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80920 kfree(info->argv);
80921 }
80922
80923-static int call_modprobe(char *module_name, int wait)
80924+static int call_modprobe(char *module_name, char *module_param, int wait)
80925 {
80926 struct subprocess_info *info;
80927 static char *envp[] = {
80928@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80929 NULL
80930 };
80931
80932- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80933+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80934 if (!argv)
80935 goto out;
80936
80937@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80938 argv[1] = "-q";
80939 argv[2] = "--";
80940 argv[3] = module_name; /* check free_modprobe_argv() */
80941- argv[4] = NULL;
80942+ argv[4] = module_param;
80943+ argv[5] = NULL;
80944
80945 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80946 NULL, free_modprobe_argv, NULL);
80947@@ -129,9 +130,8 @@ out:
80948 * If module auto-loading support is disabled then this function
80949 * becomes a no-operation.
80950 */
80951-int __request_module(bool wait, const char *fmt, ...)
80952+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80953 {
80954- va_list args;
80955 char module_name[MODULE_NAME_LEN];
80956 unsigned int max_modprobes;
80957 int ret;
80958@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80959 if (!modprobe_path[0])
80960 return 0;
80961
80962- va_start(args, fmt);
80963- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80964- va_end(args);
80965+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80966 if (ret >= MODULE_NAME_LEN)
80967 return -ENAMETOOLONG;
80968
80969@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80970 if (ret)
80971 return ret;
80972
80973+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80974+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80975+ /* hack to workaround consolekit/udisks stupidity */
80976+ read_lock(&tasklist_lock);
80977+ if (!strcmp(current->comm, "mount") &&
80978+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80979+ read_unlock(&tasklist_lock);
80980+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80981+ return -EPERM;
80982+ }
80983+ read_unlock(&tasklist_lock);
80984+ }
80985+#endif
80986+
80987 /* If modprobe needs a service that is in a module, we get a recursive
80988 * loop. Limit the number of running kmod threads to max_threads/2 or
80989 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80990@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80991
80992 trace_module_request(module_name, wait, _RET_IP_);
80993
80994- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80995+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80996
80997 atomic_dec(&kmod_concurrent);
80998 return ret;
80999 }
81000+
81001+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
81002+{
81003+ va_list args;
81004+ int ret;
81005+
81006+ va_start(args, fmt);
81007+ ret = ____request_module(wait, module_param, fmt, args);
81008+ va_end(args);
81009+
81010+ return ret;
81011+}
81012+
81013+int __request_module(bool wait, const char *fmt, ...)
81014+{
81015+ va_list args;
81016+ int ret;
81017+
81018+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81019+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81020+ char module_param[MODULE_NAME_LEN];
81021+
81022+ memset(module_param, 0, sizeof(module_param));
81023+
81024+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
81025+
81026+ va_start(args, fmt);
81027+ ret = ____request_module(wait, module_param, fmt, args);
81028+ va_end(args);
81029+
81030+ return ret;
81031+ }
81032+#endif
81033+
81034+ va_start(args, fmt);
81035+ ret = ____request_module(wait, NULL, fmt, args);
81036+ va_end(args);
81037+
81038+ return ret;
81039+}
81040+
81041 EXPORT_SYMBOL(__request_module);
81042 #endif /* CONFIG_MODULES */
81043
81044@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81045 *
81046 * Thus the __user pointer cast is valid here.
81047 */
81048- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81049+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81050
81051 /*
81052 * If ret is 0, either ____call_usermodehelper failed and the
81053@@ -650,7 +703,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81054 static int proc_cap_handler(struct ctl_table *table, int write,
81055 void __user *buffer, size_t *lenp, loff_t *ppos)
81056 {
81057- struct ctl_table t;
81058+ ctl_table_no_const t;
81059 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81060 kernel_cap_t new_cap;
81061 int err, i;
81062diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81063index 6e33498..3133bd3 100644
81064--- a/kernel/kprobes.c
81065+++ b/kernel/kprobes.c
81066@@ -31,6 +31,9 @@
81067 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81068 * <prasanna@in.ibm.com> added function-return probes.
81069 */
81070+#ifdef CONFIG_GRKERNSEC_HIDESYM
81071+#define __INCLUDED_BY_HIDESYM 1
81072+#endif
81073 #include <linux/kprobes.h>
81074 #include <linux/hash.h>
81075 #include <linux/init.h>
81076@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81077 * kernel image and loaded module images reside. This is required
81078 * so x86_64 can correctly handle the %rip-relative fixups.
81079 */
81080- kip->insns = module_alloc(PAGE_SIZE);
81081+ kip->insns = module_alloc_exec(PAGE_SIZE);
81082 if (!kip->insns) {
81083 kfree(kip);
81084 return NULL;
81085@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81086 */
81087 if (!list_is_singular(&kip->list)) {
81088 list_del(&kip->list);
81089- module_free(NULL, kip->insns);
81090+ module_free_exec(NULL, kip->insns);
81091 kfree(kip);
81092 }
81093 return 1;
81094@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81095 {
81096 int i, err = 0;
81097 unsigned long offset = 0, size = 0;
81098- char *modname, namebuf[128];
81099+ char *modname, namebuf[KSYM_NAME_LEN];
81100 const char *symbol_name;
81101 void *addr;
81102 struct kprobe_blackpoint *kb;
81103@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81104 kprobe_type = "k";
81105
81106 if (sym)
81107- seq_printf(pi, "%p %s %s+0x%x %s ",
81108+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81109 p->addr, kprobe_type, sym, offset,
81110 (modname ? modname : " "));
81111 else
81112- seq_printf(pi, "%p %s %p ",
81113+ seq_printf(pi, "%pK %s %pK ",
81114 p->addr, kprobe_type, p->addr);
81115
81116 if (!pp)
81117@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81118 const char *sym = NULL;
81119 unsigned int i = *(loff_t *) v;
81120 unsigned long offset = 0;
81121- char *modname, namebuf[128];
81122+ char *modname, namebuf[KSYM_NAME_LEN];
81123
81124 head = &kprobe_table[i];
81125 preempt_disable();
81126diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81127index 6ada93c..dce7d5d 100644
81128--- a/kernel/ksysfs.c
81129+++ b/kernel/ksysfs.c
81130@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81131 {
81132 if (count+1 > UEVENT_HELPER_PATH_LEN)
81133 return -ENOENT;
81134+ if (!capable(CAP_SYS_ADMIN))
81135+ return -EPERM;
81136 memcpy(uevent_helper, buf, count);
81137 uevent_helper[count] = '\0';
81138 if (count && uevent_helper[count-1] == '\n')
81139@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81140 return count;
81141 }
81142
81143-static struct bin_attribute notes_attr = {
81144+static bin_attribute_no_const notes_attr __read_only = {
81145 .attr = {
81146 .name = "notes",
81147 .mode = S_IRUGO,
81148diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81149index e16c45b..6f49c48 100644
81150--- a/kernel/lockdep.c
81151+++ b/kernel/lockdep.c
81152@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81153 end = (unsigned long) &_end,
81154 addr = (unsigned long) obj;
81155
81156+#ifdef CONFIG_PAX_KERNEXEC
81157+ start = ktla_ktva(start);
81158+#endif
81159+
81160 /*
81161 * static variable?
81162 */
81163@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81164 if (!static_obj(lock->key)) {
81165 debug_locks_off();
81166 printk("INFO: trying to register non-static key.\n");
81167+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81168 printk("the code is fine but needs lockdep annotation.\n");
81169 printk("turning off the locking correctness validator.\n");
81170 dump_stack();
81171@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81172 if (!class)
81173 return 0;
81174 }
81175- atomic_inc((atomic_t *)&class->ops);
81176+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81177 if (very_verbose(class)) {
81178 printk("\nacquire class [%p] %s", class->key, class->name);
81179 if (class->name_version > 1)
81180diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81181index b2c71c5..7b88d63 100644
81182--- a/kernel/lockdep_proc.c
81183+++ b/kernel/lockdep_proc.c
81184@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81185 return 0;
81186 }
81187
81188- seq_printf(m, "%p", class->key);
81189+ seq_printf(m, "%pK", class->key);
81190 #ifdef CONFIG_DEBUG_LOCKDEP
81191 seq_printf(m, " OPS:%8ld", class->ops);
81192 #endif
81193@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81194
81195 list_for_each_entry(entry, &class->locks_after, entry) {
81196 if (entry->distance == 1) {
81197- seq_printf(m, " -> [%p] ", entry->class->key);
81198+ seq_printf(m, " -> [%pK] ", entry->class->key);
81199 print_name(m, entry->class);
81200 seq_puts(m, "\n");
81201 }
81202@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81203 if (!class->key)
81204 continue;
81205
81206- seq_printf(m, "[%p] ", class->key);
81207+ seq_printf(m, "[%pK] ", class->key);
81208 print_name(m, class);
81209 seq_puts(m, "\n");
81210 }
81211@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81212 if (!i)
81213 seq_line(m, '-', 40-namelen, namelen);
81214
81215- snprintf(ip, sizeof(ip), "[<%p>]",
81216+ snprintf(ip, sizeof(ip), "[<%pK>]",
81217 (void *)class->contention_point[i]);
81218 seq_printf(m, "%40s %14lu %29s %pS\n",
81219 name, stats->contention_point[i],
81220@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81221 if (!i)
81222 seq_line(m, '-', 40-namelen, namelen);
81223
81224- snprintf(ip, sizeof(ip), "[<%p>]",
81225+ snprintf(ip, sizeof(ip), "[<%pK>]",
81226 (void *)class->contending_point[i]);
81227 seq_printf(m, "%40s %14lu %29s %pS\n",
81228 name, stats->contending_point[i],
81229diff --git a/kernel/module.c b/kernel/module.c
81230index 2069158..71101bb 100644
81231--- a/kernel/module.c
81232+++ b/kernel/module.c
81233@@ -61,6 +61,7 @@
81234 #include <linux/pfn.h>
81235 #include <linux/bsearch.h>
81236 #include <linux/fips.h>
81237+#include <linux/grsecurity.h>
81238 #include <uapi/linux/module.h>
81239 #include "module-internal.h"
81240
81241@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81242
81243 /* Bounds of module allocation, for speeding __module_address.
81244 * Protected by module_mutex. */
81245-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81246+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81247+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81248
81249 int register_module_notifier(struct notifier_block * nb)
81250 {
81251@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81252 return true;
81253
81254 list_for_each_entry_rcu(mod, &modules, list) {
81255- struct symsearch arr[] = {
81256+ struct symsearch modarr[] = {
81257 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81258 NOT_GPL_ONLY, false },
81259 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81260@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81261 if (mod->state == MODULE_STATE_UNFORMED)
81262 continue;
81263
81264- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81265+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81266 return true;
81267 }
81268 return false;
81269@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81270 if (!pcpusec->sh_size)
81271 return 0;
81272
81273- if (align > PAGE_SIZE) {
81274+ if (align-1 >= PAGE_SIZE) {
81275 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81276 mod->name, align, PAGE_SIZE);
81277 align = PAGE_SIZE;
81278@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81279 static ssize_t show_coresize(struct module_attribute *mattr,
81280 struct module_kobject *mk, char *buffer)
81281 {
81282- return sprintf(buffer, "%u\n", mk->mod->core_size);
81283+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81284 }
81285
81286 static struct module_attribute modinfo_coresize =
81287@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81288 static ssize_t show_initsize(struct module_attribute *mattr,
81289 struct module_kobject *mk, char *buffer)
81290 {
81291- return sprintf(buffer, "%u\n", mk->mod->init_size);
81292+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81293 }
81294
81295 static struct module_attribute modinfo_initsize =
81296@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81297 */
81298 #ifdef CONFIG_SYSFS
81299
81300-#ifdef CONFIG_KALLSYMS
81301+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81302 static inline bool sect_empty(const Elf_Shdr *sect)
81303 {
81304 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81305@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81306 {
81307 unsigned int notes, loaded, i;
81308 struct module_notes_attrs *notes_attrs;
81309- struct bin_attribute *nattr;
81310+ bin_attribute_no_const *nattr;
81311
81312 /* failed to create section attributes, so can't create notes */
81313 if (!mod->sect_attrs)
81314@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81315 static int module_add_modinfo_attrs(struct module *mod)
81316 {
81317 struct module_attribute *attr;
81318- struct module_attribute *temp_attr;
81319+ module_attribute_no_const *temp_attr;
81320 int error = 0;
81321 int i;
81322
81323@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81324
81325 static void unset_module_core_ro_nx(struct module *mod)
81326 {
81327- set_page_attributes(mod->module_core + mod->core_text_size,
81328- mod->module_core + mod->core_size,
81329+ set_page_attributes(mod->module_core_rw,
81330+ mod->module_core_rw + mod->core_size_rw,
81331 set_memory_x);
81332- set_page_attributes(mod->module_core,
81333- mod->module_core + mod->core_ro_size,
81334+ set_page_attributes(mod->module_core_rx,
81335+ mod->module_core_rx + mod->core_size_rx,
81336 set_memory_rw);
81337 }
81338
81339 static void unset_module_init_ro_nx(struct module *mod)
81340 {
81341- set_page_attributes(mod->module_init + mod->init_text_size,
81342- mod->module_init + mod->init_size,
81343+ set_page_attributes(mod->module_init_rw,
81344+ mod->module_init_rw + mod->init_size_rw,
81345 set_memory_x);
81346- set_page_attributes(mod->module_init,
81347- mod->module_init + mod->init_ro_size,
81348+ set_page_attributes(mod->module_init_rx,
81349+ mod->module_init_rx + mod->init_size_rx,
81350 set_memory_rw);
81351 }
81352
81353@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81354 list_for_each_entry_rcu(mod, &modules, list) {
81355 if (mod->state == MODULE_STATE_UNFORMED)
81356 continue;
81357- if ((mod->module_core) && (mod->core_text_size)) {
81358- set_page_attributes(mod->module_core,
81359- mod->module_core + mod->core_text_size,
81360+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81361+ set_page_attributes(mod->module_core_rx,
81362+ mod->module_core_rx + mod->core_size_rx,
81363 set_memory_rw);
81364 }
81365- if ((mod->module_init) && (mod->init_text_size)) {
81366- set_page_attributes(mod->module_init,
81367- mod->module_init + mod->init_text_size,
81368+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81369+ set_page_attributes(mod->module_init_rx,
81370+ mod->module_init_rx + mod->init_size_rx,
81371 set_memory_rw);
81372 }
81373 }
81374@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81375 list_for_each_entry_rcu(mod, &modules, list) {
81376 if (mod->state == MODULE_STATE_UNFORMED)
81377 continue;
81378- if ((mod->module_core) && (mod->core_text_size)) {
81379- set_page_attributes(mod->module_core,
81380- mod->module_core + mod->core_text_size,
81381+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81382+ set_page_attributes(mod->module_core_rx,
81383+ mod->module_core_rx + mod->core_size_rx,
81384 set_memory_ro);
81385 }
81386- if ((mod->module_init) && (mod->init_text_size)) {
81387- set_page_attributes(mod->module_init,
81388- mod->module_init + mod->init_text_size,
81389+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81390+ set_page_attributes(mod->module_init_rx,
81391+ mod->module_init_rx + mod->init_size_rx,
81392 set_memory_ro);
81393 }
81394 }
81395@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81396
81397 /* This may be NULL, but that's OK */
81398 unset_module_init_ro_nx(mod);
81399- module_free(mod, mod->module_init);
81400+ module_free(mod, mod->module_init_rw);
81401+ module_free_exec(mod, mod->module_init_rx);
81402 kfree(mod->args);
81403 percpu_modfree(mod);
81404
81405 /* Free lock-classes: */
81406- lockdep_free_key_range(mod->module_core, mod->core_size);
81407+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81408+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81409
81410 /* Finally, free the core (containing the module structure) */
81411 unset_module_core_ro_nx(mod);
81412- module_free(mod, mod->module_core);
81413+ module_free_exec(mod, mod->module_core_rx);
81414+ module_free(mod, mod->module_core_rw);
81415
81416 #ifdef CONFIG_MPU
81417 update_protections(current->mm);
81418@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81419 int ret = 0;
81420 const struct kernel_symbol *ksym;
81421
81422+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81423+ int is_fs_load = 0;
81424+ int register_filesystem_found = 0;
81425+ char *p;
81426+
81427+ p = strstr(mod->args, "grsec_modharden_fs");
81428+ if (p) {
81429+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81430+ /* copy \0 as well */
81431+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81432+ is_fs_load = 1;
81433+ }
81434+#endif
81435+
81436 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81437 const char *name = info->strtab + sym[i].st_name;
81438
81439+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81440+ /* it's a real shame this will never get ripped and copied
81441+ upstream! ;(
81442+ */
81443+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81444+ register_filesystem_found = 1;
81445+#endif
81446+
81447 switch (sym[i].st_shndx) {
81448 case SHN_COMMON:
81449 /* We compiled with -fno-common. These are not
81450@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81451 ksym = resolve_symbol_wait(mod, info, name);
81452 /* Ok if resolved. */
81453 if (ksym && !IS_ERR(ksym)) {
81454+ pax_open_kernel();
81455 sym[i].st_value = ksym->value;
81456+ pax_close_kernel();
81457 break;
81458 }
81459
81460@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81461 secbase = (unsigned long)mod_percpu(mod);
81462 else
81463 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81464+ pax_open_kernel();
81465 sym[i].st_value += secbase;
81466+ pax_close_kernel();
81467 break;
81468 }
81469 }
81470
81471+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81472+ if (is_fs_load && !register_filesystem_found) {
81473+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81474+ ret = -EPERM;
81475+ }
81476+#endif
81477+
81478 return ret;
81479 }
81480
81481@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81482 || s->sh_entsize != ~0UL
81483 || strstarts(sname, ".init"))
81484 continue;
81485- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81486+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81487+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81488+ else
81489+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81490 pr_debug("\t%s\n", sname);
81491 }
81492- switch (m) {
81493- case 0: /* executable */
81494- mod->core_size = debug_align(mod->core_size);
81495- mod->core_text_size = mod->core_size;
81496- break;
81497- case 1: /* RO: text and ro-data */
81498- mod->core_size = debug_align(mod->core_size);
81499- mod->core_ro_size = mod->core_size;
81500- break;
81501- case 3: /* whole core */
81502- mod->core_size = debug_align(mod->core_size);
81503- break;
81504- }
81505 }
81506
81507 pr_debug("Init section allocation order:\n");
81508@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81509 || s->sh_entsize != ~0UL
81510 || !strstarts(sname, ".init"))
81511 continue;
81512- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81513- | INIT_OFFSET_MASK);
81514+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81515+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81516+ else
81517+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81518+ s->sh_entsize |= INIT_OFFSET_MASK;
81519 pr_debug("\t%s\n", sname);
81520 }
81521- switch (m) {
81522- case 0: /* executable */
81523- mod->init_size = debug_align(mod->init_size);
81524- mod->init_text_size = mod->init_size;
81525- break;
81526- case 1: /* RO: text and ro-data */
81527- mod->init_size = debug_align(mod->init_size);
81528- mod->init_ro_size = mod->init_size;
81529- break;
81530- case 3: /* whole init */
81531- mod->init_size = debug_align(mod->init_size);
81532- break;
81533- }
81534 }
81535 }
81536
81537@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81538
81539 /* Put symbol section at end of init part of module. */
81540 symsect->sh_flags |= SHF_ALLOC;
81541- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81542+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81543 info->index.sym) | INIT_OFFSET_MASK;
81544 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81545
81546@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81547 }
81548
81549 /* Append room for core symbols at end of core part. */
81550- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81551- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81552- mod->core_size += strtab_size;
81553+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81554+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81555+ mod->core_size_rx += strtab_size;
81556
81557 /* Put string table section at end of init part of module. */
81558 strsect->sh_flags |= SHF_ALLOC;
81559- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81560+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81561 info->index.str) | INIT_OFFSET_MASK;
81562 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81563 }
81564@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81565 /* Make sure we get permanent strtab: don't use info->strtab. */
81566 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81567
81568+ pax_open_kernel();
81569+
81570 /* Set types up while we still have access to sections. */
81571 for (i = 0; i < mod->num_symtab; i++)
81572 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81573
81574- mod->core_symtab = dst = mod->module_core + info->symoffs;
81575- mod->core_strtab = s = mod->module_core + info->stroffs;
81576+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81577+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81578 src = mod->symtab;
81579 for (ndst = i = 0; i < mod->num_symtab; i++) {
81580 if (i == 0 ||
81581@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81582 }
81583 }
81584 mod->core_num_syms = ndst;
81585+
81586+ pax_close_kernel();
81587 }
81588 #else
81589 static inline void layout_symtab(struct module *mod, struct load_info *info)
81590@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81591 return vmalloc_exec(size);
81592 }
81593
81594-static void *module_alloc_update_bounds(unsigned long size)
81595+static void *module_alloc_update_bounds_rw(unsigned long size)
81596 {
81597 void *ret = module_alloc(size);
81598
81599 if (ret) {
81600 mutex_lock(&module_mutex);
81601 /* Update module bounds. */
81602- if ((unsigned long)ret < module_addr_min)
81603- module_addr_min = (unsigned long)ret;
81604- if ((unsigned long)ret + size > module_addr_max)
81605- module_addr_max = (unsigned long)ret + size;
81606+ if ((unsigned long)ret < module_addr_min_rw)
81607+ module_addr_min_rw = (unsigned long)ret;
81608+ if ((unsigned long)ret + size > module_addr_max_rw)
81609+ module_addr_max_rw = (unsigned long)ret + size;
81610+ mutex_unlock(&module_mutex);
81611+ }
81612+ return ret;
81613+}
81614+
81615+static void *module_alloc_update_bounds_rx(unsigned long size)
81616+{
81617+ void *ret = module_alloc_exec(size);
81618+
81619+ if (ret) {
81620+ mutex_lock(&module_mutex);
81621+ /* Update module bounds. */
81622+ if ((unsigned long)ret < module_addr_min_rx)
81623+ module_addr_min_rx = (unsigned long)ret;
81624+ if ((unsigned long)ret + size > module_addr_max_rx)
81625+ module_addr_max_rx = (unsigned long)ret + size;
81626 mutex_unlock(&module_mutex);
81627 }
81628 return ret;
81629@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81630 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81631 {
81632 const char *modmagic = get_modinfo(info, "vermagic");
81633+ const char *license = get_modinfo(info, "license");
81634 int err;
81635
81636+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81637+ if (!license || !license_is_gpl_compatible(license))
81638+ return -ENOEXEC;
81639+#endif
81640+
81641 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81642 modmagic = NULL;
81643
81644@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81645 }
81646
81647 /* Set up license info based on the info section */
81648- set_license(mod, get_modinfo(info, "license"));
81649+ set_license(mod, license);
81650
81651 return 0;
81652 }
81653@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81654 void *ptr;
81655
81656 /* Do the allocs. */
81657- ptr = module_alloc_update_bounds(mod->core_size);
81658+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81659 /*
81660 * The pointer to this block is stored in the module structure
81661 * which is inside the block. Just mark it as not being a
81662@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81663 if (!ptr)
81664 return -ENOMEM;
81665
81666- memset(ptr, 0, mod->core_size);
81667- mod->module_core = ptr;
81668+ memset(ptr, 0, mod->core_size_rw);
81669+ mod->module_core_rw = ptr;
81670
81671- if (mod->init_size) {
81672- ptr = module_alloc_update_bounds(mod->init_size);
81673+ if (mod->init_size_rw) {
81674+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81675 /*
81676 * The pointer to this block is stored in the module structure
81677 * which is inside the block. This block doesn't need to be
81678@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81679 */
81680 kmemleak_ignore(ptr);
81681 if (!ptr) {
81682- module_free(mod, mod->module_core);
81683+ module_free(mod, mod->module_core_rw);
81684 return -ENOMEM;
81685 }
81686- memset(ptr, 0, mod->init_size);
81687- mod->module_init = ptr;
81688+ memset(ptr, 0, mod->init_size_rw);
81689+ mod->module_init_rw = ptr;
81690 } else
81691- mod->module_init = NULL;
81692+ mod->module_init_rw = NULL;
81693+
81694+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81695+ kmemleak_not_leak(ptr);
81696+ if (!ptr) {
81697+ if (mod->module_init_rw)
81698+ module_free(mod, mod->module_init_rw);
81699+ module_free(mod, mod->module_core_rw);
81700+ return -ENOMEM;
81701+ }
81702+
81703+ pax_open_kernel();
81704+ memset(ptr, 0, mod->core_size_rx);
81705+ pax_close_kernel();
81706+ mod->module_core_rx = ptr;
81707+
81708+ if (mod->init_size_rx) {
81709+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81710+ kmemleak_ignore(ptr);
81711+ if (!ptr && mod->init_size_rx) {
81712+ module_free_exec(mod, mod->module_core_rx);
81713+ if (mod->module_init_rw)
81714+ module_free(mod, mod->module_init_rw);
81715+ module_free(mod, mod->module_core_rw);
81716+ return -ENOMEM;
81717+ }
81718+
81719+ pax_open_kernel();
81720+ memset(ptr, 0, mod->init_size_rx);
81721+ pax_close_kernel();
81722+ mod->module_init_rx = ptr;
81723+ } else
81724+ mod->module_init_rx = NULL;
81725
81726 /* Transfer each section which specifies SHF_ALLOC */
81727 pr_debug("final section addresses:\n");
81728@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81729 if (!(shdr->sh_flags & SHF_ALLOC))
81730 continue;
81731
81732- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81733- dest = mod->module_init
81734- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81735- else
81736- dest = mod->module_core + shdr->sh_entsize;
81737+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81738+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81739+ dest = mod->module_init_rw
81740+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81741+ else
81742+ dest = mod->module_init_rx
81743+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81744+ } else {
81745+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81746+ dest = mod->module_core_rw + shdr->sh_entsize;
81747+ else
81748+ dest = mod->module_core_rx + shdr->sh_entsize;
81749+ }
81750+
81751+ if (shdr->sh_type != SHT_NOBITS) {
81752+
81753+#ifdef CONFIG_PAX_KERNEXEC
81754+#ifdef CONFIG_X86_64
81755+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81756+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81757+#endif
81758+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81759+ pax_open_kernel();
81760+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81761+ pax_close_kernel();
81762+ } else
81763+#endif
81764
81765- if (shdr->sh_type != SHT_NOBITS)
81766 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81767+ }
81768 /* Update sh_addr to point to copy in image. */
81769- shdr->sh_addr = (unsigned long)dest;
81770+
81771+#ifdef CONFIG_PAX_KERNEXEC
81772+ if (shdr->sh_flags & SHF_EXECINSTR)
81773+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81774+ else
81775+#endif
81776+
81777+ shdr->sh_addr = (unsigned long)dest;
81778 pr_debug("\t0x%lx %s\n",
81779 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81780 }
81781@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81782 * Do it before processing of module parameters, so the module
81783 * can provide parameter accessor functions of its own.
81784 */
81785- if (mod->module_init)
81786- flush_icache_range((unsigned long)mod->module_init,
81787- (unsigned long)mod->module_init
81788- + mod->init_size);
81789- flush_icache_range((unsigned long)mod->module_core,
81790- (unsigned long)mod->module_core + mod->core_size);
81791+ if (mod->module_init_rx)
81792+ flush_icache_range((unsigned long)mod->module_init_rx,
81793+ (unsigned long)mod->module_init_rx
81794+ + mod->init_size_rx);
81795+ flush_icache_range((unsigned long)mod->module_core_rx,
81796+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81797
81798 set_fs(old_fs);
81799 }
81800@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81801 static void module_deallocate(struct module *mod, struct load_info *info)
81802 {
81803 percpu_modfree(mod);
81804- module_free(mod, mod->module_init);
81805- module_free(mod, mod->module_core);
81806+ module_free_exec(mod, mod->module_init_rx);
81807+ module_free_exec(mod, mod->module_core_rx);
81808+ module_free(mod, mod->module_init_rw);
81809+ module_free(mod, mod->module_core_rw);
81810 }
81811
81812 int __weak module_finalize(const Elf_Ehdr *hdr,
81813@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81814 static int post_relocation(struct module *mod, const struct load_info *info)
81815 {
81816 /* Sort exception table now relocations are done. */
81817+ pax_open_kernel();
81818 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81819+ pax_close_kernel();
81820
81821 /* Copy relocated percpu area over. */
81822 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81823@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81824 MODULE_STATE_COMING, mod);
81825
81826 /* Set RO and NX regions for core */
81827- set_section_ro_nx(mod->module_core,
81828- mod->core_text_size,
81829- mod->core_ro_size,
81830- mod->core_size);
81831+ set_section_ro_nx(mod->module_core_rx,
81832+ mod->core_size_rx,
81833+ mod->core_size_rx,
81834+ mod->core_size_rx);
81835
81836 /* Set RO and NX regions for init */
81837- set_section_ro_nx(mod->module_init,
81838- mod->init_text_size,
81839- mod->init_ro_size,
81840- mod->init_size);
81841+ set_section_ro_nx(mod->module_init_rx,
81842+ mod->init_size_rx,
81843+ mod->init_size_rx,
81844+ mod->init_size_rx);
81845
81846 do_mod_ctors(mod);
81847 /* Start the module */
81848@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81849 mod->strtab = mod->core_strtab;
81850 #endif
81851 unset_module_init_ro_nx(mod);
81852- module_free(mod, mod->module_init);
81853- mod->module_init = NULL;
81854- mod->init_size = 0;
81855- mod->init_ro_size = 0;
81856- mod->init_text_size = 0;
81857+ module_free(mod, mod->module_init_rw);
81858+ module_free_exec(mod, mod->module_init_rx);
81859+ mod->module_init_rw = NULL;
81860+ mod->module_init_rx = NULL;
81861+ mod->init_size_rw = 0;
81862+ mod->init_size_rx = 0;
81863 mutex_unlock(&module_mutex);
81864 wake_up_all(&module_wq);
81865
81866@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81867 if (err)
81868 goto free_unload;
81869
81870+ /* Now copy in args */
81871+ mod->args = strndup_user(uargs, ~0UL >> 1);
81872+ if (IS_ERR(mod->args)) {
81873+ err = PTR_ERR(mod->args);
81874+ goto free_unload;
81875+ }
81876+
81877 /* Set up MODINFO_ATTR fields */
81878 setup_modinfo(mod, info);
81879
81880+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81881+ {
81882+ char *p, *p2;
81883+
81884+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81885+ 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);
81886+ err = -EPERM;
81887+ goto free_modinfo;
81888+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81889+ p += sizeof("grsec_modharden_normal") - 1;
81890+ p2 = strstr(p, "_");
81891+ if (p2) {
81892+ *p2 = '\0';
81893+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81894+ *p2 = '_';
81895+ }
81896+ err = -EPERM;
81897+ goto free_modinfo;
81898+ }
81899+ }
81900+#endif
81901+
81902 /* Fix up syms, so that st_value is a pointer to location. */
81903 err = simplify_symbols(mod, info);
81904 if (err < 0)
81905@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81906
81907 flush_module_icache(mod);
81908
81909- /* Now copy in args */
81910- mod->args = strndup_user(uargs, ~0UL >> 1);
81911- if (IS_ERR(mod->args)) {
81912- err = PTR_ERR(mod->args);
81913- goto free_arch_cleanup;
81914- }
81915-
81916 dynamic_debug_setup(info->debug, info->num_debug);
81917
81918 /* Finally it's fully formed, ready to start executing. */
81919@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81920 ddebug_cleanup:
81921 dynamic_debug_remove(info->debug);
81922 synchronize_sched();
81923- kfree(mod->args);
81924- free_arch_cleanup:
81925 module_arch_cleanup(mod);
81926 free_modinfo:
81927 free_modinfo(mod);
81928+ kfree(mod->args);
81929 free_unload:
81930 module_unload_free(mod);
81931 unlink_mod:
81932@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81933 unsigned long nextval;
81934
81935 /* At worse, next value is at end of module */
81936- if (within_module_init(addr, mod))
81937- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81938+ if (within_module_init_rx(addr, mod))
81939+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81940+ else if (within_module_init_rw(addr, mod))
81941+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81942+ else if (within_module_core_rx(addr, mod))
81943+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81944+ else if (within_module_core_rw(addr, mod))
81945+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81946 else
81947- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81948+ return NULL;
81949
81950 /* Scan for closest preceding symbol, and next symbol. (ELF
81951 starts real symbols at 1). */
81952@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81953 return 0;
81954
81955 seq_printf(m, "%s %u",
81956- mod->name, mod->init_size + mod->core_size);
81957+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81958 print_unload_info(m, mod);
81959
81960 /* Informative for users. */
81961@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81962 mod->state == MODULE_STATE_COMING ? "Loading":
81963 "Live");
81964 /* Used by oprofile and other similar tools. */
81965- seq_printf(m, " 0x%pK", mod->module_core);
81966+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81967
81968 /* Taints info */
81969 if (mod->taints)
81970@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81971
81972 static int __init proc_modules_init(void)
81973 {
81974+#ifndef CONFIG_GRKERNSEC_HIDESYM
81975+#ifdef CONFIG_GRKERNSEC_PROC_USER
81976+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81977+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81978+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81979+#else
81980 proc_create("modules", 0, NULL, &proc_modules_operations);
81981+#endif
81982+#else
81983+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81984+#endif
81985 return 0;
81986 }
81987 module_init(proc_modules_init);
81988@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81989 {
81990 struct module *mod;
81991
81992- if (addr < module_addr_min || addr > module_addr_max)
81993+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81994+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81995 return NULL;
81996
81997 list_for_each_entry_rcu(mod, &modules, list) {
81998 if (mod->state == MODULE_STATE_UNFORMED)
81999 continue;
82000- if (within_module_core(addr, mod)
82001- || within_module_init(addr, mod))
82002+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
82003 return mod;
82004 }
82005 return NULL;
82006@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
82007 */
82008 struct module *__module_text_address(unsigned long addr)
82009 {
82010- struct module *mod = __module_address(addr);
82011+ struct module *mod;
82012+
82013+#ifdef CONFIG_X86_32
82014+ addr = ktla_ktva(addr);
82015+#endif
82016+
82017+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
82018+ return NULL;
82019+
82020+ mod = __module_address(addr);
82021+
82022 if (mod) {
82023 /* Make sure it's within the text section. */
82024- if (!within(addr, mod->module_init, mod->init_text_size)
82025- && !within(addr, mod->module_core, mod->core_text_size))
82026+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82027 mod = NULL;
82028 }
82029 return mod;
82030diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82031index 7e3443f..b2a1e6b 100644
82032--- a/kernel/mutex-debug.c
82033+++ b/kernel/mutex-debug.c
82034@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82035 }
82036
82037 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82038- struct thread_info *ti)
82039+ struct task_struct *task)
82040 {
82041 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82042
82043 /* Mark the current thread as blocked on the lock: */
82044- ti->task->blocked_on = waiter;
82045+ task->blocked_on = waiter;
82046 }
82047
82048 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82049- struct thread_info *ti)
82050+ struct task_struct *task)
82051 {
82052 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82053- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82054- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82055- ti->task->blocked_on = NULL;
82056+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82057+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82058+ task->blocked_on = NULL;
82059
82060 list_del_init(&waiter->list);
82061 waiter->task = NULL;
82062diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82063index 0799fd3..d06ae3b 100644
82064--- a/kernel/mutex-debug.h
82065+++ b/kernel/mutex-debug.h
82066@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82067 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82068 extern void debug_mutex_add_waiter(struct mutex *lock,
82069 struct mutex_waiter *waiter,
82070- struct thread_info *ti);
82071+ struct task_struct *task);
82072 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82073- struct thread_info *ti);
82074+ struct task_struct *task);
82075 extern void debug_mutex_unlock(struct mutex *lock);
82076 extern void debug_mutex_init(struct mutex *lock, const char *name,
82077 struct lock_class_key *key);
82078diff --git a/kernel/mutex.c b/kernel/mutex.c
82079index a52ee7bb..f361f16 100644
82080--- a/kernel/mutex.c
82081+++ b/kernel/mutex.c
82082@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82083 node->locked = 1;
82084 return;
82085 }
82086- ACCESS_ONCE(prev->next) = node;
82087+ ACCESS_ONCE_RW(prev->next) = node;
82088 smp_wmb();
82089 /* Wait until the lock holder passes the lock down */
82090 while (!ACCESS_ONCE(node->locked))
82091@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82092 while (!(next = ACCESS_ONCE(node->next)))
82093 arch_mutex_cpu_relax();
82094 }
82095- ACCESS_ONCE(next->locked) = 1;
82096+ ACCESS_ONCE_RW(next->locked) = 1;
82097 smp_wmb();
82098 }
82099
82100@@ -514,7 +514,7 @@ slowpath:
82101 spin_lock_mutex(&lock->wait_lock, flags);
82102
82103 debug_mutex_lock_common(lock, &waiter);
82104- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82105+ debug_mutex_add_waiter(lock, &waiter, task);
82106
82107 /* add waiting tasks to the end of the waitqueue (FIFO): */
82108 list_add_tail(&waiter.list, &lock->wait_list);
82109@@ -565,7 +565,7 @@ slowpath:
82110 done:
82111 lock_acquired(&lock->dep_map, ip);
82112 /* got the lock - rejoice! */
82113- mutex_remove_waiter(lock, &waiter, current_thread_info());
82114+ mutex_remove_waiter(lock, &waiter, task);
82115 mutex_set_owner(lock);
82116
82117 if (!__builtin_constant_p(ww_ctx == NULL)) {
82118@@ -604,7 +604,7 @@ done:
82119 return 0;
82120
82121 err:
82122- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82123+ mutex_remove_waiter(lock, &waiter, task);
82124 spin_unlock_mutex(&lock->wait_lock, flags);
82125 debug_mutex_free_waiter(&waiter);
82126 mutex_release(&lock->dep_map, 1, ip);
82127diff --git a/kernel/notifier.c b/kernel/notifier.c
82128index 2d5cc4c..d9ea600 100644
82129--- a/kernel/notifier.c
82130+++ b/kernel/notifier.c
82131@@ -5,6 +5,7 @@
82132 #include <linux/rcupdate.h>
82133 #include <linux/vmalloc.h>
82134 #include <linux/reboot.h>
82135+#include <linux/mm.h>
82136
82137 /*
82138 * Notifier list for kernel code which wants to be called
82139@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82140 while ((*nl) != NULL) {
82141 if (n->priority > (*nl)->priority)
82142 break;
82143- nl = &((*nl)->next);
82144+ nl = (struct notifier_block **)&((*nl)->next);
82145 }
82146- n->next = *nl;
82147+ pax_open_kernel();
82148+ *(const void **)&n->next = *nl;
82149 rcu_assign_pointer(*nl, n);
82150+ pax_close_kernel();
82151 return 0;
82152 }
82153
82154@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82155 return 0;
82156 if (n->priority > (*nl)->priority)
82157 break;
82158- nl = &((*nl)->next);
82159+ nl = (struct notifier_block **)&((*nl)->next);
82160 }
82161- n->next = *nl;
82162+ pax_open_kernel();
82163+ *(const void **)&n->next = *nl;
82164 rcu_assign_pointer(*nl, n);
82165+ pax_close_kernel();
82166 return 0;
82167 }
82168
82169@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82170 {
82171 while ((*nl) != NULL) {
82172 if ((*nl) == n) {
82173+ pax_open_kernel();
82174 rcu_assign_pointer(*nl, n->next);
82175+ pax_close_kernel();
82176 return 0;
82177 }
82178- nl = &((*nl)->next);
82179+ nl = (struct notifier_block **)&((*nl)->next);
82180 }
82181 return -ENOENT;
82182 }
82183diff --git a/kernel/panic.c b/kernel/panic.c
82184index 8018646..b6a5b4f 100644
82185--- a/kernel/panic.c
82186+++ b/kernel/panic.c
82187@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82188 disable_trace_on_warning();
82189
82190 pr_warn("------------[ cut here ]------------\n");
82191- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82192+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82193 raw_smp_processor_id(), current->pid, file, line, caller);
82194
82195 if (args)
82196@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82197 */
82198 void __stack_chk_fail(void)
82199 {
82200- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82201+ dump_stack();
82202+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82203 __builtin_return_address(0));
82204 }
82205 EXPORT_SYMBOL(__stack_chk_fail);
82206diff --git a/kernel/pid.c b/kernel/pid.c
82207index ebe5e80..5d6d634 100644
82208--- a/kernel/pid.c
82209+++ b/kernel/pid.c
82210@@ -33,6 +33,7 @@
82211 #include <linux/rculist.h>
82212 #include <linux/bootmem.h>
82213 #include <linux/hash.h>
82214+#include <linux/security.h>
82215 #include <linux/pid_namespace.h>
82216 #include <linux/init_task.h>
82217 #include <linux/syscalls.h>
82218@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82219
82220 int pid_max = PID_MAX_DEFAULT;
82221
82222-#define RESERVED_PIDS 300
82223+#define RESERVED_PIDS 500
82224
82225 int pid_max_min = RESERVED_PIDS + 1;
82226 int pid_max_max = PID_MAX_LIMIT;
82227@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
82228 */
82229 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82230 {
82231+ struct task_struct *task;
82232+
82233 rcu_lockdep_assert(rcu_read_lock_held(),
82234 "find_task_by_pid_ns() needs rcu_read_lock()"
82235 " protection");
82236- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82237+
82238+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82239+
82240+ if (gr_pid_is_chrooted(task))
82241+ return NULL;
82242+
82243+ return task;
82244 }
82245
82246 struct task_struct *find_task_by_vpid(pid_t vnr)
82247@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82248 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82249 }
82250
82251+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82252+{
82253+ rcu_lockdep_assert(rcu_read_lock_held(),
82254+ "find_task_by_pid_ns() needs rcu_read_lock()"
82255+ " protection");
82256+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82257+}
82258+
82259 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82260 {
82261 struct pid *pid;
82262diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82263index 601bb36..f7e6f34 100644
82264--- a/kernel/pid_namespace.c
82265+++ b/kernel/pid_namespace.c
82266@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82267 void __user *buffer, size_t *lenp, loff_t *ppos)
82268 {
82269 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82270- struct ctl_table tmp = *table;
82271+ ctl_table_no_const tmp = *table;
82272
82273 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82274 return -EPERM;
82275diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82276index c7f31aa..2b44977 100644
82277--- a/kernel/posix-cpu-timers.c
82278+++ b/kernel/posix-cpu-timers.c
82279@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82280
82281 static __init int init_posix_cpu_timers(void)
82282 {
82283- struct k_clock process = {
82284+ static struct k_clock process = {
82285 .clock_getres = process_cpu_clock_getres,
82286 .clock_get = process_cpu_clock_get,
82287 .timer_create = process_cpu_timer_create,
82288 .nsleep = process_cpu_nsleep,
82289 .nsleep_restart = process_cpu_nsleep_restart,
82290 };
82291- struct k_clock thread = {
82292+ static struct k_clock thread = {
82293 .clock_getres = thread_cpu_clock_getres,
82294 .clock_get = thread_cpu_clock_get,
82295 .timer_create = thread_cpu_timer_create,
82296diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82297index 424c2d4..679242f 100644
82298--- a/kernel/posix-timers.c
82299+++ b/kernel/posix-timers.c
82300@@ -43,6 +43,7 @@
82301 #include <linux/hash.h>
82302 #include <linux/posix-clock.h>
82303 #include <linux/posix-timers.h>
82304+#include <linux/grsecurity.h>
82305 #include <linux/syscalls.h>
82306 #include <linux/wait.h>
82307 #include <linux/workqueue.h>
82308@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82309 * which we beg off on and pass to do_sys_settimeofday().
82310 */
82311
82312-static struct k_clock posix_clocks[MAX_CLOCKS];
82313+static struct k_clock *posix_clocks[MAX_CLOCKS];
82314
82315 /*
82316 * These ones are defined below.
82317@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82318 */
82319 static __init int init_posix_timers(void)
82320 {
82321- struct k_clock clock_realtime = {
82322+ static struct k_clock clock_realtime = {
82323 .clock_getres = hrtimer_get_res,
82324 .clock_get = posix_clock_realtime_get,
82325 .clock_set = posix_clock_realtime_set,
82326@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82327 .timer_get = common_timer_get,
82328 .timer_del = common_timer_del,
82329 };
82330- struct k_clock clock_monotonic = {
82331+ static struct k_clock clock_monotonic = {
82332 .clock_getres = hrtimer_get_res,
82333 .clock_get = posix_ktime_get_ts,
82334 .nsleep = common_nsleep,
82335@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82336 .timer_get = common_timer_get,
82337 .timer_del = common_timer_del,
82338 };
82339- struct k_clock clock_monotonic_raw = {
82340+ static struct k_clock clock_monotonic_raw = {
82341 .clock_getres = hrtimer_get_res,
82342 .clock_get = posix_get_monotonic_raw,
82343 };
82344- struct k_clock clock_realtime_coarse = {
82345+ static struct k_clock clock_realtime_coarse = {
82346 .clock_getres = posix_get_coarse_res,
82347 .clock_get = posix_get_realtime_coarse,
82348 };
82349- struct k_clock clock_monotonic_coarse = {
82350+ static struct k_clock clock_monotonic_coarse = {
82351 .clock_getres = posix_get_coarse_res,
82352 .clock_get = posix_get_monotonic_coarse,
82353 };
82354- struct k_clock clock_tai = {
82355+ static struct k_clock clock_tai = {
82356 .clock_getres = hrtimer_get_res,
82357 .clock_get = posix_get_tai,
82358 .nsleep = common_nsleep,
82359@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82360 .timer_get = common_timer_get,
82361 .timer_del = common_timer_del,
82362 };
82363- struct k_clock clock_boottime = {
82364+ static struct k_clock clock_boottime = {
82365 .clock_getres = hrtimer_get_res,
82366 .clock_get = posix_get_boottime,
82367 .nsleep = common_nsleep,
82368@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82369 return;
82370 }
82371
82372- posix_clocks[clock_id] = *new_clock;
82373+ posix_clocks[clock_id] = new_clock;
82374 }
82375 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82376
82377@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82378 return (id & CLOCKFD_MASK) == CLOCKFD ?
82379 &clock_posix_dynamic : &clock_posix_cpu;
82380
82381- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82382+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82383 return NULL;
82384- return &posix_clocks[id];
82385+ return posix_clocks[id];
82386 }
82387
82388 static int common_timer_create(struct k_itimer *new_timer)
82389@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82390 struct k_clock *kc = clockid_to_kclock(which_clock);
82391 struct k_itimer *new_timer;
82392 int error, new_timer_id;
82393- sigevent_t event;
82394+ sigevent_t event = { };
82395 int it_id_set = IT_ID_NOT_SET;
82396
82397 if (!kc)
82398@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82399 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82400 return -EFAULT;
82401
82402+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82403+ have their clock_set fptr set to a nosettime dummy function
82404+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82405+ call common_clock_set, which calls do_sys_settimeofday, which
82406+ we hook
82407+ */
82408+
82409 return kc->clock_set(which_clock, &new_tp);
82410 }
82411
82412diff --git a/kernel/power/process.c b/kernel/power/process.c
82413index 06ec886..9dba35e 100644
82414--- a/kernel/power/process.c
82415+++ b/kernel/power/process.c
82416@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82417 unsigned int elapsed_msecs;
82418 bool wakeup = false;
82419 int sleep_usecs = USEC_PER_MSEC;
82420+ bool timedout = false;
82421
82422 do_gettimeofday(&start);
82423
82424@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82425
82426 while (true) {
82427 todo = 0;
82428+ if (time_after(jiffies, end_time))
82429+ timedout = true;
82430 read_lock(&tasklist_lock);
82431 do_each_thread(g, p) {
82432 if (p == current || !freeze_task(p))
82433 continue;
82434
82435- if (!freezer_should_skip(p))
82436+ if (!freezer_should_skip(p)) {
82437 todo++;
82438+ if (timedout) {
82439+ printk(KERN_ERR "Task refusing to freeze:\n");
82440+ sched_show_task(p);
82441+ }
82442+ }
82443 } while_each_thread(g, p);
82444 read_unlock(&tasklist_lock);
82445
82446@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82447 todo += wq_busy;
82448 }
82449
82450- if (!todo || time_after(jiffies, end_time))
82451+ if (!todo || timedout)
82452 break;
82453
82454 if (pm_wakeup_pending()) {
82455diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82456index 5b5a708..ec7637e 100644
82457--- a/kernel/printk/printk.c
82458+++ b/kernel/printk/printk.c
82459@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82460 if (from_file && type != SYSLOG_ACTION_OPEN)
82461 return 0;
82462
82463+#ifdef CONFIG_GRKERNSEC_DMESG
82464+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82465+ return -EPERM;
82466+#endif
82467+
82468 if (syslog_action_restricted(type)) {
82469 if (capable(CAP_SYSLOG))
82470 return 0;
82471diff --git a/kernel/profile.c b/kernel/profile.c
82472index 6631e1e..310c266 100644
82473--- a/kernel/profile.c
82474+++ b/kernel/profile.c
82475@@ -37,7 +37,7 @@ struct profile_hit {
82476 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82477 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82478
82479-static atomic_t *prof_buffer;
82480+static atomic_unchecked_t *prof_buffer;
82481 static unsigned long prof_len, prof_shift;
82482
82483 int prof_on __read_mostly;
82484@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82485 hits[i].pc = 0;
82486 continue;
82487 }
82488- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82489+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82490 hits[i].hits = hits[i].pc = 0;
82491 }
82492 }
82493@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82494 * Add the current hit(s) and flush the write-queue out
82495 * to the global buffer:
82496 */
82497- atomic_add(nr_hits, &prof_buffer[pc]);
82498+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82499 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82500- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82501+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82502 hits[i].pc = hits[i].hits = 0;
82503 }
82504 out:
82505@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82506 {
82507 unsigned long pc;
82508 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82509- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82510+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82511 }
82512 #endif /* !CONFIG_SMP */
82513
82514@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82515 return -EFAULT;
82516 buf++; p++; count--; read++;
82517 }
82518- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82519+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82520 if (copy_to_user(buf, (void *)pnt, count))
82521 return -EFAULT;
82522 read += count;
82523@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82524 }
82525 #endif
82526 profile_discard_flip_buffers();
82527- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82528+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82529 return count;
82530 }
82531
82532diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82533index a146ee3..ffed4c3 100644
82534--- a/kernel/ptrace.c
82535+++ b/kernel/ptrace.c
82536@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82537 if (seize)
82538 flags |= PT_SEIZED;
82539 rcu_read_lock();
82540- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82541+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82542 flags |= PT_PTRACE_CAP;
82543 rcu_read_unlock();
82544 task->ptrace = flags;
82545@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82546 break;
82547 return -EIO;
82548 }
82549- if (copy_to_user(dst, buf, retval))
82550+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82551 return -EFAULT;
82552 copied += retval;
82553 src += retval;
82554@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82555 bool seized = child->ptrace & PT_SEIZED;
82556 int ret = -EIO;
82557 siginfo_t siginfo, *si;
82558- void __user *datavp = (void __user *) data;
82559+ void __user *datavp = (__force void __user *) data;
82560 unsigned long __user *datalp = datavp;
82561 unsigned long flags;
82562
82563@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82564 goto out;
82565 }
82566
82567+ if (gr_handle_ptrace(child, request)) {
82568+ ret = -EPERM;
82569+ goto out_put_task_struct;
82570+ }
82571+
82572 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82573 ret = ptrace_attach(child, request, addr, data);
82574 /*
82575 * Some architectures need to do book-keeping after
82576 * a ptrace attach.
82577 */
82578- if (!ret)
82579+ if (!ret) {
82580 arch_ptrace_attach(child);
82581+ gr_audit_ptrace(child);
82582+ }
82583 goto out_put_task_struct;
82584 }
82585
82586@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82587 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82588 if (copied != sizeof(tmp))
82589 return -EIO;
82590- return put_user(tmp, (unsigned long __user *)data);
82591+ return put_user(tmp, (__force unsigned long __user *)data);
82592 }
82593
82594 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82595@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82596 }
82597
82598 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82599- compat_long_t addr, compat_long_t data)
82600+ compat_ulong_t addr, compat_ulong_t data)
82601 {
82602 struct task_struct *child;
82603 long ret;
82604@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82605 goto out;
82606 }
82607
82608+ if (gr_handle_ptrace(child, request)) {
82609+ ret = -EPERM;
82610+ goto out_put_task_struct;
82611+ }
82612+
82613 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82614 ret = ptrace_attach(child, request, addr, data);
82615 /*
82616 * Some architectures need to do book-keeping after
82617 * a ptrace attach.
82618 */
82619- if (!ret)
82620+ if (!ret) {
82621 arch_ptrace_attach(child);
82622+ gr_audit_ptrace(child);
82623+ }
82624 goto out_put_task_struct;
82625 }
82626
82627diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82628index cce6ba8..7c758b1f 100644
82629--- a/kernel/rcupdate.c
82630+++ b/kernel/rcupdate.c
82631@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82632 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82633 */
82634 if (till_stall_check < 3) {
82635- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82636+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82637 till_stall_check = 3;
82638 } else if (till_stall_check > 300) {
82639- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82640+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82641 till_stall_check = 300;
82642 }
82643 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82644diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82645index aa34411..4832cd4 100644
82646--- a/kernel/rcutiny.c
82647+++ b/kernel/rcutiny.c
82648@@ -45,7 +45,7 @@
82649 /* Forward declarations for rcutiny_plugin.h. */
82650 struct rcu_ctrlblk;
82651 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82652-static void rcu_process_callbacks(struct softirq_action *unused);
82653+static void rcu_process_callbacks(void);
82654 static void __call_rcu(struct rcu_head *head,
82655 void (*func)(struct rcu_head *rcu),
82656 struct rcu_ctrlblk *rcp);
82657@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82658 false));
82659 }
82660
82661-static void rcu_process_callbacks(struct softirq_action *unused)
82662+static __latent_entropy void rcu_process_callbacks(void)
82663 {
82664 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82665 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82666diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82667index f4871e5..8ef5741 100644
82668--- a/kernel/rcutorture.c
82669+++ b/kernel/rcutorture.c
82670@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82671 { 0 };
82672 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82673 { 0 };
82674-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82675-static atomic_t n_rcu_torture_alloc;
82676-static atomic_t n_rcu_torture_alloc_fail;
82677-static atomic_t n_rcu_torture_free;
82678-static atomic_t n_rcu_torture_mberror;
82679-static atomic_t n_rcu_torture_error;
82680+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82681+static atomic_unchecked_t n_rcu_torture_alloc;
82682+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82683+static atomic_unchecked_t n_rcu_torture_free;
82684+static atomic_unchecked_t n_rcu_torture_mberror;
82685+static atomic_unchecked_t n_rcu_torture_error;
82686 static long n_rcu_torture_barrier_error;
82687 static long n_rcu_torture_boost_ktrerror;
82688 static long n_rcu_torture_boost_rterror;
82689@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82690
82691 spin_lock_bh(&rcu_torture_lock);
82692 if (list_empty(&rcu_torture_freelist)) {
82693- atomic_inc(&n_rcu_torture_alloc_fail);
82694+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82695 spin_unlock_bh(&rcu_torture_lock);
82696 return NULL;
82697 }
82698- atomic_inc(&n_rcu_torture_alloc);
82699+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82700 p = rcu_torture_freelist.next;
82701 list_del_init(p);
82702 spin_unlock_bh(&rcu_torture_lock);
82703@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82704 static void
82705 rcu_torture_free(struct rcu_torture *p)
82706 {
82707- atomic_inc(&n_rcu_torture_free);
82708+ atomic_inc_unchecked(&n_rcu_torture_free);
82709 spin_lock_bh(&rcu_torture_lock);
82710 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82711 spin_unlock_bh(&rcu_torture_lock);
82712@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82713 i = rp->rtort_pipe_count;
82714 if (i > RCU_TORTURE_PIPE_LEN)
82715 i = RCU_TORTURE_PIPE_LEN;
82716- atomic_inc(&rcu_torture_wcount[i]);
82717+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82718 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82719 rp->rtort_mbtest = 0;
82720 rcu_torture_free(rp);
82721@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82722 i = rp->rtort_pipe_count;
82723 if (i > RCU_TORTURE_PIPE_LEN)
82724 i = RCU_TORTURE_PIPE_LEN;
82725- atomic_inc(&rcu_torture_wcount[i]);
82726+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82727 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82728 rp->rtort_mbtest = 0;
82729 list_del(&rp->rtort_free);
82730@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82731 i = old_rp->rtort_pipe_count;
82732 if (i > RCU_TORTURE_PIPE_LEN)
82733 i = RCU_TORTURE_PIPE_LEN;
82734- atomic_inc(&rcu_torture_wcount[i]);
82735+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82736 old_rp->rtort_pipe_count++;
82737 cur_ops->deferred_free(old_rp);
82738 }
82739@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82740 return;
82741 }
82742 if (p->rtort_mbtest == 0)
82743- atomic_inc(&n_rcu_torture_mberror);
82744+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82745 spin_lock(&rand_lock);
82746 cur_ops->read_delay(&rand);
82747 n_rcu_torture_timers++;
82748@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82749 continue;
82750 }
82751 if (p->rtort_mbtest == 0)
82752- atomic_inc(&n_rcu_torture_mberror);
82753+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82754 cur_ops->read_delay(&rand);
82755 preempt_disable();
82756 pipe_count = p->rtort_pipe_count;
82757@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82758 rcu_torture_current,
82759 rcu_torture_current_version,
82760 list_empty(&rcu_torture_freelist),
82761- atomic_read(&n_rcu_torture_alloc),
82762- atomic_read(&n_rcu_torture_alloc_fail),
82763- atomic_read(&n_rcu_torture_free));
82764+ atomic_read_unchecked(&n_rcu_torture_alloc),
82765+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82766+ atomic_read_unchecked(&n_rcu_torture_free));
82767 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82768- atomic_read(&n_rcu_torture_mberror),
82769+ atomic_read_unchecked(&n_rcu_torture_mberror),
82770 n_rcu_torture_boost_ktrerror,
82771 n_rcu_torture_boost_rterror);
82772 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82773@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82774 n_barrier_attempts,
82775 n_rcu_torture_barrier_error);
82776 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82777- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82778+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82779 n_rcu_torture_barrier_error != 0 ||
82780 n_rcu_torture_boost_ktrerror != 0 ||
82781 n_rcu_torture_boost_rterror != 0 ||
82782 n_rcu_torture_boost_failure != 0 ||
82783 i > 1) {
82784 cnt += sprintf(&page[cnt], "!!! ");
82785- atomic_inc(&n_rcu_torture_error);
82786+ atomic_inc_unchecked(&n_rcu_torture_error);
82787 WARN_ON_ONCE(1);
82788 }
82789 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82790@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82791 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82792 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82793 cnt += sprintf(&page[cnt], " %d",
82794- atomic_read(&rcu_torture_wcount[i]));
82795+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82796 }
82797 cnt += sprintf(&page[cnt], "\n");
82798 if (cur_ops->stats)
82799@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82800
82801 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82802
82803- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82804+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82805 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82806 else if (n_online_successes != n_online_attempts ||
82807 n_offline_successes != n_offline_attempts)
82808@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82809
82810 rcu_torture_current = NULL;
82811 rcu_torture_current_version = 0;
82812- atomic_set(&n_rcu_torture_alloc, 0);
82813- atomic_set(&n_rcu_torture_alloc_fail, 0);
82814- atomic_set(&n_rcu_torture_free, 0);
82815- atomic_set(&n_rcu_torture_mberror, 0);
82816- atomic_set(&n_rcu_torture_error, 0);
82817+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82818+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82819+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82820+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82821+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82822 n_rcu_torture_barrier_error = 0;
82823 n_rcu_torture_boost_ktrerror = 0;
82824 n_rcu_torture_boost_rterror = 0;
82825 n_rcu_torture_boost_failure = 0;
82826 n_rcu_torture_boosts = 0;
82827 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82828- atomic_set(&rcu_torture_wcount[i], 0);
82829+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82830 for_each_possible_cpu(cpu) {
82831 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82832 per_cpu(rcu_torture_count, cpu)[i] = 0;
82833diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82834index 068de3a..5e7db2f 100644
82835--- a/kernel/rcutree.c
82836+++ b/kernel/rcutree.c
82837@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82838 rcu_prepare_for_idle(smp_processor_id());
82839 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82840 smp_mb__before_atomic_inc(); /* See above. */
82841- atomic_inc(&rdtp->dynticks);
82842+ atomic_inc_unchecked(&rdtp->dynticks);
82843 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82844- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82845+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82846
82847 /*
82848 * It is illegal to enter an extended quiescent state while
82849@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82850 int user)
82851 {
82852 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82853- atomic_inc(&rdtp->dynticks);
82854+ atomic_inc_unchecked(&rdtp->dynticks);
82855 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82856 smp_mb__after_atomic_inc(); /* See above. */
82857- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82858+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82859 rcu_cleanup_after_idle(smp_processor_id());
82860 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82861 if (!user && !is_idle_task(current)) {
82862@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82863 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82864
82865 if (rdtp->dynticks_nmi_nesting == 0 &&
82866- (atomic_read(&rdtp->dynticks) & 0x1))
82867+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82868 return;
82869 rdtp->dynticks_nmi_nesting++;
82870 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82871- atomic_inc(&rdtp->dynticks);
82872+ atomic_inc_unchecked(&rdtp->dynticks);
82873 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82874 smp_mb__after_atomic_inc(); /* See above. */
82875- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82876+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82877 }
82878
82879 /**
82880@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82881 return;
82882 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82883 smp_mb__before_atomic_inc(); /* See above. */
82884- atomic_inc(&rdtp->dynticks);
82885+ atomic_inc_unchecked(&rdtp->dynticks);
82886 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82887- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82888+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82889 }
82890
82891 /**
82892@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82893 int ret;
82894
82895 preempt_disable();
82896- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82897+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82898 preempt_enable();
82899 return ret;
82900 }
82901@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82902 */
82903 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82904 {
82905- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82906+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82907 return (rdp->dynticks_snap & 0x1) == 0;
82908 }
82909
82910@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82911 unsigned int curr;
82912 unsigned int snap;
82913
82914- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82915+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82916 snap = (unsigned int)rdp->dynticks_snap;
82917
82918 /*
82919@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82920 rdp = this_cpu_ptr(rsp->rda);
82921 rcu_preempt_check_blocked_tasks(rnp);
82922 rnp->qsmask = rnp->qsmaskinit;
82923- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82924+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82925 WARN_ON_ONCE(rnp->completed != rsp->completed);
82926- ACCESS_ONCE(rnp->completed) = rsp->completed;
82927+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82928 if (rnp == rdp->mynode)
82929 __note_gp_changes(rsp, rnp, rdp);
82930 rcu_preempt_boost_start_gp(rnp);
82931@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82932 */
82933 rcu_for_each_node_breadth_first(rsp, rnp) {
82934 raw_spin_lock_irq(&rnp->lock);
82935- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82936+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82937 rdp = this_cpu_ptr(rsp->rda);
82938 if (rnp == rdp->mynode)
82939 __note_gp_changes(rsp, rnp, rdp);
82940@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82941 rsp->qlen += rdp->qlen;
82942 rdp->n_cbs_orphaned += rdp->qlen;
82943 rdp->qlen_lazy = 0;
82944- ACCESS_ONCE(rdp->qlen) = 0;
82945+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82946 }
82947
82948 /*
82949@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82950 }
82951 smp_mb(); /* List handling before counting for rcu_barrier(). */
82952 rdp->qlen_lazy -= count_lazy;
82953- ACCESS_ONCE(rdp->qlen) -= count;
82954+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82955 rdp->n_cbs_invoked += count;
82956
82957 /* Reinstate batch limit if we have worked down the excess. */
82958@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82959 /*
82960 * Do RCU core processing for the current CPU.
82961 */
82962-static void rcu_process_callbacks(struct softirq_action *unused)
82963+static __latent_entropy void rcu_process_callbacks(void)
82964 {
82965 struct rcu_state *rsp;
82966
82967@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82968 local_irq_restore(flags);
82969 return;
82970 }
82971- ACCESS_ONCE(rdp->qlen)++;
82972+ ACCESS_ONCE_RW(rdp->qlen)++;
82973 if (lazy)
82974 rdp->qlen_lazy++;
82975 else
82976@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82977 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82978 * course be required on a 64-bit system.
82979 */
82980- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82981+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82982 (ulong)atomic_long_read(&rsp->expedited_done) +
82983 ULONG_MAX / 8)) {
82984 synchronize_sched();
82985- atomic_long_inc(&rsp->expedited_wrap);
82986+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82987 return;
82988 }
82989
82990@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82991 * Take a ticket. Note that atomic_inc_return() implies a
82992 * full memory barrier.
82993 */
82994- snap = atomic_long_inc_return(&rsp->expedited_start);
82995+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82996 firstsnap = snap;
82997 get_online_cpus();
82998 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82999@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
83000 synchronize_sched_expedited_cpu_stop,
83001 NULL) == -EAGAIN) {
83002 put_online_cpus();
83003- atomic_long_inc(&rsp->expedited_tryfail);
83004+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
83005
83006 /* Check to see if someone else did our work for us. */
83007 s = atomic_long_read(&rsp->expedited_done);
83008 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83009 /* ensure test happens before caller kfree */
83010 smp_mb__before_atomic_inc(); /* ^^^ */
83011- atomic_long_inc(&rsp->expedited_workdone1);
83012+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
83013 return;
83014 }
83015
83016@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
83017 udelay(trycount * num_online_cpus());
83018 } else {
83019 wait_rcu_gp(call_rcu_sched);
83020- atomic_long_inc(&rsp->expedited_normal);
83021+ atomic_long_inc_unchecked(&rsp->expedited_normal);
83022 return;
83023 }
83024
83025@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
83026 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83027 /* ensure test happens before caller kfree */
83028 smp_mb__before_atomic_inc(); /* ^^^ */
83029- atomic_long_inc(&rsp->expedited_workdone2);
83030+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83031 return;
83032 }
83033
83034@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83035 * period works for us.
83036 */
83037 get_online_cpus();
83038- snap = atomic_long_read(&rsp->expedited_start);
83039+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83040 smp_mb(); /* ensure read is before try_stop_cpus(). */
83041 }
83042- atomic_long_inc(&rsp->expedited_stoppedcpus);
83043+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83044
83045 /*
83046 * Everyone up to our most recent fetch is covered by our grace
83047@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83048 * than we did already did their update.
83049 */
83050 do {
83051- atomic_long_inc(&rsp->expedited_done_tries);
83052+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83053 s = atomic_long_read(&rsp->expedited_done);
83054 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83055 /* ensure test happens before caller kfree */
83056 smp_mb__before_atomic_inc(); /* ^^^ */
83057- atomic_long_inc(&rsp->expedited_done_lost);
83058+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83059 break;
83060 }
83061 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83062- atomic_long_inc(&rsp->expedited_done_exit);
83063+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83064
83065 put_online_cpus();
83066 }
83067@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83068 * ACCESS_ONCE() to prevent the compiler from speculating
83069 * the increment to precede the early-exit check.
83070 */
83071- ACCESS_ONCE(rsp->n_barrier_done)++;
83072+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83073 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83074 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83075 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83076@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83077
83078 /* Increment ->n_barrier_done to prevent duplicate work. */
83079 smp_mb(); /* Keep increment after above mechanism. */
83080- ACCESS_ONCE(rsp->n_barrier_done)++;
83081+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83082 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83083 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83084 smp_mb(); /* Keep increment before caller's subsequent code. */
83085@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83086 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83087 init_callback_list(rdp);
83088 rdp->qlen_lazy = 0;
83089- ACCESS_ONCE(rdp->qlen) = 0;
83090+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83091 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83092 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83093- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83094+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83095 rdp->cpu = cpu;
83096 rdp->rsp = rsp;
83097 rcu_boot_init_nocb_percpu_data(rdp);
83098@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83099 rdp->blimit = blimit;
83100 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83101 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83102- atomic_set(&rdp->dynticks->dynticks,
83103- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83104+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83105+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83106 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83107
83108 /* Add CPU to rcu_node bitmasks. */
83109diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83110index b383258..2440c1e 100644
83111--- a/kernel/rcutree.h
83112+++ b/kernel/rcutree.h
83113@@ -87,7 +87,7 @@ struct rcu_dynticks {
83114 long long dynticks_nesting; /* Track irq/process nesting level. */
83115 /* Process level is worth LLONG_MAX/2. */
83116 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83117- atomic_t dynticks; /* Even value for idle, else odd. */
83118+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83119 #ifdef CONFIG_RCU_FAST_NO_HZ
83120 bool all_lazy; /* Are all CPU's CBs lazy? */
83121 unsigned long nonlazy_posted;
83122@@ -419,17 +419,17 @@ struct rcu_state {
83123 /* _rcu_barrier(). */
83124 /* End of fields guarded by barrier_mutex. */
83125
83126- atomic_long_t expedited_start; /* Starting ticket. */
83127- atomic_long_t expedited_done; /* Done ticket. */
83128- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83129- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83130- atomic_long_t expedited_workdone1; /* # done by others #1. */
83131- atomic_long_t expedited_workdone2; /* # done by others #2. */
83132- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83133- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83134- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83135- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83136- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83137+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83138+ atomic_long_t expedited_done; /* Done ticket. */
83139+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83140+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83141+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83142+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83143+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83144+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83145+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83146+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83147+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83148
83149 unsigned long jiffies_force_qs; /* Time at which to invoke */
83150 /* force_quiescent_state(). */
83151diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83152index 769e12e..7b2139b 100644
83153--- a/kernel/rcutree_plugin.h
83154+++ b/kernel/rcutree_plugin.h
83155@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83156
83157 /* Clean up and exit. */
83158 smp_mb(); /* ensure expedited GP seen before counter increment. */
83159- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83160+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83161 unlock_mb_ret:
83162 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83163 mb_ret:
83164@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83165 free_cpumask_var(cm);
83166 }
83167
83168-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83169+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83170 .store = &rcu_cpu_kthread_task,
83171 .thread_should_run = rcu_cpu_kthread_should_run,
83172 .thread_fn = rcu_cpu_kthread,
83173@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83174 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83175 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83176 cpu, ticks_value, ticks_title,
83177- atomic_read(&rdtp->dynticks) & 0xfff,
83178+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83179 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83180 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83181 fast_no_hz);
83182@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83183
83184 /* Enqueue the callback on the nocb list and update counts. */
83185 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83186- ACCESS_ONCE(*old_rhpp) = rhp;
83187+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83188 atomic_long_add(rhcount, &rdp->nocb_q_count);
83189 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83190
83191@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83192 * Extract queued callbacks, update counts, and wait
83193 * for a grace period to elapse.
83194 */
83195- ACCESS_ONCE(rdp->nocb_head) = NULL;
83196+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83197 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83198 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83199 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83200- ACCESS_ONCE(rdp->nocb_p_count) += c;
83201- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83202+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83203+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83204 rcu_nocb_wait_gp(rdp);
83205
83206 /* Each pass through the following loop invokes a callback. */
83207@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83208 list = next;
83209 }
83210 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83211- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83212- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83213+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83214+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83215 rdp->n_nocbs_invoked += c;
83216 }
83217 return 0;
83218@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83219 t = kthread_run(rcu_nocb_kthread, rdp,
83220 "rcuo%c/%d", rsp->abbr, cpu);
83221 BUG_ON(IS_ERR(t));
83222- ACCESS_ONCE(rdp->nocb_kthread) = t;
83223+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83224 }
83225 }
83226
83227diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83228index cf6c174..a8f4b50 100644
83229--- a/kernel/rcutree_trace.c
83230+++ b/kernel/rcutree_trace.c
83231@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83232 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83233 rdp->passed_quiesce, rdp->qs_pending);
83234 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83235- atomic_read(&rdp->dynticks->dynticks),
83236+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83237 rdp->dynticks->dynticks_nesting,
83238 rdp->dynticks->dynticks_nmi_nesting,
83239 rdp->dynticks_fqs);
83240@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83241 struct rcu_state *rsp = (struct rcu_state *)m->private;
83242
83243 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",
83244- atomic_long_read(&rsp->expedited_start),
83245+ atomic_long_read_unchecked(&rsp->expedited_start),
83246 atomic_long_read(&rsp->expedited_done),
83247- atomic_long_read(&rsp->expedited_wrap),
83248- atomic_long_read(&rsp->expedited_tryfail),
83249- atomic_long_read(&rsp->expedited_workdone1),
83250- atomic_long_read(&rsp->expedited_workdone2),
83251- atomic_long_read(&rsp->expedited_normal),
83252- atomic_long_read(&rsp->expedited_stoppedcpus),
83253- atomic_long_read(&rsp->expedited_done_tries),
83254- atomic_long_read(&rsp->expedited_done_lost),
83255- atomic_long_read(&rsp->expedited_done_exit));
83256+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83257+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83258+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83259+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83260+ atomic_long_read_unchecked(&rsp->expedited_normal),
83261+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83262+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83263+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83264+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83265 return 0;
83266 }
83267
83268diff --git a/kernel/resource.c b/kernel/resource.c
83269index 3f285dc..5755f62 100644
83270--- a/kernel/resource.c
83271+++ b/kernel/resource.c
83272@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83273
83274 static int __init ioresources_init(void)
83275 {
83276+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83277+#ifdef CONFIG_GRKERNSEC_PROC_USER
83278+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83279+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83280+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83281+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83282+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83283+#endif
83284+#else
83285 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83286 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83287+#endif
83288 return 0;
83289 }
83290 __initcall(ioresources_init);
83291diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83292index 1d96dd0..994ff19 100644
83293--- a/kernel/rtmutex-tester.c
83294+++ b/kernel/rtmutex-tester.c
83295@@ -22,7 +22,7 @@
83296 #define MAX_RT_TEST_MUTEXES 8
83297
83298 static spinlock_t rttest_lock;
83299-static atomic_t rttest_event;
83300+static atomic_unchecked_t rttest_event;
83301
83302 struct test_thread_data {
83303 int opcode;
83304@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83305
83306 case RTTEST_LOCKCONT:
83307 td->mutexes[td->opdata] = 1;
83308- td->event = atomic_add_return(1, &rttest_event);
83309+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83310 return 0;
83311
83312 case RTTEST_RESET:
83313@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83314 return 0;
83315
83316 case RTTEST_RESETEVENT:
83317- atomic_set(&rttest_event, 0);
83318+ atomic_set_unchecked(&rttest_event, 0);
83319 return 0;
83320
83321 default:
83322@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83323 return ret;
83324
83325 td->mutexes[id] = 1;
83326- td->event = atomic_add_return(1, &rttest_event);
83327+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83328 rt_mutex_lock(&mutexes[id]);
83329- td->event = atomic_add_return(1, &rttest_event);
83330+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83331 td->mutexes[id] = 4;
83332 return 0;
83333
83334@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83335 return ret;
83336
83337 td->mutexes[id] = 1;
83338- td->event = atomic_add_return(1, &rttest_event);
83339+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83340 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83341- td->event = atomic_add_return(1, &rttest_event);
83342+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83343 td->mutexes[id] = ret ? 0 : 4;
83344 return ret ? -EINTR : 0;
83345
83346@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83347 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83348 return ret;
83349
83350- td->event = atomic_add_return(1, &rttest_event);
83351+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83352 rt_mutex_unlock(&mutexes[id]);
83353- td->event = atomic_add_return(1, &rttest_event);
83354+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83355 td->mutexes[id] = 0;
83356 return 0;
83357
83358@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83359 break;
83360
83361 td->mutexes[dat] = 2;
83362- td->event = atomic_add_return(1, &rttest_event);
83363+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83364 break;
83365
83366 default:
83367@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83368 return;
83369
83370 td->mutexes[dat] = 3;
83371- td->event = atomic_add_return(1, &rttest_event);
83372+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83373 break;
83374
83375 case RTTEST_LOCKNOWAIT:
83376@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83377 return;
83378
83379 td->mutexes[dat] = 1;
83380- td->event = atomic_add_return(1, &rttest_event);
83381+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83382 return;
83383
83384 default:
83385diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83386index 4a07353..66b5291 100644
83387--- a/kernel/sched/auto_group.c
83388+++ b/kernel/sched/auto_group.c
83389@@ -11,7 +11,7 @@
83390
83391 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83392 static struct autogroup autogroup_default;
83393-static atomic_t autogroup_seq_nr;
83394+static atomic_unchecked_t autogroup_seq_nr;
83395
83396 void __init autogroup_init(struct task_struct *init_task)
83397 {
83398@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83399
83400 kref_init(&ag->kref);
83401 init_rwsem(&ag->lock);
83402- ag->id = atomic_inc_return(&autogroup_seq_nr);
83403+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83404 ag->tg = tg;
83405 #ifdef CONFIG_RT_GROUP_SCHED
83406 /*
83407diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83408index 05c39f0..442e6fe 100644
83409--- a/kernel/sched/core.c
83410+++ b/kernel/sched/core.c
83411@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83412 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83413 * or number of jiffies left till timeout) if completed.
83414 */
83415-long __sched
83416+long __sched __intentional_overflow(-1)
83417 wait_for_completion_interruptible_timeout(struct completion *x,
83418 unsigned long timeout)
83419 {
83420@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83421 *
83422 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83423 */
83424-int __sched wait_for_completion_killable(struct completion *x)
83425+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83426 {
83427 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83428 if (t == -ERESTARTSYS)
83429@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83430 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83431 * or number of jiffies left till timeout) if completed.
83432 */
83433-long __sched
83434+long __sched __intentional_overflow(-1)
83435 wait_for_completion_killable_timeout(struct completion *x,
83436 unsigned long timeout)
83437 {
83438@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83439 /* convert nice value [19,-20] to rlimit style value [1,40] */
83440 int nice_rlim = 20 - nice;
83441
83442+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83443+
83444 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83445 capable(CAP_SYS_NICE));
83446 }
83447@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83448 if (nice > 19)
83449 nice = 19;
83450
83451- if (increment < 0 && !can_nice(current, nice))
83452+ if (increment < 0 && (!can_nice(current, nice) ||
83453+ gr_handle_chroot_nice()))
83454 return -EPERM;
83455
83456 retval = security_task_setnice(current, nice);
83457@@ -3344,6 +3347,7 @@ recheck:
83458 unsigned long rlim_rtprio =
83459 task_rlimit(p, RLIMIT_RTPRIO);
83460
83461+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83462 /* can't set/change the rt policy */
83463 if (policy != p->policy && !rlim_rtprio)
83464 return -EPERM;
83465@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83466
83467 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83468
83469-static struct ctl_table sd_ctl_dir[] = {
83470+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83471 {
83472 .procname = "sched_domain",
83473 .mode = 0555,
83474@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83475 {}
83476 };
83477
83478-static struct ctl_table *sd_alloc_ctl_entry(int n)
83479+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83480 {
83481- struct ctl_table *entry =
83482+ ctl_table_no_const *entry =
83483 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83484
83485 return entry;
83486 }
83487
83488-static void sd_free_ctl_entry(struct ctl_table **tablep)
83489+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83490 {
83491- struct ctl_table *entry;
83492+ ctl_table_no_const *entry;
83493
83494 /*
83495 * In the intermediate directories, both the child directory and
83496@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83497 * will always be set. In the lowest directory the names are
83498 * static strings and all have proc handlers.
83499 */
83500- for (entry = *tablep; entry->mode; entry++) {
83501- if (entry->child)
83502- sd_free_ctl_entry(&entry->child);
83503+ for (entry = tablep; entry->mode; entry++) {
83504+ if (entry->child) {
83505+ sd_free_ctl_entry(entry->child);
83506+ pax_open_kernel();
83507+ entry->child = NULL;
83508+ pax_close_kernel();
83509+ }
83510 if (entry->proc_handler == NULL)
83511 kfree(entry->procname);
83512 }
83513
83514- kfree(*tablep);
83515- *tablep = NULL;
83516+ kfree(tablep);
83517 }
83518
83519 static int min_load_idx = 0;
83520 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83521
83522 static void
83523-set_table_entry(struct ctl_table *entry,
83524+set_table_entry(ctl_table_no_const *entry,
83525 const char *procname, void *data, int maxlen,
83526 umode_t mode, proc_handler *proc_handler,
83527 bool load_idx)
83528@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83529 static struct ctl_table *
83530 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83531 {
83532- struct ctl_table *table = sd_alloc_ctl_entry(13);
83533+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83534
83535 if (table == NULL)
83536 return NULL;
83537@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83538 return table;
83539 }
83540
83541-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83542+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83543 {
83544- struct ctl_table *entry, *table;
83545+ ctl_table_no_const *entry, *table;
83546 struct sched_domain *sd;
83547 int domain_num = 0, i;
83548 char buf[32];
83549@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83550 static void register_sched_domain_sysctl(void)
83551 {
83552 int i, cpu_num = num_possible_cpus();
83553- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83554+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83555 char buf[32];
83556
83557 WARN_ON(sd_ctl_dir[0].child);
83558+ pax_open_kernel();
83559 sd_ctl_dir[0].child = entry;
83560+ pax_close_kernel();
83561
83562 if (entry == NULL)
83563 return;
83564@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83565 if (sd_sysctl_header)
83566 unregister_sysctl_table(sd_sysctl_header);
83567 sd_sysctl_header = NULL;
83568- if (sd_ctl_dir[0].child)
83569- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83570+ if (sd_ctl_dir[0].child) {
83571+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83572+ pax_open_kernel();
83573+ sd_ctl_dir[0].child = NULL;
83574+ pax_close_kernel();
83575+ }
83576 }
83577 #else
83578 static void register_sched_domain_sysctl(void)
83579diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83580index 31cbc15..ba68c15 100644
83581--- a/kernel/sched/fair.c
83582+++ b/kernel/sched/fair.c
83583@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83584
83585 static void reset_ptenuma_scan(struct task_struct *p)
83586 {
83587- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83588+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83589 p->mm->numa_scan_offset = 0;
83590 }
83591
83592@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83593 * run_rebalance_domains is triggered when needed from the scheduler tick.
83594 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83595 */
83596-static void run_rebalance_domains(struct softirq_action *h)
83597+static __latent_entropy void run_rebalance_domains(void)
83598 {
83599 int this_cpu = smp_processor_id();
83600 struct rq *this_rq = cpu_rq(this_cpu);
83601diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83602index ef0a7b2..1b728c1 100644
83603--- a/kernel/sched/sched.h
83604+++ b/kernel/sched/sched.h
83605@@ -1004,7 +1004,7 @@ struct sched_class {
83606 #ifdef CONFIG_FAIR_GROUP_SCHED
83607 void (*task_move_group) (struct task_struct *p, int on_rq);
83608 #endif
83609-};
83610+} __do_const;
83611
83612 #define sched_class_highest (&stop_sched_class)
83613 #define for_each_class(class) \
83614diff --git a/kernel/signal.c b/kernel/signal.c
83615index 50e4107..9409983 100644
83616--- a/kernel/signal.c
83617+++ b/kernel/signal.c
83618@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83619
83620 int print_fatal_signals __read_mostly;
83621
83622-static void __user *sig_handler(struct task_struct *t, int sig)
83623+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83624 {
83625 return t->sighand->action[sig - 1].sa.sa_handler;
83626 }
83627
83628-static int sig_handler_ignored(void __user *handler, int sig)
83629+static int sig_handler_ignored(__sighandler_t handler, int sig)
83630 {
83631 /* Is it explicitly or implicitly ignored? */
83632 return handler == SIG_IGN ||
83633@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83634
83635 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83636 {
83637- void __user *handler;
83638+ __sighandler_t handler;
83639
83640 handler = sig_handler(t, sig);
83641
83642@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83643 atomic_inc(&user->sigpending);
83644 rcu_read_unlock();
83645
83646+ if (!override_rlimit)
83647+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83648+
83649 if (override_rlimit ||
83650 atomic_read(&user->sigpending) <=
83651 task_rlimit(t, RLIMIT_SIGPENDING)) {
83652@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83653
83654 int unhandled_signal(struct task_struct *tsk, int sig)
83655 {
83656- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83657+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83658 if (is_global_init(tsk))
83659 return 1;
83660 if (handler != SIG_IGN && handler != SIG_DFL)
83661@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83662 }
83663 }
83664
83665+ /* allow glibc communication via tgkill to other threads in our
83666+ thread group */
83667+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83668+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83669+ && gr_handle_signal(t, sig))
83670+ return -EPERM;
83671+
83672 return security_task_kill(t, info, sig, 0);
83673 }
83674
83675@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83676 return send_signal(sig, info, p, 1);
83677 }
83678
83679-static int
83680+int
83681 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83682 {
83683 return send_signal(sig, info, t, 0);
83684@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83685 unsigned long int flags;
83686 int ret, blocked, ignored;
83687 struct k_sigaction *action;
83688+ int is_unhandled = 0;
83689
83690 spin_lock_irqsave(&t->sighand->siglock, flags);
83691 action = &t->sighand->action[sig-1];
83692@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83693 }
83694 if (action->sa.sa_handler == SIG_DFL)
83695 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83696+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83697+ is_unhandled = 1;
83698 ret = specific_send_sig_info(sig, info, t);
83699 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83700
83701+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83702+ normal operation */
83703+ if (is_unhandled) {
83704+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83705+ gr_handle_crash(t, sig);
83706+ }
83707+
83708 return ret;
83709 }
83710
83711@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83712 ret = check_kill_permission(sig, info, p);
83713 rcu_read_unlock();
83714
83715- if (!ret && sig)
83716+ if (!ret && sig) {
83717 ret = do_send_sig_info(sig, info, p, true);
83718+ if (!ret)
83719+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83720+ }
83721
83722 return ret;
83723 }
83724@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83725 int error = -ESRCH;
83726
83727 rcu_read_lock();
83728- p = find_task_by_vpid(pid);
83729+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83730+ /* allow glibc communication via tgkill to other threads in our
83731+ thread group */
83732+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83733+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83734+ p = find_task_by_vpid_unrestricted(pid);
83735+ else
83736+#endif
83737+ p = find_task_by_vpid(pid);
83738 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83739 error = check_kill_permission(sig, info, p);
83740 /*
83741@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83742 }
83743 seg = get_fs();
83744 set_fs(KERNEL_DS);
83745- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83746- (stack_t __force __user *) &uoss,
83747+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83748+ (stack_t __force_user *) &uoss,
83749 compat_user_stack_pointer());
83750 set_fs(seg);
83751 if (ret >= 0 && uoss_ptr) {
83752diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83753index eb89e18..a4e6792 100644
83754--- a/kernel/smpboot.c
83755+++ b/kernel/smpboot.c
83756@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83757 }
83758 smpboot_unpark_thread(plug_thread, cpu);
83759 }
83760- list_add(&plug_thread->list, &hotplug_threads);
83761+ pax_list_add(&plug_thread->list, &hotplug_threads);
83762 out:
83763 mutex_unlock(&smpboot_threads_lock);
83764 return ret;
83765@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83766 {
83767 get_online_cpus();
83768 mutex_lock(&smpboot_threads_lock);
83769- list_del(&plug_thread->list);
83770+ pax_list_del(&plug_thread->list);
83771 smpboot_destroy_threads(plug_thread);
83772 mutex_unlock(&smpboot_threads_lock);
83773 put_online_cpus();
83774diff --git a/kernel/softirq.c b/kernel/softirq.c
83775index adf6c00..5d89b73 100644
83776--- a/kernel/softirq.c
83777+++ b/kernel/softirq.c
83778@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83779 EXPORT_SYMBOL(irq_stat);
83780 #endif
83781
83782-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83783+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83784
83785 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83786
83787-char *softirq_to_name[NR_SOFTIRQS] = {
83788+const char * const softirq_to_name[NR_SOFTIRQS] = {
83789 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83790 "TASKLET", "SCHED", "HRTIMER", "RCU"
83791 };
83792@@ -248,7 +248,7 @@ restart:
83793 kstat_incr_softirqs_this_cpu(vec_nr);
83794
83795 trace_softirq_entry(vec_nr);
83796- h->action(h);
83797+ h->action();
83798 trace_softirq_exit(vec_nr);
83799 if (unlikely(prev_count != preempt_count())) {
83800 printk(KERN_ERR "huh, entered softirq %u %s %p"
83801@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83802 or_softirq_pending(1UL << nr);
83803 }
83804
83805-void open_softirq(int nr, void (*action)(struct softirq_action *))
83806+void __init open_softirq(int nr, void (*action)(void))
83807 {
83808 softirq_vec[nr].action = action;
83809 }
83810@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83811
83812 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83813
83814-static void tasklet_action(struct softirq_action *a)
83815+static __latent_entropy void tasklet_action(void)
83816 {
83817 struct tasklet_struct *list;
83818
83819@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
83820 }
83821 }
83822
83823-static void tasklet_hi_action(struct softirq_action *a)
83824+static __latent_entropy void tasklet_hi_action(void)
83825 {
83826 struct tasklet_struct *list;
83827
83828@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
83829 .notifier_call = cpu_callback
83830 };
83831
83832-static struct smp_hotplug_thread softirq_threads = {
83833+static struct smp_hotplug_thread softirq_threads __read_only = {
83834 .store = &ksoftirqd,
83835 .thread_should_run = ksoftirqd_should_run,
83836 .thread_fn = run_ksoftirqd,
83837diff --git a/kernel/srcu.c b/kernel/srcu.c
83838index 01d5ccb..cdcbee6 100644
83839--- a/kernel/srcu.c
83840+++ b/kernel/srcu.c
83841@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83842
83843 idx = ACCESS_ONCE(sp->completed) & 0x1;
83844 preempt_disable();
83845- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83846+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83847 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83848- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83849+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83850 preempt_enable();
83851 return idx;
83852 }
83853diff --git a/kernel/sys.c b/kernel/sys.c
83854index 771129b..dc0c7e3 100644
83855--- a/kernel/sys.c
83856+++ b/kernel/sys.c
83857@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83858 error = -EACCES;
83859 goto out;
83860 }
83861+
83862+ if (gr_handle_chroot_setpriority(p, niceval)) {
83863+ error = -EACCES;
83864+ goto out;
83865+ }
83866+
83867 no_nice = security_task_setnice(p, niceval);
83868 if (no_nice) {
83869 error = no_nice;
83870@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83871 goto error;
83872 }
83873
83874+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83875+ goto error;
83876+
83877 if (rgid != (gid_t) -1 ||
83878 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83879 new->sgid = new->egid;
83880@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83881 old = current_cred();
83882
83883 retval = -EPERM;
83884+
83885+ if (gr_check_group_change(kgid, kgid, kgid))
83886+ goto error;
83887+
83888 if (nsown_capable(CAP_SETGID))
83889 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83890 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83891@@ -404,7 +417,7 @@ error:
83892 /*
83893 * change the user struct in a credentials set to match the new UID
83894 */
83895-static int set_user(struct cred *new)
83896+int set_user(struct cred *new)
83897 {
83898 struct user_struct *new_user;
83899
83900@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83901 goto error;
83902 }
83903
83904+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83905+ goto error;
83906+
83907 if (!uid_eq(new->uid, old->uid)) {
83908 retval = set_user(new);
83909 if (retval < 0)
83910@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83911 old = current_cred();
83912
83913 retval = -EPERM;
83914+
83915+ if (gr_check_crash_uid(kuid))
83916+ goto error;
83917+ if (gr_check_user_change(kuid, kuid, kuid))
83918+ goto error;
83919+
83920 if (nsown_capable(CAP_SETUID)) {
83921 new->suid = new->uid = kuid;
83922 if (!uid_eq(kuid, old->uid)) {
83923@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83924 goto error;
83925 }
83926
83927+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83928+ goto error;
83929+
83930 if (ruid != (uid_t) -1) {
83931 new->uid = kruid;
83932 if (!uid_eq(kruid, old->uid)) {
83933@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83934 goto error;
83935 }
83936
83937+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83938+ goto error;
83939+
83940 if (rgid != (gid_t) -1)
83941 new->gid = krgid;
83942 if (egid != (gid_t) -1)
83943@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83944 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83945 nsown_capable(CAP_SETUID)) {
83946 if (!uid_eq(kuid, old->fsuid)) {
83947+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83948+ goto error;
83949+
83950 new->fsuid = kuid;
83951 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83952 goto change_okay;
83953 }
83954 }
83955
83956+error:
83957 abort_creds(new);
83958 return old_fsuid;
83959
83960@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83961 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83962 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83963 nsown_capable(CAP_SETGID)) {
83964+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83965+ goto error;
83966+
83967 if (!gid_eq(kgid, old->fsgid)) {
83968 new->fsgid = kgid;
83969 goto change_okay;
83970 }
83971 }
83972
83973+error:
83974 abort_creds(new);
83975 return old_fsgid;
83976
83977@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83978 return -EFAULT;
83979
83980 down_read(&uts_sem);
83981- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83982+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83983 __OLD_UTS_LEN);
83984 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83985- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83986+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83987 __OLD_UTS_LEN);
83988 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83989- error |= __copy_to_user(&name->release, &utsname()->release,
83990+ error |= __copy_to_user(name->release, &utsname()->release,
83991 __OLD_UTS_LEN);
83992 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83993- error |= __copy_to_user(&name->version, &utsname()->version,
83994+ error |= __copy_to_user(name->version, &utsname()->version,
83995 __OLD_UTS_LEN);
83996 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83997- error |= __copy_to_user(&name->machine, &utsname()->machine,
83998+ error |= __copy_to_user(name->machine, &utsname()->machine,
83999 __OLD_UTS_LEN);
84000 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
84001 up_read(&uts_sem);
84002@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
84003 */
84004 new_rlim->rlim_cur = 1;
84005 }
84006+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
84007+ is changed to a lower value. Since tasks can be created by the same
84008+ user in between this limit change and an execve by this task, force
84009+ a recheck only for this task by setting PF_NPROC_EXCEEDED
84010+ */
84011+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
84012+ tsk->flags |= PF_NPROC_EXCEEDED;
84013 }
84014 if (!retval) {
84015 if (old_rlim)
84016diff --git a/kernel/sysctl.c b/kernel/sysctl.c
84017index 07f6fc4..65fb3d4 100644
84018--- a/kernel/sysctl.c
84019+++ b/kernel/sysctl.c
84020@@ -93,7 +93,6 @@
84021
84022
84023 #if defined(CONFIG_SYSCTL)
84024-
84025 /* External variables not in a header file. */
84026 extern int sysctl_overcommit_memory;
84027 extern int sysctl_overcommit_ratio;
84028@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84029
84030 /* Constants used for minimum and maximum */
84031 #ifdef CONFIG_LOCKUP_DETECTOR
84032-static int sixty = 60;
84033+static int sixty __read_only = 60;
84034 #endif
84035
84036-static int zero;
84037-static int __maybe_unused one = 1;
84038-static int __maybe_unused two = 2;
84039-static int __maybe_unused three = 3;
84040-static unsigned long one_ul = 1;
84041-static int one_hundred = 100;
84042+static int neg_one __read_only = -1;
84043+static int zero __read_only = 0;
84044+static int __maybe_unused one __read_only = 1;
84045+static int __maybe_unused two __read_only = 2;
84046+static int __maybe_unused three __read_only = 3;
84047+static unsigned long one_ul __read_only = 1;
84048+static int one_hundred __read_only = 100;
84049 #ifdef CONFIG_PRINTK
84050-static int ten_thousand = 10000;
84051+static int ten_thousand __read_only = 10000;
84052 #endif
84053
84054 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84055@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84056 void __user *buffer, size_t *lenp, loff_t *ppos);
84057 #endif
84058
84059-#ifdef CONFIG_PRINTK
84060 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84061 void __user *buffer, size_t *lenp, loff_t *ppos);
84062-#endif
84063
84064 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84065 void __user *buffer, size_t *lenp, loff_t *ppos);
84066@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84067
84068 #endif
84069
84070+extern struct ctl_table grsecurity_table[];
84071+
84072 static struct ctl_table kern_table[];
84073 static struct ctl_table vm_table[];
84074 static struct ctl_table fs_table[];
84075@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84076 int sysctl_legacy_va_layout;
84077 #endif
84078
84079+#ifdef CONFIG_PAX_SOFTMODE
84080+static ctl_table pax_table[] = {
84081+ {
84082+ .procname = "softmode",
84083+ .data = &pax_softmode,
84084+ .maxlen = sizeof(unsigned int),
84085+ .mode = 0600,
84086+ .proc_handler = &proc_dointvec,
84087+ },
84088+
84089+ { }
84090+};
84091+#endif
84092+
84093 /* The default sysctl tables: */
84094
84095 static struct ctl_table sysctl_base_table[] = {
84096@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84097 #endif
84098
84099 static struct ctl_table kern_table[] = {
84100+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84101+ {
84102+ .procname = "grsecurity",
84103+ .mode = 0500,
84104+ .child = grsecurity_table,
84105+ },
84106+#endif
84107+
84108+#ifdef CONFIG_PAX_SOFTMODE
84109+ {
84110+ .procname = "pax",
84111+ .mode = 0500,
84112+ .child = pax_table,
84113+ },
84114+#endif
84115+
84116 {
84117 .procname = "sched_child_runs_first",
84118 .data = &sysctl_sched_child_runs_first,
84119@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84120 .data = &modprobe_path,
84121 .maxlen = KMOD_PATH_LEN,
84122 .mode = 0644,
84123- .proc_handler = proc_dostring,
84124+ .proc_handler = proc_dostring_modpriv,
84125 },
84126 {
84127 .procname = "modules_disabled",
84128@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84129 .extra1 = &zero,
84130 .extra2 = &one,
84131 },
84132+#endif
84133 {
84134 .procname = "kptr_restrict",
84135 .data = &kptr_restrict,
84136 .maxlen = sizeof(int),
84137 .mode = 0644,
84138 .proc_handler = proc_dointvec_minmax_sysadmin,
84139+#ifdef CONFIG_GRKERNSEC_HIDESYM
84140+ .extra1 = &two,
84141+#else
84142 .extra1 = &zero,
84143+#endif
84144 .extra2 = &two,
84145 },
84146-#endif
84147 {
84148 .procname = "ngroups_max",
84149 .data = &ngroups_max,
84150@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84151 */
84152 {
84153 .procname = "perf_event_paranoid",
84154- .data = &sysctl_perf_event_paranoid,
84155- .maxlen = sizeof(sysctl_perf_event_paranoid),
84156+ .data = &sysctl_perf_event_legitimately_concerned,
84157+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84158 .mode = 0644,
84159- .proc_handler = proc_dointvec,
84160+ /* go ahead, be a hero */
84161+ .proc_handler = proc_dointvec_minmax_sysadmin,
84162+ .extra1 = &neg_one,
84163+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84164+ .extra2 = &three,
84165+#else
84166+ .extra2 = &two,
84167+#endif
84168 },
84169 {
84170 .procname = "perf_event_mlock_kb",
84171@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84172 .proc_handler = proc_dointvec_minmax,
84173 .extra1 = &zero,
84174 },
84175+ {
84176+ .procname = "heap_stack_gap",
84177+ .data = &sysctl_heap_stack_gap,
84178+ .maxlen = sizeof(sysctl_heap_stack_gap),
84179+ .mode = 0644,
84180+ .proc_handler = proc_doulongvec_minmax,
84181+ },
84182 #else
84183 {
84184 .procname = "nr_trim_pages",
84185@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84186 buffer, lenp, ppos);
84187 }
84188
84189+int proc_dostring_modpriv(struct ctl_table *table, int write,
84190+ void __user *buffer, size_t *lenp, loff_t *ppos)
84191+{
84192+ if (write && !capable(CAP_SYS_MODULE))
84193+ return -EPERM;
84194+
84195+ return _proc_do_string(table->data, table->maxlen, write,
84196+ buffer, lenp, ppos);
84197+}
84198+
84199 static size_t proc_skip_spaces(char **buf)
84200 {
84201 size_t ret;
84202@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84203 len = strlen(tmp);
84204 if (len > *size)
84205 len = *size;
84206+ if (len > sizeof(tmp))
84207+ len = sizeof(tmp);
84208 if (copy_to_user(*buf, tmp, len))
84209 return -EFAULT;
84210 *size -= len;
84211@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84212 static int proc_taint(struct ctl_table *table, int write,
84213 void __user *buffer, size_t *lenp, loff_t *ppos)
84214 {
84215- struct ctl_table t;
84216+ ctl_table_no_const t;
84217 unsigned long tmptaint = get_taint();
84218 int err;
84219
84220@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84221 return err;
84222 }
84223
84224-#ifdef CONFIG_PRINTK
84225 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84226 void __user *buffer, size_t *lenp, loff_t *ppos)
84227 {
84228@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84229
84230 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84231 }
84232-#endif
84233
84234 struct do_proc_dointvec_minmax_conv_param {
84235 int *min;
84236@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84237 *i = val;
84238 } else {
84239 val = convdiv * (*i) / convmul;
84240- if (!first)
84241+ if (!first) {
84242 err = proc_put_char(&buffer, &left, '\t');
84243+ if (err)
84244+ break;
84245+ }
84246 err = proc_put_long(&buffer, &left, val, false);
84247 if (err)
84248 break;
84249@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84250 return -ENOSYS;
84251 }
84252
84253+int proc_dostring_modpriv(struct ctl_table *table, int write,
84254+ void __user *buffer, size_t *lenp, loff_t *ppos)
84255+{
84256+ return -ENOSYS;
84257+}
84258+
84259 int proc_dointvec(struct ctl_table *table, int write,
84260 void __user *buffer, size_t *lenp, loff_t *ppos)
84261 {
84262@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84263 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84264 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84265 EXPORT_SYMBOL(proc_dostring);
84266+EXPORT_SYMBOL(proc_dostring_modpriv);
84267 EXPORT_SYMBOL(proc_doulongvec_minmax);
84268 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84269diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84270index 145bb4d..b2aa969 100644
84271--- a/kernel/taskstats.c
84272+++ b/kernel/taskstats.c
84273@@ -28,9 +28,12 @@
84274 #include <linux/fs.h>
84275 #include <linux/file.h>
84276 #include <linux/pid_namespace.h>
84277+#include <linux/grsecurity.h>
84278 #include <net/genetlink.h>
84279 #include <linux/atomic.h>
84280
84281+extern int gr_is_taskstats_denied(int pid);
84282+
84283 /*
84284 * Maximum length of a cpumask that can be specified in
84285 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84286@@ -570,6 +573,9 @@ err:
84287
84288 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84289 {
84290+ if (gr_is_taskstats_denied(current->pid))
84291+ return -EACCES;
84292+
84293 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84294 return cmd_attr_register_cpumask(info);
84295 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84296diff --git a/kernel/time.c b/kernel/time.c
84297index 7c7964c..784a599 100644
84298--- a/kernel/time.c
84299+++ b/kernel/time.c
84300@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84301 return error;
84302
84303 if (tz) {
84304+ /* we log in do_settimeofday called below, so don't log twice
84305+ */
84306+ if (!tv)
84307+ gr_log_timechange();
84308+
84309 sys_tz = *tz;
84310 update_vsyscall_tz();
84311 if (firsttime) {
84312@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84313 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84314 * value to a scaled second value.
84315 */
84316-unsigned long
84317+unsigned long __intentional_overflow(-1)
84318 timespec_to_jiffies(const struct timespec *value)
84319 {
84320 unsigned long sec = value->tv_sec;
84321diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84322index eec50fc..65e5df6 100644
84323--- a/kernel/time/alarmtimer.c
84324+++ b/kernel/time/alarmtimer.c
84325@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84326 struct platform_device *pdev;
84327 int error = 0;
84328 int i;
84329- struct k_clock alarm_clock = {
84330+ static struct k_clock alarm_clock = {
84331 .clock_getres = alarm_clock_getres,
84332 .clock_get = alarm_clock_get,
84333 .timer_create = alarm_timer_create,
84334diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84335index 947ba25..20cbade 100644
84336--- a/kernel/time/timekeeping.c
84337+++ b/kernel/time/timekeeping.c
84338@@ -15,6 +15,7 @@
84339 #include <linux/init.h>
84340 #include <linux/mm.h>
84341 #include <linux/sched.h>
84342+#include <linux/grsecurity.h>
84343 #include <linux/syscore_ops.h>
84344 #include <linux/clocksource.h>
84345 #include <linux/jiffies.h>
84346@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84347 if (!timespec_valid_strict(tv))
84348 return -EINVAL;
84349
84350+ gr_log_timechange();
84351+
84352 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84353 write_seqcount_begin(&timekeeper_seq);
84354
84355diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84356index 61ed862..3b52c65 100644
84357--- a/kernel/time/timer_list.c
84358+++ b/kernel/time/timer_list.c
84359@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84360
84361 static void print_name_offset(struct seq_file *m, void *sym)
84362 {
84363+#ifdef CONFIG_GRKERNSEC_HIDESYM
84364+ SEQ_printf(m, "<%p>", NULL);
84365+#else
84366 char symname[KSYM_NAME_LEN];
84367
84368 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84369 SEQ_printf(m, "<%pK>", sym);
84370 else
84371 SEQ_printf(m, "%s", symname);
84372+#endif
84373 }
84374
84375 static void
84376@@ -119,7 +123,11 @@ next_one:
84377 static void
84378 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84379 {
84380+#ifdef CONFIG_GRKERNSEC_HIDESYM
84381+ SEQ_printf(m, " .base: %p\n", NULL);
84382+#else
84383 SEQ_printf(m, " .base: %pK\n", base);
84384+#endif
84385 SEQ_printf(m, " .index: %d\n",
84386 base->index);
84387 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84388@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84389 {
84390 struct proc_dir_entry *pe;
84391
84392+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84393+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84394+#else
84395 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84396+#endif
84397 if (!pe)
84398 return -ENOMEM;
84399 return 0;
84400diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84401index 0b537f2..40d6c20 100644
84402--- a/kernel/time/timer_stats.c
84403+++ b/kernel/time/timer_stats.c
84404@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84405 static unsigned long nr_entries;
84406 static struct entry entries[MAX_ENTRIES];
84407
84408-static atomic_t overflow_count;
84409+static atomic_unchecked_t overflow_count;
84410
84411 /*
84412 * The entries are in a hash-table, for fast lookup:
84413@@ -140,7 +140,7 @@ static void reset_entries(void)
84414 nr_entries = 0;
84415 memset(entries, 0, sizeof(entries));
84416 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84417- atomic_set(&overflow_count, 0);
84418+ atomic_set_unchecked(&overflow_count, 0);
84419 }
84420
84421 static struct entry *alloc_entry(void)
84422@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84423 if (likely(entry))
84424 entry->count++;
84425 else
84426- atomic_inc(&overflow_count);
84427+ atomic_inc_unchecked(&overflow_count);
84428
84429 out_unlock:
84430 raw_spin_unlock_irqrestore(lock, flags);
84431@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84432
84433 static void print_name_offset(struct seq_file *m, unsigned long addr)
84434 {
84435+#ifdef CONFIG_GRKERNSEC_HIDESYM
84436+ seq_printf(m, "<%p>", NULL);
84437+#else
84438 char symname[KSYM_NAME_LEN];
84439
84440 if (lookup_symbol_name(addr, symname) < 0)
84441- seq_printf(m, "<%p>", (void *)addr);
84442+ seq_printf(m, "<%pK>", (void *)addr);
84443 else
84444 seq_printf(m, "%s", symname);
84445+#endif
84446 }
84447
84448 static int tstats_show(struct seq_file *m, void *v)
84449@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84450
84451 seq_puts(m, "Timer Stats Version: v0.2\n");
84452 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84453- if (atomic_read(&overflow_count))
84454+ if (atomic_read_unchecked(&overflow_count))
84455 seq_printf(m, "Overflow: %d entries\n",
84456- atomic_read(&overflow_count));
84457+ atomic_read_unchecked(&overflow_count));
84458
84459 for (i = 0; i < nr_entries; i++) {
84460 entry = entries + i;
84461@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84462 {
84463 struct proc_dir_entry *pe;
84464
84465+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84466+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84467+#else
84468 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84469+#endif
84470 if (!pe)
84471 return -ENOMEM;
84472 return 0;
84473diff --git a/kernel/timer.c b/kernel/timer.c
84474index 4296d13..0164b04 100644
84475--- a/kernel/timer.c
84476+++ b/kernel/timer.c
84477@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84478 /*
84479 * This function runs timers and the timer-tq in bottom half context.
84480 */
84481-static void run_timer_softirq(struct softirq_action *h)
84482+static __latent_entropy void run_timer_softirq(void)
84483 {
84484 struct tvec_base *base = __this_cpu_read(tvec_bases);
84485
84486@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84487 *
84488 * In all cases the return value is guaranteed to be non-negative.
84489 */
84490-signed long __sched schedule_timeout(signed long timeout)
84491+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84492 {
84493 struct timer_list timer;
84494 unsigned long expire;
84495diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84496index b8b8560..75b1a09 100644
84497--- a/kernel/trace/blktrace.c
84498+++ b/kernel/trace/blktrace.c
84499@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84500 struct blk_trace *bt = filp->private_data;
84501 char buf[16];
84502
84503- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84504+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84505
84506 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84507 }
84508@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84509 return 1;
84510
84511 bt = buf->chan->private_data;
84512- atomic_inc(&bt->dropped);
84513+ atomic_inc_unchecked(&bt->dropped);
84514 return 0;
84515 }
84516
84517@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84518
84519 bt->dir = dir;
84520 bt->dev = dev;
84521- atomic_set(&bt->dropped, 0);
84522+ atomic_set_unchecked(&bt->dropped, 0);
84523
84524 ret = -EIO;
84525 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84526diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84527index a6d098c..bb8cf65 100644
84528--- a/kernel/trace/ftrace.c
84529+++ b/kernel/trace/ftrace.c
84530@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84531 if (unlikely(ftrace_disabled))
84532 return 0;
84533
84534+ ret = ftrace_arch_code_modify_prepare();
84535+ FTRACE_WARN_ON(ret);
84536+ if (ret)
84537+ return 0;
84538+
84539 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84540+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84541 if (ret) {
84542 ftrace_bug(ret, ip);
84543- return 0;
84544 }
84545- return 1;
84546+ return ret ? 0 : 1;
84547 }
84548
84549 /*
84550@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84551 if (!count)
84552 return 0;
84553
84554+ pax_open_kernel();
84555 sort(start, count, sizeof(*start),
84556 ftrace_cmp_ips, ftrace_swap_ips);
84557+ pax_close_kernel();
84558
84559 start_pg = ftrace_allocate_pages(count);
84560 if (!start_pg)
84561@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84562 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84563
84564 static int ftrace_graph_active;
84565-static struct notifier_block ftrace_suspend_notifier;
84566-
84567 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84568 {
84569 return 0;
84570@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84571 return NOTIFY_DONE;
84572 }
84573
84574+static struct notifier_block ftrace_suspend_notifier = {
84575+ .notifier_call = ftrace_suspend_notifier_call
84576+};
84577+
84578 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84579 trace_func_graph_ent_t entryfunc)
84580 {
84581@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84582 goto out;
84583 }
84584
84585- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84586 register_pm_notifier(&ftrace_suspend_notifier);
84587
84588 ftrace_graph_active++;
84589diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84590index cc2f66f..05edd54 100644
84591--- a/kernel/trace/ring_buffer.c
84592+++ b/kernel/trace/ring_buffer.c
84593@@ -352,9 +352,9 @@ struct buffer_data_page {
84594 */
84595 struct buffer_page {
84596 struct list_head list; /* list of buffer pages */
84597- local_t write; /* index for next write */
84598+ local_unchecked_t write; /* index for next write */
84599 unsigned read; /* index for next read */
84600- local_t entries; /* entries on this page */
84601+ local_unchecked_t entries; /* entries on this page */
84602 unsigned long real_end; /* real end of data */
84603 struct buffer_data_page *page; /* Actual data page */
84604 };
84605@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84606 unsigned long last_overrun;
84607 local_t entries_bytes;
84608 local_t entries;
84609- local_t overrun;
84610- local_t commit_overrun;
84611+ local_unchecked_t overrun;
84612+ local_unchecked_t commit_overrun;
84613 local_t dropped_events;
84614 local_t committing;
84615 local_t commits;
84616@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84617 *
84618 * We add a counter to the write field to denote this.
84619 */
84620- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84621- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84622+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84623+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84624
84625 /*
84626 * Just make sure we have seen our old_write and synchronize
84627@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84628 * cmpxchg to only update if an interrupt did not already
84629 * do it for us. If the cmpxchg fails, we don't care.
84630 */
84631- (void)local_cmpxchg(&next_page->write, old_write, val);
84632- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84633+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84634+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84635
84636 /*
84637 * No need to worry about races with clearing out the commit.
84638@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84639
84640 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84641 {
84642- return local_read(&bpage->entries) & RB_WRITE_MASK;
84643+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84644 }
84645
84646 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84647 {
84648- return local_read(&bpage->write) & RB_WRITE_MASK;
84649+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84650 }
84651
84652 static int
84653@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84654 * bytes consumed in ring buffer from here.
84655 * Increment overrun to account for the lost events.
84656 */
84657- local_add(page_entries, &cpu_buffer->overrun);
84658+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84659 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84660 }
84661
84662@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84663 * it is our responsibility to update
84664 * the counters.
84665 */
84666- local_add(entries, &cpu_buffer->overrun);
84667+ local_add_unchecked(entries, &cpu_buffer->overrun);
84668 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84669
84670 /*
84671@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84672 if (tail == BUF_PAGE_SIZE)
84673 tail_page->real_end = 0;
84674
84675- local_sub(length, &tail_page->write);
84676+ local_sub_unchecked(length, &tail_page->write);
84677 return;
84678 }
84679
84680@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84681 rb_event_set_padding(event);
84682
84683 /* Set the write back to the previous setting */
84684- local_sub(length, &tail_page->write);
84685+ local_sub_unchecked(length, &tail_page->write);
84686 return;
84687 }
84688
84689@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84690
84691 /* Set write to end of buffer */
84692 length = (tail + length) - BUF_PAGE_SIZE;
84693- local_sub(length, &tail_page->write);
84694+ local_sub_unchecked(length, &tail_page->write);
84695 }
84696
84697 /*
84698@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84699 * about it.
84700 */
84701 if (unlikely(next_page == commit_page)) {
84702- local_inc(&cpu_buffer->commit_overrun);
84703+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84704 goto out_reset;
84705 }
84706
84707@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84708 cpu_buffer->tail_page) &&
84709 (cpu_buffer->commit_page ==
84710 cpu_buffer->reader_page))) {
84711- local_inc(&cpu_buffer->commit_overrun);
84712+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84713 goto out_reset;
84714 }
84715 }
84716@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84717 length += RB_LEN_TIME_EXTEND;
84718
84719 tail_page = cpu_buffer->tail_page;
84720- write = local_add_return(length, &tail_page->write);
84721+ write = local_add_return_unchecked(length, &tail_page->write);
84722
84723 /* set write to only the index of the write */
84724 write &= RB_WRITE_MASK;
84725@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84726 kmemcheck_annotate_bitfield(event, bitfield);
84727 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84728
84729- local_inc(&tail_page->entries);
84730+ local_inc_unchecked(&tail_page->entries);
84731
84732 /*
84733 * If this is the first commit on the page, then update
84734@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84735
84736 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84737 unsigned long write_mask =
84738- local_read(&bpage->write) & ~RB_WRITE_MASK;
84739+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84740 unsigned long event_length = rb_event_length(event);
84741 /*
84742 * This is on the tail page. It is possible that
84743@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84744 */
84745 old_index += write_mask;
84746 new_index += write_mask;
84747- index = local_cmpxchg(&bpage->write, old_index, new_index);
84748+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84749 if (index == old_index) {
84750 /* update counters */
84751 local_sub(event_length, &cpu_buffer->entries_bytes);
84752@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84753
84754 /* Do the likely case first */
84755 if (likely(bpage->page == (void *)addr)) {
84756- local_dec(&bpage->entries);
84757+ local_dec_unchecked(&bpage->entries);
84758 return;
84759 }
84760
84761@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84762 start = bpage;
84763 do {
84764 if (bpage->page == (void *)addr) {
84765- local_dec(&bpage->entries);
84766+ local_dec_unchecked(&bpage->entries);
84767 return;
84768 }
84769 rb_inc_page(cpu_buffer, &bpage);
84770@@ -3139,7 +3139,7 @@ static inline unsigned long
84771 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84772 {
84773 return local_read(&cpu_buffer->entries) -
84774- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84775+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84776 }
84777
84778 /**
84779@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84780 return 0;
84781
84782 cpu_buffer = buffer->buffers[cpu];
84783- ret = local_read(&cpu_buffer->overrun);
84784+ ret = local_read_unchecked(&cpu_buffer->overrun);
84785
84786 return ret;
84787 }
84788@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84789 return 0;
84790
84791 cpu_buffer = buffer->buffers[cpu];
84792- ret = local_read(&cpu_buffer->commit_overrun);
84793+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84794
84795 return ret;
84796 }
84797@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84798 /* if you care about this being correct, lock the buffer */
84799 for_each_buffer_cpu(buffer, cpu) {
84800 cpu_buffer = buffer->buffers[cpu];
84801- overruns += local_read(&cpu_buffer->overrun);
84802+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84803 }
84804
84805 return overruns;
84806@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84807 /*
84808 * Reset the reader page to size zero.
84809 */
84810- local_set(&cpu_buffer->reader_page->write, 0);
84811- local_set(&cpu_buffer->reader_page->entries, 0);
84812+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84813+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84814 local_set(&cpu_buffer->reader_page->page->commit, 0);
84815 cpu_buffer->reader_page->real_end = 0;
84816
84817@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84818 * want to compare with the last_overrun.
84819 */
84820 smp_mb();
84821- overwrite = local_read(&(cpu_buffer->overrun));
84822+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84823
84824 /*
84825 * Here's the tricky part.
84826@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84827
84828 cpu_buffer->head_page
84829 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84830- local_set(&cpu_buffer->head_page->write, 0);
84831- local_set(&cpu_buffer->head_page->entries, 0);
84832+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84833+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84834 local_set(&cpu_buffer->head_page->page->commit, 0);
84835
84836 cpu_buffer->head_page->read = 0;
84837@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84838
84839 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84840 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84841- local_set(&cpu_buffer->reader_page->write, 0);
84842- local_set(&cpu_buffer->reader_page->entries, 0);
84843+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84844+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84845 local_set(&cpu_buffer->reader_page->page->commit, 0);
84846 cpu_buffer->reader_page->read = 0;
84847
84848 local_set(&cpu_buffer->entries_bytes, 0);
84849- local_set(&cpu_buffer->overrun, 0);
84850- local_set(&cpu_buffer->commit_overrun, 0);
84851+ local_set_unchecked(&cpu_buffer->overrun, 0);
84852+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84853 local_set(&cpu_buffer->dropped_events, 0);
84854 local_set(&cpu_buffer->entries, 0);
84855 local_set(&cpu_buffer->committing, 0);
84856@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84857 rb_init_page(bpage);
84858 bpage = reader->page;
84859 reader->page = *data_page;
84860- local_set(&reader->write, 0);
84861- local_set(&reader->entries, 0);
84862+ local_set_unchecked(&reader->write, 0);
84863+ local_set_unchecked(&reader->entries, 0);
84864 reader->read = 0;
84865 *data_page = bpage;
84866
84867diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84868index 496f94d..754aeea 100644
84869--- a/kernel/trace/trace.c
84870+++ b/kernel/trace/trace.c
84871@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84872 return 0;
84873 }
84874
84875-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84876+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84877 {
84878 /* do nothing if flag is already set */
84879 if (!!(trace_flags & mask) == !!enabled)
84880diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84881index afaae41..64871f8 100644
84882--- a/kernel/trace/trace.h
84883+++ b/kernel/trace/trace.h
84884@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84885 void trace_printk_init_buffers(void);
84886 void trace_printk_start_comm(void);
84887 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84888-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84889+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84890
84891 /*
84892 * Normal trace_printk() and friends allocates special buffers
84893diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84894index 26dc348..8708ca7 100644
84895--- a/kernel/trace/trace_clock.c
84896+++ b/kernel/trace/trace_clock.c
84897@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84898 return now;
84899 }
84900
84901-static atomic64_t trace_counter;
84902+static atomic64_unchecked_t trace_counter;
84903
84904 /*
84905 * trace_clock_counter(): simply an atomic counter.
84906@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84907 */
84908 u64 notrace trace_clock_counter(void)
84909 {
84910- return atomic64_add_return(1, &trace_counter);
84911+ return atomic64_inc_return_unchecked(&trace_counter);
84912 }
84913diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84914index 29a7ebc..eb473cf 100644
84915--- a/kernel/trace/trace_events.c
84916+++ b/kernel/trace/trace_events.c
84917@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84918 struct ftrace_module_file_ops {
84919 struct list_head list;
84920 struct module *mod;
84921- struct file_operations id;
84922- struct file_operations enable;
84923- struct file_operations format;
84924- struct file_operations filter;
84925 };
84926
84927 static struct ftrace_module_file_ops *
84928@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84929
84930 file_ops->mod = mod;
84931
84932- file_ops->id = ftrace_event_id_fops;
84933- file_ops->id.owner = mod;
84934-
84935- file_ops->enable = ftrace_enable_fops;
84936- file_ops->enable.owner = mod;
84937-
84938- file_ops->filter = ftrace_event_filter_fops;
84939- file_ops->filter.owner = mod;
84940-
84941- file_ops->format = ftrace_event_format_fops;
84942- file_ops->format.owner = mod;
84943+ pax_open_kernel();
84944+ mod->trace_id.owner = mod;
84945+ mod->trace_enable.owner = mod;
84946+ mod->trace_filter.owner = mod;
84947+ mod->trace_format.owner = mod;
84948+ pax_close_kernel();
84949
84950 list_add(&file_ops->list, &ftrace_module_file_list);
84951
84952@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84953 struct ftrace_module_file_ops *file_ops)
84954 {
84955 return __trace_add_new_event(call, tr,
84956- &file_ops->id, &file_ops->enable,
84957- &file_ops->filter, &file_ops->format);
84958+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84959+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84960 }
84961
84962 #else
84963diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84964index b3dcfb2..ebee344 100644
84965--- a/kernel/trace/trace_mmiotrace.c
84966+++ b/kernel/trace/trace_mmiotrace.c
84967@@ -24,7 +24,7 @@ struct header_iter {
84968 static struct trace_array *mmio_trace_array;
84969 static bool overrun_detected;
84970 static unsigned long prev_overruns;
84971-static atomic_t dropped_count;
84972+static atomic_unchecked_t dropped_count;
84973
84974 static void mmio_reset_data(struct trace_array *tr)
84975 {
84976@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84977
84978 static unsigned long count_overruns(struct trace_iterator *iter)
84979 {
84980- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84981+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84982 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84983
84984 if (over > prev_overruns)
84985@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84986 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84987 sizeof(*entry), 0, pc);
84988 if (!event) {
84989- atomic_inc(&dropped_count);
84990+ atomic_inc_unchecked(&dropped_count);
84991 return;
84992 }
84993 entry = ring_buffer_event_data(event);
84994@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84995 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84996 sizeof(*entry), 0, pc);
84997 if (!event) {
84998- atomic_inc(&dropped_count);
84999+ atomic_inc_unchecked(&dropped_count);
85000 return;
85001 }
85002 entry = ring_buffer_event_data(event);
85003diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
85004index 34e7cba..6f9a729 100644
85005--- a/kernel/trace/trace_output.c
85006+++ b/kernel/trace/trace_output.c
85007@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
85008
85009 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
85010 if (!IS_ERR(p)) {
85011- p = mangle_path(s->buffer + s->len, p, "\n");
85012+ p = mangle_path(s->buffer + s->len, p, "\n\\");
85013 if (p) {
85014 s->len = p - s->buffer;
85015 return 1;
85016@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
85017 goto out;
85018 }
85019
85020+ pax_open_kernel();
85021 if (event->funcs->trace == NULL)
85022- event->funcs->trace = trace_nop_print;
85023+ *(void **)&event->funcs->trace = trace_nop_print;
85024 if (event->funcs->raw == NULL)
85025- event->funcs->raw = trace_nop_print;
85026+ *(void **)&event->funcs->raw = trace_nop_print;
85027 if (event->funcs->hex == NULL)
85028- event->funcs->hex = trace_nop_print;
85029+ *(void **)&event->funcs->hex = trace_nop_print;
85030 if (event->funcs->binary == NULL)
85031- event->funcs->binary = trace_nop_print;
85032+ *(void **)&event->funcs->binary = trace_nop_print;
85033+ pax_close_kernel();
85034
85035 key = event->type & (EVENT_HASHSIZE - 1);
85036
85037diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85038index b20428c..4845a10 100644
85039--- a/kernel/trace/trace_stack.c
85040+++ b/kernel/trace/trace_stack.c
85041@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85042 return;
85043
85044 /* we do not handle interrupt stacks yet */
85045- if (!object_is_on_stack(stack))
85046+ if (!object_starts_on_stack(stack))
85047 return;
85048
85049 local_irq_save(flags);
85050diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85051index 9064b91..1f5d2f8 100644
85052--- a/kernel/user_namespace.c
85053+++ b/kernel/user_namespace.c
85054@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85055 !kgid_has_mapping(parent_ns, group))
85056 return -EPERM;
85057
85058+#ifdef CONFIG_GRKERNSEC
85059+ /*
85060+ * This doesn't really inspire confidence:
85061+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85062+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85063+ * Increases kernel attack surface in areas developers
85064+ * previously cared little about ("low importance due
85065+ * to requiring "root" capability")
85066+ * To be removed when this code receives *proper* review
85067+ */
85068+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85069+ !capable(CAP_SETGID))
85070+ return -EPERM;
85071+#endif
85072+
85073 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85074 if (!ns)
85075 return -ENOMEM;
85076@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85077 if (atomic_read(&current->mm->mm_users) > 1)
85078 return -EINVAL;
85079
85080- if (current->fs->users != 1)
85081+ if (atomic_read(&current->fs->users) != 1)
85082 return -EINVAL;
85083
85084 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85085diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85086index 4f69f9a..7c6f8f8 100644
85087--- a/kernel/utsname_sysctl.c
85088+++ b/kernel/utsname_sysctl.c
85089@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85090 static int proc_do_uts_string(ctl_table *table, int write,
85091 void __user *buffer, size_t *lenp, loff_t *ppos)
85092 {
85093- struct ctl_table uts_table;
85094+ ctl_table_no_const uts_table;
85095 int r;
85096 memcpy(&uts_table, table, sizeof(uts_table));
85097 uts_table.data = get_uts(table, write);
85098diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85099index 1241d8c..d5cfc28 100644
85100--- a/kernel/watchdog.c
85101+++ b/kernel/watchdog.c
85102@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85103 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85104 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85105
85106-static struct smp_hotplug_thread watchdog_threads = {
85107+static struct smp_hotplug_thread watchdog_threads __read_only = {
85108 .store = &softlockup_watchdog,
85109 .thread_should_run = watchdog_should_run,
85110 .thread_fn = watchdog,
85111diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85112index e93f7b9..989fcd7 100644
85113--- a/kernel/workqueue.c
85114+++ b/kernel/workqueue.c
85115@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85116 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85117 worker_flags |= WORKER_REBOUND;
85118 worker_flags &= ~WORKER_UNBOUND;
85119- ACCESS_ONCE(worker->flags) = worker_flags;
85120+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85121 }
85122
85123 spin_unlock_irq(&pool->lock);
85124diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85125index 1501aa5..e771896 100644
85126--- a/lib/Kconfig.debug
85127+++ b/lib/Kconfig.debug
85128@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85129
85130 config DEBUG_WW_MUTEX_SLOWPATH
85131 bool "Wait/wound mutex debugging: Slowpath testing"
85132- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85133+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85134 select DEBUG_LOCK_ALLOC
85135 select DEBUG_SPINLOCK
85136 select DEBUG_MUTEXES
85137@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85138
85139 config DEBUG_LOCK_ALLOC
85140 bool "Lock debugging: detect incorrect freeing of live locks"
85141- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85142+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85143 select DEBUG_SPINLOCK
85144 select DEBUG_MUTEXES
85145 select LOCKDEP
85146@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85147
85148 config PROVE_LOCKING
85149 bool "Lock debugging: prove locking correctness"
85150- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85151+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85152 select LOCKDEP
85153 select DEBUG_SPINLOCK
85154 select DEBUG_MUTEXES
85155@@ -914,7 +914,7 @@ config LOCKDEP
85156
85157 config LOCK_STAT
85158 bool "Lock usage statistics"
85159- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85160+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85161 select LOCKDEP
85162 select DEBUG_SPINLOCK
85163 select DEBUG_MUTEXES
85164@@ -1357,6 +1357,7 @@ config LATENCYTOP
85165 depends on DEBUG_KERNEL
85166 depends on STACKTRACE_SUPPORT
85167 depends on PROC_FS
85168+ depends on !GRKERNSEC_HIDESYM
85169 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85170 select KALLSYMS
85171 select KALLSYMS_ALL
85172@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85173 config DEBUG_STRICT_USER_COPY_CHECKS
85174 bool "Strict user copy size checks"
85175 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85176- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85177+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85178 help
85179 Enabling this option turns a certain set of sanity checks for user
85180 copy operations into compile time failures.
85181@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85182
85183 config PROVIDE_OHCI1394_DMA_INIT
85184 bool "Remote debugging over FireWire early on boot"
85185- depends on PCI && X86
85186+ depends on PCI && X86 && !GRKERNSEC
85187 help
85188 If you want to debug problems which hang or crash the kernel early
85189 on boot and the crashing machine has a FireWire port, you can use
85190@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85191
85192 config FIREWIRE_OHCI_REMOTE_DMA
85193 bool "Remote debugging over FireWire with firewire-ohci"
85194- depends on FIREWIRE_OHCI
85195+ depends on FIREWIRE_OHCI && !GRKERNSEC
85196 help
85197 This option lets you use the FireWire bus for remote debugging
85198 with help of the firewire-ohci driver. It enables unfiltered
85199diff --git a/lib/Makefile b/lib/Makefile
85200index 7baccfd..3ceb95f 100644
85201--- a/lib/Makefile
85202+++ b/lib/Makefile
85203@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85204
85205 obj-$(CONFIG_BTREE) += btree.o
85206 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85207-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85208+obj-y += list_debug.o
85209 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85210
85211 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85212diff --git a/lib/bitmap.c b/lib/bitmap.c
85213index 06f7e4f..f3cf2b0 100644
85214--- a/lib/bitmap.c
85215+++ b/lib/bitmap.c
85216@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85217 {
85218 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85219 u32 chunk;
85220- const char __user __force *ubuf = (const char __user __force *)buf;
85221+ const char __user *ubuf = (const char __force_user *)buf;
85222
85223 bitmap_zero(maskp, nmaskbits);
85224
85225@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85226 {
85227 if (!access_ok(VERIFY_READ, ubuf, ulen))
85228 return -EFAULT;
85229- return __bitmap_parse((const char __force *)ubuf,
85230+ return __bitmap_parse((const char __force_kernel *)ubuf,
85231 ulen, 1, maskp, nmaskbits);
85232
85233 }
85234@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85235 {
85236 unsigned a, b;
85237 int c, old_c, totaldigits;
85238- const char __user __force *ubuf = (const char __user __force *)buf;
85239+ const char __user *ubuf = (const char __force_user *)buf;
85240 int exp_digit, in_range;
85241
85242 totaldigits = c = 0;
85243@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85244 {
85245 if (!access_ok(VERIFY_READ, ubuf, ulen))
85246 return -EFAULT;
85247- return __bitmap_parselist((const char __force *)ubuf,
85248+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85249 ulen, 1, maskp, nmaskbits);
85250 }
85251 EXPORT_SYMBOL(bitmap_parselist_user);
85252diff --git a/lib/bug.c b/lib/bug.c
85253index 1686034..a9c00c8 100644
85254--- a/lib/bug.c
85255+++ b/lib/bug.c
85256@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85257 return BUG_TRAP_TYPE_NONE;
85258
85259 bug = find_bug(bugaddr);
85260+ if (!bug)
85261+ return BUG_TRAP_TYPE_NONE;
85262
85263 file = NULL;
85264 line = 0;
85265diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85266index 37061ed..da83f48 100644
85267--- a/lib/debugobjects.c
85268+++ b/lib/debugobjects.c
85269@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85270 if (limit > 4)
85271 return;
85272
85273- is_on_stack = object_is_on_stack(addr);
85274+ is_on_stack = object_starts_on_stack(addr);
85275 if (is_on_stack == onstack)
85276 return;
85277
85278diff --git a/lib/devres.c b/lib/devres.c
85279index 8235331..5881053 100644
85280--- a/lib/devres.c
85281+++ b/lib/devres.c
85282@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85283 void devm_iounmap(struct device *dev, void __iomem *addr)
85284 {
85285 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85286- (void *)addr));
85287+ (void __force *)addr));
85288 iounmap(addr);
85289 }
85290 EXPORT_SYMBOL(devm_iounmap);
85291@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85292 {
85293 ioport_unmap(addr);
85294 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85295- devm_ioport_map_match, (void *)addr));
85296+ devm_ioport_map_match, (void __force *)addr));
85297 }
85298 EXPORT_SYMBOL(devm_ioport_unmap);
85299 #endif /* CONFIG_HAS_IOPORT */
85300diff --git a/lib/div64.c b/lib/div64.c
85301index a163b6c..9618fa5 100644
85302--- a/lib/div64.c
85303+++ b/lib/div64.c
85304@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85305 EXPORT_SYMBOL(__div64_32);
85306
85307 #ifndef div_s64_rem
85308-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85309+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85310 {
85311 u64 quotient;
85312
85313@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85314 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85315 */
85316 #ifndef div64_u64
85317-u64 div64_u64(u64 dividend, u64 divisor)
85318+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85319 {
85320 u32 high = divisor >> 32;
85321 u64 quot;
85322diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85323index d87a17a..ac0d79a 100644
85324--- a/lib/dma-debug.c
85325+++ b/lib/dma-debug.c
85326@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85327
85328 void dma_debug_add_bus(struct bus_type *bus)
85329 {
85330- struct notifier_block *nb;
85331+ notifier_block_no_const *nb;
85332
85333 if (global_disable)
85334 return;
85335@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85336
85337 static void check_for_stack(struct device *dev, void *addr)
85338 {
85339- if (object_is_on_stack(addr))
85340+ if (object_starts_on_stack(addr))
85341 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85342 "stack [addr=%p]\n", addr);
85343 }
85344diff --git a/lib/inflate.c b/lib/inflate.c
85345index 013a761..c28f3fc 100644
85346--- a/lib/inflate.c
85347+++ b/lib/inflate.c
85348@@ -269,7 +269,7 @@ static void free(void *where)
85349 malloc_ptr = free_mem_ptr;
85350 }
85351 #else
85352-#define malloc(a) kmalloc(a, GFP_KERNEL)
85353+#define malloc(a) kmalloc((a), GFP_KERNEL)
85354 #define free(a) kfree(a)
85355 #endif
85356
85357diff --git a/lib/ioremap.c b/lib/ioremap.c
85358index 0c9216c..863bd89 100644
85359--- a/lib/ioremap.c
85360+++ b/lib/ioremap.c
85361@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85362 unsigned long next;
85363
85364 phys_addr -= addr;
85365- pmd = pmd_alloc(&init_mm, pud, addr);
85366+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85367 if (!pmd)
85368 return -ENOMEM;
85369 do {
85370@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85371 unsigned long next;
85372
85373 phys_addr -= addr;
85374- pud = pud_alloc(&init_mm, pgd, addr);
85375+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85376 if (!pud)
85377 return -ENOMEM;
85378 do {
85379diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85380index bd2bea9..6b3c95e 100644
85381--- a/lib/is_single_threaded.c
85382+++ b/lib/is_single_threaded.c
85383@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85384 struct task_struct *p, *t;
85385 bool ret;
85386
85387+ if (!mm)
85388+ return true;
85389+
85390 if (atomic_read(&task->signal->live) != 1)
85391 return false;
85392
85393diff --git a/lib/kobject.c b/lib/kobject.c
85394index 4a1f33d..2f3ca75 100644
85395--- a/lib/kobject.c
85396+++ b/lib/kobject.c
85397@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85398
85399
85400 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85401-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85402+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85403
85404-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85405+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85406 {
85407 enum kobj_ns_type type = ops->type;
85408 int error;
85409diff --git a/lib/list_debug.c b/lib/list_debug.c
85410index c24c2f7..06e070b 100644
85411--- a/lib/list_debug.c
85412+++ b/lib/list_debug.c
85413@@ -11,7 +11,9 @@
85414 #include <linux/bug.h>
85415 #include <linux/kernel.h>
85416 #include <linux/rculist.h>
85417+#include <linux/mm.h>
85418
85419+#ifdef CONFIG_DEBUG_LIST
85420 /*
85421 * Insert a new entry between two known consecutive entries.
85422 *
85423@@ -19,21 +21,32 @@
85424 * the prev/next entries already!
85425 */
85426
85427-void __list_add(struct list_head *new,
85428- struct list_head *prev,
85429- struct list_head *next)
85430+static bool __list_add_debug(struct list_head *new,
85431+ struct list_head *prev,
85432+ struct list_head *next)
85433 {
85434- WARN(next->prev != prev,
85435+ if (WARN(next->prev != prev,
85436 "list_add corruption. next->prev should be "
85437 "prev (%p), but was %p. (next=%p).\n",
85438- prev, next->prev, next);
85439- WARN(prev->next != next,
85440+ prev, next->prev, next) ||
85441+ WARN(prev->next != next,
85442 "list_add corruption. prev->next should be "
85443 "next (%p), but was %p. (prev=%p).\n",
85444- next, prev->next, prev);
85445- WARN(new == prev || new == next,
85446- "list_add double add: new=%p, prev=%p, next=%p.\n",
85447- new, prev, next);
85448+ next, prev->next, prev) ||
85449+ WARN(new == prev || new == next,
85450+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85451+ new, prev, next))
85452+ return false;
85453+ return true;
85454+}
85455+
85456+void __list_add(struct list_head *new,
85457+ struct list_head *prev,
85458+ struct list_head *next)
85459+{
85460+ if (!__list_add_debug(new, prev, next))
85461+ return;
85462+
85463 next->prev = new;
85464 new->next = next;
85465 new->prev = prev;
85466@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85467 }
85468 EXPORT_SYMBOL(__list_add);
85469
85470-void __list_del_entry(struct list_head *entry)
85471+static bool __list_del_entry_debug(struct list_head *entry)
85472 {
85473 struct list_head *prev, *next;
85474
85475@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85476 WARN(next->prev != entry,
85477 "list_del corruption. next->prev should be %p, "
85478 "but was %p\n", entry, next->prev))
85479+ return false;
85480+ return true;
85481+}
85482+
85483+void __list_del_entry(struct list_head *entry)
85484+{
85485+ if (!__list_del_entry_debug(entry))
85486 return;
85487
85488- __list_del(prev, next);
85489+ __list_del(entry->prev, entry->next);
85490 }
85491 EXPORT_SYMBOL(__list_del_entry);
85492
85493@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85494 void __list_add_rcu(struct list_head *new,
85495 struct list_head *prev, struct list_head *next)
85496 {
85497- WARN(next->prev != prev,
85498- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85499- prev, next->prev, next);
85500- WARN(prev->next != next,
85501- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85502- next, prev->next, prev);
85503+ if (!__list_add_debug(new, prev, next))
85504+ return;
85505+
85506 new->next = next;
85507 new->prev = prev;
85508 rcu_assign_pointer(list_next_rcu(prev), new);
85509 next->prev = new;
85510 }
85511 EXPORT_SYMBOL(__list_add_rcu);
85512+#endif
85513+
85514+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85515+{
85516+#ifdef CONFIG_DEBUG_LIST
85517+ if (!__list_add_debug(new, prev, next))
85518+ return;
85519+#endif
85520+
85521+ pax_open_kernel();
85522+ next->prev = new;
85523+ new->next = next;
85524+ new->prev = prev;
85525+ prev->next = new;
85526+ pax_close_kernel();
85527+}
85528+EXPORT_SYMBOL(__pax_list_add);
85529+
85530+void pax_list_del(struct list_head *entry)
85531+{
85532+#ifdef CONFIG_DEBUG_LIST
85533+ if (!__list_del_entry_debug(entry))
85534+ return;
85535+#endif
85536+
85537+ pax_open_kernel();
85538+ __list_del(entry->prev, entry->next);
85539+ entry->next = LIST_POISON1;
85540+ entry->prev = LIST_POISON2;
85541+ pax_close_kernel();
85542+}
85543+EXPORT_SYMBOL(pax_list_del);
85544+
85545+void pax_list_del_init(struct list_head *entry)
85546+{
85547+ pax_open_kernel();
85548+ __list_del(entry->prev, entry->next);
85549+ INIT_LIST_HEAD(entry);
85550+ pax_close_kernel();
85551+}
85552+EXPORT_SYMBOL(pax_list_del_init);
85553+
85554+void __pax_list_add_rcu(struct list_head *new,
85555+ struct list_head *prev, struct list_head *next)
85556+{
85557+#ifdef CONFIG_DEBUG_LIST
85558+ if (!__list_add_debug(new, prev, next))
85559+ return;
85560+#endif
85561+
85562+ pax_open_kernel();
85563+ new->next = next;
85564+ new->prev = prev;
85565+ rcu_assign_pointer(list_next_rcu(prev), new);
85566+ next->prev = new;
85567+ pax_close_kernel();
85568+}
85569+EXPORT_SYMBOL(__pax_list_add_rcu);
85570+
85571+void pax_list_del_rcu(struct list_head *entry)
85572+{
85573+#ifdef CONFIG_DEBUG_LIST
85574+ if (!__list_del_entry_debug(entry))
85575+ return;
85576+#endif
85577+
85578+ pax_open_kernel();
85579+ __list_del(entry->prev, entry->next);
85580+ entry->next = LIST_POISON1;
85581+ entry->prev = LIST_POISON2;
85582+ pax_close_kernel();
85583+}
85584+EXPORT_SYMBOL(pax_list_del_rcu);
85585diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85586index 7deeb62..144eb47 100644
85587--- a/lib/percpu-refcount.c
85588+++ b/lib/percpu-refcount.c
85589@@ -29,7 +29,7 @@
85590 * can't hit 0 before we've added up all the percpu refs.
85591 */
85592
85593-#define PCPU_COUNT_BIAS (1U << 31)
85594+#define PCPU_COUNT_BIAS (1U << 30)
85595
85596 /**
85597 * percpu_ref_init - initialize a percpu refcount
85598diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85599index e796429..6e38f9f 100644
85600--- a/lib/radix-tree.c
85601+++ b/lib/radix-tree.c
85602@@ -92,7 +92,7 @@ struct radix_tree_preload {
85603 int nr;
85604 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85605 };
85606-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85607+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85608
85609 static inline void *ptr_to_indirect(void *ptr)
85610 {
85611diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85612index bb2b201..46abaf9 100644
85613--- a/lib/strncpy_from_user.c
85614+++ b/lib/strncpy_from_user.c
85615@@ -21,7 +21,7 @@
85616 */
85617 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85618 {
85619- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85620+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85621 long res = 0;
85622
85623 /*
85624diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85625index a28df52..3d55877 100644
85626--- a/lib/strnlen_user.c
85627+++ b/lib/strnlen_user.c
85628@@ -26,7 +26,7 @@
85629 */
85630 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85631 {
85632- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85633+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85634 long align, res = 0;
85635 unsigned long c;
85636
85637diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85638index d23762e..e21eab2 100644
85639--- a/lib/swiotlb.c
85640+++ b/lib/swiotlb.c
85641@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85642
85643 void
85644 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85645- dma_addr_t dev_addr)
85646+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85647 {
85648 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85649
85650diff --git a/lib/usercopy.c b/lib/usercopy.c
85651index 4f5b1dd..7cab418 100644
85652--- a/lib/usercopy.c
85653+++ b/lib/usercopy.c
85654@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85655 WARN(1, "Buffer overflow detected!\n");
85656 }
85657 EXPORT_SYMBOL(copy_from_user_overflow);
85658+
85659+void copy_to_user_overflow(void)
85660+{
85661+ WARN(1, "Buffer overflow detected!\n");
85662+}
85663+EXPORT_SYMBOL(copy_to_user_overflow);
85664diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85665index 739a363..aa668d7 100644
85666--- a/lib/vsprintf.c
85667+++ b/lib/vsprintf.c
85668@@ -16,6 +16,9 @@
85669 * - scnprintf and vscnprintf
85670 */
85671
85672+#ifdef CONFIG_GRKERNSEC_HIDESYM
85673+#define __INCLUDED_BY_HIDESYM 1
85674+#endif
85675 #include <stdarg.h>
85676 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85677 #include <linux/types.h>
85678@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85679 return number(buf, end, *(const netdev_features_t *)addr, spec);
85680 }
85681
85682+#ifdef CONFIG_GRKERNSEC_HIDESYM
85683+int kptr_restrict __read_mostly = 2;
85684+#else
85685 int kptr_restrict __read_mostly;
85686+#endif
85687
85688 /*
85689 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85690@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85691 * - 'f' For simple symbolic function names without offset
85692 * - 'S' For symbolic direct pointers with offset
85693 * - 's' For symbolic direct pointers without offset
85694+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85695 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85696 * - 'B' For backtraced symbolic direct pointers with offset
85697 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85698@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85699
85700 if (!ptr && *fmt != 'K') {
85701 /*
85702- * Print (null) with the same width as a pointer so it makes
85703+ * Print (nil) with the same width as a pointer so it makes
85704 * tabular output look nice.
85705 */
85706 if (spec.field_width == -1)
85707 spec.field_width = default_width;
85708- return string(buf, end, "(null)", spec);
85709+ return string(buf, end, "(nil)", spec);
85710 }
85711
85712 switch (*fmt) {
85713@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85714 /* Fallthrough */
85715 case 'S':
85716 case 's':
85717+#ifdef CONFIG_GRKERNSEC_HIDESYM
85718+ break;
85719+#else
85720+ return symbol_string(buf, end, ptr, spec, fmt);
85721+#endif
85722+ case 'A':
85723 case 'B':
85724 return symbol_string(buf, end, ptr, spec, fmt);
85725 case 'R':
85726@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85727 va_end(va);
85728 return buf;
85729 }
85730+ case 'P':
85731+ break;
85732 case 'K':
85733 /*
85734 * %pK cannot be used in IRQ context because its test
85735@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85736 return number(buf, end,
85737 (unsigned long long) *((phys_addr_t *)ptr), spec);
85738 }
85739+
85740+#ifdef CONFIG_GRKERNSEC_HIDESYM
85741+ /* 'P' = approved pointers to copy to userland,
85742+ as in the /proc/kallsyms case, as we make it display nothing
85743+ for non-root users, and the real contents for root users
85744+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85745+ above
85746+ */
85747+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85748+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85749+ dump_stack();
85750+ ptr = NULL;
85751+ }
85752+#endif
85753+
85754 spec.flags |= SMALL;
85755 if (spec.field_width == -1) {
85756 spec.field_width = default_width;
85757@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85758 typeof(type) value; \
85759 if (sizeof(type) == 8) { \
85760 args = PTR_ALIGN(args, sizeof(u32)); \
85761- *(u32 *)&value = *(u32 *)args; \
85762- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85763+ *(u32 *)&value = *(const u32 *)args; \
85764+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85765 } else { \
85766 args = PTR_ALIGN(args, sizeof(type)); \
85767- value = *(typeof(type) *)args; \
85768+ value = *(const typeof(type) *)args; \
85769 } \
85770 args += sizeof(type); \
85771 value; \
85772@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85773 case FORMAT_TYPE_STR: {
85774 const char *str_arg = args;
85775 args += strlen(str_arg) + 1;
85776- str = string(str, end, (char *)str_arg, spec);
85777+ str = string(str, end, str_arg, spec);
85778 break;
85779 }
85780
85781diff --git a/localversion-grsec b/localversion-grsec
85782new file mode 100644
85783index 0000000..7cd6065
85784--- /dev/null
85785+++ b/localversion-grsec
85786@@ -0,0 +1 @@
85787+-grsec
85788diff --git a/mm/Kconfig b/mm/Kconfig
85789index 6509d27..dbec5b8 100644
85790--- a/mm/Kconfig
85791+++ b/mm/Kconfig
85792@@ -317,10 +317,10 @@ config KSM
85793 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85794
85795 config DEFAULT_MMAP_MIN_ADDR
85796- int "Low address space to protect from user allocation"
85797+ int "Low address space to protect from user allocation"
85798 depends on MMU
85799- default 4096
85800- help
85801+ default 65536
85802+ help
85803 This is the portion of low virtual memory which should be protected
85804 from userspace allocation. Keeping a user from writing to low pages
85805 can help reduce the impact of kernel NULL pointer bugs.
85806@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85807
85808 config HWPOISON_INJECT
85809 tristate "HWPoison pages injector"
85810- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85811+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85812 select PROC_PAGE_MONITOR
85813
85814 config NOMMU_INITIAL_TRIM_EXCESS
85815diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85816index e04454c..ca5be3e 100644
85817--- a/mm/backing-dev.c
85818+++ b/mm/backing-dev.c
85819@@ -12,7 +12,7 @@
85820 #include <linux/device.h>
85821 #include <trace/events/writeback.h>
85822
85823-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85824+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85825
85826 struct backing_dev_info default_backing_dev_info = {
85827 .name = "default",
85828@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85829 return err;
85830
85831 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85832- atomic_long_inc_return(&bdi_seq));
85833+ atomic_long_inc_return_unchecked(&bdi_seq));
85834 if (err) {
85835 bdi_destroy(bdi);
85836 return err;
85837diff --git a/mm/filemap.c b/mm/filemap.c
85838index 4b51ac1..5aa90ff 100644
85839--- a/mm/filemap.c
85840+++ b/mm/filemap.c
85841@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85842 struct address_space *mapping = file->f_mapping;
85843
85844 if (!mapping->a_ops->readpage)
85845- return -ENOEXEC;
85846+ return -ENODEV;
85847 file_accessed(file);
85848 vma->vm_ops = &generic_file_vm_ops;
85849 return 0;
85850@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85851
85852 while (bytes) {
85853 char __user *buf = iov->iov_base + base;
85854- int copy = min(bytes, iov->iov_len - base);
85855+ size_t copy = min(bytes, iov->iov_len - base);
85856
85857 base = 0;
85858 left = __copy_from_user_inatomic(vaddr, buf, copy);
85859@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85860 BUG_ON(!in_atomic());
85861 kaddr = kmap_atomic(page);
85862 if (likely(i->nr_segs == 1)) {
85863- int left;
85864+ size_t left;
85865 char __user *buf = i->iov->iov_base + i->iov_offset;
85866 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85867 copied = bytes - left;
85868@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85869
85870 kaddr = kmap(page);
85871 if (likely(i->nr_segs == 1)) {
85872- int left;
85873+ size_t left;
85874 char __user *buf = i->iov->iov_base + i->iov_offset;
85875 left = __copy_from_user(kaddr + offset, buf, bytes);
85876 copied = bytes - left;
85877@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85878 * zero-length segments (without overruning the iovec).
85879 */
85880 while (bytes || unlikely(i->count && !iov->iov_len)) {
85881- int copy;
85882+ size_t copy;
85883
85884 copy = min(bytes, iov->iov_len - base);
85885 BUG_ON(!i->count || i->count < copy);
85886@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85887 *pos = i_size_read(inode);
85888
85889 if (limit != RLIM_INFINITY) {
85890+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85891 if (*pos >= limit) {
85892 send_sig(SIGXFSZ, current, 0);
85893 return -EFBIG;
85894diff --git a/mm/fremap.c b/mm/fremap.c
85895index 5bff081..d8189a9 100644
85896--- a/mm/fremap.c
85897+++ b/mm/fremap.c
85898@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85899 retry:
85900 vma = find_vma(mm, start);
85901
85902+#ifdef CONFIG_PAX_SEGMEXEC
85903+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85904+ goto out;
85905+#endif
85906+
85907 /*
85908 * Make sure the vma is shared, that it supports prefaulting,
85909 * and that the remapped range is valid and fully within
85910diff --git a/mm/highmem.c b/mm/highmem.c
85911index b32b70c..e512eb0 100644
85912--- a/mm/highmem.c
85913+++ b/mm/highmem.c
85914@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85915 * So no dangers, even with speculative execution.
85916 */
85917 page = pte_page(pkmap_page_table[i]);
85918+ pax_open_kernel();
85919 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85920-
85921+ pax_close_kernel();
85922 set_page_address(page, NULL);
85923 need_flush = 1;
85924 }
85925@@ -198,9 +199,11 @@ start:
85926 }
85927 }
85928 vaddr = PKMAP_ADDR(last_pkmap_nr);
85929+
85930+ pax_open_kernel();
85931 set_pte_at(&init_mm, vaddr,
85932 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85933-
85934+ pax_close_kernel();
85935 pkmap_count[last_pkmap_nr] = 1;
85936 set_page_address(page, (void *)vaddr);
85937
85938diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85939index b60f330..ee7de7e 100644
85940--- a/mm/hugetlb.c
85941+++ b/mm/hugetlb.c
85942@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85943 struct hstate *h = &default_hstate;
85944 unsigned long tmp;
85945 int ret;
85946+ ctl_table_no_const hugetlb_table;
85947
85948 tmp = h->max_huge_pages;
85949
85950 if (write && h->order >= MAX_ORDER)
85951 return -EINVAL;
85952
85953- table->data = &tmp;
85954- table->maxlen = sizeof(unsigned long);
85955- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85956+ hugetlb_table = *table;
85957+ hugetlb_table.data = &tmp;
85958+ hugetlb_table.maxlen = sizeof(unsigned long);
85959+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85960 if (ret)
85961 goto out;
85962
85963@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85964 struct hstate *h = &default_hstate;
85965 unsigned long tmp;
85966 int ret;
85967+ ctl_table_no_const hugetlb_table;
85968
85969 tmp = h->nr_overcommit_huge_pages;
85970
85971 if (write && h->order >= MAX_ORDER)
85972 return -EINVAL;
85973
85974- table->data = &tmp;
85975- table->maxlen = sizeof(unsigned long);
85976- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85977+ hugetlb_table = *table;
85978+ hugetlb_table.data = &tmp;
85979+ hugetlb_table.maxlen = sizeof(unsigned long);
85980+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85981 if (ret)
85982 goto out;
85983
85984@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
85985 return 1;
85986 }
85987
85988+#ifdef CONFIG_PAX_SEGMEXEC
85989+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
85990+{
85991+ struct mm_struct *mm = vma->vm_mm;
85992+ struct vm_area_struct *vma_m;
85993+ unsigned long address_m;
85994+ pte_t *ptep_m;
85995+
85996+ vma_m = pax_find_mirror_vma(vma);
85997+ if (!vma_m)
85998+ return;
85999+
86000+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86001+ address_m = address + SEGMEXEC_TASK_SIZE;
86002+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86003+ get_page(page_m);
86004+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86005+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86006+}
86007+#endif
86008+
86009 /*
86010 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86011 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86012@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86013 make_huge_pte(vma, new_page, 1));
86014 page_remove_rmap(old_page);
86015 hugepage_add_new_anon_rmap(new_page, vma, address);
86016+
86017+#ifdef CONFIG_PAX_SEGMEXEC
86018+ pax_mirror_huge_pte(vma, address, new_page);
86019+#endif
86020+
86021 /* Make the old page be freed below */
86022 new_page = old_page;
86023 }
86024@@ -2821,6 +2851,10 @@ retry:
86025 && (vma->vm_flags & VM_SHARED)));
86026 set_huge_pte_at(mm, address, ptep, new_pte);
86027
86028+#ifdef CONFIG_PAX_SEGMEXEC
86029+ pax_mirror_huge_pte(vma, address, page);
86030+#endif
86031+
86032 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86033 /* Optimization, do the COW without a second fault */
86034 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86035@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86036 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86037 struct hstate *h = hstate_vma(vma);
86038
86039+#ifdef CONFIG_PAX_SEGMEXEC
86040+ struct vm_area_struct *vma_m;
86041+#endif
86042+
86043 address &= huge_page_mask(h);
86044
86045 ptep = huge_pte_offset(mm, address);
86046@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86047 VM_FAULT_SET_HINDEX(hstate_index(h));
86048 }
86049
86050+#ifdef CONFIG_PAX_SEGMEXEC
86051+ vma_m = pax_find_mirror_vma(vma);
86052+ if (vma_m) {
86053+ unsigned long address_m;
86054+
86055+ if (vma->vm_start > vma_m->vm_start) {
86056+ address_m = address;
86057+ address -= SEGMEXEC_TASK_SIZE;
86058+ vma = vma_m;
86059+ h = hstate_vma(vma);
86060+ } else
86061+ address_m = address + SEGMEXEC_TASK_SIZE;
86062+
86063+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86064+ return VM_FAULT_OOM;
86065+ address_m &= HPAGE_MASK;
86066+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86067+ }
86068+#endif
86069+
86070 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86071 if (!ptep)
86072 return VM_FAULT_OOM;
86073diff --git a/mm/internal.h b/mm/internal.h
86074index 4390ac6..fc60373c 100644
86075--- a/mm/internal.h
86076+++ b/mm/internal.h
86077@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86078 * in mm/page_alloc.c
86079 */
86080 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86081+extern void free_compound_page(struct page *page);
86082 extern void prep_compound_page(struct page *page, unsigned long order);
86083 #ifdef CONFIG_MEMORY_FAILURE
86084 extern bool is_free_buddy_page(struct page *page);
86085@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86086
86087 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86088 unsigned long, unsigned long,
86089- unsigned long, unsigned long);
86090+ unsigned long, unsigned long) __intentional_overflow(-1);
86091
86092 extern void set_pageblock_order(void);
86093 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86094diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86095index c8d7f31..2dbeffd 100644
86096--- a/mm/kmemleak.c
86097+++ b/mm/kmemleak.c
86098@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86099
86100 for (i = 0; i < object->trace_len; i++) {
86101 void *ptr = (void *)object->trace[i];
86102- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86103+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86104 }
86105 }
86106
86107@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86108 return -ENOMEM;
86109 }
86110
86111- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86112+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86113 &kmemleak_fops);
86114 if (!dentry)
86115 pr_warning("Failed to create the debugfs kmemleak file\n");
86116diff --git a/mm/maccess.c b/mm/maccess.c
86117index d53adf9..03a24bf 100644
86118--- a/mm/maccess.c
86119+++ b/mm/maccess.c
86120@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86121 set_fs(KERNEL_DS);
86122 pagefault_disable();
86123 ret = __copy_from_user_inatomic(dst,
86124- (__force const void __user *)src, size);
86125+ (const void __force_user *)src, size);
86126 pagefault_enable();
86127 set_fs(old_fs);
86128
86129@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86130
86131 set_fs(KERNEL_DS);
86132 pagefault_disable();
86133- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86134+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86135 pagefault_enable();
86136 set_fs(old_fs);
86137
86138diff --git a/mm/madvise.c b/mm/madvise.c
86139index 7055883..aafb1ed 100644
86140--- a/mm/madvise.c
86141+++ b/mm/madvise.c
86142@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86143 pgoff_t pgoff;
86144 unsigned long new_flags = vma->vm_flags;
86145
86146+#ifdef CONFIG_PAX_SEGMEXEC
86147+ struct vm_area_struct *vma_m;
86148+#endif
86149+
86150 switch (behavior) {
86151 case MADV_NORMAL:
86152 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86153@@ -126,6 +130,13 @@ success:
86154 /*
86155 * vm_flags is protected by the mmap_sem held in write mode.
86156 */
86157+
86158+#ifdef CONFIG_PAX_SEGMEXEC
86159+ vma_m = pax_find_mirror_vma(vma);
86160+ if (vma_m)
86161+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86162+#endif
86163+
86164 vma->vm_flags = new_flags;
86165
86166 out:
86167@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86168 struct vm_area_struct ** prev,
86169 unsigned long start, unsigned long end)
86170 {
86171+
86172+#ifdef CONFIG_PAX_SEGMEXEC
86173+ struct vm_area_struct *vma_m;
86174+#endif
86175+
86176 *prev = vma;
86177 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86178 return -EINVAL;
86179@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86180 zap_page_range(vma, start, end - start, &details);
86181 } else
86182 zap_page_range(vma, start, end - start, NULL);
86183+
86184+#ifdef CONFIG_PAX_SEGMEXEC
86185+ vma_m = pax_find_mirror_vma(vma);
86186+ if (vma_m) {
86187+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86188+ struct zap_details details = {
86189+ .nonlinear_vma = vma_m,
86190+ .last_index = ULONG_MAX,
86191+ };
86192+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86193+ } else
86194+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86195+ }
86196+#endif
86197+
86198 return 0;
86199 }
86200
86201@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86202 if (end < start)
86203 return error;
86204
86205+#ifdef CONFIG_PAX_SEGMEXEC
86206+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86207+ if (end > SEGMEXEC_TASK_SIZE)
86208+ return error;
86209+ } else
86210+#endif
86211+
86212+ if (end > TASK_SIZE)
86213+ return error;
86214+
86215 error = 0;
86216 if (end == start)
86217 return error;
86218diff --git a/mm/memcontrol.c b/mm/memcontrol.c
86219index aa44621..99011b3 100644
86220--- a/mm/memcontrol.c
86221+++ b/mm/memcontrol.c
86222@@ -2772,6 +2772,8 @@ done:
86223 return 0;
86224 nomem:
86225 *ptr = NULL;
86226+ if (gfp_mask & __GFP_NOFAIL)
86227+ return 0;
86228 return -ENOMEM;
86229 bypass:
86230 *ptr = root_mem_cgroup;
86231diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86232index 2c13aa7..64cbc3f 100644
86233--- a/mm/memory-failure.c
86234+++ b/mm/memory-failure.c
86235@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86236
86237 int sysctl_memory_failure_recovery __read_mostly = 1;
86238
86239-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86240+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86241
86242 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86243
86244@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86245 pfn, t->comm, t->pid);
86246 si.si_signo = SIGBUS;
86247 si.si_errno = 0;
86248- si.si_addr = (void *)addr;
86249+ si.si_addr = (void __user *)addr;
86250 #ifdef __ARCH_SI_TRAPNO
86251 si.si_trapno = trapno;
86252 #endif
86253@@ -760,7 +760,7 @@ static struct page_state {
86254 unsigned long res;
86255 char *msg;
86256 int (*action)(struct page *p, unsigned long pfn);
86257-} error_states[] = {
86258+} __do_const error_states[] = {
86259 { reserved, reserved, "reserved kernel", me_kernel },
86260 /*
86261 * free pages are specially detected outside this table:
86262@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86263 nr_pages = 1 << compound_order(hpage);
86264 else /* normal page or thp */
86265 nr_pages = 1;
86266- atomic_long_add(nr_pages, &num_poisoned_pages);
86267+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86268
86269 /*
86270 * We need/can do nothing about count=0 pages.
86271@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86272 if (!PageHWPoison(hpage)
86273 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86274 || (p != hpage && TestSetPageHWPoison(hpage))) {
86275- atomic_long_sub(nr_pages, &num_poisoned_pages);
86276+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86277 return 0;
86278 }
86279 set_page_hwpoison_huge_page(hpage);
86280@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86281 }
86282 if (hwpoison_filter(p)) {
86283 if (TestClearPageHWPoison(p))
86284- atomic_long_sub(nr_pages, &num_poisoned_pages);
86285+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86286 unlock_page(hpage);
86287 put_page(hpage);
86288 return 0;
86289@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86290 return 0;
86291 }
86292 if (TestClearPageHWPoison(p))
86293- atomic_long_sub(nr_pages, &num_poisoned_pages);
86294+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86295 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86296 return 0;
86297 }
86298@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86299 */
86300 if (TestClearPageHWPoison(page)) {
86301 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86302- atomic_long_sub(nr_pages, &num_poisoned_pages);
86303+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86304 freeit = 1;
86305 if (PageHuge(page))
86306 clear_page_hwpoison_huge_page(page);
86307@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86308 } else {
86309 set_page_hwpoison_huge_page(hpage);
86310 dequeue_hwpoisoned_huge_page(hpage);
86311- atomic_long_add(1 << compound_trans_order(hpage),
86312+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86313 &num_poisoned_pages);
86314 }
86315 return ret;
86316@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86317 if (PageHuge(page)) {
86318 set_page_hwpoison_huge_page(hpage);
86319 dequeue_hwpoisoned_huge_page(hpage);
86320- atomic_long_add(1 << compound_trans_order(hpage),
86321+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86322 &num_poisoned_pages);
86323 } else {
86324 SetPageHWPoison(page);
86325- atomic_long_inc(&num_poisoned_pages);
86326+ atomic_long_inc_unchecked(&num_poisoned_pages);
86327 }
86328 }
86329 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86330@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86331 put_page(page);
86332 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86333 SetPageHWPoison(page);
86334- atomic_long_inc(&num_poisoned_pages);
86335+ atomic_long_inc_unchecked(&num_poisoned_pages);
86336 return 0;
86337 }
86338
86339@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86340 if (!is_free_buddy_page(page))
86341 pr_info("soft offline: %#lx: page leaked\n",
86342 pfn);
86343- atomic_long_inc(&num_poisoned_pages);
86344+ atomic_long_inc_unchecked(&num_poisoned_pages);
86345 }
86346 } else {
86347 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86348diff --git a/mm/memory.c b/mm/memory.c
86349index af84bc0..2ed0816 100644
86350--- a/mm/memory.c
86351+++ b/mm/memory.c
86352@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86353 free_pte_range(tlb, pmd, addr);
86354 } while (pmd++, addr = next, addr != end);
86355
86356+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86357 start &= PUD_MASK;
86358 if (start < floor)
86359 return;
86360@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86361 pmd = pmd_offset(pud, start);
86362 pud_clear(pud);
86363 pmd_free_tlb(tlb, pmd, start);
86364+#endif
86365+
86366 }
86367
86368 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86369@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86370 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86371 } while (pud++, addr = next, addr != end);
86372
86373+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86374 start &= PGDIR_MASK;
86375 if (start < floor)
86376 return;
86377@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86378 pud = pud_offset(pgd, start);
86379 pgd_clear(pgd);
86380 pud_free_tlb(tlb, pud, start);
86381+#endif
86382+
86383 }
86384
86385 /*
86386@@ -1645,12 +1651,6 @@ no_page_table:
86387 return page;
86388 }
86389
86390-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86391-{
86392- return stack_guard_page_start(vma, addr) ||
86393- stack_guard_page_end(vma, addr+PAGE_SIZE);
86394-}
86395-
86396 /**
86397 * __get_user_pages() - pin user pages in memory
86398 * @tsk: task_struct of target task
86399@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86400
86401 i = 0;
86402
86403- do {
86404+ while (nr_pages) {
86405 struct vm_area_struct *vma;
86406
86407- vma = find_extend_vma(mm, start);
86408+ vma = find_vma(mm, start);
86409 if (!vma && in_gate_area(mm, start)) {
86410 unsigned long pg = start & PAGE_MASK;
86411 pgd_t *pgd;
86412@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86413 goto next_page;
86414 }
86415
86416- if (!vma ||
86417+ if (!vma || start < vma->vm_start ||
86418 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86419 !(vm_flags & vma->vm_flags))
86420 return i ? : -EFAULT;
86421@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86422 int ret;
86423 unsigned int fault_flags = 0;
86424
86425- /* For mlock, just skip the stack guard page. */
86426- if (foll_flags & FOLL_MLOCK) {
86427- if (stack_guard_page(vma, start))
86428- goto next_page;
86429- }
86430 if (foll_flags & FOLL_WRITE)
86431 fault_flags |= FAULT_FLAG_WRITE;
86432 if (nonblocking)
86433@@ -1902,7 +1897,7 @@ next_page:
86434 start += page_increm * PAGE_SIZE;
86435 nr_pages -= page_increm;
86436 } while (nr_pages && start < vma->vm_end);
86437- } while (nr_pages);
86438+ }
86439 return i;
86440 }
86441 EXPORT_SYMBOL(__get_user_pages);
86442@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86443 page_add_file_rmap(page);
86444 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86445
86446+#ifdef CONFIG_PAX_SEGMEXEC
86447+ pax_mirror_file_pte(vma, addr, page, ptl);
86448+#endif
86449+
86450 retval = 0;
86451 pte_unmap_unlock(pte, ptl);
86452 return retval;
86453@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86454 if (!page_count(page))
86455 return -EINVAL;
86456 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86457+
86458+#ifdef CONFIG_PAX_SEGMEXEC
86459+ struct vm_area_struct *vma_m;
86460+#endif
86461+
86462 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86463 BUG_ON(vma->vm_flags & VM_PFNMAP);
86464 vma->vm_flags |= VM_MIXEDMAP;
86465+
86466+#ifdef CONFIG_PAX_SEGMEXEC
86467+ vma_m = pax_find_mirror_vma(vma);
86468+ if (vma_m)
86469+ vma_m->vm_flags |= VM_MIXEDMAP;
86470+#endif
86471+
86472 }
86473 return insert_page(vma, addr, page, vma->vm_page_prot);
86474 }
86475@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86476 unsigned long pfn)
86477 {
86478 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86479+ BUG_ON(vma->vm_mirror);
86480
86481 if (addr < vma->vm_start || addr >= vma->vm_end)
86482 return -EFAULT;
86483@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86484
86485 BUG_ON(pud_huge(*pud));
86486
86487- pmd = pmd_alloc(mm, pud, addr);
86488+ pmd = (mm == &init_mm) ?
86489+ pmd_alloc_kernel(mm, pud, addr) :
86490+ pmd_alloc(mm, pud, addr);
86491 if (!pmd)
86492 return -ENOMEM;
86493 do {
86494@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86495 unsigned long next;
86496 int err;
86497
86498- pud = pud_alloc(mm, pgd, addr);
86499+ pud = (mm == &init_mm) ?
86500+ pud_alloc_kernel(mm, pgd, addr) :
86501+ pud_alloc(mm, pgd, addr);
86502 if (!pud)
86503 return -ENOMEM;
86504 do {
86505@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86506 copy_user_highpage(dst, src, va, vma);
86507 }
86508
86509+#ifdef CONFIG_PAX_SEGMEXEC
86510+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86511+{
86512+ struct mm_struct *mm = vma->vm_mm;
86513+ spinlock_t *ptl;
86514+ pte_t *pte, entry;
86515+
86516+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86517+ entry = *pte;
86518+ if (!pte_present(entry)) {
86519+ if (!pte_none(entry)) {
86520+ BUG_ON(pte_file(entry));
86521+ free_swap_and_cache(pte_to_swp_entry(entry));
86522+ pte_clear_not_present_full(mm, address, pte, 0);
86523+ }
86524+ } else {
86525+ struct page *page;
86526+
86527+ flush_cache_page(vma, address, pte_pfn(entry));
86528+ entry = ptep_clear_flush(vma, address, pte);
86529+ BUG_ON(pte_dirty(entry));
86530+ page = vm_normal_page(vma, address, entry);
86531+ if (page) {
86532+ update_hiwater_rss(mm);
86533+ if (PageAnon(page))
86534+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86535+ else
86536+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86537+ page_remove_rmap(page);
86538+ page_cache_release(page);
86539+ }
86540+ }
86541+ pte_unmap_unlock(pte, ptl);
86542+}
86543+
86544+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86545+ *
86546+ * the ptl of the lower mapped page is held on entry and is not released on exit
86547+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86548+ */
86549+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86550+{
86551+ struct mm_struct *mm = vma->vm_mm;
86552+ unsigned long address_m;
86553+ spinlock_t *ptl_m;
86554+ struct vm_area_struct *vma_m;
86555+ pmd_t *pmd_m;
86556+ pte_t *pte_m, entry_m;
86557+
86558+ BUG_ON(!page_m || !PageAnon(page_m));
86559+
86560+ vma_m = pax_find_mirror_vma(vma);
86561+ if (!vma_m)
86562+ return;
86563+
86564+ BUG_ON(!PageLocked(page_m));
86565+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86566+ address_m = address + SEGMEXEC_TASK_SIZE;
86567+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86568+ pte_m = pte_offset_map(pmd_m, address_m);
86569+ ptl_m = pte_lockptr(mm, pmd_m);
86570+ if (ptl != ptl_m) {
86571+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86572+ if (!pte_none(*pte_m))
86573+ goto out;
86574+ }
86575+
86576+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86577+ page_cache_get(page_m);
86578+ page_add_anon_rmap(page_m, vma_m, address_m);
86579+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86580+ set_pte_at(mm, address_m, pte_m, entry_m);
86581+ update_mmu_cache(vma_m, address_m, pte_m);
86582+out:
86583+ if (ptl != ptl_m)
86584+ spin_unlock(ptl_m);
86585+ pte_unmap(pte_m);
86586+ unlock_page(page_m);
86587+}
86588+
86589+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86590+{
86591+ struct mm_struct *mm = vma->vm_mm;
86592+ unsigned long address_m;
86593+ spinlock_t *ptl_m;
86594+ struct vm_area_struct *vma_m;
86595+ pmd_t *pmd_m;
86596+ pte_t *pte_m, entry_m;
86597+
86598+ BUG_ON(!page_m || PageAnon(page_m));
86599+
86600+ vma_m = pax_find_mirror_vma(vma);
86601+ if (!vma_m)
86602+ return;
86603+
86604+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86605+ address_m = address + SEGMEXEC_TASK_SIZE;
86606+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86607+ pte_m = pte_offset_map(pmd_m, address_m);
86608+ ptl_m = pte_lockptr(mm, pmd_m);
86609+ if (ptl != ptl_m) {
86610+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86611+ if (!pte_none(*pte_m))
86612+ goto out;
86613+ }
86614+
86615+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86616+ page_cache_get(page_m);
86617+ page_add_file_rmap(page_m);
86618+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86619+ set_pte_at(mm, address_m, pte_m, entry_m);
86620+ update_mmu_cache(vma_m, address_m, pte_m);
86621+out:
86622+ if (ptl != ptl_m)
86623+ spin_unlock(ptl_m);
86624+ pte_unmap(pte_m);
86625+}
86626+
86627+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86628+{
86629+ struct mm_struct *mm = vma->vm_mm;
86630+ unsigned long address_m;
86631+ spinlock_t *ptl_m;
86632+ struct vm_area_struct *vma_m;
86633+ pmd_t *pmd_m;
86634+ pte_t *pte_m, entry_m;
86635+
86636+ vma_m = pax_find_mirror_vma(vma);
86637+ if (!vma_m)
86638+ return;
86639+
86640+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86641+ address_m = address + SEGMEXEC_TASK_SIZE;
86642+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86643+ pte_m = pte_offset_map(pmd_m, address_m);
86644+ ptl_m = pte_lockptr(mm, pmd_m);
86645+ if (ptl != ptl_m) {
86646+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86647+ if (!pte_none(*pte_m))
86648+ goto out;
86649+ }
86650+
86651+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86652+ set_pte_at(mm, address_m, pte_m, entry_m);
86653+out:
86654+ if (ptl != ptl_m)
86655+ spin_unlock(ptl_m);
86656+ pte_unmap(pte_m);
86657+}
86658+
86659+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86660+{
86661+ struct page *page_m;
86662+ pte_t entry;
86663+
86664+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86665+ goto out;
86666+
86667+ entry = *pte;
86668+ page_m = vm_normal_page(vma, address, entry);
86669+ if (!page_m)
86670+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86671+ else if (PageAnon(page_m)) {
86672+ if (pax_find_mirror_vma(vma)) {
86673+ pte_unmap_unlock(pte, ptl);
86674+ lock_page(page_m);
86675+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86676+ if (pte_same(entry, *pte))
86677+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86678+ else
86679+ unlock_page(page_m);
86680+ }
86681+ } else
86682+ pax_mirror_file_pte(vma, address, page_m, ptl);
86683+
86684+out:
86685+ pte_unmap_unlock(pte, ptl);
86686+}
86687+#endif
86688+
86689 /*
86690 * This routine handles present pages, when users try to write
86691 * to a shared page. It is done by copying the page to a new address
86692@@ -2809,6 +3005,12 @@ gotten:
86693 */
86694 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86695 if (likely(pte_same(*page_table, orig_pte))) {
86696+
86697+#ifdef CONFIG_PAX_SEGMEXEC
86698+ if (pax_find_mirror_vma(vma))
86699+ BUG_ON(!trylock_page(new_page));
86700+#endif
86701+
86702 if (old_page) {
86703 if (!PageAnon(old_page)) {
86704 dec_mm_counter_fast(mm, MM_FILEPAGES);
86705@@ -2860,6 +3062,10 @@ gotten:
86706 page_remove_rmap(old_page);
86707 }
86708
86709+#ifdef CONFIG_PAX_SEGMEXEC
86710+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86711+#endif
86712+
86713 /* Free the old page.. */
86714 new_page = old_page;
86715 ret |= VM_FAULT_WRITE;
86716@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86717 swap_free(entry);
86718 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86719 try_to_free_swap(page);
86720+
86721+#ifdef CONFIG_PAX_SEGMEXEC
86722+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86723+#endif
86724+
86725 unlock_page(page);
86726 if (page != swapcache) {
86727 /*
86728@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86729
86730 /* No need to invalidate - it was non-present before */
86731 update_mmu_cache(vma, address, page_table);
86732+
86733+#ifdef CONFIG_PAX_SEGMEXEC
86734+ pax_mirror_anon_pte(vma, address, page, ptl);
86735+#endif
86736+
86737 unlock:
86738 pte_unmap_unlock(page_table, ptl);
86739 out:
86740@@ -3179,40 +3395,6 @@ out_release:
86741 }
86742
86743 /*
86744- * This is like a special single-page "expand_{down|up}wards()",
86745- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86746- * doesn't hit another vma.
86747- */
86748-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86749-{
86750- address &= PAGE_MASK;
86751- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86752- struct vm_area_struct *prev = vma->vm_prev;
86753-
86754- /*
86755- * Is there a mapping abutting this one below?
86756- *
86757- * That's only ok if it's the same stack mapping
86758- * that has gotten split..
86759- */
86760- if (prev && prev->vm_end == address)
86761- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86762-
86763- expand_downwards(vma, address - PAGE_SIZE);
86764- }
86765- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86766- struct vm_area_struct *next = vma->vm_next;
86767-
86768- /* As VM_GROWSDOWN but s/below/above/ */
86769- if (next && next->vm_start == address + PAGE_SIZE)
86770- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86771-
86772- expand_upwards(vma, address + PAGE_SIZE);
86773- }
86774- return 0;
86775-}
86776-
86777-/*
86778 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86779 * but allow concurrent faults), and pte mapped but not yet locked.
86780 * We return with mmap_sem still held, but pte unmapped and unlocked.
86781@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86782 unsigned long address, pte_t *page_table, pmd_t *pmd,
86783 unsigned int flags)
86784 {
86785- struct page *page;
86786+ struct page *page = NULL;
86787 spinlock_t *ptl;
86788 pte_t entry;
86789
86790- pte_unmap(page_table);
86791-
86792- /* Check if we need to add a guard page to the stack */
86793- if (check_stack_guard_page(vma, address) < 0)
86794- return VM_FAULT_SIGBUS;
86795-
86796- /* Use the zero-page for reads */
86797 if (!(flags & FAULT_FLAG_WRITE)) {
86798 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86799 vma->vm_page_prot));
86800- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86801+ ptl = pte_lockptr(mm, pmd);
86802+ spin_lock(ptl);
86803 if (!pte_none(*page_table))
86804 goto unlock;
86805 goto setpte;
86806 }
86807
86808 /* Allocate our own private page. */
86809+ pte_unmap(page_table);
86810+
86811 if (unlikely(anon_vma_prepare(vma)))
86812 goto oom;
86813 page = alloc_zeroed_user_highpage_movable(vma, address);
86814@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86815 if (!pte_none(*page_table))
86816 goto release;
86817
86818+#ifdef CONFIG_PAX_SEGMEXEC
86819+ if (pax_find_mirror_vma(vma))
86820+ BUG_ON(!trylock_page(page));
86821+#endif
86822+
86823 inc_mm_counter_fast(mm, MM_ANONPAGES);
86824 page_add_new_anon_rmap(page, vma, address);
86825 setpte:
86826@@ -3272,6 +3455,12 @@ setpte:
86827
86828 /* No need to invalidate - it was non-present before */
86829 update_mmu_cache(vma, address, page_table);
86830+
86831+#ifdef CONFIG_PAX_SEGMEXEC
86832+ if (page)
86833+ pax_mirror_anon_pte(vma, address, page, ptl);
86834+#endif
86835+
86836 unlock:
86837 pte_unmap_unlock(page_table, ptl);
86838 return 0;
86839@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86840 */
86841 /* Only go through if we didn't race with anybody else... */
86842 if (likely(pte_same(*page_table, orig_pte))) {
86843+
86844+#ifdef CONFIG_PAX_SEGMEXEC
86845+ if (anon && pax_find_mirror_vma(vma))
86846+ BUG_ON(!trylock_page(page));
86847+#endif
86848+
86849 flush_icache_page(vma, page);
86850 entry = mk_pte(page, vma->vm_page_prot);
86851 if (flags & FAULT_FLAG_WRITE)
86852@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86853
86854 /* no need to invalidate: a not-present page won't be cached */
86855 update_mmu_cache(vma, address, page_table);
86856+
86857+#ifdef CONFIG_PAX_SEGMEXEC
86858+ if (anon)
86859+ pax_mirror_anon_pte(vma, address, page, ptl);
86860+ else
86861+ pax_mirror_file_pte(vma, address, page, ptl);
86862+#endif
86863+
86864 } else {
86865 if (cow_page)
86866 mem_cgroup_uncharge_page(cow_page);
86867@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86868 if (flags & FAULT_FLAG_WRITE)
86869 flush_tlb_fix_spurious_fault(vma, address);
86870 }
86871+
86872+#ifdef CONFIG_PAX_SEGMEXEC
86873+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86874+ return 0;
86875+#endif
86876+
86877 unlock:
86878 pte_unmap_unlock(pte, ptl);
86879 return 0;
86880@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86881 pmd_t *pmd;
86882 pte_t *pte;
86883
86884+#ifdef CONFIG_PAX_SEGMEXEC
86885+ struct vm_area_struct *vma_m;
86886+#endif
86887+
86888 __set_current_state(TASK_RUNNING);
86889
86890 count_vm_event(PGFAULT);
86891@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86892 if (unlikely(is_vm_hugetlb_page(vma)))
86893 return hugetlb_fault(mm, vma, address, flags);
86894
86895+#ifdef CONFIG_PAX_SEGMEXEC
86896+ vma_m = pax_find_mirror_vma(vma);
86897+ if (vma_m) {
86898+ unsigned long address_m;
86899+ pgd_t *pgd_m;
86900+ pud_t *pud_m;
86901+ pmd_t *pmd_m;
86902+
86903+ if (vma->vm_start > vma_m->vm_start) {
86904+ address_m = address;
86905+ address -= SEGMEXEC_TASK_SIZE;
86906+ vma = vma_m;
86907+ } else
86908+ address_m = address + SEGMEXEC_TASK_SIZE;
86909+
86910+ pgd_m = pgd_offset(mm, address_m);
86911+ pud_m = pud_alloc(mm, pgd_m, address_m);
86912+ if (!pud_m)
86913+ return VM_FAULT_OOM;
86914+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86915+ if (!pmd_m)
86916+ return VM_FAULT_OOM;
86917+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86918+ return VM_FAULT_OOM;
86919+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86920+ }
86921+#endif
86922+
86923 retry:
86924 pgd = pgd_offset(mm, address);
86925 pud = pud_alloc(mm, pgd, address);
86926@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86927 spin_unlock(&mm->page_table_lock);
86928 return 0;
86929 }
86930+
86931+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86932+{
86933+ pud_t *new = pud_alloc_one(mm, address);
86934+ if (!new)
86935+ return -ENOMEM;
86936+
86937+ smp_wmb(); /* See comment in __pte_alloc */
86938+
86939+ spin_lock(&mm->page_table_lock);
86940+ if (pgd_present(*pgd)) /* Another has populated it */
86941+ pud_free(mm, new);
86942+ else
86943+ pgd_populate_kernel(mm, pgd, new);
86944+ spin_unlock(&mm->page_table_lock);
86945+ return 0;
86946+}
86947 #endif /* __PAGETABLE_PUD_FOLDED */
86948
86949 #ifndef __PAGETABLE_PMD_FOLDED
86950@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86951 spin_unlock(&mm->page_table_lock);
86952 return 0;
86953 }
86954+
86955+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86956+{
86957+ pmd_t *new = pmd_alloc_one(mm, address);
86958+ if (!new)
86959+ return -ENOMEM;
86960+
86961+ smp_wmb(); /* See comment in __pte_alloc */
86962+
86963+ spin_lock(&mm->page_table_lock);
86964+#ifndef __ARCH_HAS_4LEVEL_HACK
86965+ if (pud_present(*pud)) /* Another has populated it */
86966+ pmd_free(mm, new);
86967+ else
86968+ pud_populate_kernel(mm, pud, new);
86969+#else
86970+ if (pgd_present(*pud)) /* Another has populated it */
86971+ pmd_free(mm, new);
86972+ else
86973+ pgd_populate_kernel(mm, pud, new);
86974+#endif /* __ARCH_HAS_4LEVEL_HACK */
86975+ spin_unlock(&mm->page_table_lock);
86976+ return 0;
86977+}
86978 #endif /* __PAGETABLE_PMD_FOLDED */
86979
86980 #if !defined(__HAVE_ARCH_GATE_AREA)
86981@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
86982 gate_vma.vm_start = FIXADDR_USER_START;
86983 gate_vma.vm_end = FIXADDR_USER_END;
86984 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
86985- gate_vma.vm_page_prot = __P101;
86986+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
86987
86988 return 0;
86989 }
86990@@ -4059,8 +4341,8 @@ out:
86991 return ret;
86992 }
86993
86994-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86995- void *buf, int len, int write)
86996+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86997+ void *buf, size_t len, int write)
86998 {
86999 resource_size_t phys_addr;
87000 unsigned long prot = 0;
87001@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87002 * Access another process' address space as given in mm. If non-NULL, use the
87003 * given task for page fault accounting.
87004 */
87005-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87006- unsigned long addr, void *buf, int len, int write)
87007+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87008+ unsigned long addr, void *buf, size_t len, int write)
87009 {
87010 struct vm_area_struct *vma;
87011 void *old_buf = buf;
87012@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87013 down_read(&mm->mmap_sem);
87014 /* ignore errors, just check how much was successfully transferred */
87015 while (len) {
87016- int bytes, ret, offset;
87017+ ssize_t bytes, ret, offset;
87018 void *maddr;
87019 struct page *page = NULL;
87020
87021@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87022 *
87023 * The caller must hold a reference on @mm.
87024 */
87025-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87026- void *buf, int len, int write)
87027+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87028+ void *buf, size_t len, int write)
87029 {
87030 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87031 }
87032@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87033 * Source/target buffer must be kernel space,
87034 * Do not walk the page table directly, use get_user_pages
87035 */
87036-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87037- void *buf, int len, int write)
87038+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87039+ void *buf, size_t len, int write)
87040 {
87041 struct mm_struct *mm;
87042- int ret;
87043+ ssize_t ret;
87044
87045 mm = get_task_mm(tsk);
87046 if (!mm)
87047diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87048index 4baf12e..5497066 100644
87049--- a/mm/mempolicy.c
87050+++ b/mm/mempolicy.c
87051@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87052 unsigned long vmstart;
87053 unsigned long vmend;
87054
87055+#ifdef CONFIG_PAX_SEGMEXEC
87056+ struct vm_area_struct *vma_m;
87057+#endif
87058+
87059 vma = find_vma(mm, start);
87060 if (!vma || vma->vm_start > start)
87061 return -EFAULT;
87062@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87063 err = vma_replace_policy(vma, new_pol);
87064 if (err)
87065 goto out;
87066+
87067+#ifdef CONFIG_PAX_SEGMEXEC
87068+ vma_m = pax_find_mirror_vma(vma);
87069+ if (vma_m) {
87070+ err = vma_replace_policy(vma_m, new_pol);
87071+ if (err)
87072+ goto out;
87073+ }
87074+#endif
87075+
87076 }
87077
87078 out:
87079@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87080
87081 if (end < start)
87082 return -EINVAL;
87083+
87084+#ifdef CONFIG_PAX_SEGMEXEC
87085+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87086+ if (end > SEGMEXEC_TASK_SIZE)
87087+ return -EINVAL;
87088+ } else
87089+#endif
87090+
87091+ if (end > TASK_SIZE)
87092+ return -EINVAL;
87093+
87094 if (end == start)
87095 return 0;
87096
87097@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87098 */
87099 tcred = __task_cred(task);
87100 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87101- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87102- !capable(CAP_SYS_NICE)) {
87103+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87104 rcu_read_unlock();
87105 err = -EPERM;
87106 goto out_put;
87107@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87108 goto out;
87109 }
87110
87111+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87112+ if (mm != current->mm &&
87113+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87114+ mmput(mm);
87115+ err = -EPERM;
87116+ goto out;
87117+ }
87118+#endif
87119+
87120 err = do_migrate_pages(mm, old, new,
87121 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87122
87123diff --git a/mm/migrate.c b/mm/migrate.c
87124index 25ca7ca..abe1836 100644
87125--- a/mm/migrate.c
87126+++ b/mm/migrate.c
87127@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87128 */
87129 tcred = __task_cred(task);
87130 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87131- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87132- !capable(CAP_SYS_NICE)) {
87133+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87134 rcu_read_unlock();
87135 err = -EPERM;
87136 goto out;
87137diff --git a/mm/mlock.c b/mm/mlock.c
87138index 79b7cf7..37472bf 100644
87139--- a/mm/mlock.c
87140+++ b/mm/mlock.c
87141@@ -13,6 +13,7 @@
87142 #include <linux/pagemap.h>
87143 #include <linux/mempolicy.h>
87144 #include <linux/syscalls.h>
87145+#include <linux/security.h>
87146 #include <linux/sched.h>
87147 #include <linux/export.h>
87148 #include <linux/rmap.h>
87149@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87150 {
87151 unsigned long nstart, end, tmp;
87152 struct vm_area_struct * vma, * prev;
87153- int error;
87154+ int error = 0;
87155
87156 VM_BUG_ON(start & ~PAGE_MASK);
87157 VM_BUG_ON(len != PAGE_ALIGN(len));
87158@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87159 return -EINVAL;
87160 if (end == start)
87161 return 0;
87162+ if (end > TASK_SIZE)
87163+ return -EINVAL;
87164+
87165 vma = find_vma(current->mm, start);
87166 if (!vma || vma->vm_start > start)
87167 return -ENOMEM;
87168@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87169 for (nstart = start ; ; ) {
87170 vm_flags_t newflags;
87171
87172+#ifdef CONFIG_PAX_SEGMEXEC
87173+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87174+ break;
87175+#endif
87176+
87177 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87178
87179 newflags = vma->vm_flags & ~VM_LOCKED;
87180@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87181 lock_limit >>= PAGE_SHIFT;
87182
87183 /* check against resource limits */
87184+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87185 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87186 error = do_mlock(start, len, 1);
87187 up_write(&current->mm->mmap_sem);
87188@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
87189 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87190 vm_flags_t newflags;
87191
87192+#ifdef CONFIG_PAX_SEGMEXEC
87193+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87194+ break;
87195+#endif
87196+
87197 newflags = vma->vm_flags & ~VM_LOCKED;
87198 if (flags & MCL_CURRENT)
87199 newflags |= VM_LOCKED;
87200
87201 /* Ignore errors */
87202 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
87203+ cond_resched();
87204 }
87205 out:
87206 return 0;
87207@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87208 lock_limit >>= PAGE_SHIFT;
87209
87210 ret = -ENOMEM;
87211+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87212 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87213 capable(CAP_IPC_LOCK))
87214 ret = do_mlockall(flags);
87215diff --git a/mm/mmap.c b/mm/mmap.c
87216index f9c97d1..3468d3b 100644
87217--- a/mm/mmap.c
87218+++ b/mm/mmap.c
87219@@ -36,6 +36,7 @@
87220 #include <linux/sched/sysctl.h>
87221 #include <linux/notifier.h>
87222 #include <linux/memory.h>
87223+#include <linux/random.h>
87224
87225 #include <asm/uaccess.h>
87226 #include <asm/cacheflush.h>
87227@@ -52,6 +53,16 @@
87228 #define arch_rebalance_pgtables(addr, len) (addr)
87229 #endif
87230
87231+static inline void verify_mm_writelocked(struct mm_struct *mm)
87232+{
87233+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87234+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87235+ up_read(&mm->mmap_sem);
87236+ BUG();
87237+ }
87238+#endif
87239+}
87240+
87241 static void unmap_region(struct mm_struct *mm,
87242 struct vm_area_struct *vma, struct vm_area_struct *prev,
87243 unsigned long start, unsigned long end);
87244@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87245 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87246 *
87247 */
87248-pgprot_t protection_map[16] = {
87249+pgprot_t protection_map[16] __read_only = {
87250 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87251 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87252 };
87253
87254-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87255+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87256 {
87257- return __pgprot(pgprot_val(protection_map[vm_flags &
87258+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87259 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87260 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87261+
87262+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87263+ if (!(__supported_pte_mask & _PAGE_NX) &&
87264+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87265+ (vm_flags & (VM_READ | VM_WRITE)))
87266+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87267+#endif
87268+
87269+ return prot;
87270 }
87271 EXPORT_SYMBOL(vm_get_page_prot);
87272
87273@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87274 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87275 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87276 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87277+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87278 /*
87279 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87280 * other variables. It can be updated by several CPUs frequently.
87281@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87282 struct vm_area_struct *next = vma->vm_next;
87283
87284 might_sleep();
87285+ BUG_ON(vma->vm_mirror);
87286 if (vma->vm_ops && vma->vm_ops->close)
87287 vma->vm_ops->close(vma);
87288 if (vma->vm_file)
87289@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87290 * not page aligned -Ram Gupta
87291 */
87292 rlim = rlimit(RLIMIT_DATA);
87293+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87294 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87295 (mm->end_data - mm->start_data) > rlim)
87296 goto out;
87297@@ -933,6 +956,12 @@ static int
87298 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87299 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87300 {
87301+
87302+#ifdef CONFIG_PAX_SEGMEXEC
87303+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87304+ return 0;
87305+#endif
87306+
87307 if (is_mergeable_vma(vma, file, vm_flags) &&
87308 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87309 if (vma->vm_pgoff == vm_pgoff)
87310@@ -952,6 +981,12 @@ static int
87311 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87312 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87313 {
87314+
87315+#ifdef CONFIG_PAX_SEGMEXEC
87316+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87317+ return 0;
87318+#endif
87319+
87320 if (is_mergeable_vma(vma, file, vm_flags) &&
87321 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87322 pgoff_t vm_pglen;
87323@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87324 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87325 struct vm_area_struct *prev, unsigned long addr,
87326 unsigned long end, unsigned long vm_flags,
87327- struct anon_vma *anon_vma, struct file *file,
87328+ struct anon_vma *anon_vma, struct file *file,
87329 pgoff_t pgoff, struct mempolicy *policy)
87330 {
87331 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87332 struct vm_area_struct *area, *next;
87333 int err;
87334
87335+#ifdef CONFIG_PAX_SEGMEXEC
87336+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87337+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87338+
87339+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87340+#endif
87341+
87342 /*
87343 * We later require that vma->vm_flags == vm_flags,
87344 * so this tests vma->vm_flags & VM_SPECIAL, too.
87345@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87346 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87347 next = next->vm_next;
87348
87349+#ifdef CONFIG_PAX_SEGMEXEC
87350+ if (prev)
87351+ prev_m = pax_find_mirror_vma(prev);
87352+ if (area)
87353+ area_m = pax_find_mirror_vma(area);
87354+ if (next)
87355+ next_m = pax_find_mirror_vma(next);
87356+#endif
87357+
87358 /*
87359 * Can it merge with the predecessor?
87360 */
87361@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87362 /* cases 1, 6 */
87363 err = vma_adjust(prev, prev->vm_start,
87364 next->vm_end, prev->vm_pgoff, NULL);
87365- } else /* cases 2, 5, 7 */
87366+
87367+#ifdef CONFIG_PAX_SEGMEXEC
87368+ if (!err && prev_m)
87369+ err = vma_adjust(prev_m, prev_m->vm_start,
87370+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87371+#endif
87372+
87373+ } else { /* cases 2, 5, 7 */
87374 err = vma_adjust(prev, prev->vm_start,
87375 end, prev->vm_pgoff, NULL);
87376+
87377+#ifdef CONFIG_PAX_SEGMEXEC
87378+ if (!err && prev_m)
87379+ err = vma_adjust(prev_m, prev_m->vm_start,
87380+ end_m, prev_m->vm_pgoff, NULL);
87381+#endif
87382+
87383+ }
87384 if (err)
87385 return NULL;
87386 khugepaged_enter_vma_merge(prev);
87387@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87388 mpol_equal(policy, vma_policy(next)) &&
87389 can_vma_merge_before(next, vm_flags,
87390 anon_vma, file, pgoff+pglen)) {
87391- if (prev && addr < prev->vm_end) /* case 4 */
87392+ if (prev && addr < prev->vm_end) { /* case 4 */
87393 err = vma_adjust(prev, prev->vm_start,
87394 addr, prev->vm_pgoff, NULL);
87395- else /* cases 3, 8 */
87396+
87397+#ifdef CONFIG_PAX_SEGMEXEC
87398+ if (!err && prev_m)
87399+ err = vma_adjust(prev_m, prev_m->vm_start,
87400+ addr_m, prev_m->vm_pgoff, NULL);
87401+#endif
87402+
87403+ } else { /* cases 3, 8 */
87404 err = vma_adjust(area, addr, next->vm_end,
87405 next->vm_pgoff - pglen, NULL);
87406+
87407+#ifdef CONFIG_PAX_SEGMEXEC
87408+ if (!err && area_m)
87409+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87410+ next_m->vm_pgoff - pglen, NULL);
87411+#endif
87412+
87413+ }
87414 if (err)
87415 return NULL;
87416 khugepaged_enter_vma_merge(area);
87417@@ -1165,8 +1246,10 @@ none:
87418 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87419 struct file *file, long pages)
87420 {
87421- const unsigned long stack_flags
87422- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87423+
87424+#ifdef CONFIG_PAX_RANDMMAP
87425+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87426+#endif
87427
87428 mm->total_vm += pages;
87429
87430@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87431 mm->shared_vm += pages;
87432 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87433 mm->exec_vm += pages;
87434- } else if (flags & stack_flags)
87435+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87436 mm->stack_vm += pages;
87437 }
87438 #endif /* CONFIG_PROC_FS */
87439@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87440 * (the exception is when the underlying filesystem is noexec
87441 * mounted, in which case we dont add PROT_EXEC.)
87442 */
87443- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87444+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87445 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87446 prot |= PROT_EXEC;
87447
87448@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87449 /* Obtain the address to map to. we verify (or select) it and ensure
87450 * that it represents a valid section of the address space.
87451 */
87452- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87453+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87454 if (addr & ~PAGE_MASK)
87455 return addr;
87456
87457@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87458 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87459 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87460
87461+#ifdef CONFIG_PAX_MPROTECT
87462+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87463+
87464+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87465+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87466+ mm->binfmt->handle_mmap)
87467+ mm->binfmt->handle_mmap(file);
87468+#endif
87469+
87470+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87471+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87472+ gr_log_rwxmmap(file);
87473+
87474+#ifdef CONFIG_PAX_EMUPLT
87475+ vm_flags &= ~VM_EXEC;
87476+#else
87477+ return -EPERM;
87478+#endif
87479+
87480+ }
87481+
87482+ if (!(vm_flags & VM_EXEC))
87483+ vm_flags &= ~VM_MAYEXEC;
87484+#else
87485+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87486+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87487+#endif
87488+ else
87489+ vm_flags &= ~VM_MAYWRITE;
87490+ }
87491+#endif
87492+
87493+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87494+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87495+ vm_flags &= ~VM_PAGEEXEC;
87496+#endif
87497+
87498 if (flags & MAP_LOCKED)
87499 if (!can_do_mlock())
87500 return -EPERM;
87501@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87502 locked += mm->locked_vm;
87503 lock_limit = rlimit(RLIMIT_MEMLOCK);
87504 lock_limit >>= PAGE_SHIFT;
87505+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87506 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87507 return -EAGAIN;
87508 }
87509@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87510 vm_flags |= VM_NORESERVE;
87511 }
87512
87513+ if (!gr_acl_handle_mmap(file, prot))
87514+ return -EACCES;
87515+
87516 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87517 if (!IS_ERR_VALUE(addr) &&
87518 ((vm_flags & VM_LOCKED) ||
87519@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87520 vm_flags_t vm_flags = vma->vm_flags;
87521
87522 /* If it was private or non-writable, the write bit is already clear */
87523- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87524+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87525 return 0;
87526
87527 /* The backer wishes to know when pages are first written to? */
87528@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87529 unsigned long charged = 0;
87530 struct inode *inode = file ? file_inode(file) : NULL;
87531
87532+#ifdef CONFIG_PAX_SEGMEXEC
87533+ struct vm_area_struct *vma_m = NULL;
87534+#endif
87535+
87536+ /*
87537+ * mm->mmap_sem is required to protect against another thread
87538+ * changing the mappings in case we sleep.
87539+ */
87540+ verify_mm_writelocked(mm);
87541+
87542 /* Check against address space limit. */
87543+
87544+#ifdef CONFIG_PAX_RANDMMAP
87545+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87546+#endif
87547+
87548 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87549 unsigned long nr_pages;
87550
87551@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87552
87553 /* Clear old maps */
87554 error = -ENOMEM;
87555-munmap_back:
87556 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87557 if (do_munmap(mm, addr, len))
87558 return -ENOMEM;
87559- goto munmap_back;
87560+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87561 }
87562
87563 /*
87564@@ -1536,6 +1674,16 @@ munmap_back:
87565 goto unacct_error;
87566 }
87567
87568+#ifdef CONFIG_PAX_SEGMEXEC
87569+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87570+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87571+ if (!vma_m) {
87572+ error = -ENOMEM;
87573+ goto free_vma;
87574+ }
87575+ }
87576+#endif
87577+
87578 vma->vm_mm = mm;
87579 vma->vm_start = addr;
87580 vma->vm_end = addr + len;
87581@@ -1560,6 +1708,13 @@ munmap_back:
87582 if (error)
87583 goto unmap_and_free_vma;
87584
87585+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87586+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87587+ vma->vm_flags |= VM_PAGEEXEC;
87588+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87589+ }
87590+#endif
87591+
87592 /* Can addr have changed??
87593 *
87594 * Answer: Yes, several device drivers can do it in their
87595@@ -1598,6 +1753,11 @@ munmap_back:
87596 vma_link(mm, vma, prev, rb_link, rb_parent);
87597 file = vma->vm_file;
87598
87599+#ifdef CONFIG_PAX_SEGMEXEC
87600+ if (vma_m)
87601+ BUG_ON(pax_mirror_vma(vma_m, vma));
87602+#endif
87603+
87604 /* Once vma denies write, undo our temporary denial count */
87605 if (correct_wcount)
87606 atomic_inc(&inode->i_writecount);
87607@@ -1605,6 +1765,7 @@ out:
87608 perf_event_mmap(vma);
87609
87610 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87611+ track_exec_limit(mm, addr, addr + len, vm_flags);
87612 if (vm_flags & VM_LOCKED) {
87613 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87614 vma == get_gate_vma(current->mm)))
87615@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87616 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87617 charged = 0;
87618 free_vma:
87619+
87620+#ifdef CONFIG_PAX_SEGMEXEC
87621+ if (vma_m)
87622+ kmem_cache_free(vm_area_cachep, vma_m);
87623+#endif
87624+
87625 kmem_cache_free(vm_area_cachep, vma);
87626 unacct_error:
87627 if (charged)
87628@@ -1635,7 +1802,63 @@ unacct_error:
87629 return error;
87630 }
87631
87632-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87633+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87634+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87635+{
87636+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87637+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87638+
87639+ return 0;
87640+}
87641+#endif
87642+
87643+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87644+{
87645+ if (!vma) {
87646+#ifdef CONFIG_STACK_GROWSUP
87647+ if (addr > sysctl_heap_stack_gap)
87648+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87649+ else
87650+ vma = find_vma(current->mm, 0);
87651+ if (vma && (vma->vm_flags & VM_GROWSUP))
87652+ return false;
87653+#endif
87654+ return true;
87655+ }
87656+
87657+ if (addr + len > vma->vm_start)
87658+ return false;
87659+
87660+ if (vma->vm_flags & VM_GROWSDOWN)
87661+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87662+#ifdef CONFIG_STACK_GROWSUP
87663+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87664+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87665+#endif
87666+ else if (offset)
87667+ return offset <= vma->vm_start - addr - len;
87668+
87669+ return true;
87670+}
87671+
87672+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87673+{
87674+ if (vma->vm_start < len)
87675+ return -ENOMEM;
87676+
87677+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87678+ if (offset <= vma->vm_start - len)
87679+ return vma->vm_start - len - offset;
87680+ else
87681+ return -ENOMEM;
87682+ }
87683+
87684+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87685+ return vma->vm_start - len - sysctl_heap_stack_gap;
87686+ return -ENOMEM;
87687+}
87688+
87689+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87690 {
87691 /*
87692 * We implement the search by looking for an rbtree node that
87693@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87694 }
87695 }
87696
87697- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87698+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87699 check_current:
87700 /* Check if current node has a suitable gap */
87701 if (gap_start > high_limit)
87702 return -ENOMEM;
87703+
87704+ if (gap_end - gap_start > info->threadstack_offset)
87705+ gap_start += info->threadstack_offset;
87706+ else
87707+ gap_start = gap_end;
87708+
87709+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87710+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87711+ gap_start += sysctl_heap_stack_gap;
87712+ else
87713+ gap_start = gap_end;
87714+ }
87715+ if (vma->vm_flags & VM_GROWSDOWN) {
87716+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87717+ gap_end -= sysctl_heap_stack_gap;
87718+ else
87719+ gap_end = gap_start;
87720+ }
87721 if (gap_end >= low_limit && gap_end - gap_start >= length)
87722 goto found;
87723
87724@@ -1737,7 +1978,7 @@ found:
87725 return gap_start;
87726 }
87727
87728-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87729+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87730 {
87731 struct mm_struct *mm = current->mm;
87732 struct vm_area_struct *vma;
87733@@ -1791,6 +2032,24 @@ check_current:
87734 gap_end = vma->vm_start;
87735 if (gap_end < low_limit)
87736 return -ENOMEM;
87737+
87738+ if (gap_end - gap_start > info->threadstack_offset)
87739+ gap_end -= info->threadstack_offset;
87740+ else
87741+ gap_end = gap_start;
87742+
87743+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87744+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87745+ gap_start += sysctl_heap_stack_gap;
87746+ else
87747+ gap_start = gap_end;
87748+ }
87749+ if (vma->vm_flags & VM_GROWSDOWN) {
87750+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87751+ gap_end -= sysctl_heap_stack_gap;
87752+ else
87753+ gap_end = gap_start;
87754+ }
87755 if (gap_start <= high_limit && gap_end - gap_start >= length)
87756 goto found;
87757
87758@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87759 struct mm_struct *mm = current->mm;
87760 struct vm_area_struct *vma;
87761 struct vm_unmapped_area_info info;
87762+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87763
87764 if (len > TASK_SIZE)
87765 return -ENOMEM;
87766@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87767 if (flags & MAP_FIXED)
87768 return addr;
87769
87770+#ifdef CONFIG_PAX_RANDMMAP
87771+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87772+#endif
87773+
87774 if (addr) {
87775 addr = PAGE_ALIGN(addr);
87776 vma = find_vma(mm, addr);
87777- if (TASK_SIZE - len >= addr &&
87778- (!vma || addr + len <= vma->vm_start))
87779+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87780 return addr;
87781 }
87782
87783 info.flags = 0;
87784 info.length = len;
87785 info.low_limit = TASK_UNMAPPED_BASE;
87786+
87787+#ifdef CONFIG_PAX_RANDMMAP
87788+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87789+ info.low_limit += mm->delta_mmap;
87790+#endif
87791+
87792 info.high_limit = TASK_SIZE;
87793 info.align_mask = 0;
87794+ info.threadstack_offset = offset;
87795 return vm_unmapped_area(&info);
87796 }
87797 #endif
87798@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87799 struct mm_struct *mm = current->mm;
87800 unsigned long addr = addr0;
87801 struct vm_unmapped_area_info info;
87802+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87803
87804 /* requested length too big for entire address space */
87805 if (len > TASK_SIZE)
87806@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87807 if (flags & MAP_FIXED)
87808 return addr;
87809
87810+#ifdef CONFIG_PAX_RANDMMAP
87811+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87812+#endif
87813+
87814 /* requesting a specific address */
87815 if (addr) {
87816 addr = PAGE_ALIGN(addr);
87817 vma = find_vma(mm, addr);
87818- if (TASK_SIZE - len >= addr &&
87819- (!vma || addr + len <= vma->vm_start))
87820+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87821 return addr;
87822 }
87823
87824@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87825 info.low_limit = PAGE_SIZE;
87826 info.high_limit = mm->mmap_base;
87827 info.align_mask = 0;
87828+ info.threadstack_offset = offset;
87829 addr = vm_unmapped_area(&info);
87830
87831 /*
87832@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87833 VM_BUG_ON(addr != -ENOMEM);
87834 info.flags = 0;
87835 info.low_limit = TASK_UNMAPPED_BASE;
87836+
87837+#ifdef CONFIG_PAX_RANDMMAP
87838+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87839+ info.low_limit += mm->delta_mmap;
87840+#endif
87841+
87842 info.high_limit = TASK_SIZE;
87843 addr = vm_unmapped_area(&info);
87844 }
87845@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87846 return vma;
87847 }
87848
87849+#ifdef CONFIG_PAX_SEGMEXEC
87850+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87851+{
87852+ struct vm_area_struct *vma_m;
87853+
87854+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87855+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87856+ BUG_ON(vma->vm_mirror);
87857+ return NULL;
87858+ }
87859+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87860+ vma_m = vma->vm_mirror;
87861+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87862+ BUG_ON(vma->vm_file != vma_m->vm_file);
87863+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87864+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87865+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87866+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87867+ return vma_m;
87868+}
87869+#endif
87870+
87871 /*
87872 * Verify that the stack growth is acceptable and
87873 * update accounting. This is shared with both the
87874@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87875 return -ENOMEM;
87876
87877 /* Stack limit test */
87878+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87879 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87880 return -ENOMEM;
87881
87882@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87883 locked = mm->locked_vm + grow;
87884 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87885 limit >>= PAGE_SHIFT;
87886+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87887 if (locked > limit && !capable(CAP_IPC_LOCK))
87888 return -ENOMEM;
87889 }
87890@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87891 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87892 * vma is the last one with address > vma->vm_end. Have to extend vma.
87893 */
87894+#ifndef CONFIG_IA64
87895+static
87896+#endif
87897 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87898 {
87899 int error;
87900+ bool locknext;
87901
87902 if (!(vma->vm_flags & VM_GROWSUP))
87903 return -EFAULT;
87904
87905+ /* Also guard against wrapping around to address 0. */
87906+ if (address < PAGE_ALIGN(address+1))
87907+ address = PAGE_ALIGN(address+1);
87908+ else
87909+ return -ENOMEM;
87910+
87911 /*
87912 * We must make sure the anon_vma is allocated
87913 * so that the anon_vma locking is not a noop.
87914 */
87915 if (unlikely(anon_vma_prepare(vma)))
87916 return -ENOMEM;
87917+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87918+ if (locknext && anon_vma_prepare(vma->vm_next))
87919+ return -ENOMEM;
87920 vma_lock_anon_vma(vma);
87921+ if (locknext)
87922+ vma_lock_anon_vma(vma->vm_next);
87923
87924 /*
87925 * vma->vm_start/vm_end cannot change under us because the caller
87926 * is required to hold the mmap_sem in read mode. We need the
87927- * anon_vma lock to serialize against concurrent expand_stacks.
87928- * Also guard against wrapping around to address 0.
87929+ * anon_vma locks to serialize against concurrent expand_stacks
87930+ * and expand_upwards.
87931 */
87932- if (address < PAGE_ALIGN(address+4))
87933- address = PAGE_ALIGN(address+4);
87934- else {
87935- vma_unlock_anon_vma(vma);
87936- return -ENOMEM;
87937- }
87938 error = 0;
87939
87940 /* Somebody else might have raced and expanded it already */
87941- if (address > vma->vm_end) {
87942+ 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)
87943+ error = -ENOMEM;
87944+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87945 unsigned long size, grow;
87946
87947 size = address - vma->vm_start;
87948@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87949 }
87950 }
87951 }
87952+ if (locknext)
87953+ vma_unlock_anon_vma(vma->vm_next);
87954 vma_unlock_anon_vma(vma);
87955 khugepaged_enter_vma_merge(vma);
87956 validate_mm(vma->vm_mm);
87957@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87958 unsigned long address)
87959 {
87960 int error;
87961+ bool lockprev = false;
87962+ struct vm_area_struct *prev;
87963
87964 /*
87965 * We must make sure the anon_vma is allocated
87966@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87967 if (error)
87968 return error;
87969
87970+ prev = vma->vm_prev;
87971+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87972+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87973+#endif
87974+ if (lockprev && anon_vma_prepare(prev))
87975+ return -ENOMEM;
87976+ if (lockprev)
87977+ vma_lock_anon_vma(prev);
87978+
87979 vma_lock_anon_vma(vma);
87980
87981 /*
87982@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
87983 */
87984
87985 /* Somebody else might have raced and expanded it already */
87986- if (address < vma->vm_start) {
87987+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
87988+ error = -ENOMEM;
87989+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
87990 unsigned long size, grow;
87991
87992+#ifdef CONFIG_PAX_SEGMEXEC
87993+ struct vm_area_struct *vma_m;
87994+
87995+ vma_m = pax_find_mirror_vma(vma);
87996+#endif
87997+
87998 size = vma->vm_end - address;
87999 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88000
88001@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88002 vma->vm_pgoff -= grow;
88003 anon_vma_interval_tree_post_update_vma(vma);
88004 vma_gap_update(vma);
88005+
88006+#ifdef CONFIG_PAX_SEGMEXEC
88007+ if (vma_m) {
88008+ anon_vma_interval_tree_pre_update_vma(vma_m);
88009+ vma_m->vm_start -= grow << PAGE_SHIFT;
88010+ vma_m->vm_pgoff -= grow;
88011+ anon_vma_interval_tree_post_update_vma(vma_m);
88012+ vma_gap_update(vma_m);
88013+ }
88014+#endif
88015+
88016 spin_unlock(&vma->vm_mm->page_table_lock);
88017
88018+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88019 perf_event_mmap(vma);
88020 }
88021 }
88022 }
88023 vma_unlock_anon_vma(vma);
88024+ if (lockprev)
88025+ vma_unlock_anon_vma(prev);
88026 khugepaged_enter_vma_merge(vma);
88027 validate_mm(vma->vm_mm);
88028 return error;
88029@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88030 do {
88031 long nrpages = vma_pages(vma);
88032
88033+#ifdef CONFIG_PAX_SEGMEXEC
88034+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88035+ vma = remove_vma(vma);
88036+ continue;
88037+ }
88038+#endif
88039+
88040 if (vma->vm_flags & VM_ACCOUNT)
88041 nr_accounted += nrpages;
88042 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88043@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88044 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88045 vma->vm_prev = NULL;
88046 do {
88047+
88048+#ifdef CONFIG_PAX_SEGMEXEC
88049+ if (vma->vm_mirror) {
88050+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88051+ vma->vm_mirror->vm_mirror = NULL;
88052+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88053+ vma->vm_mirror = NULL;
88054+ }
88055+#endif
88056+
88057 vma_rb_erase(vma, &mm->mm_rb);
88058 mm->map_count--;
88059 tail_vma = vma;
88060@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88061 struct vm_area_struct *new;
88062 int err = -ENOMEM;
88063
88064+#ifdef CONFIG_PAX_SEGMEXEC
88065+ struct vm_area_struct *vma_m, *new_m = NULL;
88066+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88067+#endif
88068+
88069 if (is_vm_hugetlb_page(vma) && (addr &
88070 ~(huge_page_mask(hstate_vma(vma)))))
88071 return -EINVAL;
88072
88073+#ifdef CONFIG_PAX_SEGMEXEC
88074+ vma_m = pax_find_mirror_vma(vma);
88075+#endif
88076+
88077 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88078 if (!new)
88079 goto out_err;
88080
88081+#ifdef CONFIG_PAX_SEGMEXEC
88082+ if (vma_m) {
88083+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88084+ if (!new_m) {
88085+ kmem_cache_free(vm_area_cachep, new);
88086+ goto out_err;
88087+ }
88088+ }
88089+#endif
88090+
88091 /* most fields are the same, copy all, and then fixup */
88092 *new = *vma;
88093
88094@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88095 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88096 }
88097
88098+#ifdef CONFIG_PAX_SEGMEXEC
88099+ if (vma_m) {
88100+ *new_m = *vma_m;
88101+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88102+ new_m->vm_mirror = new;
88103+ new->vm_mirror = new_m;
88104+
88105+ if (new_below)
88106+ new_m->vm_end = addr_m;
88107+ else {
88108+ new_m->vm_start = addr_m;
88109+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88110+ }
88111+ }
88112+#endif
88113+
88114 pol = mpol_dup(vma_policy(vma));
88115 if (IS_ERR(pol)) {
88116 err = PTR_ERR(pol);
88117@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88118 else
88119 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88120
88121+#ifdef CONFIG_PAX_SEGMEXEC
88122+ if (!err && vma_m) {
88123+ if (anon_vma_clone(new_m, vma_m))
88124+ goto out_free_mpol;
88125+
88126+ mpol_get(pol);
88127+ vma_set_policy(new_m, pol);
88128+
88129+ if (new_m->vm_file)
88130+ get_file(new_m->vm_file);
88131+
88132+ if (new_m->vm_ops && new_m->vm_ops->open)
88133+ new_m->vm_ops->open(new_m);
88134+
88135+ if (new_below)
88136+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88137+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88138+ else
88139+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88140+
88141+ if (err) {
88142+ if (new_m->vm_ops && new_m->vm_ops->close)
88143+ new_m->vm_ops->close(new_m);
88144+ if (new_m->vm_file)
88145+ fput(new_m->vm_file);
88146+ mpol_put(pol);
88147+ }
88148+ }
88149+#endif
88150+
88151 /* Success. */
88152 if (!err)
88153 return 0;
88154@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88155 new->vm_ops->close(new);
88156 if (new->vm_file)
88157 fput(new->vm_file);
88158- unlink_anon_vmas(new);
88159 out_free_mpol:
88160 mpol_put(pol);
88161 out_free_vma:
88162+
88163+#ifdef CONFIG_PAX_SEGMEXEC
88164+ if (new_m) {
88165+ unlink_anon_vmas(new_m);
88166+ kmem_cache_free(vm_area_cachep, new_m);
88167+ }
88168+#endif
88169+
88170+ unlink_anon_vmas(new);
88171 kmem_cache_free(vm_area_cachep, new);
88172 out_err:
88173 return err;
88174@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88175 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88176 unsigned long addr, int new_below)
88177 {
88178+
88179+#ifdef CONFIG_PAX_SEGMEXEC
88180+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88181+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88182+ if (mm->map_count >= sysctl_max_map_count-1)
88183+ return -ENOMEM;
88184+ } else
88185+#endif
88186+
88187 if (mm->map_count >= sysctl_max_map_count)
88188 return -ENOMEM;
88189
88190@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88191 * work. This now handles partial unmappings.
88192 * Jeremy Fitzhardinge <jeremy@goop.org>
88193 */
88194+#ifdef CONFIG_PAX_SEGMEXEC
88195 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88196 {
88197+ int ret = __do_munmap(mm, start, len);
88198+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88199+ return ret;
88200+
88201+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88202+}
88203+
88204+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88205+#else
88206+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88207+#endif
88208+{
88209 unsigned long end;
88210 struct vm_area_struct *vma, *prev, *last;
88211
88212+ /*
88213+ * mm->mmap_sem is required to protect against another thread
88214+ * changing the mappings in case we sleep.
88215+ */
88216+ verify_mm_writelocked(mm);
88217+
88218 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88219 return -EINVAL;
88220
88221@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88222 /* Fix up all other VM information */
88223 remove_vma_list(mm, vma);
88224
88225+ track_exec_limit(mm, start, end, 0UL);
88226+
88227 return 0;
88228 }
88229
88230@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88231 int ret;
88232 struct mm_struct *mm = current->mm;
88233
88234+
88235+#ifdef CONFIG_PAX_SEGMEXEC
88236+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88237+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88238+ return -EINVAL;
88239+#endif
88240+
88241 down_write(&mm->mmap_sem);
88242 ret = do_munmap(mm, start, len);
88243 up_write(&mm->mmap_sem);
88244@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88245 return vm_munmap(addr, len);
88246 }
88247
88248-static inline void verify_mm_writelocked(struct mm_struct *mm)
88249-{
88250-#ifdef CONFIG_DEBUG_VM
88251- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88252- WARN_ON(1);
88253- up_read(&mm->mmap_sem);
88254- }
88255-#endif
88256-}
88257-
88258 /*
88259 * this is really a simplified "do_mmap". it only handles
88260 * anonymous maps. eventually we may be able to do some
88261@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88262 struct rb_node ** rb_link, * rb_parent;
88263 pgoff_t pgoff = addr >> PAGE_SHIFT;
88264 int error;
88265+ unsigned long charged;
88266
88267 len = PAGE_ALIGN(len);
88268 if (!len)
88269@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88270
88271 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88272
88273+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88274+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88275+ flags &= ~VM_EXEC;
88276+
88277+#ifdef CONFIG_PAX_MPROTECT
88278+ if (mm->pax_flags & MF_PAX_MPROTECT)
88279+ flags &= ~VM_MAYEXEC;
88280+#endif
88281+
88282+ }
88283+#endif
88284+
88285 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88286 if (error & ~PAGE_MASK)
88287 return error;
88288
88289+ charged = len >> PAGE_SHIFT;
88290+
88291 /*
88292 * mlock MCL_FUTURE?
88293 */
88294 if (mm->def_flags & VM_LOCKED) {
88295 unsigned long locked, lock_limit;
88296- locked = len >> PAGE_SHIFT;
88297+ locked = charged;
88298 locked += mm->locked_vm;
88299 lock_limit = rlimit(RLIMIT_MEMLOCK);
88300 lock_limit >>= PAGE_SHIFT;
88301@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88302 /*
88303 * Clear old maps. this also does some error checking for us
88304 */
88305- munmap_back:
88306 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88307 if (do_munmap(mm, addr, len))
88308 return -ENOMEM;
88309- goto munmap_back;
88310+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88311 }
88312
88313 /* Check against address space limits *after* clearing old maps... */
88314- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88315+ if (!may_expand_vm(mm, charged))
88316 return -ENOMEM;
88317
88318 if (mm->map_count > sysctl_max_map_count)
88319 return -ENOMEM;
88320
88321- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88322+ if (security_vm_enough_memory_mm(mm, charged))
88323 return -ENOMEM;
88324
88325 /* Can we just expand an old private anonymous mapping? */
88326@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88327 */
88328 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88329 if (!vma) {
88330- vm_unacct_memory(len >> PAGE_SHIFT);
88331+ vm_unacct_memory(charged);
88332 return -ENOMEM;
88333 }
88334
88335@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88336 vma_link(mm, vma, prev, rb_link, rb_parent);
88337 out:
88338 perf_event_mmap(vma);
88339- mm->total_vm += len >> PAGE_SHIFT;
88340+ mm->total_vm += charged;
88341 if (flags & VM_LOCKED)
88342- mm->locked_vm += (len >> PAGE_SHIFT);
88343+ mm->locked_vm += charged;
88344+ track_exec_limit(mm, addr, addr + len, flags);
88345 return addr;
88346 }
88347
88348@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88349 while (vma) {
88350 if (vma->vm_flags & VM_ACCOUNT)
88351 nr_accounted += vma_pages(vma);
88352+ vma->vm_mirror = NULL;
88353 vma = remove_vma(vma);
88354 }
88355 vm_unacct_memory(nr_accounted);
88356@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88357 struct vm_area_struct *prev;
88358 struct rb_node **rb_link, *rb_parent;
88359
88360+#ifdef CONFIG_PAX_SEGMEXEC
88361+ struct vm_area_struct *vma_m = NULL;
88362+#endif
88363+
88364+ if (security_mmap_addr(vma->vm_start))
88365+ return -EPERM;
88366+
88367 /*
88368 * The vm_pgoff of a purely anonymous vma should be irrelevant
88369 * until its first write fault, when page's anon_vma and index
88370@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88371 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88372 return -ENOMEM;
88373
88374+#ifdef CONFIG_PAX_SEGMEXEC
88375+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88376+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88377+ if (!vma_m)
88378+ return -ENOMEM;
88379+ }
88380+#endif
88381+
88382 vma_link(mm, vma, prev, rb_link, rb_parent);
88383+
88384+#ifdef CONFIG_PAX_SEGMEXEC
88385+ if (vma_m)
88386+ BUG_ON(pax_mirror_vma(vma_m, vma));
88387+#endif
88388+
88389 return 0;
88390 }
88391
88392@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88393 struct mempolicy *pol;
88394 bool faulted_in_anon_vma = true;
88395
88396+ BUG_ON(vma->vm_mirror);
88397+
88398 /*
88399 * If anonymous vma has not yet been faulted, update new pgoff
88400 * to match new location, to increase its chance of merging.
88401@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88402 return NULL;
88403 }
88404
88405+#ifdef CONFIG_PAX_SEGMEXEC
88406+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88407+{
88408+ struct vm_area_struct *prev_m;
88409+ struct rb_node **rb_link_m, *rb_parent_m;
88410+ struct mempolicy *pol_m;
88411+
88412+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88413+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88414+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88415+ *vma_m = *vma;
88416+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88417+ if (anon_vma_clone(vma_m, vma))
88418+ return -ENOMEM;
88419+ pol_m = vma_policy(vma_m);
88420+ mpol_get(pol_m);
88421+ vma_set_policy(vma_m, pol_m);
88422+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88423+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88424+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88425+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88426+ if (vma_m->vm_file)
88427+ get_file(vma_m->vm_file);
88428+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88429+ vma_m->vm_ops->open(vma_m);
88430+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88431+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88432+ vma_m->vm_mirror = vma;
88433+ vma->vm_mirror = vma_m;
88434+ return 0;
88435+}
88436+#endif
88437+
88438 /*
88439 * Return true if the calling process may expand its vm space by the passed
88440 * number of pages
88441@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88442
88443 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88444
88445+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88446 if (cur + npages > lim)
88447 return 0;
88448 return 1;
88449@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88450 vma->vm_start = addr;
88451 vma->vm_end = addr + len;
88452
88453+#ifdef CONFIG_PAX_MPROTECT
88454+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88455+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88456+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88457+ return -EPERM;
88458+ if (!(vm_flags & VM_EXEC))
88459+ vm_flags &= ~VM_MAYEXEC;
88460+#else
88461+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88462+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88463+#endif
88464+ else
88465+ vm_flags &= ~VM_MAYWRITE;
88466+ }
88467+#endif
88468+
88469 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88470 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88471
88472diff --git a/mm/mprotect.c b/mm/mprotect.c
88473index 94722a4..e661e29 100644
88474--- a/mm/mprotect.c
88475+++ b/mm/mprotect.c
88476@@ -23,10 +23,18 @@
88477 #include <linux/mmu_notifier.h>
88478 #include <linux/migrate.h>
88479 #include <linux/perf_event.h>
88480+#include <linux/sched/sysctl.h>
88481+
88482+#ifdef CONFIG_PAX_MPROTECT
88483+#include <linux/elf.h>
88484+#include <linux/binfmts.h>
88485+#endif
88486+
88487 #include <asm/uaccess.h>
88488 #include <asm/pgtable.h>
88489 #include <asm/cacheflush.h>
88490 #include <asm/tlbflush.h>
88491+#include <asm/mmu_context.h>
88492
88493 #ifndef pgprot_modify
88494 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88495@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88496 return pages;
88497 }
88498
88499+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88500+/* called while holding the mmap semaphor for writing except stack expansion */
88501+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88502+{
88503+ unsigned long oldlimit, newlimit = 0UL;
88504+
88505+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88506+ return;
88507+
88508+ spin_lock(&mm->page_table_lock);
88509+ oldlimit = mm->context.user_cs_limit;
88510+ if ((prot & VM_EXEC) && oldlimit < end)
88511+ /* USER_CS limit moved up */
88512+ newlimit = end;
88513+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88514+ /* USER_CS limit moved down */
88515+ newlimit = start;
88516+
88517+ if (newlimit) {
88518+ mm->context.user_cs_limit = newlimit;
88519+
88520+#ifdef CONFIG_SMP
88521+ wmb();
88522+ cpus_clear(mm->context.cpu_user_cs_mask);
88523+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88524+#endif
88525+
88526+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88527+ }
88528+ spin_unlock(&mm->page_table_lock);
88529+ if (newlimit == end) {
88530+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88531+
88532+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88533+ if (is_vm_hugetlb_page(vma))
88534+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88535+ else
88536+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88537+ }
88538+}
88539+#endif
88540+
88541 int
88542 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88543 unsigned long start, unsigned long end, unsigned long newflags)
88544@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88545 int error;
88546 int dirty_accountable = 0;
88547
88548+#ifdef CONFIG_PAX_SEGMEXEC
88549+ struct vm_area_struct *vma_m = NULL;
88550+ unsigned long start_m, end_m;
88551+
88552+ start_m = start + SEGMEXEC_TASK_SIZE;
88553+ end_m = end + SEGMEXEC_TASK_SIZE;
88554+#endif
88555+
88556 if (newflags == oldflags) {
88557 *pprev = vma;
88558 return 0;
88559 }
88560
88561+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88562+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88563+
88564+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88565+ return -ENOMEM;
88566+
88567+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88568+ return -ENOMEM;
88569+ }
88570+
88571 /*
88572 * If we make a private mapping writable we increase our commit;
88573 * but (without finer accounting) cannot reduce our commit if we
88574@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88575 }
88576 }
88577
88578+#ifdef CONFIG_PAX_SEGMEXEC
88579+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88580+ if (start != vma->vm_start) {
88581+ error = split_vma(mm, vma, start, 1);
88582+ if (error)
88583+ goto fail;
88584+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88585+ *pprev = (*pprev)->vm_next;
88586+ }
88587+
88588+ if (end != vma->vm_end) {
88589+ error = split_vma(mm, vma, end, 0);
88590+ if (error)
88591+ goto fail;
88592+ }
88593+
88594+ if (pax_find_mirror_vma(vma)) {
88595+ error = __do_munmap(mm, start_m, end_m - start_m);
88596+ if (error)
88597+ goto fail;
88598+ } else {
88599+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88600+ if (!vma_m) {
88601+ error = -ENOMEM;
88602+ goto fail;
88603+ }
88604+ vma->vm_flags = newflags;
88605+ error = pax_mirror_vma(vma_m, vma);
88606+ if (error) {
88607+ vma->vm_flags = oldflags;
88608+ goto fail;
88609+ }
88610+ }
88611+ }
88612+#endif
88613+
88614 /*
88615 * First try to merge with previous and/or next vma.
88616 */
88617@@ -296,9 +400,21 @@ success:
88618 * vm_flags and vm_page_prot are protected by the mmap_sem
88619 * held in write mode.
88620 */
88621+
88622+#ifdef CONFIG_PAX_SEGMEXEC
88623+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88624+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88625+#endif
88626+
88627 vma->vm_flags = newflags;
88628+
88629+#ifdef CONFIG_PAX_MPROTECT
88630+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88631+ mm->binfmt->handle_mprotect(vma, newflags);
88632+#endif
88633+
88634 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88635- vm_get_page_prot(newflags));
88636+ vm_get_page_prot(vma->vm_flags));
88637
88638 if (vma_wants_writenotify(vma)) {
88639 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88640@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88641 end = start + len;
88642 if (end <= start)
88643 return -ENOMEM;
88644+
88645+#ifdef CONFIG_PAX_SEGMEXEC
88646+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88647+ if (end > SEGMEXEC_TASK_SIZE)
88648+ return -EINVAL;
88649+ } else
88650+#endif
88651+
88652+ if (end > TASK_SIZE)
88653+ return -EINVAL;
88654+
88655 if (!arch_validate_prot(prot))
88656 return -EINVAL;
88657
88658@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88659 /*
88660 * Does the application expect PROT_READ to imply PROT_EXEC:
88661 */
88662- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88663+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88664 prot |= PROT_EXEC;
88665
88666 vm_flags = calc_vm_prot_bits(prot);
88667@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88668 if (start > vma->vm_start)
88669 prev = vma;
88670
88671+#ifdef CONFIG_PAX_MPROTECT
88672+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88673+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88674+#endif
88675+
88676 for (nstart = start ; ; ) {
88677 unsigned long newflags;
88678
88679@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88680
88681 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88682 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88683+ if (prot & (PROT_WRITE | PROT_EXEC))
88684+ gr_log_rwxmprotect(vma);
88685+
88686+ error = -EACCES;
88687+ goto out;
88688+ }
88689+
88690+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88691 error = -EACCES;
88692 goto out;
88693 }
88694@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88695 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88696 if (error)
88697 goto out;
88698+
88699+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88700+
88701 nstart = tmp;
88702
88703 if (nstart < prev->vm_end)
88704diff --git a/mm/mremap.c b/mm/mremap.c
88705index 0843feb..4f5b2e6 100644
88706--- a/mm/mremap.c
88707+++ b/mm/mremap.c
88708@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88709 continue;
88710 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88711 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88712+
88713+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88714+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88715+ pte = pte_exprotect(pte);
88716+#endif
88717+
88718 pte = move_soft_dirty_pte(pte);
88719 set_pte_at(mm, new_addr, new_pte, pte);
88720 }
88721@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88722 if (is_vm_hugetlb_page(vma))
88723 goto Einval;
88724
88725+#ifdef CONFIG_PAX_SEGMEXEC
88726+ if (pax_find_mirror_vma(vma))
88727+ goto Einval;
88728+#endif
88729+
88730 /* We can't remap across vm area boundaries */
88731 if (old_len > vma->vm_end - addr)
88732 goto Efault;
88733@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88734 unsigned long ret = -EINVAL;
88735 unsigned long charged = 0;
88736 unsigned long map_flags;
88737+ unsigned long pax_task_size = TASK_SIZE;
88738
88739 if (new_addr & ~PAGE_MASK)
88740 goto out;
88741
88742- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88743+#ifdef CONFIG_PAX_SEGMEXEC
88744+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88745+ pax_task_size = SEGMEXEC_TASK_SIZE;
88746+#endif
88747+
88748+ pax_task_size -= PAGE_SIZE;
88749+
88750+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88751 goto out;
88752
88753 /* Check if the location we're moving into overlaps the
88754 * old location at all, and fail if it does.
88755 */
88756- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88757- goto out;
88758-
88759- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88760+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88761 goto out;
88762
88763 ret = do_munmap(mm, new_addr, new_len);
88764@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88765 unsigned long ret = -EINVAL;
88766 unsigned long charged = 0;
88767 bool locked = false;
88768+ unsigned long pax_task_size = TASK_SIZE;
88769
88770 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88771 return ret;
88772@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88773 if (!new_len)
88774 return ret;
88775
88776+#ifdef CONFIG_PAX_SEGMEXEC
88777+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88778+ pax_task_size = SEGMEXEC_TASK_SIZE;
88779+#endif
88780+
88781+ pax_task_size -= PAGE_SIZE;
88782+
88783+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88784+ old_len > pax_task_size || addr > pax_task_size-old_len)
88785+ return ret;
88786+
88787 down_write(&current->mm->mmap_sem);
88788
88789 if (flags & MREMAP_FIXED) {
88790@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88791 new_addr = addr;
88792 }
88793 ret = addr;
88794+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88795 goto out;
88796 }
88797 }
88798@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88799 goto out;
88800 }
88801
88802+ map_flags = vma->vm_flags;
88803 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88804+ if (!(ret & ~PAGE_MASK)) {
88805+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88806+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88807+ }
88808 }
88809 out:
88810 if (ret & ~PAGE_MASK)
88811diff --git a/mm/nommu.c b/mm/nommu.c
88812index ecd1f15..77039bd 100644
88813--- a/mm/nommu.c
88814+++ b/mm/nommu.c
88815@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88816 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88817 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88818 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88819-int heap_stack_gap = 0;
88820
88821 atomic_long_t mmap_pages_allocated;
88822
88823@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88824 EXPORT_SYMBOL(find_vma);
88825
88826 /*
88827- * find a VMA
88828- * - we don't extend stack VMAs under NOMMU conditions
88829- */
88830-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88831-{
88832- return find_vma(mm, addr);
88833-}
88834-
88835-/*
88836 * expand a stack to a given address
88837 * - not supported under NOMMU conditions
88838 */
88839@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88840
88841 /* most fields are the same, copy all, and then fixup */
88842 *new = *vma;
88843+ INIT_LIST_HEAD(&new->anon_vma_chain);
88844 *region = *vma->vm_region;
88845 new->vm_region = region;
88846
88847@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88848 }
88849 EXPORT_SYMBOL(generic_file_remap_pages);
88850
88851-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88852- unsigned long addr, void *buf, int len, int write)
88853+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88854+ unsigned long addr, void *buf, size_t len, int write)
88855 {
88856 struct vm_area_struct *vma;
88857
88858@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88859 *
88860 * The caller must hold a reference on @mm.
88861 */
88862-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88863- void *buf, int len, int write)
88864+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88865+ void *buf, size_t len, int write)
88866 {
88867 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88868 }
88869@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88870 * Access another process' address space.
88871 * - source/target buffer must be kernel space
88872 */
88873-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88874+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88875 {
88876 struct mm_struct *mm;
88877
88878diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88879index 3f0c895..60cd104 100644
88880--- a/mm/page-writeback.c
88881+++ b/mm/page-writeback.c
88882@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88883 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88884 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88885 */
88886-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88887+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88888 unsigned long thresh,
88889 unsigned long bg_thresh,
88890 unsigned long dirty,
88891diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88892index b100255..fba1254 100644
88893--- a/mm/page_alloc.c
88894+++ b/mm/page_alloc.c
88895@@ -60,6 +60,7 @@
88896 #include <linux/page-debug-flags.h>
88897 #include <linux/hugetlb.h>
88898 #include <linux/sched/rt.h>
88899+#include <linux/random.h>
88900
88901 #include <asm/sections.h>
88902 #include <asm/tlbflush.h>
88903@@ -353,7 +354,7 @@ out:
88904 * This usage means that zero-order pages may not be compound.
88905 */
88906
88907-static void free_compound_page(struct page *page)
88908+void free_compound_page(struct page *page)
88909 {
88910 __free_pages_ok(page, compound_order(page));
88911 }
88912@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88913 int i;
88914 int bad = 0;
88915
88916+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88917+ unsigned long index = 1UL << order;
88918+#endif
88919+
88920 trace_mm_page_free(page, order);
88921 kmemcheck_free_shadow(page, order);
88922
88923@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88924 debug_check_no_obj_freed(page_address(page),
88925 PAGE_SIZE << order);
88926 }
88927+
88928+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88929+ for (; index; --index)
88930+ sanitize_highpage(page + index - 1);
88931+#endif
88932+
88933 arch_free_page(page, order);
88934 kernel_map_pages(page, 1 << order, 0);
88935
88936@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88937 local_irq_restore(flags);
88938 }
88939
88940+#ifdef CONFIG_PAX_LATENT_ENTROPY
88941+bool __meminitdata extra_latent_entropy;
88942+
88943+static int __init setup_pax_extra_latent_entropy(char *str)
88944+{
88945+ extra_latent_entropy = true;
88946+ return 0;
88947+}
88948+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88949+
88950+volatile u64 latent_entropy;
88951+EXPORT_SYMBOL(latent_entropy);
88952+#endif
88953+
88954 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88955 {
88956 unsigned int nr_pages = 1 << order;
88957@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88958 set_page_count(p, 0);
88959 }
88960
88961+#ifdef CONFIG_PAX_LATENT_ENTROPY
88962+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88963+ u64 hash = 0;
88964+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88965+ const u64 *data = lowmem_page_address(page);
88966+
88967+ for (index = 0; index < end; index++)
88968+ hash ^= hash + data[index];
88969+ latent_entropy ^= hash;
88970+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
88971+ }
88972+#endif
88973+
88974 page_zone(page)->managed_pages += 1 << order;
88975 set_page_refcounted(page);
88976 __free_pages(page, order);
88977@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
88978 arch_alloc_page(page, order);
88979 kernel_map_pages(page, 1 << order, 1);
88980
88981+#ifndef CONFIG_PAX_MEMORY_SANITIZE
88982 if (gfp_flags & __GFP_ZERO)
88983 prep_zero_page(page, order, gfp_flags);
88984+#endif
88985
88986 if (order && (gfp_flags & __GFP_COMP))
88987 prep_compound_page(page, order);
88988diff --git a/mm/page_io.c b/mm/page_io.c
88989index ba05b64..ef2f314 100644
88990--- a/mm/page_io.c
88991+++ b/mm/page_io.c
88992@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
88993 struct file *swap_file = sis->swap_file;
88994 struct address_space *mapping = swap_file->f_mapping;
88995 struct iovec iov = {
88996- .iov_base = kmap(page),
88997+ .iov_base = (void __force_user *)kmap(page),
88998 .iov_len = PAGE_SIZE,
88999 };
89000
89001diff --git a/mm/percpu.c b/mm/percpu.c
89002index 8c8e08f..73a5cda 100644
89003--- a/mm/percpu.c
89004+++ b/mm/percpu.c
89005@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89006 static unsigned int pcpu_high_unit_cpu __read_mostly;
89007
89008 /* the address of the first chunk which starts with the kernel static area */
89009-void *pcpu_base_addr __read_mostly;
89010+void *pcpu_base_addr __read_only;
89011 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89012
89013 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89014diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89015index fd26d04..0cea1b0 100644
89016--- a/mm/process_vm_access.c
89017+++ b/mm/process_vm_access.c
89018@@ -13,6 +13,7 @@
89019 #include <linux/uio.h>
89020 #include <linux/sched.h>
89021 #include <linux/highmem.h>
89022+#include <linux/security.h>
89023 #include <linux/ptrace.h>
89024 #include <linux/slab.h>
89025 #include <linux/syscalls.h>
89026@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89027 size_t iov_l_curr_offset = 0;
89028 ssize_t iov_len;
89029
89030+ return -ENOSYS; // PaX: until properly audited
89031+
89032 /*
89033 * Work out how many pages of struct pages we're going to need
89034 * when eventually calling get_user_pages
89035 */
89036 for (i = 0; i < riovcnt; i++) {
89037 iov_len = rvec[i].iov_len;
89038- if (iov_len > 0) {
89039- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89040- + iov_len)
89041- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89042- / PAGE_SIZE + 1;
89043- nr_pages = max(nr_pages, nr_pages_iov);
89044- }
89045+ if (iov_len <= 0)
89046+ continue;
89047+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89048+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89049+ nr_pages = max(nr_pages, nr_pages_iov);
89050 }
89051
89052 if (nr_pages == 0)
89053@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89054 goto free_proc_pages;
89055 }
89056
89057+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89058+ rc = -EPERM;
89059+ goto put_task_struct;
89060+ }
89061+
89062 mm = mm_access(task, PTRACE_MODE_ATTACH);
89063 if (!mm || IS_ERR(mm)) {
89064 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89065diff --git a/mm/rmap.c b/mm/rmap.c
89066index b2e29ac..4168491 100644
89067--- a/mm/rmap.c
89068+++ b/mm/rmap.c
89069@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89070 struct anon_vma *anon_vma = vma->anon_vma;
89071 struct anon_vma_chain *avc;
89072
89073+#ifdef CONFIG_PAX_SEGMEXEC
89074+ struct anon_vma_chain *avc_m = NULL;
89075+#endif
89076+
89077 might_sleep();
89078 if (unlikely(!anon_vma)) {
89079 struct mm_struct *mm = vma->vm_mm;
89080@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89081 if (!avc)
89082 goto out_enomem;
89083
89084+#ifdef CONFIG_PAX_SEGMEXEC
89085+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89086+ if (!avc_m)
89087+ goto out_enomem_free_avc;
89088+#endif
89089+
89090 anon_vma = find_mergeable_anon_vma(vma);
89091 allocated = NULL;
89092 if (!anon_vma) {
89093@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89094 /* page_table_lock to protect against threads */
89095 spin_lock(&mm->page_table_lock);
89096 if (likely(!vma->anon_vma)) {
89097+
89098+#ifdef CONFIG_PAX_SEGMEXEC
89099+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89100+
89101+ if (vma_m) {
89102+ BUG_ON(vma_m->anon_vma);
89103+ vma_m->anon_vma = anon_vma;
89104+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89105+ avc_m = NULL;
89106+ }
89107+#endif
89108+
89109 vma->anon_vma = anon_vma;
89110 anon_vma_chain_link(vma, avc, anon_vma);
89111 allocated = NULL;
89112@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89113
89114 if (unlikely(allocated))
89115 put_anon_vma(allocated);
89116+
89117+#ifdef CONFIG_PAX_SEGMEXEC
89118+ if (unlikely(avc_m))
89119+ anon_vma_chain_free(avc_m);
89120+#endif
89121+
89122 if (unlikely(avc))
89123 anon_vma_chain_free(avc);
89124 }
89125 return 0;
89126
89127 out_enomem_free_avc:
89128+
89129+#ifdef CONFIG_PAX_SEGMEXEC
89130+ if (avc_m)
89131+ anon_vma_chain_free(avc_m);
89132+#endif
89133+
89134 anon_vma_chain_free(avc);
89135 out_enomem:
89136 return -ENOMEM;
89137@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89138 * Attach the anon_vmas from src to dst.
89139 * Returns 0 on success, -ENOMEM on failure.
89140 */
89141-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89142+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89143 {
89144 struct anon_vma_chain *avc, *pavc;
89145 struct anon_vma *root = NULL;
89146@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89147 * the corresponding VMA in the parent process is attached to.
89148 * Returns 0 on success, non-zero on failure.
89149 */
89150-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89151+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89152 {
89153 struct anon_vma_chain *avc;
89154 struct anon_vma *anon_vma;
89155@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89156 void __init anon_vma_init(void)
89157 {
89158 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89159- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89160- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89161+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89162+ anon_vma_ctor);
89163+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89164+ SLAB_PANIC|SLAB_NO_SANITIZE);
89165 }
89166
89167 /*
89168diff --git a/mm/shmem.c b/mm/shmem.c
89169index e43dc55..930e3a2 100644
89170--- a/mm/shmem.c
89171+++ b/mm/shmem.c
89172@@ -33,7 +33,7 @@
89173 #include <linux/swap.h>
89174 #include <linux/aio.h>
89175
89176-static struct vfsmount *shm_mnt;
89177+struct vfsmount *shm_mnt;
89178
89179 #ifdef CONFIG_SHMEM
89180 /*
89181@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89182 #define BOGO_DIRENT_SIZE 20
89183
89184 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89185-#define SHORT_SYMLINK_LEN 128
89186+#define SHORT_SYMLINK_LEN 64
89187
89188 /*
89189 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89190@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89191 static int shmem_xattr_validate(const char *name)
89192 {
89193 struct { const char *prefix; size_t len; } arr[] = {
89194+
89195+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89196+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89197+#endif
89198+
89199 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89200 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89201 };
89202@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89203 if (err)
89204 return err;
89205
89206+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89207+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89208+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89209+ return -EOPNOTSUPP;
89210+ if (size > 8)
89211+ return -EINVAL;
89212+ }
89213+#endif
89214+
89215 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89216 }
89217
89218@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89219 int err = -ENOMEM;
89220
89221 /* Round up to L1_CACHE_BYTES to resist false sharing */
89222- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89223- L1_CACHE_BYTES), GFP_KERNEL);
89224+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89225 if (!sbinfo)
89226 return -ENOMEM;
89227
89228diff --git a/mm/slab.c b/mm/slab.c
89229index 2580db0..0523956 100644
89230--- a/mm/slab.c
89231+++ b/mm/slab.c
89232@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89233 if ((x)->max_freeable < i) \
89234 (x)->max_freeable = i; \
89235 } while (0)
89236-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89237-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89238-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89239-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89240+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89241+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89242+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89243+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89244+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89245+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89246 #else
89247 #define STATS_INC_ACTIVE(x) do { } while (0)
89248 #define STATS_DEC_ACTIVE(x) do { } while (0)
89249@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89250 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89251 #define STATS_INC_FREEHIT(x) do { } while (0)
89252 #define STATS_INC_FREEMISS(x) do { } while (0)
89253+#define STATS_INC_SANITIZED(x) do { } while (0)
89254+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89255 #endif
89256
89257 #if DEBUG
89258@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89259 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89260 */
89261 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89262- const struct slab *slab, void *obj)
89263+ const struct slab *slab, const void *obj)
89264 {
89265 u32 offset = (obj - slab->s_mem);
89266 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89267@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89268 */
89269
89270 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89271- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89272+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89273
89274 if (INDEX_AC != INDEX_NODE)
89275 kmalloc_caches[INDEX_NODE] =
89276 create_kmalloc_cache("kmalloc-node",
89277- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89278+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89279
89280 slab_early_init = 0;
89281
89282@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89283 struct array_cache *ac = cpu_cache_get(cachep);
89284
89285 check_irq_off();
89286+
89287+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89288+ if (pax_sanitize_slab) {
89289+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89290+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89291+
89292+ if (cachep->ctor)
89293+ cachep->ctor(objp);
89294+
89295+ STATS_INC_SANITIZED(cachep);
89296+ } else
89297+ STATS_INC_NOT_SANITIZED(cachep);
89298+ }
89299+#endif
89300+
89301 kmemleak_free_recursive(objp, cachep->flags);
89302 objp = cache_free_debugcheck(cachep, objp, caller);
89303
89304@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89305
89306 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89307 return;
89308+ VM_BUG_ON(!virt_addr_valid(objp));
89309 local_irq_save(flags);
89310 kfree_debugcheck(objp);
89311 c = virt_to_cache(objp);
89312@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89313 }
89314 /* cpu stats */
89315 {
89316- unsigned long allochit = atomic_read(&cachep->allochit);
89317- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89318- unsigned long freehit = atomic_read(&cachep->freehit);
89319- unsigned long freemiss = atomic_read(&cachep->freemiss);
89320+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89321+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89322+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89323+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89324
89325 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89326 allochit, allocmiss, freehit, freemiss);
89327 }
89328+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89329+ {
89330+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89331+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89332+
89333+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89334+ }
89335+#endif
89336 #endif
89337 }
89338
89339@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89340 static int __init slab_proc_init(void)
89341 {
89342 #ifdef CONFIG_DEBUG_SLAB_LEAK
89343- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89344+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89345 #endif
89346 return 0;
89347 }
89348 module_init(slab_proc_init);
89349 #endif
89350
89351+bool is_usercopy_object(const void *ptr)
89352+{
89353+ struct page *page;
89354+ struct kmem_cache *cachep;
89355+
89356+ if (ZERO_OR_NULL_PTR(ptr))
89357+ return false;
89358+
89359+ if (!slab_is_available())
89360+ return false;
89361+
89362+ if (!virt_addr_valid(ptr))
89363+ return false;
89364+
89365+ page = virt_to_head_page(ptr);
89366+
89367+ if (!PageSlab(page))
89368+ return false;
89369+
89370+ cachep = page->slab_cache;
89371+ return cachep->flags & SLAB_USERCOPY;
89372+}
89373+
89374+#ifdef CONFIG_PAX_USERCOPY
89375+const char *check_heap_object(const void *ptr, unsigned long n)
89376+{
89377+ struct page *page;
89378+ struct kmem_cache *cachep;
89379+ struct slab *slabp;
89380+ unsigned int objnr;
89381+ unsigned long offset;
89382+
89383+ if (ZERO_OR_NULL_PTR(ptr))
89384+ return "<null>";
89385+
89386+ if (!virt_addr_valid(ptr))
89387+ return NULL;
89388+
89389+ page = virt_to_head_page(ptr);
89390+
89391+ if (!PageSlab(page))
89392+ return NULL;
89393+
89394+ cachep = page->slab_cache;
89395+ if (!(cachep->flags & SLAB_USERCOPY))
89396+ return cachep->name;
89397+
89398+ slabp = page->slab_page;
89399+ objnr = obj_to_index(cachep, slabp, ptr);
89400+ BUG_ON(objnr >= cachep->num);
89401+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89402+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89403+ return NULL;
89404+
89405+ return cachep->name;
89406+}
89407+#endif
89408+
89409 /**
89410 * ksize - get the actual amount of memory allocated for a given object
89411 * @objp: Pointer to the object
89412diff --git a/mm/slab.h b/mm/slab.h
89413index a535033..2f98fe5 100644
89414--- a/mm/slab.h
89415+++ b/mm/slab.h
89416@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89417 /* The slab cache that manages slab cache information */
89418 extern struct kmem_cache *kmem_cache;
89419
89420+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89421+#ifdef CONFIG_X86_64
89422+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89423+#else
89424+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89425+#endif
89426+extern bool pax_sanitize_slab;
89427+#endif
89428+
89429 unsigned long calculate_alignment(unsigned long flags,
89430 unsigned long align, unsigned long size);
89431
89432@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89433
89434 /* Legal flag mask for kmem_cache_create(), for various configurations */
89435 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89436- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89437+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89438+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89439
89440 #if defined(CONFIG_DEBUG_SLAB)
89441 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89442@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89443 return s;
89444
89445 page = virt_to_head_page(x);
89446+
89447+ BUG_ON(!PageSlab(page));
89448+
89449 cachep = page->slab_cache;
89450 if (slab_equal_or_root(cachep, s))
89451 return cachep;
89452diff --git a/mm/slab_common.c b/mm/slab_common.c
89453index 538bade..36fed99 100644
89454--- a/mm/slab_common.c
89455+++ b/mm/slab_common.c
89456@@ -22,11 +22,22 @@
89457
89458 #include "slab.h"
89459
89460-enum slab_state slab_state;
89461+enum slab_state slab_state __read_only;
89462 LIST_HEAD(slab_caches);
89463 DEFINE_MUTEX(slab_mutex);
89464 struct kmem_cache *kmem_cache;
89465
89466+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89467+bool pax_sanitize_slab __read_only = true;
89468+static int __init pax_sanitize_slab_setup(char *str)
89469+{
89470+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89471+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89472+ return 1;
89473+}
89474+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89475+#endif
89476+
89477 #ifdef CONFIG_DEBUG_VM
89478 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89479 size_t size)
89480@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89481
89482 err = __kmem_cache_create(s, flags);
89483 if (!err) {
89484- s->refcount = 1;
89485+ atomic_set(&s->refcount, 1);
89486 list_add(&s->list, &slab_caches);
89487 memcg_cache_list_add(memcg, s);
89488 } else {
89489@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89490
89491 get_online_cpus();
89492 mutex_lock(&slab_mutex);
89493- s->refcount--;
89494- if (!s->refcount) {
89495+ if (atomic_dec_and_test(&s->refcount)) {
89496 list_del(&s->list);
89497
89498 if (!__kmem_cache_shutdown(s)) {
89499@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89500 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89501 name, size, err);
89502
89503- s->refcount = -1; /* Exempt from merging for now */
89504+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89505 }
89506
89507 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89508@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89509
89510 create_boot_cache(s, name, size, flags);
89511 list_add(&s->list, &slab_caches);
89512- s->refcount = 1;
89513+ atomic_set(&s->refcount, 1);
89514 return s;
89515 }
89516
89517@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89518 EXPORT_SYMBOL(kmalloc_dma_caches);
89519 #endif
89520
89521+#ifdef CONFIG_PAX_USERCOPY_SLABS
89522+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89523+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89524+#endif
89525+
89526 /*
89527 * Conversion table for small slabs sizes / 8 to the index in the
89528 * kmalloc array. This is necessary for slabs < 192 since we have non power
89529@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89530 return kmalloc_dma_caches[index];
89531
89532 #endif
89533+
89534+#ifdef CONFIG_PAX_USERCOPY_SLABS
89535+ if (unlikely((flags & GFP_USERCOPY)))
89536+ return kmalloc_usercopy_caches[index];
89537+
89538+#endif
89539+
89540 return kmalloc_caches[index];
89541 }
89542
89543@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89544 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89545 if (!kmalloc_caches[i]) {
89546 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89547- 1 << i, flags);
89548+ 1 << i, SLAB_USERCOPY | flags);
89549 }
89550
89551 /*
89552@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89553 * earlier power of two caches
89554 */
89555 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89556- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89557+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89558
89559 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89560- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89561+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89562 }
89563
89564 /* Kmalloc array is now usable */
89565@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89566 }
89567 }
89568 #endif
89569+
89570+#ifdef CONFIG_PAX_USERCOPY_SLABS
89571+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89572+ struct kmem_cache *s = kmalloc_caches[i];
89573+
89574+ if (s) {
89575+ int size = kmalloc_size(i);
89576+ char *n = kasprintf(GFP_NOWAIT,
89577+ "usercopy-kmalloc-%d", size);
89578+
89579+ BUG_ON(!n);
89580+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89581+ size, SLAB_USERCOPY | flags);
89582+ }
89583+ }
89584+#endif
89585+
89586 }
89587 #endif /* !CONFIG_SLOB */
89588
89589@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89590 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89591 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89592 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89593+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89594+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89595+#endif
89596 #endif
89597 seq_putc(m, '\n');
89598 }
89599diff --git a/mm/slob.c b/mm/slob.c
89600index 91bd3f2..e2f549e 100644
89601--- a/mm/slob.c
89602+++ b/mm/slob.c
89603@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89604 /*
89605 * Return the size of a slob block.
89606 */
89607-static slobidx_t slob_units(slob_t *s)
89608+static slobidx_t slob_units(const slob_t *s)
89609 {
89610 if (s->units > 0)
89611 return s->units;
89612@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89613 /*
89614 * Return the next free slob block pointer after this one.
89615 */
89616-static slob_t *slob_next(slob_t *s)
89617+static slob_t *slob_next(const slob_t *s)
89618 {
89619 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89620 slobidx_t next;
89621@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89622 /*
89623 * Returns true if s is the last free block in its page.
89624 */
89625-static int slob_last(slob_t *s)
89626+static int slob_last(const slob_t *s)
89627 {
89628 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89629 }
89630
89631-static void *slob_new_pages(gfp_t gfp, int order, int node)
89632+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89633 {
89634- void *page;
89635+ struct page *page;
89636
89637 #ifdef CONFIG_NUMA
89638 if (node != NUMA_NO_NODE)
89639@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89640 if (!page)
89641 return NULL;
89642
89643- return page_address(page);
89644+ __SetPageSlab(page);
89645+ return page;
89646 }
89647
89648-static void slob_free_pages(void *b, int order)
89649+static void slob_free_pages(struct page *sp, int order)
89650 {
89651 if (current->reclaim_state)
89652 current->reclaim_state->reclaimed_slab += 1 << order;
89653- free_pages((unsigned long)b, order);
89654+ __ClearPageSlab(sp);
89655+ page_mapcount_reset(sp);
89656+ sp->private = 0;
89657+ __free_pages(sp, order);
89658 }
89659
89660 /*
89661@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89662
89663 /* Not enough space: must allocate a new page */
89664 if (!b) {
89665- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89666- if (!b)
89667+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89668+ if (!sp)
89669 return NULL;
89670- sp = virt_to_page(b);
89671- __SetPageSlab(sp);
89672+ b = page_address(sp);
89673
89674 spin_lock_irqsave(&slob_lock, flags);
89675 sp->units = SLOB_UNITS(PAGE_SIZE);
89676 sp->freelist = b;
89677+ sp->private = 0;
89678 INIT_LIST_HEAD(&sp->list);
89679 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89680 set_slob_page_free(sp, slob_list);
89681@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89682 if (slob_page_free(sp))
89683 clear_slob_page_free(sp);
89684 spin_unlock_irqrestore(&slob_lock, flags);
89685- __ClearPageSlab(sp);
89686- page_mapcount_reset(sp);
89687- slob_free_pages(b, 0);
89688+ slob_free_pages(sp, 0);
89689 return;
89690 }
89691
89692+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89693+ if (pax_sanitize_slab)
89694+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89695+#endif
89696+
89697 if (!slob_page_free(sp)) {
89698 /* This slob page is about to become partially free. Easy! */
89699 sp->units = units;
89700@@ -424,11 +431,10 @@ out:
89701 */
89702
89703 static __always_inline void *
89704-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89705+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89706 {
89707- unsigned int *m;
89708- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89709- void *ret;
89710+ slob_t *m;
89711+ void *ret = NULL;
89712
89713 gfp &= gfp_allowed_mask;
89714
89715@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89716
89717 if (!m)
89718 return NULL;
89719- *m = size;
89720+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89721+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89722+ m[0].units = size;
89723+ m[1].units = align;
89724 ret = (void *)m + align;
89725
89726 trace_kmalloc_node(caller, ret,
89727 size, size + align, gfp, node);
89728 } else {
89729 unsigned int order = get_order(size);
89730+ struct page *page;
89731
89732 if (likely(order))
89733 gfp |= __GFP_COMP;
89734- ret = slob_new_pages(gfp, order, node);
89735+ page = slob_new_pages(gfp, order, node);
89736+ if (page) {
89737+ ret = page_address(page);
89738+ page->private = size;
89739+ }
89740
89741 trace_kmalloc_node(caller, ret,
89742 size, PAGE_SIZE << order, gfp, node);
89743 }
89744
89745- kmemleak_alloc(ret, size, 1, gfp);
89746+ return ret;
89747+}
89748+
89749+static __always_inline void *
89750+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89751+{
89752+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89753+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89754+
89755+ if (!ZERO_OR_NULL_PTR(ret))
89756+ kmemleak_alloc(ret, size, 1, gfp);
89757 return ret;
89758 }
89759
89760@@ -493,34 +517,112 @@ void kfree(const void *block)
89761 return;
89762 kmemleak_free(block);
89763
89764+ VM_BUG_ON(!virt_addr_valid(block));
89765 sp = virt_to_page(block);
89766- if (PageSlab(sp)) {
89767+ VM_BUG_ON(!PageSlab(sp));
89768+ if (!sp->private) {
89769 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89770- unsigned int *m = (unsigned int *)(block - align);
89771- slob_free(m, *m + align);
89772- } else
89773+ slob_t *m = (slob_t *)(block - align);
89774+ slob_free(m, m[0].units + align);
89775+ } else {
89776+ __ClearPageSlab(sp);
89777+ page_mapcount_reset(sp);
89778+ sp->private = 0;
89779 __free_pages(sp, compound_order(sp));
89780+ }
89781 }
89782 EXPORT_SYMBOL(kfree);
89783
89784+bool is_usercopy_object(const void *ptr)
89785+{
89786+ if (!slab_is_available())
89787+ return false;
89788+
89789+ // PAX: TODO
89790+
89791+ return false;
89792+}
89793+
89794+#ifdef CONFIG_PAX_USERCOPY
89795+const char *check_heap_object(const void *ptr, unsigned long n)
89796+{
89797+ struct page *page;
89798+ const slob_t *free;
89799+ const void *base;
89800+ unsigned long flags;
89801+
89802+ if (ZERO_OR_NULL_PTR(ptr))
89803+ return "<null>";
89804+
89805+ if (!virt_addr_valid(ptr))
89806+ return NULL;
89807+
89808+ page = virt_to_head_page(ptr);
89809+ if (!PageSlab(page))
89810+ return NULL;
89811+
89812+ if (page->private) {
89813+ base = page;
89814+ if (base <= ptr && n <= page->private - (ptr - base))
89815+ return NULL;
89816+ return "<slob>";
89817+ }
89818+
89819+ /* some tricky double walking to find the chunk */
89820+ spin_lock_irqsave(&slob_lock, flags);
89821+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89822+ free = page->freelist;
89823+
89824+ while (!slob_last(free) && (void *)free <= ptr) {
89825+ base = free + slob_units(free);
89826+ free = slob_next(free);
89827+ }
89828+
89829+ while (base < (void *)free) {
89830+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89831+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89832+ int offset;
89833+
89834+ if (ptr < base + align)
89835+ break;
89836+
89837+ offset = ptr - base - align;
89838+ if (offset >= m) {
89839+ base += size;
89840+ continue;
89841+ }
89842+
89843+ if (n > m - offset)
89844+ break;
89845+
89846+ spin_unlock_irqrestore(&slob_lock, flags);
89847+ return NULL;
89848+ }
89849+
89850+ spin_unlock_irqrestore(&slob_lock, flags);
89851+ return "<slob>";
89852+}
89853+#endif
89854+
89855 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89856 size_t ksize(const void *block)
89857 {
89858 struct page *sp;
89859 int align;
89860- unsigned int *m;
89861+ slob_t *m;
89862
89863 BUG_ON(!block);
89864 if (unlikely(block == ZERO_SIZE_PTR))
89865 return 0;
89866
89867 sp = virt_to_page(block);
89868- if (unlikely(!PageSlab(sp)))
89869- return PAGE_SIZE << compound_order(sp);
89870+ VM_BUG_ON(!PageSlab(sp));
89871+ if (sp->private)
89872+ return sp->private;
89873
89874 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89875- m = (unsigned int *)(block - align);
89876- return SLOB_UNITS(*m) * SLOB_UNIT;
89877+ m = (slob_t *)(block - align);
89878+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89879 }
89880 EXPORT_SYMBOL(ksize);
89881
89882@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89883
89884 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89885 {
89886- void *b;
89887+ void *b = NULL;
89888
89889 flags &= gfp_allowed_mask;
89890
89891 lockdep_trace_alloc(flags);
89892
89893+#ifdef CONFIG_PAX_USERCOPY_SLABS
89894+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89895+#else
89896 if (c->size < PAGE_SIZE) {
89897 b = slob_alloc(c->size, flags, c->align, node);
89898 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89899 SLOB_UNITS(c->size) * SLOB_UNIT,
89900 flags, node);
89901 } else {
89902- b = slob_new_pages(flags, get_order(c->size), node);
89903+ struct page *sp;
89904+
89905+ sp = slob_new_pages(flags, get_order(c->size), node);
89906+ if (sp) {
89907+ b = page_address(sp);
89908+ sp->private = c->size;
89909+ }
89910 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89911 PAGE_SIZE << get_order(c->size),
89912 flags, node);
89913 }
89914+#endif
89915
89916 if (b && c->ctor)
89917 c->ctor(b);
89918@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89919
89920 static void __kmem_cache_free(void *b, int size)
89921 {
89922- if (size < PAGE_SIZE)
89923+ struct page *sp;
89924+
89925+ sp = virt_to_page(b);
89926+ BUG_ON(!PageSlab(sp));
89927+ if (!sp->private)
89928 slob_free(b, size);
89929 else
89930- slob_free_pages(b, get_order(size));
89931+ slob_free_pages(sp, get_order(size));
89932 }
89933
89934 static void kmem_rcu_free(struct rcu_head *head)
89935@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89936
89937 void kmem_cache_free(struct kmem_cache *c, void *b)
89938 {
89939+ int size = c->size;
89940+
89941+#ifdef CONFIG_PAX_USERCOPY_SLABS
89942+ if (size + c->align < PAGE_SIZE) {
89943+ size += c->align;
89944+ b -= c->align;
89945+ }
89946+#endif
89947+
89948 kmemleak_free_recursive(b, c->flags);
89949 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89950 struct slob_rcu *slob_rcu;
89951- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89952- slob_rcu->size = c->size;
89953+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89954+ slob_rcu->size = size;
89955 call_rcu(&slob_rcu->head, kmem_rcu_free);
89956 } else {
89957- __kmem_cache_free(b, c->size);
89958+ __kmem_cache_free(b, size);
89959 }
89960
89961+#ifdef CONFIG_PAX_USERCOPY_SLABS
89962+ trace_kfree(_RET_IP_, b);
89963+#else
89964 trace_kmem_cache_free(_RET_IP_, b);
89965+#endif
89966+
89967 }
89968 EXPORT_SYMBOL(kmem_cache_free);
89969
89970diff --git a/mm/slub.c b/mm/slub.c
89971index e3ba1f2..bd45dac 100644
89972--- a/mm/slub.c
89973+++ b/mm/slub.c
89974@@ -207,7 +207,7 @@ struct track {
89975
89976 enum track_item { TRACK_ALLOC, TRACK_FREE };
89977
89978-#ifdef CONFIG_SYSFS
89979+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89980 static int sysfs_slab_add(struct kmem_cache *);
89981 static int sysfs_slab_alias(struct kmem_cache *, const char *);
89982 static void sysfs_slab_remove(struct kmem_cache *);
89983@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
89984 if (!t->addr)
89985 return;
89986
89987- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
89988+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
89989 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
89990 #ifdef CONFIG_STACKTRACE
89991 {
89992@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
89993
89994 slab_free_hook(s, x);
89995
89996+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89997+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
89998+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
89999+ if (s->ctor)
90000+ s->ctor(x);
90001+ }
90002+#endif
90003+
90004 redo:
90005 /*
90006 * Determine the currently cpus per cpu slab.
90007@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90008 * Merge control. If this is set then no merging of slab caches will occur.
90009 * (Could be removed. This was introduced to pacify the merge skeptics.)
90010 */
90011-static int slub_nomerge;
90012+static int slub_nomerge = 1;
90013
90014 /*
90015 * Calculate the order of allocation given an slab object size.
90016@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90017 s->inuse = size;
90018
90019 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90020+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90021+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90022+#endif
90023 s->ctor)) {
90024 /*
90025 * Relocate free pointer after the object if it is not
90026@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90027 EXPORT_SYMBOL(__kmalloc_node);
90028 #endif
90029
90030+bool is_usercopy_object(const void *ptr)
90031+{
90032+ struct page *page;
90033+ struct kmem_cache *s;
90034+
90035+ if (ZERO_OR_NULL_PTR(ptr))
90036+ return false;
90037+
90038+ if (!slab_is_available())
90039+ return false;
90040+
90041+ if (!virt_addr_valid(ptr))
90042+ return false;
90043+
90044+ page = virt_to_head_page(ptr);
90045+
90046+ if (!PageSlab(page))
90047+ return false;
90048+
90049+ s = page->slab_cache;
90050+ return s->flags & SLAB_USERCOPY;
90051+}
90052+
90053+#ifdef CONFIG_PAX_USERCOPY
90054+const char *check_heap_object(const void *ptr, unsigned long n)
90055+{
90056+ struct page *page;
90057+ struct kmem_cache *s;
90058+ unsigned long offset;
90059+
90060+ if (ZERO_OR_NULL_PTR(ptr))
90061+ return "<null>";
90062+
90063+ if (!virt_addr_valid(ptr))
90064+ return NULL;
90065+
90066+ page = virt_to_head_page(ptr);
90067+
90068+ if (!PageSlab(page))
90069+ return NULL;
90070+
90071+ s = page->slab_cache;
90072+ if (!(s->flags & SLAB_USERCOPY))
90073+ return s->name;
90074+
90075+ offset = (ptr - page_address(page)) % s->size;
90076+ if (offset <= s->object_size && n <= s->object_size - offset)
90077+ return NULL;
90078+
90079+ return s->name;
90080+}
90081+#endif
90082+
90083 size_t ksize(const void *object)
90084 {
90085 struct page *page;
90086@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90087 if (unlikely(ZERO_OR_NULL_PTR(x)))
90088 return;
90089
90090+ VM_BUG_ON(!virt_addr_valid(x));
90091 page = virt_to_head_page(x);
90092 if (unlikely(!PageSlab(page))) {
90093 BUG_ON(!PageCompound(page));
90094@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90095 /*
90096 * We may have set a slab to be unmergeable during bootstrap.
90097 */
90098- if (s->refcount < 0)
90099+ if (atomic_read(&s->refcount) < 0)
90100 return 1;
90101
90102 return 0;
90103@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90104
90105 s = find_mergeable(memcg, size, align, flags, name, ctor);
90106 if (s) {
90107- s->refcount++;
90108+ atomic_inc(&s->refcount);
90109 /*
90110 * Adjust the object sizes so that we clear
90111 * the complete object on kzalloc.
90112@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90113 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90114
90115 if (sysfs_slab_alias(s, name)) {
90116- s->refcount--;
90117+ atomic_dec(&s->refcount);
90118 s = NULL;
90119 }
90120 }
90121@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90122 }
90123 #endif
90124
90125-#ifdef CONFIG_SYSFS
90126+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90127 static int count_inuse(struct page *page)
90128 {
90129 return page->inuse;
90130@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90131 validate_slab_cache(kmalloc_caches[9]);
90132 }
90133 #else
90134-#ifdef CONFIG_SYSFS
90135+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90136 static void resiliency_test(void) {};
90137 #endif
90138 #endif
90139
90140-#ifdef CONFIG_SYSFS
90141+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90142 enum slab_stat_type {
90143 SL_ALL, /* All slabs */
90144 SL_PARTIAL, /* Only partially allocated slabs */
90145@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90146
90147 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90148 {
90149- return sprintf(buf, "%d\n", s->refcount - 1);
90150+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90151 }
90152 SLAB_ATTR_RO(aliases);
90153
90154@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90155 SLAB_ATTR_RO(cache_dma);
90156 #endif
90157
90158+#ifdef CONFIG_PAX_USERCOPY_SLABS
90159+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90160+{
90161+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90162+}
90163+SLAB_ATTR_RO(usercopy);
90164+#endif
90165+
90166 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90167 {
90168 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90169@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90170 #ifdef CONFIG_ZONE_DMA
90171 &cache_dma_attr.attr,
90172 #endif
90173+#ifdef CONFIG_PAX_USERCOPY_SLABS
90174+ &usercopy_attr.attr,
90175+#endif
90176 #ifdef CONFIG_NUMA
90177 &remote_node_defrag_ratio_attr.attr,
90178 #endif
90179@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90180 return name;
90181 }
90182
90183+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90184 static int sysfs_slab_add(struct kmem_cache *s)
90185 {
90186 int err;
90187@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90188 }
90189
90190 s->kobj.kset = slab_kset;
90191- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90192+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90193 if (err) {
90194 kobject_put(&s->kobj);
90195 return err;
90196@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90197 kobject_del(&s->kobj);
90198 kobject_put(&s->kobj);
90199 }
90200+#endif
90201
90202 /*
90203 * Need to buffer aliases during bootup until sysfs becomes
90204@@ -5213,6 +5291,7 @@ struct saved_alias {
90205
90206 static struct saved_alias *alias_list;
90207
90208+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90209 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90210 {
90211 struct saved_alias *al;
90212@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90213 alias_list = al;
90214 return 0;
90215 }
90216+#endif
90217
90218 static int __init slab_sysfs_init(void)
90219 {
90220diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90221index 27eeab3..7c3f7f2 100644
90222--- a/mm/sparse-vmemmap.c
90223+++ b/mm/sparse-vmemmap.c
90224@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90225 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90226 if (!p)
90227 return NULL;
90228- pud_populate(&init_mm, pud, p);
90229+ pud_populate_kernel(&init_mm, pud, p);
90230 }
90231 return pud;
90232 }
90233@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90234 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90235 if (!p)
90236 return NULL;
90237- pgd_populate(&init_mm, pgd, p);
90238+ pgd_populate_kernel(&init_mm, pgd, p);
90239 }
90240 return pgd;
90241 }
90242diff --git a/mm/sparse.c b/mm/sparse.c
90243index 308d503..3dbbd04 100644
90244--- a/mm/sparse.c
90245+++ b/mm/sparse.c
90246@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90247
90248 for (i = 0; i < PAGES_PER_SECTION; i++) {
90249 if (PageHWPoison(&memmap[i])) {
90250- atomic_long_sub(1, &num_poisoned_pages);
90251+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90252 ClearPageHWPoison(&memmap[i]);
90253 }
90254 }
90255diff --git a/mm/swap.c b/mm/swap.c
90256index c899502..d4dc2cd 100644
90257--- a/mm/swap.c
90258+++ b/mm/swap.c
90259@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
90260
90261 __page_cache_release(page);
90262 dtor = get_compound_page_dtor(page);
90263+ if (!PageHuge(page))
90264+ BUG_ON(dtor != free_compound_page);
90265 (*dtor)(page);
90266 }
90267
90268diff --git a/mm/swapfile.c b/mm/swapfile.c
90269index 6cf2e60..d204b3e 100644
90270--- a/mm/swapfile.c
90271+++ b/mm/swapfile.c
90272@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90273
90274 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90275 /* Activity counter to indicate that a swapon or swapoff has occurred */
90276-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90277+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90278
90279 static inline unsigned char swap_count(unsigned char ent)
90280 {
90281@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90282 }
90283 filp_close(swap_file, NULL);
90284 err = 0;
90285- atomic_inc(&proc_poll_event);
90286+ atomic_inc_unchecked(&proc_poll_event);
90287 wake_up_interruptible(&proc_poll_wait);
90288
90289 out_dput:
90290@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90291
90292 poll_wait(file, &proc_poll_wait, wait);
90293
90294- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90295- seq->poll_event = atomic_read(&proc_poll_event);
90296+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90297+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90298 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90299 }
90300
90301@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90302 return ret;
90303
90304 seq = file->private_data;
90305- seq->poll_event = atomic_read(&proc_poll_event);
90306+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90307 return 0;
90308 }
90309
90310@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90311 (frontswap_map) ? "FS" : "");
90312
90313 mutex_unlock(&swapon_mutex);
90314- atomic_inc(&proc_poll_event);
90315+ atomic_inc_unchecked(&proc_poll_event);
90316 wake_up_interruptible(&proc_poll_wait);
90317
90318 if (S_ISREG(inode->i_mode))
90319diff --git a/mm/util.c b/mm/util.c
90320index 7441c41..c3de793 100644
90321--- a/mm/util.c
90322+++ b/mm/util.c
90323@@ -294,6 +294,12 @@ done:
90324 void arch_pick_mmap_layout(struct mm_struct *mm)
90325 {
90326 mm->mmap_base = TASK_UNMAPPED_BASE;
90327+
90328+#ifdef CONFIG_PAX_RANDMMAP
90329+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90330+ mm->mmap_base += mm->delta_mmap;
90331+#endif
90332+
90333 mm->get_unmapped_area = arch_get_unmapped_area;
90334 }
90335 #endif
90336diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90337index 13a5495..6707d97 100644
90338--- a/mm/vmalloc.c
90339+++ b/mm/vmalloc.c
90340@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90341
90342 pte = pte_offset_kernel(pmd, addr);
90343 do {
90344- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90345- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90346+
90347+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90348+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90349+ BUG_ON(!pte_exec(*pte));
90350+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90351+ continue;
90352+ }
90353+#endif
90354+
90355+ {
90356+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90357+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90358+ }
90359 } while (pte++, addr += PAGE_SIZE, addr != end);
90360 }
90361
90362@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90363 pte = pte_alloc_kernel(pmd, addr);
90364 if (!pte)
90365 return -ENOMEM;
90366+
90367+ pax_open_kernel();
90368 do {
90369 struct page *page = pages[*nr];
90370
90371- if (WARN_ON(!pte_none(*pte)))
90372+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90373+ if (pgprot_val(prot) & _PAGE_NX)
90374+#endif
90375+
90376+ if (!pte_none(*pte)) {
90377+ pax_close_kernel();
90378+ WARN_ON(1);
90379 return -EBUSY;
90380- if (WARN_ON(!page))
90381+ }
90382+ if (!page) {
90383+ pax_close_kernel();
90384+ WARN_ON(1);
90385 return -ENOMEM;
90386+ }
90387 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90388 (*nr)++;
90389 } while (pte++, addr += PAGE_SIZE, addr != end);
90390+ pax_close_kernel();
90391 return 0;
90392 }
90393
90394@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90395 pmd_t *pmd;
90396 unsigned long next;
90397
90398- pmd = pmd_alloc(&init_mm, pud, addr);
90399+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90400 if (!pmd)
90401 return -ENOMEM;
90402 do {
90403@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90404 pud_t *pud;
90405 unsigned long next;
90406
90407- pud = pud_alloc(&init_mm, pgd, addr);
90408+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90409 if (!pud)
90410 return -ENOMEM;
90411 do {
90412@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90413 if (addr >= MODULES_VADDR && addr < MODULES_END)
90414 return 1;
90415 #endif
90416+
90417+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90418+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90419+ return 1;
90420+#endif
90421+
90422 return is_vmalloc_addr(x);
90423 }
90424
90425@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90426
90427 if (!pgd_none(*pgd)) {
90428 pud_t *pud = pud_offset(pgd, addr);
90429+#ifdef CONFIG_X86
90430+ if (!pud_large(*pud))
90431+#endif
90432 if (!pud_none(*pud)) {
90433 pmd_t *pmd = pmd_offset(pud, addr);
90434+#ifdef CONFIG_X86
90435+ if (!pmd_large(*pmd))
90436+#endif
90437 if (!pmd_none(*pmd)) {
90438 pte_t *ptep, pte;
90439
90440@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90441 * Allocate a region of KVA of the specified size and alignment, within the
90442 * vstart and vend.
90443 */
90444-static struct vmap_area *alloc_vmap_area(unsigned long size,
90445+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90446 unsigned long align,
90447 unsigned long vstart, unsigned long vend,
90448 int node, gfp_t gfp_mask)
90449@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90450 struct vm_struct *area;
90451
90452 BUG_ON(in_interrupt());
90453+
90454+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90455+ if (flags & VM_KERNEXEC) {
90456+ if (start != VMALLOC_START || end != VMALLOC_END)
90457+ return NULL;
90458+ start = (unsigned long)MODULES_EXEC_VADDR;
90459+ end = (unsigned long)MODULES_EXEC_END;
90460+ }
90461+#endif
90462+
90463 if (flags & VM_IOREMAP)
90464 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90465
90466@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90467 if (count > totalram_pages)
90468 return NULL;
90469
90470+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90471+ if (!(pgprot_val(prot) & _PAGE_NX))
90472+ flags |= VM_KERNEXEC;
90473+#endif
90474+
90475 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90476 __builtin_return_address(0));
90477 if (!area)
90478@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90479 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90480 goto fail;
90481
90482+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90483+ if (!(pgprot_val(prot) & _PAGE_NX))
90484+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90485+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90486+ else
90487+#endif
90488+
90489 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90490 start, end, node, gfp_mask, caller);
90491 if (!area)
90492@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90493 * For tight control over page level allocator and protection flags
90494 * use __vmalloc() instead.
90495 */
90496-
90497 void *vmalloc_exec(unsigned long size)
90498 {
90499- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90500+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90501 NUMA_NO_NODE, __builtin_return_address(0));
90502 }
90503
90504@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90505 {
90506 struct vm_struct *area;
90507
90508+ BUG_ON(vma->vm_mirror);
90509+
90510 size = PAGE_ALIGN(size);
90511
90512 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90513@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90514 v->addr, v->addr + v->size, v->size);
90515
90516 if (v->caller)
90517+#ifdef CONFIG_GRKERNSEC_HIDESYM
90518+ seq_printf(m, " %pK", v->caller);
90519+#else
90520 seq_printf(m, " %pS", v->caller);
90521+#endif
90522
90523 if (v->nr_pages)
90524 seq_printf(m, " pages=%d", v->nr_pages);
90525diff --git a/mm/vmstat.c b/mm/vmstat.c
90526index 20c2ef4..15e7ab7 100644
90527--- a/mm/vmstat.c
90528+++ b/mm/vmstat.c
90529@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90530 *
90531 * vm_stat contains the global counters
90532 */
90533-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90534+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90535 EXPORT_SYMBOL(vm_stat);
90536
90537 #ifdef CONFIG_SMP
90538@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90539 v = p->vm_stat_diff[i];
90540 p->vm_stat_diff[i] = 0;
90541 local_irq_restore(flags);
90542- atomic_long_add(v, &zone->vm_stat[i]);
90543+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90544 global_diff[i] += v;
90545 #ifdef CONFIG_NUMA
90546 /* 3 seconds idle till flush */
90547@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90548
90549 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90550 if (global_diff[i])
90551- atomic_long_add(global_diff[i], &vm_stat[i]);
90552+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90553 }
90554
90555 /*
90556@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90557 if (pset->vm_stat_diff[i]) {
90558 int v = pset->vm_stat_diff[i];
90559 pset->vm_stat_diff[i] = 0;
90560- atomic_long_add(v, &zone->vm_stat[i]);
90561- atomic_long_add(v, &vm_stat[i]);
90562+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90563+ atomic_long_add_unchecked(v, &vm_stat[i]);
90564 }
90565 }
90566 #endif
90567@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90568 start_cpu_timer(cpu);
90569 #endif
90570 #ifdef CONFIG_PROC_FS
90571- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90572- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90573- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90574- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90575+ {
90576+ mode_t gr_mode = S_IRUGO;
90577+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90578+ gr_mode = S_IRUSR;
90579+#endif
90580+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90581+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90582+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90583+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90584+#else
90585+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90586+#endif
90587+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90588+ }
90589 #endif
90590 return 0;
90591 }
90592diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90593index 2fb2d88..8c06e40 100644
90594--- a/net/8021q/vlan.c
90595+++ b/net/8021q/vlan.c
90596@@ -469,7 +469,7 @@ out:
90597 return NOTIFY_DONE;
90598 }
90599
90600-static struct notifier_block vlan_notifier_block __read_mostly = {
90601+static struct notifier_block vlan_notifier_block = {
90602 .notifier_call = vlan_device_event,
90603 };
90604
90605@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90606 err = -EPERM;
90607 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90608 break;
90609- if ((args.u.name_type >= 0) &&
90610- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90611+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90612 struct vlan_net *vn;
90613
90614 vn = net_generic(net, vlan_net_id);
90615diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
90616index 3091297..c7e634a 100644
90617--- a/net/8021q/vlan_netlink.c
90618+++ b/net/8021q/vlan_netlink.c
90619@@ -171,7 +171,7 @@ static size_t vlan_get_size(const struct net_device *dev)
90620
90621 return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */
90622 nla_total_size(2) + /* IFLA_VLAN_ID */
90623- sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */
90624+ nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
90625 vlan_qos_map_size(vlan->nr_ingress_mappings) +
90626 vlan_qos_map_size(vlan->nr_egress_mappings);
90627 }
90628diff --git a/net/9p/mod.c b/net/9p/mod.c
90629index 6ab36ae..6f1841b 100644
90630--- a/net/9p/mod.c
90631+++ b/net/9p/mod.c
90632@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90633 void v9fs_register_trans(struct p9_trans_module *m)
90634 {
90635 spin_lock(&v9fs_trans_lock);
90636- list_add_tail(&m->list, &v9fs_trans_list);
90637+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90638 spin_unlock(&v9fs_trans_lock);
90639 }
90640 EXPORT_SYMBOL(v9fs_register_trans);
90641@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90642 void v9fs_unregister_trans(struct p9_trans_module *m)
90643 {
90644 spin_lock(&v9fs_trans_lock);
90645- list_del_init(&m->list);
90646+ pax_list_del_init((struct list_head *)&m->list);
90647 spin_unlock(&v9fs_trans_lock);
90648 }
90649 EXPORT_SYMBOL(v9fs_unregister_trans);
90650diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90651index 3ffda1b..fceac96 100644
90652--- a/net/9p/trans_fd.c
90653+++ b/net/9p/trans_fd.c
90654@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90655 oldfs = get_fs();
90656 set_fs(get_ds());
90657 /* The cast to a user pointer is valid due to the set_fs() */
90658- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90659+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90660 set_fs(oldfs);
90661
90662 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90663diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90664index 876fbe8..8bbea9f 100644
90665--- a/net/atm/atm_misc.c
90666+++ b/net/atm/atm_misc.c
90667@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90668 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90669 return 1;
90670 atm_return(vcc, truesize);
90671- atomic_inc(&vcc->stats->rx_drop);
90672+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90673 return 0;
90674 }
90675 EXPORT_SYMBOL(atm_charge);
90676@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90677 }
90678 }
90679 atm_return(vcc, guess);
90680- atomic_inc(&vcc->stats->rx_drop);
90681+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90682 return NULL;
90683 }
90684 EXPORT_SYMBOL(atm_alloc_charge);
90685@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90686
90687 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90688 {
90689-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90690+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90691 __SONET_ITEMS
90692 #undef __HANDLE_ITEM
90693 }
90694@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90695
90696 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90697 {
90698-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90699+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90700 __SONET_ITEMS
90701 #undef __HANDLE_ITEM
90702 }
90703diff --git a/net/atm/lec.h b/net/atm/lec.h
90704index 4149db1..f2ab682 100644
90705--- a/net/atm/lec.h
90706+++ b/net/atm/lec.h
90707@@ -48,7 +48,7 @@ struct lane2_ops {
90708 const u8 *tlvs, u32 sizeoftlvs);
90709 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90710 const u8 *tlvs, u32 sizeoftlvs);
90711-};
90712+} __no_const;
90713
90714 /*
90715 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90716diff --git a/net/atm/proc.c b/net/atm/proc.c
90717index bbb6461..cf04016 100644
90718--- a/net/atm/proc.c
90719+++ b/net/atm/proc.c
90720@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90721 const struct k_atm_aal_stats *stats)
90722 {
90723 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90724- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90725- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90726- atomic_read(&stats->rx_drop));
90727+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90728+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90729+ atomic_read_unchecked(&stats->rx_drop));
90730 }
90731
90732 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90733diff --git a/net/atm/resources.c b/net/atm/resources.c
90734index 0447d5d..3cf4728 100644
90735--- a/net/atm/resources.c
90736+++ b/net/atm/resources.c
90737@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90738 static void copy_aal_stats(struct k_atm_aal_stats *from,
90739 struct atm_aal_stats *to)
90740 {
90741-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90742+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90743 __AAL_STAT_ITEMS
90744 #undef __HANDLE_ITEM
90745 }
90746@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90747 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90748 struct atm_aal_stats *to)
90749 {
90750-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90751+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90752 __AAL_STAT_ITEMS
90753 #undef __HANDLE_ITEM
90754 }
90755diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90756index 919a5ce..cc6b444 100644
90757--- a/net/ax25/sysctl_net_ax25.c
90758+++ b/net/ax25/sysctl_net_ax25.c
90759@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90760 {
90761 char path[sizeof("net/ax25/") + IFNAMSIZ];
90762 int k;
90763- struct ctl_table *table;
90764+ ctl_table_no_const *table;
90765
90766 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90767 if (!table)
90768diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90769index 62da527..aa27535 100644
90770--- a/net/batman-adv/bat_iv_ogm.c
90771+++ b/net/batman-adv/bat_iv_ogm.c
90772@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90773
90774 /* randomize initial seqno to avoid collision */
90775 get_random_bytes(&random_seqno, sizeof(random_seqno));
90776- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90777+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90778
90779 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90780 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90781@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90782 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90783
90784 /* change sequence number to network order */
90785- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90786+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90787 batadv_ogm_packet->seqno = htonl(seqno);
90788- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90789+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90790
90791 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90792 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90793@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90794 return;
90795
90796 /* could be changed by schedule_own_packet() */
90797- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90798+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90799
90800 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90801 has_directlink_flag = 1;
90802diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90803index c478e6b..469fd2f 100644
90804--- a/net/batman-adv/hard-interface.c
90805+++ b/net/batman-adv/hard-interface.c
90806@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90807 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90808 dev_add_pack(&hard_iface->batman_adv_ptype);
90809
90810- atomic_set(&hard_iface->frag_seqno, 1);
90811+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90812 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90813 hard_iface->net_dev->name);
90814
90815diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90816index 33b6144..3212ac5 100644
90817--- a/net/batman-adv/soft-interface.c
90818+++ b/net/batman-adv/soft-interface.c
90819@@ -261,7 +261,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90820 primary_if->net_dev->dev_addr, ETH_ALEN);
90821
90822 /* set broadcast sequence number */
90823- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90824+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90825 bcast_packet->seqno = htonl(seqno);
90826
90827 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90828@@ -481,7 +481,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90829 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90830
90831 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90832- atomic_set(&bat_priv->bcast_seqno, 1);
90833+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90834 atomic_set(&bat_priv->tt.vn, 0);
90835 atomic_set(&bat_priv->tt.local_changes, 0);
90836 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90837diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90838index b2c94e1..3d47e07 100644
90839--- a/net/batman-adv/types.h
90840+++ b/net/batman-adv/types.h
90841@@ -51,7 +51,7 @@
90842 struct batadv_hard_iface_bat_iv {
90843 unsigned char *ogm_buff;
90844 int ogm_buff_len;
90845- atomic_t ogm_seqno;
90846+ atomic_unchecked_t ogm_seqno;
90847 };
90848
90849 /**
90850@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90851 int16_t if_num;
90852 char if_status;
90853 struct net_device *net_dev;
90854- atomic_t frag_seqno;
90855+ atomic_unchecked_t frag_seqno;
90856 uint8_t num_bcasts;
90857 struct kobject *hardif_obj;
90858 atomic_t refcount;
90859@@ -560,7 +560,7 @@ struct batadv_priv {
90860 #ifdef CONFIG_BATMAN_ADV_DEBUG
90861 atomic_t log_level;
90862 #endif
90863- atomic_t bcast_seqno;
90864+ atomic_unchecked_t bcast_seqno;
90865 atomic_t bcast_queue_left;
90866 atomic_t batman_queue_left;
90867 char num_ifaces;
90868diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90869index 857e1b8..5ad07b2 100644
90870--- a/net/batman-adv/unicast.c
90871+++ b/net/batman-adv/unicast.c
90872@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90873 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90874 frag2->flags = large_tail;
90875
90876- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90877+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90878 frag1->seqno = htons(seqno - 1);
90879 frag2->seqno = htons(seqno);
90880
90881diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90882index 9bd7d95..6c4884f 100644
90883--- a/net/bluetooth/hci_sock.c
90884+++ b/net/bluetooth/hci_sock.c
90885@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90886 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90887 }
90888
90889- len = min_t(unsigned int, len, sizeof(uf));
90890+ len = min((size_t)len, sizeof(uf));
90891 if (copy_from_user(&uf, optval, len)) {
90892 err = -EFAULT;
90893 break;
90894diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90895index 8c3499b..2661c6a 100644
90896--- a/net/bluetooth/l2cap_core.c
90897+++ b/net/bluetooth/l2cap_core.c
90898@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90899 break;
90900
90901 case L2CAP_CONF_RFC:
90902- if (olen == sizeof(rfc))
90903- memcpy(&rfc, (void *)val, olen);
90904+ if (olen != sizeof(rfc))
90905+ break;
90906+
90907+ memcpy(&rfc, (void *)val, olen);
90908
90909 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90910 rfc.mode != chan->mode)
90911diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90912index 0098af8..fb5a31f 100644
90913--- a/net/bluetooth/l2cap_sock.c
90914+++ b/net/bluetooth/l2cap_sock.c
90915@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90916 struct sock *sk = sock->sk;
90917 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90918 struct l2cap_options opts;
90919- int len, err = 0;
90920+ int err = 0;
90921+ size_t len = optlen;
90922 u32 opt;
90923
90924 BT_DBG("sk %p", sk);
90925@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90926 opts.max_tx = chan->max_tx;
90927 opts.txwin_size = chan->tx_win;
90928
90929- len = min_t(unsigned int, sizeof(opts), optlen);
90930+ len = min(sizeof(opts), len);
90931 if (copy_from_user((char *) &opts, optval, len)) {
90932 err = -EFAULT;
90933 break;
90934@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90935 struct bt_security sec;
90936 struct bt_power pwr;
90937 struct l2cap_conn *conn;
90938- int len, err = 0;
90939+ int err = 0;
90940+ size_t len = optlen;
90941 u32 opt;
90942
90943 BT_DBG("sk %p", sk);
90944@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90945
90946 sec.level = BT_SECURITY_LOW;
90947
90948- len = min_t(unsigned int, sizeof(sec), optlen);
90949+ len = min(sizeof(sec), len);
90950 if (copy_from_user((char *) &sec, optval, len)) {
90951 err = -EFAULT;
90952 break;
90953@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90954
90955 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90956
90957- len = min_t(unsigned int, sizeof(pwr), optlen);
90958+ len = min(sizeof(pwr), len);
90959 if (copy_from_user((char *) &pwr, optval, len)) {
90960 err = -EFAULT;
90961 break;
90962diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90963index 30b3721..c1bd0a0 100644
90964--- a/net/bluetooth/rfcomm/sock.c
90965+++ b/net/bluetooth/rfcomm/sock.c
90966@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90967 struct sock *sk = sock->sk;
90968 struct bt_security sec;
90969 int err = 0;
90970- size_t len;
90971+ size_t len = optlen;
90972 u32 opt;
90973
90974 BT_DBG("sk %p", sk);
90975@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90976
90977 sec.level = BT_SECURITY_LOW;
90978
90979- len = min_t(unsigned int, sizeof(sec), optlen);
90980+ len = min(sizeof(sec), len);
90981 if (copy_from_user((char *) &sec, optval, len)) {
90982 err = -EFAULT;
90983 break;
90984diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
90985index b6e44ad..5b0d514 100644
90986--- a/net/bluetooth/rfcomm/tty.c
90987+++ b/net/bluetooth/rfcomm/tty.c
90988@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
90989 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
90990
90991 spin_lock_irqsave(&dev->port.lock, flags);
90992- if (dev->port.count > 0) {
90993+ if (atomic_read(&dev->port.count) > 0) {
90994 spin_unlock_irqrestore(&dev->port.lock, flags);
90995 return;
90996 }
90997@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
90998 return -ENODEV;
90999
91000 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91001- dev->channel, dev->port.count);
91002+ dev->channel, atomic_read(&dev->port.count));
91003
91004 spin_lock_irqsave(&dev->port.lock, flags);
91005- if (++dev->port.count > 1) {
91006+ if (atomic_inc_return(&dev->port.count) > 1) {
91007 spin_unlock_irqrestore(&dev->port.lock, flags);
91008 return 0;
91009 }
91010@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91011 return;
91012
91013 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91014- dev->port.count);
91015+ atomic_read(&dev->port.count));
91016
91017 spin_lock_irqsave(&dev->port.lock, flags);
91018- if (!--dev->port.count) {
91019+ if (!atomic_dec_return(&dev->port.count)) {
91020 spin_unlock_irqrestore(&dev->port.lock, flags);
91021 if (dev->tty_dev->parent)
91022 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91023diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
91024index 5180938..7c470c3 100644
91025--- a/net/bridge/netfilter/ebt_ulog.c
91026+++ b/net/bridge/netfilter/ebt_ulog.c
91027@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91028 ub->qlen++;
91029
91030 pm = nlmsg_data(nlh);
91031+ memset(pm, 0, sizeof(*pm));
91032
91033 /* Fill in the ulog data */
91034 pm->version = EBT_ULOG_VERSION;
91035@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91036 pm->hook = hooknr;
91037 if (uloginfo->prefix != NULL)
91038 strcpy(pm->prefix, uloginfo->prefix);
91039- else
91040- *(pm->prefix) = '\0';
91041
91042 if (in) {
91043 strcpy(pm->physindev, in->name);
91044@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
91045 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
91046 else
91047 strcpy(pm->indev, in->name);
91048- } else
91049- pm->indev[0] = pm->physindev[0] = '\0';
91050+ }
91051
91052 if (out) {
91053 /* If out exists, then out is a bridge port */
91054 strcpy(pm->physoutdev, out->name);
91055 /* rcu_read_lock()ed by nf_hook_slow */
91056 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
91057- } else
91058- pm->outdev[0] = pm->physoutdev[0] = '\0';
91059+ }
91060
91061 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
91062 BUG();
91063diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91064index ac78024..161a80c 100644
91065--- a/net/bridge/netfilter/ebtables.c
91066+++ b/net/bridge/netfilter/ebtables.c
91067@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91068 tmp.valid_hooks = t->table->valid_hooks;
91069 }
91070 mutex_unlock(&ebt_mutex);
91071- if (copy_to_user(user, &tmp, *len) != 0){
91072+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91073 BUGPRINT("c2u Didn't work\n");
91074 ret = -EFAULT;
91075 break;
91076@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91077 goto out;
91078 tmp.valid_hooks = t->valid_hooks;
91079
91080- if (copy_to_user(user, &tmp, *len) != 0) {
91081+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91082 ret = -EFAULT;
91083 break;
91084 }
91085@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91086 tmp.entries_size = t->table->entries_size;
91087 tmp.valid_hooks = t->table->valid_hooks;
91088
91089- if (copy_to_user(user, &tmp, *len) != 0) {
91090+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91091 ret = -EFAULT;
91092 break;
91093 }
91094diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91095index 0f45522..dab651f 100644
91096--- a/net/caif/cfctrl.c
91097+++ b/net/caif/cfctrl.c
91098@@ -10,6 +10,7 @@
91099 #include <linux/spinlock.h>
91100 #include <linux/slab.h>
91101 #include <linux/pkt_sched.h>
91102+#include <linux/sched.h>
91103 #include <net/caif/caif_layer.h>
91104 #include <net/caif/cfpkt.h>
91105 #include <net/caif/cfctrl.h>
91106@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91107 memset(&dev_info, 0, sizeof(dev_info));
91108 dev_info.id = 0xff;
91109 cfsrvl_init(&this->serv, 0, &dev_info, false);
91110- atomic_set(&this->req_seq_no, 1);
91111- atomic_set(&this->rsp_seq_no, 1);
91112+ atomic_set_unchecked(&this->req_seq_no, 1);
91113+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91114 this->serv.layer.receive = cfctrl_recv;
91115 sprintf(this->serv.layer.name, "ctrl");
91116 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91117@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91118 struct cfctrl_request_info *req)
91119 {
91120 spin_lock_bh(&ctrl->info_list_lock);
91121- atomic_inc(&ctrl->req_seq_no);
91122- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91123+ atomic_inc_unchecked(&ctrl->req_seq_no);
91124+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91125 list_add_tail(&req->list, &ctrl->list);
91126 spin_unlock_bh(&ctrl->info_list_lock);
91127 }
91128@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91129 if (p != first)
91130 pr_warn("Requests are not received in order\n");
91131
91132- atomic_set(&ctrl->rsp_seq_no,
91133+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91134 p->sequence_no);
91135 list_del(&p->list);
91136 goto out;
91137diff --git a/net/can/af_can.c b/net/can/af_can.c
91138index 3ab8dd2..b9aef13 100644
91139--- a/net/can/af_can.c
91140+++ b/net/can/af_can.c
91141@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91142 };
91143
91144 /* notifier block for netdevice event */
91145-static struct notifier_block can_netdev_notifier __read_mostly = {
91146+static struct notifier_block can_netdev_notifier = {
91147 .notifier_call = can_notifier,
91148 };
91149
91150diff --git a/net/can/gw.c b/net/can/gw.c
91151index 2f291f9..98c986a 100644
91152--- a/net/can/gw.c
91153+++ b/net/can/gw.c
91154@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91155 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91156
91157 static HLIST_HEAD(cgw_list);
91158-static struct notifier_block notifier;
91159
91160 static struct kmem_cache *cgw_cache __read_mostly;
91161
91162@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91163 return err;
91164 }
91165
91166+static struct notifier_block notifier = {
91167+ .notifier_call = cgw_notifier
91168+};
91169+
91170 static __init int cgw_module_init(void)
91171 {
91172 /* sanitize given module parameter */
91173@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91174 return -ENOMEM;
91175
91176 /* set notifier */
91177- notifier.notifier_call = cgw_notifier;
91178 register_netdevice_notifier(&notifier);
91179
91180 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91181diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91182index eb0a46a..5f3bae8 100644
91183--- a/net/ceph/messenger.c
91184+++ b/net/ceph/messenger.c
91185@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91186 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91187
91188 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91189-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91190+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91191
91192 static struct page *zero_page; /* used in certain error cases */
91193
91194@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91195 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91196 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91197
91198- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91199+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91200 s = addr_str[i];
91201
91202 switch (ss->ss_family) {
91203diff --git a/net/compat.c b/net/compat.c
91204index f0a1ba6..24e30e5 100644
91205--- a/net/compat.c
91206+++ b/net/compat.c
91207@@ -71,9 +71,11 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91208 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91209 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91210 return -EFAULT;
91211- kmsg->msg_name = compat_ptr(tmp1);
91212- kmsg->msg_iov = compat_ptr(tmp2);
91213- kmsg->msg_control = compat_ptr(tmp3);
91214+ if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
91215+ return -EINVAL;
91216+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91217+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91218+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91219 return 0;
91220 }
91221
91222@@ -85,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91223
91224 if (kern_msg->msg_namelen) {
91225 if (mode == VERIFY_READ) {
91226- int err = move_addr_to_kernel(kern_msg->msg_name,
91227+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91228 kern_msg->msg_namelen,
91229 kern_address);
91230 if (err < 0)
91231@@ -96,7 +98,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91232 kern_msg->msg_name = NULL;
91233
91234 tot_len = iov_from_user_compat_to_kern(kern_iov,
91235- (struct compat_iovec __user *)kern_msg->msg_iov,
91236+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91237 kern_msg->msg_iovlen);
91238 if (tot_len >= 0)
91239 kern_msg->msg_iov = kern_iov;
91240@@ -116,20 +118,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91241
91242 #define CMSG_COMPAT_FIRSTHDR(msg) \
91243 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91244- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91245+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91246 (struct compat_cmsghdr __user *)NULL)
91247
91248 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91249 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91250 (ucmlen) <= (unsigned long) \
91251 ((mhdr)->msg_controllen - \
91252- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91253+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91254
91255 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91256 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91257 {
91258 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91259- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91260+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91261 msg->msg_controllen)
91262 return NULL;
91263 return (struct compat_cmsghdr __user *)ptr;
91264@@ -219,7 +221,7 @@ Efault:
91265
91266 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91267 {
91268- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91269+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91270 struct compat_cmsghdr cmhdr;
91271 struct compat_timeval ctv;
91272 struct compat_timespec cts[3];
91273@@ -275,7 +277,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91274
91275 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91276 {
91277- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91278+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91279 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91280 int fdnum = scm->fp->count;
91281 struct file **fp = scm->fp->fp;
91282@@ -363,7 +365,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91283 return -EFAULT;
91284 old_fs = get_fs();
91285 set_fs(KERNEL_DS);
91286- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91287+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91288 set_fs(old_fs);
91289
91290 return err;
91291@@ -424,7 +426,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91292 len = sizeof(ktime);
91293 old_fs = get_fs();
91294 set_fs(KERNEL_DS);
91295- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91296+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91297 set_fs(old_fs);
91298
91299 if (!err) {
91300@@ -567,7 +569,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91301 case MCAST_JOIN_GROUP:
91302 case MCAST_LEAVE_GROUP:
91303 {
91304- struct compat_group_req __user *gr32 = (void *)optval;
91305+ struct compat_group_req __user *gr32 = (void __user *)optval;
91306 struct group_req __user *kgr =
91307 compat_alloc_user_space(sizeof(struct group_req));
91308 u32 interface;
91309@@ -588,7 +590,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91310 case MCAST_BLOCK_SOURCE:
91311 case MCAST_UNBLOCK_SOURCE:
91312 {
91313- struct compat_group_source_req __user *gsr32 = (void *)optval;
91314+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91315 struct group_source_req __user *kgsr = compat_alloc_user_space(
91316 sizeof(struct group_source_req));
91317 u32 interface;
91318@@ -609,7 +611,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91319 }
91320 case MCAST_MSFILTER:
91321 {
91322- struct compat_group_filter __user *gf32 = (void *)optval;
91323+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91324 struct group_filter __user *kgf;
91325 u32 interface, fmode, numsrc;
91326
91327@@ -647,7 +649,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91328 char __user *optval, int __user *optlen,
91329 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91330 {
91331- struct compat_group_filter __user *gf32 = (void *)optval;
91332+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91333 struct group_filter __user *kgf;
91334 int __user *koptlen;
91335 u32 interface, fmode, numsrc;
91336@@ -805,7 +807,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91337
91338 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91339 return -EINVAL;
91340- if (copy_from_user(a, args, nas[call]))
91341+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91342 return -EFAULT;
91343 a0 = a[0];
91344 a1 = a[1];
91345diff --git a/net/core/datagram.c b/net/core/datagram.c
91346index 8ab48cd..57b1a80 100644
91347--- a/net/core/datagram.c
91348+++ b/net/core/datagram.c
91349@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91350 }
91351
91352 kfree_skb(skb);
91353- atomic_inc(&sk->sk_drops);
91354+ atomic_inc_unchecked(&sk->sk_drops);
91355 sk_mem_reclaim_partial(sk);
91356
91357 return err;
91358diff --git a/net/core/dev.c b/net/core/dev.c
91359index 26755dd..2a232de 100644
91360--- a/net/core/dev.c
91361+++ b/net/core/dev.c
91362@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91363 {
91364 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91365 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91366- atomic_long_inc(&dev->rx_dropped);
91367+ atomic_long_inc_unchecked(&dev->rx_dropped);
91368 kfree_skb(skb);
91369 return NET_RX_DROP;
91370 }
91371 }
91372
91373 if (unlikely(!is_skb_forwardable(dev, skb))) {
91374- atomic_long_inc(&dev->rx_dropped);
91375+ atomic_long_inc_unchecked(&dev->rx_dropped);
91376 kfree_skb(skb);
91377 return NET_RX_DROP;
91378 }
91379@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91380
91381 struct dev_gso_cb {
91382 void (*destructor)(struct sk_buff *skb);
91383-};
91384+} __no_const;
91385
91386 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91387
91388@@ -3206,7 +3206,7 @@ enqueue:
91389
91390 local_irq_restore(flags);
91391
91392- atomic_long_inc(&skb->dev->rx_dropped);
91393+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91394 kfree_skb(skb);
91395 return NET_RX_DROP;
91396 }
91397@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91398 }
91399 EXPORT_SYMBOL(netif_rx_ni);
91400
91401-static void net_tx_action(struct softirq_action *h)
91402+static __latent_entropy void net_tx_action(void)
91403 {
91404 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91405
91406@@ -3612,7 +3612,7 @@ ncls:
91407 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91408 } else {
91409 drop:
91410- atomic_long_inc(&skb->dev->rx_dropped);
91411+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91412 kfree_skb(skb);
91413 /* Jamal, now you will not able to escape explaining
91414 * me how you were going to use this. :-)
91415@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91416 }
91417 EXPORT_SYMBOL(netif_napi_del);
91418
91419-static void net_rx_action(struct softirq_action *h)
91420+static __latent_entropy void net_rx_action(void)
91421 {
91422 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91423 unsigned long time_limit = jiffies + 2;
91424@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91425 } else {
91426 netdev_stats_to_stats64(storage, &dev->stats);
91427 }
91428- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91429+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91430 return storage;
91431 }
91432 EXPORT_SYMBOL(dev_get_stats);
91433diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91434index 5b7d0e1..cb960fc 100644
91435--- a/net/core/dev_ioctl.c
91436+++ b/net/core/dev_ioctl.c
91437@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91438 if (no_module && capable(CAP_NET_ADMIN))
91439 no_module = request_module("netdev-%s", name);
91440 if (no_module && capable(CAP_SYS_MODULE)) {
91441+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91442+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91443+#else
91444 if (!request_module("%s", name))
91445 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91446 name);
91447+#endif
91448 }
91449 }
91450 EXPORT_SYMBOL(dev_load);
91451diff --git a/net/core/flow.c b/net/core/flow.c
91452index dfa602c..3103d88 100644
91453--- a/net/core/flow.c
91454+++ b/net/core/flow.c
91455@@ -61,7 +61,7 @@ struct flow_cache {
91456 struct timer_list rnd_timer;
91457 };
91458
91459-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91460+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91461 EXPORT_SYMBOL(flow_cache_genid);
91462 static struct flow_cache flow_cache_global;
91463 static struct kmem_cache *flow_cachep __read_mostly;
91464@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91465
91466 static int flow_entry_valid(struct flow_cache_entry *fle)
91467 {
91468- if (atomic_read(&flow_cache_genid) != fle->genid)
91469+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91470 return 0;
91471 if (fle->object && !fle->object->ops->check(fle->object))
91472 return 0;
91473@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91474 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91475 fcp->hash_count++;
91476 }
91477- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91478+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91479 flo = fle->object;
91480 if (!flo)
91481 goto ret_object;
91482@@ -279,7 +279,7 @@ nocache:
91483 }
91484 flo = resolver(net, key, family, dir, flo, ctx);
91485 if (fle) {
91486- fle->genid = atomic_read(&flow_cache_genid);
91487+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91488 if (!IS_ERR(flo))
91489 fle->object = flo;
91490 else
91491diff --git a/net/core/iovec.c b/net/core/iovec.c
91492index de178e4..1dabd8b 100644
91493--- a/net/core/iovec.c
91494+++ b/net/core/iovec.c
91495@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91496 if (m->msg_namelen) {
91497 if (mode == VERIFY_READ) {
91498 void __user *namep;
91499- namep = (void __user __force *) m->msg_name;
91500+ namep = (void __force_user *) m->msg_name;
91501 err = move_addr_to_kernel(namep, m->msg_namelen,
91502 address);
91503 if (err < 0)
91504@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91505 }
91506
91507 size = m->msg_iovlen * sizeof(struct iovec);
91508- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91509+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91510 return -EFAULT;
91511
91512 m->msg_iov = iov;
91513diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91514index 60533db..14842cc 100644
91515--- a/net/core/neighbour.c
91516+++ b/net/core/neighbour.c
91517@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91518 void __user *buffer, size_t *lenp, loff_t *ppos)
91519 {
91520 int size, ret;
91521- struct ctl_table tmp = *ctl;
91522+ ctl_table_no_const tmp = *ctl;
91523
91524 tmp.extra1 = &zero;
91525 tmp.extra2 = &unres_qlen_max;
91526diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91527index 2bf8329..7960607 100644
91528--- a/net/core/net-procfs.c
91529+++ b/net/core/net-procfs.c
91530@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91531 else
91532 seq_printf(seq, "%04x", ntohs(pt->type));
91533
91534+#ifdef CONFIG_GRKERNSEC_HIDESYM
91535+ seq_printf(seq, " %-8s %pf\n",
91536+ pt->dev ? pt->dev->name : "", NULL);
91537+#else
91538 seq_printf(seq, " %-8s %pf\n",
91539 pt->dev ? pt->dev->name : "", pt->func);
91540+#endif
91541 }
91542
91543 return 0;
91544diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91545index 981fed3..536af34 100644
91546--- a/net/core/net-sysfs.c
91547+++ b/net/core/net-sysfs.c
91548@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91549 }
91550 EXPORT_SYMBOL(netdev_class_remove_file);
91551
91552-int netdev_kobject_init(void)
91553+int __init netdev_kobject_init(void)
91554 {
91555 kobj_ns_type_register(&net_ns_type_operations);
91556 return class_register(&net_class);
91557diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91558index f9765203..9feaef8 100644
91559--- a/net/core/net_namespace.c
91560+++ b/net/core/net_namespace.c
91561@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91562 int error;
91563 LIST_HEAD(net_exit_list);
91564
91565- list_add_tail(&ops->list, list);
91566+ pax_list_add_tail((struct list_head *)&ops->list, list);
91567 if (ops->init || (ops->id && ops->size)) {
91568 for_each_net(net) {
91569 error = ops_init(ops, net);
91570@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91571
91572 out_undo:
91573 /* If I have an error cleanup all namespaces I initialized */
91574- list_del(&ops->list);
91575+ pax_list_del((struct list_head *)&ops->list);
91576 ops_exit_list(ops, &net_exit_list);
91577 ops_free_list(ops, &net_exit_list);
91578 return error;
91579@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91580 struct net *net;
91581 LIST_HEAD(net_exit_list);
91582
91583- list_del(&ops->list);
91584+ pax_list_del((struct list_head *)&ops->list);
91585 for_each_net(net)
91586 list_add_tail(&net->exit_list, &net_exit_list);
91587 ops_exit_list(ops, &net_exit_list);
91588@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91589 mutex_lock(&net_mutex);
91590 error = register_pernet_operations(&pernet_list, ops);
91591 if (!error && (first_device == &pernet_list))
91592- first_device = &ops->list;
91593+ first_device = (struct list_head *)&ops->list;
91594 mutex_unlock(&net_mutex);
91595 return error;
91596 }
91597diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91598index fc75c9e..8c8e9be 100644
91599--- a/net/core/netpoll.c
91600+++ b/net/core/netpoll.c
91601@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91602 struct udphdr *udph;
91603 struct iphdr *iph;
91604 struct ethhdr *eth;
91605- static atomic_t ip_ident;
91606+ static atomic_unchecked_t ip_ident;
91607 struct ipv6hdr *ip6h;
91608
91609 udp_len = len + sizeof(*udph);
91610@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91611 put_unaligned(0x45, (unsigned char *)iph);
91612 iph->tos = 0;
91613 put_unaligned(htons(ip_len), &(iph->tot_len));
91614- iph->id = htons(atomic_inc_return(&ip_ident));
91615+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91616 iph->frag_off = 0;
91617 iph->ttl = 64;
91618 iph->protocol = IPPROTO_UDP;
91619diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91620index ca198c1d1..125372f 100644
91621--- a/net/core/rtnetlink.c
91622+++ b/net/core/rtnetlink.c
91623@@ -58,7 +58,7 @@ struct rtnl_link {
91624 rtnl_doit_func doit;
91625 rtnl_dumpit_func dumpit;
91626 rtnl_calcit_func calcit;
91627-};
91628+} __no_const;
91629
91630 static DEFINE_MUTEX(rtnl_mutex);
91631
91632@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91633 if (rtnl_link_ops_get(ops->kind))
91634 return -EEXIST;
91635
91636- if (!ops->dellink)
91637- ops->dellink = unregister_netdevice_queue;
91638+ if (!ops->dellink) {
91639+ pax_open_kernel();
91640+ *(void **)&ops->dellink = unregister_netdevice_queue;
91641+ pax_close_kernel();
91642+ }
91643
91644- list_add_tail(&ops->list, &link_ops);
91645+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91646 return 0;
91647 }
91648 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91649@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91650 for_each_net(net) {
91651 __rtnl_kill_links(net, ops);
91652 }
91653- list_del(&ops->list);
91654+ pax_list_del((struct list_head *)&ops->list);
91655 }
91656 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91657
91658diff --git a/net/core/scm.c b/net/core/scm.c
91659index b4da80b..98d6bdb 100644
91660--- a/net/core/scm.c
91661+++ b/net/core/scm.c
91662@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91663 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91664 {
91665 struct cmsghdr __user *cm
91666- = (__force struct cmsghdr __user *)msg->msg_control;
91667+ = (struct cmsghdr __force_user *)msg->msg_control;
91668 struct cmsghdr cmhdr;
91669 int cmlen = CMSG_LEN(len);
91670 int err;
91671@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91672 err = -EFAULT;
91673 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91674 goto out;
91675- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91676+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91677 goto out;
91678 cmlen = CMSG_SPACE(len);
91679 if (msg->msg_controllen < cmlen)
91680@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91681 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91682 {
91683 struct cmsghdr __user *cm
91684- = (__force struct cmsghdr __user*)msg->msg_control;
91685+ = (struct cmsghdr __force_user *)msg->msg_control;
91686
91687 int fdmax = 0;
91688 int fdnum = scm->fp->count;
91689@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91690 if (fdnum < fdmax)
91691 fdmax = fdnum;
91692
91693- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91694+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91695 i++, cmfptr++)
91696 {
91697 struct socket *sock;
91698diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91699index 2c3d0f5..f5a326f 100644
91700--- a/net/core/skbuff.c
91701+++ b/net/core/skbuff.c
91702@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91703 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91704 sizeof(struct sk_buff),
91705 0,
91706- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91707+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91708+ SLAB_NO_SANITIZE,
91709 NULL);
91710 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91711 (2*sizeof(struct sk_buff)) +
91712 sizeof(atomic_t),
91713 0,
91714- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91715+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91716+ SLAB_NO_SANITIZE,
91717 NULL);
91718 }
91719
91720diff --git a/net/core/sock.c b/net/core/sock.c
91721index 2c097c5..bf72858 100644
91722--- a/net/core/sock.c
91723+++ b/net/core/sock.c
91724@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91725 struct sk_buff_head *list = &sk->sk_receive_queue;
91726
91727 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91728- atomic_inc(&sk->sk_drops);
91729+ atomic_inc_unchecked(&sk->sk_drops);
91730 trace_sock_rcvqueue_full(sk, skb);
91731 return -ENOMEM;
91732 }
91733@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91734 return err;
91735
91736 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91737- atomic_inc(&sk->sk_drops);
91738+ atomic_inc_unchecked(&sk->sk_drops);
91739 return -ENOBUFS;
91740 }
91741
91742@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91743 skb_dst_force(skb);
91744
91745 spin_lock_irqsave(&list->lock, flags);
91746- skb->dropcount = atomic_read(&sk->sk_drops);
91747+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91748 __skb_queue_tail(list, skb);
91749 spin_unlock_irqrestore(&list->lock, flags);
91750
91751@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91752 skb->dev = NULL;
91753
91754 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91755- atomic_inc(&sk->sk_drops);
91756+ atomic_inc_unchecked(&sk->sk_drops);
91757 goto discard_and_relse;
91758 }
91759 if (nested)
91760@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91761 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91762 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91763 bh_unlock_sock(sk);
91764- atomic_inc(&sk->sk_drops);
91765+ atomic_inc_unchecked(&sk->sk_drops);
91766 goto discard_and_relse;
91767 }
91768
91769@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91770 struct timeval tm;
91771 } v;
91772
91773- int lv = sizeof(int);
91774- int len;
91775+ unsigned int lv = sizeof(int);
91776+ unsigned int len;
91777
91778 if (get_user(len, optlen))
91779 return -EFAULT;
91780- if (len < 0)
91781+ if (len > INT_MAX)
91782 return -EINVAL;
91783
91784 memset(&v, 0, sizeof(v));
91785@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91786
91787 case SO_PEERNAME:
91788 {
91789- char address[128];
91790+ char address[_K_SS_MAXSIZE];
91791
91792 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91793 return -ENOTCONN;
91794- if (lv < len)
91795+ if (lv < len || sizeof address < len)
91796 return -EINVAL;
91797 if (copy_to_user(optval, address, len))
91798 return -EFAULT;
91799@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91800
91801 if (len > lv)
91802 len = lv;
91803- if (copy_to_user(optval, &v, len))
91804+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91805 return -EFAULT;
91806 lenout:
91807 if (put_user(len, optlen))
91808@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91809 */
91810 smp_wmb();
91811 atomic_set(&sk->sk_refcnt, 1);
91812- atomic_set(&sk->sk_drops, 0);
91813+ atomic_set_unchecked(&sk->sk_drops, 0);
91814 }
91815 EXPORT_SYMBOL(sock_init_data);
91816
91817diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91818index a0e9cf6..ef7f9ed 100644
91819--- a/net/core/sock_diag.c
91820+++ b/net/core/sock_diag.c
91821@@ -9,26 +9,33 @@
91822 #include <linux/inet_diag.h>
91823 #include <linux/sock_diag.h>
91824
91825-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91826+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91827 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91828 static DEFINE_MUTEX(sock_diag_table_mutex);
91829
91830 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91831 {
91832+#ifndef CONFIG_GRKERNSEC_HIDESYM
91833 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91834 cookie[1] != INET_DIAG_NOCOOKIE) &&
91835 ((u32)(unsigned long)sk != cookie[0] ||
91836 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91837 return -ESTALE;
91838 else
91839+#endif
91840 return 0;
91841 }
91842 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91843
91844 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91845 {
91846+#ifdef CONFIG_GRKERNSEC_HIDESYM
91847+ cookie[0] = 0;
91848+ cookie[1] = 0;
91849+#else
91850 cookie[0] = (u32)(unsigned long)sk;
91851 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91852+#endif
91853 }
91854 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91855
91856@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91857 mutex_lock(&sock_diag_table_mutex);
91858 if (sock_diag_handlers[hndl->family])
91859 err = -EBUSY;
91860- else
91861+ else {
91862+ pax_open_kernel();
91863 sock_diag_handlers[hndl->family] = hndl;
91864+ pax_close_kernel();
91865+ }
91866 mutex_unlock(&sock_diag_table_mutex);
91867
91868 return err;
91869@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91870
91871 mutex_lock(&sock_diag_table_mutex);
91872 BUG_ON(sock_diag_handlers[family] != hnld);
91873+ pax_open_kernel();
91874 sock_diag_handlers[family] = NULL;
91875+ pax_close_kernel();
91876 mutex_unlock(&sock_diag_table_mutex);
91877 }
91878 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91879diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91880index 31107ab..ae03d5a 100644
91881--- a/net/core/sysctl_net_core.c
91882+++ b/net/core/sysctl_net_core.c
91883@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91884 {
91885 unsigned int orig_size, size;
91886 int ret, i;
91887- struct ctl_table tmp = {
91888+ ctl_table_no_const tmp = {
91889 .data = &size,
91890 .maxlen = sizeof(size),
91891 .mode = table->mode
91892@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91893
91894 static __net_init int sysctl_core_net_init(struct net *net)
91895 {
91896- struct ctl_table *tbl;
91897+ ctl_table_no_const *tbl = NULL;
91898
91899 net->core.sysctl_somaxconn = SOMAXCONN;
91900
91901- tbl = netns_core_table;
91902 if (!net_eq(net, &init_net)) {
91903- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91904+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91905 if (tbl == NULL)
91906 goto err_dup;
91907
91908@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91909 if (net->user_ns != &init_user_ns) {
91910 tbl[0].procname = NULL;
91911 }
91912- }
91913-
91914- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91915+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91916+ } else
91917+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91918 if (net->core.sysctl_hdr == NULL)
91919 goto err_reg;
91920
91921 return 0;
91922
91923 err_reg:
91924- if (tbl != netns_core_table)
91925- kfree(tbl);
91926+ kfree(tbl);
91927 err_dup:
91928 return -ENOMEM;
91929 }
91930@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91931 kfree(tbl);
91932 }
91933
91934-static __net_initdata struct pernet_operations sysctl_core_ops = {
91935+static __net_initconst struct pernet_operations sysctl_core_ops = {
91936 .init = sysctl_core_net_init,
91937 .exit = sysctl_core_net_exit,
91938 };
91939diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91940index dd4d506..fb2fb87 100644
91941--- a/net/decnet/af_decnet.c
91942+++ b/net/decnet/af_decnet.c
91943@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91944 .sysctl_rmem = sysctl_decnet_rmem,
91945 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91946 .obj_size = sizeof(struct dn_sock),
91947+ .slab_flags = SLAB_USERCOPY,
91948 };
91949
91950 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91951diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91952index 5325b54..a0d4d69 100644
91953--- a/net/decnet/sysctl_net_decnet.c
91954+++ b/net/decnet/sysctl_net_decnet.c
91955@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91956
91957 if (len > *lenp) len = *lenp;
91958
91959- if (copy_to_user(buffer, addr, len))
91960+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91961 return -EFAULT;
91962
91963 *lenp = len;
91964@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91965
91966 if (len > *lenp) len = *lenp;
91967
91968- if (copy_to_user(buffer, devname, len))
91969+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91970 return -EFAULT;
91971
91972 *lenp = len;
91973diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91974index 3b9d5f2..d7015c6 100644
91975--- a/net/ieee802154/6lowpan.c
91976+++ b/net/ieee802154/6lowpan.c
91977@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91978 hc06_ptr += 3;
91979 } else {
91980 /* compress nothing */
91981- memcpy(hc06_ptr, &hdr, 4);
91982+ memcpy(hc06_ptr, hdr, 4);
91983 /* replace the top byte with new ECN | DSCP format */
91984 *hc06_ptr = tmp;
91985 hc06_ptr += 4;
91986diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91987index dd6b523..dfe558f 100644
91988--- a/net/ipv4/af_inet.c
91989+++ b/net/ipv4/af_inet.c
91990@@ -1687,13 +1687,9 @@ static int __init inet_init(void)
91991
91992 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91993
91994- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91995- if (!sysctl_local_reserved_ports)
91996- goto out;
91997-
91998 rc = proto_register(&tcp_prot, 1);
91999 if (rc)
92000- goto out_free_reserved_ports;
92001+ goto out;
92002
92003 rc = proto_register(&udp_prot, 1);
92004 if (rc)
92005@@ -1802,8 +1798,6 @@ out_unregister_udp_proto:
92006 proto_unregister(&udp_prot);
92007 out_unregister_tcp_proto:
92008 proto_unregister(&tcp_prot);
92009-out_free_reserved_ports:
92010- kfree(sysctl_local_reserved_ports);
92011 goto out;
92012 }
92013
92014diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92015index 34ca6d5..b6421e8 100644
92016--- a/net/ipv4/devinet.c
92017+++ b/net/ipv4/devinet.c
92018@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92019 idx = 0;
92020 head = &net->dev_index_head[h];
92021 rcu_read_lock();
92022- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92023+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92024 net->dev_base_seq;
92025 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92026 if (idx < s_idx)
92027@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92028 idx = 0;
92029 head = &net->dev_index_head[h];
92030 rcu_read_lock();
92031- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92032+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92033 net->dev_base_seq;
92034 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92035 if (idx < s_idx)
92036@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92037 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92038 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92039
92040-static struct devinet_sysctl_table {
92041+static const struct devinet_sysctl_table {
92042 struct ctl_table_header *sysctl_header;
92043 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92044 } devinet_sysctl = {
92045@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92046 int err;
92047 struct ipv4_devconf *all, *dflt;
92048 #ifdef CONFIG_SYSCTL
92049- struct ctl_table *tbl = ctl_forward_entry;
92050+ ctl_table_no_const *tbl = NULL;
92051 struct ctl_table_header *forw_hdr;
92052 #endif
92053
92054@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92055 goto err_alloc_dflt;
92056
92057 #ifdef CONFIG_SYSCTL
92058- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92059+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92060 if (tbl == NULL)
92061 goto err_alloc_ctl;
92062
92063@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92064 goto err_reg_dflt;
92065
92066 err = -ENOMEM;
92067- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92068+ if (!net_eq(net, &init_net))
92069+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92070+ else
92071+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92072 if (forw_hdr == NULL)
92073 goto err_reg_ctl;
92074 net->ipv4.forw_hdr = forw_hdr;
92075@@ -2240,8 +2243,7 @@ err_reg_ctl:
92076 err_reg_dflt:
92077 __devinet_sysctl_unregister(all);
92078 err_reg_all:
92079- if (tbl != ctl_forward_entry)
92080- kfree(tbl);
92081+ kfree(tbl);
92082 err_alloc_ctl:
92083 #endif
92084 if (dflt != &ipv4_devconf_dflt)
92085diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92086index b3f627a..b0f3e99 100644
92087--- a/net/ipv4/fib_frontend.c
92088+++ b/net/ipv4/fib_frontend.c
92089@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92090 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92091 fib_sync_up(dev);
92092 #endif
92093- atomic_inc(&net->ipv4.dev_addr_genid);
92094+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92095 rt_cache_flush(dev_net(dev));
92096 break;
92097 case NETDEV_DOWN:
92098 fib_del_ifaddr(ifa, NULL);
92099- atomic_inc(&net->ipv4.dev_addr_genid);
92100+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92101 if (ifa->ifa_dev->ifa_list == NULL) {
92102 /* Last address was deleted from this interface.
92103 * Disable IP.
92104@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92105 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92106 fib_sync_up(dev);
92107 #endif
92108- atomic_inc(&net->ipv4.dev_addr_genid);
92109+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92110 rt_cache_flush(net);
92111 break;
92112 case NETDEV_DOWN:
92113diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92114index d5dbca5..6251d5f 100644
92115--- a/net/ipv4/fib_semantics.c
92116+++ b/net/ipv4/fib_semantics.c
92117@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92118 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92119 nh->nh_gw,
92120 nh->nh_parent->fib_scope);
92121- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92122+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92123
92124 return nh->nh_saddr;
92125 }
92126diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92127index 6acb541..9ea617d 100644
92128--- a/net/ipv4/inet_connection_sock.c
92129+++ b/net/ipv4/inet_connection_sock.c
92130@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92131 .range = { 32768, 61000 },
92132 };
92133
92134-unsigned long *sysctl_local_reserved_ports;
92135+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92136 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92137
92138 void inet_get_local_port_range(int *low, int *high)
92139diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92140index 7bd8983..b956690 100644
92141--- a/net/ipv4/inet_hashtables.c
92142+++ b/net/ipv4/inet_hashtables.c
92143@@ -18,12 +18,15 @@
92144 #include <linux/sched.h>
92145 #include <linux/slab.h>
92146 #include <linux/wait.h>
92147+#include <linux/security.h>
92148
92149 #include <net/inet_connection_sock.h>
92150 #include <net/inet_hashtables.h>
92151 #include <net/secure_seq.h>
92152 #include <net/ip.h>
92153
92154+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92155+
92156 /*
92157 * Allocate and initialize a new local port bind bucket.
92158 * The bindhash mutex for snum's hash chain must be held here.
92159@@ -287,7 +290,7 @@ begintw:
92160 if (unlikely(!INET_TW_MATCH(sk, net, acookie,
92161 saddr, daddr, ports,
92162 dif))) {
92163- sock_put(sk);
92164+ inet_twsk_put(inet_twsk(sk));
92165 goto begintw;
92166 }
92167 goto out;
92168@@ -554,6 +557,8 @@ ok:
92169 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92170 spin_unlock(&head->lock);
92171
92172+ gr_update_task_in_ip_table(current, inet_sk(sk));
92173+
92174 if (tw) {
92175 inet_twsk_deschedule(tw, death_row);
92176 while (twrefcnt) {
92177diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92178index 33d5537..da337a4 100644
92179--- a/net/ipv4/inetpeer.c
92180+++ b/net/ipv4/inetpeer.c
92181@@ -503,8 +503,8 @@ relookup:
92182 if (p) {
92183 p->daddr = *daddr;
92184 atomic_set(&p->refcnt, 1);
92185- atomic_set(&p->rid, 0);
92186- atomic_set(&p->ip_id_count,
92187+ atomic_set_unchecked(&p->rid, 0);
92188+ atomic_set_unchecked(&p->ip_id_count,
92189 (daddr->family == AF_INET) ?
92190 secure_ip_id(daddr->addr.a4) :
92191 secure_ipv6_id(daddr->addr.a6));
92192diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92193index b66910a..cfe416e 100644
92194--- a/net/ipv4/ip_fragment.c
92195+++ b/net/ipv4/ip_fragment.c
92196@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92197 return 0;
92198
92199 start = qp->rid;
92200- end = atomic_inc_return(&peer->rid);
92201+ end = atomic_inc_return_unchecked(&peer->rid);
92202 qp->rid = end;
92203
92204 rc = qp->q.fragments && (end - start) > max;
92205@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92206
92207 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92208 {
92209- struct ctl_table *table;
92210+ ctl_table_no_const *table = NULL;
92211 struct ctl_table_header *hdr;
92212
92213- table = ip4_frags_ns_ctl_table;
92214 if (!net_eq(net, &init_net)) {
92215- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92216+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92217 if (table == NULL)
92218 goto err_alloc;
92219
92220@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92221 /* Don't export sysctls to unprivileged users */
92222 if (net->user_ns != &init_user_ns)
92223 table[0].procname = NULL;
92224- }
92225+ hdr = register_net_sysctl(net, "net/ipv4", table);
92226+ } else
92227+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92228
92229- hdr = register_net_sysctl(net, "net/ipv4", table);
92230 if (hdr == NULL)
92231 goto err_reg;
92232
92233@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92234 return 0;
92235
92236 err_reg:
92237- if (!net_eq(net, &init_net))
92238- kfree(table);
92239+ kfree(table);
92240 err_alloc:
92241 return -ENOMEM;
92242 }
92243diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92244index 8d6939e..19d0a95 100644
92245--- a/net/ipv4/ip_gre.c
92246+++ b/net/ipv4/ip_gre.c
92247@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92248 module_param(log_ecn_error, bool, 0644);
92249 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92250
92251-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92252+static struct rtnl_link_ops ipgre_link_ops;
92253 static int ipgre_tunnel_init(struct net_device *dev);
92254
92255 static int ipgre_net_id __read_mostly;
92256@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92257 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92258 };
92259
92260-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92261+static struct rtnl_link_ops ipgre_link_ops = {
92262 .kind = "gre",
92263 .maxtype = IFLA_GRE_MAX,
92264 .policy = ipgre_policy,
92265@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92266 .fill_info = ipgre_fill_info,
92267 };
92268
92269-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92270+static struct rtnl_link_ops ipgre_tap_ops = {
92271 .kind = "gretap",
92272 .maxtype = IFLA_GRE_MAX,
92273 .policy = ipgre_policy,
92274diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
92275index a04d872..7f4ab5d 100644
92276--- a/net/ipv4/ip_output.c
92277+++ b/net/ipv4/ip_output.c
92278@@ -836,7 +836,7 @@ static int __ip_append_data(struct sock *sk,
92279 csummode = CHECKSUM_PARTIAL;
92280
92281 cork->length += length;
92282- if (((length > mtu) || (skb && skb_is_gso(skb))) &&
92283+ if (((length > mtu) || (skb && skb_has_frags(skb))) &&
92284 (sk->sk_protocol == IPPROTO_UDP) &&
92285 (rt->dst.dev->features & NETIF_F_UFO) && !rt->dst.header_len) {
92286 err = ip_ufo_append_data(sk, queue, getfrag, from, length,
92287diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92288index d9c4f11..02b82dbc 100644
92289--- a/net/ipv4/ip_sockglue.c
92290+++ b/net/ipv4/ip_sockglue.c
92291@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92292 len = min_t(unsigned int, len, opt->optlen);
92293 if (put_user(len, optlen))
92294 return -EFAULT;
92295- if (copy_to_user(optval, opt->__data, len))
92296+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92297+ copy_to_user(optval, opt->__data, len))
92298 return -EFAULT;
92299 return 0;
92300 }
92301@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92302 if (sk->sk_type != SOCK_STREAM)
92303 return -ENOPROTOOPT;
92304
92305- msg.msg_control = optval;
92306+ msg.msg_control = (void __force_kernel *)optval;
92307 msg.msg_controllen = len;
92308 msg.msg_flags = flags;
92309
92310diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92311index 17cc0ff..63856c4 100644
92312--- a/net/ipv4/ip_vti.c
92313+++ b/net/ipv4/ip_vti.c
92314@@ -47,7 +47,7 @@
92315 #define HASH_SIZE 16
92316 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92317
92318-static struct rtnl_link_ops vti_link_ops __read_mostly;
92319+static struct rtnl_link_ops vti_link_ops;
92320
92321 static int vti_net_id __read_mostly;
92322 struct vti_net {
92323@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92324 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92325 };
92326
92327-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92328+static struct rtnl_link_ops vti_link_ops = {
92329 .kind = "vti",
92330 .maxtype = IFLA_VTI_MAX,
92331 .policy = vti_policy,
92332diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92333index efa1138..20dbba0 100644
92334--- a/net/ipv4/ipconfig.c
92335+++ b/net/ipv4/ipconfig.c
92336@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92337
92338 mm_segment_t oldfs = get_fs();
92339 set_fs(get_ds());
92340- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92341+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92342 set_fs(oldfs);
92343 return res;
92344 }
92345@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92346
92347 mm_segment_t oldfs = get_fs();
92348 set_fs(get_ds());
92349- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92350+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92351 set_fs(oldfs);
92352 return res;
92353 }
92354@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92355
92356 mm_segment_t oldfs = get_fs();
92357 set_fs(get_ds());
92358- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92359+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92360 set_fs(oldfs);
92361 return res;
92362 }
92363diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92364index b3ac3c3..ec6bd95 100644
92365--- a/net/ipv4/ipip.c
92366+++ b/net/ipv4/ipip.c
92367@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92368 static int ipip_net_id __read_mostly;
92369
92370 static int ipip_tunnel_init(struct net_device *dev);
92371-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92372+static struct rtnl_link_ops ipip_link_ops;
92373
92374 static int ipip_err(struct sk_buff *skb, u32 info)
92375 {
92376@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92377 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92378 };
92379
92380-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92381+static struct rtnl_link_ops ipip_link_ops = {
92382 .kind = "ipip",
92383 .maxtype = IFLA_IPTUN_MAX,
92384 .policy = ipip_policy,
92385diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92386index 85a4f21..1beb1f5 100644
92387--- a/net/ipv4/netfilter/arp_tables.c
92388+++ b/net/ipv4/netfilter/arp_tables.c
92389@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92390 #endif
92391
92392 static int get_info(struct net *net, void __user *user,
92393- const int *len, int compat)
92394+ int len, int compat)
92395 {
92396 char name[XT_TABLE_MAXNAMELEN];
92397 struct xt_table *t;
92398 int ret;
92399
92400- if (*len != sizeof(struct arpt_getinfo)) {
92401- duprintf("length %u != %Zu\n", *len,
92402+ if (len != sizeof(struct arpt_getinfo)) {
92403+ duprintf("length %u != %Zu\n", len,
92404 sizeof(struct arpt_getinfo));
92405 return -EINVAL;
92406 }
92407@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92408 info.size = private->size;
92409 strcpy(info.name, name);
92410
92411- if (copy_to_user(user, &info, *len) != 0)
92412+ if (copy_to_user(user, &info, len) != 0)
92413 ret = -EFAULT;
92414 else
92415 ret = 0;
92416@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92417
92418 switch (cmd) {
92419 case ARPT_SO_GET_INFO:
92420- ret = get_info(sock_net(sk), user, len, 1);
92421+ ret = get_info(sock_net(sk), user, *len, 1);
92422 break;
92423 case ARPT_SO_GET_ENTRIES:
92424 ret = compat_get_entries(sock_net(sk), user, len);
92425@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92426
92427 switch (cmd) {
92428 case ARPT_SO_GET_INFO:
92429- ret = get_info(sock_net(sk), user, len, 0);
92430+ ret = get_info(sock_net(sk), user, *len, 0);
92431 break;
92432
92433 case ARPT_SO_GET_ENTRIES:
92434diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92435index d23118d..6ad7277 100644
92436--- a/net/ipv4/netfilter/ip_tables.c
92437+++ b/net/ipv4/netfilter/ip_tables.c
92438@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92439 #endif
92440
92441 static int get_info(struct net *net, void __user *user,
92442- const int *len, int compat)
92443+ int len, int compat)
92444 {
92445 char name[XT_TABLE_MAXNAMELEN];
92446 struct xt_table *t;
92447 int ret;
92448
92449- if (*len != sizeof(struct ipt_getinfo)) {
92450- duprintf("length %u != %zu\n", *len,
92451+ if (len != sizeof(struct ipt_getinfo)) {
92452+ duprintf("length %u != %zu\n", len,
92453 sizeof(struct ipt_getinfo));
92454 return -EINVAL;
92455 }
92456@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92457 info.size = private->size;
92458 strcpy(info.name, name);
92459
92460- if (copy_to_user(user, &info, *len) != 0)
92461+ if (copy_to_user(user, &info, len) != 0)
92462 ret = -EFAULT;
92463 else
92464 ret = 0;
92465@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92466
92467 switch (cmd) {
92468 case IPT_SO_GET_INFO:
92469- ret = get_info(sock_net(sk), user, len, 1);
92470+ ret = get_info(sock_net(sk), user, *len, 1);
92471 break;
92472 case IPT_SO_GET_ENTRIES:
92473 ret = compat_get_entries(sock_net(sk), user, len);
92474@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92475
92476 switch (cmd) {
92477 case IPT_SO_GET_INFO:
92478- ret = get_info(sock_net(sk), user, len, 0);
92479+ ret = get_info(sock_net(sk), user, *len, 0);
92480 break;
92481
92482 case IPT_SO_GET_ENTRIES:
92483diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
92484index cbc2215..9cb993c 100644
92485--- a/net/ipv4/netfilter/ipt_ULOG.c
92486+++ b/net/ipv4/netfilter/ipt_ULOG.c
92487@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
92488 ub->qlen++;
92489
92490 pm = nlmsg_data(nlh);
92491+ memset(pm, 0, sizeof(*pm));
92492
92493 /* We might not have a timestamp, get one */
92494 if (skb->tstamp.tv64 == 0)
92495@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
92496 }
92497 else if (loginfo->prefix[0] != '\0')
92498 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
92499- else
92500- *(pm->prefix) = '\0';
92501
92502 if (in && in->hard_header_len > 0 &&
92503 skb->mac_header != skb->network_header &&
92504@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
92505
92506 if (in)
92507 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
92508- else
92509- pm->indev_name[0] = '\0';
92510
92511 if (out)
92512 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
92513- else
92514- pm->outdev_name[0] = '\0';
92515
92516 /* copy_len <= skb->len, so can't fail. */
92517 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
92518diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92519index 746427c..80eab72 100644
92520--- a/net/ipv4/ping.c
92521+++ b/net/ipv4/ping.c
92522@@ -55,7 +55,7 @@
92523
92524
92525 struct ping_table ping_table;
92526-struct pingv6_ops pingv6_ops;
92527+struct pingv6_ops *pingv6_ops;
92528 EXPORT_SYMBOL_GPL(pingv6_ops);
92529
92530 static u16 ping_port_rover;
92531@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92532 return -ENODEV;
92533 }
92534 }
92535- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92536+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92537 scoped);
92538 rcu_read_unlock();
92539
92540@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92541 }
92542 #if IS_ENABLED(CONFIG_IPV6)
92543 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92544- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92545+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92546 #endif
92547 }
92548
92549@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92550 info, (u8 *)icmph);
92551 #if IS_ENABLED(CONFIG_IPV6)
92552 } else if (family == AF_INET6) {
92553- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92554+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92555 info, (u8 *)icmph);
92556 #endif
92557 }
92558@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92559 return ip_recv_error(sk, msg, len);
92560 #if IS_ENABLED(CONFIG_IPV6)
92561 } else if (family == AF_INET6) {
92562- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92563+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92564 #endif
92565 }
92566 }
92567@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92568 IP6CB(skb)->iif);
92569
92570 if (inet6_sk(sk)->rxopt.all)
92571- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92572+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92573 #endif
92574 } else {
92575 BUG();
92576@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92577 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92578 0, sock_i_ino(sp),
92579 atomic_read(&sp->sk_refcnt), sp,
92580- atomic_read(&sp->sk_drops), len);
92581+ atomic_read_unchecked(&sp->sk_drops), len);
92582 }
92583
92584 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92585diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92586index 6fb2337..9cd6b20 100644
92587--- a/net/ipv4/raw.c
92588+++ b/net/ipv4/raw.c
92589@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92590 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92591 {
92592 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92593- atomic_inc(&sk->sk_drops);
92594+ atomic_inc_unchecked(&sk->sk_drops);
92595 kfree_skb(skb);
92596 return NET_RX_DROP;
92597 }
92598@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92599
92600 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92601 {
92602+ struct icmp_filter filter;
92603+
92604 if (optlen > sizeof(struct icmp_filter))
92605 optlen = sizeof(struct icmp_filter);
92606- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92607+ if (copy_from_user(&filter, optval, optlen))
92608 return -EFAULT;
92609+ raw_sk(sk)->filter = filter;
92610 return 0;
92611 }
92612
92613 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92614 {
92615 int len, ret = -EFAULT;
92616+ struct icmp_filter filter;
92617
92618 if (get_user(len, optlen))
92619 goto out;
92620@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92621 if (len > sizeof(struct icmp_filter))
92622 len = sizeof(struct icmp_filter);
92623 ret = -EFAULT;
92624- if (put_user(len, optlen) ||
92625- copy_to_user(optval, &raw_sk(sk)->filter, len))
92626+ filter = raw_sk(sk)->filter;
92627+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92628 goto out;
92629 ret = 0;
92630 out: return ret;
92631@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92632 0, 0L, 0,
92633 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92634 0, sock_i_ino(sp),
92635- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92636+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92637 }
92638
92639 static int raw_seq_show(struct seq_file *seq, void *v)
92640diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92641index a9a54a2..647316e 100644
92642--- a/net/ipv4/route.c
92643+++ b/net/ipv4/route.c
92644@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92645 .maxlen = sizeof(int),
92646 .mode = 0200,
92647 .proc_handler = ipv4_sysctl_rtcache_flush,
92648+ .extra1 = &init_net,
92649 },
92650 { },
92651 };
92652
92653 static __net_init int sysctl_route_net_init(struct net *net)
92654 {
92655- struct ctl_table *tbl;
92656+ ctl_table_no_const *tbl = NULL;
92657
92658- tbl = ipv4_route_flush_table;
92659 if (!net_eq(net, &init_net)) {
92660- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92661+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92662 if (tbl == NULL)
92663 goto err_dup;
92664
92665 /* Don't export sysctls to unprivileged users */
92666 if (net->user_ns != &init_user_ns)
92667 tbl[0].procname = NULL;
92668- }
92669- tbl[0].extra1 = net;
92670+ tbl[0].extra1 = net;
92671+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92672+ } else
92673+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92674
92675- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92676 if (net->ipv4.route_hdr == NULL)
92677 goto err_reg;
92678 return 0;
92679
92680 err_reg:
92681- if (tbl != ipv4_route_flush_table)
92682- kfree(tbl);
92683+ kfree(tbl);
92684 err_dup:
92685 return -ENOMEM;
92686 }
92687@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92688
92689 static __net_init int rt_genid_init(struct net *net)
92690 {
92691- atomic_set(&net->rt_genid, 0);
92692- atomic_set(&net->fnhe_genid, 0);
92693+ atomic_set_unchecked(&net->rt_genid, 0);
92694+ atomic_set_unchecked(&net->fnhe_genid, 0);
92695 get_random_bytes(&net->ipv4.dev_addr_genid,
92696 sizeof(net->ipv4.dev_addr_genid));
92697 return 0;
92698diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92699index 610e324..fd42e75 100644
92700--- a/net/ipv4/sysctl_net_ipv4.c
92701+++ b/net/ipv4/sysctl_net_ipv4.c
92702@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92703 {
92704 int ret;
92705 int range[2];
92706- struct ctl_table tmp = {
92707+ ctl_table_no_const tmp = {
92708 .data = &range,
92709 .maxlen = sizeof(range),
92710 .mode = table->mode,
92711@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92712 int ret;
92713 gid_t urange[2];
92714 kgid_t low, high;
92715- struct ctl_table tmp = {
92716+ ctl_table_no_const tmp = {
92717 .data = &urange,
92718 .maxlen = sizeof(urange),
92719 .mode = table->mode,
92720@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92721 void __user *buffer, size_t *lenp, loff_t *ppos)
92722 {
92723 char val[TCP_CA_NAME_MAX];
92724- struct ctl_table tbl = {
92725+ ctl_table_no_const tbl = {
92726 .data = val,
92727 .maxlen = TCP_CA_NAME_MAX,
92728 };
92729@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92730 void __user *buffer, size_t *lenp,
92731 loff_t *ppos)
92732 {
92733- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92734+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92735 int ret;
92736
92737 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92738@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92739 void __user *buffer, size_t *lenp,
92740 loff_t *ppos)
92741 {
92742- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92743+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92744 int ret;
92745
92746 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92747@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92748 struct mem_cgroup *memcg;
92749 #endif
92750
92751- struct ctl_table tmp = {
92752+ ctl_table_no_const tmp = {
92753 .data = &vec,
92754 .maxlen = sizeof(vec),
92755 .mode = ctl->mode,
92756 };
92757
92758 if (!write) {
92759- ctl->data = &net->ipv4.sysctl_tcp_mem;
92760- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92761+ ctl_table_no_const tcp_mem = *ctl;
92762+
92763+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92764+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92765 }
92766
92767 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92768@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92769 void __user *buffer, size_t *lenp,
92770 loff_t *ppos)
92771 {
92772- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92773+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92774 struct tcp_fastopen_context *ctxt;
92775 int ret;
92776 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92777@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92778 },
92779 {
92780 .procname = "ip_local_reserved_ports",
92781- .data = NULL, /* initialized in sysctl_ipv4_init */
92782+ .data = sysctl_local_reserved_ports,
92783 .maxlen = 65536,
92784 .mode = 0644,
92785 .proc_handler = proc_do_large_bitmap,
92786@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92787
92788 static __net_init int ipv4_sysctl_init_net(struct net *net)
92789 {
92790- struct ctl_table *table;
92791+ ctl_table_no_const *table = NULL;
92792
92793- table = ipv4_net_table;
92794 if (!net_eq(net, &init_net)) {
92795- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92796+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92797 if (table == NULL)
92798 goto err_alloc;
92799
92800@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92801
92802 tcp_init_mem(net);
92803
92804- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92805+ if (!net_eq(net, &init_net))
92806+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92807+ else
92808+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92809 if (net->ipv4.ipv4_hdr == NULL)
92810 goto err_reg;
92811
92812 return 0;
92813
92814 err_reg:
92815- if (!net_eq(net, &init_net))
92816- kfree(table);
92817+ kfree(table);
92818 err_alloc:
92819 return -ENOMEM;
92820 }
92821@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92822 static __init int sysctl_ipv4_init(void)
92823 {
92824 struct ctl_table_header *hdr;
92825- struct ctl_table *i;
92826-
92827- for (i = ipv4_table; i->procname; i++) {
92828- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92829- i->data = sysctl_local_reserved_ports;
92830- break;
92831- }
92832- }
92833- if (!i->procname)
92834- return -EINVAL;
92835
92836 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92837 if (hdr == NULL)
92838diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92839index 3ca2139..c4cc060 100644
92840--- a/net/ipv4/tcp_input.c
92841+++ b/net/ipv4/tcp_input.c
92842@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92843 * simplifies code)
92844 */
92845 static void
92846-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92847+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92848 struct sk_buff *head, struct sk_buff *tail,
92849 u32 start, u32 end)
92850 {
92851@@ -5465,6 +5465,7 @@ discard:
92852 tcp_paws_reject(&tp->rx_opt, 0))
92853 goto discard_and_undo;
92854
92855+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92856 if (th->syn) {
92857 /* We see SYN without ACK. It is attempt of
92858 * simultaneous connect with crossed SYNs.
92859@@ -5515,6 +5516,7 @@ discard:
92860 goto discard;
92861 #endif
92862 }
92863+#endif
92864 /* "fifth, if neither of the SYN or RST bits is set then
92865 * drop the segment and return."
92866 */
92867@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92868 goto discard;
92869
92870 if (th->syn) {
92871- if (th->fin)
92872+ if (th->fin || th->urg || th->psh)
92873 goto discard;
92874 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92875 return 1;
92876diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92877index b299da5..097db06 100644
92878--- a/net/ipv4/tcp_ipv4.c
92879+++ b/net/ipv4/tcp_ipv4.c
92880@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92881 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92882
92883
92884+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92885+extern int grsec_enable_blackhole;
92886+#endif
92887+
92888 #ifdef CONFIG_TCP_MD5SIG
92889 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92890 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92891@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92892 return 0;
92893
92894 reset:
92895+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92896+ if (!grsec_enable_blackhole)
92897+#endif
92898 tcp_v4_send_reset(rsk, skb);
92899 discard:
92900 kfree_skb(skb);
92901@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92902 TCP_SKB_CB(skb)->sacked = 0;
92903
92904 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92905- if (!sk)
92906+ if (!sk) {
92907+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92908+ ret = 1;
92909+#endif
92910 goto no_tcp_socket;
92911-
92912+ }
92913 process:
92914- if (sk->sk_state == TCP_TIME_WAIT)
92915+ if (sk->sk_state == TCP_TIME_WAIT) {
92916+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92917+ ret = 2;
92918+#endif
92919 goto do_time_wait;
92920+ }
92921
92922 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92923 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92924@@ -2034,6 +2048,10 @@ csum_error:
92925 bad_packet:
92926 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92927 } else {
92928+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92929+ if (!grsec_enable_blackhole || (ret == 1 &&
92930+ (skb->dev->flags & IFF_LOOPBACK)))
92931+#endif
92932 tcp_v4_send_reset(NULL, skb);
92933 }
92934
92935diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92936index ab1c086..2a8d76b 100644
92937--- a/net/ipv4/tcp_minisocks.c
92938+++ b/net/ipv4/tcp_minisocks.c
92939@@ -27,6 +27,10 @@
92940 #include <net/inet_common.h>
92941 #include <net/xfrm.h>
92942
92943+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92944+extern int grsec_enable_blackhole;
92945+#endif
92946+
92947 int sysctl_tcp_syncookies __read_mostly = 1;
92948 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92949
92950@@ -715,7 +719,10 @@ embryonic_reset:
92951 * avoid becoming vulnerable to outside attack aiming at
92952 * resetting legit local connections.
92953 */
92954- req->rsk_ops->send_reset(sk, skb);
92955+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92956+ if (!grsec_enable_blackhole)
92957+#endif
92958+ req->rsk_ops->send_reset(sk, skb);
92959 } else if (fastopen) { /* received a valid RST pkt */
92960 reqsk_fastopen_remove(sk, req, true);
92961 tcp_reset(sk);
92962diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
92963index 170737a..75cbd26 100644
92964--- a/net/ipv4/tcp_output.c
92965+++ b/net/ipv4/tcp_output.c
92966@@ -982,6 +982,9 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
92967 static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb,
92968 unsigned int mss_now)
92969 {
92970+ /* Make sure we own this skb before messing gso_size/gso_segs */
92971+ WARN_ON_ONCE(skb_cloned(skb));
92972+
92973 if (skb->len <= mss_now || !sk_can_gso(sk) ||
92974 skb->ip_summed == CHECKSUM_NONE) {
92975 /* Avoid the costly divide in the normal
92976@@ -1063,9 +1066,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
92977 if (nsize < 0)
92978 nsize = 0;
92979
92980- if (skb_cloned(skb) &&
92981- skb_is_nonlinear(skb) &&
92982- pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
92983+ if (skb_unclone(skb, GFP_ATOMIC))
92984 return -ENOMEM;
92985
92986 /* Get a new skb... force flag on. */
92987@@ -2334,6 +2335,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
92988 int oldpcount = tcp_skb_pcount(skb);
92989
92990 if (unlikely(oldpcount > 1)) {
92991+ if (skb_unclone(skb, GFP_ATOMIC))
92992+ return -ENOMEM;
92993 tcp_init_tso_segs(sk, skb, cur_mss);
92994 tcp_adjust_pcount(sk, skb, oldpcount - tcp_skb_pcount(skb));
92995 }
92996diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92997index d4943f6..e7a74a5 100644
92998--- a/net/ipv4/tcp_probe.c
92999+++ b/net/ipv4/tcp_probe.c
93000@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
93001 if (cnt + width >= len)
93002 break;
93003
93004- if (copy_to_user(buf + cnt, tbuf, width))
93005+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
93006 return -EFAULT;
93007 cnt += width;
93008 }
93009diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
93010index 4b85e6f..22f9ac9 100644
93011--- a/net/ipv4/tcp_timer.c
93012+++ b/net/ipv4/tcp_timer.c
93013@@ -22,6 +22,10 @@
93014 #include <linux/gfp.h>
93015 #include <net/tcp.h>
93016
93017+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93018+extern int grsec_lastack_retries;
93019+#endif
93020+
93021 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
93022 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
93023 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
93024@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
93025 }
93026 }
93027
93028+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93029+ if ((sk->sk_state == TCP_LAST_ACK) &&
93030+ (grsec_lastack_retries > 0) &&
93031+ (grsec_lastack_retries < retry_until))
93032+ retry_until = grsec_lastack_retries;
93033+#endif
93034+
93035 if (retransmits_timed_out(sk, retry_until,
93036 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
93037 /* Has it gone just too far? */
93038diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
93039index 766e6ba..aff2f8d 100644
93040--- a/net/ipv4/udp.c
93041+++ b/net/ipv4/udp.c
93042@@ -87,6 +87,7 @@
93043 #include <linux/types.h>
93044 #include <linux/fcntl.h>
93045 #include <linux/module.h>
93046+#include <linux/security.h>
93047 #include <linux/socket.h>
93048 #include <linux/sockios.h>
93049 #include <linux/igmp.h>
93050@@ -112,6 +113,10 @@
93051 #include <net/busy_poll.h>
93052 #include "udp_impl.h"
93053
93054+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93055+extern int grsec_enable_blackhole;
93056+#endif
93057+
93058 struct udp_table udp_table __read_mostly;
93059 EXPORT_SYMBOL(udp_table);
93060
93061@@ -595,6 +600,9 @@ found:
93062 return s;
93063 }
93064
93065+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
93066+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
93067+
93068 /*
93069 * This routine is called by the ICMP module when it gets some
93070 * sort of error condition. If err < 0 then the socket should
93071@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93072 dport = usin->sin_port;
93073 if (dport == 0)
93074 return -EINVAL;
93075+
93076+ err = gr_search_udp_sendmsg(sk, usin);
93077+ if (err)
93078+ return err;
93079 } else {
93080 if (sk->sk_state != TCP_ESTABLISHED)
93081 return -EDESTADDRREQ;
93082+
93083+ err = gr_search_udp_sendmsg(sk, NULL);
93084+ if (err)
93085+ return err;
93086+
93087 daddr = inet->inet_daddr;
93088 dport = inet->inet_dport;
93089 /* Open fast path for connected socket.
93090@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93091 IS_UDPLITE(sk));
93092 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93093 IS_UDPLITE(sk));
93094- atomic_inc(&sk->sk_drops);
93095+ atomic_inc_unchecked(&sk->sk_drops);
93096 __skb_unlink(skb, rcvq);
93097 __skb_queue_tail(&list_kill, skb);
93098 }
93099@@ -1223,6 +1240,10 @@ try_again:
93100 if (!skb)
93101 goto out;
93102
93103+ err = gr_search_udp_recvmsg(sk, skb);
93104+ if (err)
93105+ goto out_free;
93106+
93107 ulen = skb->len - sizeof(struct udphdr);
93108 copied = len;
93109 if (copied > ulen)
93110@@ -1256,7 +1277,7 @@ try_again:
93111 if (unlikely(err)) {
93112 trace_kfree_skb(skb, udp_recvmsg);
93113 if (!peeked) {
93114- atomic_inc(&sk->sk_drops);
93115+ atomic_inc_unchecked(&sk->sk_drops);
93116 UDP_INC_STATS_USER(sock_net(sk),
93117 UDP_MIB_INERRORS, is_udplite);
93118 }
93119@@ -1543,7 +1564,7 @@ csum_error:
93120 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93121 drop:
93122 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93123- atomic_inc(&sk->sk_drops);
93124+ atomic_inc_unchecked(&sk->sk_drops);
93125 kfree_skb(skb);
93126 return -1;
93127 }
93128@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93129 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93130
93131 if (!skb1) {
93132- atomic_inc(&sk->sk_drops);
93133+ atomic_inc_unchecked(&sk->sk_drops);
93134 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93135 IS_UDPLITE(sk));
93136 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93137@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93138 goto csum_error;
93139
93140 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93141+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93142+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93143+#endif
93144 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93145
93146 /*
93147@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93148 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93149 0, sock_i_ino(sp),
93150 atomic_read(&sp->sk_refcnt), sp,
93151- atomic_read(&sp->sk_drops), len);
93152+ atomic_read_unchecked(&sp->sk_drops), len);
93153 }
93154
93155 int udp4_seq_show(struct seq_file *seq, void *v)
93156diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93157index 9a459be..c7bc04c 100644
93158--- a/net/ipv4/xfrm4_policy.c
93159+++ b/net/ipv4/xfrm4_policy.c
93160@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93161 fl4->flowi4_tos = iph->tos;
93162 }
93163
93164-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93165+static int xfrm4_garbage_collect(struct dst_ops *ops)
93166 {
93167 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93168
93169- xfrm4_policy_afinfo.garbage_collect(net);
93170+ xfrm_garbage_collect_deferred(net);
93171 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93172 }
93173
93174@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93175
93176 static int __net_init xfrm4_net_init(struct net *net)
93177 {
93178- struct ctl_table *table;
93179+ ctl_table_no_const *table = NULL;
93180 struct ctl_table_header *hdr;
93181
93182- table = xfrm4_policy_table;
93183 if (!net_eq(net, &init_net)) {
93184- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93185+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93186 if (!table)
93187 goto err_alloc;
93188
93189 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93190- }
93191-
93192- hdr = register_net_sysctl(net, "net/ipv4", table);
93193+ hdr = register_net_sysctl(net, "net/ipv4", table);
93194+ } else
93195+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93196 if (!hdr)
93197 goto err_reg;
93198
93199@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93200 return 0;
93201
93202 err_reg:
93203- if (!net_eq(net, &init_net))
93204- kfree(table);
93205+ kfree(table);
93206 err_alloc:
93207 return -ENOMEM;
93208 }
93209diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93210index 0f99f7b..9375cf5 100644
93211--- a/net/ipv6/addrconf.c
93212+++ b/net/ipv6/addrconf.c
93213@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93214 idx = 0;
93215 head = &net->dev_index_head[h];
93216 rcu_read_lock();
93217- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93218+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93219 net->dev_base_seq;
93220 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93221 if (idx < s_idx)
93222@@ -2408,7 +2408,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93223 p.iph.ihl = 5;
93224 p.iph.protocol = IPPROTO_IPV6;
93225 p.iph.ttl = 64;
93226- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93227+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93228
93229 if (ops->ndo_do_ioctl) {
93230 mm_segment_t oldfs = get_fs();
93231@@ -4057,7 +4057,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93232 s_ip_idx = ip_idx = cb->args[2];
93233
93234 rcu_read_lock();
93235- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93236+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93237 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93238 idx = 0;
93239 head = &net->dev_index_head[h];
93240@@ -4678,7 +4678,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93241 dst_free(&ifp->rt->dst);
93242 break;
93243 }
93244- atomic_inc(&net->ipv6.dev_addr_genid);
93245+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93246 }
93247
93248 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93249@@ -4698,7 +4698,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93250 int *valp = ctl->data;
93251 int val = *valp;
93252 loff_t pos = *ppos;
93253- struct ctl_table lctl;
93254+ ctl_table_no_const lctl;
93255 int ret;
93256
93257 /*
93258@@ -4783,7 +4783,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93259 int *valp = ctl->data;
93260 int val = *valp;
93261 loff_t pos = *ppos;
93262- struct ctl_table lctl;
93263+ ctl_table_no_const lctl;
93264 int ret;
93265
93266 /*
93267diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93268index 197e6f4..16d8396 100644
93269--- a/net/ipv6/datagram.c
93270+++ b/net/ipv6/datagram.c
93271@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93272 0,
93273 sock_i_ino(sp),
93274 atomic_read(&sp->sk_refcnt), sp,
93275- atomic_read(&sp->sk_drops));
93276+ atomic_read_unchecked(&sp->sk_drops));
93277 }
93278diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93279index 7cfc8d2..c5394b6 100644
93280--- a/net/ipv6/icmp.c
93281+++ b/net/ipv6/icmp.c
93282@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93283
93284 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93285 {
93286- struct ctl_table *table;
93287+ ctl_table_no_const *table;
93288
93289 table = kmemdup(ipv6_icmp_table_template,
93290 sizeof(ipv6_icmp_table_template),
93291diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
93292index 32b4a16..066640e 100644
93293--- a/net/ipv6/inet6_hashtables.c
93294+++ b/net/ipv6/inet6_hashtables.c
93295@@ -116,7 +116,7 @@ begintw:
93296 }
93297 if (unlikely(!INET6_TW_MATCH(sk, net, saddr, daddr,
93298 ports, dif))) {
93299- sock_put(sk);
93300+ inet_twsk_put(inet_twsk(sk));
93301 goto begintw;
93302 }
93303 goto out;
93304diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93305index 8bc717b..76fbb5d 100644
93306--- a/net/ipv6/ip6_gre.c
93307+++ b/net/ipv6/ip6_gre.c
93308@@ -74,7 +74,7 @@ struct ip6gre_net {
93309 struct net_device *fb_tunnel_dev;
93310 };
93311
93312-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93313+static struct rtnl_link_ops ip6gre_link_ops;
93314 static int ip6gre_tunnel_init(struct net_device *dev);
93315 static void ip6gre_tunnel_setup(struct net_device *dev);
93316 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93317@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93318 }
93319
93320
93321-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93322+static struct inet6_protocol ip6gre_protocol = {
93323 .handler = ip6gre_rcv,
93324 .err_handler = ip6gre_err,
93325 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93326@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93327 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93328 };
93329
93330-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93331+static struct rtnl_link_ops ip6gre_link_ops = {
93332 .kind = "ip6gre",
93333 .maxtype = IFLA_GRE_MAX,
93334 .policy = ip6gre_policy,
93335@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93336 .fill_info = ip6gre_fill_info,
93337 };
93338
93339-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93340+static struct rtnl_link_ops ip6gre_tap_ops = {
93341 .kind = "ip6gretap",
93342 .maxtype = IFLA_GRE_MAX,
93343 .policy = ip6gre_policy,
93344diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
93345index 44df1c9..2e542d0 100644
93346--- a/net/ipv6/ip6_output.c
93347+++ b/net/ipv6/ip6_output.c
93348@@ -1252,7 +1252,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
93349 skb = skb_peek_tail(&sk->sk_write_queue);
93350 cork->length += length;
93351 if (((length > mtu) ||
93352- (skb && skb_is_gso(skb))) &&
93353+ (skb && skb_has_frags(skb))) &&
93354 (sk->sk_protocol == IPPROTO_UDP) &&
93355 (rt->dst.dev->features & NETIF_F_UFO)) {
93356 err = ip6_ufo_append_data(sk, getfrag, from, length,
93357diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93358index cf5d490..30946f0 100644
93359--- a/net/ipv6/ip6_tunnel.c
93360+++ b/net/ipv6/ip6_tunnel.c
93361@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93362
93363 static int ip6_tnl_dev_init(struct net_device *dev);
93364 static void ip6_tnl_dev_setup(struct net_device *dev);
93365-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93366+static struct rtnl_link_ops ip6_link_ops;
93367
93368 static int ip6_tnl_net_id __read_mostly;
93369 struct ip6_tnl_net {
93370@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93371 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93372 };
93373
93374-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93375+static struct rtnl_link_ops ip6_link_ops = {
93376 .kind = "ip6tnl",
93377 .maxtype = IFLA_IPTUN_MAX,
93378 .policy = ip6_tnl_policy,
93379diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93380index d1e2e8e..51c19ae 100644
93381--- a/net/ipv6/ipv6_sockglue.c
93382+++ b/net/ipv6/ipv6_sockglue.c
93383@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93384 if (sk->sk_type != SOCK_STREAM)
93385 return -ENOPROTOOPT;
93386
93387- msg.msg_control = optval;
93388+ msg.msg_control = (void __force_kernel *)optval;
93389 msg.msg_controllen = len;
93390 msg.msg_flags = flags;
93391
93392diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93393index 44400c2..8e11f52 100644
93394--- a/net/ipv6/netfilter/ip6_tables.c
93395+++ b/net/ipv6/netfilter/ip6_tables.c
93396@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93397 #endif
93398
93399 static int get_info(struct net *net, void __user *user,
93400- const int *len, int compat)
93401+ int len, int compat)
93402 {
93403 char name[XT_TABLE_MAXNAMELEN];
93404 struct xt_table *t;
93405 int ret;
93406
93407- if (*len != sizeof(struct ip6t_getinfo)) {
93408- duprintf("length %u != %zu\n", *len,
93409+ if (len != sizeof(struct ip6t_getinfo)) {
93410+ duprintf("length %u != %zu\n", len,
93411 sizeof(struct ip6t_getinfo));
93412 return -EINVAL;
93413 }
93414@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93415 info.size = private->size;
93416 strcpy(info.name, name);
93417
93418- if (copy_to_user(user, &info, *len) != 0)
93419+ if (copy_to_user(user, &info, len) != 0)
93420 ret = -EFAULT;
93421 else
93422 ret = 0;
93423@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93424
93425 switch (cmd) {
93426 case IP6T_SO_GET_INFO:
93427- ret = get_info(sock_net(sk), user, len, 1);
93428+ ret = get_info(sock_net(sk), user, *len, 1);
93429 break;
93430 case IP6T_SO_GET_ENTRIES:
93431 ret = compat_get_entries(sock_net(sk), user, len);
93432@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93433
93434 switch (cmd) {
93435 case IP6T_SO_GET_INFO:
93436- ret = get_info(sock_net(sk), user, len, 0);
93437+ ret = get_info(sock_net(sk), user, *len, 0);
93438 break;
93439
93440 case IP6T_SO_GET_ENTRIES:
93441diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93442index dffdc1a..ccc6678 100644
93443--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93444+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93445@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93446
93447 static int nf_ct_frag6_sysctl_register(struct net *net)
93448 {
93449- struct ctl_table *table;
93450+ ctl_table_no_const *table = NULL;
93451 struct ctl_table_header *hdr;
93452
93453- table = nf_ct_frag6_sysctl_table;
93454 if (!net_eq(net, &init_net)) {
93455- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93456+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93457 GFP_KERNEL);
93458 if (table == NULL)
93459 goto err_alloc;
93460@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93461 table[0].data = &net->nf_frag.frags.timeout;
93462 table[1].data = &net->nf_frag.frags.low_thresh;
93463 table[2].data = &net->nf_frag.frags.high_thresh;
93464- }
93465-
93466- hdr = register_net_sysctl(net, "net/netfilter", table);
93467+ hdr = register_net_sysctl(net, "net/netfilter", table);
93468+ } else
93469+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93470 if (hdr == NULL)
93471 goto err_reg;
93472
93473@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93474 return 0;
93475
93476 err_reg:
93477- if (!net_eq(net, &init_net))
93478- kfree(table);
93479+ kfree(table);
93480 err_alloc:
93481 return -ENOMEM;
93482 }
93483diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93484index ab92a36..bb4a528 100644
93485--- a/net/ipv6/output_core.c
93486+++ b/net/ipv6/output_core.c
93487@@ -8,8 +8,8 @@
93488
93489 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93490 {
93491- static atomic_t ipv6_fragmentation_id;
93492- int old, new;
93493+ static atomic_unchecked_t ipv6_fragmentation_id;
93494+ int id;
93495
93496 #if IS_ENABLED(CONFIG_IPV6)
93497 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93498@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93499 }
93500 }
93501 #endif
93502- do {
93503- old = atomic_read(&ipv6_fragmentation_id);
93504- new = old + 1;
93505- if (!new)
93506- new = 1;
93507- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93508- fhdr->identification = htonl(new);
93509+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93510+ if (!id)
93511+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93512+ fhdr->identification = htonl(id);
93513 }
93514 EXPORT_SYMBOL(ipv6_select_ident);
93515
93516diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93517index 18f19df..b46ada1 100644
93518--- a/net/ipv6/ping.c
93519+++ b/net/ipv6/ping.c
93520@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93521 };
93522 #endif
93523
93524+static struct pingv6_ops real_pingv6_ops = {
93525+ .ipv6_recv_error = ipv6_recv_error,
93526+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93527+ .icmpv6_err_convert = icmpv6_err_convert,
93528+ .ipv6_icmp_error = ipv6_icmp_error,
93529+ .ipv6_chk_addr = ipv6_chk_addr,
93530+};
93531+
93532+static struct pingv6_ops dummy_pingv6_ops = {
93533+ .ipv6_recv_error = dummy_ipv6_recv_error,
93534+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93535+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93536+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93537+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93538+};
93539+
93540 int __init pingv6_init(void)
93541 {
93542 #ifdef CONFIG_PROC_FS
93543@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93544 if (ret)
93545 return ret;
93546 #endif
93547- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93548- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93549- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93550- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93551- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93552+ pingv6_ops = &real_pingv6_ops;
93553 return inet6_register_protosw(&pingv6_protosw);
93554 }
93555
93556@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93557 */
93558 void pingv6_exit(void)
93559 {
93560- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93561- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93562- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93563- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93564- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93565+ pingv6_ops = &dummy_pingv6_ops;
93566 #ifdef CONFIG_PROC_FS
93567 unregister_pernet_subsys(&ping_v6_net_ops);
93568 #endif
93569diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93570index cdaed47..515edde9 100644
93571--- a/net/ipv6/raw.c
93572+++ b/net/ipv6/raw.c
93573@@ -108,7 +108,7 @@ found:
93574 */
93575 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93576 {
93577- struct icmp6hdr *_hdr;
93578+ struct icmp6hdr _hdr;
93579 const struct icmp6hdr *hdr;
93580
93581 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93582@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93583 {
93584 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93585 skb_checksum_complete(skb)) {
93586- atomic_inc(&sk->sk_drops);
93587+ atomic_inc_unchecked(&sk->sk_drops);
93588 kfree_skb(skb);
93589 return NET_RX_DROP;
93590 }
93591@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93592 struct raw6_sock *rp = raw6_sk(sk);
93593
93594 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93595- atomic_inc(&sk->sk_drops);
93596+ atomic_inc_unchecked(&sk->sk_drops);
93597 kfree_skb(skb);
93598 return NET_RX_DROP;
93599 }
93600@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93601
93602 if (inet->hdrincl) {
93603 if (skb_checksum_complete(skb)) {
93604- atomic_inc(&sk->sk_drops);
93605+ atomic_inc_unchecked(&sk->sk_drops);
93606 kfree_skb(skb);
93607 return NET_RX_DROP;
93608 }
93609@@ -602,7 +602,7 @@ out:
93610 return err;
93611 }
93612
93613-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93614+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93615 struct flowi6 *fl6, struct dst_entry **dstp,
93616 unsigned int flags)
93617 {
93618@@ -915,12 +915,15 @@ do_confirm:
93619 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93620 char __user *optval, int optlen)
93621 {
93622+ struct icmp6_filter filter;
93623+
93624 switch (optname) {
93625 case ICMPV6_FILTER:
93626 if (optlen > sizeof(struct icmp6_filter))
93627 optlen = sizeof(struct icmp6_filter);
93628- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93629+ if (copy_from_user(&filter, optval, optlen))
93630 return -EFAULT;
93631+ raw6_sk(sk)->filter = filter;
93632 return 0;
93633 default:
93634 return -ENOPROTOOPT;
93635@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93636 char __user *optval, int __user *optlen)
93637 {
93638 int len;
93639+ struct icmp6_filter filter;
93640
93641 switch (optname) {
93642 case ICMPV6_FILTER:
93643@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93644 len = sizeof(struct icmp6_filter);
93645 if (put_user(len, optlen))
93646 return -EFAULT;
93647- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93648+ filter = raw6_sk(sk)->filter;
93649+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93650 return -EFAULT;
93651 return 0;
93652 default:
93653diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93654index 1aeb473..bea761c 100644
93655--- a/net/ipv6/reassembly.c
93656+++ b/net/ipv6/reassembly.c
93657@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93658
93659 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93660 {
93661- struct ctl_table *table;
93662+ ctl_table_no_const *table = NULL;
93663 struct ctl_table_header *hdr;
93664
93665- table = ip6_frags_ns_ctl_table;
93666 if (!net_eq(net, &init_net)) {
93667- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93668+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93669 if (table == NULL)
93670 goto err_alloc;
93671
93672@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93673 /* Don't export sysctls to unprivileged users */
93674 if (net->user_ns != &init_user_ns)
93675 table[0].procname = NULL;
93676- }
93677+ hdr = register_net_sysctl(net, "net/ipv6", table);
93678+ } else
93679+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93680
93681- hdr = register_net_sysctl(net, "net/ipv6", table);
93682 if (hdr == NULL)
93683 goto err_reg;
93684
93685@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93686 return 0;
93687
93688 err_reg:
93689- if (!net_eq(net, &init_net))
93690- kfree(table);
93691+ kfree(table);
93692 err_alloc:
93693 return -ENOMEM;
93694 }
93695diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93696index 8d9a93ed..cd89616 100644
93697--- a/net/ipv6/route.c
93698+++ b/net/ipv6/route.c
93699@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93700
93701 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93702 {
93703- struct ctl_table *table;
93704+ ctl_table_no_const *table;
93705
93706 table = kmemdup(ipv6_route_table_template,
93707 sizeof(ipv6_route_table_template),
93708diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93709index 86f639b..71e355e 100644
93710--- a/net/ipv6/sit.c
93711+++ b/net/ipv6/sit.c
93712@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93713 static void ipip6_dev_free(struct net_device *dev);
93714 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93715 __be32 *v4dst);
93716-static struct rtnl_link_ops sit_link_ops __read_mostly;
93717+static struct rtnl_link_ops sit_link_ops;
93718
93719 static int sit_net_id __read_mostly;
93720 struct sit_net {
93721@@ -1601,7 +1601,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93722 #endif
93723 };
93724
93725-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93726+static struct rtnl_link_ops sit_link_ops = {
93727 .kind = "sit",
93728 .maxtype = IFLA_IPTUN_MAX,
93729 .policy = ipip6_policy,
93730diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93731index 107b2f1..72741a9 100644
93732--- a/net/ipv6/sysctl_net_ipv6.c
93733+++ b/net/ipv6/sysctl_net_ipv6.c
93734@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93735
93736 static int __net_init ipv6_sysctl_net_init(struct net *net)
93737 {
93738- struct ctl_table *ipv6_table;
93739+ ctl_table_no_const *ipv6_table;
93740 struct ctl_table *ipv6_route_table;
93741 struct ctl_table *ipv6_icmp_table;
93742 int err;
93743diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93744index 6e1649d..75ddb4c 100644
93745--- a/net/ipv6/tcp_ipv6.c
93746+++ b/net/ipv6/tcp_ipv6.c
93747@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93748 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93749 }
93750
93751+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93752+extern int grsec_enable_blackhole;
93753+#endif
93754+
93755 static void tcp_v6_hash(struct sock *sk)
93756 {
93757 if (sk->sk_state != TCP_CLOSE) {
93758@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93759 return 0;
93760
93761 reset:
93762+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93763+ if (!grsec_enable_blackhole)
93764+#endif
93765 tcp_v6_send_reset(sk, skb);
93766 discard:
93767 if (opt_skb)
93768@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93769 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93770 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93771 if (np->rxopt.bits.rxtclass)
93772- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93773+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93774 if (ipv6_opt_accepted(sk, opt_skb)) {
93775 skb_set_owner_r(opt_skb, sk);
93776 opt_skb = xchg(&np->pktoptions, opt_skb);
93777@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93778 TCP_SKB_CB(skb)->sacked = 0;
93779
93780 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93781- if (!sk)
93782+ if (!sk) {
93783+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93784+ ret = 1;
93785+#endif
93786 goto no_tcp_socket;
93787+ }
93788
93789 process:
93790- if (sk->sk_state == TCP_TIME_WAIT)
93791+ if (sk->sk_state == TCP_TIME_WAIT) {
93792+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93793+ ret = 2;
93794+#endif
93795 goto do_time_wait;
93796+ }
93797
93798 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93799 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93800@@ -1538,6 +1553,10 @@ csum_error:
93801 bad_packet:
93802 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93803 } else {
93804+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93805+ if (!grsec_enable_blackhole || (ret == 1 &&
93806+ (skb->dev->flags & IFF_LOOPBACK)))
93807+#endif
93808 tcp_v6_send_reset(NULL, skb);
93809 }
93810
93811diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93812index f405815..45a68a6 100644
93813--- a/net/ipv6/udp.c
93814+++ b/net/ipv6/udp.c
93815@@ -53,6 +53,10 @@
93816 #include <trace/events/skb.h>
93817 #include "udp_impl.h"
93818
93819+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93820+extern int grsec_enable_blackhole;
93821+#endif
93822+
93823 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93824 {
93825 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93826@@ -420,7 +424,7 @@ try_again:
93827 if (unlikely(err)) {
93828 trace_kfree_skb(skb, udpv6_recvmsg);
93829 if (!peeked) {
93830- atomic_inc(&sk->sk_drops);
93831+ atomic_inc_unchecked(&sk->sk_drops);
93832 if (is_udp4)
93833 UDP_INC_STATS_USER(sock_net(sk),
93834 UDP_MIB_INERRORS,
93835@@ -666,7 +670,7 @@ csum_error:
93836 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93837 drop:
93838 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93839- atomic_inc(&sk->sk_drops);
93840+ atomic_inc_unchecked(&sk->sk_drops);
93841 kfree_skb(skb);
93842 return -1;
93843 }
93844@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93845 if (likely(skb1 == NULL))
93846 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93847 if (!skb1) {
93848- atomic_inc(&sk->sk_drops);
93849+ atomic_inc_unchecked(&sk->sk_drops);
93850 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93851 IS_UDPLITE(sk));
93852 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93853@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93854 goto csum_error;
93855
93856 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93857+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93858+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93859+#endif
93860 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93861
93862 kfree_skb(skb);
93863diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93864index 23ed03d..6532e67 100644
93865--- a/net/ipv6/xfrm6_policy.c
93866+++ b/net/ipv6/xfrm6_policy.c
93867@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93868 }
93869 }
93870
93871-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93872+static int xfrm6_garbage_collect(struct dst_ops *ops)
93873 {
93874 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93875
93876- xfrm6_policy_afinfo.garbage_collect(net);
93877+ xfrm_garbage_collect_deferred(net);
93878 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93879 }
93880
93881@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93882
93883 static int __net_init xfrm6_net_init(struct net *net)
93884 {
93885- struct ctl_table *table;
93886+ ctl_table_no_const *table = NULL;
93887 struct ctl_table_header *hdr;
93888
93889- table = xfrm6_policy_table;
93890 if (!net_eq(net, &init_net)) {
93891- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93892+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93893 if (!table)
93894 goto err_alloc;
93895
93896 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93897- }
93898+ hdr = register_net_sysctl(net, "net/ipv6", table);
93899+ } else
93900+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93901
93902- hdr = register_net_sysctl(net, "net/ipv6", table);
93903 if (!hdr)
93904 goto err_reg;
93905
93906@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93907 return 0;
93908
93909 err_reg:
93910- if (!net_eq(net, &init_net))
93911- kfree(table);
93912+ kfree(table);
93913 err_alloc:
93914 return -ENOMEM;
93915 }
93916diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93917index 41ac7938..75e3bb1 100644
93918--- a/net/irda/ircomm/ircomm_tty.c
93919+++ b/net/irda/ircomm/ircomm_tty.c
93920@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93921 add_wait_queue(&port->open_wait, &wait);
93922
93923 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93924- __FILE__, __LINE__, tty->driver->name, port->count);
93925+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93926
93927 spin_lock_irqsave(&port->lock, flags);
93928 if (!tty_hung_up_p(filp))
93929- port->count--;
93930+ atomic_dec(&port->count);
93931 port->blocked_open++;
93932 spin_unlock_irqrestore(&port->lock, flags);
93933
93934@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93935 }
93936
93937 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93938- __FILE__, __LINE__, tty->driver->name, port->count);
93939+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93940
93941 schedule();
93942 }
93943@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93944
93945 spin_lock_irqsave(&port->lock, flags);
93946 if (!tty_hung_up_p(filp))
93947- port->count++;
93948+ atomic_inc(&port->count);
93949 port->blocked_open--;
93950 spin_unlock_irqrestore(&port->lock, flags);
93951
93952 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93953- __FILE__, __LINE__, tty->driver->name, port->count);
93954+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93955
93956 if (!retval)
93957 port->flags |= ASYNC_NORMAL_ACTIVE;
93958@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93959
93960 /* ++ is not atomic, so this should be protected - Jean II */
93961 spin_lock_irqsave(&self->port.lock, flags);
93962- self->port.count++;
93963+ atomic_inc(&self->port.count);
93964 spin_unlock_irqrestore(&self->port.lock, flags);
93965 tty_port_tty_set(&self->port, tty);
93966
93967 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93968- self->line, self->port.count);
93969+ self->line, atomic_read(&self->port.count));
93970
93971 /* Not really used by us, but lets do it anyway */
93972 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93973@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93974 tty_kref_put(port->tty);
93975 }
93976 port->tty = NULL;
93977- port->count = 0;
93978+ atomic_set(&port->count, 0);
93979 spin_unlock_irqrestore(&port->lock, flags);
93980
93981 wake_up_interruptible(&port->open_wait);
93982@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93983 seq_putc(m, '\n');
93984
93985 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93986- seq_printf(m, "Open count: %d\n", self->port.count);
93987+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93988 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93989 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93990
93991diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93992index 168aff5..9d43132 100644
93993--- a/net/iucv/af_iucv.c
93994+++ b/net/iucv/af_iucv.c
93995@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93996
93997 write_lock_bh(&iucv_sk_list.lock);
93998
93999- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
94000+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
94001 while (__iucv_get_sock_by_name(name)) {
94002 sprintf(name, "%08x",
94003- atomic_inc_return(&iucv_sk_list.autobind_name));
94004+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
94005 }
94006
94007 write_unlock_bh(&iucv_sk_list.lock);
94008diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
94009index cd5b8ec..f205e6b 100644
94010--- a/net/iucv/iucv.c
94011+++ b/net/iucv/iucv.c
94012@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
94013 return NOTIFY_OK;
94014 }
94015
94016-static struct notifier_block __refdata iucv_cpu_notifier = {
94017+static struct notifier_block iucv_cpu_notifier = {
94018 .notifier_call = iucv_cpu_notify,
94019 };
94020
94021diff --git a/net/key/af_key.c b/net/key/af_key.c
94022index ab8bd2c..3a3eb81 100644
94023--- a/net/key/af_key.c
94024+++ b/net/key/af_key.c
94025@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
94026
94027 x->id.proto = proto;
94028 x->id.spi = sa->sadb_sa_spi;
94029- x->props.replay_window = sa->sadb_sa_replay;
94030+ x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
94031+ (sizeof(x->replay.bitmap) * 8));
94032 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
94033 x->props.flags |= XFRM_STATE_NOECN;
94034 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
94035@@ -3048,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
94036 static u32 get_acqseq(void)
94037 {
94038 u32 res;
94039- static atomic_t acqseq;
94040+ static atomic_unchecked_t acqseq;
94041
94042 do {
94043- res = atomic_inc_return(&acqseq);
94044+ res = atomic_inc_return_unchecked(&acqseq);
94045 } while (!res);
94046 return res;
94047 }
94048diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
94049index feae495..aedaa2c 100644
94050--- a/net/l2tp/l2tp_core.c
94051+++ b/net/l2tp/l2tp_core.c
94052@@ -496,6 +496,7 @@ out:
94053 static inline int l2tp_verify_udp_checksum(struct sock *sk,
94054 struct sk_buff *skb)
94055 {
94056+ struct l2tp_tunnel *tunnel = (struct l2tp_tunnel *)sk->sk_user_data;
94057 struct udphdr *uh = udp_hdr(skb);
94058 u16 ulen = ntohs(uh->len);
94059 __wsum psum;
94060@@ -504,7 +505,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
94061 return 0;
94062
94063 #if IS_ENABLED(CONFIG_IPV6)
94064- if (sk->sk_family == PF_INET6) {
94065+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped) {
94066 if (!uh->check) {
94067 LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
94068 return 1;
94069@@ -1128,7 +1129,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
94070 /* Queue the packet to IP for output */
94071 skb->local_df = 1;
94072 #if IS_ENABLED(CONFIG_IPV6)
94073- if (skb->sk->sk_family == PF_INET6)
94074+ if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
94075 error = inet6_csk_xmit(skb, NULL);
94076 else
94077 #endif
94078@@ -1255,7 +1256,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
94079
94080 /* Calculate UDP checksum if configured to do so */
94081 #if IS_ENABLED(CONFIG_IPV6)
94082- if (sk->sk_family == PF_INET6)
94083+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
94084 l2tp_xmit_ipv6_csum(sk, skb, udp_len);
94085 else
94086 #endif
94087@@ -1704,6 +1705,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
94088 if (cfg != NULL)
94089 tunnel->debug = cfg->debug;
94090
94091+#if IS_ENABLED(CONFIG_IPV6)
94092+ if (sk->sk_family == PF_INET6) {
94093+ struct ipv6_pinfo *np = inet6_sk(sk);
94094+
94095+ if (ipv6_addr_v4mapped(&np->saddr) &&
94096+ ipv6_addr_v4mapped(&np->daddr)) {
94097+ struct inet_sock *inet = inet_sk(sk);
94098+
94099+ tunnel->v4mapped = true;
94100+ inet->inet_saddr = np->saddr.s6_addr32[3];
94101+ inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
94102+ inet->inet_daddr = np->daddr.s6_addr32[3];
94103+ } else {
94104+ tunnel->v4mapped = false;
94105+ }
94106+ }
94107+#endif
94108+
94109 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
94110 tunnel->encap = encap;
94111 if (encap == L2TP_ENCAPTYPE_UDP) {
94112@@ -1712,7 +1731,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
94113 udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
94114 udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
94115 #if IS_ENABLED(CONFIG_IPV6)
94116- if (sk->sk_family == PF_INET6)
94117+ if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
94118 udpv6_encap_enable();
94119 else
94120 #endif
94121diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
94122index 66a559b..6f251cb 100644
94123--- a/net/l2tp/l2tp_core.h
94124+++ b/net/l2tp/l2tp_core.h
94125@@ -194,6 +194,9 @@ struct l2tp_tunnel {
94126 struct sock *sock; /* Parent socket */
94127 int fd; /* Parent fd, if tunnel socket
94128 * was created by userspace */
94129+#if IS_ENABLED(CONFIG_IPV6)
94130+ bool v4mapped;
94131+#endif
94132
94133 struct work_struct del_work;
94134
94135diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
94136index 43dd752..63a23bc 100644
94137--- a/net/mac80211/cfg.c
94138+++ b/net/mac80211/cfg.c
94139@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
94140 ret = ieee80211_vif_use_channel(sdata, chandef,
94141 IEEE80211_CHANCTX_EXCLUSIVE);
94142 }
94143- } else if (local->open_count == local->monitors) {
94144+ } else if (local_read(&local->open_count) == local->monitors) {
94145 local->_oper_chandef = *chandef;
94146 ieee80211_hw_config(local, 0);
94147 }
94148@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94149 else
94150 local->probe_req_reg--;
94151
94152- if (!local->open_count)
94153+ if (!local_read(&local->open_count))
94154 break;
94155
94156 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94157@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94158 if (chanctx_conf) {
94159 *chandef = chanctx_conf->def;
94160 ret = 0;
94161- } else if (local->open_count > 0 &&
94162- local->open_count == local->monitors &&
94163+ } else if (local_read(&local->open_count) > 0 &&
94164+ local_read(&local->open_count) == local->monitors &&
94165 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94166 if (local->use_chanctx)
94167 *chandef = local->monitor_chandef;
94168diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94169index 8412a30..6e00181 100644
94170--- a/net/mac80211/ieee80211_i.h
94171+++ b/net/mac80211/ieee80211_i.h
94172@@ -28,6 +28,7 @@
94173 #include <net/ieee80211_radiotap.h>
94174 #include <net/cfg80211.h>
94175 #include <net/mac80211.h>
94176+#include <asm/local.h>
94177 #include "key.h"
94178 #include "sta_info.h"
94179 #include "debug.h"
94180@@ -907,7 +908,7 @@ struct ieee80211_local {
94181 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94182 spinlock_t queue_stop_reason_lock;
94183
94184- int open_count;
94185+ local_t open_count;
94186 int monitors, cooked_mntrs;
94187 /* number of interfaces with corresponding FIF_ flags */
94188 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94189diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94190index cc11759..11d5541 100644
94191--- a/net/mac80211/iface.c
94192+++ b/net/mac80211/iface.c
94193@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94194 break;
94195 }
94196
94197- if (local->open_count == 0) {
94198+ if (local_read(&local->open_count) == 0) {
94199 res = drv_start(local);
94200 if (res)
94201 goto err_del_bss;
94202@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94203 res = drv_add_interface(local, sdata);
94204 if (res)
94205 goto err_stop;
94206- } else if (local->monitors == 0 && local->open_count == 0) {
94207+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94208 res = ieee80211_add_virtual_monitor(local);
94209 if (res)
94210 goto err_stop;
94211@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94212 atomic_inc(&local->iff_promiscs);
94213
94214 if (coming_up)
94215- local->open_count++;
94216+ local_inc(&local->open_count);
94217
94218 if (hw_reconf_flags)
94219 ieee80211_hw_config(local, hw_reconf_flags);
94220@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94221 err_del_interface:
94222 drv_remove_interface(local, sdata);
94223 err_stop:
94224- if (!local->open_count)
94225+ if (!local_read(&local->open_count))
94226 drv_stop(local);
94227 err_del_bss:
94228 sdata->bss = NULL;
94229@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94230 }
94231
94232 if (going_down)
94233- local->open_count--;
94234+ local_dec(&local->open_count);
94235
94236 switch (sdata->vif.type) {
94237 case NL80211_IFTYPE_AP_VLAN:
94238@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94239 }
94240 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94241
94242- if (local->open_count == 0)
94243+ if (local_read(&local->open_count) == 0)
94244 ieee80211_clear_tx_pending(local);
94245
94246 /*
94247@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94248
94249 ieee80211_recalc_ps(local, -1);
94250
94251- if (local->open_count == 0) {
94252+ if (local_read(&local->open_count) == 0) {
94253 ieee80211_stop_device(local);
94254
94255 /* no reconfiguring after stop! */
94256@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94257 ieee80211_configure_filter(local);
94258 ieee80211_hw_config(local, hw_reconf_flags);
94259
94260- if (local->monitors == local->open_count)
94261+ if (local->monitors == local_read(&local->open_count))
94262 ieee80211_add_virtual_monitor(local);
94263 }
94264
94265diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94266index 091088a..daf43c7 100644
94267--- a/net/mac80211/main.c
94268+++ b/net/mac80211/main.c
94269@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94270 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94271 IEEE80211_CONF_CHANGE_POWER);
94272
94273- if (changed && local->open_count) {
94274+ if (changed && local_read(&local->open_count)) {
94275 ret = drv_config(local, changed);
94276 /*
94277 * Goal:
94278diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94279index 3401262..d5cd68d 100644
94280--- a/net/mac80211/pm.c
94281+++ b/net/mac80211/pm.c
94282@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94283 struct ieee80211_sub_if_data *sdata;
94284 struct sta_info *sta;
94285
94286- if (!local->open_count)
94287+ if (!local_read(&local->open_count))
94288 goto suspend;
94289
94290 ieee80211_scan_cancel(local);
94291@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94292 cancel_work_sync(&local->dynamic_ps_enable_work);
94293 del_timer_sync(&local->dynamic_ps_timer);
94294
94295- local->wowlan = wowlan && local->open_count;
94296+ local->wowlan = wowlan && local_read(&local->open_count);
94297 if (local->wowlan) {
94298 int err = drv_suspend(local, wowlan);
94299 if (err < 0) {
94300@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94301 WARN_ON(!list_empty(&local->chanctx_list));
94302
94303 /* stop hardware - this must stop RX */
94304- if (local->open_count)
94305+ if (local_read(&local->open_count))
94306 ieee80211_stop_device(local);
94307
94308 suspend:
94309diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94310index 30d58d2..449ac8e 100644
94311--- a/net/mac80211/rate.c
94312+++ b/net/mac80211/rate.c
94313@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94314
94315 ASSERT_RTNL();
94316
94317- if (local->open_count)
94318+ if (local_read(&local->open_count))
94319 return -EBUSY;
94320
94321 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94322diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94323index c97a065..ff61928 100644
94324--- a/net/mac80211/rc80211_pid_debugfs.c
94325+++ b/net/mac80211/rc80211_pid_debugfs.c
94326@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94327
94328 spin_unlock_irqrestore(&events->lock, status);
94329
94330- if (copy_to_user(buf, pb, p))
94331+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94332 return -EFAULT;
94333
94334 return p;
94335diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94336index 2265445..ba14971 100644
94337--- a/net/mac80211/util.c
94338+++ b/net/mac80211/util.c
94339@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94340 }
94341 #endif
94342 /* everything else happens only if HW was up & running */
94343- if (!local->open_count)
94344+ if (!local_read(&local->open_count))
94345 goto wake_up;
94346
94347 /*
94348@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94349 local->in_reconfig = false;
94350 barrier();
94351
94352- if (local->monitors == local->open_count && local->monitors > 0)
94353+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94354 ieee80211_add_virtual_monitor(local);
94355
94356 /*
94357diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94358index 56d22ca..87c778f 100644
94359--- a/net/netfilter/Kconfig
94360+++ b/net/netfilter/Kconfig
94361@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94362
94363 To compile it as a module, choose M here. If unsure, say N.
94364
94365+config NETFILTER_XT_MATCH_GRADM
94366+ tristate '"gradm" match support'
94367+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94368+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94369+ ---help---
94370+ The gradm match allows to match on grsecurity RBAC being enabled.
94371+ It is useful when iptables rules are applied early on bootup to
94372+ prevent connections to the machine (except from a trusted host)
94373+ while the RBAC system is disabled.
94374+
94375 config NETFILTER_XT_MATCH_HASHLIMIT
94376 tristate '"hashlimit" match support'
94377 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94378diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94379index a1abf87..dbcb7ee 100644
94380--- a/net/netfilter/Makefile
94381+++ b/net/netfilter/Makefile
94382@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94383 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94384 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94385 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94386+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94387 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94388 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94389 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94390diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94391index f771390..145b765 100644
94392--- a/net/netfilter/ipset/ip_set_core.c
94393+++ b/net/netfilter/ipset/ip_set_core.c
94394@@ -1820,7 +1820,7 @@ done:
94395 return ret;
94396 }
94397
94398-static struct nf_sockopt_ops so_set __read_mostly = {
94399+static struct nf_sockopt_ops so_set = {
94400 .pf = PF_INET,
94401 .get_optmin = SO_IP_SET,
94402 .get_optmax = SO_IP_SET + 1,
94403diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94404index 4c8e5c0..5a79b4d 100644
94405--- a/net/netfilter/ipvs/ip_vs_conn.c
94406+++ b/net/netfilter/ipvs/ip_vs_conn.c
94407@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94408 /* Increase the refcnt counter of the dest */
94409 ip_vs_dest_hold(dest);
94410
94411- conn_flags = atomic_read(&dest->conn_flags);
94412+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94413 if (cp->protocol != IPPROTO_UDP)
94414 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94415 flags = cp->flags;
94416@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94417
94418 cp->control = NULL;
94419 atomic_set(&cp->n_control, 0);
94420- atomic_set(&cp->in_pkts, 0);
94421+ atomic_set_unchecked(&cp->in_pkts, 0);
94422
94423 cp->packet_xmit = NULL;
94424 cp->app = NULL;
94425@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94426
94427 /* Don't drop the entry if its number of incoming packets is not
94428 located in [0, 8] */
94429- i = atomic_read(&cp->in_pkts);
94430+ i = atomic_read_unchecked(&cp->in_pkts);
94431 if (i > 8 || i < 0) return 0;
94432
94433 if (!todrop_rate[i]) return 0;
94434diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94435index 4f69e83..da2d8bf 100644
94436--- a/net/netfilter/ipvs/ip_vs_core.c
94437+++ b/net/netfilter/ipvs/ip_vs_core.c
94438@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94439 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94440 /* do not touch skb anymore */
94441
94442- atomic_inc(&cp->in_pkts);
94443+ atomic_inc_unchecked(&cp->in_pkts);
94444 ip_vs_conn_put(cp);
94445 return ret;
94446 }
94447@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94448 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94449 pkts = sysctl_sync_threshold(ipvs);
94450 else
94451- pkts = atomic_add_return(1, &cp->in_pkts);
94452+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94453
94454 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94455 ip_vs_sync_conn(net, cp, pkts);
94456diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94457index c8148e4..eff604f 100644
94458--- a/net/netfilter/ipvs/ip_vs_ctl.c
94459+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94460@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94461 */
94462 ip_vs_rs_hash(ipvs, dest);
94463 }
94464- atomic_set(&dest->conn_flags, conn_flags);
94465+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94466
94467 /* bind the service */
94468 if (!dest->svc) {
94469@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94470 * align with netns init in ip_vs_control_net_init()
94471 */
94472
94473-static struct ctl_table vs_vars[] = {
94474+static ctl_table_no_const vs_vars[] __read_only = {
94475 {
94476 .procname = "amemthresh",
94477 .maxlen = sizeof(int),
94478@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94479 " %-7s %-6d %-10d %-10d\n",
94480 &dest->addr.in6,
94481 ntohs(dest->port),
94482- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94483+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94484 atomic_read(&dest->weight),
94485 atomic_read(&dest->activeconns),
94486 atomic_read(&dest->inactconns));
94487@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94488 "%-7s %-6d %-10d %-10d\n",
94489 ntohl(dest->addr.ip),
94490 ntohs(dest->port),
94491- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94492+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94493 atomic_read(&dest->weight),
94494 atomic_read(&dest->activeconns),
94495 atomic_read(&dest->inactconns));
94496@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94497
94498 entry.addr = dest->addr.ip;
94499 entry.port = dest->port;
94500- entry.conn_flags = atomic_read(&dest->conn_flags);
94501+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94502 entry.weight = atomic_read(&dest->weight);
94503 entry.u_threshold = dest->u_threshold;
94504 entry.l_threshold = dest->l_threshold;
94505@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94506 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94507 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94508 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94509- (atomic_read(&dest->conn_flags) &
94510+ (atomic_read_unchecked(&dest->conn_flags) &
94511 IP_VS_CONN_F_FWD_MASK)) ||
94512 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94513 atomic_read(&dest->weight)) ||
94514@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94515 {
94516 int idx;
94517 struct netns_ipvs *ipvs = net_ipvs(net);
94518- struct ctl_table *tbl;
94519+ ctl_table_no_const *tbl;
94520
94521 atomic_set(&ipvs->dropentry, 0);
94522 spin_lock_init(&ipvs->dropentry_lock);
94523diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94524index 1383b0e..a486da1 100644
94525--- a/net/netfilter/ipvs/ip_vs_lblc.c
94526+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94527@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94528 * IPVS LBLC sysctl table
94529 */
94530 #ifdef CONFIG_SYSCTL
94531-static struct ctl_table vs_vars_table[] = {
94532+static ctl_table_no_const vs_vars_table[] __read_only = {
94533 {
94534 .procname = "lblc_expiration",
94535 .data = NULL,
94536diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94537index 3cd85b2..dfab2b8 100644
94538--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94539+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94540@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94541 * IPVS LBLCR sysctl table
94542 */
94543
94544-static struct ctl_table vs_vars_table[] = {
94545+static ctl_table_no_const vs_vars_table[] __read_only = {
94546 {
94547 .procname = "lblcr_expiration",
94548 .data = NULL,
94549diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94550index f448471..995f131 100644
94551--- a/net/netfilter/ipvs/ip_vs_sync.c
94552+++ b/net/netfilter/ipvs/ip_vs_sync.c
94553@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94554 cp = cp->control;
94555 if (cp) {
94556 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94557- pkts = atomic_add_return(1, &cp->in_pkts);
94558+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94559 else
94560 pkts = sysctl_sync_threshold(ipvs);
94561 ip_vs_sync_conn(net, cp->control, pkts);
94562@@ -771,7 +771,7 @@ control:
94563 if (!cp)
94564 return;
94565 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94566- pkts = atomic_add_return(1, &cp->in_pkts);
94567+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94568 else
94569 pkts = sysctl_sync_threshold(ipvs);
94570 goto sloop;
94571@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94572
94573 if (opt)
94574 memcpy(&cp->in_seq, opt, sizeof(*opt));
94575- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94576+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94577 cp->state = state;
94578 cp->old_state = cp->state;
94579 /*
94580diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94581index c47444e..b0961c6 100644
94582--- a/net/netfilter/ipvs/ip_vs_xmit.c
94583+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94584@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94585 else
94586 rc = NF_ACCEPT;
94587 /* do not touch skb anymore */
94588- atomic_inc(&cp->in_pkts);
94589+ atomic_inc_unchecked(&cp->in_pkts);
94590 goto out;
94591 }
94592
94593@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94594 else
94595 rc = NF_ACCEPT;
94596 /* do not touch skb anymore */
94597- atomic_inc(&cp->in_pkts);
94598+ atomic_inc_unchecked(&cp->in_pkts);
94599 goto out;
94600 }
94601
94602diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94603index 2d3030a..7ba1c0a 100644
94604--- a/net/netfilter/nf_conntrack_acct.c
94605+++ b/net/netfilter/nf_conntrack_acct.c
94606@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94607 #ifdef CONFIG_SYSCTL
94608 static int nf_conntrack_acct_init_sysctl(struct net *net)
94609 {
94610- struct ctl_table *table;
94611+ ctl_table_no_const *table;
94612
94613 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94614 GFP_KERNEL);
94615diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94616index 0283bae..5febcb0 100644
94617--- a/net/netfilter/nf_conntrack_core.c
94618+++ b/net/netfilter/nf_conntrack_core.c
94619@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94620 #define DYING_NULLS_VAL ((1<<30)+1)
94621 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94622
94623+#ifdef CONFIG_GRKERNSEC_HIDESYM
94624+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94625+#endif
94626+
94627 int nf_conntrack_init_net(struct net *net)
94628 {
94629 int ret;
94630@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94631 goto err_stat;
94632 }
94633
94634+#ifdef CONFIG_GRKERNSEC_HIDESYM
94635+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94636+#else
94637 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94638+#endif
94639 if (!net->ct.slabname) {
94640 ret = -ENOMEM;
94641 goto err_slabname;
94642diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94643index 1df1761..ce8b88a 100644
94644--- a/net/netfilter/nf_conntrack_ecache.c
94645+++ b/net/netfilter/nf_conntrack_ecache.c
94646@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94647 #ifdef CONFIG_SYSCTL
94648 static int nf_conntrack_event_init_sysctl(struct net *net)
94649 {
94650- struct ctl_table *table;
94651+ ctl_table_no_const *table;
94652
94653 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94654 GFP_KERNEL);
94655diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94656index 974a2a4..52cc6ff 100644
94657--- a/net/netfilter/nf_conntrack_helper.c
94658+++ b/net/netfilter/nf_conntrack_helper.c
94659@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94660
94661 static int nf_conntrack_helper_init_sysctl(struct net *net)
94662 {
94663- struct ctl_table *table;
94664+ ctl_table_no_const *table;
94665
94666 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94667 GFP_KERNEL);
94668diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94669index 0ab9636..cea3c6a 100644
94670--- a/net/netfilter/nf_conntrack_proto.c
94671+++ b/net/netfilter/nf_conntrack_proto.c
94672@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94673
94674 static void
94675 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94676- struct ctl_table **table,
94677+ ctl_table_no_const **table,
94678 unsigned int users)
94679 {
94680 if (users > 0)
94681diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94682index a99b6c3..cb372f9 100644
94683--- a/net/netfilter/nf_conntrack_proto_dccp.c
94684+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94685@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94686 const char *msg;
94687 u_int8_t state;
94688
94689- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94690+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94691 BUG_ON(dh == NULL);
94692
94693 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94694@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94695 out_invalid:
94696 if (LOG_INVALID(net, IPPROTO_DCCP))
94697 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94698- NULL, msg);
94699+ NULL, "%s", msg);
94700 return false;
94701 }
94702
94703@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94704 u_int8_t type, old_state, new_state;
94705 enum ct_dccp_roles role;
94706
94707- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94708+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94709 BUG_ON(dh == NULL);
94710 type = dh->dccph_type;
94711
94712@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94713 unsigned int cscov;
94714 const char *msg;
94715
94716- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94717+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94718 if (dh == NULL) {
94719 msg = "nf_ct_dccp: short packet ";
94720 goto out_invalid;
94721@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94722
94723 out_invalid:
94724 if (LOG_INVALID(net, IPPROTO_DCCP))
94725- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94726+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94727 return -NF_ACCEPT;
94728 }
94729
94730diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94731index f641751..d3c5b51 100644
94732--- a/net/netfilter/nf_conntrack_standalone.c
94733+++ b/net/netfilter/nf_conntrack_standalone.c
94734@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94735
94736 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94737 {
94738- struct ctl_table *table;
94739+ ctl_table_no_const *table;
94740
94741 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94742 GFP_KERNEL);
94743diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94744index 902fb0a..87f7fdb 100644
94745--- a/net/netfilter/nf_conntrack_timestamp.c
94746+++ b/net/netfilter/nf_conntrack_timestamp.c
94747@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94748 #ifdef CONFIG_SYSCTL
94749 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94750 {
94751- struct ctl_table *table;
94752+ ctl_table_no_const *table;
94753
94754 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94755 GFP_KERNEL);
94756diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94757index 85296d4..8becdec 100644
94758--- a/net/netfilter/nf_log.c
94759+++ b/net/netfilter/nf_log.c
94760@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94761
94762 #ifdef CONFIG_SYSCTL
94763 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94764-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94765+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94766
94767 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94768 void __user *buffer, size_t *lenp, loff_t *ppos)
94769@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94770 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94771 mutex_unlock(&nf_log_mutex);
94772 } else {
94773+ ctl_table_no_const nf_log_table = *table;
94774+
94775 mutex_lock(&nf_log_mutex);
94776 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94777 lockdep_is_held(&nf_log_mutex));
94778 if (!logger)
94779- table->data = "NONE";
94780+ nf_log_table.data = "NONE";
94781 else
94782- table->data = logger->name;
94783- r = proc_dostring(table, write, buffer, lenp, ppos);
94784+ nf_log_table.data = logger->name;
94785+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94786 mutex_unlock(&nf_log_mutex);
94787 }
94788
94789diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94790index f042ae5..30ea486 100644
94791--- a/net/netfilter/nf_sockopt.c
94792+++ b/net/netfilter/nf_sockopt.c
94793@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94794 }
94795 }
94796
94797- list_add(&reg->list, &nf_sockopts);
94798+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94799 out:
94800 mutex_unlock(&nf_sockopt_mutex);
94801 return ret;
94802@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94803 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94804 {
94805 mutex_lock(&nf_sockopt_mutex);
94806- list_del(&reg->list);
94807+ pax_list_del((struct list_head *)&reg->list);
94808 mutex_unlock(&nf_sockopt_mutex);
94809 }
94810 EXPORT_SYMBOL(nf_unregister_sockopt);
94811diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94812index d92cc31..e46f350 100644
94813--- a/net/netfilter/nfnetlink_log.c
94814+++ b/net/netfilter/nfnetlink_log.c
94815@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94816 struct nfnl_log_net {
94817 spinlock_t instances_lock;
94818 struct hlist_head instance_table[INSTANCE_BUCKETS];
94819- atomic_t global_seq;
94820+ atomic_unchecked_t global_seq;
94821 };
94822
94823 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94824@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94825 /* global sequence number */
94826 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94827 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94828- htonl(atomic_inc_return(&log->global_seq))))
94829+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94830 goto nla_put_failure;
94831
94832 if (data_len) {
94833diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94834new file mode 100644
94835index 0000000..c566332
94836--- /dev/null
94837+++ b/net/netfilter/xt_gradm.c
94838@@ -0,0 +1,51 @@
94839+/*
94840+ * gradm match for netfilter
94841